Bug 5085: Clean-up test and retest JUnit tests
[yangtools.git] / yang / yang-data-codec-gson / src / test / java / org / opendaylight / yangtools / yang / data / codec / gson / TestingNormalizedNodeStructuresCreator.java
index f1400854d9d76d2840849a0d8c6b9a5a3165ab94..db4814c9820364919af8ba334fe5d31d5cb14708 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,
@@ -12,11 +12,8 @@ import com.google.common.collect.Sets;
 import java.util.HashMap;
 import java.util.Map;
 import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.data.api.CompositeNode;
-import org.opendaylight.yangtools.yang.data.api.SimpleNode;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.AugmentationIdentifier;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.InstanceIdentifierBuilder;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeWithValue;
@@ -32,8 +29,6 @@ import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 import org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListEntryNode;
 import org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListNode;
-import org.opendaylight.yangtools.yang.data.impl.ImmutableCompositeNode;
-import org.opendaylight.yangtools.yang.data.impl.NodeFactory;
 import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
 import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.CollectionNodeBuilder;
 import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeAttrBuilder;
@@ -42,8 +37,9 @@ import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.ListNodeBuil
 
 public class TestingNormalizedNodeStructuresCreator {
 
+    @SafeVarargs
     static NormalizedNode<?, ?> cont1Node(
-            DataContainerChild<? extends YangInstanceIdentifier.PathArgument, ?>... children) {
+            final DataContainerChild<? extends PathArgument, ?>... children) {
         DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> cont1 = Builders.containerBuilder();
         cont1.withNodeIdentifier(new NodeIdentifier(QName.create("ns:complex:json", "2014-08-11", "cont1")));
 
@@ -73,12 +69,6 @@ public class TestingNormalizedNodeStructuresCreator {
         DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> choc12Builder = Builders.choiceBuilder()
                 .withNodeIdentifier(new NodeIdentifier(QName.create("ns:complex:json", "2014-08-11", "choc12")));
 
-//        DataContainerNodeBuilder<AugmentationIdentifier, AugmentationNode> choc12Augmentation = Builders
-//                .augmentationBuilder();
-//        choc12Augmentation.withNodeIdentifier(new AugmentationIdentifier(Sets.newHashSet(QName.create(
-//                "ns:complex:json", "2014-08-11", "c12B"))));
-//        choc12Augmentation.withChild(lf17Node());
-
         choc12Builder.withChild(lf17Node());
         return choc12Builder.build();
     }
@@ -116,8 +106,9 @@ public class TestingNormalizedNodeStructuresCreator {
                 .withValue("lf15_11 value from augmentation").build();
     }
 
+    @SafeVarargs
     private static DataContainerChild<? extends PathArgument, ?> choc11Node(
-            DataContainerChild<? extends PathArgument, ?>... children) {
+            final DataContainerChild<? extends PathArgument, ?>... children) {
         DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> choc11Builder = Builders.choiceBuilder()
                 .withNodeIdentifier(new NodeIdentifier(QName.create("ns:complex:json", "2014-08-11", "choc11")));
         choc11Builder.withValue(Lists.newArrayList(children));
@@ -214,10 +205,11 @@ public class TestingNormalizedNodeStructuresCreator {
     }
 
     private static Object lf112Value() {
-        InstanceIdentifierBuilder builder = YangInstanceIdentifier.builder();
-        builder.node(QName.create("ns:complex:json", "2014-08-11", "cont1"));
-        builder.node(QName.create("ns:complex:json", "2014-08-11", "lflst11"));
-        return builder.build();
+        return YangInstanceIdentifier.create(
+                new NodeIdentifier(QName.create("ns:complex:json", "2014-08-11", "cont1")),
+                new NodeIdentifier(QName.create("ns:complex:json", "2014-08-11", "lflst11")),
+                new NodeWithValue<>(QName.create("ns:complex:json", "2014-08-11", "lflst11"),"foo")
+        );
     }
 
     private static DataContainerChild<? extends PathArgument, ?> childLflst11() {
@@ -226,40 +218,45 @@ public class TestingNormalizedNodeStructuresCreator {
         lflst11.withChild(Builders
                 .leafSetEntryBuilder()
                 .withNodeIdentifier(
-                        new NodeWithValue(QName.create("ns:complex:json", "2014-08-11", "lflst11"), "lflst11 value1"))
+                        new NodeWithValue<>(QName.create("ns:complex:json", "2014-08-11", "lflst11"), "lflst11 value1"))
                 .withValue("lflst11 value1").build());
         lflst11.withChild(Builders
                 .leafSetEntryBuilder()
                 .withNodeIdentifier(
-                        new NodeWithValue(QName.create("ns:complex:json", "2014-08-11", "lflst11"), "lflst11 value2"))
+                        new NodeWithValue<>(QName.create("ns:complex:json", "2014-08-11", "lflst11"), "lflst11 value2"))
                 .withValue("lflst11 value2").build());
         return lflst11.build();
     }
 
-    private static CompositeNode prepareLf12Value() {
-        SimpleNode<?> anyxmlInData = NodeFactory.createImmutableSimpleNode(
-                QName.create("ns:complex:json", "2014-08-11", "anyxml-in-data"), null, "foo");
-        return ImmutableCompositeNode.builder().add(anyxmlInData)
-                .setQName(QName.create("ns:complex:json", "2014-08-11", "lf12-any")).toInstance();
-    }
-
-    private static CompositeNode prepareLf13Value() {
-        SimpleNode<?> anyxmlInData = NodeFactory.createImmutableSimpleNode(
-                QName.create("ns:complex:json", "2014-08-11", "anyxml-in-data"), null, "foo");
-        return ImmutableCompositeNode.builder().add(anyxmlInData)
-                .setQName(QName.create("ns:complex:json", "2014-08-11", "lf13-any")).toInstance();
+    private static DataContainerChild<? extends PathArgument, ?> childLflst11Multiline() {
+        ListNodeBuilder<Object, LeafSetEntryNode<Object>> lflst11 = Builders.leafSetBuilder().withNodeIdentifier(
+                new NodeIdentifier(QName.create("ns:complex:json", "2014-08-11", "lflst11")));
+        lflst11.withChild(Builders
+                .leafSetEntryBuilder()
+                .withNodeIdentifier(
+                        new NodeWithValue<>(QName.create("ns:complex:json", "2014-08-11", "lflst11"), "lflst11 value1\nanother line 1"))
+                .withValue("lflst11 value1\nanother line 1").build());
+        lflst11.withChild(Builders
+                .leafSetEntryBuilder()
+                .withNodeIdentifier(
+                        new NodeWithValue<>(QName.create("ns:complex:json", "2014-08-11", "lflst11"), "lflst11 value2\r\nanother line 2"))
+                .withValue("lflst11 value2\r\nanother line 2").build());
+        return lflst11.build();
     }
 
     public static NormalizedNode<?, ?> leafNodeInContainer() {
         LeafNode<Object> lf11 = Builders.leafBuilder()
                 .withNodeIdentifier(new NodeIdentifier(QName.create("ns:complex:json", "2014-08-11", "lf11")))
-                .withValue((int) 453).build();
+                .withValue(453).build();
         return cont1Node(lf11);
     }
 
     public static NormalizedNode<?, ?> leafListNodeInContainer() {
         return cont1Node(childLflst11());
     }
+    public static NormalizedNode<?, ?> leafListNodeInContainerMultiline() {
+        return cont1Node(childLflst11Multiline());
+    }
 
     public static NormalizedNode<?, ?> keyedListNodeInContainer() {
         return cont1Node(childLst11());
@@ -279,11 +276,11 @@ public class TestingNormalizedNodeStructuresCreator {
      * @return
      */
     public static NormalizedNode<?, ?> caseNodeAugmentationInChoiceInContainer() {
-        return cont1Node(choc11Node(lf13Node(), lf15_11Node(), lf15_12Node(), lf15_21Node()));
+        return cont1Node(choc11Node(augmentC11AWithLf15_11AndLf15_12Node(), lf13Node(), augmentC11AWithLf15_21Node()));
     }
 
     public static NormalizedNode<?, ?> caseNodeExternalAugmentationInChoiceInContainer() {
-        return cont1Node(choc11Node(lf13Node(), lf15_11Node(), lf15_12Node(), lf15_11NodeExternal(), lf15_12NodeExternal()));
+        return cont1Node(choc11Node(lf13Node(), augmentC11AWithLf15_11AndLf15_12Node(), externalAugmentC11AWithLf15_11AndLf15_12Node()));
     }
 
     public static NormalizedNode<?, ?> choiceNodeAugmentationInContainer() {
@@ -294,4 +291,7 @@ public class TestingNormalizedNodeStructuresCreator {
         return cont1Node(lst12Node());
     }
 
+    public static NormalizedNode<?, ?> topLevelContainer() {
+        return cont1Node();
+    }
 }