Merge "Fix testing support for OSGi services registration under String name(s)"
[controller.git] / opendaylight / md-sal / sal-rest-connector / src / test / java / org / opendaylight / controller / sal / restconf / impl / cnsn / to / json / test / CnSnToJsonBasicDataTypesTest.java
index f71e2eeaa656c8524cc54f7b64c41bbac93cc5a9..c45c0b3288b566f7f0a0c397fb509db8db4e3cb1 100644 (file)
@@ -1,25 +1,26 @@
 package org.opendaylight.controller.sal.restconf.impl.cnsn.to.json.test;
 
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
 
 import java.io.IOException;
 import java.io.StringReader;
-import java.math.BigDecimal;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
 
 import javax.ws.rs.WebApplicationException;
-import javax.xml.bind.DatatypeConverter;
 
 import org.junit.BeforeClass;
 import org.junit.Test;
 import org.opendaylight.controller.sal.rest.impl.StructuredDataToJsonProvider;
+import org.opendaylight.controller.sal.rest.impl.XmlToCompositeNodeProvider;
 import org.opendaylight.controller.sal.restconf.impl.test.TestUtils;
 import org.opendaylight.controller.sal.restconf.impl.test.YangAndXmlAndDataSchemaLoader;
-import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.data.api.*;
-import org.opendaylight.yangtools.yang.data.impl.NodeFactory;
+import org.opendaylight.yangtools.yang.data.api.CompositeNode;
 
 import com.google.gson.stream.JsonReader;
 import com.google.gson.stream.JsonToken;
@@ -34,7 +35,8 @@ public class CnSnToJsonBasicDataTypesTest extends YangAndXmlAndDataSchemaLoader
     @Test
     public void simpleYangDataTest() {
 
-        CompositeNode compositeNode = TestUtils.loadCompositeNode("/cnsn-to-json/simple-data-types/xml/data.xml");
+        CompositeNode compositeNode = TestUtils.readInputToCnSn("/cnsn-to-json/simple-data-types/xml/data.xml",
+                XmlToCompositeNodeProvider.INSTANCE);
 
         String jsonOutput = null;
 
@@ -50,105 +52,6 @@ public class CnSnToJsonBasicDataTypesTest extends YangAndXmlAndDataSchemaLoader
         verifyJsonOutput(jsonOutput);
     }
 
-    private CompositeNode prepareData() {
-        MutableCompositeNode cont = NodeFactory.createMutableCompositeNode(TestUtils.buildQName("cont"), null, null,
-                ModifyAction.CREATE, null);
-
-        List<Node<?>> childNodes = new ArrayList<>();
-        childNodes.add(NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lfnint8Min"), cont, (byte) -128,
-                ModifyAction.CREATE, null));
-        childNodes.add(NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lfnint8Max"), cont, (byte) 127,
-                ModifyAction.CREATE, null));
-        childNodes.add(NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lfnint16Min"), cont, (short) -32768,
-                ModifyAction.CREATE, null));
-        childNodes.add(NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lfnint16Max"), cont, (short) 32767,
-                ModifyAction.CREATE, null));
-        childNodes.add(NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lfnint32Min"), cont,
-                (int) -2147483648, ModifyAction.CREATE, null));
-        childNodes.add(NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lfnint32Max"), cont, (int) 2147483647,
-                ModifyAction.CREATE, null));
-        childNodes.add(NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lfnint64Min"), cont, new Long(
-                "-9223372036854775807"), ModifyAction.CREATE, null));
-        childNodes.add(NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lfnint64Max"), cont, new Long(
-                "9223372036854775807"), ModifyAction.CREATE, null));
-        childNodes.add(NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lfnuint8Max"), cont, (short) 255,
-                ModifyAction.CREATE, null));
-        childNodes.add(NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lfnuint16Max"), cont, (int) 65535,
-                ModifyAction.CREATE, null));
-        childNodes.add(NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lfnuint32Max"), cont, new Long(
-                "4294967295"), ModifyAction.CREATE, null));
-        childNodes.add(NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lfstr"), cont, "lfstr",
-                ModifyAction.CREATE, null));
-        childNodes.add(NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lfstr1"), cont, "",
-                ModifyAction.CREATE, null));
-        childNodes.add(NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lfbool1"), cont, Boolean.TRUE,
-                ModifyAction.CREATE, null));
-        childNodes.add(NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lfbool2"), cont, Boolean.FALSE,
-                ModifyAction.CREATE, null));
-        childNodes.add(NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lfdecimal1"), cont, new BigDecimal(
-                "43.32"), ModifyAction.CREATE, null));
-        childNodes.add(NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lfdecimal2"), cont, new BigDecimal(
-                "-0.43"), ModifyAction.CREATE, null));
-        childNodes.add(NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lfdecimal3"), cont, new BigDecimal(
-                "43"), ModifyAction.CREATE, null));
-        childNodes.add(NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lfdecimal4"), cont, new BigDecimal(
-                "43E3"), ModifyAction.CREATE, null));
-        childNodes.add(NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lfdecimal6"), cont, new BigDecimal(
-                "33.12345"), ModifyAction.CREATE, null));
-        childNodes.add(NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lfenum"), cont, "enum3",
-                ModifyAction.CREATE, null));
-
-        HashSet<String> bits = new HashSet<String>();
-        bits.add("bit3");
-        childNodes.add(NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lfbits"), cont, bits,
-                ModifyAction.CREATE, null));
-
-        childNodes.add(NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lfbinary"), cont, DatatypeConverter
-                .parseBase64Binary("AAaacdabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"),
-                ModifyAction.CREATE, null));
-        childNodes.add(NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lfempty"), cont, null,
-                ModifyAction.CREATE, null));
-        childNodes.add(NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lfunion1"), cont, (int) 324,
-                ModifyAction.CREATE, null));
-        childNodes.add(NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lfunion2"), cont, new BigDecimal(
-                "33.3"), ModifyAction.CREATE, null));
-        childNodes.add(NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lfunion3"), cont, "55",
-                ModifyAction.CREATE, null));
-        childNodes.add(NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lfunion4"), cont, Boolean.TRUE,
-                ModifyAction.CREATE, null));
-        childNodes.add(NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lfunion5"), cont, "true",
-                ModifyAction.CREATE, null));
-        childNodes.add(NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lfunion6"), cont, "false",
-                ModifyAction.CREATE, null));
-        childNodes.add(NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lfunion7"), cont, null,
-                ModifyAction.CREATE, null));
-        childNodes.add(NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lfunion8"), cont, "",
-                ModifyAction.CREATE, null));
-        childNodes.add(NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lfunion9"), cont, "",
-                ModifyAction.CREATE, null));
-
-        HashSet<String> bits2 = new HashSet<String>();
-        bits2.add("bt1");
-        childNodes.add(NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lfunion10"), cont, bits2,
-                ModifyAction.CREATE, null));
-
-        childNodes.add(NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lfunion11"), cont, (short) 33,
-                ModifyAction.CREATE, null));
-        childNodes.add(NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lfunion12"), cont, Boolean.FALSE,
-                ModifyAction.CREATE, null));
-        try {
-            childNodes.add(NodeFactory.createMutableSimpleNode(TestUtils.buildQName("identityref1"), cont, new QName(
-                    new URI("simple:data:types"), "iden"), ModifyAction.CREATE, null));
-        } catch (URISyntaxException e) {
-        }
-
-        cont.getChildren().addAll(childNodes);
-
-        cont.init();
-
-        return cont;
-    }
-
     private void verifyJsonOutput(String jsonOutput) {
         StringReader strReader = new StringReader(jsonOutput);
         JsonReader jReader = new JsonReader(strReader);
@@ -179,7 +82,6 @@ public class CnSnToJsonBasicDataTypesTest extends YangAndXmlAndDataSchemaLoader
     private void jsonReadContElements(JsonReader jReader) throws IOException {
         jReader.beginObject();
         List<String> loadedLfs = new ArrayList<>();
-        boolean exceptForDecimal5Raised = false;
         boolean enumChecked = false;
         boolean bitsChecked = false;
         boolean lfdecimal6Checked = false;
@@ -191,7 +93,6 @@ public class CnSnToJsonBasicDataTypesTest extends YangAndXmlAndDataSchemaLoader
         boolean lfbool2Checked = false;
         boolean lfstrChecked = false;
         boolean lfbinaryChecked = false;
-        // boolean lfref1Checked = false;
         boolean lfemptyChecked = false;
         boolean lfstr1Checked = false;
         boolean lfidentityrefChecked = false;
@@ -202,11 +103,7 @@ public class CnSnToJsonBasicDataTypesTest extends YangAndXmlAndDataSchemaLoader
             try {
                 peek = jReader.peek();
             } catch (IOException e) {
-                if (keyName.equals("lfdecimal5")) {
-                    exceptForDecimal5Raised = true;
-                } else {
-                    assertTrue("Key " + keyName + " has incorrect value for specifed type", false);
-                }
+                assertTrue("Key " + keyName + " has incorrect value for specifed type", false);
             }
 
             if (keyName.startsWith("lfnint") || keyName.startsWith("lfnuint")) {