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/13 12:26:39 UTC
svn commit: r1531665 [1/2] - in
/jena/Experimental/new-test/src/test/java/com/hp/hpl/jena: graph/
rdf/model/ rdf/model/temp/ testing_framework/ util/ util/iterator/
Author: claude
Date: Sun Oct 13 10:26:38 2013
New Revision: 1531665
URL: http://svn.apache.org/r1531665
Log:
Added extended Iterator contract tests
Added Literal Contract tests
Added:
jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/rdf/model/LiteralContractTest.java
- copied, changed from r1530718, jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/rdf/model/AbstractLiteralTest.java
jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/util/
jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/util/iterator/
jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/util/iterator/ExtendedIteratorContractTests.java (with props)
Removed:
jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/rdf/model/AbstractFindPropertiesTests.java
jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/rdf/model/AbstractListObjectsTest.java
jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/rdf/model/AbstractLiteralTest.java
Modified:
jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/GraphContractTest.java
jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/rdf/model/AbstractIteratorTest.java
jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/rdf/model/AbstractModelContractSuite.java
jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/rdf/model/ModelConContractTests.java
jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/rdf/model/ModelContractTests.java
jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/rdf/model/ResourceContractTests.java
jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/rdf/model/temp/IteratorTest.java
jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/rdf/model/temp/LiteralTest.java
jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/testing_framework/TestUtils.java
Modified: jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/GraphContractTest.java
URL: http://svn.apache.org/viewvc/jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/GraphContractTest.java?rev=1531665&r1=1531664&r2=1531665&view=diff
==============================================================================
--- jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/GraphContractTest.java (original)
+++ jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/graph/GraphContractTest.java Sun Oct 13 10:26:38 2013
@@ -469,6 +469,7 @@ public abstract class GraphContractTest
graph.contains(triple("S2 P2 O2")));
assertTrue("Graph should contain <S3 P3 O3>",
graph.contains(triple("S3 P3 O3")));
+ GL.assertEmpty();
}
@Test
Modified: jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/rdf/model/AbstractIteratorTest.java
URL: http://svn.apache.org/viewvc/jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/rdf/model/AbstractIteratorTest.java?rev=1531665&r1=1531664&r2=1531665&view=diff
==============================================================================
--- jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/rdf/model/AbstractIteratorTest.java (original)
+++ jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/rdf/model/AbstractIteratorTest.java Sun Oct 13 10:26:38 2013
@@ -18,6 +18,8 @@
package com.hp.hpl.jena.rdf.model;
+import static com.hp.hpl.jena.testing_framework.ModelHelper.modelWithStatements;
+
import com.hp.hpl.jena.rdf.model.Literal;
import com.hp.hpl.jena.rdf.model.NodeIterator;
import com.hp.hpl.jena.rdf.model.NsIterator;
@@ -32,7 +34,9 @@ import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
-public abstract class AbstractIteratorTest extends AbstractProducerUser {
+@Contract()
+public abstract class AbstractIteratorTest
+{
protected Model model;
private static int num = 5;
Resource subject[];
@@ -72,6 +76,21 @@ public abstract class AbstractIteratorTe
}
}
+ @Test
+ public void testListObjectsNoRemove() {
+ final Model m = modelWithStatements(getModelProducer(),
+ "a P b; b Q c; c R a");
+ final NodeIterator it = m.listObjects();
+ it.next();
+ try {
+ it.remove();
+ Assert.fail("listObjects should not support .remove()");
+ } catch (final UnsupportedOperationException e) {
+ // expected
+ }
+ }
+
+
/**
* bug detected in StatementIteratorImpl - next does not advance current, so
* remove doesn't work with next; this test should expose the bug.
Modified: jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/rdf/model/AbstractModelContractSuite.java
URL: http://svn.apache.org/viewvc/jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/rdf/model/AbstractModelContractSuite.java?rev=1531665&r1=1531664&r2=1531665&view=diff
==============================================================================
--- jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/rdf/model/AbstractModelContractSuite.java (original)
+++ jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/rdf/model/AbstractModelContractSuite.java Sun Oct 13 10:26:38 2013
@@ -1,5 +1,8 @@
package com.hp.hpl.jena.rdf.model;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
import java.util.StringTokenizer;
import org.junit.runner.RunWith;
@@ -7,11 +10,16 @@ import org.junit.runners.Suite;
import org.xenei.junit.contract.Contract;
import org.xenei.junit.contract.ContractImpl;
import org.xenei.junit.contract.ContractSuite;
+import org.xenei.junit.contract.Contract.Inject;
+
import static com.hp.hpl.jena.testing_framework.ModelHelper.*;
import com.hp.hpl.jena.testing_framework.IContainerProducer;
import com.hp.hpl.jena.testing_framework.AbstractModelProducer;
import com.hp.hpl.jena.testing_framework.INodeProducer;
import com.hp.hpl.jena.testing_framework.IStatementProducer;
+import com.hp.hpl.jena.util.iterator.ExtendedIterator;
+import com.hp.hpl.jena.util.iterator.WrappedIterator;
+import com.hp.hpl.jena.util.iterator.ExtendedIteratorContractTests.IteratorProducer;
import com.hp.hpl.jena.vocabulary.RDF;
@Suite.SuiteClasses({ AbstractModelContractSuite.ModelContractTests.class,
@@ -20,7 +28,8 @@ import com.hp.hpl.jena.vocabulary.RDF;
AbstractModelContractSuite.SeqMethodsTests.class,
// AbstractModelContractSuite.RDFNodeTests.class,
AbstractModelContractSuite.ResourceTests.class,
- AbstractModelContractSuite.StatementTests.class, })
+ AbstractModelContractSuite.StatementTests.class,
+ AbstractModelContractSuite.StatementIterTests.class})
// @RunWith( ContractSuite.class )
public abstract class AbstractModelContractSuite {
@@ -346,4 +355,57 @@ public abstract class AbstractModelContr
}
}
+
+ public interface StmtIter extends StmtIterator {
+ }
+
+ @RunWith(ContractSuite.class)
+ @ContractImpl(StmtIterator.class)
+ public static class StatementIterTests {
+ IteratorProducer<Statement> producer = new IteratorProducer<Statement>() {
+
+ Model m = null;
+
+ Statement[] objs = { statement( "s p o" ), statement( "s p2 o2" ), statement( "s p3 o3 "),
+ statement( "s p o4" ) };
+
+
+ public List<Statement> getList() {
+ return Arrays.asList( objs );
+ }
+
+ @Override
+ public StmtIterator newInstance() {
+ return getModel().listStatements();
+ }
+
+ private Model getModel() {
+ if (m == null)
+ {
+ m = modelProducer.newInstance();
+ for (Statement s : objs )
+ {
+ m.add( s );
+ }
+ }
+ return m;
+ }
+
+ @Override
+ public void cleanUp() {
+ }
+
+ @Override
+ public boolean supportsDelete() {
+ return true;
+ }
+
+ };
+
+ @Inject("com.hp.hpl.jena.util.iterator.ExtendedIteratorContractTests.IteratorProducer<%s>")
+ public IteratorProducer<Statement> getIteratorProducer() {
+ return producer;
+ }
+
+ }
}
Copied: jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/rdf/model/LiteralContractTest.java (from r1530718, jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/rdf/model/AbstractLiteralTest.java)
URL: http://svn.apache.org/viewvc/jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/rdf/model/LiteralContractTest.java?p2=jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/rdf/model/LiteralContractTest.java&p1=jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/rdf/model/AbstractLiteralTest.java&r1=1530718&r2=1531665&rev=1531665&view=diff
==============================================================================
--- jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/rdf/model/AbstractLiteralTest.java (original)
+++ jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/rdf/model/LiteralContractTest.java Sun Oct 13 10:26:38 2013
@@ -19,12 +19,18 @@
package com.hp.hpl.jena.rdf.model;
import static com.hp.hpl.jena.testing_framework.ModelHelper.*;
+import static org.junit.Assert.*;
+import com.hp.hpl.jena.datatypes.DatatypeFormatException;
import com.hp.hpl.jena.datatypes.TypeMapper;
+import com.hp.hpl.jena.datatypes.xsd.XSDDatatype;
import com.hp.hpl.jena.graph.impl.AdhocDatatype;
import com.hp.hpl.jena.rdf.model.Literal;
import com.hp.hpl.jena.rdf.model.LiteralRequiredException;
import com.hp.hpl.jena.rdf.model.Model;
+import com.hp.hpl.jena.shared.BadBooleanException;
+import com.hp.hpl.jena.shared.BadCharLiteralException;
+import com.hp.hpl.jena.testing_framework.INodeProducer;
import org.junit.Assert;
import org.junit.Before;
@@ -34,136 +40,208 @@ import org.junit.Test;
* TestLiteralImpl - minimal, this is the first time an extra test has been
* needed above the regression testing.
*/
-public abstract class AbstractLiteralTest extends AbstractProducerUser {
+public abstract class LiteralContractTest {
- private static Model model;
- private Resource X;
- private Property P;
+ /*
+ * Literals have multiple types so each type is tested separately so that
+ * the complete contract for each type is understood in total.
+ *
+ * For example a byte may be interpreted as any of the wider integer types.
+ */
- static class UniqueValueClass1 {
- String value;
+ public interface LiteralProducer extends INodeProducer<Literal> {
+ Literal newInstance(boolean b);
- UniqueValueClass1(final String value) {
- this.value = value;
- }
+ Literal newInstance(char c);
- @Override
- public String toString() {
- return value;
- }
- }
+ Literal newInstance(double d);
- static class UniqueValueClass2 {
- String value;
+ Literal newInstance(float f);
- UniqueValueClass2(final String value) {
- this.value = value;
- }
+ Literal newInstance(int i);
+
+ Literal newInstance(long l);
+
+ Literal newInstance(String val, String lang);
+
+ Literal newInstance(Object o);
- @Override
- public String toString() {
- return value;
- }
}
+ private LiteralProducer lp;
+
+ public abstract LiteralProducer getLiteralProducer();
+
@Before
- final public void setupAbstractLiteralTest() {
- model = getModelProducer().newModel();
- X = resource("X");
- P = property("P");
+ public final void beforeLiteralContractTests() {
+ lp = getLiteralProducer();
}
- /**
- * Test that a literal node can be as'ed into a literal.
- */
@Test
- public void testAsLiteral() {
- literal("17").as(Literal.class);
+ public void testEquals() {
+
+ // boolean
+ Literal l1 = lp.newInstance(true);
+ Literal l2 = lp.newInstance(true);
+ assertEquivalent("error with equals boolean", l1, l2);
+
+ l2 = lp.newInstance(false);
+ assertNotEquivalent("error with not equals boolean", l1, l2);
+
+ // byte
+ byte b = 1;
+ byte b2 = 2;
+ l1 = lp.newInstance(b);
+ l2 = lp.newInstance(b);
+ assertEquivalent("error with equals boolean", l1, l2);
+
+ l2 = lp.newInstance(b2);
+ assertNotEquivalent("error with not equals boolean", l1, l2);
+
+ // char
+ char c = 'c';
+ char c2 = 'd';
+ l1 = lp.newInstance(c);
+ l2 = lp.newInstance(c);
+ assertEquivalent("error with equals boolean", l1, l2);
+
+ l2 = lp.newInstance(c2);
+ assertNotEquivalent("error with not equals boolean", l1, l2);
+
+ // double
+ double d = 4.5d;
+ double d2 = 5.6d;
+
+ l1 = lp.newInstance(d);
+ l2 = lp.newInstance(d);
+ assertEquivalent("error with equals boolean", l1, l2);
+
+ l2 = lp.newInstance(d2);
+ assertNotEquivalent("error with not equals boolean", l1, l2);
+
+ // Float
+ float f = 4.5f;
+ float f2 = 5.6f;
+ l1 = lp.newInstance(f);
+ l2 = lp.newInstance(f);
+ assertEquivalent("error with equals boolean", l1, l2);
+
+ l2 = lp.newInstance(f2);
+ assertNotEquivalent("error with not equals boolean", l1, l2);
+
+ // Int
+ int i = 4;
+ int i2 = 5;
+ l1 = lp.newInstance(i);
+ l2 = lp.newInstance(i);
+ assertEquivalent("error with equals boolean", l1, l2);
+
+ l2 = lp.newInstance(i2);
+ assertNotEquivalent("error with not equals boolean", l1, l2);
+
+ // Long
+ long ln = 4L;
+ long ln2 = 5L;
+ l1 = lp.newInstance(ln);
+ l2 = lp.newInstance(ln);
+ assertEquivalent("error with equals boolean", l1, l2);
+
+ l2 = lp.newInstance(ln2);
+ assertNotEquivalent("error with not equals boolean", l1, l2);
+
+ // Short
+ short s = 4;
+ short s2 = 5;
+ l1 = lp.newInstance(s);
+ l2 = lp.newInstance(s);
+ assertEquivalent("error with equals boolean", l1, l2);
+
+ l2 = lp.newInstance(s2);
+ assertNotEquivalent("error with not equals boolean", l1, l2);
+
+ // String
+ String st = "foo";
+ String st2 = "bar";
+ l1 = lp.newInstance(st, "en");
+ l2 = lp.newInstance(st, "en");
+ assertEquivalent("error with equals boolean", l1, l2);
+
+ l2 = lp.newInstance(st2, "en");
+ assertNotEquivalent("error with not equals boolean", l1, l2);
+
+ l1 = lp.newInstance(st, "en");
+ l2 = lp.newInstance(st, "fr");
+ assertNotEquivalent("error with not equals boolean", l1, l2);
+
}
/**
- * Test that a non-literal node cannot be as'ed into a literal
+ * Test that a literal node can be as'ed into a literal.
*/
@Test
- public void testCannotAsNonLiteral() {
- try {
- resource("plumPie").as(Literal.class);
- Assert.fail("non-literal cannot be converted to literal");
- } catch (final LiteralRequiredException l) {
- // expected
- }
- }
+ public void testAsLiteral() {
+
+ // boolean
+ lp.newInstance(true).as(Literal.class);
+
+ // byte
+ byte b = 1;
+ lp.newInstance(b).as(Literal.class);
+
+ // char
+ char c = 'c';
+ lp.newInstance(c).as(Literal.class);
+ // double
+ double d = 4.5d;
+ lp.newInstance(d).as(Literal.class);
+
+ // Float
+ float f = 4.5f;
+ lp.newInstance(f).as(Literal.class);
+
+ // Int
+ int i = 5;
+ lp.newInstance(i).as(Literal.class);
+
+ // Long
+ long ln = 4L;
+ lp.newInstance(ln).as(Literal.class);
+
+ // Short
+ short s = 4;
+ lp.newInstance(s).as(Literal.class);
+
+ // String
+ String st = "foo";
+ lp.newInstance(st, "en").as(Literal.class);
- @Test
- public void testInModel() {
- final Model m2 = getModelProducer().newModel();
- final Literal l1 = model.createLiteral("17");
- final Literal l2 = l1.inModel(m2);
- Assert.assertEquals(l1, l2);
- Assert.assertSame(m2, l2.getModel());
- }
-
- @Test
- public void testLiteralHasModel() {
- testLiteralHasModel(model, model.createLiteral("hello, world"));
- testLiteralHasModel(model, model.createLiteral("hello, world", "en-UK"));
- testLiteralHasModel(model, model.createLiteral("hello, world", true));
- testLiteralHasModel(model, model.createTypedLiteral("hello, world"));
- testLiteralHasModel(model, model.createTypedLiteral(false));
- testLiteralHasModel(model, model.createTypedLiteral(17));
- testLiteralHasModel(model, model.createTypedLiteral('x'));
- }
-
- private void testLiteralHasModel(final Model m, final Literal lit) {
- Assert.assertSame(m, lit.getModel());
- }
-
- @Test
- public void testSameAdhocClassUS() {
- try {
- final UniqueValueClass1 ra = new UniqueValueClass1("rhubarb");
- final UniqueValueClass1 rb = new UniqueValueClass1("cottage");
- Assert.assertNull("not expecting registered RDF Datatype",
- TypeMapper.getInstance().getTypeByValue(ra));
- final Literal la = model.createTypedLiteral(ra); // Sets the type
- // mapper
- // - contaminates it
- // with
- // UniqueValueClass1
- final Literal lb = model.createTypedLiteral(rb);
- assertInstanceOf(AdhocDatatype.class, la.getDatatype());
- Assert.assertSame(la.getDatatype(), lb.getDatatype());
- Assert.assertNotNull(TypeMapper.getInstance().getTypeByValue(ra));
- } finally {
- TypeMapper.reset();
- }
- }
-
- // Tests are not necessarily run in order so use UniqueValueClass2
- @Test
- public void testTypedLiteralTypesAndValues() {
- // Resource r = model.createResource( "eh:/rhubarb" );
- final UniqueValueClass2 r = new UniqueValueClass2("rhubarb");
- Assert.assertNull("not expecting registered RDF Datatype", TypeMapper
- .getInstance().getTypeByValue(r));
- final Literal typed = model.createTypedLiteral(r); // Sets the type
- // mapper -
- // contaminates it
- // with
- // UniqueValueClass2
- final Literal string = model.createLiteral(r.value);
- Assert.assertEquals(string.getLexicalForm(), typed.getLexicalForm());
- Assert.assertEquals(string.getLanguage(), typed.getLanguage());
- assertDiffer(string.getDatatypeURI(), typed.getDatatypeURI());
- Assert.assertNotNull(
- "a datatype should have been invented for Resource[Impl]",
- typed.getDatatype());
- assertDiffer(typed, string);
- assertDiffer(typed.getValue(), string.getValue());
- Assert.assertEquals(r, typed.getValue());
- assertDiffer(typed.hashCode(), string.hashCode());
}
+ // // Tests are not necessarily run in order so use UniqueValueClass2
+ // @Test
+ // public void testTypedLiteralTypesAndValues() {
+ // // Resource r = model.createResource( "eh:/rhubarb" );
+ // final UniqueValueClass2 r = new UniqueValueClass2("rhubarb");
+ // Assert.assertNull("not expecting registered RDF Datatype", TypeMapper
+ // .getInstance().getTypeByValue(r));
+ // final Literal typed = model.createTypedLiteral(r); // Sets the type
+ // // mapper -
+ // // contaminates it
+ // // with
+ // // UniqueValueClass2
+ // final Literal string = model.createLiteral(r.value);
+ // Assert.assertEquals(string.getLexicalForm(), typed.getLexicalForm());
+ // Assert.assertEquals(string.getLanguage(), typed.getLanguage());
+ // assertDiffer(string.getDatatypeURI(), typed.getDatatypeURI());
+ // Assert.assertNotNull(
+ // "a datatype should have been invented for Resource[Impl]",
+ // typed.getDatatype());
+ // assertDiffer(typed, string);
+ // assertDiffer(typed.getValue(), string.getValue());
+ // Assert.assertEquals(r, typed.getValue());
+ // assertDiffer(typed.hashCode(), string.hashCode());
+ // }
+
protected void assertInRange(final long min, final long x, final long max) {
if ((min <= x) && (x <= max)) {
return;
@@ -180,274 +258,2071 @@ public abstract class AbstractLiteralTes
}
@Test
- public void testBooleans() {
- Assert.assertTrue(model.createTypedLiteral(true).getBoolean());
- Assert.assertFalse(model.createTypedLiteral(false).getBoolean());
+ public void testGetBoolean_boolean() {
+ assertTrue(lp.newInstance(true).getBoolean());
+ assertFalse(lp.newInstance(false).getBoolean());
}
- protected void testByte(final Model model, final byte tv) {
- final Literal l = model.createTypedLiteral(tv);
- Assert.assertEquals(tv, l.getByte());
- Assert.assertEquals(tv, l.getShort());
- Assert.assertEquals(tv, l.getInt());
- Assert.assertEquals(tv, l.getLong());
+ @Test
+ public void testGetBoolean_int() {
+ int i = 1;
+ try {
+ lp.newInstance(i).getBoolean();
+ fail("Should have thrown DatatypeFormatException");
+ }
+ catch (DatatypeFormatException expected)
+ {
+ // expected
+ }
+ }
+
+ @Test
+ public void testGetBoolean_long() {
+ // long
+ long l = 1;
+ try {
+ lp.newInstance(l).getBoolean();
+ fail("Should have thrown DatatypeFormatException");
+ } catch (DatatypeFormatException expected) {
+ // expected
+ }
}
@Test
- public void testByteLiterals() {
- testByte(model, (byte) 0);
- testByte(model, (byte) -1);
- testByte(model, Byte.MIN_VALUE);
- testByte(model, Byte.MAX_VALUE);
+ public void testGetBoolean_float() {
+ float f = 1;
+ try {
+ lp.newInstance(f).getBoolean();
+ fail("Should have thrown DatatypeFormatException");
+ }
+ catch (DatatypeFormatException expected)
+ {
+ // expected
+ }
+ }
+
+ @Test
+ public void testGetBoolean_double() {
+ double d = 1;
+ try {
+ lp.newInstance(d).getBoolean();
+ fail( "Should have thrown DatatypeFormatException");
+ }
+ catch (DatatypeFormatException expected)
+ {
+ // expected
+ } }
+
+ @Test
+ public void testGetBoolean_string() {
+ String s = "true";
+ String l = "en";
+ assertTrue(lp.newInstance(s, l).getBoolean());
+ s = "false";
+ assertFalse(lp.newInstance(s, l).getBoolean());
+ s = "1";
+ try {
+ lp.newInstance(s, l).getBoolean();
+ fail("Should have thrown BadBooleanException");
+ }
+ catch (BadBooleanException expected)
+ {
+ // expected
+ }
+ s = "0";
+ try {
+ lp.newInstance(s, l).getBoolean();
+ fail("Should have thrown BadBooleanException");
+ }
+ catch (BadBooleanException expected)
+ {
+ // expected
+ }
}
- protected void testCharacter(final Model model, final char tv) {
- Assert.assertEquals(tv, model.createTypedLiteral(tv).getChar());
+ @Test
+ public void testGetBoolean_char() {
+ char c = 0x1;
+ try {
+ lp.newInstance(c).getBoolean();
+ fail("Should have thrown DatatypeFormatException");
+ } catch (DatatypeFormatException expected) {
+ // expected
+ }
}
@Test
- public void testCharacterLiterals() {
- testCharacter(model, 'A');
- testCharacter(model, 'a');
- testCharacter(model, '#');
- testCharacter(model, '@');
- testCharacter(model, '0');
- testCharacter(model, '9');
- testCharacter(model, '\u1234');
- testCharacter(model, '\u5678');
+ public void testGetByte_boolean() {
+ byte b = 1;
+ try {
+ lp.newInstance(true).getByte();
+ fail( "Should have thrown DatatypeFormatException");
+ }
+ catch (DatatypeFormatException expected)
+ {
+ // expected
+ }
}
- protected void testDouble(final Model model, final double tv) {
- Assert.assertEquals(tv, model.createTypedLiteral(tv).getDouble(),
- dDelta);
+ @Test
+ public void testGetByte_int() {
+ // int
+ int i = 1;
+ assertEquals(i, lp.newInstance(i).getByte());
+ i = 0;
+ assertEquals(i, lp.newInstance(i).getByte());
+
+ i = Byte.MAX_VALUE;
+ assertEquals(i, lp.newInstance(i).getByte());
+
+ i = Short.MAX_VALUE;
+ try {
+ lp.newInstance(i).getByte();
+ fail("Should have thrown IllegalArgumentException");
+ } catch (IllegalArgumentException expected) {
+ // expected
+ }
+
+ i = Short.MIN_VALUE;
+ try {
+ lp.newInstance(i).getByte();
+ fail("Should have thrown IllegalArgumentException");
+ } catch (IllegalArgumentException expected) {
+ // expected
+ }
+
}
@Test
- public void testDoubleLiterals() {
- testDouble(model, 0.0);
- testDouble(model, 1.0);
- testDouble(model, -1.0);
- testDouble(model, 12345.678901);
- testDouble(model, Double.MIN_VALUE);
- testDouble(model, Double.MAX_VALUE);
+ public void testGetByte_long() {
+ // long
+ long l = 1;
+ assertEquals(l, lp.newInstance(l).getByte());
+ l = 0;
+ assertEquals(l, lp.newInstance(l).getByte());
+ l = Byte.MAX_VALUE;
+ assertEquals(l, lp.newInstance(l).getByte());
+
+ l = Byte.MAX_VALUE;
+ l += 1;
+ try {
+ lp.newInstance(l).getByte();
+ fail("Should have thrown IllegalArgumentException");
+ } catch (IllegalArgumentException expected) {
+ // expected
+ }
+
+ l = Byte.MIN_VALUE;
+ l -= 1;
+ try {
+ lp.newInstance(l).getByte();
+ fail("Should have thrown IllegalArgumentException");
+ } catch (IllegalArgumentException expected) {
+ // expected
+ }
+
}
- protected void testFloat(final Model model, final float tv) {
- Assert.assertEquals(tv, model.createTypedLiteral(tv).getFloat(), fDelta);
+ @Test
+ public void testGetByte_float() {
+ float f = 1;
+ byte b = 1;
+ assertEquals(b, lp.newInstance(f).getByte());
+ f = 0;
+ b = 0;
+ assertEquals(b, lp.newInstance(f).getByte());
+ f = Byte.MAX_VALUE;
+ b = Byte.MAX_VALUE;
+ assertEquals(b, lp.newInstance(f).getByte());
+
+ f = Byte.MAX_VALUE;
+ f += 1;
+ try {
+ lp.newInstance(f).getByte();
+ fail("Should have thrown IllegalArgumentException");
+ } catch (IllegalArgumentException expected) {
+ // expected
+ }
+
+ f = Byte.MIN_VALUE;
+ b = Byte.MIN_VALUE;
+ assertEquals(b, lp.newInstance(f).getByte());
+ f = Byte.MIN_VALUE;
+ f -= 1;
+ try {
+ lp.newInstance(f).getByte();
+ fail("Should have thrown IllegalArgumentException");
+ } catch (IllegalArgumentException expected) {
+ // expected
+ }
+
+ f = 1.5f; // non integer value
+ assertEquals( 1, lp.newInstance(f).getByte());
}
@Test
- public void testFloatLiterals() {
- testFloat(model, 0.0f);
- testFloat(model, 1.0f);
- testFloat(model, -1.0f);
- testFloat(model, 12345.6789f);
- testFloat(model, Float.MIN_VALUE);
- testFloat(model, Float.MAX_VALUE);
+ public void testGetByte_double() {
+
+ byte b = 1;
+ double d = b;
+ assertEquals(b, lp.newInstance(d).getByte());
+ b = 0;
+ d = 0;
+ assertEquals(b, lp.newInstance(d).getByte());
+
+ d = Byte.MAX_VALUE;
+ b = Byte.MAX_VALUE;
+ assertEquals(b, lp.newInstance(d).getByte());
+
+ d = Byte.MAX_VALUE;
+ d += 1;
+ try {
+ lp.newInstance(d).getByte();
+ fail("Should have thrown IllegalArgumentException");
+ } catch (IllegalArgumentException expected) {
+ // expected
+ }
+
+ d = Byte.MIN_VALUE;
+ b = Byte.MIN_VALUE;
+ assertEquals(b, lp.newInstance(d).getByte());
+
+ d = Byte.MIN_VALUE;
+ d -= 1;
+ try {
+ lp.newInstance(d).getByte();
+ fail("Should have thrown IllegalArgumentException");
+ } catch (IllegalArgumentException expected) {
+ // expected
+ }
}
- // public void testLiteralObjects()
- // {
- // // testLiteralObject( model, 0 );
- // // testLiteralObject( model, 12345 );
- // // testLiteralObject( model, -67890 );
- // }
+ @Test
+ public void testGetByte_string() {
+ String s = "true";
+ String l = "en";
+ try {
+ lp.newInstance(s, l).getByte();
+ fail("Should have thrown NumberFormatException");
+ } catch (NumberFormatException expected) {
+ // expected
+ }
+ s = "1";
+ byte b = 1;
+ assertEquals(b, lp.newInstance(s, l).getByte());
+ s = "0";
+ b = 0;
+ assertEquals(b, lp.newInstance(s, l).getByte());
+ s = Integer.toString(Byte.MAX_VALUE + 1);
+ try {
+ lp.newInstance(s, l).getByte();
+ fail("Should have thrown NumberFormatException");
+ } catch (NumberFormatException expected) {
+ // expected
+ }
- protected void testInt(final Model model, final int tv) {
- final Literal l = model.createTypedLiteral(tv);
+ s = Integer.toString(Byte.MIN_VALUE - 1);
try {
- Assert.assertEquals(tv, l.getByte());
- assertInRange(Byte.MIN_VALUE, tv, Byte.MAX_VALUE);
- } catch (final NumberFormatException e) {
- assertOutsideRange(Byte.MIN_VALUE, tv, Byte.MAX_VALUE);
- } catch (final IllegalArgumentException e) {
- assertOutsideRange(Byte.MIN_VALUE, tv, Byte.MAX_VALUE);
+ lp.newInstance(s, l).getByte();
+ fail("Should have thrown NumberFormatException");
+ } catch (NumberFormatException expected) {
+ // expected
}
+ }
+
+ @Test
+ public void testGetByte_char() {
+ char c = 0x1;
try {
- Assert.assertEquals(tv, l.getShort());
- assertInRange(Short.MIN_VALUE, tv, Short.MAX_VALUE);
- } catch (final NumberFormatException e) {
- assertOutsideRange(Short.MIN_VALUE, tv, Short.MAX_VALUE);
- } catch (final IllegalArgumentException e) {
- assertOutsideRange(Short.MIN_VALUE, tv, Short.MAX_VALUE);
+ lp.newInstance(c).getByte();
+ fail("Should have thrown DatatypeFormatException");
+ } catch (DatatypeFormatException expected) {
+ // expected
}
- Assert.assertEquals(tv, l.getInt());
- Assert.assertEquals(tv, l.getLong());
}
@Test
- public void testIntLiterals() {
- testInt(model, 0);
- testInt(model, -1);
- testInt(model, Integer.MIN_VALUE);
- testInt(model, Integer.MAX_VALUE);
+ public void testGetChar_boolean() {
+ try {
+ lp.newInstance(true).getChar();
+ fail("Should have thrown DatatypeFormatException");
+ }
+ catch (DatatypeFormatException expected)
+ {
+ // expected
+ }
+ }
+
+ @Test
+ public void testGetChar_int() {
+ // int
+ int i = 1;
+ try {
+ lp.newInstance(i).getChar();
+ fail("Should have thrown DatatypeFormatException");
+ } catch (DatatypeFormatException expected) {
+ // expected
+ }
+ }
+
+ @Test
+ public void testGetChar_long() {
+ // long
+ long l = 1;
+ try {
+ lp.newInstance(l).getChar();
+ fail("Should have thrown DatatypeFormatException");
+ } catch (DatatypeFormatException expected) {
+ // expected
+ }
+
}
- protected void testLanguagedString(final Model model, final String tv,
- final String lang) {
- final Literal l = model.createLiteral(tv, lang);
- Assert.assertEquals(tv, l.getString());
- Assert.assertEquals(tv, l.getLexicalForm());
- Assert.assertEquals(lang, l.getLanguage());
+ @Test
+ public void testGetChar_float() {
+ float f = 1.0f;
+ float delta = 0.0f;
+ try {
+ lp.newInstance(f).getChar();
+ } catch (DatatypeFormatException expected) {
+ // expected
+ }
}
@Test
- public void testLanguagedStringLiterals() {
- testLanguagedString(model, "", "en");
- testLanguagedString(model, "chat", "fr");
+ public void testGetChar_double() {
+ double d = 1;
+ try {
+ lp.newInstance(d).getChar();
+ fail( "Should have thrown DatatypeFormatException");
+ }
+ catch (DatatypeFormatException expected)
+ {
+ // expected
+ }
}
- protected void testLong(final Model model, final long tv) {
- final Literal l = model.createTypedLiteral(tv);
+ @Test
+ public void testGetChar_string() {
+ String s = "true";
+ String l = "en";
try {
- Assert.assertEquals(tv, l.getByte());
- assertInRange(Byte.MIN_VALUE, tv, Byte.MAX_VALUE);
- } catch (final NumberFormatException e) {
- assertOutsideRange(Byte.MIN_VALUE, tv, Byte.MAX_VALUE);
- } catch (final IllegalArgumentException e) {
- assertOutsideRange(Byte.MIN_VALUE, tv, Byte.MAX_VALUE);
+ assertEquals(s, lp.newInstance(s, l).getChar());
+ fail( "Should have thrown BadCharLiteralException");
}
+ catch (BadCharLiteralException expected)
+ {
+ // expected
+ }
+ s = "1";
+ char c = '1';
+ assertEquals(c, lp.newInstance(s, l).getChar());
+
+ s = Character.toString( Character.MAX_VALUE );
+ assertEquals(Character.MAX_VALUE, lp.newInstance(s, l).getChar());
+
+ s += "0";
try {
- Assert.assertEquals(tv, l.getShort());
- assertInRange(Short.MIN_VALUE, tv, Short.MAX_VALUE);
- } catch (final NumberFormatException e) {
- assertOutsideRange(Short.MIN_VALUE, tv, Short.MAX_VALUE);
- } catch (final IllegalArgumentException e) {
- assertOutsideRange(Short.MIN_VALUE, tv, Short.MAX_VALUE);
+ lp.newInstance(s, l).getChar();
}
+ catch (BadCharLiteralException expected) {
+ // expected
+ }
+ s = Character.toString( Character.MIN_VALUE );
+ assertEquals(Character.MIN_VALUE, lp.newInstance(s, l).getChar());
+
+ s += "0";
try {
- Assert.assertEquals(tv, l.getInt());
- assertInRange(Integer.MIN_VALUE, tv, Integer.MAX_VALUE);
- } catch (final NumberFormatException e) {
- assertOutsideRange(Integer.MIN_VALUE, tv, Integer.MAX_VALUE);
- } catch (final IllegalArgumentException e) {
- assertOutsideRange(Integer.MIN_VALUE, tv, Integer.MAX_VALUE);
+ lp.newInstance(s, l).getChar();
+ }
+ catch (BadCharLiteralException expected) {
+ // expected
}
- Assert.assertEquals(tv, l.getLong());
}
@Test
- public void testLongLiterals() {
- testLong(model, 0);
- testLong(model, -1);
- testLong(model, Long.MIN_VALUE);
- testLong(model, Long.MAX_VALUE);
+ public void testGetChar_char() {
+ char c = 0x1;
+ assertEquals(c, lp.newInstance(c).getChar());
+ c = 0x0;
+ assertEquals(c, lp.newInstance(c).getChar());
+ c = '1';
+ assertEquals(c, lp.newInstance(c).getChar());
+ c = '0';
+ assertEquals(c, lp.newInstance(c).getChar());
+ }
+
+ @Test
+ public void testGetDatatype_boolean() {
+ assertEquals(XSDDatatype.XSDboolean, lp.newInstance(true).getDatatype());
+ }
+
+ @Test
+ public void testGetDatatype_int() {
+ // byte
+ byte b = 1;
+ assertEquals(XSDDatatype.XSDint, lp.newInstance(b).getDatatype());
+
+ // short
+ short s = 1;
+ assertEquals(XSDDatatype.XSDint, lp.newInstance(s).getDatatype());
+
+ // int
+ int i = 1;
+ assertEquals(XSDDatatype.XSDint, lp.newInstance(i).getDatatype());
+ }
+
+ @Test
+ public void testGetDatatype_long() {
+ // long
+ long l = 1;
+ assertEquals(XSDDatatype.XSDlong, lp.newInstance(l).getDatatype());
+ }
+
+ @Test
+ public void testGetDatatype_float() {
+ float f = 1;
+ assertEquals(XSDDatatype.XSDfloat, lp.newInstance(f).getDatatype());
+ }
+
+ @Test
+ public void testGetDatatype_double() {
+ double d = 1;
+ assertEquals(XSDDatatype.XSDdouble, lp.newInstance(d).getDatatype());
+ }
+
+ @Test
+ public void testGetDatatype_string() {
+ char c = 0x1;
+ assertEquals(XSDDatatype.XSDstring, lp.newInstance(c).getDatatype());
+
+ String s = "true";
+ String l = "en";
+ assertNull(lp.newInstance(s, l).getDatatype());
+
+
}
- protected void testPlainString(final Model model, final String tv) {
- final Literal l = model.createLiteral(tv);
- Assert.assertEquals(tv, l.getString());
- Assert.assertEquals(tv, l.getLexicalForm());
- Assert.assertEquals("", l.getLanguage());
+ @Test
+ public void testGetDatatypeURI_boolean() {
+ assertEquals(XSDDatatype.XSDboolean.getURI(), lp.newInstance(true)
+ .getDatatypeURI());
+ assertEquals(XSDDatatype.XSDboolean.getURI(), lp.newInstance(false)
+ .getDatatypeURI());
}
@Test
- public void testPlainStringLiterals() {
- testPlainString(model, "");
- testPlainString(model, "A test string");
- testPlainString(model, "Another test string");
+ public void testGetDatatypeURI_int() {
+ // byte
+ byte b = 1;
+ assertEquals(XSDDatatype.XSDint.getURI(), lp.newInstance(b)
+ .getDatatypeURI());
+
+ // short
+ short s = 1;
+ assertEquals(XSDDatatype.XSDint.getURI(), lp.newInstance(s)
+ .getDatatypeURI());
+
+ // int
+ int i = 1;
+ assertEquals(XSDDatatype.XSDint.getURI(), lp.newInstance(i)
+ .getDatatypeURI());
}
- protected void testShort(final Model model, final short tv) {
- final Literal l = model.createTypedLiteral(tv);
+ @Test
+ public void testGetDatatypeURI_long() {
+ // long
+ long l = 1;
+ assertEquals(XSDDatatype.XSDlong.getURI(), lp.newInstance(l)
+ .getDatatypeURI());
+ l = 0;
+ assertEquals(XSDDatatype.XSDlong.getURI(), lp.newInstance(l)
+ .getDatatypeURI());
+ l = 0x7fffffff; // bit pattern ends in 1
+ assertEquals(XSDDatatype.XSDlong.getURI(), lp.newInstance(l)
+ .getDatatypeURI());
+ l = 0x7ffffffe; // bit pattern ends in 0
+ assertEquals(XSDDatatype.XSDlong.getURI(), lp.newInstance(l)
+ .getDatatypeURI());
+ }
+
+ @Test
+ public void testGetDatatypeURI_float() {
+ float f = 1;
+ assertEquals(XSDDatatype.XSDfloat.getURI(), lp.newInstance(f)
+ .getDatatypeURI());
+ f = 0;
+ assertEquals(XSDDatatype.XSDfloat.getURI(), lp.newInstance(f)
+ .getDatatypeURI());
+ f = 7; // bit pattern ends in 1
+ assertEquals(XSDDatatype.XSDfloat.getURI(), lp.newInstance(f)
+ .getDatatypeURI());
+ f = 6; // bit pattern ends in 0
+ assertEquals(XSDDatatype.XSDfloat.getURI(), lp.newInstance(f)
+ .getDatatypeURI());
+ }
+
+ @Test
+ public void testGetDatatypeURI_double() {
+ double d = 1;
+ assertEquals(XSDDatatype.XSDdouble.getURI(), lp.newInstance(d)
+ .getDatatypeURI());
+ d = 0;
+ assertEquals(XSDDatatype.XSDdouble.getURI(), lp.newInstance(d)
+ .getDatatypeURI());
+ d = 7; // bit pattern ends in 1
+ assertEquals(XSDDatatype.XSDdouble.getURI(), lp.newInstance(d)
+ .getDatatypeURI());
+ d = 6; // bit pattern ends in 0
+ assertEquals(XSDDatatype.XSDdouble.getURI(), lp.newInstance(d)
+ .getDatatypeURI());
+ }
+
+ @Test
+ public void testGetDatatypeURI_string() {
+ String s = "true";
+ String l = "en";
+ assertNull(lp.newInstance(s, l).getDatatypeURI());
+ }
+
+ @Test
+ public void testGetDatatypeURI_char() {
+ char c = 0x1;
+ assertEquals(XSDDatatype.XSDstring.getURI(), lp.newInstance(c)
+ .getDatatypeURI());
+ c = 0x0;
+ assertEquals(XSDDatatype.XSDstring.getURI(), lp.newInstance(c)
+ .getDatatypeURI());
+ c = '1';
+ assertEquals(XSDDatatype.XSDstring.getURI(), lp.newInstance(c)
+ .getDatatypeURI());
+ c = '0';
+ assertEquals(XSDDatatype.XSDstring.getURI(), lp.newInstance(c)
+ .getDatatypeURI());
+ }
+
+ @Test
+ public void testGetInt_boolean() {
try {
- Assert.assertEquals(tv, l.getByte());
- assertInRange(Byte.MIN_VALUE, tv, Byte.MAX_VALUE);
- } catch (final NumberFormatException e) {
- assertOutsideRange(Byte.MIN_VALUE, tv, Byte.MAX_VALUE);
- } catch (final IllegalArgumentException e) {
- assertOutsideRange(Byte.MIN_VALUE, tv, Byte.MAX_VALUE);
+ lp.newInstance(true).getInt();
+ fail( "Should have thrown DatatypeFormatException");
+ }
+ catch (DatatypeFormatException expected)
+ {
+ // expected
}
- Assert.assertEquals(tv, l.getShort());
- Assert.assertEquals(tv, l.getInt());
- Assert.assertEquals(tv, l.getLong());
}
+
@Test
- public void testShortLiterals() {
- testShort(model, (short) 0);
- testShort(model, (short) -1);
- testShort(model, Short.MIN_VALUE);
- testShort(model, Short.MAX_VALUE);
+ public void testGetInt_int() {
+ // int
+ int i = 1;
+ assertEquals(i, lp.newInstance(i).getInt());
+ i = 0;
+ assertEquals(i, lp.newInstance(i).getInt());
+ i = Byte.MAX_VALUE;
+ assertEquals(i, lp.newInstance(Byte.MAX_VALUE).getInt());
+
+ i = Byte.MIN_VALUE;
+ assertEquals(i, lp.newInstance(Byte.MIN_VALUE).getInt());
+
+ i = Short.MAX_VALUE;
+ assertEquals(i, lp.newInstance(Short.MAX_VALUE).getInt());
+
+ i = Short.MIN_VALUE;
+ assertEquals(i, lp.newInstance(Short.MIN_VALUE).getInt());
+
+ i = Integer.MAX_VALUE;
+ assertEquals(i, lp.newInstance(Integer.MAX_VALUE).getInt());
+
+ i = Integer.MIN_VALUE;
+ assertEquals(i, lp.newInstance(Integer.MIN_VALUE).getInt());
}
@Test
- public void testStringLiteralEquality() {
- Assert.assertEquals(model.createLiteral("A"), model.createLiteral("A"));
- Assert.assertEquals(model.createLiteral("Alpha"),
- model.createLiteral("Alpha"));
- assertDiffer(model.createLiteral("Alpha"), model.createLiteral("Beta"));
- assertDiffer(model.createLiteral("A", "en"), model.createLiteral("A"));
- assertDiffer(model.createLiteral("A"), model.createLiteral("A", "en"));
- assertDiffer(model.createLiteral("A", "en"),
- model.createLiteral("A", "fr"));
- Assert.assertEquals(model.createLiteral("A", "en"),
- model.createLiteral("A", "en"));
+ public void testGetInt_long() {
+ // long
+ long l = 1;
+ assertEquals(1, lp.newInstance(l).getInt());
+ l = 0;
+ assertEquals(0, lp.newInstance(l).getInt());
+
+ try {
+ lp.newInstance(Long.MAX_VALUE).getInt();
+ fail( "Should have thrown IllegalArgumentException");
+ }
+ catch (IllegalArgumentException expected) {
+ // expected
+ }
+
+ try {
+ lp.newInstance(Long.MIN_VALUE).getInt();
+ fail( "Should have thrown IllegalArgumentException");
+ }
+ catch (IllegalArgumentException expected) {
+ // expected
+ }
}
- // protected void testLiteralObject( Model model, int x )
- // {
- // LitTestObj tv = new LitTestObj( x );
- // LitTestObjF factory = new LitTestObjF();
- // assertEquals( tv, model.createTypedLiteral( tv ).getObject( factory ) );
- // }
+ @Test
+ public void testGetInt_float() {
+ float f = 1;
+ int i = 1;
+ assertEquals(i, lp.newInstance(f).getInt());
+ f = 0;
+ i = 0;
+ assertEquals(i, lp.newInstance(f).getInt());
+ f = Integer.MAX_VALUE;
+ // this will fail because Float(MAX_INT) = 2.14748365E9 and MAX_INT=2147483647
+ // so when converting back the float version becomes 2147483650
+ try {
+ lp.newInstance(f).getInt();
+ fail( "Should have thrown IllegalArgumentException");
+ }
+ catch (IllegalArgumentException expected)
+ {
+ // expected
+ }
+
+ f = Integer.MIN_VALUE;
+ assertEquals(Integer.MIN_VALUE, lp.newInstance(f).getInt());
+ f = Integer.MIN_VALUE;
+ f -= 1e3f;
+ try {
+ lp.newInstance(f).getInt();
+ fail("Should have thrown IllegalArgumentException");
+ } catch (IllegalArgumentException expected) {
+ // expected
+ }
+
+ f = Float.MIN_VALUE; // just above 0
+ assertEquals( 0, lp.newInstance(f).getInt());
+
+ f = 1.7f; // truncates non integer value in range
+ assertEquals( 1, lp.newInstance(f).getInt());
+
+ }
@Test
- public void testAddWithBooleanObject() {
- model.addLiteral(X, P, true);
- Assert.assertTrue(model.contains(X, P, model.createTypedLiteral(true)));
- Assert.assertTrue(model.containsLiteral(X, P, true));
+ public void testGetInt_double() {
+ double d = 0.0;
+ int i = 0;
+ assertEquals(i, lp.newInstance(d).getInt());
+ d = 1.0;
+ i = 1;
+ assertEquals(i, lp.newInstance(d).getInt());
+ d = Integer.MAX_VALUE*1.0;
+ assertEquals(Integer.MAX_VALUE, lp.newInstance(d).getInt());
+
+ d = Integer.MAX_VALUE+1.0;
+ try {
+ lp.newInstance(d).getInt();
+ fail( "Should have thrown IllegalArgumentException");
+ }
+ catch (IllegalArgumentException expected ) {
+ // expected
+ }
+
+ d = Integer.MAX_VALUE*1.0;
+ assertEquals(Integer.MAX_VALUE, lp.newInstance(d).getInt());
+
+ d = Integer.MIN_VALUE-1.0;
+ try {
+ lp.newInstance(d).getInt();
+ fail( "Should have thrown IllegalArgumentException");
+ }
+ catch (IllegalArgumentException expected ) {
+ // expected
+ }
+
+ d = 1.7d; // truncates values in range
+ assertEquals(1, lp.newInstance(d).getInt());
+ }
+
+ @Test
+ public void testGetInt_string() {
+ String s = "true";
+ String l = "en";
+ try {
+ lp.newInstance(s, l).getInt();
+ fail("Should have thrown NumberFormatException");
+ } catch (NumberFormatException expected) {
+ // expected
+ }
+ s = "1";
+ int i = 1;
+ assertEquals(i, lp.newInstance(s, l).getInt());
+ s = "0";
+ i = 0;
+ assertEquals(i, lp.newInstance(s, l).getInt());
+
+ s = Integer.toString(Integer.MAX_VALUE);
+ assertEquals(Integer.MAX_VALUE, lp.newInstance(s, l).getInt());
+
+ s += "0";
+ try {
+ lp.newInstance(s, l).getInt();
+ fail("Should have thrown NumberFormatException");
+ }
+ catch (NumberFormatException expected)
+ {
+ // expected
+ }
+
+ s = Integer.toString(Integer.MIN_VALUE);
+ assertEquals(Integer.MIN_VALUE, lp.newInstance(s, l).getInt());
+
+ s += "0";
+ try {
+ lp.newInstance(s, l).getInt();
+ fail("Should have thrown NumberFormatException");
+ }
+ catch (NumberFormatException expected)
+ {
+ // expected
+ }
+ }
+
+ @Test
+ public void testGetInt_char() {
+ char c = 0x1;
+ try {
+ lp.newInstance(c).getInt();
+ fail( "Should have thrown DatatypeFormatException");
+ }
+ catch (DatatypeFormatException expected)
+ {
+ // expected
+ }
+ }
+
+ @Test
+ public void testGetFloat_boolean() {
+ try {
+ lp.newInstance(true).getFloat();
+ fail("Should have thrown DatatypeFormatException");
+ } catch (DatatypeFormatException expected) {
+ // expected
+ }
+ }
+
+
+ @Test
+ public void testGetFloat_int() {
+ // int
+ int i = 0;
+ float f = 0.0f;
+ float delta = 0.0f;
+ assertEquals(f, lp.newInstance(i).getFloat(),delta);
+ i = 1;
+ f = 1.0f;
+ assertEquals(f, lp.newInstance(i).getFloat(),delta);
+
+ i = Byte.MAX_VALUE;
+ f = i*1.0f;
+ assertEquals(f, lp.newInstance(i).getFloat(),delta);
+
+ i = Byte.MIN_VALUE;
+ f = i*1.0f;
+ assertEquals(f, lp.newInstance(i).getFloat(),delta);
+
+ i = Short.MAX_VALUE;
+ f = i*1.0f;
+ assertEquals(f, lp.newInstance(i).getFloat(),delta);
+
+ i = Short.MIN_VALUE;
+ f = i*1.0f;
+ assertEquals(f, lp.newInstance(i).getFloat(),delta);
+
+ i = Integer.MAX_VALUE;
+ f = i*1.0f;
+ assertEquals(f, lp.newInstance(i).getFloat(),delta);
+
+ i = Integer.MIN_VALUE;
+ f = i*1.0f;
+ assertEquals(f, lp.newInstance(i).getFloat(),delta);
+ }
+
+ @Test
+ public void testGetFloat_long() {
+ // long
+ long l = 0;
+ float f = 0.0f;
+ float delta = 0.0f;
+ assertEquals(f, lp.newInstance(l).getFloat(), delta);
+ l = 1;
+ f = 1.0f;
+ assertEquals(f, lp.newInstance(l).getFloat(), delta);
+ l = Long.MAX_VALUE;
+ f = l*1.0f;
+ assertEquals(f, lp.newInstance(l).getFloat(), delta);
+ l = Long.MIN_VALUE;
+ f = l*1.0f;
+ assertEquals(f, lp.newInstance(l).getFloat(), delta);
+ }
+
+ @Test
+ public void testGetFloat_float() {
+ float f = 1.0f;
+ float delta = 0.0f;
+ assertEquals(f, lp.newInstance(f).getFloat(), delta);
+ f = 0.0f;
+ assertEquals(f, lp.newInstance(f).getFloat(), delta);
+ f = Float.MAX_VALUE;
+ assertEquals(f, lp.newInstance(f).getFloat(), delta);
+ f = Float.MIN_VALUE;
+ assertEquals(f, lp.newInstance(f).getFloat(), delta);
+ f = Float.MAX_VALUE*-1.0f;
+ assertEquals(f, lp.newInstance(f).getFloat(), delta);
+ f = Float.MIN_VALUE*-1.0f;
+ assertEquals(f, lp.newInstance(f).getFloat(), delta);
+ }
+
+ @Test
+ public void testGetFloat_double() {
+ double d = 0.0d;
+ float f = 0.0f;
+ float delta = 0.0f;
+ assertEquals(f, lp.newInstance(d).getFloat(), delta);
+ d = 1.0d;
+ f = 1.0f;
+ assertEquals(f, lp.newInstance(d).getFloat(), delta);
+ d = Float.MAX_VALUE;
+ assertEquals(Float.MAX_VALUE, lp.newInstance(d).getFloat(), delta);
+ d = Float.MIN_VALUE;
+ assertEquals(Float.MIN_VALUE, lp.newInstance(d).getFloat(), delta);
+
+ assertEquals( Float.POSITIVE_INFINITY, lp.newInstance(Double.MAX_VALUE).getFloat(), delta );
+ d = Double.MAX_VALUE * -1.0;
+ assertEquals( Float.NEGATIVE_INFINITY, lp.newInstance(d).getFloat(), delta );
+
+ assertEquals( 0.0f, lp.newInstance(Double.MIN_VALUE).getFloat(), delta );
+ d = Double.MIN_VALUE * -1.0;
+ assertEquals( 0.0F, lp.newInstance(d).getFloat(), delta );
+
+ }
+
+ @Test
+ public void testGetFloat_string() {
+ String s = "true";
+ String l = "en";
+ try {
+ lp.newInstance(s, l).getFloat();
+ fail("Should thrown NumberFormatException");
+ } catch (NumberFormatException expected) {
+ // expected
+ }
+ s = "0";
+ float f = 0;
+ float delta = 0.0f;
+ assertEquals(f, lp.newInstance(s, l).getFloat(), delta);
+ s = "1";
+ f = 1;
+ assertEquals(f, lp.newInstance(s, l).getFloat(), delta);
+
+ s = Float.toString(Float.MAX_VALUE);
+
+ assertEquals(Float.MAX_VALUE, lp.newInstance(s, l).getFloat(), delta);
+
+ s += "0";
+ assertEquals(Float.POSITIVE_INFINITY, lp.newInstance(s, l).getFloat(), delta);
+
+ s = Float.toString(Float.MIN_VALUE);
+ assertEquals(Float.MIN_VALUE, lp.newInstance(s, l).getFloat(), delta);
+
+ // smaller than min_value becomes zero
+ s += "0";
+ assertEquals(0.0f, lp.newInstance(s, l).getFloat(), delta);
+
+ }
+
+ @Test
+ public void testGetFloat_char() {
+ char c = 0x1;
+ try {
+ lp.newInstance(c).getFloat();
+ fail( "Should have thrown DatatypeFormatException");
+ }
+ catch (DatatypeFormatException expected)
+ {
+ // expected
+ }
+ }
+
+ @Test
+ public void testGetDouble_boolean() {
+ try {
+ lp.newInstance(true).getDouble();
+ fail("Should have thrown DatatypeFormatException");
+ } catch (DatatypeFormatException expected) {
+ // expected
+ }
+ }
+
+ @Test
+ public void testGetDouble_int() {
+ // int
+ int i = 1;
+ double d = 1;
+ double delta = 0.0;
+ assertEquals(d, lp.newInstance(i).getDouble(), delta);
+ i = 0;
+ d = 0.0;
+ assertEquals(d, lp.newInstance(i).getDouble(), delta);
+
+ i = Byte.MAX_VALUE; // bit pattern ends in 1
+ d = i*1.0;
+ assertEquals(d, lp.newInstance(i).getDouble(), delta);
+ i = Byte.MIN_VALUE; // bit pattern ends in 0
+ d = i*1.0;
+ assertEquals(d, lp.newInstance(i).getDouble(), delta);
+
+ i = Short.MAX_VALUE; // bit pattern ends in 1
+ d = i*1.0;
+ assertEquals(d, lp.newInstance(i).getDouble(), delta);
+ i = Short.MIN_VALUE; // bit pattern ends in 0
+ d = i*1.0;
+ assertEquals(d, lp.newInstance(i).getDouble(), delta);
+
+
+ i = Integer.MAX_VALUE; // bit pattern ends in 1
+ d = i*1.0;
+ assertEquals(d, lp.newInstance(i).getDouble(), delta);
+ i = Integer.MIN_VALUE; // bit pattern ends in 0
+ d = i*1.0;
+ assertEquals(d, lp.newInstance(i).getDouble(), delta);
+ }
+
+ @Test
+ public void testGetDouble_long() {
+ // long
+ long l = 1;
+ double d = 1;
+ double delta = 0.0d;
+ assertEquals(d, lp.newInstance(l).getDouble(), delta);
+ l = 0;
+ d = 0;
+ assertEquals(d, lp.newInstance(l).getDouble(), delta);
+ l = Long.MAX_VALUE;
+ d = l*1.0;
+ assertEquals(d, lp.newInstance(l).getDouble(), delta);
+ l = Long.MIN_VALUE;
+ d = l*1.0;
+ assertEquals(d, lp.newInstance(l).getDouble(), delta);
+ }
+
+ @Test
+ public void testGetDouble_float() {
+ float f = 1;
+ double d = 1;
+ double delta = 0.0d;
+ assertEquals(d, lp.newInstance(f).getDouble(), delta);
+ f = 0;
+ d = 0;
+ assertEquals(d, lp.newInstance(f).getDouble(), delta);
+ f = Float.MAX_VALUE;
+ d = Float.MAX_VALUE;
+ assertEquals(d, lp.newInstance(f).getDouble(), delta);
+ f = Float.MIN_VALUE;
+ d = Float.MIN_VALUE;
+ assertEquals(d, lp.newInstance(f).getDouble(), delta);
+ }
+
+ @Test
+ public void testGetDouble_double() {
+ double d = 0.0d;
+ double delta = 0.0;
+ assertEquals(d, lp.newInstance(d).getDouble(), delta);
+ d = 1.0;
+ assertEquals(d, lp.newInstance(d).getDouble(), delta);
+ d = Double.MAX_VALUE;
+ assertEquals(d, lp.newInstance(d).getDouble(), delta);
+ d = Double.MIN_VALUE;
+ assertEquals(d, lp.newInstance(d).getDouble(), delta);
+ d = Double.MAX_VALUE*-1.0;
+ assertEquals(d, lp.newInstance(d).getDouble(), delta);
+ d = Double.MIN_VALUE*-1.0;
+ assertEquals(d, lp.newInstance(d).getDouble(), delta);
+ }
+
+ @Test
+ public void testGetDouble_string() {
+ double d;
+ double delta = 0.0;
+ String s = "true";
+ String l = "en";
+ try {
+ lp.newInstance(s, l).getDouble();
+ fail("Should have thrown NumberFormatException");
+ } catch (NumberFormatException expected) {
+ // expected result
+ }
+ s = "1.5";
+ d = 1.5;
+ assertEquals(d, lp.newInstance(s, l).getDouble(), delta);
+ s = "1";
+ d = 1.0;
+ assertEquals(d, lp.newInstance(s, l).getDouble(), delta);
+ s = "0";
+ d = 0.0;
+ assertEquals(d, lp.newInstance(s, l).getDouble(), delta);
+ }
+
+ @Test
+ public void testGetDouble_char() {
+ char c = 0x1;
+ try {
+ lp.newInstance(c).getDouble();
+ fail( "Should have thrown DatatypeFormatException");
+ }
+ catch (DatatypeFormatException expected)
+ {
+ // expected
+ }
+ }
+
+ @Test
+ public void testGetLanguage_boolean() {
+ assertEquals("", lp.newInstance(true).getLanguage());
+ }
+
+ @Test
+ public void testGetLanguage_int() {
+ // int
+ int i = 1;
+ assertEquals("", lp.newInstance(i).getLanguage());
+ }
+
+ @Test
+ public void testGetLanguage_long() {
+ // long
+ long l = 1;
+ assertEquals("", lp.newInstance(l).getLanguage());
+ }
+
+ @Test
+ public void testGetLanguage_float() {
+ float f = 1;
+ assertEquals("", lp.newInstance(f).getLanguage());
+ }
+
+ @Test
+ public void testGetLanguage_double() {
+ double d = 1;
+ assertEquals("", lp.newInstance(d).getLanguage());
+ }
+
+ @Test
+ public void testGetLanguage_string() {
+ String s = "true";
+ String l = "en";
+ assertEquals(l, lp.newInstance(s, l).getLanguage());
+ s = "false";
+ assertEquals(l, lp.newInstance(s, l).getLanguage());
+ s = "true";
+ l = "fr";
+ assertEquals(l, lp.newInstance(s, l).getLanguage());
+ s = "false";
+ assertEquals(l, lp.newInstance(s, l).getLanguage()); }
+
+ @Test
+ public void testGetLanguage_char() {
+ char c = 0x1;
+ assertEquals("", lp.newInstance(c).getLanguage());
}
@Test
- public void testAddWithCharObject() {
- model.addLiteral(X, P, 'x');
- Assert.assertTrue(model.contains(X, P, model.createTypedLiteral('x')));
- Assert.assertTrue(model.containsLiteral(X, P, 'x'));
+ public void testGetLexicalForm_boolean() {
+ assertEquals("true", lp.newInstance(true).getLexicalForm());
+ assertEquals("false", lp.newInstance(false).getLexicalForm());
}
@Test
- public void testAddWithDoubleObject() {
- model.addLiteral(X, P, 14.0d);
- Assert.assertTrue(model.contains(X, P, model.createTypedLiteral(14.0d)));
- Assert.assertTrue(model.containsLiteral(X, P, 14.0d));
+ public void testGetLexicalForm_int() {
+ // int
+ int i = 1;
+ assertEquals("1", lp.newInstance(i).getLexicalForm());
+ i = 0;
+ assertEquals("0", lp.newInstance(i).getLexicalForm());
+ i = Integer.MAX_VALUE;
+ assertEquals(Integer.toString(Integer.MAX_VALUE), lp.newInstance(i).getLexicalForm());
+ i = Integer.MIN_VALUE;
+ assertEquals(Integer.toString(Integer.MIN_VALUE), lp.newInstance(i).getLexicalForm());
}
@Test
- public void testAddWithFloatObject() {
- model.addLiteral(X, P, 14.0f);
- Assert.assertTrue(model.contains(X, P, model.createTypedLiteral(14.0f)));
- Assert.assertTrue(model.containsLiteral(X, P, 14.0f));
+ public void testGetLexicalForm_long() {
+ // long
+ long l = 1;
+ assertEquals("1", lp.newInstance(l).getLexicalForm());
+ l = 0;
+ assertEquals("0", lp.newInstance(l).getLexicalForm());
+ l = Integer.MAX_VALUE;
+ assertEquals(Integer.toString(Integer.MAX_VALUE), lp.newInstance(l).getLexicalForm());
+ l = Integer.MIN_VALUE;
+ assertEquals(Integer.toString(Integer.MIN_VALUE), lp.newInstance(l).getLexicalForm());
+ }
+
+ @Test
+ public void testGetLexicalForm_float() {
+ float f = 1;
+ assertEquals("1.0", lp.newInstance(f).getLexicalForm());
+ f = 0;
+ assertEquals("0.0", lp.newInstance(f).getLexicalForm());
+ f = Float.MAX_VALUE;
+ assertEquals(Float.toString(Float.MAX_VALUE), lp.newInstance(f).getLexicalForm());
+ f = Float.MIN_VALUE;
+ assertEquals(Float.toString(Float.MIN_VALUE), lp.newInstance(f).getLexicalForm());
+
}
@Test
- public void testAddWithIntObject() {
- model.addLiteral(X, P, 99);
- Assert.assertTrue(model.contains(X, P, model.createTypedLiteral(99)));
- Assert.assertTrue(model.containsLiteral(X, P, 99));
+ public void testGetLexicalForm_double() {
+ double d = 1;
+ assertEquals("1.0", lp.newInstance(d).getLexicalForm());
+ d = 0;
+ assertEquals("0.0", lp.newInstance(d).getLexicalForm());
+ assertEquals(Double.toString(Double.MAX_VALUE), lp.newInstance(Double.MAX_VALUE).getLexicalForm());
+ assertEquals(Double.toString(Double.MIN_VALUE), lp.newInstance(Double.MIN_VALUE).getLexicalForm());
}
@Test
- public void testAddWithLiteralObject() {
- final Literal lit = model.createLiteral("spoo");
- model.addLiteral(X, P, lit);
- Assert.assertTrue(model.contains(X, P, lit));
- Assert.assertTrue(model.containsLiteral(X, P, lit));
+ public void testGetLexicalForm_string() {
+ String s = "true";
+ String l = "en";
+ assertEquals(s, lp.newInstance(s, l).getLexicalForm());
+ s = "false";
+ assertEquals(s, lp.newInstance(s, l).getLexicalForm());
+ s = "1";
+ assertEquals(s, lp.newInstance(s, l).getLexicalForm());
+ s = "0";
+ assertEquals(s, lp.newInstance(s, l).getLexicalForm());
}
@Test
- public void testAddWithLongObject() {
- model.addLiteral(X, P, 99L);
- Assert.assertTrue(model.contains(X, P, model.createTypedLiteral(99L)));
- Assert.assertTrue(model.containsLiteral(X, P, 99L));
+ public void testGetLexicalForm_char() {
+ char c = 0x1;
+ assertEquals(Character.toString(c), lp.newInstance(c).getLexicalForm());
+ c = 0x0;
+ assertEquals(Character.toString(c), lp.newInstance(c).getLexicalForm());
+ c = Character.MAX_VALUE;
+ assertEquals(Character.toString(Character.MAX_VALUE), lp.newInstance(c).getLexicalForm());
+ c = Character.MIN_VALUE;
+ assertEquals(Character.toString(Character.MIN_VALUE), lp.newInstance(c).getLexicalForm());
}
- // that version of addLiteral is deprecated; test removed.
- // public void testAddWithAnObject()
- // {
- // Object z = new Date();
- // model.addLiteral( X, P, z );
- // assertTrue( model.contains( X, P, model.createTypedLiteral( z ) ) );
- // assertTrue( model.containsLiteral( X, P, z ) );
+ @Test
+ public void testGetLong_boolean() {
+ try {
+ lp.newInstance(true).getLong();
+ fail( "Should have thrown DatatypeFormatException");
+ }
+ catch (DatatypeFormatException expected)
+ {
+ // expected
+ }
+ }
+
+ @Test
+ public void testGetLong_int() {
+ // int
+ int i = 1;
+ assertEquals(i, lp.newInstance(i).getLong());
+ i = 0;
+ assertEquals(i, lp.newInstance(i).getLong());
+
+ i = Byte.MAX_VALUE;
+ assertEquals(i, lp.newInstance(i).getLong());
+ i = Byte.MIN_VALUE;
+ assertEquals(i, lp.newInstance(i).getLong());
+
+ i = Short.MAX_VALUE;
+ assertEquals(i, lp.newInstance(i).getLong());
+ i = Short.MIN_VALUE;
+ assertEquals(i, lp.newInstance(i).getLong());
+
+ i = Integer.MAX_VALUE;
+ assertEquals(i, lp.newInstance(i).getLong());
+ i = Integer.MIN_VALUE;
+ assertEquals(i, lp.newInstance(i).getLong());
+ }
+
+ @Test
+ public void testGetLong_long() {
+ // long
+ long l = 1;
+ assertEquals(l, lp.newInstance(l).getLong());
+ l = 0;
+ assertEquals(l, lp.newInstance(l).getLong());
+ l = Long.MAX_VALUE;
+ assertEquals(l, lp.newInstance(l).getLong());
+ l = Long.MIN_VALUE;
+ assertEquals(l, lp.newInstance(l).getLong());
+
+ // 1 either size of int value returnes Long
+ l = 1L+Integer.MAX_VALUE;
+ assertEquals(l, lp.newInstance(l).getLong());
+ l = -1L+Integer.MIN_VALUE;
+ assertEquals(l, lp.newInstance(l).getLong());
+ }
+
+ @Test
+ public void testGetLong_float() {
+ float f = 1;
+ long l = 1;
+ assertEquals(l, lp.newInstance(f).getLong());
+ f = 0;
+ l = 0;
+ assertEquals(l, lp.newInstance(f).getLong());
+ f = Long.MAX_VALUE;
+ l = Long.MAX_VALUE;
+ assertEquals(l, lp.newInstance(f).getLong());
+
+ f = Long.MIN_VALUE;
+ l = Long.MIN_VALUE;
+ assertEquals(l, lp.newInstance(f).getLong());
+
+
+ f = Float.MAX_VALUE;
+ assertEquals(Long.MAX_VALUE, lp.newInstance(f).getLong());
+ f = Float.MAX_VALUE * -1.0f;
+ assertEquals(Long.MIN_VALUE, lp.newInstance(f).getLong());
+
+ f = Float.MIN_VALUE;
+ assertEquals(0, lp.newInstance(f).getLong());
+
+ f = Float.MIN_VALUE*-1.0f;
+ assertEquals(0, lp.newInstance(f).getLong());
+
+ f = 1.5f; // non integer value
+ assertEquals(1,lp.newInstance(f).getLong());
+ }
+
+ @Test
+ public void testGetLong_double() {
+ double d = 1;
+ long l = 1;
+ assertEquals(l, lp.newInstance(d).getLong());
+ d = 0;
+ l = 0;
+ assertEquals(l, lp.newInstance(d).getLong());
+ d = Long.MAX_VALUE*1.0;
+ l = Long.MAX_VALUE;
+ assertEquals(l, lp.newInstance(d).getLong());
+
+ d = Double.MAX_VALUE;
+ assertEquals( Long.MAX_VALUE,lp.newInstance(d).getLong());
+
+ d = Double.MAX_VALUE*-1.0;
+ assertEquals( Long.MIN_VALUE,lp.newInstance(d).getLong());
+
+ d = Double.MIN_VALUE;
+ assertEquals( 0,lp.newInstance(d).getLong());
+ d = Double.MIN_VALUE *-1.0;
+ assertEquals( 0,lp.newInstance(d).getLong());
+ }
+
+ @Test
+ public void testGetLong_string() {
+ String s = "true";
+ String lang = "en";
+ try {
+ lp.newInstance(s, lang).getLong();
+ fail("Should have thrown NumberFormatException");
+ }
+ catch (NumberFormatException expected)
+ {
+ // expected
+ }
+ s = "1";
+ long l = 1;
+ assertEquals(l, lp.newInstance(s, lang).getLong());
+ s = "0";
+ l = 0;
+ assertEquals(l, lp.newInstance(s, lang).getLong());
+
+ s = Long.toString( Long.MAX_VALUE);
+ assertEquals(Long.MAX_VALUE, lp.newInstance(s, lang).getLong());
+
+ s += "0";
+ try {
+ lp.newInstance(s, lang).getLong();
+ fail( "Should have thrown NumberFormatException");
+ }
+ catch (NumberFormatException expected)
+ {
+ // expected
+ }
+
+ s = Long.toString( Long.MIN_VALUE);
+ assertEquals(Long.MIN_VALUE, lp.newInstance(s, lang).getLong());
+
+ s += "0";
+ try {
+ lp.newInstance(s, lang).getLong();
+ fail( "Should have thrown NumberFormatException");
+ }
+ catch (NumberFormatException expected)
+ {
+ // expected
+ }
+ }
+
+ @Test
+ public void testGetLong_char() {
+ char c = 0x1;
+ try {
+ lp.newInstance(c).getLong();
+ fail( "Should have thrown DatatypeFormatException");
+ }
+ catch (DatatypeFormatException expected)
+ {
+ // expected
+ }
+ }
+
+ @Test
+ public void testGetShort_boolean() {
+ try {
+ lp.newInstance(true).getShort();
+ fail("Should have thrown DatatypeFormatException");
+ } catch (DatatypeFormatException expected) {
+ // expected
+ }
+ }
+
+ @Test
+ public void testGetShort_byte() {
+ // byte
+ byte b = 1;
+ assertEquals(b, lp.newInstance(b).getShort());
+ b = 0;
+ assertEquals(b, lp.newInstance(b).getShort());
+ b = 0xf; // bit pattern ends in 1
+ assertEquals(b, lp.newInstance(b).getShort());
+ b = 0xe; // bit pattern ends in 0
+ assertEquals(b, lp.newInstance(b).getShort());
+ }
+
+
+ @Test
+ public void testGetShort_int() {
+ // int
+ int i = 1;
+ short s = 1;
+ assertEquals(i, lp.newInstance(i).getShort());
+ i = 0;
+ s = 0;
+ assertEquals(i, lp.newInstance(i).getShort());
+
+ i = Byte.MAX_VALUE;
+ s = Byte.MAX_VALUE;
+ assertEquals(s, lp.newInstance(i).getShort());
+
+ i = Byte.MIN_VALUE;
+ s = Byte.MIN_VALUE;
+ assertEquals(s, lp.newInstance(i).getShort());
+
+
+ i = Short.MAX_VALUE;
+ assertEquals(Short.MAX_VALUE, lp.newInstance(i).getShort());
+
+ i = Short.MIN_VALUE;
+ assertEquals(Short.MIN_VALUE, lp.newInstance(i).getShort());
+
+ try {
+ lp.newInstance(Integer.MAX_VALUE).getShort();
+ fail( "Should have thrown IllegalArgumentException");
+ } catch (IllegalArgumentException expected) {
+ // exected
+ }
+
+ try {
+ lp.newInstance(Integer.MIN_VALUE).getShort();
+ fail( "Should have thrown IllegalArgumentException");
+ } catch (IllegalArgumentException expected) {
+ // exected
+ }
+ }
+
+ @Test
+ public void testGetShort_long() {
+ // long
+ long l = 1;
+ assertEquals(l, lp.newInstance(l).getShort());
+ l = 0;
+ assertEquals(l, lp.newInstance(l).getShort());
+ l = Short.MAX_VALUE;
+ l += 1;
+ try {
+ lp.newInstance(l).getShort();
+ fail("Should have thrown IllegalArgumentException");
+ } catch (IllegalArgumentException expected) {
+ // expected
+ }
+ l = Short.MIN_VALUE;
+ l -= 1;
+ try {
+ lp.newInstance(l).getShort();
+ fail("Should have thrown IllegalArgumentException");
+ } catch (IllegalArgumentException expected) {
+ // expected
+ }
+ }
+
+ @Test
+ public void testGetShort_float() {
+ float f = 1;
+ short s = 1;
+ assertEquals(s, lp.newInstance(f).getShort());
+ f = 0;
+ s = 0;
+ assertEquals(s, lp.newInstance(f).getShort());
+ f = Short.MAX_VALUE;
+ s = Short.MAX_VALUE;
+ assertEquals(s, lp.newInstance(f).getShort());
+
+ f = Short.MAX_VALUE;
+ f += 1;
+ try {
+ lp.newInstance(f).getShort();
+ fail("Should have thrown IllegalArgumentException");
+ } catch (IllegalArgumentException expected) {
+ // expected
+ }
+
+ f = Short.MIN_VALUE;
+ s = Short.MIN_VALUE;
+ assertEquals(s, lp.newInstance(f).getShort());
+ f = Short.MIN_VALUE;
+ f -= 1;
+ try {
+ lp.newInstance(f).getShort();
+ fail("Should have thrown IllegalArgumentException");
+ } catch (IllegalArgumentException expected) {
+ // expected
+ }
+
+ f = 1.5f; // non integer value
+ s = 1;
+ assertEquals( s, lp.newInstance(f).getShort());
+ }
+
+ @Test
+ public void testGetShort_double() {
+ double d = 1.0;
+ short s = 1;
+ assertEquals(s, lp.newInstance(d).getShort());
+ d = 0.0;
+ s = 0;
+ assertEquals(s, lp.newInstance(d).getShort());
+ d = Short.MAX_VALUE;
+ d += 1.0;
+ try {
+ lp.newInstance(d).getShort();
+ fail("Should have thrown IllegalArgumentException");
+ } catch (IllegalArgumentException expected) {
+ // expected
+ }
+ d = Short.MIN_VALUE;
+ d -= 1.0;
+ try {
+ lp.newInstance(d).getShort();
+ fail("Should have thrown IllegalArgumentException");
+ } catch (IllegalArgumentException expected) {
+ // expected
+ }
+
+ }
+
+ @Test
+ public void testGetShort_string() {
+ String s = "true";
+ String l = "en";
+ try {
+ lp.newInstance(s, l).getShort();
+ fail("Should have thrown NumberFormatException");
+ } catch (NumberFormatException expected) {
+ // expected
+ }
+ s = "1";
+ short sh = 1;
+ assertEquals(sh, lp.newInstance(s, l).getShort());
+ s = "0";
+ sh = 0;
+ s = Short.toString( Short.MAX_VALUE );
+ assertEquals(Short.MAX_VALUE, lp.newInstance(s, l).getShort());
+
+ s +="0";
+ try {
+ lp.newInstance(s, l).getShort();
+ fail("Should have thrown NumberFormatException");
+ } catch (NumberFormatException expected) {
+ // expected
+ }
+
+ s = Short.toString( Short.MIN_VALUE );
+ assertEquals(Short.MIN_VALUE, lp.newInstance(s, l).getShort());
+ s +="0";
+ try {
+ lp.newInstance(s, l).getShort();
+ fail("Should have thrown NumberFormatException");
+ } catch (NumberFormatException expected) {
+ // expected
+ }
+ }
+
+ @Test
+ public void testGetShort_char() {
+ char c = 0x1;
+ try {
+ lp.newInstance(c).getShort();
+ fail("Should have thrown DatatypeFormatException");
+ } catch (DatatypeFormatException expected) {
+ // expected
+ }
+ }
+
+ @Test
+ public void testGetString_boolean() {
+ assertEquals("true", lp.newInstance(true).getString());
+ assertEquals("false", lp.newInstance(false).getString());
+ }
+
+
+ @Test
+ public void testGetString_int() {
+ // int
+ int i = 1;
+ assertEquals("1", lp.newInstance(i).getString());
+ i = 0;
+ assertEquals("0", lp.newInstance(i).getString());
+
+ i = Byte.MAX_VALUE;
+ assertEquals(Byte.toString(Byte.MAX_VALUE), lp.newInstance(i).getString());
+ i = Byte.MIN_VALUE;
+ assertEquals(Byte.toString(Byte.MIN_VALUE), lp.newInstance(i).getString());
+
+ i = Short.MAX_VALUE;
+ assertEquals(Short.toString(Short.MAX_VALUE), lp.newInstance(i).getString());
+ i = Short.MIN_VALUE;
+ assertEquals(Short.toString(Short.MIN_VALUE), lp.newInstance(i).getString());
+
+ i = Integer.MAX_VALUE;
+ assertEquals(Integer.toString(Integer.MAX_VALUE), lp.newInstance(i).getString());
+ i = Integer.MIN_VALUE;
+ assertEquals(Integer.toString(Integer.MIN_VALUE), lp.newInstance(i).getString());
+ }
+
+ @Test
+ public void testGetString_long() {
+ // long
+ long l = 1;
+ assertEquals("1", lp.newInstance(l).getString());
+ l = 0;
+ assertEquals("0", lp.newInstance(l).getString());
+ l = Long.MAX_VALUE;
+ assertEquals(Long.toString(Long.MAX_VALUE), lp.newInstance(l).getString());
+ l = Long.MIN_VALUE;
+ assertEquals(Long.toString(Long.MIN_VALUE), lp.newInstance(l).getString());
+ }
+
+ @Test
+ public void testGetString_float() {
+ float f = 1;
+ assertEquals("1.0", lp.newInstance(f).getString());
+ f = 0;
+ assertEquals("0.0", lp.newInstance(f).getString());
+ f = Float.MAX_VALUE;
+ assertEquals(Float.toString(Float.MAX_VALUE), lp.newInstance(f).getString());
+ f = Float.MIN_VALUE;
+ assertEquals(Float.toString(Float.MIN_VALUE), lp.newInstance(f).getString());
+ }
+
+ @Test
+ public void testGetString_double() {
+ double d = 1;
+ assertEquals("1.0", lp.newInstance(d).getString());
+ d = 0;
+ assertEquals("0.0", lp.newInstance(d).getString());
+ d = Double.MAX_VALUE;
+ assertEquals(Double.toString(Double.MAX_VALUE), lp.newInstance(d).getString());
+ d = Double.MIN_VALUE;
+ assertEquals(Double.toString(Double.MIN_VALUE), lp.newInstance(d).getString());
+ }
+
+ @Test
+ public void testGetString_string() {
+ String s = "true";
+ String l = "en";
+ assertEquals(s, lp.newInstance(s, l).getString());
+ s = "false";
+ assertEquals(s, lp.newInstance(s, l).getString());
+ s = "1";
+ assertEquals(s, lp.newInstance(s, l).getString());
+ s = "0";
+ assertEquals(s, lp.newInstance(s, l).getString());
+ }
+
+ @Test
+ public void testGetString_char() {
+ char c = 0x1;
+ String s = ""+c;
+ assertEquals(s, lp.newInstance(c).getString());
+ c = 0x0;
+ s = ""+c;
+ assertEquals(s, lp.newInstance(c).getString());
+ c = Character.MAX_VALUE;
+ s = ""+c;
+ assertEquals(s, lp.newInstance(c).getString());
+ c = Character.MIN_VALUE;
+ s = ""+c;
+ assertEquals(s, lp.newInstance(c).getString());
+ }
+
+ @Test
+ public void testGetValue_boolean() {
+ assertEquals(Boolean.TRUE, lp.newInstance(true).getValue());
+ assertEquals(Boolean.FALSE, lp.newInstance(false).getValue());
+ }
+
+ @Test
+ public void testGetValue_int() {
+ // int
+ int i = 1;
+ assertEquals(i, lp.newInstance(i).getValue());
+ i = 0;
+ assertEquals(i, lp.newInstance(i).getValue());
+
+ // byte
+ i = Byte.MAX_VALUE;
+ assertEquals(i, lp.newInstance(Byte.MAX_VALUE).getValue());
+ i = Byte.MIN_VALUE;
+ assertEquals(i, lp.newInstance(Byte.MIN_VALUE).getValue());
+
+ // short
+ i = Short.MAX_VALUE;
+ assertEquals(i, lp.newInstance(Short.MAX_VALUE).getValue());
+ i = Short.MIN_VALUE;
+ assertEquals(i, lp.newInstance(Short.MIN_VALUE).getValue());
+
+ i = Integer.MAX_VALUE;
+ assertEquals(Integer.MAX_VALUE, lp.newInstance(i).getValue());
+ i = Integer.MIN_VALUE;
+ assertEquals(Integer.MIN_VALUE, lp.newInstance(i).getValue());
+ }
+
+ @Test
+ public void testGetValue_long() {
+ // long
+ long l = 1;
+ assertEquals(1, lp.newInstance(l).getValue());
+ l = 0;
+ assertEquals(0, lp.newInstance(l).getValue());
+ l = Long.MAX_VALUE;
+ assertEquals(Long.MAX_VALUE, lp.newInstance(l).getValue());
+ l = Long.MIN_VALUE;
+ assertEquals(Long.MIN_VALUE, lp.newInstance(l).getValue());
+ }
+
+ @Test
+ public void testGetValue_float() {
+ float f = 1;
+ assertEquals(f, lp.newInstance(f).getValue());
+ f = 0;
+ assertEquals(f, lp.newInstance(f).getValue());
+ f = Float.MAX_VALUE;
+ assertEquals(Float.MAX_VALUE, lp.newInstance(f).getValue());
+ f = Float.MIN_VALUE;
+ assertEquals(Float.MIN_VALUE, lp.newInstance(f).getValue());
+ }
+
+ @Test
+ public void testGetValue_double() {
+ double d = 1;
+ assertEquals(d, lp.newInstance(d).getValue());
+ d = 0;
+ assertEquals(d, lp.newInstance(d).getValue());
+ d = Double.MAX_VALUE;
+ assertEquals(Double.MAX_VALUE, lp.newInstance(d).getValue());
+ d = Double.MIN_VALUE;
+ assertEquals(Double.MIN_VALUE, lp.newInstance(d).getValue());
+ }
+
+ @Test
+ public void testGetValue_string() {
+ String s = "true";
+ String l = "en";
+ assertEquals(s, lp.newInstance(s, l).getValue());
+ s = "false";
+ assertEquals(s, lp.newInstance(s, l).getValue());
+ s = "1";
+ assertEquals(s, lp.newInstance(s, l).getValue());
+ s = "0";
+ assertEquals(s, lp.newInstance(s, l).getValue());
+ }
+
+ @Test
+ public void testGetValue_char() {
+ char c = (char)0x0;
+ assertEquals(c, lp.newInstance(c).getValue());
+ c = (char)0x1;
+ assertEquals(c, lp.newInstance(c).getValue());
+ c = Character.MAX_VALUE;
+ assertEquals(Character.MAX_VALUE, lp.newInstance(c).getValue());
+ c = Character.MIN_VALUE;
+ assertEquals(Character.MIN_VALUE, lp.newInstance(c).getValue());
+ }
+
+ @Test
+ public void testIsWellFormedXML_boolean() {
+ assertFalse( lp.newInstance(true).isWellFormedXML());
+ }
+
+ @Test
+ public void testIsWellFormedXML_int() {
+ int i = 1;
+ assertFalse(lp.newInstance(i).isWellFormedXML());
+ }
+
+ @Test
+ public void testIsWellFormedXML_long() {
+ // long
+ long l = 1;
+ assertFalse(lp.newInstance(l).isWellFormedXML());
+ }
+
+ @Test
+ public void testIsWellFormedXML_float() {
+ float f = 1;
+ assertFalse( lp.newInstance(f).isWellFormedXML());
+ }
+
+ @Test
+ public void testIsWellFormedXML_double() {
+ double d = 1;
+ assertFalse( lp.newInstance(d).isWellFormedXML());
+ }
+
+ @Test
+ public void testIsWellFormedXML_string() {
+ String s = "true";
+ String l = "en";
+ assertFalse( lp.newInstance(s, l).isWellFormedXML());
+ }
+
+ @Test
+ public void testIsWellFormedXML_char() {
+ char c = 0x1;
+ assertFalse(lp.newInstance(c).isWellFormedXML());
+ }
+
+ /*
+ * FIXME
+ *
+ * @Test public void testSameValueAs_Literal_boolean() { assertEquals(1,
+ * lp.newInstance(true).sameValueAs()); assertEquals(0,
+ * lp.newInstance(false).sameValueAs()); }
+ *
+ * @Test public void testSameValueAs_Literal_byte() { // byte byte b = 1;
+ * assertEquals(b, lp.newInstance(b).sameValueAs()); b = 0; assertEquals(b,
+ * lp.newInstance(b).sameValueAs()); b = 0xf; // bit pattern ends in 1
+ * assertEquals(b, lp.newInstance(b).sameValueAs()); b = 0xe; // bit pattern
+ * ends in 0 assertEquals(b, lp.newInstance(b).sameValueAs()); }
+ *
+ * @Test public void testSameValueAs_Literal_short() { // short short s = 1;
+ * assertEquals(s, lp.newInstance(s).sameValueAs()); s = 0; assertEquals(s,
+ * lp.newInstance(s).sameValueAs()); s = 0xf; // bit pattern ends in 1
+ * assertEquals(s, lp.newInstance(s).sameValueAs()); s = 0xe; // bit pattern
+ * ends in 0 assertEquals(s, lp.newInstance(s).sameValueAs()); }
+ *
+ * @Test public void testSameValueAs_Literal_int() { // int int i = 1;
+ * assertEquals(i, lp.newInstance(i).sameValueAs()); i = 0; assertEquals(i,
+ * lp.newInstance(i).sameValueAs()); i = 0x7fff; // bit pattern ends in 1
+ * assertEquals(i, lp.newInstance(i).sameValueAs()); i = 0x7ffe; // bit
+ * pattern ends in 0 assertEquals(i, lp.newInstance(i).sameValueAs()); }
+ *
+ * @Test public void testSameValueAs_Literal_long() { // long long l = 1;
+ * assertEquals(l, lp.newInstance(l).sameValueAs()); l = 0; assertEquals(l,
+ * lp.newInstance(l).sameValueAs()); l = 0x7fffffff; // bit pattern ends in
+ * 1 assertEquals(l, lp.newInstance(l).sameValueAs()); l = 0x7ffffffe; //
+ * bit pattern ends in 0 assertEquals(l, lp.newInstance(l).sameValueAs()); }
+ *
+ * @Test public void testSameValueAs_Literal_float() { float f = 1;
+ * assertEquals(f, lp.newInstance(f).sameValueAs()); f = 0; assertEquals(f,
+ * lp.newInstance(f).sameValueAs()); f = 7; // bit pattern ends in 1
+ * assertEquals(f, lp.newInstance(f).sameValueAs()); f = 6; // bit pattern
+ * ends in 0 assertEquals(f, lp.newInstance(f).sameValueAs()); }
+ *
+ * @Test public void testSameValueAs_Literal_double() { double d = 1;
+ * assertEquals(d, lp.newInstance(d).sameValueAs()); d = 0; assertEquals(d,
+ * lp.newInstance(d).sameValueAs()); d = 7; // bit pattern ends in 1
+ * assertEquals(d, lp.newInstance(d).sameValueAs()); d = 6; // bit pattern
+ * ends in 0 assertEquals(d, lp.newInstance(d).sameValueAs()); }
+ *
+ * @Test public void testSameValueAs_Literal_string() { String s = "true";
+ * String l = "en"; assertEquals(s, lp.newInstance(s, l).sameValueAs()); s =
+ * "false"; assertEquals(s, lp.newInstance(s, l).sameValueAs()); s = "1";
+ * assertEquals(s, lp.newInstance(s, l).sameValueAs()); s = "0";
+ * assertEquals(s, lp.newInstance(s, l).sameValueAs()); }
+ *
+ * @Test public void testSameValueAs_Literal_char() { char c = 0x1;
+ * assertEquals(c, lp.newInstance(c).sameValueAs()); c = 0x0;
+ * assertEquals(c, lp.newInstance(s).sameValueAs()); c = '1';
+ * assertEquals(c, lp.newInstance(c).sameValueAs()); c = '0';
+ * assertEquals(c, lp.newInstance(c).sameValueAs()); }
+ */
+ // /// FIXME END OF EDIT
+ //
+ // // byte
+ // byte b = 1;
+ // lp.newInstance( b ).as(Literal.class);
+ //
+ // // char
+ // char c = 'c';
+ // lp.newInstance( c ).as(Literal.class);
+ // // double
+ // double d = 4.5d;
+ // lp.newInstance( d ).as(Literal.class);
+ //
+ // // Float
+ // float f = 4.5f;
+ // lp.newInstance( f ).as(Literal.class);
+ //
+ // // Int
+ // int i = 5;
+ // lp.newInstance( i ).as(Literal.class);
+ //
+ // // Long
+ // long ln = 4L;
+ // lp.newInstance( ln ).as(Literal.class);
+ //
+ // // Short
+ // Short s = 4;
+ // lp.newInstance( s ).as(Literal.class);
+ //
+ // // String
+ // String st = "foo";
+ // lp.newInstance( st, "en" ).as(Literal.class);
+ // }
+ //
+ // protected void testByte(final Model model, final byte tv) {
+ // final Literal l = model.createTypedLiteral(tv);
+ // Assert.assertEquals(tv, l.getByte());
+ // Assert.assertEquals(tv, l.newInstance());
+ // Assert.assertEquals(tv, l.newInstance());
+ // Assert.assertEquals(tv, l.newInstance());
+ // }
+ //
+ // @Test
+ // public void testByteLiterals() {
+ // testByte(model, (byte) 0);
+ // testByte(model, (byte) -1);
+ // testByte(model, Byte.MIN_VALUE);
+ // testByte(model, Byte.MAX_VALUE);
+ // }
+ //
+ // protected void testCharacter(final Model model, final char tv) {
+ // Assert.assertEquals(tv, model.createTypedLiteral(tv).newInstance());
+ // }
+ //
+ // @Test
+ // public void testCharacterLiterals() {
+ // testCharacter(model, 'A');
+ // testCharacter(model, 'a');
+ // testCharacter(model, '#');
+ // testCharacter(model, '@');
+ // testCharacter(model, '0');
+ // testCharacter(model, '9');
+ // testCharacter(model, '\u1234');
+ // testCharacter(model, '\u5678');
+ // }
+ //
+ // protected void testDouble(final Model model, final double tv) {
+ // Assert.assertEquals(tv, model.createTypedLiteral(tv).newInstance(),
+ // dDelta);
+ // }
+ //
+ // @Test
+ // public void testDoubleLiterals() {
+ // testDouble(model, 0.0);
+ // testDouble(model, 1.0);
+ // testDouble(model, -1.0);
+ // testDouble(model, 12345.678901);
+ // testDouble(model, Double.MIN_VALUE);
+ // testDouble(model, Double.MAX_VALUE);
+ // }
+ //
+ // protected void testFloat(final Model model, final float tv) {
+ // Assert.assertEquals(tv, model.createTypedLiteral(tv).newInstance(),
+ // fDelta);
+ // }
+ //
+ // @Test
+ // public void testFloatLiterals() {
+ // testFloat(model, 0.0f);
+ // testFloat(model, 1.0f);
+ // testFloat(model, -1.0f);
+ // testFloat(model, 12345.6789f);
+ // testFloat(model, Float.MIN_VALUE);
+ // testFloat(model, Float.MAX_VALUE);
+ // }
+ //
+ // // public void testLiteralObjects()
+ // // {
+ // // // testLiteralObject( model, 0 );
+ // // // testLiteralObject( model, 12345 );
+ // // // testLiteralObject( model, -67890 );
+ // // }
+ //
+ // protected void testInt(final Model model, final int tv) {
+ // final Literal l = model.createTypedLiteral(tv);
+ // try {
+ // Assert.assertEquals(tv, l.newInstance());
+ // assertInRange(Byte.MIN_VALUE, tv, Byte.MAX_VALUE);
+ // } catch (final NumberFormatException e) {
+ // assertOutsideRange(Byte.MIN_VALUE, tv, Byte.MAX_VALUE);
+ // } catch (final IllegalArgumentException e) {
+ // assertOutsideRange(Byte.MIN_VALUE, tv, Byte.MAX_VALUE);
+ // }
+ // try {
+ // Assert.assertEquals(tv, l.newInstance());
+ // assertInRange(Short.MIN_VALUE, tv, Short.MAX_VALUE);
+ // } catch (final NumberFormatException e) {
+ // assertOutsideRange(Short.MIN_VALUE, tv, Short.MAX_VALUE);
+ // } catch (final IllegalArgumentException e) {
+ // assertOutsideRange(Short.MIN_VALUE, tv, Short.MAX_VALUE);
+ // }
+ // Assert.assertEquals(tv, l.newInstance());
+ // Assert.assertEquals(tv, l.newInstance());
+ // }
+ //
+ // @Test
+ // public void testIntLiterals() {
+ // testInt(model, 0);
+ // testInt(model, -1);
+ // testInt(model, Integer.MIN_VALUE);
+ // testInt(model, Integer.MAX_VALUE);
+ // }
+ //
+ // protected void testLanguagedString(final Model model, final String tv,
+ // final String lang) {
+ // final Literal l = model.createLiteral(tv, lang);
+ // Assert.assertEquals(tv, l.getString());
+ // Assert.assertEquals(tv, l.getLexicalForm());
+ // Assert.assertEquals(lang, l.getLanguage());
+ // }
+ //
+ // @Test
+ // public void testLanguagedStringLiterals() {
+ // testLanguagedString(model, "", "en");
+ // testLanguagedString(model, "chat", "fr");
+ // }
+ //
+ // protected void testLong(final Model model, final long tv) {
+ // final Literal l = model.createTypedLiteral(tv);
+ // try {
+ // Assert.assertEquals(tv, l.newInstance());
+ // assertInRange(Byte.MIN_VALUE, tv, Byte.MAX_VALUE);
+ // } catch (final NumberFormatException e) {
+ // assertOutsideRange(Byte.MIN_VALUE, tv, Byte.MAX_VALUE);
+ // } catch (final IllegalArgumentException e) {
+ // assertOutsideRange(Byte.MIN_VALUE, tv, Byte.MAX_VALUE);
+ // }
+ // try {
+ // Assert.assertEquals(tv, l.newInstance());
+ // assertInRange(Short.MIN_VALUE, tv, Short.MAX_VALUE);
+ // } catch (final NumberFormatException e) {
+ // assertOutsideRange(Short.MIN_VALUE, tv, Short.MAX_VALUE);
+ // } catch (final IllegalArgumentException e) {
+ // assertOutsideRange(Short.MIN_VALUE, tv, Short.MAX_VALUE);
+ // }
+ // try {
+ // Assert.assertEquals(tv, l.newInstance());
+ // assertInRange(Integer.MIN_VALUE, tv, Integer.MAX_VALUE);
+ // } catch (final NumberFormatException e) {
+ // assertOutsideRange(Integer.MIN_VALUE, tv, Integer.MAX_VALUE);
+ // } catch (final IllegalArgumentException e) {
+ // assertOutsideRange(Integer.MIN_VALUE, tv, Integer.MAX_VALUE);
+ // }
+ // Assert.assertEquals(tv, l.newInstance());
+ // }
+ //
+ // @Test
+ // public void testLongLiterals() {
+ // testLong(model, 0);
+ // testLong(model, -1);
+ // testLong(model, Long.MIN_VALUE);
+ // testLong(model, Long.MAX_VALUE);
+ // }
+ //
+ // protected void testPlainString(final Model model, final String tv) {
+ // final Literal l = model.createLiteral(tv);
+ // Assert.assertEquals(tv, l.getString());
+ // Assert.assertEquals(tv, l.getLexicalForm());
+ // Assert.assertEquals("", l.getLanguage());
+ // }
+ //
+ // @Test
+ // public void testPlainStringLiterals() {
+ // testPlainString(model, "");
+ // testPlainString(model, "A test string");
+ // testPlainString(model, "Another test string");
+ // }
+ //
+ // protected void testShort(final Model model, final short tv) {
+ // final Literal l = model.createTypedLiteral(tv);
+ // try {
+ // Assert.assertEquals(tv, l.newInstance());
+ // assertInRange(Byte.MIN_VALUE, tv, Byte.MAX_VALUE);
+ // } catch (final NumberFormatException e) {
+ // assertOutsideRange(Byte.MIN_VALUE, tv, Byte.MAX_VALUE);
+ // } catch (final IllegalArgumentException e) {
+ // assertOutsideRange(Byte.MIN_VALUE, tv, Byte.MAX_VALUE);
+ // }
+ // Assert.assertEquals(tv, l.newInstance());
+ // Assert.assertEquals(tv, l.newInstance());
+ // Assert.assertEquals(tv, l.newInstance());
+ // }
+ //
+ // @Test
+ // public void testShortLiterals() {
+ // testShort(model, (short) 0);
+ // testShort(model, (short) -1);
+ // testShort(model, Short.MIN_VALUE);
+ // testShort(model, Short.MAX_VALUE);
+ // }
+ //
+ // @Test
+ // public void testStringLiteralEquality() {
+ // Assert.assertEquals(model.createLiteral("A"), model.createLiteral("A"));
+ // Assert.assertEquals(model.createLiteral("Alpha"),
+ // model.createLiteral("Alpha"));
+ // assertDiffer(model.createLiteral("Alpha"), model.createLiteral("Beta"));
+ // assertDiffer(model.createLiteral("A", "en"), model.createLiteral("A"));
+ // assertDiffer(model.createLiteral("A"), model.createLiteral("A", "en"));
+ // assertDiffer(model.createLiteral("A", "en"),
+ // model.createLiteral("A", "fr"));
+ // Assert.assertEquals(model.createLiteral("A", "en"),
+ // model.createLiteral("A", "en"));
// }
+ //
+ // // protected void testLiteralObject( Model model, int x )
+ // // {
+ // // LitTestObj tv = new LitTestObj( x );
+ // // LitTestObjF factory = new LitTestObjF();
+ // // assertEquals( tv, model.createTypedLiteral( tv ).getObject( factory )
+ // );
+ // // }
+ //
+ //
+ // // that version of addLiteral is deprecated; test removed.
+ // // public void testAddWithAnObject()
+ // // {
+ // // Object z = new Date();
+ // // model.addLiteral( X, P, z );
+ // // assertTrue( model.contains( X, P, model.createTypedLiteral( z ) ) );
+ // // assertTrue( model.containsLiteral( X, P, z ) );
+ // // }
}
Modified: jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/rdf/model/ModelConContractTests.java
URL: http://svn.apache.org/viewvc/jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/rdf/model/ModelConContractTests.java?rev=1531665&r1=1531664&r2=1531665&view=diff
==============================================================================
--- jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/rdf/model/ModelConContractTests.java (original)
+++ jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/rdf/model/ModelConContractTests.java Sun Oct 13 10:26:38 2013
@@ -19,6 +19,7 @@
package com.hp.hpl.jena.rdf.model;
import static com.hp.hpl.jena.testing_framework.ModelHelper.*;
+import static com.hp.hpl.jena.testing_framework.TestUtils.assertInstanceOf;
import static org.junit.Assert.*;
import java.util.Arrays;
import java.util.Calendar;
@@ -33,6 +34,7 @@ import org.xenei.junit.contract.Contract
import com.hp.hpl.jena.datatypes.BaseDatatype;
import com.hp.hpl.jena.datatypes.RDFDatatype;
+import com.hp.hpl.jena.datatypes.TypeMapper;
import com.hp.hpl.jena.datatypes.xsd.XSDDatatype;
import com.hp.hpl.jena.datatypes.xsd.XSDDateTime;
import com.hp.hpl.jena.graph.Node;
@@ -664,6 +666,8 @@ public abstract class ModelConContractTe
assertEquals("must be associated with model", modelCon, s.getModel());
assertFalse("Should not be in model", model.contains(s));
}
+
+
@Test
public void testCreateProperty_String() {
@@ -952,17 +956,40 @@ public abstract class ModelConContractTe
@Test
public void testCreateTypedLiteral_Object() {
model.register(SL);
- txnBegin(model);
- final Literal l = modelCon.createTypedLiteral(tvObject);
- txnCommit(model);
+
+
+
- BaseDatatype dt = new AdhocDatatype(ModelHelper.LitTestObj.class);
-
- SL.assertEmpty();
- assertEquals("must be associated with model", modelCon, l.getModel());
- assertFalse("Found literal in model", model.contains(null, null, l));
- assertEquals("wrong type of literal", dt.getURI(), l.getDatatypeURI());
- assertEquals("wrong value", tvObject.toString(), l.getString());
+ try {
+ final LitTestObj ra = new LitTestObj("rhubarb");
+ final LitTestObj rb = new LitTestObj("cottage");
+ Assert.assertNull("not expecting registered RDF Datatype",
+ TypeMapper.getInstance().getTypeByValue(ra));
+ txnBegin(model);
+ final Literal la = model.createTypedLiteral(ra); // Sets the type
+ // mapper
+ // - contaminates it
+ // with
+ // UniqueValueClass1
+ final Literal lb = model.createTypedLiteral(rb);
+ txnCommit(model);
+ SL.assertEmpty();
+ assertEquals("must be associated with model", modelCon, la.getModel());
+ assertEquals("must be associated with model", modelCon, lb.getModel());
+ assertFalse("Found literal in model", model.contains(null, null, la));
+ assertFalse("Found literal in model", model.contains(null, null, lb));
+ assertInstanceOf(AdhocDatatype.class, la.getDatatype());
+ Assert.assertSame(la.getDatatype(), lb.getDatatype());
+ Assert.assertNotNull(TypeMapper.getInstance().getTypeByValue(ra));
+ RDFDatatype dt = TypeMapper.getInstance().getTypeByValue(ra);
+ assertEquals("wrong type of literal", dt.getURI(), la.getDatatypeURI());
+ assertEquals("wrong value", ra.toString(), la.getString());
+ assertEquals("wrong value", rb.toString(), lb.getString());
+
+ } finally {
+ TypeMapper.reset();
+ }
+
}
@Test
Modified: jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/rdf/model/ModelContractTests.java
URL: http://svn.apache.org/viewvc/jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/rdf/model/ModelContractTests.java?rev=1531665&r1=1531664&r2=1531665&view=diff
==============================================================================
--- jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/rdf/model/ModelContractTests.java (original)
+++ jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/rdf/model/ModelContractTests.java Sun Oct 13 10:26:38 2013
@@ -1488,7 +1488,7 @@ public abstract class ModelContractTests
* </ul>
*/
@Test
- public void testlistNameSpaces() {
+ public void testListNameSpaces() {
txnBegin(model);
modelAdd(model,
"a R b; a R 5; a R _1; _1 P 'foo'; _2 P 'bar'; a rdf:type z");
@@ -1540,6 +1540,7 @@ public abstract class ModelContractTests
assertEquals("wrong number of objects", 1, list.size());
assertEquals("wrong object", rdfNode("'foo'"), list.get(0));
+ // test find all
list = model.listObjectsOfProperty(null).toList();
nodes = new RDFNode[] { rdfNode("b"), rdfNode("5"), rdfNode("_1"),
Modified: jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/rdf/model/ResourceContractTests.java
URL: http://svn.apache.org/viewvc/jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/rdf/model/ResourceContractTests.java?rev=1531665&r1=1531664&r2=1531665&view=diff
==============================================================================
--- jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/rdf/model/ResourceContractTests.java (original)
+++ jena/Experimental/new-test/src/test/java/com/hp/hpl/jena/rdf/model/ResourceContractTests.java Sun Oct 13 10:26:38 2013
@@ -38,6 +38,7 @@ import java.util.List;
import static org.junit.Assert.*;
import org.junit.After;
+import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.xenei.junit.contract.Contract;
@@ -728,6 +729,19 @@ public abstract class ResourceContractTe
assertEquals("resource should equal original", r, r2);
}
+ /**
+ * Test that a non-literal node cannot be as'ed into a literal
+ */
+ @Test
+ public void testAs_Literal_fails() {
+ try {
+ r.as(Literal.class);
+ Assert.fail("non-literal cannot be converted to literal");
+ } catch (final LiteralRequiredException l) {
+ // expected
+ }
+ }
+
// // FIXME implement this
//