Merge "Fixed for bug 1197"
[controller.git] / opendaylight / md-sal / sal-rest-connector / src / test / java / org / opendaylight / controller / sal / restconf / impl / test / RestGetAugmentedElementWhenEqualNamesTest.java
1 /*
2  * Copyright (c) 2014 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.restconf.impl.test;
9
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertTrue;
12 import static org.junit.Assert.fail;
13
14 import java.io.FileNotFoundException;
15 import org.junit.BeforeClass;
16 import org.junit.Rule;
17 import org.junit.Test;
18 import org.junit.rules.ExpectedException;
19 import org.opendaylight.controller.sal.restconf.impl.ControllerContext;
20 import org.opendaylight.controller.sal.restconf.impl.InstanceIdWithSchemaNode;
21 import org.opendaylight.controller.sal.restconf.impl.RestconfDocumentedException;
22 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
23
24 public class RestGetAugmentedElementWhenEqualNamesTest {
25
26     private static ControllerContext controllerContext = ControllerContext.getInstance();
27
28     @Rule
29     public ExpectedException exception = ExpectedException.none();
30
31     @BeforeClass
32     public static void init() throws FileNotFoundException {
33         SchemaContext schemaContextTestModule = TestUtils.loadSchemaContext("/common/augment/yang");
34         controllerContext.setSchemas(schemaContextTestModule);
35     }
36
37     @Test
38     public void augmentedNodesInUri() {
39         InstanceIdWithSchemaNode iiWithData = controllerContext.toInstanceIdentifier("main:cont/augment-main-a:cont1");
40         assertEquals("ns:augment:main:a", iiWithData.getSchemaNode().getQName().getNamespace().toString());
41         iiWithData = controllerContext.toInstanceIdentifier("main:cont/augment-main-b:cont1");
42         assertEquals("ns:augment:main:b", iiWithData.getSchemaNode().getQName().getNamespace().toString());
43     }
44
45     @Test
46     public void nodeWithoutNamespaceHasMoreAugments() {
47         try {
48             controllerContext.toInstanceIdentifier("main:cont/cont1");
49             fail("Expected exception");
50         } catch (RestconfDocumentedException e) {
51             assertTrue(e.getErrors().get(0).getErrorMessage().contains("is added as augment from more than one module"));
52         }
53     }
54 }