jena-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cla...@apache.org
Subject svn commit: r1531665 [2/2] - in /jena/Experimental/new-test/src/test/java/com/hp/hpl/jena: graph/ rdf/model/ rdf/model/temp/ testing_framework/ util/ util/iterator/
Date Sun, 13 Oct 2013 10:26:39 GMT
Modified: jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/rdf/model/temp/IteratorTest.java
URL: http://svn.apache.org/viewvc/jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/rdf/model/temp/IteratorTest.java?rev=1531665&r1=1531664&r2=1531665&view=diff
==============================================================================
--- jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/rdf/model/temp/IteratorTest.java
(original)
+++ jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/rdf/model/temp/IteratorTest.java
Sun Oct 13 10:26:38 2013
@@ -1,24 +1,58 @@
 package com.hp.hpl.jena.rdf.model.temp;
 
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.junit.runner.RunWith;
+import org.xenei.junit.contract.Contract;
+import org.xenei.junit.contract.Contract.Inject;
+import org.xenei.junit.contract.ContractImpl;
+import org.xenei.junit.contract.ContractSuite;
+import org.xenei.junit.contract.IProducer;
+
 import com.hp.hpl.jena.rdf.model.AbstractIteratorTest;
 import com.hp.hpl.jena.rdf.model.ModelContractTests;
 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.util.iterator.ExtendedIterator;
+import com.hp.hpl.jena.util.iterator.ExtendedIteratorContractTests;
+import com.hp.hpl.jena.util.iterator.ExtendedIteratorContractTests.IteratorProducer;
+import com.hp.hpl.jena.util.iterator.WrappedIterator;
+
+//@RunWith( ContractSuite.class )
+//@ContractImpl( ExtendedIterator.class )
+public class IteratorTest  extends ExtendedIteratorContractTests {
+
+	IteratorProducer producer = new IteratorProducer() {
+		
+		Object[] objs = { "one", "two", "three", "four" };
+		
+		public List<Object> getList() {
+			return Arrays.asList( objs );
+		}
 
-public class IteratorTest extends AbstractIteratorTest {
-
-	AbstractModelProducer producer = new AbstractModelProducer() {
+		@Override
+		public ExtendedIterator<Object> newInstance() {
+			List<Object> l = new ArrayList<Object>( getList() );
+			return WrappedIterator.create( l.iterator() );
+		}
 
 		@Override
-		protected Model createNewModel() {
-			return ModelFactory.createDefaultModel();
+		public void cleanUp() {
+		}
+		
+		@Override
+		public boolean supportsDelete() {
+			return true;
 		}
 
 	};
 
 	@Override
-	public ModelProducerInterface getModelProducer() {
+	@Inject("com.hp.hpl.jena.util.iterator.ExtendedIteratorContractTests.IteratorProducer<%s>")
+	public IteratorProducer getIteratorProducer() {
 		return producer;
 	}
 }

Modified: jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/rdf/model/temp/LiteralTest.java
URL: http://svn.apache.org/viewvc/jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/rdf/model/temp/LiteralTest.java?rev=1531665&r1=1531664&r2=1531665&view=diff
==============================================================================
--- jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/rdf/model/temp/LiteralTest.java
(original)
+++ jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/rdf/model/temp/LiteralTest.java
Sun Oct 13 10:26:38 2013
@@ -1,24 +1,91 @@
 package com.hp.hpl.jena.rdf.model.temp;
 
-import com.hp.hpl.jena.rdf.model.AbstractLiteralTest;
+import com.hp.hpl.jena.rdf.model.Literal;
+import com.hp.hpl.jena.rdf.model.LiteralContractTest;
 import com.hp.hpl.jena.rdf.model.ModelContractTests;
 import com.hp.hpl.jena.rdf.model.Model;
 import com.hp.hpl.jena.rdf.model.ModelFactory;
 import com.hp.hpl.jena.testing_framework.AbstractModelProducer;
 
-public class LiteralTest extends AbstractLiteralTest {
+public class LiteralTest extends LiteralContractTest {
 
-	AbstractModelProducer producer = new AbstractModelProducer() {
+	LiteralProducer producer = new LiteralProducer() {
+		private Model model;
+		
+		@Override
+		public Literal newInstance(String uri) {
+			return getModel().createLiteral(uri);
+		}
+
+		@Override
+		public Model getModel() {
+			if (model == null)
+			{
+				model = ModelFactory.createDefaultModel();
+			}
+			return model;
+		}
+
+		@Override
+		public Literal newInstance() {
+			return getModel().createLiteral("");
+		}
+
+		@Override
+		public void cleanUp() {
+			if (model != null)
+			{
+				model.close();
+				model = null;
+			}
+		}
+
+
+		@Override
+		public Literal newInstance(boolean b) {
+			return getModel().createTypedLiteral(b);
+		}
+
+		@Override
+		public Literal newInstance(char c) {
+			return getModel().createTypedLiteral(c);
+		}
 
 		@Override
-		protected Model createNewModel() {
-			return ModelFactory.createDefaultModel();
+		public Literal newInstance(double d) {
+			return getModel().createTypedLiteral(d);
 		}
 
+		@Override
+		public Literal newInstance(float f) {
+			return getModel().createTypedLiteral(f);
+		}
+
+		@Override
+		public Literal newInstance(int i) {
+			return getModel().createTypedLiteral(i);
+		}
+
+		@Override
+		public Literal newInstance(long l) {
+			return getModel().createTypedLiteral(l);
+		}
+
+
+		@Override
+		public Literal newInstance(String val, String lang) {
+			return getModel().createLiteral(val,lang);
+		}
+
+		@Override
+		public Literal newInstance(Object o) {
+			return getModel().createTypedLiteral( o );
+		}
 	};
 
 	@Override
-	public ModelProducerInterface getModelProducer() {
+	public LiteralProducer getLiteralProducer() {
 		return producer;
 	}
+
 }

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=1531665&r1=1531664&r2=1531665&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
Sun Oct 13 10:26:38 2013
@@ -218,6 +218,17 @@ public class TestUtils {
 		assertEquals(msg, o1.hashCode(), o2.hashCode());
 	}
 
+	/**
+	 * Tests o1.equals( o2 ) && o2.equals(o1) && o1.hashCode() == o2.hashCode()
+	 * 
+	 * @param o1
+	 * @param o2
+	 */
+	public static void assertNotEquivalent(String msg, Object o1, Object o2) {
+		assertNotEquals(msg, o1, o2);
+		assertNotEquals(msg, o2, o1);
+	}
+
 	private static URL getURL(String fn) {
 		URL u = TestUtils.class.getClassLoader().getResource(fn);
 		if (u == null) {

Added: 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=1531665&view=auto
==============================================================================
--- jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/util/iterator/ExtendedIteratorContractTests.java
(added)
+++ jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/util/iterator/ExtendedIteratorContractTests.java
Sun Oct 13 10:26:38 2013
@@ -0,0 +1,208 @@
+package com.hp.hpl.jena.util.iterator;
+
+import static org.junit.Assert.*;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.jena.atlas.logging.Log;
+import org.junit.Before;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.xenei.junit.contract.Contract;
+import org.xenei.junit.contract.IProducer;
+
+@Contract(ExtendedIterator.class)
+public abstract class ExtendedIteratorContractTests {
+	
+	public static Logger LOG = LoggerFactory.getLogger(ExtendedIteratorContractTests.class);
+
+	public static interface IteratorProducer<T> {
+		
+		public ExtendedIterator<T> newInstance();
+		
+		public void cleanUp();
+
+		public List<T> getList();
+		
+		public boolean supportsDelete(); 
+	}
+
+	@Contract.Inject( "com.hp.hpl.jena.util.iterator.ExtendedIteratorContractTests.IteratorProducer<%s>")
+	abstract public IteratorProducer getIteratorProducer();
+
+	@Before
+	public final void beforeExtendedIteratorContractTests() {
+		List<Object> lst = getIteratorProducer().getList();
+		Set<Object> stmt = new HashSet<Object>();
+		stmt.addAll(lst);
+		if (stmt.size() == lst.size())
+		{
+			LOG.warn( "Iterator List should have duplicates for proper testing");
+		}
+	}
+
+	/**
+	 * Answer the next object, and remove it. Equivalent to next(); remove().
+	 */
+	@Test
+	public void testRemoveNext() {
+		List<Object> lst = getIteratorProducer().newInstance().toList();
+		ExtendedIterator<Object> iter = getIteratorProducer().newInstance();
+
+		try {
+			Object o = iter.removeNext();
+			if (!getIteratorProducer().supportsDelete()) {
+				fail("Should have thrown UnsupportedOperationException");
+			}
+			assertEquals(lst.get(0), o);
+			List<Object> lst2 = getIteratorProducer().newInstance().toList();
+			assertEquals( "Element not deleted", lst.size()-1,lst2.size());
+			lst.removeAll(lst2);
+			assertEquals( "Wrong elements returned", 1, lst.size() );
+			assertEquals( o, lst.get(0) );
+		} catch (UnsupportedOperationException e) {
+			if (getIteratorProducer().supportsDelete()) {
+				fail("Should not have thrown UnsupportedOperationException");
+			}
+		}
+
+	}
+
+	/**
+	 * return a new iterator which delivers all the elements of this iterator
+	 * and then all the elements of the other iterator. Does not copy either
+	 * iterator; they are consumed as the result iterator is consumed.
+	 */
+	@Test
+	public void testAndThen() {
+		ExtendedIterator<Object> iter = (ExtendedIterator<Object>) getIteratorProducer()
+				.newInstance();
+		ExtendedIterator<Object> iter2 = (ExtendedIterator<Object>) 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());
+		}
+		for (int i = 0; i < sz; i++) {
+			assertEquals(lst.get(i), iter.next());
+		}
+	}
+
+	/**
+	 * return a new iterator containing only the elements of _this_ which pass
+	 * the filter _f_. The order of the elements is preserved. Does not copy
+	 * _this_, which is consumed as the result is consumed.
+	 */
+	@Test
+	public void testfilterKeep() {
+		ExtendedIterator<?> iter = getIteratorProducer().newInstance()
+				.filterKeep(new OddFilter());
+		List<Object> lst = getIteratorProducer().newInstance().toList();
+		for (int j = 0; j < lst.size(); j++) {
+			if ((j & 1) == 1) {
+				assertEquals(lst.get(j), iter.next());
+			}
+		}
+
+	}
+
+	/**
+	 * return a new iterator containing only the elements of _this_ which are
+	 * rejected by the filter _f_. The order of the elements is preserved. Does
+	 * not copy _this_, which is consumed as the result is consumed.
+	 */
+	@Test
+	public void testfilterDrop()
+
+	{
+		ExtendedIterator<?> iter = getIteratorProducer().newInstance()
+				.filterDrop(new OddFilter());
+		List<Object> lst = getIteratorProducer().newInstance().toList();
+		for (int j = 0; j < lst.size(); j++) {
+			if ((j & 1) == 0) {
+				assertEquals(lst.get(j), iter.next());
+			}
+		}
+
+	}
+
+	/**
+	 * return a new iterator where each element is the result of applying _map1_
+	 * to the corresponding element of _this_. _this_ is not copied; it is
+	 * consumed as the result is consumed.
+	 */
+	@Test
+	public void textMapWith() {
+		ExtendedIterator<Integer> iter = getIteratorProducer().newInstance()
+				.mapWith(new IntMap<Object>());
+		List<Object> lst = getIteratorProducer().getList();
+
+		for (int j = 0; j < lst.size(); j++) {
+			assertEquals(Integer.valueOf(j), iter.next());
+		}
+		assertFalse(iter.hasNext());
+	}
+
+	/**
+	 * Answer a list of the [remaining] elements of this iterator, in order,
+	 * consuming this iterator.
+	 */
+	@Test
+	public void toList() {
+		List<Object> lst1 = getIteratorProducer().newInstance().toList();
+		List<Object> lst2 = new ArrayList<Object>(getIteratorProducer().getList());
+
+		assertEquals(lst2.size(), lst1.size());
+
+		for (Object o : lst1)
+		{
+			assertTrue( "missing value "+o, lst2.contains( o ));
+			lst2.remove( o );
+		}
+
+	}
+
+	/**
+	 * Answer a set of the [remaining] elements of this iterator, consuming this
+	 * iterator.
+	 */
+	@Test
+	public void testToSet() {
+		Set<?> set1 = getIteratorProducer().newInstance().toSet();
+		List<?> lst2 = getIteratorProducer().getList();
+
+		assertTrue(set1.containsAll(lst2));
+		assertTrue(lst2.containsAll(set1));
+	}
+
+	private static class OddFilter<X> extends Filter<X> {
+
+		boolean acceptFlg = true;
+
+		@Override
+		public boolean accept(X o) {
+			acceptFlg = !acceptFlg;
+			return acceptFlg;
+		}
+
+	}
+
+	private static class IntMap<Object> implements Map1<Object, Integer> {
+
+		int i = 0;
+
+		@Override
+		public Integer map1(Object o) {
+			return new Integer(i++);
+		}
+
+	}
+}
\ No newline at end of file

Propchange: jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/util/iterator/ExtendedIteratorContractTests.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message