e9488c18115fbf30ffa067cc3e5307e553b452e3
[netconf.git] / restconf / restconf-nb-bierman02 / 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.md.sal.rest.common.TestRestconfUtils;
20 import org.opendaylight.netconf.sal.restconf.impl.ControllerContext;
21 import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
22 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
23 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
24
25 public class RestGetAugmentedElementWhenEqualNamesTest {
26
27     private static SchemaContext schemaContext;
28
29     private final ControllerContext controllerContext = TestRestconfUtils.newControllerContext(schemaContext);
30
31     @Rule
32     public ExpectedException exception = ExpectedException.none();
33
34     @BeforeClass
35     public static void init() throws FileNotFoundException {
36         schemaContext = TestUtils.loadSchemaContext("/common/augment/yang");
37     }
38
39     @Test
40     public void augmentedNodesInUri() {
41         InstanceIdentifierContext<?> iiWithData =
42                 controllerContext.toInstanceIdentifier("main:cont/augment-main-a:cont1");
43         assertEquals("ns:augment:main:a", iiWithData.getSchemaNode().getQName().getNamespace().toString());
44         iiWithData = controllerContext.toInstanceIdentifier("main:cont/augment-main-b:cont1");
45         assertEquals("ns:augment:main:b", iiWithData.getSchemaNode().getQName().getNamespace().toString());
46     }
47
48     @Test
49     public void nodeWithoutNamespaceHasMoreAugments() {
50         try {
51             controllerContext.toInstanceIdentifier("main:cont/cont1");
52             fail("Expected exception");
53         } catch (final RestconfDocumentedException e) {
54             assertTrue(e.getErrors().get(0).getErrorMessage()
55                     .contains("is added as augment from more than one module"));
56         }
57     }
58 }