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 static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNotNull;
12 import static org.junit.Assert.assertTrue;
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;
25 public class InstanceIdentifierTypeLeafTest {
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();
38 final PathArgument lastPathArgument = yiD.getLastPathArgument();
39 assertTrue(lastPathArgument.getNodeType().getNamespace().toString().equals("iid:value:module"));
40 assertTrue(lastPathArgument.getNodeType().getLocalName().equals("iid-list"));
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"));
49 final NodeIdentifierWithPredicates valueList = (NodeIdentifierWithPredicates) lastPathArgumentOfValue;
50 final String valueIid = (String) valueList.getValue(
51 QName.create(lastPathArgumentOfValue.getNodeType(), "value-iid"));
52 assertEquals("value", valueIid);