Bump versions to 4.0.0-SNAPSHOT
[netconf.git] / restconf / restconf-nb-bierman02 / src / test / java / org / opendaylight / controller / sal / rest / impl / InstanceIdentifierTypeLeafTest.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.controller.sal.rest.impl;
9
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNotNull;
12 import static org.junit.Assert.assertTrue;
13
14 import org.junit.Test;
15 import org.opendaylight.controller.md.sal.rest.common.TestRestconfUtils;
16 import org.opendaylight.netconf.sal.restconf.impl.ControllerContext;
17 import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
18 import org.opendaylight.yangtools.yang.common.QName;
19 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
20 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
21 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
22 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
23 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
24
25 public class InstanceIdentifierTypeLeafTest {
26
27     @Test
28     public void stringToInstanceIdentifierTest() throws Exception {
29         final EffectiveModelContext schemaContext =
30                 YangParserTestUtils.parseYangFiles(TestRestconfUtils.loadFiles("/instanceidentifier"));
31         ControllerContext controllerContext = TestRestconfUtils.newControllerContext(schemaContext);
32         final InstanceIdentifierContext instanceIdentifier =
33                 controllerContext.toInstanceIdentifier(
34                         "/iid-value-module:cont-iid/iid-list/%2Fiid-value-module%3Acont-iid%2Fiid-value-module%3A"
35                                 + "values-iid%5Biid-value-module:value-iid='value'%5D");
36         final YangInstanceIdentifier yiD = instanceIdentifier.getInstanceIdentifier();
37         assertNotNull(yiD);
38         final PathArgument lastPathArgument = yiD.getLastPathArgument();
39         assertTrue(lastPathArgument.getNodeType().getNamespace().toString().equals("iid:value:module"));
40         assertTrue(lastPathArgument.getNodeType().getLocalName().equals("iid-list"));
41
42         final NodeIdentifierWithPredicates list = (NodeIdentifierWithPredicates) lastPathArgument;
43         final YangInstanceIdentifier value = (YangInstanceIdentifier) list.getValue(
44             QName.create(lastPathArgument.getNodeType(), "iid-leaf"));
45         final PathArgument lastPathArgumentOfValue = value.getLastPathArgument();
46         assertTrue(lastPathArgumentOfValue.getNodeType().getNamespace().toString().equals("iid:value:module"));
47         assertTrue(lastPathArgumentOfValue.getNodeType().getLocalName().equals("values-iid"));
48
49         final NodeIdentifierWithPredicates valueList = (NodeIdentifierWithPredicates) lastPathArgumentOfValue;
50         final String valueIid = (String) valueList.getValue(
51                 QName.create(lastPathArgumentOfValue.getNodeType(), "value-iid"));
52         assertEquals("value", valueIid);
53     }
54
55 }