Bug 7159: Add yang-test-util artifact
[yangtools.git] / yang / yang-data-codec-gson / src / test / java / org / opendaylight / yangtools / yang / data / codec / gson / JsonStreamToNormalizedNodeTest.java
index 4f59b16c03e0eb48cb65d249285fb0d7ff986614..5ab681dc290ed29a6282ebf4edf2bb9ce7f17d00 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
+ * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
@@ -11,7 +11,6 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
-import static org.opendaylight.yangtools.yang.data.codec.gson.TestUtils.loadModules;
 import static org.opendaylight.yangtools.yang.data.codec.gson.TestUtils.loadTextFile;
 import static org.opendaylight.yangtools.yang.data.impl.schema.Builders.augmentationBuilder;
 import static org.opendaylight.yangtools.yang.data.impl.schema.Builders.choiceBuilder;
@@ -24,19 +23,18 @@ import java.io.IOException;
 import java.io.StringReader;
 import java.net.URISyntaxException;
 import org.junit.BeforeClass;
-import org.junit.Ignore;
 import org.junit.Test;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter;
-import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
-import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNormalizedNodeStreamWriter;
 import org.opendaylight.yangtools.yang.data.impl.schema.NormalizedNodeResult;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 import org.opendaylight.yangtools.yang.model.api.SchemaNode;
+import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
+import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
 
 /**
  *
@@ -49,28 +47,8 @@ public class JsonStreamToNormalizedNodeTest {
     private static SchemaContext schemaContext;
 
     @BeforeClass
-    public static void initialization() throws IOException, URISyntaxException {
-        schemaContext = loadModules("/complexjson/yang");
-    }
-
-    /**
-     * case when anyxml contains simple value will be implemented when anyxml normalized node reprezentation will be
-     * specified
-     */
-    @Ignore
-    @Test
-    public void anyXmlNodeWithSimpleValueInContainer() throws IOException, URISyntaxException {
-
-    }
-
-    /**
-     * case when anyxml contains complex xml will be implemented when anyxml normalized node reprezentation will be
-     * specified
-     */
-    @Ignore
-    @Test
-    public void anyXmlNodeWithCompositeValueInContainer() throws IOException, URISyntaxException {
-
+    public static void initialization() throws IOException, URISyntaxException, ReactorException {
+        schemaContext = YangParserTestUtils.parseYangSources("/complexjson/yang");
     }
 
     @Test
@@ -174,7 +152,7 @@ public class JsonStreamToNormalizedNodeTest {
         try {
             //second parameter isn't necessary because error will be raised before it is used.
             verifyTransformationToNormalizedNode(inputJson, null);
-                       fail("Expected exception not raised");
+            fail("Expected exception not raised");
         } catch (final IllegalStateException e) {
             final String errorMessage = e.getMessage();
             assertTrue(errorMessage.contains("Choose suitable module name for element lf11-namesake:"));
@@ -207,7 +185,7 @@ public class JsonStreamToNormalizedNodeTest {
             //second parameter isn't necessary because error will be raised before it is used.
             verifyTransformationToNormalizedNode(inputJson, null);
         } catch (final IllegalStateException e) {
-            assertTrue(e.getMessage().contains("Schema node with name dummy-element wasn't found."));
+            assertTrue(e.getMessage().contains("Schema node with name dummy-element wasn't found"));
         }
     }
 
@@ -218,7 +196,7 @@ public class JsonStreamToNormalizedNodeTest {
 
         final NormalizedNodeResult result = new NormalizedNodeResult();
         final NormalizedNodeStreamWriter streamWriter = ImmutableNormalizedNodeStreamWriter.from(result);
-        final SchemaNode parentNode = schemaContext.getDataChildByName("cont1");
+        final SchemaNode parentNode = schemaContext.getDataChildByName(CONT_1);
         final JsonParserStream jsonParser = JsonParserStream.create(streamWriter, schemaContext, parentNode);
         jsonParser.parse(new JsonReader(new StringReader(inputJson)));
         final NormalizedNode<?, ?> transformedInput = result.getResult();
@@ -231,7 +209,7 @@ public class JsonStreamToNormalizedNodeTest {
 
         final NormalizedNodeResult result = new NormalizedNodeResult();
         final NormalizedNodeStreamWriter streamWriter = ImmutableNormalizedNodeStreamWriter.from(result);
-        final SchemaNode parentNode = schemaContext.getDataChildByName("cont1");
+        final SchemaNode parentNode = schemaContext.getDataChildByName(CONT_1);
         final JsonParserStream jsonParser = JsonParserStream.create(streamWriter, schemaContext, parentNode);
         jsonParser.parse(new JsonReader(new StringReader(inputJson)));
         final NormalizedNode<?, ?> transformedInput = result.getResult();
@@ -244,10 +222,10 @@ public class JsonStreamToNormalizedNodeTest {
 
         final NormalizedNodeResult result = new NormalizedNodeResult();
         final NormalizedNodeStreamWriter streamWriter = ImmutableNormalizedNodeStreamWriter.from(result);
-        final SchemaNode parentNode = schemaContext.getDataChildByName("cont1");
+        final SchemaNode parentNode = schemaContext.getDataChildByName(CONT_1);
 
-        QName augmentChoice1QName = QName.create(parentNode.getQName(), "augment-choice1");
-        QName augmentChoice2QName = QName.create(augmentChoice1QName, "augment-choice2");
+        final QName augmentChoice1QName = QName.create(parentNode.getQName(), "augment-choice1");
+        final QName augmentChoice2QName = QName.create(augmentChoice1QName, "augment-choice2");
         final QName containerQName = QName.create(augmentChoice1QName, "case11-choice-case-container");
         final QName leafQName = QName.create(augmentChoice1QName, "case11-choice-case-leaf");
 
@@ -283,7 +261,7 @@ public class JsonStreamToNormalizedNodeTest {
         assertEquals(cont1Normalized, transformedInput);
     }
 
-    private void verifyTransformationToNormalizedNode(final String inputJson,
+    private static void verifyTransformationToNormalizedNode(final String inputJson,
             final NormalizedNode<?, ?> awaitedStructure) {
         final NormalizedNodeResult result = new NormalizedNodeResult();
         final NormalizedNodeStreamWriter streamWriter = ImmutableNormalizedNodeStreamWriter.from(result);