d0b30cb9988f38452fb6c7f3505e28cf0430d4dd
[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.hamcrest.CoreMatchers.containsString;
11 import static org.hamcrest.MatcherAssert.assertThat;
12 import static org.junit.Assert.assertEquals;
13 import static org.junit.Assert.assertThrows;
14
15 import java.io.FileNotFoundException;
16 import org.junit.BeforeClass;
17 import org.junit.Test;
18 import org.opendaylight.controller.md.sal.rest.common.TestRestconfUtils;
19 import org.opendaylight.netconf.sal.restconf.impl.ControllerContext;
20 import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
21 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
22 import org.opendaylight.yangtools.yang.common.XMLNamespace;
23 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
24
25 public class RestGetAugmentedElementWhenEqualNamesTest {
26
27     private static EffectiveModelContext schemaContext;
28
29     private final ControllerContext controllerContext = TestRestconfUtils.newControllerContext(schemaContext);
30
31     @BeforeClass
32     public static void init() throws FileNotFoundException {
33         schemaContext = TestUtils.loadSchemaContext("/common/augment/yang");
34     }
35
36     @Test
37     public void augmentedNodesInUri() {
38         InstanceIdentifierContext iiWithData =
39                 controllerContext.toInstanceIdentifier("main:cont/augment-main-a:cont1");
40         assertEquals(XMLNamespace.of("ns:augment:main:a"), iiWithData.getSchemaNode().getQName().getNamespace());
41         iiWithData = controllerContext.toInstanceIdentifier("main:cont/augment-main-b:cont1");
42         assertEquals(XMLNamespace.of("ns:augment:main:b"), iiWithData.getSchemaNode().getQName().getNamespace());
43     }
44
45     @Test
46     public void nodeWithoutNamespaceHasMoreAugments() {
47         final var ex = assertThrows(RestconfDocumentedException.class,
48             () -> controllerContext.toInstanceIdentifier("main:cont/cont1"));
49         assertThat(ex.getErrors().get(0).getErrorMessage(),
50             containsString("is added as augment from more than one module"));
51     }
52 }