You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jena.apache.org by cl...@apache.org on 2013/10/09 19:16:18 UTC
svn commit: r1530718 [10/10] - in /jena/Experimental/new-test: ./
src/test/java/com/hp/hpl/jena/graph/
src/test/java/com/hp/hpl/jena/graph/compose/
src/test/java/com/hp/hpl/jena/graph/impl/
src/test/java/com/hp/hpl/jena/mem/ src/test/java/com/hp/hpl/je...
Modified: jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/rdf/model/temp/SeqMethodsTest.java
URL: http://svn.apache.org/viewvc/jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/rdf/model/temp/SeqMethodsTest.java?rev=1530718&r1=1530717&r2=1530718&view=diff
==============================================================================
--- jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/rdf/model/temp/SeqMethodsTest.java (original)
+++ jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/rdf/model/temp/SeqMethodsTest.java Wed Oct 9 17:16:15 2013
@@ -1,26 +1,57 @@
package com.hp.hpl.jena.rdf.model.temp;
-import com.hp.hpl.jena.rdf.model.AbstractSeqMethodsTest;
+import org.xenei.junit.contract.Contract.Inject;
+
+import com.hp.hpl.jena.rdf.model.Container;
+import com.hp.hpl.jena.rdf.model.Resource;
+import com.hp.hpl.jena.rdf.model.Seq;
+import com.hp.hpl.jena.rdf.model.SeqContractTests;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;
-import com.hp.hpl.jena.testing_framework.AbstractModelProducer;
-import com.hp.hpl.jena.testing_framework.ModelProducerInterface;
+import com.hp.hpl.jena.testing_framework.IContainerProducer;
+import com.hp.hpl.jena.vocabulary.RDF;
+
+public class SeqMethodsTest extends SeqContractTests {
+ IContainerProducer<Seq> producer = new IContainerProducer<Seq>() {
+ Model model = null;
+ @Override
+ public Seq newInstance(String uri) {
+ return getModel().createSeq(uri);
+ }
+ @Override
+ public Model getModel() {
+ if (model == null) {
+ model = ModelFactory.createDefaultModel();
+ }
+ return model;
+ }
-public class SeqMethodsTest extends AbstractSeqMethodsTest {
- AbstractModelProducer producer = new AbstractModelProducer()
- {
+ @Override
+ public Seq newInstance() {
+ return getModel().createSeq();
+ }
@Override
- protected Model createNewModel() {
- return ModelFactory.createDefaultModel();
+ public void cleanUp() {
+ model = null;
+ }
+
+ @Override
+ public Resource getContainerType() {
+ return RDF.Seq;
+ }
+
+ @Override
+ public Class<? extends Container> getContainerClass() {
+ return Seq.class;
}
-
};
-
+
@Override
- public ModelProducerInterface getModelProducer() {
+ @Inject("com.hp.hpl.jena.testing_framework.IContainerProducer<%s>")
+ public IContainerProducer<Seq> getSeqProducer() {
return producer;
}
}
Modified: jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/rdf/model/temp/StatementTest.java
URL: http://svn.apache.org/viewvc/jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/rdf/model/temp/StatementTest.java?rev=1530718&r1=1530717&r2=1530718&view=diff
==============================================================================
--- jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/rdf/model/temp/StatementTest.java (original)
+++ jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/rdf/model/temp/StatementTest.java Wed Oct 9 17:16:15 2013
@@ -1,27 +1,79 @@
package com.hp.hpl.jena.rdf.model.temp;
-import com.hp.hpl.jena.rdf.model.AbstractStatementTest;
+import static com.hp.hpl.jena.testing_framework.ModelHelper.property;
+import static com.hp.hpl.jena.testing_framework.ModelHelper.rdfNode;
+import static com.hp.hpl.jena.testing_framework.ModelHelper.resource;
+
+import java.util.StringTokenizer;
+
+import org.xenei.junit.contract.Contract;
+
+import com.hp.hpl.jena.rdf.model.Property;
+import com.hp.hpl.jena.rdf.model.RDFNode;
+import com.hp.hpl.jena.rdf.model.Resource;
+import com.hp.hpl.jena.rdf.model.Statement;
+import com.hp.hpl.jena.rdf.model.StatementContractTests;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.testing_framework.AbstractModelProducer;
-import com.hp.hpl.jena.testing_framework.ModelProducerInterface;
+import com.hp.hpl.jena.testing_framework.IStatementProducer;
+public class StatementTest extends StatementContractTests {
+ private IStatementProducer<Statement> producer = new IStatementProducer<Statement>() {
-public class StatementTest extends AbstractStatementTest {
+ private Model model;
- AbstractModelProducer producer = new AbstractModelProducer()
- {
+ private AbstractModelProducer<Model> modelProducer = new AbstractModelProducer<Model>() {
+
+ @Override
+ public boolean areIndependent() {
+ return true;
+ }
+
+ @Override
+ protected Model createNewModel() {
+ return ModelFactory.createDefaultModel();
+ }
+ };
+
+ @Override
+ public Statement newInstance(String fact) {
+ StringTokenizer st = new StringTokenizer(fact);
+ Resource sub = resource(st.nextToken());
+ Property pred = property(st.nextToken());
+ RDFNode obj = rdfNode(st.nextToken());
+ return newInstance(sub, pred, obj);
+ }
+
+ @Override
+ public Statement newInstance(Resource s, Property p, RDFNode o) {
+ return getModel().createStatement(s, p, o);
+ }
@Override
- protected Model createNewModel() {
- return ModelFactory.createDefaultModel();
+ public Model getModel() {
+ if (model == null) {
+ model = getModelProducer().newInstance();
+ }
+ return model;
+ }
+
+ @Override
+ public void cleanUp() {
+ getModelProducer().cleanUp();
+ }
+
+ @Override
+ public AbstractModelProducer<Model> getModelProducer() {
+ return modelProducer;
}
-
};
-
+
@Override
- public ModelProducerInterface getModelProducer() {
+ @Contract.Inject( "org.xenei.junit.contract.IProducer<%s>" )
+ public IStatementProducer<Statement> getStatementProducer() {
return producer;
}
+
}
Modified: jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/shared/JenaExceptionTest.java
URL: http://svn.apache.org/viewvc/jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/shared/JenaExceptionTest.java?rev=1530718&r1=1530717&r2=1530718&view=diff
==============================================================================
--- jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/shared/JenaExceptionTest.java (original)
+++ jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/shared/JenaExceptionTest.java Wed Oct 9 17:16:15 2013
@@ -24,20 +24,18 @@ import org.junit.Test;
/**
* Test the jena Exception class
- *
+ *
*/
-public class JenaExceptionTest
- {
-
+public class JenaExceptionTest {
+
/**
* Test that nested Jena exceptions preserve the caught exception's message.
*/
@Test
- public void testRethrownMessage()
- {
- Exception e = new Exception( "kings and queens" );
- JenaException j = new JenaException( e );
- assertTrue( j.getMessage().endsWith( e.getMessage() ) );
- assertEquals( e, j.getCause() );
- }
+ public void testRethrownMessage() {
+ Exception e = new Exception("kings and queens");
+ JenaException j = new JenaException(e);
+ assertTrue(j.getMessage().endsWith(e.getMessage()));
+ assertEquals(e, j.getCause());
+ }
}
Copied: jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/shared/PrefixMappingContractTest.java (from r1525417, jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/shared/AbstractPrefixMappingTest.java)
URL: http://svn.apache.org/viewvc/jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/shared/PrefixMappingContractTest.java?p2=jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/shared/PrefixMappingContractTest.java&p1=jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/shared/AbstractPrefixMappingTest.java&r1=1525417&r2=1530718&rev=1530718&view=diff
==============================================================================
--- jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/shared/AbstractPrefixMappingTest.java (original)
+++ jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/shared/PrefixMappingContractTest.java Wed Oct 9 17:16:15 2013
@@ -28,27 +28,28 @@ import java.util.Map;
import java.util.Set;
import org.junit.Test;
+import org.xenei.junit.contract.Contract;
+
+import org.xenei.junit.contract.IProducer;
/**
- * Test prefix mappings - subclass this test and override getMapping() to
- * deliver the prefixMapping to be tested.
+ * Test prefix mappings - subclass this test and override getMappingProducer()
+ * to deliver the IProducer<prefixMapping> to be tested.
*/
+@Contract(PrefixMapping.class)
+public abstract class PrefixMappingContractTest {
-public abstract class AbstractPrefixMappingTest {
-
- public static boolean sameMapping( final PrefixMapping L, final PrefixMapping R )
- {
+ public static boolean sameMapping(final PrefixMapping L,
+ final PrefixMapping R) {
return L.getNsPrefixMap().equals(R.getNsPrefixMap());
}
-
- /**
- * Subclasses implement to return a new, empty prefixMapping of their
- * preferred implementation.
- */
- abstract protected PrefixMapping getMapping();
-
- public static final String[] illegalPrefixes = { "<hello>", "has:colon", "with a space",
- "-dashStart", "has#octothorp", "has/slash", "1numericStart", ".dotStart" };
+
+ @Contract.Inject( "org.xenei.junit.contract.IProducer<%s>" )
+ abstract public IProducer<? extends PrefixMapping> getMappingProducer();
+
+ public static final String[] illegalPrefixes = { "<hello>", "has:colon",
+ "with a space", "-dashStart", "has#octothorp", "has/slash",
+ "1numericStart", ".dotStart" };
public static final String httpURI = "http://example.com/";
public static final String httpPrefix = "hpfx";
@@ -59,11 +60,10 @@ public abstract class AbstractPrefixMapp
public static final String[] prefixes = { httpPrefix, urnPrefix };
public static final String[] uris = { httpURI, urnURI };
- private String createFQN( String prefix, String suffix )
- {
- return String.format( "%s:%s", prefix, suffix );
+ private String createFQN(String prefix, String suffix) {
+ return String.format("%s:%s", prefix, suffix);
}
-
+
/**
* test that we can extract a proper Map from a PrefixMapping
*/
@@ -74,51 +74,51 @@ public abstract class AbstractPrefixMapp
assertEquals("map should have two elements", 2, map.size());
assertEquals(httpURI, map.get(httpPrefix));
assertEquals(urnURI, map.get(urnPrefix));
-
+
// verify adding to map does not change PrefixMap.
map.put("newPfx", "http://example.com/new");
- assertNull( "Should not have added new prefix", pm.getNsPrefixURI("newPfx"));
- assertNull( "Should not have added new uri", pm.getNsURIPrefix("http://example.com/new"));
-
+ assertNull("Should not have added new prefix",
+ pm.getNsPrefixURI("newPfx"));
+ assertNull("Should not have added new uri",
+ pm.getNsURIPrefix("http://example.com/new"));
+
// verify changing map does not change PrefixMap
- map.put( httpPrefix, urnURI );
+ map.put(httpPrefix, urnURI);
assertEquals(httpURI, pm.getNsPrefixURI(httpPrefix));
assertEquals(urnPrefix, pm.getNsURIPrefix(urnURI));
-
+
}
private PrefixMapping getConfiguredMapping() {
- PrefixMapping ns = getMapping();
+ PrefixMapping ns = getMappingProducer().newInstance();
ns.setNsPrefix(httpPrefix, httpURI);
ns.setNsPrefix(urnPrefix, urnURI);
return ns;
}
-
@Test
public void testExpandPrefix_String() {
-
+
/**
* these are the required mappings which the test cases below should
- * satisfy: an array of 2-arrays, where element 0 is the string to expand
- * and element 1 is the string it should expand to.
+ * satisfy: an array of 2-arrays, where element 0 is the string to
+ * expand and element 1 is the string it should expand to.
*/
String[][] expansions = {
{ createFQN(httpPrefix, "pathPart"), httpURI + "pathPart" },
{ createFQN(urnPrefix, "partPath"), urnURI + "partPath" },
{ createFQN(httpPrefix, "path:part"), httpURI + "path:part" }, };
-
+
/**
- * these are strings that should not change when they are prefix-expanded
- * with crisp and rope as legal prefixes.
+ * these are strings that should not change when they are
+ * prefix-expanded with crisp and rope as legal prefixes.
*/
String[] dontChange = { "",
"http://www.somedomain.something/whatever#", "crispy:cabbage",
"cris:isOnInfiniteEarths", "rop:tangled/web", "roped:abseiling" };
-
PrefixMapping ns = getConfiguredMapping();
-
+
/* */
for (int i = 0; i < dontChange.length; i += 1)
assertEquals("should be unchanged", dontChange[i],
@@ -133,44 +133,54 @@ public abstract class AbstractPrefixMapp
public void testShortForm_String() {
PrefixMapping ns = getConfiguredMapping();
assertEquals("", ns.shortForm(""));
- assertEquals( "should not change", "foo:bar/stuff", ns.shortForm( "foo:bar/stuff") );
- for (int i=0;i<prefixes.length;i++)
- {
- logAssertEquals( this.getClass(), "matching uri should return uri", uris[i], ns.shortForm( uris[i] ));
-
- assertEquals( createFQN( prefixes[i], "tail"), ns.shortForm(uris[i] + "tail"));
- assertEquals( createFQN( prefixes[i], "two/segments"), ns.shortForm(uris[i] + "two/segments"));
- assertEquals( createFQN( prefixes[i], "colon:separated"), ns.shortForm(uris[i] + "colon:separated"));
+ assertEquals("should not change", "foo:bar/stuff",
+ ns.shortForm("foo:bar/stuff"));
+ for (int i = 0; i < prefixes.length; i++) {
+ logAssertEquals(this.getClass(), "matching uri should return uri",
+ uris[i], ns.shortForm(uris[i]));
+
+ assertEquals(createFQN(prefixes[i], "tail"),
+ ns.shortForm(uris[i] + "tail"));
+ assertEquals(createFQN(prefixes[i], "two/segments"),
+ ns.shortForm(uris[i] + "two/segments"));
+ assertEquals(createFQN(prefixes[i], "colon:separated"),
+ ns.shortForm(uris[i] + "colon:separated"));
}
}
@Test
public void testQnameFor_String() {
PrefixMapping ns = getConfiguredMapping();
-
- assertNull("Should return null if the ns is not registered", ns.qnameFor("eg:rowboat"));
-
- for (int i=0;i<prefixes.length;i++)
- {
- assertNull("Should return null if local name starts with number", ns.qnameFor(uris[i] + "12345"));
- assertNull("Should return null if it is URI only", ns.qnameFor( uris[i] ));
- assertNull("Should return null if local name contains a slash", ns.qnameFor( uris[i]+"non/fiction" ));
-
- assertEquals("Should create qName for "+uris[i] + "rowboat", createFQN( prefixes[i], "rowboat"), ns.qnameFor(uris[i] + "rowboat"));
-
+
+ assertNull("Should return null if the ns is not registered",
+ ns.qnameFor("eg:rowboat"));
+
+ for (int i = 0; i < prefixes.length; i++) {
+ assertNull("Should return null if local name starts with number",
+ ns.qnameFor(uris[i] + "12345"));
+ assertNull("Should return null if it is URI only",
+ ns.qnameFor(uris[i]));
+ assertNull("Should return null if local name contains a slash",
+ ns.qnameFor(uris[i] + "non/fiction"));
+
+ assertEquals("Should create qName for " + uris[i] + "rowboat",
+ createFQN(prefixes[i], "rowboat"),
+ ns.qnameFor(uris[i] + "rowboat"));
+
// add long version
- ns.setNsPrefix( prefixes[i]+"Long", uris[i]+"long/");
- assertEquals("Should return long version if local name contains a slash", createFQN( prefixes[i]+"Long", "name" ), ns.qnameFor( uris[i]+"long/name" ));
-
+ ns.setNsPrefix(prefixes[i] + "Long", uris[i] + "long/");
+ assertEquals(
+ "Should return long version if local name contains a slash",
+ createFQN(prefixes[i] + "Long", "name"),
+ ns.qnameFor(uris[i] + "long/name"));
+
}
}
-
-
@Test
public void testSetNsPrefixes_PrefixMapping() {
- PrefixMapping a = getMapping();
- PrefixMapping b = getMapping();
+ PrefixMapping a = getMappingProducer().newInstance();
+ PrefixMapping b = getMappingProducer().newInstance();
assertFalse("must have two diffferent maps", a == b);
a.setNsPrefix(httpPrefix, httpURI);
a.setNsPrefix("duplicate", "http://example.com/duplicate");
@@ -178,51 +188,54 @@ public abstract class AbstractPrefixMapp
b.setNsPrefix("duplicate", "http://example.com/duplicate2");
assertEquals(null, b.getNsPrefixURI(httpPrefix));
assertEquals(null, a.getNsPrefixURI(urnPrefix));
- assertSame( "setPrefixes( PrefixMapping) must return prefixMapping", b, b.setNsPrefixes(a) );
+ assertSame("setPrefixes( PrefixMapping) must return prefixMapping", b,
+ b.setNsPrefixes(a));
assertEquals(httpURI, b.getNsPrefixURI(httpPrefix));
assertEquals(urnURI, b.getNsPrefixURI(urnPrefix));
-
+
// verify duplicate was changed
- assertEquals( "duplicate should now match 'a' version", "http://example.com/duplicate", b.getNsPrefixURI("duplicate" ));
-
- }
+ assertEquals("duplicate should now match 'a' version",
+ "http://example.com/duplicate", b.getNsPrefixURI("duplicate"));
+ }
@Test
- public void testGetNsPrefixURI_String()
- {
+ public void testGetNsPrefixURI_String() {
PrefixMapping pm = getConfiguredMapping();
- assertEquals( httpURI, pm.getNsPrefixURI(httpPrefix));
- assertEquals( urnURI, pm.getNsPrefixURI(urnPrefix));
- assertNull( "Missing prefix should return null", pm.getNsPrefixURI("missingPrefix"));
+ assertEquals(httpURI, pm.getNsPrefixURI(httpPrefix));
+ assertEquals(urnURI, pm.getNsPrefixURI(urnPrefix));
+ assertNull("Missing prefix should return null",
+ pm.getNsPrefixURI("missingPrefix"));
}
-
+
@Test
- public void testGetNsURIPrefix_String()
- {
+ public void testGetNsURIPrefix_String() {
PrefixMapping pm = getConfiguredMapping();
- assertEquals( httpPrefix, pm.getNsURIPrefix(httpURI));
- assertEquals( urnPrefix, pm.getNsURIPrefix(urnURI));
- assertNull( "missing URI must return null", pm.getNsURIPrefix("http://example.com/misisng"));
-
- // setup a duplicate prefix
- pm.setNsPrefix(httpPrefix+"2", httpURI);
- String foundPrefix = pm.getNsURIPrefix( httpURI );
- assertNotNull( "duplicated URI must return a prefix", foundPrefix );
- assertEquals( "Must return most recently added in this case", httpPrefix+"2",foundPrefix);
-
+ assertEquals(httpPrefix, pm.getNsURIPrefix(httpURI));
+ assertEquals(urnPrefix, pm.getNsURIPrefix(urnURI));
+ assertNull("missing URI must return null",
+ pm.getNsURIPrefix("http://example.com/misisng"));
+
+ // setup a duplicate prefix
+ pm.setNsPrefix(httpPrefix + "2", httpURI);
+ String foundPrefix = pm.getNsURIPrefix(httpURI);
+ assertNotNull("duplicated URI must return a prefix", foundPrefix);
+ assertEquals("Must return most recently added in this case", httpPrefix
+ + "2", foundPrefix);
+
// test removing prefix uncovers previous map
- pm.removeNsPrefix(httpPrefix+"2");
- assertEquals( "Must return earlier prefix in this case", httpPrefix ,pm.getNsURIPrefix( httpURI ));
+ pm.removeNsPrefix(httpPrefix + "2");
+ assertEquals("Must return earlier prefix in this case", httpPrefix,
+ pm.getNsURIPrefix(httpURI));
}
-
+
/**
* as for testAddOtherPrefixMapping, except that it's a plain Map we're
* adding.
*/
@Test
public void testSetNsPrefixes_Map() {
- PrefixMapping b = getMapping();
+ PrefixMapping b = getMappingProducer().newInstance();
Map<String, String> map = new HashMap<String, String>();
map.put(httpPrefix, httpURI);
map.put("over", "http://example.com/overwritten/");
@@ -231,12 +244,13 @@ public abstract class AbstractPrefixMapp
b.setNsPrefixes(map);
assertEquals(httpURI, b.getNsPrefixURI(httpPrefix));
assertEquals(urnURI, b.getNsPrefixURI(urnPrefix));
- assertEquals("http://example.com/overwritten/", b.getNsPrefixURI("over"));
+ assertEquals("http://example.com/overwritten/",
+ b.getNsPrefixURI("over"));
}
@Test
public void testWithDefaultMappings_PrefixMap() {
- PrefixMapping pm = getMapping();
+ PrefixMapping pm = getMappingProducer().newInstance();
PrefixMapping root = PrefixMapping.Factory.create();
pm.setNsPrefix("a", "aFirst#");
pm.setNsPrefix("b", "bFirst#");
@@ -253,7 +267,7 @@ public abstract class AbstractPrefixMapp
@Test
public void testSecondPrefixRetainsExistingMap() {
- PrefixMapping A = getMapping();
+ PrefixMapping A = getMappingProducer().newInstance();
A.setNsPrefix("a", httpURI);
A.setNsPrefix("b", httpURI);
assertEquals(httpURI, A.getNsPrefixURI("a"));
@@ -262,7 +276,7 @@ public abstract class AbstractPrefixMapp
@Test
public void testSecondPrefixReplacesReverseMap() {
- PrefixMapping A = getMapping();
+ PrefixMapping A = getMappingProducer().newInstance();
A.setNsPrefix("a", httpURI);
A.setNsPrefix("b", httpURI);
assertEquals("b", A.getNsURIPrefix(httpURI));
@@ -270,29 +284,31 @@ public abstract class AbstractPrefixMapp
@Test
public void testRemoveNsPrefix_String() {
-
+
PrefixMapping pm = getConfiguredMapping();
-
+
pm.setNsPrefix("", "http://example.com/default");
-
+
int sz = pm.getNsPrefixMap().keySet().size();
// test removing missing entries
- assertSame( pm, pm.removeNsPrefix("nothere"));
- assertEquals( "No entries should have been removed", sz, pm.getNsPrefixMap().keySet().size());
-
+ assertSame(pm, pm.removeNsPrefix("nothere"));
+ assertEquals("No entries should have been removed", sz, pm
+ .getNsPrefixMap().keySet().size());
+
// test removing an illegal prefix does not fail
- assertSame( pm, pm.removeNsPrefix( illegalPrefixes[0] ));
- assertEquals( "No entries should have been removed", sz, pm.getNsPrefixMap().keySet().size());
-
+ assertSame(pm, pm.removeNsPrefix(illegalPrefixes[0]));
+ assertEquals("No entries should have been removed", sz, pm
+ .getNsPrefixMap().keySet().size());
+
// test removing a real entry
- assertSame( pm, pm.removeNsPrefix(urnPrefix));
+ assertSame(pm, pm.removeNsPrefix(urnPrefix));
assertEquals(null, pm.getNsPrefixURI(urnPrefix));
assertEquals(httpURI, pm.getNsPrefixURI(httpPrefix));
assertEquals("http://example.com/default", pm.getNsPrefixURI(""));
-
+
// test remove defalut
- assertSame( pm, pm.removeNsPrefix(""));
- assertEquals(null, pm.getNsPrefixURI(""));
+ assertSame(pm, pm.removeNsPrefix(""));
+ assertEquals(null, pm.getNsPrefixURI(""));
}
@Test
@@ -315,8 +331,10 @@ public abstract class AbstractPrefixMapp
}
protected void testEqualsBase(String S, String T, boolean expected) {
- testEquals(S, T, expected, getMapping(), getMapping());
- testEquals(S, T, expected, PrefixMapping.Factory.create(), getMapping());
+ testEquals(S, T, expected, getMappingProducer().newInstance(),
+ getMappingProducer().newInstance());
+ testEquals(S, T, expected, PrefixMapping.Factory.create(),
+ getMappingProducer().newInstance());
}
protected void testEquals(String S, String T, boolean expected,
@@ -340,7 +358,7 @@ public abstract class AbstractPrefixMapp
@Test
public void testLock() {
- PrefixMapping A = getMapping();
+ PrefixMapping A = getMappingProducer().newInstance();
assertSame(A, A.lock());
/* */
try {
@@ -371,86 +389,93 @@ public abstract class AbstractPrefixMapp
// expected
}
}
-
+
/**
* Verify that all items in the before map still exists in the after map.
+ *
* @param before
* @param after
*/
- private void assertNoUpdateToMap( Map<String,String> before, Map<String,String> after)
- {
- if (!after.keySet().containsAll(before.keySet()))
- {
- Set<String> diff = new HashSet<String>( before.keySet() );
- diff.removeAll( after.keySet() );
- fail( "Prefixes "+diff+" do not appear in result");
- }
- if (!after.values().containsAll(before.values()))
- {
- Set<String> diff = new HashSet<String>( before.values() );
- diff.removeAll( after.values() );
- fail( "URIs "+diff+" do not appear in result");
- }
+ private void assertNoUpdateToMap(Map<String, String> before,
+ Map<String, String> after) {
+ if (!after.keySet().containsAll(before.keySet())) {
+ Set<String> diff = new HashSet<String>(before.keySet());
+ diff.removeAll(after.keySet());
+ fail("Prefixes " + diff + " do not appear in result");
+ }
+ if (!after.values().containsAll(before.values())) {
+ Set<String> diff = new HashSet<String>(before.values());
+ diff.removeAll(after.values());
+ fail("URIs " + diff + " do not appear in result");
+ }
}
-
+
@Test
- public void testSetNsPrefix_String_String()
- {
+ public void testSetNsPrefix_String_String() {
PrefixMapping pm = getConfiguredMapping();
- Map<String,String> before = null;
+ Map<String, String> before = null;
// test invalid NCName prefix
- for (String pfx : illegalPrefixes)
- {
+ for (String pfx : illegalPrefixes) {
before = pm.getNsPrefixMap();
try {
- pm.setNsPrefix( pfx, "http://example.com/bad_prefix/");
- fail( pfx+" should have thrown PrefixMapping.IllegalPrefixException");
+ pm.setNsPrefix(pfx, "http://example.com/bad_prefix/");
+ fail(pfx
+ + " should have thrown PrefixMapping.IllegalPrefixException");
} catch (PrefixMapping.IllegalPrefixException expected) {
// expected
}
- assertNoUpdateToMap( before, pm.getNsPrefixMap());
- }
-
+ assertNoUpdateToMap(before, pm.getNsPrefixMap());
+ }
+
before = pm.getNsPrefixMap();
// test set default prefix should not change existing mapping
- assertSame( "setNsPrefix should return PrefixMap", pm, pm.setNsPrefix("", httpURI));
- assertEquals( httpURI, pm.getNsPrefixURI(""));
- assertEquals( httpURI, pm.getNsPrefixURI(httpPrefix));
- assertNoUpdateToMap( before, pm.getNsPrefixMap() );
-
- // Test that adding a new prefix mapping for U does not throw away a default
+ assertSame("setNsPrefix should return PrefixMap", pm,
+ pm.setNsPrefix("", httpURI));
+ assertEquals(httpURI, pm.getNsPrefixURI(""));
+ assertEquals(httpURI, pm.getNsPrefixURI(httpPrefix));
+ assertNoUpdateToMap(before, pm.getNsPrefixMap());
+
+ // Test that adding a new prefix mapping for U does not throw away a
+ // default
// mapping for U.
before = pm.getNsPrefixMap();
- assertSame( "setNsPrefix should return PrefixMap", pm, pm.setNsPrefix("pfx", httpURI));
- assertEquals( httpURI, pm.getNsPrefixURI(""));
- assertEquals( httpURI, pm.getNsPrefixURI("pfx"));
- assertNoUpdateToMap( before, pm.getNsPrefixMap() );
-
+ assertSame("setNsPrefix should return PrefixMap", pm,
+ pm.setNsPrefix("pfx", httpURI));
+ assertEquals(httpURI, pm.getNsPrefixURI(""));
+ assertEquals(httpURI, pm.getNsPrefixURI("pfx"));
+ assertNoUpdateToMap(before, pm.getNsPrefixMap());
+
// test valid NCName prefix
before = pm.getNsPrefixMap();
- assertSame( "setNsPrefix should return PrefixMap", pm, pm.setNsPrefix( "foo", "http://example.com/foo/"));
- assertEquals( "http://example.com/foo/", pm.getNsPrefixURI("foo"));
- assertNoUpdateToMap( before, pm.getNsPrefixMap() );
-
+ assertSame("setNsPrefix should return PrefixMap", pm,
+ pm.setNsPrefix("foo", "http://example.com/foo/"));
+ assertEquals("http://example.com/foo/", pm.getNsPrefixURI("foo"));
+ assertNoUpdateToMap(before, pm.getNsPrefixMap());
+
// test duplicate prefix is accepted
// add a second prefix for the foo url
before = pm.getNsPrefixMap();
- assertSame( "setNsPrefix should return PrefixMap", pm, pm.setNsPrefix( "foo2", "http://example.com/foo/"));
- assertEquals( pm.getNsPrefixURI("foo"), pm.getNsPrefixURI("foo2"));
- assertEquals( "Shoud not change original", "http://example.com/foo/", pm.getNsPrefixURI("foo"));
- assertNoUpdateToMap( before, pm.getNsPrefixMap() );
-
+ assertSame("setNsPrefix should return PrefixMap", pm,
+ pm.setNsPrefix("foo2", "http://example.com/foo/"));
+ assertEquals(pm.getNsPrefixURI("foo"), pm.getNsPrefixURI("foo2"));
+ assertEquals("Shoud not change original", "http://example.com/foo/",
+ pm.getNsPrefixURI("foo"));
+ assertNoUpdateToMap(before, pm.getNsPrefixMap());
+
// test new URI for old prefix overwrites old URI
- assertSame( "setNsPrefix should return PrefixMap", pm, pm.setNsPrefix( "foo2", "http://example.com/bar/"));
- assertEquals( "http://example.com/bar/", pm.getNsPrefixURI("foo2") );
- assertEquals( "Should not duplicate URI of changed", "http://example.com/foo/", pm.getNsPrefixURI("foo"));
-
+ assertSame("setNsPrefix should return PrefixMap", pm,
+ pm.setNsPrefix("foo2", "http://example.com/bar/"));
+ assertEquals("http://example.com/bar/", pm.getNsPrefixURI("foo2"));
+ assertEquals("Should not duplicate URI of changed",
+ "http://example.com/foo/", pm.getNsPrefixURI("foo"));
+
// verify that bad URIs are accepted
// they may not be silently ignored but must be accepted
before = pm.getNsPrefixMap();
- assertSame( "setNsPrefix should return PrefixMap", pm, pm.setNsPrefix( "bad", "http://example.com/foo"));
- assertNoUpdateToMap( before, pm.getNsPrefixMap() );
-
+ assertSame("setNsPrefix should return PrefixMap", pm,
+ pm.setNsPrefix("bad", "http://example.com/foo"));
+ assertNoUpdateToMap(before, pm.getNsPrefixMap());
+
// verify null URI throws exception
before = pm.getNsPrefixMap();
try {
@@ -459,6 +484,6 @@ public abstract class AbstractPrefixMapp
} catch (NullPointerException e) {
// expected
}
- assertNoUpdateToMap( before, pm.getNsPrefixMap() );
+ assertNoUpdateToMap(before, pm.getNsPrefixMap());
}
}
Modified: jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/shared/RandomOrderGraphTest.java
URL: http://svn.apache.org/viewvc/jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/shared/RandomOrderGraphTest.java?rev=1530718&r1=1530717&r2=1530718&view=diff
==============================================================================
--- jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/shared/RandomOrderGraphTest.java (original)
+++ jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/shared/RandomOrderGraphTest.java Wed Oct 9 17:16:15 2013
@@ -15,35 +15,35 @@ import com.hp.hpl.jena.graph.impl.Wrappe
import com.hp.hpl.jena.graph.impl.WrappedGraphTest;
import com.hp.hpl.jena.sparql.graph.GraphFactory;
import com.hp.hpl.jena.testing_framework.AbstractGraphProducer;
-import com.hp.hpl.jena.testing_framework.GraphProducerInterface;
public class RandomOrderGraphTest extends WrappedGraphTest {
- public RandomOrderGraphTest()
- {
- graphProducer = new AbstractGraphProducer(){
+ public RandomOrderGraphTest() {
+ graphProducer = new AbstractGraphProducer() {
@Override
protected Graph createNewGraph() {
- return new RandomOrderGraph(5,GraphFactory.createGraphMem());
- }};
+ return new RandomOrderGraph(5, GraphFactory.createGraphMem());
+ }
+ };
}
-
+
@Test
public void testRandomFindTriple() {
- Graph g = graphWithTxn( "a b 1; a b 2; a b 3; a b 4; a b 5; a b 6");
- List<Triple> l1 = g.find( new Triple( node( "a"), node("b"), Node.ANY) ).toList();
- List<Triple> l2 = g.find( new Triple( node( "a"), node("b"), Node.ANY) ).toList();
- Assert.assertNotEquals( "Lists should be different", l1, l2 );
+ Graph g = graphWithTxn("a b 1; a b 2; a b 3; a b 4; a b 5; a b 6");
+ List<Triple> l1 = g.find(new Triple(node("a"), node("b"), Node.ANY))
+ .toList();
+ List<Triple> l2 = g.find(new Triple(node("a"), node("b"), Node.ANY))
+ .toList();
+ Assert.assertNotEquals("Lists should be different", l1, l2);
}
-
+
@Test
public void testRandomFindNodes() {
- Graph g = graphWithTxn( "a b 1; a b 2; a b 3; a b 4; a b 5; a b 6");
- List<Triple> l1 = g.find( node( "a"), node("b"), Node.ANY).toList();
- List<Triple> l2 = g.find( node( "a"), node("b"), Node.ANY).toList();
- Assert.assertNotEquals( "Lists should be different", l1, l2 );
+ Graph g = graphWithTxn("a b 1; a b 2; a b 3; a b 4; a b 5; a b 6");
+ List<Triple> l1 = g.find(node("a"), node("b"), Node.ANY).toList();
+ List<Triple> l2 = g.find(node("a"), node("b"), Node.ANY).toList();
+ Assert.assertNotEquals("Lists should be different", l1, l2);
}
-
}
Modified: jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/shared/impl/PrefixMappingTest.java
URL: http://svn.apache.org/viewvc/jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/shared/impl/PrefixMappingTest.java?rev=1530718&r1=1530717&r2=1530718&view=diff
==============================================================================
--- jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/shared/impl/PrefixMappingTest.java (original)
+++ jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/shared/impl/PrefixMappingTest.java Wed Oct 9 17:16:15 2013
@@ -18,14 +18,17 @@
package com.hp.hpl.jena.shared.impl;
-
import static org.junit.Assert.*;
import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.xenei.junit.contract.Contract;
+import org.xenei.junit.contract.ContractImpl;
+import org.xenei.junit.contract.ContractSuite;
-import com.hp.hpl.jena.assembler.JA ;
-import com.hp.hpl.jena.shared.AbstractPrefixMappingTest;
+import com.hp.hpl.jena.assembler.JA;
import com.hp.hpl.jena.shared.PrefixMapping;
-import com.hp.hpl.jena.shared.impl.PrefixMappingImpl ;
+import com.hp.hpl.jena.shared.impl.PrefixMappingImpl;
+import org.xenei.junit.contract.IProducer;
import com.hp.hpl.jena.vocabulary.DC_11;
import com.hp.hpl.jena.vocabulary.OWL;
import com.hp.hpl.jena.vocabulary.RDF;
@@ -33,41 +36,54 @@ import com.hp.hpl.jena.vocabulary.RDFS;
import com.hp.hpl.jena.vocabulary.RSS;
import com.hp.hpl.jena.vocabulary.VCARD;
-
/**
- Tests PrefixMappingImpl by subclassing AbstractTestPrefixMapping, qv.
-*/
+ * Tests PrefixMappingImpl by subclassing AbstractTestPrefixMapping, qv.
+ */
-public class PrefixMappingTest extends AbstractPrefixMappingTest
- {
-
- @Override
- protected PrefixMapping getMapping()
- { return new PrefixMappingImpl(); }
-
- @Test
- public void testStandard()
- { testStandard( PrefixMapping.Standard ); }
-
- @Test
- public void testExtended()
- { testExtended( PrefixMapping.Extended ); }
-
- private void testStandard( PrefixMapping st )
- {
- assertEquals( RDF.getURI(), st.getNsPrefixURI( "rdf" ) );
- assertEquals( RDFS.getURI(), st.getNsPrefixURI( "rdfs" ) );
- assertEquals( DC_11.getURI(), st.getNsPrefixURI( "dc" ) );
- assertEquals( OWL.getURI(), st.getNsPrefixURI( "owl" ) );
- }
-
- private void testExtended( PrefixMapping st )
- {
- testStandard( st );
- assertEquals( RSS.getURI(), st.getNsPrefixURI( "rss" ) );
- assertEquals( VCARD.getURI(), st.getNsPrefixURI( "vcard" ) );
- assertEquals( JA.getURI(), st.getNsPrefixURI( "ja" ) );
- assertEquals( "http://www.example.org/", st.getNsPrefixURI( "eg" ) );
- }
+@RunWith(ContractSuite.class)
+@ContractImpl(PrefixMappingImpl.class)
+public class PrefixMappingTest {
+ private IProducer<PrefixMappingImpl> producer = new IProducer<PrefixMappingImpl>() {
+
+ @Override
+ public PrefixMappingImpl newInstance() {
+ return new PrefixMappingImpl();
+ }
+
+ @Override
+ public void cleanUp() {
+ // do not do anything
+ }
+ };
+
+ @Contract.Inject( "org.xenei.junit.contract.IProducer<%s>" )
+ public IProducer<PrefixMappingImpl> getMappingProducer() {
+ return producer;
+ }
+
+ @Test
+ public void testStandard() {
+ testStandard(PrefixMapping.Standard);
+ }
+
+ @Test
+ public void testExtended() {
+ testExtended(PrefixMapping.Extended);
+ }
+
+ private void testStandard(PrefixMapping st) {
+ assertEquals(RDF.getURI(), st.getNsPrefixURI("rdf"));
+ assertEquals(RDFS.getURI(), st.getNsPrefixURI("rdfs"));
+ assertEquals(DC_11.getURI(), st.getNsPrefixURI("dc"));
+ assertEquals(OWL.getURI(), st.getNsPrefixURI("owl"));
+ }
+
+ private void testExtended(PrefixMapping st) {
+ testStandard(st);
+ assertEquals(RSS.getURI(), st.getNsPrefixURI("rss"));
+ assertEquals(VCARD.getURI(), st.getNsPrefixURI("vcard"));
+ assertEquals(JA.getURI(), st.getNsPrefixURI("ja"));
+ assertEquals("http://www.example.org/", st.getNsPrefixURI("eg"));
+ }
- }
+}
Modified: jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/shared/package-info.java
URL: http://svn.apache.org/viewvc/jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/shared/package-info.java?rev=1530718&r1=1530717&r2=1530718&view=diff
==============================================================================
--- jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/shared/package-info.java (original)
+++ jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/shared/package-info.java Wed Oct 9 17:16:15 2013
@@ -16,6 +16,7 @@
limitations under the License.
*/
package com.hp.hpl.jena.shared;
+
// TODO move wg subdir to testing classes
// TODO write tests for uuid subdir
/**
Modified: jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/testing_framework/AbstractGraphProducer.java
URL: http://svn.apache.org/viewvc/jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/testing_framework/AbstractGraphProducer.java?rev=1530718&r1=1530717&r2=1530718&view=diff
==============================================================================
--- jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/testing_framework/AbstractGraphProducer.java (original)
+++ jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/testing_framework/AbstractGraphProducer.java Wed Oct 9 17:16:15 2013
@@ -20,6 +20,9 @@ package com.hp.hpl.jena.testing_framewor
import java.util.ArrayList;
import java.util.List;
+import org.xenei.junit.contract.IProducer;
+
+
import com.hp.hpl.jena.graph.Graph;
/**
@@ -30,7 +33,8 @@ import com.hp.hpl.jena.graph.Graph;
* the graph is closed.
*
*/
-public abstract class AbstractGraphProducer implements GraphProducerInterface {
+public abstract class AbstractGraphProducer<T extends Graph> implements
+ IProducer<T> {
/**
* The list of graphs that have been opened in this test.
@@ -42,11 +46,11 @@ public abstract class AbstractGraphProdu
*
* @return a newly constructed graph of type under test.
*/
- abstract protected Graph createNewGraph();
+ abstract protected T createNewGraph();
@Override
- final public Graph newGraph() {
- Graph retval = createNewGraph();
+ final public T newInstance() {
+ T retval = createNewGraph();
graphList.add(retval);
return retval;
}
@@ -66,7 +70,7 @@ public abstract class AbstractGraphProdu
};
@Override
- final public void closeGraphs() {
+ final public void cleanUp() {
for (Graph g : graphList) {
if (!g.isClosed()) {
g.close();
Modified: jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/testing_framework/AbstractModelProducer.java
URL: http://svn.apache.org/viewvc/jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/testing_framework/AbstractModelProducer.java?rev=1530718&r1=1530717&r2=1530718&view=diff
==============================================================================
--- jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/testing_framework/AbstractModelProducer.java (original)
+++ jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/testing_framework/AbstractModelProducer.java Wed Oct 9 17:16:15 2013
@@ -20,6 +20,9 @@ package com.hp.hpl.jena.testing_framewor
import java.util.ArrayList;
import java.util.List;
+import org.xenei.junit.contract.IProducer;
+
+
import com.hp.hpl.jena.rdf.model.Model;
/**
@@ -30,7 +33,8 @@ import com.hp.hpl.jena.rdf.model.Model;
* the model is closed.
*
*/
-public abstract class AbstractModelProducer implements ModelProducerInterface {
+public abstract class AbstractModelProducer<T extends Model> implements
+ IProducer<T> {
/**
* The list of graphs that have been opened in this test.
@@ -38,15 +42,23 @@ public abstract class AbstractModelProdu
protected List<Model> modelList = new ArrayList<Model>();
/**
+ * @return true if the models returned by this poducer are independent,
+ * false otherwise.
+ *
+ */
+ abstract public boolean areIndependent();
+
+ /**
* The method to create a new model.
*
* @return a newly constructed model of type under test.
*/
- abstract protected Model createNewModel();
+ abstract protected T createNewModel();
+ @SuppressWarnings("unchecked")
@Override
- final public Model newModel() {
- Model retval = createNewModel();
+ final public T newInstance() {
+ T retval = createNewModel();
modelList.add(retval);
return retval;
}
@@ -66,7 +78,7 @@ public abstract class AbstractModelProdu
};
@Override
- final public void closeModels() {
+ final public void cleanUp() {
for (Model m : modelList) {
if (!m.isClosed()) {
m.close();
Added: jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/testing_framework/AbstractRecordingListener.java
URL: http://svn.apache.org/viewvc/jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/testing_framework/AbstractRecordingListener.java?rev=1530718&view=auto
==============================================================================
--- jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/testing_framework/AbstractRecordingListener.java (added)
+++ jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/testing_framework/AbstractRecordingListener.java Wed Oct 9 17:16:15 2013
@@ -0,0 +1,190 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.hp.hpl.jena.testing_framework;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+
+import org.junit.Assert;
+
+import com.hp.hpl.jena.rdf.model.Model;
+import com.hp.hpl.jena.rdf.model.Statement;
+
+/**
+ * This testing listener records the event names and data, and provides a method
+ * for comparing the actual with the expected history.
+ */
+public class AbstractRecordingListener {
+
+ @SuppressWarnings("unchecked")
+ public static boolean checkEquality(final Object o1, final Object o2) {
+ if (o1 == o2) {
+ return true;
+ }
+ if (o1.getClass().isArray() && o2.getClass().isArray()) {
+ final Object[] o1a = (Object[]) o1;
+ final Object[] o2a = (Object[]) o2;
+
+ if (o1a.length == o2a.length) {
+ for (int i = 0; i < o1a.length; i++) {
+ if (!checkEquality(o1a[i], o2a[i])) {
+ return false;
+ }
+ }
+ return true;
+ }
+ return false;
+ } else if ((o1 instanceof Collection<?>)
+ && (o2 instanceof Collection<?>)) {
+ return checkEquality(((Collection<Object>) o1).toArray(),
+ ((Collection<Object>) o2).toArray());
+
+ } else if ((o1 instanceof Model) && (o2 instanceof Model)) {
+ return checkEquality(((Model) o1).listStatements().toList(),
+ ((Model) o2).listStatements().toList());
+
+ } else if ((o1 instanceof Statement) && (o2 instanceof Statement)) {
+ return checkEquality(((Statement) o1).asTriple(),
+ ((Statement) o2).asTriple());
+
+ } else {
+ return o1.equals(o2);
+ }
+ }
+
+ private List<Object> history = new ArrayList<Object>();
+
+ protected final void record(String tag, Object x, Object y) {
+ history.add(tag);
+ history.add(x);
+ history.add(y);
+ }
+
+ protected final void record(String tag, Object info) {
+ history.add(tag);
+ history.add(info);
+ }
+
+ public final int differ(Object... things) {
+ for (int i = 0; i < history.size(); i++) {
+ if (!things[i].equals(history.get(i))) {
+ return i;
+ }
+ }
+ return -1;
+ }
+
+ public final boolean has(Object... things) {
+ return history.equals(Arrays.asList(things));
+ }
+
+ public final void assertHas(Object... things) {
+ if (has(things) == false) {
+ int idx = differ(things);
+ Assert.fail("expected " + Arrays.asList(things) + " but got "
+ + history + " differ at position " + idx);
+ }
+ }
+
+ public final void assertEmpty() {
+ if (history.size() > 0) {
+ Assert.fail("Should be no history but got " + history);
+ }
+ }
+
+ public final int size() {
+ return history.size();
+ }
+
+ public final boolean has(List<?> things) {
+ return history.equals(things);
+ }
+
+ public final boolean hasStart(List<Object> L) {
+ return L.size() <= history.size()
+ && L.equals(history.subList(0, L.size()));
+ }
+
+ public final boolean hasEnd(List<Object> L) {
+ return L.size() <= history.size()
+ && L.equals(history.subList(history.size() - L.size(),
+ history.size()));
+ }
+
+ public final void assertHas(List<?> things) {
+ if (has(things) == false)
+ Assert.fail("expected " + things + " but got " + history);
+ }
+
+ public final void assertContains(Object... things) {
+ if (contains(things) == false)
+ Assert.fail(String.format("expected %s but got %s",
+ Arrays.asList(things), history));
+ }
+
+ public final void assertHasStart(Object... start) {
+ List<Object> L = Arrays.asList(start);
+ if (hasStart(L) == false)
+ Assert.fail("expected " + L + " at the beginning of " + history);
+ }
+
+ public final void assertHasEnd(Object... end) {
+ List<Object> L = Arrays.asList(end);
+ if (hasEnd(L) == false)
+ Assert.fail("expected " + L + " at the end of " + history);
+ }
+
+ public final void clear() {
+ history.clear();
+ }
+
+ public final boolean contains(Object... objects) {
+ for (int i = 0; i < history.size(); i++) {
+ if (history.get(i).equals(objects[0])) {
+ boolean found = true;
+ for (int j = 1; j < objects.length; j++) {
+ if (i + j >= history.size()) {
+ found = false;
+ break;
+ }
+ if (!history.get(i + j).equals(objects[j])) {
+ found = false;
+ break;
+ }
+ }
+ if (found) {
+ return true;
+ }
+ }
+
+ }
+ return false;
+
+ }
+
+ public final Iterator<Object> from(Object start) {
+ Iterator<Object> iter = history.iterator();
+ while (iter.hasNext() && !iter.next().equals(start))
+ ; // loop
+ return iter;
+ }
+}
Propchange: jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/testing_framework/AbstractRecordingListener.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/testing_framework/GraphHelper.java
URL: http://svn.apache.org/viewvc/jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/testing_framework/GraphHelper.java?rev=1530718&r1=1530717&r2=1530718&view=diff
==============================================================================
--- jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/testing_framework/GraphHelper.java (original)
+++ jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/testing_framework/GraphHelper.java Wed Oct 9 17:16:15 2013
@@ -23,6 +23,7 @@ package com.hp.hpl.jena.testing_framewor
*/
import static org.junit.Assert.*;
+
import java.lang.reflect.Constructor;
import java.util.ArrayList;
import java.util.Arrays;
@@ -33,6 +34,9 @@ import java.util.Map;
import java.util.Set;
import java.util.StringTokenizer;
+import org.xenei.junit.contract.IProducer;
+
+
import com.hp.hpl.jena.graph.Factory;
import com.hp.hpl.jena.graph.Graph;
import com.hp.hpl.jena.graph.GraphUtil;
@@ -197,13 +201,13 @@ public class GraphHelper extends TestUti
* @return The populated graph
*/
public static Graph graphWith(Graph g, String s) {
- return graphAdd(g, s);
+ return graphAddTxn(g, s);
}
/**
* Answer a new memory-based graph with Extended prefixes.
*/
- private static Graph newGraph() {
+ public static Graph memGraph() {
Graph result = Factory.createGraphMem();
result.getPrefixMapping().setNsPrefixes(PrefixMapping.Extended);
return result;
@@ -215,7 +219,7 @@ public class GraphHelper extends TestUti
* over-ridable; do not use for abstraction.
*/
public static Graph graphWith(String s) {
- return graphWith(newGraph(), s);
+ return graphWith(memGraph(), s);
}
/**
@@ -290,6 +294,19 @@ public class GraphHelper extends TestUti
b.append(nice(n));
}
+ protected static Graph graphWithTxn(IProducer<Graph> producer, String s) {
+ Graph g = producer.newInstance();
+ txnBegin(g);
+ try {
+ graphAdd(g, s);
+ txnCommit(g);
+ } catch (Exception e) {
+ txnRollback(g);
+ fail(e.getMessage());
+ }
+ return g;
+ }
+
/**
* Answer the "nice" representation of this node, the string returned by
* <code>n.toString(PrefixMapping.Extended,true)</code>.
Modified: jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/testing_framework/GraphProducerInterface.java
URL: http://svn.apache.org/viewvc/jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/testing_framework/GraphProducerInterface.java?rev=1530718&r1=1530717&r2=1530718&view=diff
==============================================================================
--- jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/testing_framework/GraphProducerInterface.java (original)
+++ jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/testing_framework/GraphProducerInterface.java Wed Oct 9 17:16:15 2013
@@ -17,27 +17,25 @@
*/
package com.hp.hpl.jena.testing_framework;
-import com.hp.hpl.jena.graph.Graph;
-
/**
* Creates the graph for testing. Implementations must track the creation of
* graphs created with newGraph and close them when closeGraphs is called.
*
*/
-public interface GraphProducerInterface {
-
- /**
- * Returns a new Graph to take part in the test.
- *
- * @return The graph implementation to test.
- */
- public abstract Graph newGraph();
-
- /**
- * provides a hook to close down graphs. When called all graphs created by
- * the newGraph() method should be closed. Note that some graphs may have
- * been closed during the test, so graphs should be tested for being closed
- * prior to closing.
- */
- public abstract void closeGraphs();
-}
+//public interface GraphProducerInterface<T> {
+//
+// /**
+// * Returns a new Graph to take part in the test.
+// *
+// * @return The graph implementation to test.
+// */
+// public abstract Graph newGraph();
+//
+// /**
+// * provides a hook to close down graphs. When called all graphs created by
+// * the newGraph() method should be closed. Note that some graphs may have
+// * been closed during the test, so graphs should be tested for being closed
+// * prior to closing.
+// */
+// public abstract void closeGraphs();
+// }
Added: jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/testing_framework/IContainerProducer.java
URL: http://svn.apache.org/viewvc/jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/testing_framework/IContainerProducer.java?rev=1530718&view=auto
==============================================================================
--- jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/testing_framework/IContainerProducer.java (added)
+++ jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/testing_framework/IContainerProducer.java Wed Oct 9 17:16:15 2013
@@ -0,0 +1,19 @@
+package com.hp.hpl.jena.testing_framework;
+
+import com.hp.hpl.jena.rdf.model.Container;
+import com.hp.hpl.jena.rdf.model.Resource;
+
+public interface IContainerProducer<T extends Container> extends
+ INodeProducer<T> {
+
+ /**
+ * The Resource identifying the continer type. e.g. RDF.seq
+ */
+ Resource getContainerType();
+
+ /**
+ * The class of the continaer. e.g. Seq.class
+ */
+ Class<? extends Container> getContainerClass();
+
+}
Propchange: jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/testing_framework/IContainerProducer.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/testing_framework/INodeProducer.java
URL: http://svn.apache.org/viewvc/jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/testing_framework/INodeProducer.java?rev=1530718&view=auto
==============================================================================
--- jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/testing_framework/INodeProducer.java (added)
+++ jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/testing_framework/INodeProducer.java Wed Oct 9 17:16:15 2013
@@ -0,0 +1,40 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ */
+package com.hp.hpl.jena.testing_framework;
+
+
+import org.xenei.junit.contract.IProducer;
+
+import com.hp.hpl.jena.rdf.model.Model;
+import com.hp.hpl.jena.rdf.model.RDFNode;
+
+/**
+ * An abstract implementation of the IProducer<RDFNode> interface.
+ *
+ * This class handles tracking of the created graphs and closing them. It also
+ * provides a callback for the implementing class to perform extra cleanup when
+ * the graph is closed.
+ *
+ */
+public interface INodeProducer<T extends RDFNode> extends IProducer<T> {
+
+ abstract public T newInstance(String uri);
+
+ abstract public Model getModel();
+
+}
Propchange: jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/testing_framework/INodeProducer.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/testing_framework/IStatementProducer.java
URL: http://svn.apache.org/viewvc/jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/testing_framework/IStatementProducer.java?rev=1530718&view=auto
==============================================================================
--- jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/testing_framework/IStatementProducer.java (added)
+++ jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/testing_framework/IStatementProducer.java Wed Oct 9 17:16:15 2013
@@ -0,0 +1,45 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ */
+package com.hp.hpl.jena.testing_framework;
+
+import com.hp.hpl.jena.rdf.model.Model;
+import com.hp.hpl.jena.rdf.model.Property;
+import com.hp.hpl.jena.rdf.model.RDFNode;
+import com.hp.hpl.jena.rdf.model.Resource;
+import com.hp.hpl.jena.rdf.model.Statement;
+
+/**
+ * An abstract implementation of the IProducer<RDFNode> interface.
+ *
+ * This class handles tracking of the created graphs and closing them. It also
+ * provides a callback for the implementing class to perform extra cleanup when
+ * the graph is closed.
+ *
+ */
+public interface IStatementProducer<T extends Statement> {
+
+ abstract public T newInstance(String fact);
+
+ abstract public T newInstance(Resource s, Property p, RDFNode o);
+
+ abstract public Model getModel();
+
+ abstract public void cleanUp();
+
+ abstract public AbstractModelProducer<Model> getModelProducer();
+}
Propchange: jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/testing_framework/IStatementProducer.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Copied: jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/testing_framework/ITripleStoreProducer.java (from r1520788, jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/testing_framework/TripleStoreProducerInterface.java)
URL: http://svn.apache.org/viewvc/jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/testing_framework/ITripleStoreProducer.java?p2=jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/testing_framework/ITripleStoreProducer.java&p1=jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/testing_framework/TripleStoreProducerInterface.java&r1=1520788&r2=1530718&rev=1530718&view=diff
==============================================================================
--- jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/testing_framework/TripleStoreProducerInterface.java (original)
+++ jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/testing_framework/ITripleStoreProducer.java Wed Oct 9 17:16:15 2013
@@ -23,7 +23,7 @@ import com.hp.hpl.jena.graph.impl.Triple
* Creates the graph for testing
*
*/
-public interface TripleStoreProducerInterface {
+public interface ITripleStoreProducer {
/**
* Returns a TripleStore to take part in the test. Must be overridden in a
Modified: jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/testing_framework/ModelHelper.java
URL: http://svn.apache.org/viewvc/jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/testing_framework/ModelHelper.java?rev=1530718&r1=1530717&r2=1530718&view=diff
==============================================================================
--- jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/testing_framework/ModelHelper.java (original)
+++ jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/testing_framework/ModelHelper.java Wed Oct 9 17:16:15 2013
@@ -18,7 +18,6 @@
package com.hp.hpl.jena.testing_framework;
-import com.hp.hpl.jena.graph.Graph;
import com.hp.hpl.jena.graph.Node;
import com.hp.hpl.jena.rdf.model.Literal;
import com.hp.hpl.jena.rdf.model.Model;
@@ -32,9 +31,6 @@ import com.hp.hpl.jena.rdf.model.StmtIte
import com.hp.hpl.jena.shared.PrefixMapping;
import com.hp.hpl.jena.util.CollectionFactory;
-import static com.hp.hpl.jena.testing_framework.ModelHelper.modelAdd;
-import static com.hp.hpl.jena.testing_framework.ModelHelper.txnBegin;
-import static com.hp.hpl.jena.testing_framework.ModelHelper.txnCommit;
import static org.junit.Assert.*;
import java.util.ArrayList;
import java.util.HashSet;
@@ -43,6 +39,7 @@ import java.util.Set;
import java.util.StringTokenizer;
import org.junit.Assert;
+import org.xenei.junit.contract.IProducer;
/**
* provides useful functionality for testing models, eg building small models
@@ -53,17 +50,16 @@ import org.junit.Assert;
public class ModelHelper extends GraphHelper {
private static Model builderModel;
- // protected static Model aModel;
- static {
- builderModel = ModelFactory.createDefaultModel();
- builderModel.setNsPrefixes( PrefixMapping.Extended );
- }
+ static {
+ builderModel = ModelFactory.createDefaultModel();
+ builderModel.setNsPrefixes(PrefixMapping.Extended);
+ }
protected static final Model empty = ModelFactory.createDefaultModel();
- protected static Model extendedModel(AbstractModelProducer producer) {
- Model result = producer.newModel();
+ protected static Model extendedModel(IProducer<Model> producer) {
+ Model result = producer.newInstance();
result.setNsPrefixes(PrefixMapping.Extended);
return result;
}
@@ -72,26 +68,24 @@ public class ModelHelper extends GraphHe
return nice(n.asNode());
}
- public static Statement statement( String fact )
- {
+ public static Statement statement(String fact) {
StringTokenizer st = new StringTokenizer(fact);
- Resource sub = resource( st.nextToken());
- Property pred = property( st.nextToken());
- RDFNode obj = rdfNode( st.nextToken());
+ Resource sub = resource(st.nextToken());
+ Property pred = property(st.nextToken());
+ RDFNode obj = rdfNode(st.nextToken());
return builderModel.createStatement(sub, pred, obj);
}
-
- public static Statement statement( Resource s, Property p, RDFNode o )
- {
+
+ public static Statement statement(Resource s, Property p, RDFNode o) {
return builderModel.createStatement(s, p, o);
}
-
+
public static RDFNode rdfNode(Model m, String s) {
return m.asRDFNode(NodeCreateUtils.create(s));
}
public static RDFNode rdfNode(String s) {
- return rdfNode( builderModel, s );
+ return rdfNode(builderModel, s);
}
public static <T extends RDFNode> T rdfNode(String s, Class<T> c) {
@@ -102,46 +96,47 @@ public class ModelHelper extends GraphHe
return ResourceFactory.createResource();
}
- public static Resource resource( String s )
- { return (Resource) rdfNode(s); }
+ public static Resource resource(String s) {
+ return (Resource) rdfNode(s);
+ }
-// public static Resource resource(Model m, String s) {
-// return (Resource) rdfNode(m, s);
-// }
+ // public static Resource resource(Model m, String s) {
+ // return (Resource) rdfNode(m, s);
+ // }
- public static Property property( String s )
- { return rdfNode(s).as(Property.class); }
+ public static Property property(String s) {
+ return rdfNode(s).as(Property.class);
+ }
public static Property property(Model m, String s) {
return rdfNode(m, s).as(Property.class);
}
- public static Literal literal(String s, String lang)
- {
+ public static Literal literal(String s, String lang) {
return builderModel.createLiteral(s, lang);
}
-
+
public static Literal literal(String s) {
return rdfNode(s).as(Literal.class);
}
-// /**
-// * Create an array of Statements parsed from a semi-separated string.
-// *
-// * @param lockModel
-// * a model to serve as a statement factory
-// * @param facts
-// * a sequence of semicolon-separated "S P O" facts
-// * @return a Statement[] of the (S P O) statements from the string
-// */
-// public static Statement[] statements(Model m, String facts) {
-// ArrayList<Statement> sl = new ArrayList<Statement>();
-// StringTokenizer st = new StringTokenizer(facts, ";");
-// while (st.hasMoreTokens())
-// sl.add(statement(m, st.nextToken()));
-// return sl.toArray(new Statement[sl.size()]);
-// }
-
+ // /**
+ // * Create an array of Statements parsed from a semi-separated string.
+ // *
+ // * @param lockModel
+ // * a model to serve as a statement factory
+ // * @param facts
+ // * a sequence of semicolon-separated "S P O" facts
+ // * @return a Statement[] of the (S P O) statements from the string
+ // */
+ // public static Statement[] statements(Model m, String facts) {
+ // ArrayList<Statement> sl = new ArrayList<Statement>();
+ // StringTokenizer st = new StringTokenizer(facts, ";");
+ // while (st.hasMoreTokens())
+ // sl.add(statement(m, st.nextToken()));
+ // return sl.toArray(new Statement[sl.size()]);
+ // }
+
/**
* Create an array of Statements parsed from a semi-separated string.
*
@@ -166,7 +161,7 @@ public class ModelHelper extends GraphHe
* a whitespace-separated sequence to feed to resource
* @return a Resource[] of the parsed resources
*/
- public static Resource[] resources( String items) {
+ public static Resource[] resources(String items) {
ArrayList<Resource> rl = new ArrayList<Resource>();
StringTokenizer st = new StringTokenizer(items);
while (st.hasMoreTokens())
@@ -179,13 +174,13 @@ public class ModelHelper extends GraphHe
* <code>items</code> string. Each resource specification is interpreted as
* per <code>resource</code>.
*/
- public static Set<Resource> resourceSet( String items )
- {
- Set<Resource> result = new HashSet<Resource>();
- StringTokenizer st = new StringTokenizer( items );
- while (st.hasMoreTokens()) result.add( resource( st.nextToken() ) );
- return result;
- }
+ public static Set<Resource> resourceSet(String items) {
+ Set<Resource> result = new HashSet<Resource>();
+ StringTokenizer st = new StringTokenizer(items);
+ while (st.hasMoreTokens())
+ result.add(resource(st.nextToken()));
+ return result;
+ }
/**
* add to a model all the statements expressed by a string.
@@ -200,34 +195,34 @@ public class ModelHelper extends GraphHe
*/
public static Model modelAdd(Model m, String facts) {
StringTokenizer semis = new StringTokenizer(facts, ";");
-
+
while (semis.hasMoreTokens()) {
StringTokenizer st = new StringTokenizer(semis.nextToken());
- Resource sub = resource( st.nextToken());
- Property pred = property( st.nextToken());
- RDFNode obj = rdfNode( st.nextToken());
- m.add(sub,pred,obj);
+ Resource sub = resource(st.nextToken());
+ Property pred = property(st.nextToken());
+ RDFNode obj = rdfNode(st.nextToken());
+ m.add(sub, pred, obj);
}
-
+
return m;
}
-
+
/**
- * create a memory based model with extended prefixes and initialises it with statements
- * parsed from a string.
+ * create a memory based model with extended prefixes and initialises it
+ * with statements parsed from a string.
*
* does all insertions in a transaction.
*
* @param facts
* @return
*/
- public static Model memModel( String facts ) {
+ public static Model memModel(String facts) {
Model model = ModelFactory.createMemModelMaker().createFreshModel();
model.setNsPrefixes(PrefixMapping.Extended);
- txnBegin( model );
- modelAdd(model, facts);
- txnCommit( model );
- return model;
+ txnBegin(model);
+ modelAdd(model, facts);
+ txnCommit(model);
+ return model;
}
/**
@@ -240,15 +235,15 @@ public class ModelHelper extends GraphHe
* a string in semicolon-separated "S P O" format
* @return a model containing those facts
*/
- public static Model modelWithStatements(ModelProducerInterface producer,
+ public static Model modelWithStatements(IProducer<Model> producer,
String facts) {
Model m = createModel(producer);
- txnBegin( m );
- modelAdd( m, facts );
- txnCommit( m );
+ txnBegin(m);
+ modelAdd(m, facts);
+ txnCommit(m);
return m;
}
-
+
/**
* Creates a model with extended prefixes and initialises it with statements
* parsed from the statement iterator.
@@ -259,23 +254,22 @@ public class ModelHelper extends GraphHe
* a string in semicolon-separated "S P O" format
* @return a model containing those facts
*/
- public static Model modelWithStatements( ModelProducerInterface producer, final StmtIterator it )
- {
+ public static Model modelWithStatements(IProducer<Model> producer,
+ final StmtIterator it) {
Model m = createModel(producer);
- txnBegin( m );
- while (it.hasNext())
- {
+ txnBegin(m);
+ while (it.hasNext()) {
m.add(it.nextStatement());
}
- txnCommit( m );
+ txnCommit(m);
return m;
}
/**
* make a model and give it Extended prefixes
*/
- public static Model createModel(ModelProducerInterface producer) {
- Model result = producer.newModel();
+ public static Model createModel(IProducer<Model> producer) {
+ Model result = producer.newInstance();
result.setNsPrefixes(PrefixMapping.Extended);
return result;
}
@@ -370,13 +364,12 @@ public class ModelHelper extends GraphHe
public String toString() {
return "[" + Long.toString(content) + "]";
}
-
- public long getContent()
- {
+
+ public long getContent() {
return content;
}
}
-
+
/**
* Begin a transaction on the model if transactions are supported.
*
Modified: jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/testing_framework/NodeProducerInterface.java
URL: http://svn.apache.org/viewvc/jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/testing_framework/NodeProducerInterface.java?rev=1530718&r1=1530717&r2=1530718&view=diff
==============================================================================
--- jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/testing_framework/NodeProducerInterface.java (original)
+++ jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/testing_framework/NodeProducerInterface.java Wed Oct 9 17:16:15 2013
@@ -17,20 +17,16 @@
*/
package com.hp.hpl.jena.testing_framework;
-import com.hp.hpl.jena.rdf.model.Model;
-import com.hp.hpl.jena.rdf.model.RDFNode;
-import com.hp.hpl.jena.rdf.model.Resource;
-
/**
* Creates the graph for testing. Implementations must track the creation of
* graphs created with newGraph and close them when closeGraphs is called.
*
*/
-public interface NodeProducerInterface {
-
- /**
- * Returns a new anonymous RDFNode in an model.
- */
- public abstract RDFNode newRDFNode();
-
-}
+//public interface NodeProducerInterface {
+//
+// /**
+// * Returns a new anonymous RDFNode in an model.
+// */
+// public abstract RDFNode newRDFNode();
+//
+// }
Modified: jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/testing_framework/TestFileData.java
URL: http://svn.apache.org/viewvc/jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/testing_framework/TestFileData.java?rev=1530718&r1=1530717&r2=1530718&view=diff
==============================================================================
--- jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/testing_framework/TestFileData.java (original)
+++ jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/testing_framework/TestFileData.java Wed Oct 9 17:16:15 2013
@@ -12,194 +12,168 @@ import static org.junit.Assert.assertTru
import org.junit.Test;
import com.hp.hpl.jena.graph.Graph;
-import com.hp.hpl.jena.graph.Node;
import com.hp.hpl.jena.graph.NodeFactory;
import com.hp.hpl.jena.graph.Triple;
import com.hp.hpl.jena.rdf.model.AnonId;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;
-import com.hp.hpl.jena.rdf.model.Statement;
import com.hp.hpl.jena.sparql.graph.GraphFactory;
-
/**
- * Class that produces RDF and TTL data, a Graph and a Model that all contain the same data.
- * This is used for various tests where files are read/written
- *
+ * Class that produces RDF and TTL data, a Graph and a Model that all contain
+ * the same data. This is used for various tests where files are read/written
+ *
*/
public class TestFileData {
- private static String ttlStr()
- {
+ private static String ttlStr() {
String[] lines = {
- "<http://example.com/subject> <http://example.com/predicate> <http://example.com/object> .",
- "<e> <p5> 'verify base works' ."
- };
- return toDataString( lines );
- }
-
- private static String rdfStr()
- {
+ "<http://example.com/subject> <http://example.com/predicate> <http://example.com/object> .",
+ "<e> <p5> 'verify base works' ." };
+ return toDataString(lines);
+ }
+
+ private static String rdfStr() {
String[] lines = {
- "<rdf:RDF",
- " xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"",
- " xmlns:ex=\"http://example.com/\">",
- " <rdf:Description rdf:about=\"http://example.com/subject\">",
- " <ex:predicate rdf:resource=\"http://example.com/object\"/>",
- " </rdf:Description>",
- " <rdf:Description rdf:about=\"e\">",
- " <ex:p5>verify base works</ex:p5>",
- " </rdf:Description>",
- "</rdf:RDF>"
- };
- return toDataString( lines );
- }
-
- private static String toDataString( String[] lines )
- {
+ "<rdf:RDF",
+ " xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"",
+ " xmlns:ex=\"http://example.com/\">",
+ " <rdf:Description rdf:about=\"http://example.com/subject\">",
+ " <ex:predicate rdf:resource=\"http://example.com/object\"/>",
+ " </rdf:Description>", " <rdf:Description rdf:about=\"e\">",
+ " <ex:p5>verify base works</ex:p5>", " </rdf:Description>",
+ "</rdf:RDF>" };
+ return toDataString(lines);
+ }
+
+ private static String toDataString(String[] lines) {
String eol = System.getProperty("line.separator");
StringBuilder sb = new StringBuilder();
- for (String l : lines)
- {
- sb.append( l ).append(eol);
+ for (String l : lines) {
+ sb.append(l).append(eol);
}
return sb.toString();
}
-
- public static Graph getGraph()
- {
+
+ public static Graph getGraph() {
Graph g = GraphFactory.createGraphMem();
-
- g.add( new Triple( NodeFactory.createURI( "http://example.com/subject"),
- NodeFactory.createURI( "http://example.com/predicate"),
- NodeFactory.createURI( "http://example.com/object")
- ) );
-
- g.add( new Triple( NodeFactory.createAnon( AnonId.create("a")),
- NodeFactory.createURI( "http://example.com/p1"),
- NodeFactory.createAnon( AnonId.create("b"))
- ) );
-
- g.add( new Triple( NodeFactory.createAnon( AnonId.create("b")),
- NodeFactory.createURI( "http://example.com/p2"),
- NodeFactory.createLiteral( "foo" )
- ) );
-
- g.add( new Triple( NodeFactory.createURI( "http://example.com/ns/e"),
- NodeFactory.createURI( "http://example.com/ns/p5"),
- NodeFactory.createLiteral( "verify base works")
- ) );
-
+
+ g.add(new Triple(NodeFactory.createURI("http://example.com/subject"),
+ NodeFactory.createURI("http://example.com/predicate"),
+ NodeFactory.createURI("http://example.com/object")));
+
+ g.add(new Triple(NodeFactory.createAnon(AnonId.create("a")),
+ NodeFactory.createURI("http://example.com/p1"), NodeFactory
+ .createAnon(AnonId.create("b"))));
+
+ g.add(new Triple(NodeFactory.createAnon(AnonId.create("b")),
+ NodeFactory.createURI("http://example.com/p2"), NodeFactory
+ .createLiteral("foo")));
+
+ g.add(new Triple(NodeFactory.createURI("http://example.com/ns/e"),
+ NodeFactory.createURI("http://example.com/ns/p5"), NodeFactory
+ .createLiteral("verify base works")));
+
return g;
}
-
- public static Model getModel()
- {
+
+ public static Model getModel() {
return ModelFactory.createModelForGraph(getGraph());
}
-
- public static InputStream getRDFInput()
- {
- return new ByteArrayInputStream( rdfStr().getBytes() );
- }
-
- public static InputStream getTTLInput()
- {
- return new ByteArrayInputStream( ttlStr().getBytes() );
- }
-
- public static Reader getRDFReader()
- {
- return new StringReader( rdfStr() );
- }
-
- public static Reader getTTLReader()
- {
- return new StringReader( ttlStr() );
- }
-
- public static String getRDFName() throws IOException
- {
+
+ public static InputStream getRDFInput() {
+ return new ByteArrayInputStream(rdfStr().getBytes());
+ }
+
+ public static InputStream getTTLInput() {
+ return new ByteArrayInputStream(ttlStr().getBytes());
+ }
+
+ public static Reader getRDFReader() {
+ return new StringReader(rdfStr());
+ }
+
+ public static Reader getTTLReader() {
+ return new StringReader(ttlStr());
+ }
+
+ public static String getRDFName() throws IOException {
File f = File.createTempFile("tfd", ".rdf");
f.deleteOnExit();
- FileOutputStream fos = new FileOutputStream( f );
- fos.write( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>".getBytes());
- fos.write( System.getProperty("line.separator").getBytes() );
- fos.write( rdfStr().getBytes() );
+ FileOutputStream fos = new FileOutputStream(f);
+ fos.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>".getBytes());
+ fos.write(System.getProperty("line.separator").getBytes());
+ fos.write(rdfStr().getBytes());
fos.close();
-
+
return f.toURI().toURL().toExternalForm();
}
-
- public static String getTTLName() throws IOException
- {
+
+ public static String getTTLName() throws IOException {
File f = File.createTempFile("tfd", ".ttl");
f.deleteOnExit();
- FileOutputStream fos = new FileOutputStream( f );
- fos.write( ttlStr().getBytes() );
+ FileOutputStream fos = new FileOutputStream(f);
+ fos.write(ttlStr().getBytes());
fos.close();
-
+
return f.toURI().toURL().toExternalForm();
}
-
+
@Test
- public void testEquality()
- {
- Model ttl = ModelFactory.createDefaultModel().read( getTTLInput(), "http://example/ns/", "TTL");
- Model rdf = ModelFactory.createDefaultModel().read( getRDFInput(), "http://example/ns/", "RDF/XML-ABBREV");
-
- assertTrue( ttl.isIsomorphicWith( rdf ));
- assertTrue( rdf.isIsomorphicWith( ttl ));
- }
-
- public static void main(String ... argv) throws Exception
- {
-// //Model model = ModelFactory.createDefaultModel() ;
-// //String x = "<s> <p> 'verify it works' ." ;
-//
-//
-// //Reader sr = getTTLReader();
-// //model.read(sr, "http://example/", "TTL") ;
-// //model.read(sr, "", "TTL") ;
-// //model.read( getRDFInput() );
-// Model ttl = ModelFactory.createDefaultModel().read( getTTLInput(), "", "TTL");
-// Model rdf = ModelFactory.createDefaultModel().read( getRDFInput(), "", "RDF/XML-ABBREV");
-//
-// ttl.write(System.out, "RDF/XML-ABBREV") ;
-// System.out.println("-----") ;
-// // model.setNsPrefix("ex", "http://example/") ;
-// rdf.write(System.out, "N-TRIPLES") ;
-// System.out.println("-----") ;
-// System.out.println( getTTLName() );
-// System.out.println( "ttl iso rdf: "+ttl.isIsomorphicWith(rdf));
-//
-// System.out.println( getRDFName() );
-// System.out.println( "rdf iso ttl: "+rdf.isIsomorphicWith(ttl));
-
- String[] lines = {
- "<rdf:RDF",
- " xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">",
- " <rdf:Description rdf:about=\"e\">",
- " <p5>verify base works</p5>",
- " </rdf:Description>",
- "</rdf:RDF>"
- };
-
- String eol = System.getProperty("line.separator");
+ public void testEquality() {
+ Model ttl = ModelFactory.createDefaultModel().read(getTTLInput(),
+ "http://example/ns/", "TTL");
+ Model rdf = ModelFactory.createDefaultModel().read(getRDFInput(),
+ "http://example/ns/", "RDF/XML-ABBREV");
+
+ assertTrue(ttl.isIsomorphicWith(rdf));
+ assertTrue(rdf.isIsomorphicWith(ttl));
+ }
+
+ public static void main(String... argv) throws Exception {
+ // //Model model = ModelFactory.createDefaultModel() ;
+ // //String x = "<s> <p> 'verify it works' ." ;
+ //
+ //
+ // //Reader sr = getTTLReader();
+ // //model.read(sr, "http://example/", "TTL") ;
+ // //model.read(sr, "", "TTL") ;
+ // //model.read( getRDFInput() );
+ // Model ttl = ModelFactory.createDefaultModel().read( getTTLInput(),
+ // "", "TTL");
+ // Model rdf = ModelFactory.createDefaultModel().read( getRDFInput(),
+ // "", "RDF/XML-ABBREV");
+ //
+ // ttl.write(System.out, "RDF/XML-ABBREV") ;
+ // System.out.println("-----") ;
+ // // model.setNsPrefix("ex", "http://example/") ;
+ // rdf.write(System.out, "N-TRIPLES") ;
+ // System.out.println("-----") ;
+ // System.out.println( getTTLName() );
+ // System.out.println( "ttl iso rdf: "+ttl.isIsomorphicWith(rdf));
+ //
+ // System.out.println( getRDFName() );
+ // System.out.println( "rdf iso ttl: "+rdf.isIsomorphicWith(ttl));
+
+ String[] lines = { "<rdf:RDF",
+ " xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">",
+ " <rdf:Description rdf:about=\"e\">",
+ " <p5>verify base works</p5>", " </rdf:Description>",
+ "</rdf:RDF>" };
+
+ String eol = System.getProperty("line.separator");
StringBuilder sb = new StringBuilder();
- for (String l : lines)
- {
- sb.append( l ).append(eol);
+ for (String l : lines) {
+ sb.append(l).append(eol);
}
- Model model = ModelFactory.createDefaultModel() ;
-
- StringReader sr = new StringReader(sb.toString()) ;
- model.read(sr, "http://example/") ;
- model.write(System.out, "N-TRIPLES") ;
- System.out.println("-----") ;
- model.setNsPrefix("ex", "http://example/") ;
- model.write(System.out, "RDF/XML-ABBREV", "http://another/") ;
- }
+ Model model = ModelFactory.createDefaultModel();
+ StringReader sr = new StringReader(sb.toString());
+ model.read(sr, "http://example/");
+ model.write(System.out, "N-TRIPLES");
+ System.out.println("-----");
+ model.setNsPrefix("ex", "http://example/");
+ model.write(System.out, "RDF/XML-ABBREV", "http://another/");
+ }
}
Modified: jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/testing_framework/TestUtils.java
URL: http://svn.apache.org/viewvc/jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/testing_framework/TestUtils.java?rev=1530718&r1=1530717&r2=1530718&view=diff
==============================================================================
--- jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/testing_framework/TestUtils.java (original)
+++ jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/testing_framework/TestUtils.java Wed Oct 9 17:16:15 2013
@@ -218,90 +218,85 @@ public class TestUtils {
assertEquals(msg, o1.hashCode(), o2.hashCode());
}
- private static URL getURL( String fn )
- {
+ private static URL getURL(String fn) {
URL u = TestUtils.class.getClassLoader().getResource(fn);
if (u == null) {
throw new RuntimeException(new FileNotFoundException(fn));
}
return u;
}
+
public static String getFileName(String fn) {
-
+
try {
return getURL(fn).toURI().toString();
} catch (URISyntaxException e) {
throw new RuntimeException(e);
}
}
-
- public static InputStream getInputStream( String fn ) throws IOException {
- return getURL( fn ).openStream();
+
+ public static InputStream getInputStream(String fn) throws IOException {
+ return getURL(fn).openStream();
}
-
+
// FIXME this is to be removed when testing is complete
- public static void logAssertEquals( Class<?> clazz, String msg, Object obj1, Object obj2)
- {
- if (obj1 == null && obj2 == null)
- {
+ public static void logAssertEquals(Class<?> clazz, String msg, Object obj1,
+ Object obj2) {
+ if (obj1 == null && obj2 == null) {
return;
}
-
- if (obj1 != null)
- {
- if (obj1 == obj2)
- {
- return;
+
+ if (obj1 != null) {
+ if (obj1 == obj2) {
+ return;
}
- if (obj1.equals(obj2))
- {
+ if (obj1.equals(obj2)) {
return;
}
}
- LoggerFactory.getLogger(clazz).warn( String.format( "%s expected: %s got: %s", msg, obj1, obj2));
- System.out.println( String.format( "[%sWARNING] %s expected: %s got: %s", clazz, msg, obj1, obj2));
+ LoggerFactory.getLogger(clazz).warn(
+ String.format("%s expected: %s got: %s", msg, obj1, obj2));
+ System.out.println(String.format("[%sWARNING] %s expected: %s got: %s",
+ clazz, msg, obj1, obj2));
}
-
+
// FIXME this is to be removed when testing is complete
- public static void logAssertTrue( Class<?> clazz, String msg, boolean value)
- {
- if (value)
- {
+ public static void logAssertTrue(Class<?> clazz, String msg, boolean value) {
+ if (value) {
return;
}
-
- LoggerFactory.getLogger(clazz).warn( String.format( "%s", msg));
- System.out.println( String.format( "[%s WARNING] %s ", clazz, msg));
+
+ LoggerFactory.getLogger(clazz).warn(String.format("%s", msg));
+ System.out.println(String.format("[%s WARNING] %s ", clazz, msg));
}
-
+
// FIXME this is to be removed when testing is complete
- public static void logAssertFalse( Class<?> clazz, String msg, boolean value)
- {
- if (!value)
- {
- return;
- }
-
- LoggerFactory.getLogger(clazz).warn( String.format( "%s", msg));
- System.out.println( String.format( "[%s WARNING] %s ", clazz, msg));
+ public static void logAssertFalse(Class<?> clazz, String msg, boolean value) {
+ if (!value) {
+ return;
}
+
+ LoggerFactory.getLogger(clazz).warn(String.format("%s", msg));
+ System.out.println(String.format("[%s WARNING] %s ", clazz, msg));
+ }
+
// FIXME this is to be removed when testing is complete
- public static void logAssertSame( Class<?> clazz, String msg, Object obj1, Object obj2)
- {
- if (obj1 == null && obj2 == null)
- {
+ public static void logAssertSame(Class<?> clazz, String msg, Object obj1,
+ Object obj2) {
+ if (obj1 == null && obj2 == null) {
return;
}
-
- if (obj1 != null)
- {
- if (obj1 == obj2)
- {
- return;
+
+ if (obj1 != null) {
+ if (obj1 == obj2) {
+ return;
}
}
- LoggerFactory.getLogger(clazz).warn( String.format( "%s expected: %s got: %s", msg, obj1, obj2));
- System.out.println( String.format( "[%s WARNING] %s expected: %s got: %s",clazz, msg, obj1, obj2));
+ LoggerFactory.getLogger(clazz).warn(
+ String.format("%s expected: %s got: %s", msg, obj1, obj2));
+ System.out
+ .println(String.format("[%s WARNING] %s expected: %s got: %s",
+ clazz, msg, obj1, obj2));
}
-
+
}