2 * Copyright (c) 2016 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.rest.impl;
10 import org.junit.Assert;
11 import org.junit.Test;
12 import org.opendaylight.controller.md.sal.rest.common.TestRestconfUtils;
13 import org.opendaylight.netconf.sal.restconf.impl.ControllerContext;
14 import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
15 import org.opendaylight.yangtools.yang.common.QName;
16 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
17 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
18 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
19 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
20 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
22 public class InstanceIdentifierTypeLeafTest {
25 public void stringToInstanceIdentifierTest() throws Exception {
26 final SchemaContext schemaContext =
27 YangParserTestUtils.parseYangFiles(TestRestconfUtils.loadFiles("/instanceidentifier"));
28 ControllerContext.getInstance().setGlobalSchema(schemaContext);
29 final InstanceIdentifierContext<?> instanceIdentifier =
30 ControllerContext.getInstance().toInstanceIdentifier(
31 "/iid-value-module:cont-iid/iid-list/%2Fiid-value-module%3Acont-iid%2Fiid-value-module%3A"
32 + "values-iid%5Biid-value-module:value-iid='value'%5D");
33 final YangInstanceIdentifier yiD = instanceIdentifier.getInstanceIdentifier();
34 Assert.assertNotNull(yiD);
35 final PathArgument lastPathArgument = yiD.getLastPathArgument();
36 Assert.assertTrue(lastPathArgument.getNodeType().getNamespace().toString().equals("iid:value:module"));
37 Assert.assertTrue(lastPathArgument.getNodeType().getLocalName().equals("iid-list"));
39 final NodeIdentifierWithPredicates list = (NodeIdentifierWithPredicates) lastPathArgument;
40 final YangInstanceIdentifier value = (YangInstanceIdentifier) list.getKeyValues()
41 .get(QName.create(lastPathArgument.getNodeType(), "iid-leaf"));
42 final PathArgument lastPathArgumentOfValue = value.getLastPathArgument();
43 Assert.assertTrue(lastPathArgumentOfValue.getNodeType().getNamespace().toString().equals("iid:value:module"));
44 Assert.assertTrue(lastPathArgumentOfValue.getNodeType().getLocalName().equals("values-iid"));
46 final NodeIdentifierWithPredicates valueList = (NodeIdentifierWithPredicates) lastPathArgumentOfValue;
47 final String valueIid = (String) valueList.getKeyValues()
48 .get(QName.create(lastPathArgumentOfValue.getNodeType(), "value-iid"));
49 Assert.assertEquals("value", valueIid);