-package org.opendaylight.controller.sal.restconf.impl.test;
+package org.opendaylight.controller.sal.restconf.impl.cnsn.to.json.test;
-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 static org.junit.Assert.*;
-import java.io.*;
-import java.util.*;
+import java.io.IOException;
+import java.io.StringReader;
+import java.util.Map;
+import java.util.Set;
import org.junit.Test;
+import org.opendaylight.controller.sal.restconf.impl.test.TestUtils;
import org.opendaylight.controller.sal.restconf.impl.test.structures.*;
import org.opendaylight.yangtools.yang.data.api.*;
import org.opendaylight.yangtools.yang.data.impl.NodeFactory;
-import com.google.gson.stream.*;
+import com.google.gson.stream.JsonReader;
+import com.google.gson.stream.JsonToken;
public class ToJsonBasicYangTypesTest {
@Test
public void compositeNodeAndYangWithJsonReaderEmptyDataTest() {
String jsonOutput = TestUtils.convertCompositeNodeDataAndYangToJson(prepareCompositeNodeWithEmpties(),
- "/yang-to-json-conversion/simple-yang-types", "/yang-to-json-conversion/simple-yang-types/xml");
+ "/cnsn-to-json/simple-yang-types", "/cnsn-to-json/simple-yang-types/xml", "simple-yang-types", "cont1");
verifyJsonOutputForEmpty(jsonOutput);
}
@Test
public void xmlAndYangTypesWithJsonReaderTest() {
String jsonOutput = TestUtils.convertCompositeNodeDataAndYangToJson(
- TestUtils.loadCompositeNode("/yang-to-json-conversion/simple-yang-types/xml/data.xml"),
- "/yang-to-json-conversion/simple-yang-types", "/yang-to-json-conversion/simple-yang-types/xml");
+ TestUtils.loadCompositeNode("/cnsn-to-json/simple-yang-types/xml/data.xml"),
+ "/cnsn-to-json/simple-yang-types", "/cnsn-to-json/simple-yang-types/xml", "simple-yang-types", "cont1");
verifyJsonOutput(jsonOutput);
}
return lstItem;
}
- private String nextValue(JsonReader jReader) throws IOException {
+ private Object nextValue(JsonReader jReader) throws IOException {
if (jReader.peek().equals(JsonToken.NULL)) {
jReader.nextNull();
return null;
+ } else if (jReader.peek().equals(JsonToken.NUMBER)) {
+ return jReader.nextInt();
} else {
return jReader.nextString();
}
LstItem lst11_2 = null;
LstItem lst11_3 = null;
for (LstItem lstItem : lstItems) {
- if (lstItem.getLfs().get("lf111").getValue().equals("1")) {
+ if (lstItem.getLfs().get("lf111").getValue().equals(1)) {
lst11_1 = lstItem;
- } else if (lstItem.getLfs().get("lf111").getValue().equals("2")) {
+ } else if (lstItem.getLfs().get("lf111").getValue().equals(2)) {
lst11_2 = lstItem;
- } else if (lstItem.getLfs().get("lf111").getValue().equals("3")) {
+ } else if (lstItem.getLfs().get("lf111").getValue().equals(3)) {
lst11_3 = lstItem;
}
}
assertEquals(1, lst11_1.getLfs().size());
assertEquals(1, lst11_1.getConts().size());
assertEquals(1, lst11_1.getLsts().size());
- assertEquals(lst11_1.getLsts().get("lst111"), new Lst("lst111").addLstItem(new LstItem().addLf("lf1111", "35"))
- .addLstItem(new LstItem().addLf("lf1111", "34")).addLstItem(new LstItem()).addLstItem(new LstItem()));
+ assertEquals(
+ lst11_1.getLsts().get("lst111"),
+ new Lst("lst111").addLstItem(new LstItem().addLf("lf1111", (int) 35))
+ .addLstItem(new LstItem().addLf("lf1111", (int) 34)).addLstItem(new LstItem())
+ .addLstItem(new LstItem()));
assertEquals(lst11_1.getConts().get("cont111"), new Cont("cont111"));
// : lst11_1
assertEquals(1, lst11_2_cont111.getLsts().size());
assertTrue(lst11_2_cont111.getConts().isEmpty());
- assertEquals(new LfLst("lflst1111").addLf("1024").addLf("4096"), lst11_2_cont111.getLfLsts().get("lflst1111"));
+ assertEquals(new LfLst("lflst1111").addLf((int) 1024).addLf((int) 4096),
+ lst11_2_cont111.getLfLsts().get("lflst1111"));
assertEquals(
- new Lst("lst1111").addLstItem(new LstItem().addLf("lf1111B", "4")).addLstItem(
+ new Lst("lst1111").addLstItem(new LstItem().addLf("lf1111B", (int) 4)).addLstItem(
new LstItem().addLf("lf1111A", "lf1111A str12")), lst11_2_cont111.getLsts().get("lst1111"));
// :-cont111
assertEquals(lst11_2.getLsts().get("lst112"), new Lst("lst112").addLstItem(new LstItem()));
assertNotNull(lflst12);
assertEquals(3, lflst11.getLfs().size());
- assertTrue(lflst11.getLfs().contains(new Lf("55")));
- assertTrue(lflst11.getLfs().contains(new Lf("56")));
- assertTrue(lflst11.getLfs().contains(new Lf("57")));
+ assertTrue(lflst11.getLfs().contains(new Lf(55)));
+ assertTrue(lflst11.getLfs().contains(new Lf(56)));
+ assertTrue(lflst11.getLfs().contains(new Lf(57)));
assertEquals(3, lflst12.getLfs().size());
assertTrue(lflst12.getLfs().contains(new Lf("lflst12 str1")));
LstItem lst11_2 = null;
for (LstItem lstItem : lst11.getLstItems()) {
Lf lf = lstItem.getLfs().get("lf111");
- if (lf != null && lf.getValue().equals("140")) {
+ if (lf != null && lf.getValue().equals(140)) {
lst11_1 = lstItem;
- } else if (lf != null && lf.getValue().equals("141")) {
+ } else if (lf != null && lf.getValue().equals(141)) {
lst11_2 = lstItem;
}
}
// cont111 check
assertEquals(new Lf("lf1111", "lf1111 str2"), lst11_2_cont.getLfs().get("lf1111"));
- assertEquals(new LfLst("lflst1111").addLf(new Lf("2049")).addLf(new Lf("1025")).addLf(new Lf("4097")),
- lst11_2_cont.getLfLsts().get("lflst1111"));
+ assertEquals(new LfLst("lflst1111").addLf(new Lf(2049)).addLf(new Lf(1025)).addLf(new Lf(4097)), lst11_2_cont
+ .getLfLsts().get("lflst1111"));
assertNotNull(lst11_2_cont.getLsts().get("lst1111"));
checkLst1111(lst11_2_cont.getLsts().get("lst1111").getLstItems(), new Lf("lf1111A", "lf1111A str21"), new Lf(
- "lf1111B", "5"), new Lf("lf1111A", "lf1111A str22"), new Lf("lf1111B", "8"));
+ "lf1111B", 5), new Lf("lf1111A", "lf1111A str22"), new Lf("lf1111B", 8));
- checkLst11x(lst11_2.getLsts().get("lst111"), new LstItem().addLf(new Lf("lf1111", "55")),
- new LstItem().addLf(new Lf("lf1111", "56")));
+ checkLst11x(lst11_2.getLsts().get("lst111"), new LstItem().addLf(new Lf("lf1111", 55)),
+ new LstItem().addLf(new Lf("lf1111", 56)));
checkLst11x(lst11_2.getLsts().get("lst112"), new LstItem().addLf(new Lf("lf1121", "lf1121 str22")),
new LstItem().addLf(new Lf("lf1121", "lf1121 str21")));
}
// cont111 check
assertEquals(new Lf("lf1111", "lf1111 str"), lst11_1_cont.getLfs().get("lf1111"));
- assertEquals(new LfLst("lflst1111").addLf(new Lf("2048")).addLf(new Lf("1024")).addLf(new Lf("4096")),
- lst11_1_cont.getLfLsts().get("lflst1111"));
+ assertEquals(new LfLst("lflst1111").addLf(new Lf(2048)).addLf(new Lf(1024)).addLf(new Lf(4096)), lst11_1_cont
+ .getLfLsts().get("lflst1111"));
assertNotNull(lst11_1_cont.getLsts().get("lst1111"));
checkLst1111(lst11_1_cont.getLsts().get("lst1111").getLstItems(), new Lf("lf1111A", "lf1111A str11"), new Lf(
- "lf1111B", "4"), new Lf("lf1111A", "lf1111A str12"), new Lf("lf1111B", "7"));
+ "lf1111B", 4), new Lf("lf1111A", "lf1111A str12"), new Lf("lf1111B", 7));
- checkLst11x(lst11_1.getLsts().get("lst111"), new LstItem().addLf(new Lf("lf1111", "65")));
+ checkLst11x(lst11_1.getLsts().get("lst111"), new LstItem().addLf(new Lf("lf1111", 65)));
checkLst11x(lst11_1.getLsts().get("lst112"), new LstItem().addLf(new Lf("lf1121", "lf1121 str11")));
}
null, ModifyAction.CREATE, null);
cont1.getChildren().add(lst11_1);
- MutableSimpleNode<?> lf111_1 = NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lf111"), lst11_1, "1",
- ModifyAction.CREATE, null);
+ MutableSimpleNode<?> lf111_1 = NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lf111"), lst11_1,
+ (short) 1, ModifyAction.CREATE, null);
lst11_1.getChildren().add(lf111_1);
// lst111_1_1
lst11_1, null, ModifyAction.CREATE, null);
lst11_1.getChildren().add(lst111_1_1);
MutableSimpleNode<?> lf1111_1_1 = NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lf1111"),
- lst111_1_1, "34", ModifyAction.CREATE, null);
+ lst111_1_1, (int) 34, ModifyAction.CREATE, null);
lst111_1_1.getChildren().add(lf1111_1_1);
lst111_1_1.init();
// :lst111_1_1
lst11_1, null, ModifyAction.CREATE, null);
lst11_1.getChildren().add(lst111_1_2);
MutableSimpleNode<?> lf1111_1_2 = NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lf1111"),
- lst111_1_2, "35", ModifyAction.CREATE, null);
+ lst111_1_2, (int) 35, ModifyAction.CREATE, null);
lst111_1_2.getChildren().add(lf1111_1_2);
lst111_1_2.init();
// :lst111_1_2
null, ModifyAction.CREATE, null);
cont1.getChildren().add(lst11_2);
- MutableSimpleNode<?> lf111_2 = NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lf111"), lst11_2, "2",
- ModifyAction.CREATE, null);
+ MutableSimpleNode<?> lf111_2 = NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lf111"), lst11_2,
+ (short) 2, ModifyAction.CREATE, null);
lst11_2.getChildren().add(lf111_2);
// cont111_2
lst11_2.getChildren().add(cont111_2);
MutableSimpleNode<?> lflst1111_2_2 = NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lflst1111"),
- cont111_2, "1024", ModifyAction.CREATE, null);
+ cont111_2, (int) 1024, ModifyAction.CREATE, null);
cont111_2.getChildren().add(lflst1111_2_2);
MutableSimpleNode<?> lflst1111_2_3 = NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lflst1111"),
- cont111_2, "4096", ModifyAction.CREATE, null);
+ cont111_2, (int) 4096, ModifyAction.CREATE, null);
cont111_2.getChildren().add(lflst1111_2_3);
// lst1111_2
cont111_2, null, ModifyAction.CREATE, null);
cont111_2.getChildren().add(lst1111_2_1);
MutableSimpleNode<?> lf1111B_2_1 = NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lf1111B"),
- lst1111_2_1, "4", ModifyAction.CREATE, null);
+ lst1111_2_1, (short) 4, ModifyAction.CREATE, null);
lst1111_2_1.getChildren().add(lf1111B_2_1);
lst1111_2_1.init();
MutableCompositeNode lst1111_2_2 = NodeFactory.createMutableCompositeNode(TestUtils.buildQName("lst1111"),
cont111_2, null, ModifyAction.CREATE, null);
cont111_2.getChildren().add(lst1111_2_2);
- MutableSimpleNode<?> lf1111B_2_2 = NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lf1111A"),
+ MutableSimpleNode<?> lf1111A_2_2 = NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lf1111A"),
lst1111_2_2, "lf1111A str12", ModifyAction.CREATE, null);
- lst1111_2_2.getChildren().add(lf1111B_2_2);
+ lst1111_2_2.getChildren().add(lf1111A_2_2);
lst1111_2_2.init();
// :lst1111_2
null, ModifyAction.CREATE, null);
cont1.getChildren().add(lst11_3);
- MutableSimpleNode<?> lf111_3 = NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lf111"), lst11_3, "3",
- ModifyAction.CREATE, null);
+ MutableSimpleNode<?> lf111_3 = NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lf111"), lst11_3,
+ (short) 3, ModifyAction.CREATE, null);
lst11_3.getChildren().add(lf111_3);
// cont111_3