X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=restconf%2Frestconf-nb-bierman02%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Frestconf%2Fimpl%2Ftest%2FRestGetAugmentedElementWhenEqualNamesTest.java;h=d0b30cb9988f38452fb6c7f3505e28cf0430d4dd;hb=9cc114dc8e4109893e2346477b5ae14391afe01c;hp=bf1841c97736a6ec9bccc935dc95b94e9b94f8d2;hpb=297030dc32e29a3ac0c76aa3d6279e7e047532b3;p=netconf.git diff --git a/restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestGetAugmentedElementWhenEqualNamesTest.java b/restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestGetAugmentedElementWhenEqualNamesTest.java index bf1841c977..d0b30cb998 100644 --- a/restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestGetAugmentedElementWhenEqualNamesTest.java +++ b/restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestGetAugmentedElementWhenEqualNamesTest.java @@ -7,51 +7,46 @@ */ package org.opendaylight.controller.sal.restconf.impl.test; +import static org.hamcrest.CoreMatchers.containsString; +import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.Assert.assertThrows; import java.io.FileNotFoundException; import org.junit.BeforeClass; -import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExpectedException; +import org.opendaylight.controller.md.sal.rest.common.TestRestconfUtils; import org.opendaylight.netconf.sal.restconf.impl.ControllerContext; import org.opendaylight.restconf.common.context.InstanceIdentifierContext; import org.opendaylight.restconf.common.errors.RestconfDocumentedException; -import org.opendaylight.yangtools.yang.model.api.SchemaContext; -import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; +import org.opendaylight.yangtools.yang.common.XMLNamespace; +import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext; public class RestGetAugmentedElementWhenEqualNamesTest { - private static ControllerContext controllerContext = ControllerContext.getInstance(); + private static EffectiveModelContext schemaContext; - @Rule - public ExpectedException exception = ExpectedException.none(); + private final ControllerContext controllerContext = TestRestconfUtils.newControllerContext(schemaContext); @BeforeClass - public static void init() throws FileNotFoundException, ReactorException { - final SchemaContext schemaContextTestModule = TestUtils.loadSchemaContext("/common/augment/yang"); - controllerContext.setSchemas(schemaContextTestModule); + public static void init() throws FileNotFoundException { + schemaContext = TestUtils.loadSchemaContext("/common/augment/yang"); } @Test public void augmentedNodesInUri() { - InstanceIdentifierContext iiWithData = + InstanceIdentifierContext iiWithData = controllerContext.toInstanceIdentifier("main:cont/augment-main-a:cont1"); - assertEquals("ns:augment:main:a", iiWithData.getSchemaNode().getQName().getNamespace().toString()); + assertEquals(XMLNamespace.of("ns:augment:main:a"), iiWithData.getSchemaNode().getQName().getNamespace()); iiWithData = controllerContext.toInstanceIdentifier("main:cont/augment-main-b:cont1"); - assertEquals("ns:augment:main:b", iiWithData.getSchemaNode().getQName().getNamespace().toString()); + assertEquals(XMLNamespace.of("ns:augment:main:b"), iiWithData.getSchemaNode().getQName().getNamespace()); } @Test public void nodeWithoutNamespaceHasMoreAugments() { - try { - controllerContext.toInstanceIdentifier("main:cont/cont1"); - fail("Expected exception"); - } catch (final RestconfDocumentedException e) { - assertTrue(e.getErrors().get(0).getErrorMessage() - .contains("is added as augment from more than one module")); - } + final var ex = assertThrows(RestconfDocumentedException.class, + () -> controllerContext.toInstanceIdentifier("main:cont/cont1")); + assertThat(ex.getErrors().get(0).getErrorMessage(), + containsString("is added as augment from more than one module")); } }