Author: der
Date: Tue Apr 22 09:53:01 2014
New Revision: 1589060
URL: http://svn.apache.org/r1589060
Log:
Reinstating testing of user-defined datatypes to address JENA-410
Added:
jena/trunk/jena-core/testing/xsd/
jena/trunk/jena-core/testing/xsd/README_LICENSE
jena/trunk/jena-core/testing/xsd/daml+oil-ex-dt.xsd
Modified:
jena/trunk/jena-core/src/test/java/com/hp/hpl/jena/graph/test/TestTypedLiterals.java
Modified:
jena/trunk/jena-core/src/test/java/com/hp/hpl/jena/graph/test/TestTypedLiterals.java
URL:
http://svn.apache.org/viewvc/jena/trunk/jena-core/src/test/java/com/hp/hpl/jena/graph/test/TestTypedLiterals.java?rev=1589060&r1=1589059&r2=1589060&view=diff
==============================================================================
---
jena/trunk/jena-core/src/test/java/com/hp/hpl/jena/graph/test/TestTypedLiterals.java
(original)
+++
jena/trunk/jena-core/src/test/java/com/hp/hpl/jena/graph/test/TestTypedLiterals.java
Tue Apr 22 09:53:01 2014
@@ -18,6 +18,8 @@
package com.hp.hpl.jena.graph.test;
+import java.io.FileReader;
+import java.io.IOException;
import java.math.BigDecimal ;
import java.math.BigInteger ;
import java.text.SimpleDateFormat ;
@@ -154,7 +156,66 @@ public class TestTypedLiterals extends T
} catch (DatatypeFormatException e) {}
assertEquals("Extract xml tag", l1.isWellFormedXML(), false);
}
-
+
+ /**
+ * Test user defined data types.
+ * This is based on a corrected, modified version of an early DAML+OIL
example
+ * but is not specific to DAML+OIL.
+ */
+ public void testUserDefined() throws IOException {
+ String uri = "http://www.daml.org/2001/03/daml+oil-ex-dt";
+ String filename = "testing/xsd/daml+oil-ex-dt.xsd";
+ TypeMapper tm = TypeMapper.getInstance();
+ List<String> typenames = XSDDatatype.loadUserDefined(uri, new
FileReader(filename), null, tm);
+ assertIteratorValues(typenames.iterator(), new Object[] {
+ uri + "#XSDEnumerationHeight",
+ uri + "#over12",
+ uri + "#over17",
+ uri + "#over59",
+ uri + "#clothingsize" });
+
+ // Check the string restriction
+ RDFDatatype heightType = tm.getSafeTypeByName(uri +
"#XSDEnumerationHeight");
+ checkLegalLiteral("short", heightType, String.class, "short");
+ checkLegalLiteral("tall", heightType, String.class, "tall");
+ checkIllegalLiteral("shortish", heightType);
+
+ // Check the numeric restriction
+ RDFDatatype over12Type = tm.getSafeTypeByName(uri + "#over12");
+ checkLegalLiteral("15", over12Type, Integer.class, new Integer(15));
+ checkIllegalLiteral("12", over12Type);
+
+ // Check the union type
+ RDFDatatype clothingsize = tm.getSafeTypeByName(uri + "#clothingsize");
+ checkLegalLiteral("42", clothingsize, Integer.class, new Integer(42));
+ checkLegalLiteral("short", clothingsize, String.class, "short");
+
+ // Check use of isValidLiteral for base versus derived combinations
+ LiteralLabel iOver12 = m.createTypedLiteral("13",
over12Type).asNode().getLiteral();
+ LiteralLabel iDecimal14 = m.createTypedLiteral("14",
XSDDatatype.XSDdecimal).asNode().getLiteral();
+ LiteralLabel iDecimal10 = m.createTypedLiteral("10",
XSDDatatype.XSDdecimal).asNode().getLiteral();
+ LiteralLabel iString = m.createTypedLiteral("15",
XSDDatatype.XSDstring).asNode().getLiteral();
+ LiteralLabel iPlain = m.createLiteral("foo").asNode().getLiteral();
+
+ assertTrue(over12Type.isValidLiteral(iOver12));
+ assertTrue(over12Type.isValidLiteral(iDecimal14));
+ assertTrue( ! over12Type.isValidLiteral(iDecimal10));
+ assertTrue( ! over12Type.isValidLiteral(iString));
+ assertTrue( ! over12Type.isValidLiteral(iPlain));
+
+ assertTrue(XSDDatatype.XSDdecimal.isValidLiteral(iOver12));
+ assertTrue(XSDDatatype.XSDdecimal.isValidLiteral(iDecimal14));
+ assertTrue(XSDDatatype.XSDdecimal.isValidLiteral(iDecimal10));
+ assertTrue( ! XSDDatatype.XSDdecimal.isValidLiteral(iString));
+ assertTrue( ! XSDDatatype.XSDdecimal.isValidLiteral(iPlain));
+
+ assertTrue(XSDDatatype.XSDstring.isValidLiteral(iString));
+ assertTrue(XSDDatatype.XSDstring.isValidLiteral(iPlain));
+ assertTrue( ! XSDDatatype.XSDstring.isValidLiteral(iOver12));
+ assertTrue( ! XSDDatatype.XSDstring.isValidLiteral(iDecimal10));
+ assertTrue( ! XSDDatatype.XSDstring.isValidLiteral(iDecimal14));
+ }
+
public void testXMLLiteral() {
Literal ll;
Added: jena/trunk/jena-core/testing/xsd/README_LICENSE
URL:
http://svn.apache.org/viewvc/jena/trunk/jena-core/testing/xsd/README_LICENSE?rev=1589060&view=auto
==============================================================================
--- jena/trunk/jena-core/testing/xsd/README_LICENSE (added)
+++ jena/trunk/jena-core/testing/xsd/README_LICENSE Tue Apr 22 09:53:01 2014
@@ -0,0 +1,16 @@
+The following statement applied to all files in this directory unless
otherwise noted:
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
Added: jena/trunk/jena-core/testing/xsd/daml+oil-ex-dt.xsd
URL:
http://svn.apache.org/viewvc/jena/trunk/jena-core/testing/xsd/daml%2Boil-ex-dt.xsd?rev=1589060&view=auto
==============================================================================
--- jena/trunk/jena-core/testing/xsd/daml+oil-ex-dt.xsd (added)
+++ jena/trunk/jena-core/testing/xsd/daml+oil-ex-dt.xsd Tue Apr 22 09:53:01 2014
@@ -0,0 +1,53 @@
+<!--
+ <xsd:schema xmlns:xsd ="http://www.w3.org/2000/10/XMLSchema">
+-->
+<xsd:schema xmlns:xsd ="http://www.w3.org/2001/XMLSchema">
+
+<xsd:simpleType name="over12">
+ <!-- over12 is an XMLS datatype based on decimal -->
+ <!-- with the added restriction that values must be >= 13 -->
+ <xsd:restriction base="xsd:decimal">
+ <xsd:minInclusive value="13"/>
+ </xsd:restriction>
+</xsd:simpleType>
+
+<xsd:simpleType name="over17">
+ <!-- over17 is an XMLS datatype based on positiveIntege -->
+ <!-- with the added restriction that values must be >= 18 -->
+ <xsd:restriction base="xsd:positiveInteger">
+ <xsd:minInclusive value="18"/>
+ </xsd:restriction>
+</xsd:simpleType>
+
+<xsd:simpleType name="over59">
+ <!-- over59 is an XMLS datatype based on positiveIntege -->
+ <!-- with the added restriction that values must be >= 59 -->
+ <xsd:restriction base="xsd:positiveInteger">
+ <xsd:minInclusive value="60"/>
+ </xsd:restriction>
+</xsd:simpleType>
+
+<xsd:simpleType name="clothingsize">
+ <!-- clothingsize is an XMLS union datatype -->
+ <!-- values of clothingsize may be either integers or strings -->
+ <xsd:union>
+ <xsd:simpleType>
+ <xsd:restriction base='xsd:integer'/>
+ </xsd:simpleType>
+ <xsd:simpleType>
+ <xsd:restriction base='xsd:string'/>
+ </xsd:simpleType>
+ </xsd:union>
+</xsd:simpleType>
+
+<xsd:simpleType name="XSDEnumerationHeight">
+ <!-- This is an XMLS datatype valid values for which are the strings -->
+ <!-- "short", "medium" and "tall". -->
+ <xsd:restriction base="xsd:string">
+ <xsd:enumeration value="short"/>
+ <xsd:enumeration value="medium"/>
+ <xsd:enumeration value="tall"/>
+ </xsd:restriction>
+</xsd:simpleType>
+
+</xsd:schema>