X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-rest-connector%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Frestconf%2Fimpl%2Ftest%2FURITest.java;h=ed871bb52727895c5cdf69dd80e0caa2433cacef;hb=d206d27042eef2185c875f85cf6eac61a1bd77c4;hp=eef9e414e93e75d90ec29719d7f93b85952c9400;hpb=6fd408a04fe4a3611843e2246ece6d7c34b76903;p=controller.git diff --git a/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/URITest.java b/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/URITest.java index eef9e414e9..ed871bb527 100644 --- a/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/URITest.java +++ b/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/URITest.java @@ -14,21 +14,22 @@ import static org.mockito.Matchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; +import com.google.common.base.Optional; +import com.google.common.collect.Iterables; import java.io.FileNotFoundException; import java.util.Set; - import org.junit.BeforeClass; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; -import org.opendaylight.controller.sal.core.api.mount.MountInstance; -import org.opendaylight.controller.sal.core.api.mount.MountService; +import org.opendaylight.controller.md.sal.dom.api.DOMMountPoint; +import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService; import org.opendaylight.controller.sal.restconf.impl.BrokerFacade; 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.controller.sal.restconf.impl.RestconfDocumentedException; import org.opendaylight.controller.sal.restconf.impl.RestconfImpl; -import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier; +import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode; import org.opendaylight.yangtools.yang.model.api.Module; import org.opendaylight.yangtools.yang.model.api.SchemaContext; @@ -67,15 +68,13 @@ public class URITest { @Test public void testToInstanceIdentifierListWithNullKey() { - exception.expect(ResponseException.class); - exception.expectMessage("HTTP 400 Bad Request"); + exception.expect(RestconfDocumentedException.class); controllerContext.toInstanceIdentifier("simple-nodes:user/null/boo"); } @Test public void testToInstanceIdentifierListWithMissingKey() { - exception.expect(ResponseException.class); - exception.expectMessage("HTTP 400 Bad Request"); + exception.expect(RestconfDocumentedException.class); controllerContext.toInstanceIdentifier("simple-nodes:user/foo"); } @@ -96,29 +95,25 @@ public class URITest { @Test public void testToInstanceIdentifierChoiceException() { - exception.expect(ResponseException.class); - exception.expectMessage("HTTP 400 Bad Request"); + exception.expect(RestconfDocumentedException.class); controllerContext.toInstanceIdentifier("simple-nodes:food/snack"); } @Test public void testToInstanceIdentifierCaseException() { - exception.expect(ResponseException.class); - exception.expectMessage("HTTP 400 Bad Request"); + exception.expect(RestconfDocumentedException.class); controllerContext.toInstanceIdentifier("simple-nodes:food/sports-arena"); } @Test public void testToInstanceIdentifierChoiceCaseException() { - exception.expect(ResponseException.class); - exception.expectMessage("HTTP 400 Bad Request"); + exception.expect(RestconfDocumentedException.class); controllerContext.toInstanceIdentifier("simple-nodes:food/snack/sports-arena"); } - + @Test public void testToInstanceIdentifierWithoutNode() { - exception.expect(ResponseException.class); - exception.expectMessage("HTTP 400 Bad Request"); + exception.expect(RestconfDocumentedException.class); controllerContext.toInstanceIdentifier("simple-nodes"); } @@ -137,31 +132,29 @@ public class URITest { initMountService(true); InstanceIdWithSchemaNode instanceIdentifier = controllerContext .toInstanceIdentifier("simple-nodes:users/yang-ext:mount/"); - assertEquals(true, instanceIdentifier.getInstanceIdentifier().getPath().isEmpty()); + assertTrue(Iterables.isEmpty(instanceIdentifier.getInstanceIdentifier().getPathArguments())); } @Test public void testMountPointWithoutMountService() throws FileNotFoundException { - exception.expect(ResponseException.class); - exception.expectMessage("HTTP 503 Service Unavailable"); - + exception.expect(RestconfDocumentedException.class); + controllerContext.setMountService(null); InstanceIdWithSchemaNode instanceIdentifier = controllerContext .toInstanceIdentifier("simple-nodes:users/yang-ext:mount/test-interface2:class/student/name"); } - + @Test public void testMountPointWithoutMountPointSchema() { initMountService(false); - exception.expect(ResponseException.class); - exception.expectMessage("HTTP 400 Bad Request"); - + exception.expect(RestconfDocumentedException.class); + InstanceIdWithSchemaNode instanceIdentifier = controllerContext .toInstanceIdentifier("simple-nodes:users/yang-ext:mount/test-interface2:class"); } - - public void initMountService(boolean withSchema) { - MountService mountService = mock(MountService.class); + + public void initMountService(final boolean withSchema) { + DOMMountPointService mountService = mock(DOMMountPointService.class); controllerContext.setMountService(mountService); BrokerFacade brokerFacade = mock(BrokerFacade.class); RestconfImpl restconfImpl = RestconfImpl.getInstance(); @@ -170,11 +163,12 @@ public class URITest { Set modules2 = TestUtils.loadModulesFrom("/test-config-data/yang2"); SchemaContext schemaContext2 = TestUtils.loadSchemaContext(modules2); - MountInstance mountInstance = mock(MountInstance.class); - if (withSchema) + DOMMountPoint mountInstance = mock(DOMMountPoint.class); + if (withSchema) { when(mountInstance.getSchemaContext()).thenReturn(schemaContext2); - else + } else { when(mountInstance.getSchemaContext()).thenReturn(null); - when(mountService.getMountPoint(any(InstanceIdentifier.class))).thenReturn(mountInstance); + } + when(mountService.getMountPoint(any(YangInstanceIdentifier.class))).thenReturn(Optional.of(mountInstance)); } }