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/27 12:35:21 UTC

svn commit: r1536104 [4/4] - in /jena/Experimental/new-test: ./ src/test/java/ 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/...

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=1536104&r1=1536103&r2=1536104&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 Sun Oct 27 11:35:20 2013
@@ -7,6 +7,8 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.io.Reader;
 import java.io.StringReader;
+import java.util.HashMap;
+import java.util.Map;
 
 import static org.junit.Assert.assertTrue;
 import org.junit.Test;
@@ -25,6 +27,165 @@ import com.hp.hpl.jena.sparql.graph.Grap
  * 
  */
 public class TestFileData {
+	
+	private static Map<String,String[]> rdfData = new HashMap<String,String[]>();
+	private static Map<String,String[]> ttlData = new HashMap<String,String[]>();
+	
+	static {
+		rdfData.put( "", // default set must be equiv to TTL default
+				new String[] {
+			"<?xml version=\"1.0\" encoding=\"UTF-8\"?>",
+			"<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>" }			
+				);
+		rdfData.put( "OntologyList0",
+				new String[] {
+				"<?xml version='1.0' encoding='ISO-8859-1'?>",
+				"<!DOCTYPE rdf:RDF [",
+				"    <!ENTITY rdf   'http://www.w3.org/1999/02/22-rdf-syntax-ns#'>",
+				"    <!ENTITY rdfs  'http://www.w3.org/2000/01/rdf-schema#'>",
+				"]>",
+				"<rdf:RDF",
+				"    xmlns:rdf   =\"&rdf;\"",
+				"    xmlns:rdfs  =\"&rdfs;\"",
+				"    xml:base    =\"uri:urn:x-rdf:test\"",
+				"    xmlns       =\"uri:urn:x-rdf:test#\"",
+				">",
+				"<rdf:Description rdf:ID=\"root\">",
+				"   <p rdf:parseType=\"Collection\">",
+				"   </p>",
+				"</rdf:Description>",
+				"</rdf:RDF>" }
+				);
+		rdfData.put( "OntologyList1",
+				new String[] {
+				"<?xml version='1.0' encoding='ISO-8859-1'?>",
+				"<!DOCTYPE rdf:RDF [",
+				"    <!ENTITY rdf   'http://www.w3.org/1999/02/22-rdf-syntax-ns#'>",
+				"    <!ENTITY rdfs  'http://www.w3.org/2000/01/rdf-schema#'>",
+				"]>",
+				"<rdf:RDF",
+				"    xmlns:rdf   =\"&rdf;\"",
+				"    xmlns:rdfs  =\"&rdfs;\"",
+				"    xml:base    =\"uri:urn:x-rdf:test\"",
+				"    xmlns       =\"uri:urn:x-rdf:test#\"",
+				">",
+				"<rdf:Description rdf:ID=\"root\">",
+				"   <p rdf:parseType=\"Collection\">",
+				"    <rdf:Description rdf:ID=\"a\" />",
+				"   </p>",
+				"</rdf:Description>",
+				"</rdf:RDF>"
+				}
+		);
+		rdfData.put( "OntologyList2",
+				new String[] {
+				"<?xml version='1.0' encoding='ISO-8859-1'?>",
+				"<!DOCTYPE rdf:RDF [",
+				"    <!ENTITY rdf   'http://www.w3.org/1999/02/22-rdf-syntax-ns#'>",
+				"    <!ENTITY rdfs  'http://www.w3.org/2000/01/rdf-schema#'>",
+				"]>",
+				"<rdf:RDF",
+				"    xmlns:rdf   =\"&rdf;\"",
+				"    xmlns:rdfs  =\"&rdfs;\"",
+				"    xml:base    =\"uri:urn:x-rdf:test\"",
+				"    xmlns       =\"uri:urn:x-rdf:test#\"",
+				">",
+				"<rdf:Description rdf:ID=\"root\">",
+				"   <p rdf:parseType=\"Collection\">",
+				"    <rdf:Description rdf:ID=\"a\" />",
+				"    <rdf:Description rdf:ID=\"b\" />",
+				"   </p>",
+				"</rdf:Description>",
+				"</rdf:RDF>"
+				}
+		);
+		rdfData.put( "OntologyList3",
+				new String[] {
+				"<?xml version='1.0' encoding='ISO-8859-1'?>",
+				"<!DOCTYPE rdf:RDF [",
+				"    <!ENTITY rdf   'http://www.w3.org/1999/02/22-rdf-syntax-ns#'>",
+				"    <!ENTITY rdfs  'http://www.w3.org/2000/01/rdf-schema#'>",
+				"]>",
+				"<rdf:RDF",
+				"    xmlns:rdf   =\"&rdf;\"",
+				"    xmlns:rdfs  =\"&rdfs;\"",
+				"    xml:base    =\"uri:urn:x-rdf:test\"",
+				"    xmlns       =\"uri:urn:x-rdf:test#\"",
+				">",
+				"<rdf:Description rdf:ID=\"root\">",
+				"   <p rdf:parseType=\"Collection\">",
+				"    <rdf:Description rdf:ID=\"a\" />",
+				"    <rdf:Description rdf:ID=\"b\" />",
+				"    <rdf:Description rdf:ID=\"c\" />",
+				"   </p>",
+				"</rdf:Description>",
+				"</rdf:RDF>"
+				}
+		);
+		rdfData.put( "OntologyList4",
+				new String[] {
+				"<?xml version='1.0' encoding='ISO-8859-1'?>",
+				"<!DOCTYPE rdf:RDF [",
+				"    <!ENTITY rdf   'http://www.w3.org/1999/02/22-rdf-syntax-ns#'>",
+				"    <!ENTITY rdfs  'http://www.w3.org/2000/01/rdf-schema#'>",
+				"]>",
+				"<rdf:RDF",
+				"    xmlns:rdf   =\"&rdf;\"",
+				"    xmlns:rdfs  =\"&rdfs;\"",
+				"    xml:base    =\"uri:urn:x-rdf:test\"",
+				"    xmlns       =\"uri:urn:x-rdf:test#\"",
+				">",
+				"<rdf:Description rdf:ID=\"root\">",
+				"   <p rdf:parseType=\"Collection\">",
+				"    <rdf:Description rdf:ID=\"a\" />",
+				"    <rdf:Description rdf:ID=\"b\" />",
+				"    <rdf:Description rdf:ID=\"c\" />",
+				"    <rdf:Description rdf:ID=\"d\" />",
+				"   </p>",
+				"</rdf:Description>",
+				"</rdf:RDF>"
+				}
+		);
+		rdfData.put( "OntologyList5",
+				new String[] {
+				"<?xml version='1.0' encoding='ISO-8859-1'?>",
+				"<!DOCTYPE rdf:RDF [",
+				"    <!ENTITY rdf   'http://www.w3.org/1999/02/22-rdf-syntax-ns#'>",
+				"    <!ENTITY rdfs  'http://www.w3.org/2000/01/rdf-schema#'>",
+				"]>",
+				"<rdf:RDF",
+				"    xmlns:rdf   =\"&rdf;\"",
+				"    xmlns:rdfs  =\"&rdfs;\"",
+				"    xml:base    =\"uri:urn:x-rdf:test\"",
+				"    xmlns       =\"uri:urn:x-rdf:test#\"",
+				">",
+				"<rdf:Description rdf:ID=\"root\">",
+				"   <p rdf:parseType=\"Collection\">",
+				"    <rdf:Description rdf:ID=\"a\" />",
+				"    <rdf:Description rdf:ID=\"b\" />",
+				"    <rdf:Description rdf:ID=\"c\" />",
+				"    <rdf:Description rdf:ID=\"d\" />",
+				"    <rdf:Description rdf:ID=\"e\" />",
+				"   </p>",
+				"</rdf:Description>",
+				"</rdf:RDF>"
+				}
+		);
+		
+		ttlData.put( "", // default set must be equiv to RDF default
+				new String[] {
+				"<http://example.com/subject> <http://example.com/predicate> <http://example.com/object> .",
+				"<e> <p5> 'verify base works' ." }
+				);
+		
+	}
 	private static String ttlStr() {
 		String[] lines = {
 				"<http://example.com/subject> <http://example.com/predicate> <http://example.com/object> .",
@@ -32,18 +193,6 @@ public class TestFileData {
 		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) {
 		String eol = System.getProperty("line.separator");
@@ -79,47 +228,106 @@ public class TestFileData {
 	public static Model getModel() {
 		return ModelFactory.createModelForGraph(getGraph());
 	}
-
-	public static InputStream getRDFInput() {
-		return new ByteArrayInputStream(rdfStr().getBytes());
+	
+	public static Model populateRDFModel( Model model, String name ) throws IOException
+	{
+		ModelHelper.txnBegin( model );
+		model.read( getRDFInput( name ), "http://example.com/test/");
+		ModelHelper.txnCommit(model);
+		return model;
+	}
+	
+	public static Model getRDFModel( String name ) throws IOException
+	{
+		return populateRDFModel( ModelFactory.createDefaultModel(), name );
+	}
+
+	private static String[] getRDFData( String name ) throws IOException
+	{
+		String[] data = rdfData.get( name );
+		if (data == null)
+		{
+			throw new IOException( "Can not find RDF data "+name );
+		}
+		return data;
 	}
-
-	public static InputStream getTTLInput() {
-		return new ByteArrayInputStream(ttlStr().getBytes());
+	
+	public static InputStream getRDFInput( String name ) throws IOException
+	{
+		return new ByteArrayInputStream(toDataString(getRDFData(name)).getBytes());
+	}
+	
+	public static InputStream getRDFInput() throws IOException {
+		return getRDFInput( "" );
+	}
+
+	private static String[] getTTLData( String name ) throws IOException
+	{
+		String[] data = ttlData.get( name );
+		if (data == null)
+		{
+			throw new IOException( "Can not find TTL data "+name );
+		}
+		return data;
 	}
-
-	public static Reader getRDFReader() {
-		return new StringReader(rdfStr());
+	
+	public static InputStream getTTLInput( String name ) throws IOException
+	{
+		return new ByteArrayInputStream(toDataString(getTTLData(name)).getBytes());
+	}
+	
+	public static InputStream getTTLInput()  throws IOException{
+		return getTTLInput("");
+	}
+
+	
+	public static Reader getRDFReader(String name)  throws IOException{
+		
+		return new StringReader(toDataString(getRDFData(name)));
+	}
+	
+	public static Reader getRDFReader()  throws IOException{
+		
+		return getRDFReader("");
 	}
 
 	public static Reader getTTLReader() {
 		return new StringReader(ttlStr());
 	}
 
+	public static String getRDFName( String name ) throws IOException
+	{
+		return createFile( toDataString(getRDFData(name)), ".rdf");
+	}
+	
 	public static String getRDFName() throws IOException {
-		File f = File.createTempFile("tfd", ".rdf");
+		return getRDFName( "");
+	}
+	
+	private static String createFile( String data, String extension ) throws IOException
+	{
+		File f = File.createTempFile("tfd", extension );
 		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());
+		//fos.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>".getBytes());
+		//fos.write(System.getProperty("line.separator").getBytes());
+		fos.write(data.getBytes());
 		fos.close();
-
 		return f.toURI().toURL().toExternalForm();
 	}
 
 	public static String getTTLName() throws IOException {
-		File f = File.createTempFile("tfd", ".ttl");
-		f.deleteOnExit();
-		FileOutputStream fos = new FileOutputStream(f);
-		fos.write(ttlStr().getBytes());
-		fos.close();
-
-		return f.toURI().toURL().toExternalForm();
+		return getTTLName( "" );
+	}
+	
+	public static String getTTLName(String name) throws IOException {
+		return createFile( toDataString(getTTLData(name)), ".ttl" );
 	}
 
+	public static final String NS = "uri:urn:x-rdf:test#";
+
 	@Test
-	public void testEquality() {
+	public void testEquality() throws Exception {
 		Model ttl = ModelFactory.createDefaultModel().read(getTTLInput(),
 				"http://example/ns/", "TTL");
 		Model rdf = ModelFactory.createDefaultModel().read(getRDFInput(),

Modified: jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/util/iterator/ExtendedIteratorContractTests.java
URL: http://svn.apache.org/viewvc/jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/util/iterator/ExtendedIteratorContractTests.java?rev=1536104&r1=1536103&r2=1536104&view=diff
==============================================================================
--- jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/util/iterator/ExtendedIteratorContractTests.java (original)
+++ jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/util/iterator/ExtendedIteratorContractTests.java Sun Oct 27 11:35:20 2013
@@ -20,19 +20,19 @@ import com.hp.hpl.jena.testing_framework
 @Ignore
 @Contract(ExtendedIterator.class)
 public class ExtendedIteratorContractTests<T> {
-	
-	public static Logger LOG = LoggerFactory.getLogger(ExtendedIteratorContractTests.class);
+
+	public static Logger LOG = LoggerFactory
+			.getLogger(ExtendedIteratorContractTests.class);
 
 	private IIteratorProducer<T> producer;
-	
-	public ExtendedIteratorContractTests()
-	{
+
+	public ExtendedIteratorContractTests() {
 		@SuppressWarnings("unchecked")
 		IIteratorProducer<T> p = (IIteratorProducer<T>) new IIteratorProducer<String>() {
-			
+
 			List<String> objs = new ArrayList<String>(
-					Arrays.asList(new String[]{ "one", "two", "three", "four" }) );
-			
+					Arrays.asList(new String[] { "one", "two", "three", "four" }));
+
 			@Override
 			public List<String> getList() {
 				return objs;
@@ -40,13 +40,13 @@ public class ExtendedIteratorContractTes
 
 			@Override
 			public ExtendedIterator<String> newInstance() {
-				return WrappedIterator.create( objs.iterator() );
+				return WrappedIterator.create(objs.iterator());
 			}
 
 			@Override
 			public void cleanUp() {
 			}
-			
+
 			@Override
 			public boolean supportsDelete() {
 				return true;
@@ -60,12 +60,12 @@ public class ExtendedIteratorContractTes
 		};
 		producer = p;
 	}
-	
+
 	@Contract.Inject
-	public final void setIteratorProducer( IIteratorProducer<T> producer ) {
+	public final void setIteratorProducer(IIteratorProducer<T> producer) {
 		this.producer = producer;
 	}
-	
+
 	public final IIteratorProducer<T> getIteratorProducer() {
 		return producer;
 	}
@@ -75,9 +75,8 @@ public class ExtendedIteratorContractTes
 		List<T> lst = getIteratorProducer().getList();
 		Set<T> stmt = new HashSet<T>();
 		stmt.addAll(lst);
-		if (stmt.size() == lst.size())
-		{
-			LOG.warn( "Iterator List should have duplicates for proper testing");
+		if (stmt.size() == lst.size()) {
+			LOG.warn("Iterator List should have duplicates for proper testing");
 		}
 	}
 
@@ -86,7 +85,8 @@ public class ExtendedIteratorContractTes
 	 */
 	@Test
 	public void testRemoveNext() {
-		List<T> lst = new ArrayList<T>(getIteratorProducer().newInstance().toList());
+		List<T> lst = new ArrayList<T>(getIteratorProducer().newInstance()
+				.toList());
 		ExtendedIterator<T> iter = getIteratorProducer().newInstance();
 
 		try {
@@ -95,13 +95,12 @@ public class ExtendedIteratorContractTes
 				fail("Should have thrown UnsupportedOperationException");
 			}
 			assertEquals(lst.get(0), o);
-			if (! getIteratorProducer().isCopy())
-			{
+			if (!getIteratorProducer().isCopy()) {
 				List<T> lst2 = getIteratorProducer().newInstance().toList();
-				assertEquals( "Element not deleted", lst.size()-1,lst2.size());
+				assertEquals("Element not deleted", lst.size() - 1, lst2.size());
 				lst.removeAll(lst2);
-				assertEquals( "Wrong elements returned", 1, lst.size() );
-				assertEquals( o, lst.get(0) );
+				assertEquals("Wrong elements returned", 1, lst.size());
+				assertEquals(o, lst.get(0));
 			}
 		} catch (UnsupportedOperationException e) {
 			if (getIteratorProducer().supportsDelete()) {
@@ -118,16 +117,14 @@ public class ExtendedIteratorContractTes
 	 */
 	@Test
 	public void testAndThen() {
-		ExtendedIterator<T> iter = getIteratorProducer()
-				.newInstance();
-		ExtendedIterator<T> iter2 = getIteratorProducer()
-				.newInstance();
+		ExtendedIterator<T> iter = getIteratorProducer().newInstance();
+		ExtendedIterator<T> iter2 = getIteratorProducer().newInstance();
 
 		iter = iter.andThen(iter2);
 		int sz = getIteratorProducer().getList().size();
 		List<Object> lst = new ArrayList<Object>();
 		for (int i = 0; i < sz; i++) {
-			lst.add( iter.next());
+			lst.add(iter.next());
 		}
 		for (int i = 0; i < sz; i++) {
 			assertEquals(lst.get(i), iter.next());
@@ -200,10 +197,9 @@ public class ExtendedIteratorContractTes
 
 		assertEquals(lst2.size(), lst1.size());
 
-		for (Object o : lst1)
-		{
-			assertTrue( "missing value "+o, lst2.contains( o ));
-			lst2.remove( o );
+		for (Object o : lst1) {
+			assertTrue("missing value " + o, lst2.contains(o));
+			lst2.remove(o);
 		}
 
 	}

Modified: jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/util/iterator/WrappedIteratorTest.java
URL: http://svn.apache.org/viewvc/jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/util/iterator/WrappedIteratorTest.java?rev=1536104&r1=1536103&r2=1536104&view=diff
==============================================================================
--- jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/util/iterator/WrappedIteratorTest.java (original)
+++ jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/util/iterator/WrappedIteratorTest.java Sun Oct 27 11:35:20 2013
@@ -4,8 +4,6 @@ import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
 
-import org.xenei.junit.contract.Contract.Inject;
-
 import com.hp.hpl.jena.testing_framework.IIteratorProducer;
 import com.hp.hpl.jena.util.iterator.ExtendedIterator;
 import com.hp.hpl.jena.util.iterator.WrappedIterator;
@@ -15,35 +13,35 @@ public class WrappedIteratorTest extends
 	public WrappedIteratorTest() {
 		super();
 		super.setIteratorProducer(new IIteratorProducer<String>() {
-		
-		List<String> objs = new ArrayList<String>(
-				Arrays.asList(new String[]{ "one", "two", "three", "four" }) );
-		
-		@Override
-		public List<String> getList() {
-			return objs;
-		}
-
-		@Override
-		public ExtendedIterator<String> newInstance() {
-			return WrappedIterator.create( objs.iterator() );
-		}
-
-		@Override
-		public void cleanUp() {
-		}
-		
-		@Override
-		public boolean supportsDelete() {
-			return true;
-		}
-
-		@Override
-		public boolean isCopy() {
-			return false;
-		}
 
-	});
+			List<String> objs = new ArrayList<String>(Arrays
+					.asList(new String[] { "one", "two", "three", "four" }));
+
+			@Override
+			public List<String> getList() {
+				return objs;
+			}
+
+			@Override
+			public ExtendedIterator<String> newInstance() {
+				return WrappedIterator.create(objs.iterator());
+			}
+
+			@Override
+			public void cleanUp() {
+			}
+
+			@Override
+			public boolean supportsDelete() {
+				return true;
+			}
+
+			@Override
+			public boolean isCopy() {
+				return false;
+			}
+
+		});
 	}
-	
+
 }

Modified: jena/Experimental/new-test/src/test/java/dummy.java
URL: http://svn.apache.org/viewvc/jena/Experimental/new-test/src/test/java/dummy.java?rev=1536104&r1=1536103&r2=1536104&view=diff
==============================================================================
--- jena/Experimental/new-test/src/test/java/dummy.java (original)
+++ jena/Experimental/new-test/src/test/java/dummy.java Sun Oct 27 11:35:20 2013
@@ -6,20 +6,19 @@ import com.hp.hpl.jena.rdf.model.Propert
 import com.hp.hpl.jena.rdf.model.Resource;
 import com.hp.hpl.jena.rdf.model.Statement;
 
-
 public class dummy {
 
 	public static void main(String[] args) {
-			Model m = ModelFactory.createDefaultModel();
-			Resource s = m.createResource();
-			Property p = m.createProperty("http://example.com/p");
-			Literal o = m.createLiteral( "foo" );
-			Statement stmt = m.createStatement(s, p, o);
-			
-			Bag bg = stmt.getBag();
-			System.out.println( "Should have thrown exception as statement is "+stmt);
-	
-		}
-	
+		Model m = ModelFactory.createDefaultModel();
+		Resource s = m.createResource();
+		Property p = m.createProperty("http://example.com/p");
+		Literal o = m.createLiteral("foo");
+		Statement stmt = m.createStatement(s, p, o);
+
+		Bag bg = stmt.getBag();
+		System.out.println("Should have thrown exception as statement is "
+				+ stmt);
+
+	}
 
 }