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