Merge "Eliminate all trailing whitespace in xtend"
authorTony Tkacik <ttkacik@cisco.com>
Thu, 12 Mar 2015 17:10:46 +0000 (17:10 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Thu, 12 Mar 2015 17:10:46 +0000 (17:10 +0000)
yang/yang-data-codec-gson/src/main/java/org/opendaylight/yangtools/yang/data/codec/gson/ChoiceNodeDataWithSchema.java
yang/yang-data-codec-gson/src/main/java/org/opendaylight/yangtools/yang/data/codec/gson/CompositeNodeDataWithSchema.java
yang/yang-data-codec-gson/src/main/java/org/opendaylight/yangtools/yang/data/codec/gson/JsonParserStream.java
yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/JsonStreamToNormalizedNodeTest.java
yang/yang-data-codec-gson/src/test/resources/complexjson/keyed-list-restconf-behaviour.json [new file with mode: 0644]

index b7ab6fa19bef10d50eccd9dc9f612c3b0e1f5022..cacc6727def1a89e8a842192d6f5600bdee815c6 100644 (file)
@@ -27,8 +27,8 @@ class ChoiceNodeDataWithSchema extends CompositeNodeDataWithSchema {
     }
 
     @Override
-    protected CompositeNodeDataWithSchema addCompositeChild(final DataSchemaNode schema) {
-        CaseNodeDataWithSchema newChild = new CaseNodeDataWithSchema((ChoiceCaseNode) schema);
+    protected CompositeNodeDataWithSchema addCompositeChild(final DataSchemaNode schema, final boolean rootListItem) {
+        final CaseNodeDataWithSchema newChild = new CaseNodeDataWithSchema((ChoiceCaseNode) schema);
         caseNodeDataWithSchema = newChild;
         addCompositeChild(newChild);
         return newChild;
index 70612910d65ae098371ba9635c1004546a410be2..c071bbde826fe3c3d98f5f05de11285967f3830b 100644 (file)
@@ -59,14 +59,14 @@ class CompositeNodeDataWithSchema extends AbstractNodeDataWithSchema {
         super(schema);
     }
 
-    public AbstractNodeDataWithSchema addChild(final Deque<DataSchemaNode> schemas) {
+    public AbstractNodeDataWithSchema addChild(final Deque<DataSchemaNode> schemas, final boolean rootListItem) {
         Preconditions.checkArgument(!schemas.isEmpty(), "Expecting at least one schema");
 
         // Pop the first node...
         final DataSchemaNode schema = schemas.pop();
         if (schemas.isEmpty()) {
             // Simple, direct node
-            return addChild(schema);
+            return addChild(schema,rootListItem);
         }
 
         // The choice/case mess, reuse what we already popped
@@ -95,12 +95,12 @@ class CompositeNodeDataWithSchema extends AbstractNodeDataWithSchema {
 
         CompositeNodeDataWithSchema caseNodeDataWithSchema = findChoice(childNodes, choiceCandidate, caseCandidate);
         if (caseNodeDataWithSchema == null) {
-            ChoiceNodeDataWithSchema choiceNodeDataWithSchema = new ChoiceNodeDataWithSchema(choiceNode);
+            final ChoiceNodeDataWithSchema choiceNodeDataWithSchema = new ChoiceNodeDataWithSchema(choiceNode);
             addChild(choiceNodeDataWithSchema);
-            caseNodeDataWithSchema = choiceNodeDataWithSchema.addCompositeChild(caseNode);
+            caseNodeDataWithSchema = choiceNodeDataWithSchema.addCompositeChild(caseNode,rootListItem);
         }
 
-        return caseNodeDataWithSchema.addChild(schemas);
+        return caseNodeDataWithSchema.addChild(schemas, rootListItem);
     }
 
     private AbstractNodeDataWithSchema addSimpleChild(final DataSchemaNode schema) {
@@ -128,10 +128,10 @@ class CompositeNodeDataWithSchema extends AbstractNodeDataWithSchema {
     private CaseNodeDataWithSchema findChoice(final Collection<AbstractNodeDataWithSchema> childNodes, final DataSchemaNode choiceCandidate,
             final DataSchemaNode caseCandidate) {
         if (childNodes != null) {
-            for (AbstractNodeDataWithSchema nodeDataWithSchema : childNodes) {
+            for (final AbstractNodeDataWithSchema nodeDataWithSchema : childNodes) {
                 if (nodeDataWithSchema instanceof ChoiceNodeDataWithSchema
                         && nodeDataWithSchema.getSchema().getQName().equals(choiceCandidate.getQName())) {
-                    CaseNodeDataWithSchema casePrevious = ((ChoiceNodeDataWithSchema) nodeDataWithSchema).getCase();
+                    final CaseNodeDataWithSchema casePrevious = ((ChoiceNodeDataWithSchema) nodeDataWithSchema).getCase();
 
                     Preconditions.checkArgument(casePrevious.getSchema().getQName().equals(caseCandidate.getQName()),
                         "Data from case %s are specified but other data from case %s were specified erlier. Data aren't from the same case.",
@@ -144,10 +144,20 @@ class CompositeNodeDataWithSchema extends AbstractNodeDataWithSchema {
         return null;
     }
 
-    AbstractNodeDataWithSchema addCompositeChild(final DataSchemaNode schema) {
+    AbstractNodeDataWithSchema addCompositeChild(final DataSchemaNode schema, final boolean rootListItem) {
         CompositeNodeDataWithSchema newChild;
         if (schema instanceof ListSchemaNode) {
             newChild = new ListNodeDataWithSchema(schema);
+            /*
+             * If we are reading root we may want to emit map also for object which represent one list
+             * item.
+             * */
+            if(rootListItem) {
+                addCompositeChild(newChild);
+                final ListEntryNodeDataWithSchema entry = new ListEntryNodeDataWithSchema(schema);
+                newChild.addChild(entry);
+                return entry;
+            }
         } else if (schema instanceof LeafListSchemaNode) {
             newChild = new LeafListNodeDataWithSchema(schema);
         } else if (schema instanceof ContainerSchemaNode) {
@@ -160,7 +170,7 @@ class CompositeNodeDataWithSchema extends AbstractNodeDataWithSchema {
     }
 
     void addCompositeChild(final CompositeNodeDataWithSchema newChild) {
-        AugmentationSchema augSchema = findCorrespondingAugment(getSchema(), newChild.getSchema());
+        final AugmentationSchema augSchema = findCorrespondingAugment(getSchema(), newChild.getSchema());
         if (augSchema != null) {
             augmentationsToChild.put(augSchema, newChild);
         } else {
@@ -168,9 +178,9 @@ class CompositeNodeDataWithSchema extends AbstractNodeDataWithSchema {
         }
     }
 
-    private AbstractNodeDataWithSchema addChild(final DataSchemaNode schema) {
-        AbstractNodeDataWithSchema newChild = addSimpleChild(schema);
-        return newChild == null ? addCompositeChild(schema) : newChild;
+    private AbstractNodeDataWithSchema addChild(final DataSchemaNode schema, final boolean rootListItem) {
+        final AbstractNodeDataWithSchema newChild = addSimpleChild(schema);
+        return newChild == null ? addCompositeChild(schema,rootListItem) : newChild;
     }
 
     public void addChild(final AbstractNodeDataWithSchema newChild) {
@@ -191,8 +201,8 @@ class CompositeNodeDataWithSchema extends AbstractNodeDataWithSchema {
      */
     AugmentationSchema findCorrespondingAugment(final DataSchemaNode parent, final DataSchemaNode child) {
         if (parent instanceof AugmentationTarget && !((parent instanceof ChoiceCaseNode) || (parent instanceof ChoiceSchemaNode))) {
-            for (AugmentationSchema augmentation : ((AugmentationTarget) parent).getAvailableAugmentations()) {
-                DataSchemaNode childInAugmentation = augmentation.getDataChildByName(child.getQName());
+            for (final AugmentationSchema augmentation : ((AugmentationTarget) parent).getAvailableAugmentations()) {
+                final DataSchemaNode childInAugmentation = augmentation.getDataChildByName(child.getQName());
                 if (childInAugmentation != null) {
                     return augmentation;
                 }
@@ -203,15 +213,15 @@ class CompositeNodeDataWithSchema extends AbstractNodeDataWithSchema {
 
     @Override
     public void write(final NormalizedNodeStreamWriter writer) throws IOException {
-        for (AbstractNodeDataWithSchema child : children) {
+        for (final AbstractNodeDataWithSchema child : children) {
             child.write(writer);
         }
-        for (Entry<AugmentationSchema, Collection<AbstractNodeDataWithSchema>> augmentationToChild : augmentationsToChild.asMap().entrySet()) {
+        for (final Entry<AugmentationSchema, Collection<AbstractNodeDataWithSchema>> augmentationToChild : augmentationsToChild.asMap().entrySet()) {
             final Collection<AbstractNodeDataWithSchema> childsFromAgumentation = augmentationToChild.getValue();
             if (!childsFromAgumentation.isEmpty()) {
                 writer.startAugmentationNode(toAugmentationIdentifier(augmentationToChild.getKey()));
 
-                for (AbstractNodeDataWithSchema nodeDataWithSchema : childsFromAgumentation) {
+                for (final AbstractNodeDataWithSchema nodeDataWithSchema : childsFromAgumentation) {
                     nodeDataWithSchema.write(writer);
                 }
 
index aad07b35665f9c8c15390a659cb0af448cd45983..f56d6d2344880a6aa676be7230930be41521256d 100644 (file)
@@ -83,7 +83,7 @@ public final class JsonParserStream implements Closeable, Flushable {
             reader.peek();
             isEmpty = false;
             final CompositeNodeDataWithSchema compositeNodeDataWithSchema = new CompositeNodeDataWithSchema(parentNode);
-            read(reader, compositeNodeDataWithSchema);
+            read(reader, compositeNodeDataWithSchema,true);
             compositeNodeDataWithSchema.write(writer);
 
             return this;
@@ -115,7 +115,7 @@ public final class JsonParserStream implements Closeable, Flushable {
         ((SimpleNodeDataWithSchema) parent).setValue(translatedValue);
     }
 
-    public void read(final JsonReader in, final AbstractNodeDataWithSchema parent) throws IOException {
+    public void read(final JsonReader in, final AbstractNodeDataWithSchema parent, final boolean rootRead) throws IOException {
         switch (in.peek()) {
         case STRING:
         case NUMBER:
@@ -139,7 +139,7 @@ public final class JsonParserStream implements Closeable, Flushable {
                     newChild = new LeafListEntryNodeDataWithSchema(parent.getSchema());
                     ((CompositeNodeDataWithSchema) parent).addChild(newChild);
                 }
-                read(in, newChild);
+                read(in, newChild,false);
             }
             in.endArray();
             return;
@@ -163,12 +163,12 @@ public final class JsonParserStream implements Closeable, Flushable {
                 }
 
                 AbstractNodeDataWithSchema newChild;
-                newChild = ((CompositeNodeDataWithSchema) parent).addChild(childDataSchemaNodes);
+                newChild = ((CompositeNodeDataWithSchema) parent).addChild(childDataSchemaNodes,rootRead);
 //                FIXME:anyxml data shouldn't be skipped but should be loaded somehow. will be specified after 17AUG2014
                 if (newChild instanceof AnyXmlNodeDataWithSchema) {
                     in.skipValue();
                 } else {
-                    read(in, newChild);
+                    read(in, newChild,false);
                 }
                 removeNamespace();
             }
index 1a71142be5553ecee451b42edb5fce7d02bf2612..6fb7b1ed34cfc2d7e7860d06f67f753ecf6aebaf 100644 (file)
@@ -8,6 +8,7 @@
 package org.opendaylight.yangtools.yang.data.codec.gson;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 import static org.opendaylight.yangtools.yang.data.codec.gson.TestUtils.loadModules;
 import static org.opendaylight.yangtools.yang.data.codec.gson.TestUtils.loadTextFile;
@@ -24,6 +25,7 @@ import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStre
 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;
 
 /**
  *
@@ -60,34 +62,34 @@ public class JsonStreamToNormalizedNodeTest {
 
     @Test
     public void leafNodeInContainer() throws IOException, URISyntaxException {
-        String inputJson = loadTextFile("/complexjson/leaf-node-in-container.json");
+        final String inputJson = loadTextFile("/complexjson/leaf-node-in-container.json");
         verifyTransformationToNormalizedNode(inputJson, TestingNormalizedNodeStructuresCreator.leafNodeInContainer());
     }
 
     @Test
     public void leafNodeViaAugmentationInContainer() throws IOException, URISyntaxException {
-        String inputJson = loadTextFile("/complexjson/leaf-node-via-augmentation-in-container.json");
+        final String inputJson = loadTextFile("/complexjson/leaf-node-via-augmentation-in-container.json");
         verifyTransformationToNormalizedNode(inputJson,
                 TestingNormalizedNodeStructuresCreator.leafNodeViaAugmentationInContainer());
     }
 
     @Test
     public void leafListNodeInContainer() throws IOException, URISyntaxException {
-        String inputJson = loadTextFile("/complexjson/leaflist-node-in-container.json");
+        final String inputJson = loadTextFile("/complexjson/leaflist-node-in-container.json");
         verifyTransformationToNormalizedNode(inputJson,
                 TestingNormalizedNodeStructuresCreator.leafListNodeInContainer());
     }
 
     @Test
     public void keyedListNodeInContainer() throws IOException, URISyntaxException {
-        String inputJson = loadTextFile("/complexjson/keyed-list-node-in-container.json");
+        final String inputJson = loadTextFile("/complexjson/keyed-list-node-in-container.json");
         verifyTransformationToNormalizedNode(inputJson,
                 TestingNormalizedNodeStructuresCreator.keyedListNodeInContainer());
     }
 
     @Test
     public void choiceNodeInContainer() throws IOException, URISyntaxException {
-        String inputJson = loadTextFile("/complexjson/choice-node-in-container.json");
+        final String inputJson = loadTextFile("/complexjson/choice-node-in-container.json");
         verifyTransformationToNormalizedNode(inputJson, TestingNormalizedNodeStructuresCreator.choiceNodeInContainer());
     }
 
@@ -100,7 +102,7 @@ public class JsonStreamToNormalizedNodeTest {
      */
     @Test
     public void caseNodeAugmentationInChoiceInContainer() throws IOException, URISyntaxException {
-        String inputJson = loadTextFile("/complexjson/case-node-augmentation-in-choice-in-container.json");
+        final String inputJson = loadTextFile("/complexjson/case-node-augmentation-in-choice-in-container.json");
         verifyTransformationToNormalizedNode(inputJson,
                 TestingNormalizedNodeStructuresCreator.caseNodeAugmentationInChoiceInContainer());
     }
@@ -113,7 +115,7 @@ public class JsonStreamToNormalizedNodeTest {
      */
     @Test
     public void caseNodeExternalAugmentationInChoiceInContainer() throws IOException, URISyntaxException {
-        String inputJson = loadTextFile("/complexjson/case-node-external-augmentation-in-choice-in-container.json");
+        final String inputJson = loadTextFile("/complexjson/case-node-external-augmentation-in-choice-in-container.json");
         verifyTransformationToNormalizedNode(inputJson,
                 TestingNormalizedNodeStructuresCreator.caseNodeExternalAugmentationInChoiceInContainer());
     }
@@ -123,14 +125,14 @@ public class JsonStreamToNormalizedNodeTest {
      */
     @Test
     public void choiceNodeAugmentationInContainer() throws IOException, URISyntaxException {
-        String inputJson = loadTextFile("/complexjson/choice-node-augmentation-in-container.json");
+        final String inputJson = loadTextFile("/complexjson/choice-node-augmentation-in-container.json");
         verifyTransformationToNormalizedNode(inputJson,
                 TestingNormalizedNodeStructuresCreator.choiceNodeAugmentationInContainer());
     }
 
     @Test
     public void unkeyedNodeInContainer() throws IOException, URISyntaxException {
-        String inputJson = loadTextFile("/complexjson/unkeyed-node-in-container.json");
+        final String inputJson = loadTextFile("/complexjson/unkeyed-node-in-container.json");
         verifyTransformationToNormalizedNode(inputJson, TestingNormalizedNodeStructuresCreator.unkeyedNodeInContainer());
     }
 
@@ -142,7 +144,7 @@ public class JsonStreamToNormalizedNodeTest {
      */
     @Test
     public void missingModuleInfoInTopLevelElement() throws IOException, URISyntaxException {
-        String inputJson = loadTextFile("/complexjson/missing-module-in-top-level.json");
+        final String inputJson = loadTextFile("/complexjson/missing-module-in-top-level.json");
         verifyTransformationToNormalizedNode(inputJson, TestingNormalizedNodeStructuresCreator.topLevelContainer());
     }
 
@@ -155,11 +157,11 @@ public class JsonStreamToNormalizedNodeTest {
      */
     @Test
     public void leafNamesakes() throws IOException, URISyntaxException {
-        String inputJson = loadTextFile("/complexjson/namesakes.json");
+        final String inputJson = loadTextFile("/complexjson/namesakes.json");
         try {
             //second parameter isn't necessary because error will be raised before it is used.
             verifyTransformationToNormalizedNode(inputJson, null);
-        } catch (IllegalStateException e) {
+        } catch (final IllegalStateException e) {
             final String errorMessage = e.getMessage();
             assertTrue(errorMessage.contains("Choose suitable module name for element lf11-namesake:"));
             assertTrue(errorMessage.contains("complexjson-augmentation"));
@@ -175,23 +177,36 @@ public class JsonStreamToNormalizedNodeTest {
      */
     @Test
     public void parsingNotExistingElement() throws IOException, URISyntaxException {
-        String inputJson = loadTextFile("/complexjson/not-existing-element.json");
+        final String inputJson = loadTextFile("/complexjson/not-existing-element.json");
         try {
             //second parameter isn't necessary because error will be raised before it is used.
             verifyTransformationToNormalizedNode(inputJson, null);
-        } catch (IllegalStateException e) {
+        } catch (final IllegalStateException e) {
             assertTrue(e.getMessage().contains("Schema node with name dummy-element wasn't found."));
         }
     }
 
 
+    @Test
+    public void listItemWithoutArray() throws IOException, URISyntaxException {
+        final String inputJson = loadTextFile("/complexjson/keyed-list-restconf-behaviour.json");
+
+        final NormalizedNodeResult result = new NormalizedNodeResult();
+        final NormalizedNodeStreamWriter streamWriter = ImmutableNormalizedNodeStreamWriter.from(result);
+        final SchemaNode parentNode = schemaContext.getDataChildByName("cont1");
+        final JsonParserStream jsonParser = JsonParserStream.create(streamWriter, schemaContext, parentNode);
+        jsonParser.parse(new JsonReader(new StringReader(inputJson)));
+        final NormalizedNode<?, ?> transformedInput = result.getResult();
+        assertNotNull(transformedInput);
+    }
+
     private void verifyTransformationToNormalizedNode(final String inputJson,
             final NormalizedNode<?, ?> awaitedStructure) {
-        NormalizedNodeResult result = new NormalizedNodeResult();
+        final NormalizedNodeResult result = new NormalizedNodeResult();
         final NormalizedNodeStreamWriter streamWriter = ImmutableNormalizedNodeStreamWriter.from(result);
-        JsonParserStream jsonParser = JsonParserStream.create(streamWriter, schemaContext);
+        final JsonParserStream jsonParser = JsonParserStream.create(streamWriter, schemaContext);
         jsonParser.parse(new JsonReader(new StringReader(inputJson)));
-        NormalizedNode<?, ?> transformedInput = result.getResult();
+        final NormalizedNode<?, ?> transformedInput = result.getResult();
         assertEquals("Transformation of json input to normalized node wasn't successful.", awaitedStructure,
                 transformedInput);
     }
diff --git a/yang/yang-data-codec-gson/src/test/resources/complexjson/keyed-list-restconf-behaviour.json b/yang/yang-data-codec-gson/src/test/resources/complexjson/keyed-list-restconf-behaviour.json
new file mode 100644 (file)
index 0000000..2844d7d
--- /dev/null
@@ -0,0 +1,8 @@
+{
+  "lst11": {
+                "key111":"key111 value",
+                "lf112":"/complexjson:cont1/complexjson:lflst11[.='foo']",
+                "lf113":"lf113 value",
+                "lf111":"lf111 value"
+            }
+}