X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-rest-connector%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Frestconf%2Fimpl%2Fcnsn%2Fto%2Fjson%2Ftest%2FCnSnToJsonBasicDataTypesTest.java;h=312365585eaa149aaa05125acc4530840451c8e9;hb=f207c0c13689d0744c2ed2eb0395076fee82ffe6;hp=f71e2eeaa656c8524cc54f7b64c41bbac93cc5a9;hpb=6eb461f54fe6705b07f34b6cee197ea968de4991;p=controller.git diff --git a/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/cnsn/to/json/test/CnSnToJsonBasicDataTypesTest.java b/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/cnsn/to/json/test/CnSnToJsonBasicDataTypesTest.java index f71e2eeaa6..312365585e 100644 --- a/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/cnsn/to/json/test/CnSnToJsonBasicDataTypesTest.java +++ b/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/cnsn/to/json/test/CnSnToJsonBasicDataTypesTest.java @@ -1,25 +1,33 @@ +/* + * Copyright (c) 2014 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, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ 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 +42,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 +59,6 @@ public class CnSnToJsonBasicDataTypesTest extends YangAndXmlAndDataSchemaLoader verifyJsonOutput(jsonOutput); } - private CompositeNode prepareData() { - MutableCompositeNode cont = NodeFactory.createMutableCompositeNode(TestUtils.buildQName("cont"), null, null, - ModifyAction.CREATE, null); - - List> 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 bits = new HashSet(); - 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 bits2 = new HashSet(); - 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 +89,6 @@ public class CnSnToJsonBasicDataTypesTest extends YangAndXmlAndDataSchemaLoader private void jsonReadContElements(JsonReader jReader) throws IOException { jReader.beginObject(); List loadedLfs = new ArrayList<>(); - boolean exceptForDecimal5Raised = false; boolean enumChecked = false; boolean bitsChecked = false; boolean lfdecimal6Checked = false; @@ -191,7 +100,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 +110,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")) {