*/
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.common.XMLNamespace;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
public class RestGetAugmentedElementWhenEqualNamesTest {
private final ControllerContext controllerContext = TestRestconfUtils.newControllerContext(schemaContext);
- @Rule
- public ExpectedException exception = ExpectedException.none();
-
@BeforeClass
public static void init() throws FileNotFoundException {
schemaContext = TestUtils.loadSchemaContext("/common/augment/yang");
public void augmentedNodesInUri() {
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"));
}
}
package org.opendaylight.controller.sal.restconf.impl.test;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import java.util.Optional;
import org.junit.BeforeClass;
import org.junit.Ignore;
-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.mdsal.dom.api.DOMMountPoint;
import org.opendaylight.mdsal.dom.api.DOMSchemaService;
private final ControllerContext controllerContext =
TestRestconfUtils.newControllerContext(schemaContext, mountInstance);
- @Rule
- public ExpectedException exception = ExpectedException.none();
-
@BeforeClass
public static void init() throws FileNotFoundException, ReactorException {
schemaContext = TestUtils.loadSchemaContext("/full-versions/yangs");
@Test
public void testToInstanceIdentifierListWithNullKey() {
- this.exception.expect(RestconfDocumentedException.class);
- controllerContext.toInstanceIdentifier("simple-nodes:user/null/boo");
+ assertThrows(RestconfDocumentedException.class,
+ () -> controllerContext.toInstanceIdentifier("simple-nodes:user/null/boo"));
}
@Test
public void testToInstanceIdentifierListWithMissingKey() {
- this.exception.expect(RestconfDocumentedException.class);
- controllerContext.toInstanceIdentifier("simple-nodes:user/foo");
+ assertThrows(RestconfDocumentedException.class,
+ () -> controllerContext.toInstanceIdentifier("simple-nodes:user/foo"));
}
@Test
@Test
public void testToInstanceIdentifierChoiceException() {
- this.exception.expect(RestconfDocumentedException.class);
- controllerContext.toInstanceIdentifier("simple-nodes:food/snack");
+ assertThrows(RestconfDocumentedException.class,
+ () -> controllerContext.toInstanceIdentifier("simple-nodes:food/snack"));
}
@Test
public void testToInstanceIdentifierCaseException() {
- this.exception.expect(RestconfDocumentedException.class);
- controllerContext.toInstanceIdentifier("simple-nodes:food/sports-arena");
+ assertThrows(RestconfDocumentedException.class,
+ () -> controllerContext.toInstanceIdentifier("simple-nodes:food/sports-arena"));
}
@Test
public void testToInstanceIdentifierChoiceCaseException() {
- this.exception.expect(RestconfDocumentedException.class);
- controllerContext.toInstanceIdentifier("simple-nodes:food/snack/sports-arena");
+ assertThrows(RestconfDocumentedException.class,
+ () -> controllerContext.toInstanceIdentifier("simple-nodes:food/snack/sports-arena"));
}
@Test
public void testToInstanceIdentifierWithoutNode() {
- this.exception.expect(RestconfDocumentedException.class);
- controllerContext.toInstanceIdentifier("simple-nodes");
+ assertThrows(RestconfDocumentedException.class,
+ () -> controllerContext.toInstanceIdentifier("simple-nodes"));
}
@Test
@Test
public void testMountPointWithoutMountPointSchema() throws FileNotFoundException, ReactorException {
- this.exception.expect(RestconfDocumentedException.class);
-
- controllerContext.toInstanceIdentifier("simple-nodes:users/yang-ext:mount/test-interface2:class");
+ assertThrows(RestconfDocumentedException.class,
+ () -> controllerContext.toInstanceIdentifier("simple-nodes:users/yang-ext:mount/test-interface2:class"));
}
- public void initSchemaService() {
+ private void initSchemaService() {
doReturn(Optional.of(FixedDOMSchemaService.of(mountSchemaContext))).when(mountInstance)
.getService(DOMSchemaService.class);
}