1 package org.opendaylight.controller.sal.restconf.impl.test;
3 import static org.junit.Assert.assertEquals;
4 import static org.junit.Assert.assertNotNull;
5 import static org.junit.Assert.assertTrue;
7 import java.io.IOException;
8 import java.net.URISyntaxException;
12 import javax.ws.rs.WebApplicationException;
14 import org.junit.BeforeClass;
15 import org.junit.Test;
16 import org.opendaylight.controller.sal.rest.impl.JsonToCompositeNodeProvider;
17 import org.opendaylight.controller.sal.rest.impl.XmlToCompositeNodeProvider;
18 import org.opendaylight.yangtools.yang.common.QName;
19 import org.opendaylight.yangtools.yang.data.api.CompositeNode;
20 import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier;
21 import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier.NodeIdentifierWithPredicates;
22 import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier.PathArgument;
23 import org.opendaylight.yangtools.yang.data.api.SimpleNode;
25 public class XmlAndJsonToCnSnInstanceIdentifierTest extends YangAndXmlAndDataSchemaLoader {
28 public static void initialize() {
29 dataLoad("/instanceidentifier/yang", 3, "instance-identifier-module", "cont");
33 public void loadXmlToCnSn() throws WebApplicationException, IOException, URISyntaxException {
34 CompositeNode cnSn = TestUtils.readInputToCnSn("/instanceidentifier/xml/xmldata.xml",
35 XmlToCompositeNodeProvider.INSTANCE);
36 TestUtils.normalizeCompositeNode(cnSn, modules, schemaNodePath);
41 public void loadJsonToCnSn() throws WebApplicationException, IOException, URISyntaxException {
42 CompositeNode cnSn = TestUtils.readInputToCnSn("/instanceidentifier/json/jsondata.json",
43 JsonToCompositeNodeProvider.INSTANCE);
44 TestUtils.normalizeCompositeNode(cnSn, modules, schemaNodePath);
48 private void verify(CompositeNode cnSn) throws URISyntaxException {
49 SimpleNode<?> lf111 = getSnWithInstanceIdentifier(cnSn);
50 Object value = lf111.getValue();
51 assertTrue(value instanceof InstanceIdentifier);
53 InstanceIdentifier instanceIdentifier = (InstanceIdentifier) value;
54 List<PathArgument> pathArguments = instanceIdentifier.getPath();
55 assertEquals(4, pathArguments.size());
56 String revisionDate = "2014-01-17";
57 assertEquals(TestUtils.buildQName("cont", "instance:identifier:module", revisionDate), pathArguments.get(0)
59 assertEquals(TestUtils.buildQName("cont1", "instance:identifier:module", revisionDate), pathArguments.get(1)
61 assertEquals(TestUtils.buildQName("lst11", "augment:module", revisionDate), pathArguments.get(2).getNodeType());
62 assertEquals(TestUtils.buildQName("lf112", "augment:augment:module", revisionDate), pathArguments.get(3)
65 assertTrue(pathArguments.get(2) instanceof NodeIdentifierWithPredicates);
66 Map<QName, Object> predicates = ((NodeIdentifierWithPredicates) pathArguments.get(2)).getKeyValues();
67 assertEquals(2, predicates.size());
68 assertEquals("value1", predicates.get(TestUtils.buildQName("keyvalue111", "augment:module", revisionDate)));
69 assertEquals("value2", predicates.get(TestUtils.buildQName("keyvalue112", "augment:module", revisionDate)));
72 private SimpleNode<?> getSnWithInstanceIdentifier(CompositeNode cnSn) throws URISyntaxException {
73 CompositeNode cont1 = cnSn.getFirstCompositeByName(TestUtils.buildQName("cont1", "instance:identifier:module",
76 CompositeNode lst11 = cont1.getFirstCompositeByName(TestUtils.buildQName("lst11", "augment:module",
79 SimpleNode<?> lf111 = lst11.getFirstSimpleByName(TestUtils.buildQName("lf111", "augment:augment:module",