2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.controller.sal.restconf.impl.test;
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNotNull;
12 import static org.junit.Assert.assertTrue;
14 import java.io.IOException;
15 import java.net.URISyntaxException;
16 import java.util.List;
19 import javax.ws.rs.WebApplicationException;
21 import org.junit.BeforeClass;
22 import org.junit.Test;
23 import org.opendaylight.controller.sal.rest.impl.JsonToCompositeNodeProvider;
24 import org.opendaylight.controller.sal.rest.impl.XmlToCompositeNodeProvider;
25 import org.opendaylight.yangtools.yang.common.QName;
26 import org.opendaylight.yangtools.yang.data.api.CompositeNode;
27 import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier;
28 import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier.NodeIdentifierWithPredicates;
29 import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier.PathArgument;
30 import org.opendaylight.yangtools.yang.data.api.SimpleNode;
32 public class XmlAndJsonToCnSnInstanceIdentifierTest extends YangAndXmlAndDataSchemaLoader {
35 public static void initialize() {
36 dataLoad("/instanceidentifier/yang", 3, "instance-identifier-module", "cont");
40 public void loadXmlToCnSn() throws WebApplicationException, IOException, URISyntaxException {
41 CompositeNode cnSn = TestUtils.readInputToCnSn("/instanceidentifier/xml/xmldata.xml",
42 XmlToCompositeNodeProvider.INSTANCE);
43 TestUtils.normalizeCompositeNode(cnSn, modules, schemaNodePath);
48 public void loadJsonToCnSn() throws WebApplicationException, IOException, URISyntaxException {
49 CompositeNode cnSn = TestUtils.readInputToCnSn("/instanceidentifier/json/jsondata.json",
50 JsonToCompositeNodeProvider.INSTANCE);
51 TestUtils.normalizeCompositeNode(cnSn, modules, schemaNodePath);
55 private void verify(CompositeNode cnSn) throws URISyntaxException {
56 SimpleNode<?> lf111 = getSnWithInstanceIdentifier(cnSn);
57 Object value = lf111.getValue();
58 assertTrue(value instanceof InstanceIdentifier);
60 InstanceIdentifier instanceIdentifier = (InstanceIdentifier) value;
61 List<PathArgument> pathArguments = instanceIdentifier.getPath();
62 assertEquals(4, pathArguments.size());
63 String revisionDate = "2014-01-17";
64 assertEquals(TestUtils.buildQName("cont", "instance:identifier:module", revisionDate), pathArguments.get(0)
66 assertEquals(TestUtils.buildQName("cont1", "instance:identifier:module", revisionDate), pathArguments.get(1)
68 assertEquals(TestUtils.buildQName("lst11", "augment:module", revisionDate), pathArguments.get(2).getNodeType());
69 assertEquals(TestUtils.buildQName("lf112", "augment:augment:module", revisionDate), pathArguments.get(3)
72 assertTrue(pathArguments.get(2) instanceof NodeIdentifierWithPredicates);
73 Map<QName, Object> predicates = ((NodeIdentifierWithPredicates) pathArguments.get(2)).getKeyValues();
74 assertEquals(2, predicates.size());
75 assertEquals("value1", predicates.get(TestUtils.buildQName("keyvalue111", "augment:module", revisionDate)));
76 assertEquals("value2", predicates.get(TestUtils.buildQName("keyvalue112", "augment:module", revisionDate)));
79 private SimpleNode<?> getSnWithInstanceIdentifier(CompositeNode cnSn) throws URISyntaxException {
80 CompositeNode cont1 = cnSn.getFirstCompositeByName(TestUtils.buildQName("cont1", "instance:identifier:module",
83 CompositeNode lst11 = cont1.getFirstCompositeByName(TestUtils.buildQName("lst11", "augment:module",
86 SimpleNode<?> lf111 = lst11.getFirstSimpleByName(TestUtils.buildQName("lf111", "augment:augment:module",