use of org.apache.jena.graph.impl.LiteralLabel in project jena by apache.
the class TestLiteralLabels method testDatatypeIsEqualsNotCalledIfSecondOperandIsNotTyped.
public void testDatatypeIsEqualsNotCalledIfSecondOperandIsNotTyped() {
RDFDatatype d = new BaseDatatype("eh:/FakeDataType") {
@Override
public boolean isEqual(LiteralLabel A, LiteralLabel B) {
fail("RDFDatatype::isEquals should not be called if B has no datatype");
return false;
}
};
LiteralLabel A = LiteralLabelFactory.createByValue("17", "", d);
LiteralLabel B = LiteralLabelFactory.createByValue("17", "", null);
assertFalse(A.sameValueAs(B));
}
use of org.apache.jena.graph.impl.LiteralLabel in project jena by apache.
the class TestLiteralLabels method testHashCode.
public void testHashCode() {
LiteralLabel ll = LiteralLabelFactory.createByValue("test", "", null);
ll.hashCode();
}
use of org.apache.jena.graph.impl.LiteralLabel in project jena by apache.
the class TestLiteralLabels method testHashCode2.
public void testHashCode2() {
LiteralLabel ll1 = LiteralLabelFactory.createByValue("test", "", null);
LiteralLabel ll2 = LiteralLabelFactory.createByValue("test", "", null);
assertEquals(ll1.hashCode(), ll2.hashCode());
}
use of org.apache.jena.graph.impl.LiteralLabel in project jena by apache.
the class Rational method testIsValidLiteral.
/**
* Test the isValidLiteral machinery
*/
public void testIsValidLiteral() {
Literal l = m.createTypedLiteral("1000", XSDDatatype.XSDinteger);
LiteralLabel ll = l.asNode().getLiteral();
assertTrue(XSDDatatype.XSDlong.isValidLiteral(ll));
assertTrue(XSDDatatype.XSDint.isValidLiteral(ll));
assertTrue(XSDDatatype.XSDshort.isValidLiteral(ll));
assertTrue(XSDDatatype.XSDunsignedInt.isValidLiteral(ll));
assertTrue(XSDDatatype.XSDunsignedLong.isValidLiteral(ll));
assertTrue(XSDDatatype.XSDunsignedShort.isValidLiteral(ll));
assertTrue(XSDDatatype.XSDpositiveInteger.isValidLiteral(ll));
assertTrue(XSDDatatype.XSDdecimal.isValidLiteral(ll));
assertTrue(!XSDDatatype.XSDstring.isValidLiteral(ll));
assertTrue(!XSDDatatype.XSDbyte.isValidLiteral(ll));
assertTrue(!XSDDatatype.XSDnegativeInteger.isValidLiteral(ll));
l = m.createTypedLiteral("-2", XSDDatatype.XSDinteger);
ll = l.asNode().getLiteral();
assertTrue(XSDDatatype.XSDlong.isValidLiteral(ll));
assertTrue(XSDDatatype.XSDint.isValidLiteral(ll));
assertTrue(XSDDatatype.XSDshort.isValidLiteral(ll));
assertTrue(!XSDDatatype.XSDunsignedInt.isValidLiteral(ll));
assertTrue(!XSDDatatype.XSDunsignedLong.isValidLiteral(ll));
assertTrue(!XSDDatatype.XSDunsignedShort.isValidLiteral(ll));
assertTrue(XSDDatatype.XSDdecimal.isValidLiteral(ll));
assertTrue(!XSDDatatype.XSDpositiveInteger.isValidLiteral(ll));
assertTrue(!XSDDatatype.XSDstring.isValidLiteral(ll));
assertTrue(XSDDatatype.XSDbyte.isValidLiteral(ll));
assertTrue(XSDDatatype.XSDnegativeInteger.isValidLiteral(ll));
l = m.createTypedLiteral("4.5", XSDDatatype.XSDfloat);
ll = l.asNode().getLiteral();
assertTrue(!XSDDatatype.XSDdouble.isValidLiteral(ll));
assertTrue(!XSDDatatype.XSDdecimal.isValidLiteral(ll));
Literal l2 = m.createTypedLiteral("foo", XSDDatatype.XSDstring);
assertTrue(XSDDatatype.XSDstring.isValidLiteral(l2.asNode().getLiteral()));
assertTrue(XSDDatatype.XSDnormalizedString.isValidLiteral(l2.asNode().getLiteral()));
assertTrue(!XSDDatatype.XSDint.isValidLiteral(l2.asNode().getLiteral()));
l = m.createTypedLiteral("foo bar");
ll = l.asNode().getLiteral();
assertTrue(XSDDatatype.XSDstring.isValidLiteral(ll));
assertTrue(!XSDDatatype.XSDint.isValidLiteral(ll));
l = m.createTypedLiteral("12");
ll = l.asNode().getLiteral();
assertTrue(XSDDatatype.XSDstring.isValidLiteral(ll));
assertTrue(!XSDDatatype.XSDint.isValidLiteral(ll));
// Test the isValidValue form which had a problem with numbers
assertTrue(XSDDatatype.XSDnonNegativeInteger.isValidValue(Integer.valueOf(10)));
assertTrue(XSDDatatype.XSDnonNegativeInteger.isValidValue(Integer.valueOf(10)));
assertTrue(!XSDDatatype.XSDnonNegativeInteger.isValidValue(Integer.valueOf(-10)));
assertTrue(!XSDDatatype.XSDnonNegativeInteger.isValidValue("10"));
// The correct behaviour on float/double is unclear but will be clarified
// by the SWBP working group task force on XML schema.
// For now we leave that float, double and the decimal tree are all distinct
assertTrue(XSDDatatype.XSDfloat.isValidValue(Float.valueOf("2.3")));
assertTrue(XSDDatatype.XSDdouble.isValidValue(Double.valueOf("2.3")));
assertTrue(!XSDDatatype.XSDfloat.isValidValue(Integer.valueOf("2")));
assertTrue(!XSDDatatype.XSDfloat.isValidValue(Double.valueOf("2.3")));
}
use of org.apache.jena.graph.impl.LiteralLabel in project jena by apache.
the class Rational method testUnknown.
/**
* Test the base functioning of unknown datatypes
*/
public void testUnknown() {
String typeURI = "urn:x-hp-dt:unknown";
String typeURI2 = "urn:x-hp-dt:unknown2";
boolean originalFlag = JenaParameters.enableSilentAcceptanceOfUnknownDatatypes;
JenaParameters.enableSilentAcceptanceOfUnknownDatatypes = true;
Literal l1 = m.createTypedLiteral("foo", typeURI);
Literal l3 = m.createTypedLiteral("15", typeURI);
Literal l5 = m.createTypedLiteral("foo", typeURI2);
Literal l6 = m.createLiteral("foo", "lang1");
JenaParameters.enableSilentAcceptanceOfUnknownDatatypes = originalFlag;
// Check for successful creation
assertNotNull(l1);
assertNotNull(l3);
assertNotNull(l5);
// check equality function
assertDiffer("datatype sensitive", l1, l5);
assertDiffer("value sensitive", l1, l3);
assertDiffer("typed and plain differ", l1, l6);
// Check typed accessors
try {
l3.getInt();
assertTrue("Allowed int conversion", false);
} catch (DatatypeFormatException e) {
}
assertEquals("Extract value", l1.getValue(), new BaseDatatype.TypedValue("foo", typeURI));
assertEquals("Extract xml tag", l1.isWellFormedXML(), false);
JenaParameters.enableSilentAcceptanceOfUnknownDatatypes = false;
boolean foundException = false;
try {
m.createTypedLiteral("food", typeURI + "3");
} catch (DatatypeFormatException e2) {
foundException = true;
}
JenaParameters.enableSilentAcceptanceOfUnknownDatatypes = originalFlag;
assertTrue("Detected unknown datatype", foundException);
// Check we can create a literal of an unregistered java type without anything blowing up
Object foo = new java.sql.Date(123456l);
LiteralLabel ll = LiteralLabelFactory.createTypedLiteral(foo);
assertEquals(ll.getLexicalForm(), foo.toString());
}
Aggregations