X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-rest-connector%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Frestconf%2Fimpl%2Ftest%2FControllerContextTest.java;h=4c5922d73fa962b3aaea2d547846c8905e66bb8a;hp=c68fcb90714567849192db25d9dc676e43f700a9;hb=91d7c1ee52322acad08e9f81228ac36b3aa684f5;hpb=67a2d25f63cc03d6291f9b3110e70fac812c3793 diff --git a/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/ControllerContextTest.java b/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/ControllerContextTest.java index c68fcb9071..4c5922d73f 100644 --- a/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/ControllerContextTest.java +++ b/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/ControllerContextTest.java @@ -2,21 +2,19 @@ package org.opendaylight.controller.sal.restconf.impl.test; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.eq; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; import java.io.FileNotFoundException; import java.util.Set; +import org.junit.After; import org.junit.BeforeClass; +import org.junit.Rule; import org.junit.Test; -import org.opendaylight.controller.sal.core.api.mount.MountInstance; -import org.opendaylight.controller.sal.core.api.mount.MountService; +import org.junit.rules.ExpectedException; import org.opendaylight.controller.sal.restconf.impl.ControllerContext; import org.opendaylight.controller.sal.restconf.impl.InstanceIdWithSchemaNode; +import org.opendaylight.controller.sal.restconf.impl.ResponseException; import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode; import org.opendaylight.yangtools.yang.model.api.Module; import org.opendaylight.yangtools.yang.model.api.SchemaContext; @@ -25,6 +23,9 @@ public class ControllerContextTest { private static final ControllerContext controllerContext = ControllerContext.getInstance(); + @Rule + public ExpectedException exception = ExpectedException.none(); + @BeforeClass public static void init() throws FileNotFoundException { Set allModules = TestUtils.loadModulesFrom("/full-versions/yangs"); @@ -33,6 +34,11 @@ public class ControllerContextTest { controllerContext.setSchemas(schemaContext); } + @After + public void releaseMountService() { + controllerContext.setMountService(null); + } + @Test public void testToInstanceIdentifierList() throws FileNotFoundException { InstanceIdWithSchemaNode instanceIdentifier = controllerContext @@ -50,48 +56,20 @@ public class ControllerContextTest { instanceIdentifier = controllerContext.toInstanceIdentifier("simple-nodes:users/user/foo"); assertEquals(instanceIdentifier.getSchemaNode().getQName().getLocalName(), "user"); - - instanceIdentifier = controllerContext.toInstanceIdentifier("simple-nodes:user/null/boo"); - assertNull(instanceIdentifier); - - instanceIdentifier = controllerContext.toInstanceIdentifier("simple-nodes:user/foo"); - assertNull(instanceIdentifier); - } @Test - public void testToInstanceIdentifierMountPoint() throws FileNotFoundException { - try { - String mountPointPath = "simple-nodes:user/foo/boo"; - String nestedPath = "simple-nodes:user/foo/boo/simple-nodes:users"; - InstanceIdWithSchemaNode mountInstanceIdentifier = controllerContext.toInstanceIdentifier(mountPointPath); - assertEquals("user", mountInstanceIdentifier.getSchemaNode().getQName().getLocalName()); - - MountInstance mountInstance = mock(MountInstance.class); - MountService mountService = mock(MountService.class); - - controllerContext.setMountService(mountService); - // when(mountService.getMountPoint(any(InstanceIdentifier.class))).thenReturn(null); - - when(mountService.getMountPoint(eq(mountInstanceIdentifier.getInstanceIdentifier()))).thenReturn( - mountInstance); - - when(mountInstance.getSchemaContext()).thenReturn(controllerContext.getGlobalSchema()); - - InstanceIdWithSchemaNode mountedInstanceIdentifier = controllerContext.toInstanceIdentifier(nestedPath); - assertEquals("users", mountedInstanceIdentifier.getSchemaNode().getQName().getLocalName()); - - mountedInstanceIdentifier = controllerContext.toInstanceIdentifier(mountPointPath + "/" + mountPointPath); - assertEquals("user", mountedInstanceIdentifier.getSchemaNode().getQName().getLocalName()); - - mountedInstanceIdentifier = controllerContext - .toInstanceIdentifier("simple-nodes:user/foo/var/simple-nodes:users"); - assertNull(mountedInstanceIdentifier); - - } finally { - controllerContext.setMountService(null); - } + public void testToInstanceIdentifierListWithNullKey() { + exception.expect(ResponseException.class); + exception.expectMessage("HTTP 400 Bad Request"); + controllerContext.toInstanceIdentifier("simple-nodes:user/null/boo"); + } + @Test + public void testToInstanceIdentifierListWithMissingKey() { + exception.expect(ResponseException.class); + exception.expectMessage("HTTP 400 Bad Request"); + controllerContext.toInstanceIdentifier("simple-nodes:user/foo"); } @Test @@ -104,18 +82,30 @@ public class ControllerContextTest { @Test public void testToInstanceIdentifierChoice() throws FileNotFoundException { - InstanceIdWithSchemaNode instanceIdentifier = controllerContext.toInstanceIdentifier("simple-nodes:food/beer"); + InstanceIdWithSchemaNode instanceIdentifier = controllerContext + .toInstanceIdentifier("simple-nodes:food/nonalcoholic/beer"); assertEquals(instanceIdentifier.getSchemaNode().getQName().getLocalName(), "beer"); + } - instanceIdentifier = controllerContext.toInstanceIdentifier("simple-nodes:food/snack"); - assertNull(instanceIdentifier); - - instanceIdentifier = controllerContext.toInstanceIdentifier("simple-nodes:food/sports-arena"); - assertNull(instanceIdentifier); + @Test + public void testToInstanceIdentifierChoiceException() { + exception.expect(ResponseException.class); + exception.expectMessage("HTTP 400 Bad Request"); + controllerContext.toInstanceIdentifier("simple-nodes:food/snack"); + } - instanceIdentifier = controllerContext.toInstanceIdentifier("simple-nodes:food/snack/sports-arena"); - assertNull(instanceIdentifier); + @Test + public void testToInstanceIdentifierCaseException() { + exception.expect(ResponseException.class); + exception.expectMessage("HTTP 400 Bad Request"); + controllerContext.toInstanceIdentifier("simple-nodes:food/sports-arena"); + } + @Test + public void testToInstanceIdentifierChoiceCaseException() { + exception.expect(ResponseException.class); + exception.expectMessage("HTTP 400 Bad Request"); + controllerContext.toInstanceIdentifier("simple-nodes:food/snack/sports-arena"); } }