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%2FURIParametersParsing.java;h=808361346e936179890afc2f6200df745b9fb7f4;hb=982e75ece2483e413befe3edd8fd90022a644f72;hp=e0596f69884fd508b09edd52cf4d0ad6d92d2dec;hpb=1bcaf624205de83ea78a131e960103f2b785468c;p=netconf.git diff --git a/restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/URIParametersParsing.java b/restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/URIParametersParsing.java index e0596f6988..808361346e 100644 --- a/restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/URIParametersParsing.java +++ b/restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/URIParametersParsing.java @@ -9,15 +9,12 @@ package org.opendaylight.controller.sal.restconf.impl.test; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.eq; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -import static org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil.getRevisionFormat; import com.google.common.base.Preconditions; import java.io.FileNotFoundException; -import java.text.ParseException; -import java.util.Date; import java.util.Set; import javax.ws.rs.core.MultivaluedMap; import javax.ws.rs.core.UriBuilder; @@ -25,8 +22,8 @@ import javax.ws.rs.core.UriInfo; import org.junit.Before; import org.junit.Test; import org.mockito.Mockito; -import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker.DataChangeScope; import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; +import org.opendaylight.controller.md.sal.rest.common.TestRestconfUtils; import org.opendaylight.netconf.sal.restconf.impl.BrokerFacade; import org.opendaylight.netconf.sal.restconf.impl.ControllerContext; import org.opendaylight.netconf.sal.restconf.impl.RestconfImpl; @@ -34,8 +31,10 @@ import org.opendaylight.netconf.sal.streams.listeners.ListenerAdapter; import org.opendaylight.netconf.sal.streams.listeners.Notificator; import org.opendaylight.restconf.common.context.InstanceIdentifierContext; import org.opendaylight.restconf.common.context.NormalizedNodeContext; +import org.opendaylight.restconf.common.util.DataChangeScope; import org.opendaylight.yang.gen.v1.urn.sal.restconf.event.subscription.rev140708.NotificationOutputTypeGrouping.NotificationOutputType; import org.opendaylight.yangtools.yang.common.QName; +import org.opendaylight.yangtools.yang.common.Revision; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.AugmentationIdentifier; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.InstanceIdentifierBuilder; @@ -44,9 +43,8 @@ import org.opendaylight.yangtools.yang.data.api.schema.AugmentationNode; import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode; import org.opendaylight.yangtools.yang.data.api.schema.LeafNode; import org.opendaylight.yangtools.yang.data.impl.schema.Builders; -import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeAttrBuilder; import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeBuilder; -import org.opendaylight.yangtools.yang.model.api.AugmentationSchema; +import org.opendaylight.yangtools.yang.model.api.AugmentationSchemaNode; import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode; import org.opendaylight.yangtools.yang.model.api.DataSchemaNode; import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode; @@ -65,12 +63,10 @@ public class URIParametersParsing { @Before public void init() throws FileNotFoundException, ReactorException { - this.restconf = RestconfImpl.getInstance(); this.mockedBrokerFacade = mock(BrokerFacade.class); - this.controllerContext = ControllerContext.getInstance(); - this.controllerContext.setSchemas(TestUtils.loadSchemaContext("/datastore-and-scope-specification")); - this.restconf.setControllerContext(this.controllerContext); - this.restconf.setBroker(this.mockedBrokerFacade); + this.controllerContext = TestRestconfUtils.newControllerContext( + TestUtils.loadSchemaContext("/datastore-and-scope-specification")); + this.restconf = RestconfImpl.newInstance(mockedBrokerFacade, controllerContext); } @Test @@ -87,12 +83,12 @@ public class URIParametersParsing { final LogicalDatastoreType datastoreExpected, final DataChangeScope scopeExpected) { final InstanceIdentifierBuilder iiBuilder = YangInstanceIdentifier.builder(); - iiBuilder.node(QName.create("dummyStreamName")); + iiBuilder.node(QName.create("", "dummyStreamName")); final String datastoreValue = datastore == null ? "CONFIGURATION" : datastore; final String scopeValue = scope == null ? "BASE" : scope + ""; Notificator.createListener(iiBuilder.build(), "dummyStreamName/datastore=" + datastoreValue + "/scope=" - + scopeValue, NotificationOutputType.XML); + + scopeValue, NotificationOutputType.XML, controllerContext); final UriInfo mockedUriInfo = mock(UriInfo.class); @SuppressWarnings("unchecked") @@ -105,8 +101,8 @@ public class URIParametersParsing { final UriBuilder uriBuilder = UriBuilder.fromUri("www.whatever.com"); when(mockedUriInfo.getAbsolutePathBuilder()).thenReturn(uriBuilder); - this.restconf.invokeRpc("sal-remote:create-data-change-event-subscription", prepareDomRpcNode(datastore, scope), - mockedUriInfo); + this.restconf.invokeRpc("sal-remote:create-data-change-event-subscription", + prepareDomRpcNode(datastoreValue, scopeValue), mockedUriInfo); final ListenerAdapter listener = Notificator.getListenerFor("data-change-event-subscription/opendaylight-inventory:nodes/datastore=" @@ -116,13 +112,7 @@ public class URIParametersParsing { private NormalizedNodeContext prepareDomRpcNode(final String datastore, final String scope) { final SchemaContext schema = this.controllerContext.getGlobalSchema(); - final Date revDate; - try { - revDate = getRevisionFormat().parse("2014-01-14"); - } catch (final ParseException e) { - throw new IllegalStateException(e); - } - final Module rpcSalRemoteModule = schema.findModuleByName("sal-remote", revDate); + final Module rpcSalRemoteModule = schema.findModule("sal-remote", Revision.of("2014-01-14")).get(); final Set setRpcs = rpcSalRemoteModule.getRpcs(); final QName rpcQName = QName.create(rpcSalRemoteModule.getQNameModule(), "create-data-change-event-subscription"); @@ -138,43 +128,44 @@ public class URIParametersParsing { } assertNotNull("RPC ContainerSchemaNode was not found!", rpcInputSchemaNode); - final DataContainerNodeAttrBuilder container = + final DataContainerNodeBuilder container = Builders.containerBuilder(rpcInputSchemaNode); final QName pathQName = QName.create("urn:opendaylight:params:xml:ns:yang:controller:md:sal:remote", "2014-01-14", "path"); final DataSchemaNode pathSchemaNode = rpcInputSchemaNode.getDataChildByName(pathQName); assertTrue(pathSchemaNode instanceof LeafSchemaNode); - final LeafNode pathNode = (Builders.leafBuilder((LeafSchemaNode) pathSchemaNode) + final LeafNode pathNode = Builders.leafBuilder((LeafSchemaNode) pathSchemaNode) .withValue(YangInstanceIdentifier.builder() - .node(QName.create("urn:opendaylight:inventory", "2013-08-19", "nodes")).build())).build(); + .node(QName.create("urn:opendaylight:inventory", "2013-08-19", "nodes")).build()).build(); container.withChild(pathNode); - final AugmentationSchema augmentationSchema = rpcInputSchemaNode.getAvailableAugmentations().iterator().next(); + final AugmentationSchemaNode augmentationSchema = rpcInputSchemaNode.getAvailableAugmentations().iterator() + .next(); Preconditions.checkNotNull(augmentationSchema); final DataContainerNodeBuilder augmentationBuilder = Builders.augmentationBuilder(augmentationSchema); - final QName dataStoreQName = QName.create("urn:sal:restconf:event:subscription", "2014-7-8", "datastore"); + final QName dataStoreQName = QName.create("urn:sal:restconf:event:subscription", "2014-07-08", "datastore"); final DataSchemaNode dsSchemaNode = augmentationSchema.getDataChildByName(dataStoreQName); assertTrue(dsSchemaNode instanceof LeafSchemaNode); - final LeafNode dsNode = (Builders.leafBuilder((LeafSchemaNode) dsSchemaNode) - .withValue(datastore)).build(); + final LeafNode dsNode = Builders.leafBuilder((LeafSchemaNode) dsSchemaNode) + .withValue(datastore).build(); augmentationBuilder.withChild(dsNode); - final QName scopeQName = QName.create("urn:sal:restconf:event:subscription", "2014-7-8", "scope"); + final QName scopeQName = QName.create("urn:sal:restconf:event:subscription", "2014-07-08", "scope"); final DataSchemaNode scopeSchemaNode = augmentationSchema.getDataChildByName(scopeQName); assertTrue(scopeSchemaNode instanceof LeafSchemaNode); - final LeafNode scopeNode = (Builders.leafBuilder((LeafSchemaNode) scopeSchemaNode) - .withValue(scope)).build(); + final LeafNode scopeNode = Builders.leafBuilder((LeafSchemaNode) scopeSchemaNode) + .withValue(scope).build(); augmentationBuilder.withChild(scopeNode); final QName outputQName = - QName.create("urn:sal:restconf:event:subscription", "2014-7-8", "notification-output-type"); + QName.create("urn:sal:restconf:event:subscription", "2014-07-08", "notification-output-type"); final DataSchemaNode outputSchemaNode = augmentationSchema.getDataChildByName(outputQName); assertTrue(outputSchemaNode instanceof LeafSchemaNode); final LeafNode outputNode = - (Builders.leafBuilder((LeafSchemaNode) outputSchemaNode).withValue("XML")).build(); + Builders.leafBuilder((LeafSchemaNode) outputSchemaNode).withValue("XML").build(); augmentationBuilder.withChild(outputNode); container.withChild(augmentationBuilder.build()); @@ -183,7 +174,7 @@ public class URIParametersParsing { when(rpcDef.getPath()).thenReturn(SchemaPath.create(true, rpcQName)); when(rpcDef.getQName()).thenReturn(rpcQName); - return new NormalizedNodeContext(new InstanceIdentifierContext(null, rpcDef, null, schema), + return new NormalizedNodeContext(new InstanceIdentifierContext<>(null, rpcDef, null, schema), container.build()); } }