BUG-4688: switch revisions from Date to Revision
[yangtools.git] / yang / yang-data-jaxen / src / test / java / org / opendaylight / yangtools / yang / data / jaxen / DerivedFromXPathFunctionTest.java
index c08dd24dcf25e307b3d214007152a4af0f5b9bac..1c0c1d5fb391b12bd4a33abe196c3e5aaaad5c51 100644 (file)
@@ -21,7 +21,6 @@ import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.Maps;
 import java.net.URI;
-import java.text.ParseException;
 import org.jaxen.Context;
 import org.jaxen.Function;
 import org.jaxen.FunctionCallException;
@@ -29,7 +28,7 @@ import org.junit.BeforeClass;
 import org.junit.Test;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.QNameModule;
-import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil;
+import org.opendaylight.yangtools.yang.common.Revision;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
@@ -47,18 +46,17 @@ public class DerivedFromXPathFunctionTest {
     private static JaxenSchemaContextFactory jaxenSchemaContextFactory;
 
     private static QNameModule barModule;
-    private static QName myContainer; 
+    private static QName myContainer;
     private static QName myList;
     private static QName keyLeaf;
     private static QName idrefLeaf;
     private static QName idC2Identity;
 
     @BeforeClass
-    public static void setup() throws ParseException {
+    public static void setup() {
         jaxenSchemaContextFactory = new JaxenSchemaContextFactory();
 
-        barModule = QNameModule.create(URI.create("bar-ns"),
-                SimpleDateFormatUtil.getRevisionFormat().parse("2017-04-03"));
+        barModule = QNameModule.create(URI.create("bar-ns"), Revision.valueOf("2017-04-03"));
         myContainer = QName.create(barModule, "my-container");
         myList = QName.create(barModule, "my-list");
         keyLeaf = QName.create(barModule, "key-leaf");
@@ -69,9 +67,9 @@ public class DerivedFromXPathFunctionTest {
     @Test
     public void testDerivedFromFunction() throws Exception {
         // also includes test for derived-from-or-self function
-        final SchemaContext schemaContext = YangParserTestUtils.parseYangSources(ImmutableList.of(
+        final SchemaContext schemaContext = YangParserTestUtils.parseYangResources(DerivedFromXPathFunctionTest.class,
                 "/yang-xpath-functions-test/derived-from-function/foo.yang",
-                "/yang-xpath-functions-test/derived-from-function/bar.yang"));
+                "/yang-xpath-functions-test/derived-from-function/bar.yang");
         assertNotNull(schemaContext);
 
         final XPathSchemaContext jaxenSchemaContext = jaxenSchemaContextFactory.createContext(schemaContext);
@@ -108,7 +106,7 @@ public class DerivedFromXPathFunctionTest {
 
     @Test
     public void testInvalidTypeOfCorrespondingSchemaNode() throws Exception {
-        final SchemaContext schemaContext = YangParserTestUtils.parseYangSource(
+        final SchemaContext schemaContext = YangParserTestUtils.parseYangResources(DerivedFromXPathFunctionTest.class,
                 "/yang-xpath-functions-test/derived-from-function/bar-invalid.yang");
         assertNotNull(schemaContext);
 
@@ -132,9 +130,9 @@ public class DerivedFromXPathFunctionTest {
 
     @Test
     public void testInvalidNormalizedNodeValueType() throws Exception {
-        final SchemaContext schemaContext = YangParserTestUtils.parseYangSources(ImmutableList.of(
+        final SchemaContext schemaContext = YangParserTestUtils.parseYangResources(DerivedFromXPathFunctionTest.class,
                 "/yang-xpath-functions-test/derived-from-function/foo.yang",
-                "/yang-xpath-functions-test/derived-from-function/bar.yang"));
+                "/yang-xpath-functions-test/derived-from-function/bar.yang");
         assertNotNull(schemaContext);
 
         final XPathSchemaContext jaxenSchemaContext = jaxenSchemaContextFactory.createContext(schemaContext);
@@ -157,9 +155,9 @@ public class DerivedFromXPathFunctionTest {
 
     @Test
     public void shouldFailOnUnknownPrefixOfIdentity() throws Exception {
-        final SchemaContext schemaContext = YangParserTestUtils.parseYangSources(ImmutableList.of(
+        final SchemaContext schemaContext = YangParserTestUtils.parseYangResources(DerivedFromXPathFunctionTest.class,
                 "/yang-xpath-functions-test/derived-from-function/foo.yang",
-                "/yang-xpath-functions-test/derived-from-function/bar.yang"));
+                "/yang-xpath-functions-test/derived-from-function/bar.yang");
         assertNotNull(schemaContext);
 
         final XPathSchemaContext jaxenSchemaContext = jaxenSchemaContextFactory.createContext(schemaContext);
@@ -181,15 +179,16 @@ public class DerivedFromXPathFunctionTest {
             getDerivedFromResult(derivedFromFunction, normalizedNodeContext, "unknown-prefix:id-a3");
             fail("Function call should have failed on unresolved prefix of the identity argument.");
         } catch (IllegalArgumentException ex) {
-            assertEquals("Cannot resolve prefix 'unknown-prefix' from identity 'unknown-prefix:id-a3'.", ex.getMessage());
+            assertEquals("Cannot resolve prefix 'unknown-prefix' from identity 'unknown-prefix:id-a3'.",
+                ex.getMessage());
         }
     }
 
     @Test
     public void shouldFailOnMalformedIdentityArgument() throws Exception {
-        final SchemaContext schemaContext = YangParserTestUtils.parseYangSources(ImmutableList.of(
+        final SchemaContext schemaContext = YangParserTestUtils.parseYangResources(DerivedFromXPathFunctionTest.class,
                 "/yang-xpath-functions-test/derived-from-function/foo.yang",
-                "/yang-xpath-functions-test/derived-from-function/bar.yang"));
+                "/yang-xpath-functions-test/derived-from-function/bar.yang");
         assertNotNull(schemaContext);
 
         final XPathSchemaContext jaxenSchemaContext = jaxenSchemaContextFactory.createContext(schemaContext);
@@ -217,9 +216,9 @@ public class DerivedFromXPathFunctionTest {
 
     @Test
     public void shouldFailOnUnknownIdentityArgument() throws Exception {
-        final SchemaContext schemaContext = YangParserTestUtils.parseYangSources(ImmutableList.of(
+        final SchemaContext schemaContext = YangParserTestUtils.parseYangResources(DerivedFromXPathFunctionTest.class,
                 "/yang-xpath-functions-test/derived-from-function/foo.yang",
-                "/yang-xpath-functions-test/derived-from-function/bar.yang"));
+                "/yang-xpath-functions-test/derived-from-function/bar.yang");
         assertNotNull(schemaContext);
 
         final XPathSchemaContext jaxenSchemaContext = jaxenSchemaContextFactory.createContext(schemaContext);
@@ -242,8 +241,8 @@ public class DerivedFromXPathFunctionTest {
             fail("Function call should have failed on unknown identity argument.");
         } catch (IllegalArgumentException ex) {
             assertTrue(ex.getMessage().startsWith(
-                    "Identity (foo-ns?revision=2017-04-03)id-a333 does not have a corresponding identity schema " +
-                    "node in the module"));
+                    "Identity (foo-ns?revision=2017-04-03)id-a333 does not have a corresponding identity schema "
+                    "node in the module"));
         }
     }
 
@@ -304,4 +303,4 @@ public class DerivedFromXPathFunctionTest {
                 .node(new NodeIdentifierWithPredicates(myList, keys)).node(idrefLeaf);
         return path;
     }
-}
\ No newline at end of file
+}