Merge "Instance identifier support"
[controller.git] / opendaylight / md-sal / sal-rest-connector / src / test / java / org / opendaylight / controller / sal / restconf / impl / test / RestGetAugmentedElementWhenEqualNamesTest.java
1 package org.opendaylight.controller.sal.restconf.impl.test;
2
3 import static org.junit.Assert.assertEquals;
4 import static org.junit.Assert.assertTrue;
5
6 import java.io.FileNotFoundException;
7
8 import org.junit.BeforeClass;
9 import org.junit.Rule;
10 import org.junit.Test;
11 import org.junit.rules.ExpectedException;
12 import org.opendaylight.controller.sal.restconf.impl.ControllerContext;
13 import org.opendaylight.controller.sal.restconf.impl.InstanceIdWithSchemaNode;
14 import org.opendaylight.controller.sal.restconf.impl.ResponseException;
15 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
16
17 public class RestGetAugmentedElementWhenEqualNamesTest {
18     
19     private static ControllerContext controllerContext = ControllerContext.getInstance();
20     
21     @Rule
22     public ExpectedException exception = ExpectedException.none();
23     
24     @BeforeClass
25     public static void init() throws FileNotFoundException {
26         SchemaContext schemaContextTestModule = TestUtils.loadSchemaContext("/common/augment/yang");
27         controllerContext.setSchemas(schemaContextTestModule);
28     }
29
30     @Test
31     public void augmentedNodesInUri() {
32         InstanceIdWithSchemaNode iiWithData = controllerContext.toInstanceIdentifier("main:cont/augment-main-a:cont1");
33         assertEquals("ns:augment:main:a", iiWithData.getSchemaNode().getQName().getNamespace().toString());
34         iiWithData = controllerContext.toInstanceIdentifier("main:cont/augment-main-b:cont1");
35         assertEquals("ns:augment:main:b", iiWithData.getSchemaNode().getQName().getNamespace().toString());
36     }
37     
38     @Test
39     public void nodeWithoutNamespaceHasMoreAugments() {
40         boolean exceptionCaught = false;
41         try {
42             controllerContext.toInstanceIdentifier("main:cont/cont1");
43         } catch (ResponseException e) {
44             assertTrue(((String) e.getResponse().getEntity()).contains("is added as augment from more than one module"));
45             exceptionCaught = true;
46         }
47         assertTrue(exceptionCaught);
48     }
49
50 }