001: /*
002: (c) Copyright 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
003: [see end of file]
004: $Id: TestStatements.java,v 1.20 2008/01/02 12:04:43 andy_seaborne Exp $
005: */
006:
007: package com.hp.hpl.jena.rdf.model.test;
008:
009: import com.hp.hpl.jena.graph.FrontsTriple;
010: import com.hp.hpl.jena.rdf.model.*;
011: import junit.framework.*;
012:
013: import com.hp.hpl.jena.vocabulary.RDF;
014:
015: public class TestStatements extends ModelTestBase {
016: public TestStatements(String name) {
017: super (name);
018: }
019:
020: public static TestSuite suite() {
021: return new TestSuite(TestStatements.class);
022: }
023:
024: public void testStatmentMap1Selectors() {
025: Statement s = statement("sub pred obj");
026: assertEquals(resource("sub"), Statement.Util.getSubject.map1(s));
027: assertEquals(resource("pred"), Statement.Util.getPredicate
028: .map1(s));
029: assertEquals(resource("obj"), Statement.Util.getObject.map1(s));
030: }
031:
032: /**
033: this case came up when Chris was sorting out ReifedStatement and
034: had mishacked Model.createStatement. A resource created in one
035: model and incorporated into a statement asserted constructed by a
036: different model should test equal to the resource extracted from that
037: statement, even if it's a bnode.
038: */
039: public void testStuff() {
040: Model red = ModelFactory.createDefaultModel();
041: Model blue = ModelFactory.createDefaultModel();
042: Resource r = red.createResource();
043: Property p = red.createProperty("");
044: Statement s = blue.createStatement(r, p, r);
045: assertEquals("subject preserved", r, s.getSubject());
046: assertEquals("object preserved", r, s.getObject());
047: }
048:
049: public void testOtherStuff() {
050: Model A = ModelFactory.createDefaultModel();
051: Model B = ModelFactory.createDefaultModel();
052: Resource S = A.createResource("jena:S");
053: Resource R = A.createResource("jena:R");
054: Property P = A.createProperty("jena:P");
055: RDFNode O = A.createResource("jena:O");
056: A.add(S, P, O);
057: B.add(S, P, O);
058: assertTrue("X1", A.isIsomorphicWith(B));
059: /* */
060: A.add(R, RDF.subject, S);
061: B.add(R, RDF.predicate, P);
062: assertFalse("X2", A.isIsomorphicWith(B));
063: /* */
064: A.add(R, RDF.predicate, P);
065: B.add(R, RDF.subject, S);
066: assertTrue("X3", A.isIsomorphicWith(B));
067: /* */
068: A.add(R, RDF.object, O);
069: B.add(R, RDF.type, RDF.Statement);
070: assertFalse("X4", A.isIsomorphicWith(B));
071: /* */
072: A.add(R, RDF.type, RDF.Statement);
073: B.add(R, RDF.object, O);
074: assertTrue("X5", A.isIsomorphicWith(B));
075: }
076:
077: public void testSet() {
078: Model A = ModelFactory.createDefaultModel();
079: Model B = ModelFactory.createDefaultModel();
080: Resource S = A.createResource("jena:S");
081: Resource R = A.createResource("jena:R");
082: Property P = A.createProperty("jena:P");
083: RDFNode O = A.createResource("jena:O");
084: Statement spo = A.createStatement(S, P, O);
085: A.add(spo);
086: Statement sps = A.createStatement(S, P, S);
087: assertEquals(sps, spo.changeObject(S));
088: assertFalse(A.contains(spo));
089: assertTrue(A.contains(sps));
090: }
091:
092: public void testPortingBlankNodes() {
093: Model A = ModelFactory.createDefaultModel();
094: Model B = ModelFactory.createDefaultModel();
095: Resource anon = A.createResource();
096: Resource bAnon = (Resource) anon.inModel(B);
097: assertTrue("moved resource should still be blank", bAnon
098: .isAnon());
099: assertEquals("move resource should equal original", anon, bAnon);
100: }
101:
102: public void testTripleWrapper() {
103: Model A = ModelFactory.createDefaultModel();
104: assertInstanceOf(FrontsTriple.class, statement(A, "s p o"));
105: }
106:
107: /**
108: Feeble test that toString'ing a Statement[Impl] will display the data-type
109: of its object if it has one.
110: */
111: public void testStatementPrintsType() {
112: Model m = ModelFactory.createDefaultModel();
113: String fakeURI = "fake:URI";
114: Resource S = m.createResource();
115: Property P = property(m, "PP");
116: RDFNode O = m.createTypedLiteral("42", fakeURI);
117: Statement st = m.createStatement(S, P, O);
118: assertTrue(st.toString().indexOf(fakeURI) > 0);
119: }
120:
121: public void testHasWellFormedXML() {
122: assertFalse(statement("s P 1").hasWellFormedXML());
123: assertFalse(statement("S P '<x>/x>'rdf:XMLLiteral")
124: .hasWellFormedXML());
125: assertTrue(statement("S P '<x></x>'rdf:XMLLiteral")
126: .hasWellFormedXML());
127: }
128: }
129:
130: /*
131: (c) Copyright 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
132: All rights reserved.
133:
134: Redistribution and use in source and binary forms, with or without
135: modification, are permitted provided that the following conditions
136: are met:
137:
138: 1. Redistributions of source code must retain the above copyright
139: notice, this list of conditions and the following disclaimer.
140:
141: 2. Redistributions in binary form must reproduce the above copyright
142: notice, this list of conditions and the following disclaimer in the
143: documentation and/or other materials provided with the distribution.
144:
145: 3. The name of the author may not be used to endorse or promote products
146: derived from this software without specific prior written permission.
147:
148: THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
149: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
150: OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
151: IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
152: INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
153: NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
154: DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
155: THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
156: (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
157: THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
158: */
|