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%2FRestconfImplTest.java;h=02fa1fe8e2ae2f977be9b08902199854b59d428c;hb=580ecde4af04ece62a9eb1d6adc541e2125ac065;hp=a9b23db075028e4ff4d7af09c2ec280dc5383f88;hpb=efca5e72d8c1e7b805ed28d1313375dc7d8594f1;p=netconf.git diff --git a/restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestconfImplTest.java b/restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestconfImplTest.java index a9b23db075..02fa1fe8e2 100644 --- a/restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestconfImplTest.java +++ b/restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestconfImplTest.java @@ -19,6 +19,7 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import static org.opendaylight.yangtools.util.concurrent.FluentFutures.immediateFluentFuture; +import com.google.common.collect.Iterables; import com.google.common.collect.Lists; import com.google.common.collect.Sets; import java.io.FileNotFoundException; @@ -36,6 +37,7 @@ import javax.ws.rs.core.MultivaluedHashMap; import javax.ws.rs.core.MultivaluedMap; import javax.ws.rs.core.UriBuilder; import javax.ws.rs.core.UriInfo; +import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; import org.mockito.Mockito; @@ -43,16 +45,19 @@ import org.opendaylight.controller.md.sal.rest.common.TestRestconfUtils; import org.opendaylight.mdsal.dom.api.DOMMountPoint; import org.opendaylight.mdsal.dom.api.DOMRpcResult; import org.opendaylight.mdsal.dom.api.DOMRpcService; +import org.opendaylight.netconf.sal.rest.api.Draft02; +import org.opendaylight.netconf.sal.rest.impl.NormalizedNodeContext; import org.opendaylight.netconf.sal.restconf.impl.BrokerFacade; import org.opendaylight.netconf.sal.restconf.impl.ControllerContext; import org.opendaylight.netconf.sal.restconf.impl.RestconfImpl; import org.opendaylight.netconf.sal.streams.listeners.Notificator; +import org.opendaylight.netconf.sal.streams.websockets.WebSocketServer; import org.opendaylight.restconf.common.context.InstanceIdentifierContext; -import org.opendaylight.restconf.common.context.NormalizedNodeContext; import org.opendaylight.restconf.common.errors.RestconfDocumentedException; import org.opendaylight.restconf.common.errors.RestconfError; -import org.opendaylight.restconf.common.errors.RestconfError.ErrorTag; -import org.opendaylight.restconf.common.errors.RestconfError.ErrorType; +import org.opendaylight.yangtools.yang.common.Empty; +import org.opendaylight.yangtools.yang.common.ErrorTag; +import org.opendaylight.yangtools.yang.common.ErrorType; import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates; import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode; @@ -61,9 +66,14 @@ import org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode; import org.opendaylight.yangtools.yang.data.api.schema.LeafSetNode; import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode; import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; +import org.opendaylight.yangtools.yang.data.api.schema.builder.DataContainerNodeBuilder; +import org.opendaylight.yangtools.yang.data.impl.schema.SchemaAwareBuilders; +import org.opendaylight.yangtools.yang.model.api.DataSchemaNode; +import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext; +import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode; +import org.opendaylight.yangtools.yang.model.api.ListSchemaNode; import org.opendaylight.yangtools.yang.model.api.Module; import org.opendaylight.yangtools.yang.model.api.RpcDefinition; -import org.opendaylight.yangtools.yang.model.api.SchemaContext; import org.opendaylight.yangtools.yang.model.api.SchemaNode; import org.opendaylight.yangtools.yang.model.api.SchemaPath; import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; @@ -73,7 +83,7 @@ import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; */ public class RestconfImplTest { - private static SchemaContext schemaContext; + private static EffectiveModelContext schemaContext; private final BrokerFacade brokerFacade = mock(BrokerFacade.class); private final ControllerContext controllerContext = TestRestconfUtils.newControllerContext(schemaContext); @@ -81,9 +91,12 @@ public class RestconfImplTest { @BeforeClass public static void init() throws FileNotFoundException, ReactorException { - schemaContext = TestUtils.loadSchemaContext("/full-versions/yangs"); - final Set allModules = schemaContext.getModules(); - assertNotNull(allModules); + schemaContext = TestUtils.loadSchemaContext("/full-versions/yangs", "/modules/restconf-module-testing"); + } + + @AfterClass + public static void cleanUp() { + WebSocketServer.destroyInstance(); // NETCONF-604 } @Test @@ -102,7 +115,7 @@ public class RestconfImplTest { final MapEntryNode payload = mock(MapEntryNode.class); final NodeIdentifierWithPredicates nodeIdWithPred = - new NodeIdentifierWithPredicates(keyDef, keyDef, al2.toArray()); + NodeIdentifierWithPredicates.of(keyDef, keyDef, al2.toArray()); when(payload.getIdentifier()).thenReturn(nodeIdWithPred); final List keyDefinitions = new ArrayList<>(); @@ -152,10 +165,10 @@ public class RestconfImplTest { final DOMRpcService rpcService = mock(DOMRpcService.class); doReturn(Optional.of(rpcService)).when(mount).getService(DOMRpcService.class); doReturn(immediateFluentFuture(mock(DOMRpcResult.class))).when(rpcService) - .invokeRpc(any(SchemaPath.class), any(NormalizedNode.class)); + .invokeRpc(any(QName.class), any(NormalizedNode.class)); this.restconfImpl.invokeRpc("randomId", ctx, uriInfo); this.restconfImpl.invokeRpc("ietf-netconf", ctx, uriInfo); - verify(rpcService, times(2)).invokeRpc(any(SchemaPath.class), isNull()); + verify(rpcService, times(2)).invokeRpc(any(QName.class), any()); } /** @@ -176,19 +189,19 @@ public class RestconfImplTest { "2014-01-14", "create-notification-stream")).when(schemaNode).getQName(); doReturn(null).when(iiCtx).getMountPoint(); - final Set> children = new HashSet<>(); - final DataContainerChild child = mock(DataContainerChild.class, + final Set children = new HashSet<>(); + final DataContainerChild child = mock(DataContainerChild.class, Mockito.withSettings().extraInterfaces(LeafSetNode.class)); final LeafSetEntryNode entryNode = mock(LeafSetEntryNode.class); - when(entryNode.getValue()).thenReturn("(http://netconfcentral.org/ns/toaster?revision=2009-11-20)toastDone"); - when(((LeafSetNode) child).getValue()).thenReturn(Sets.newHashSet(entryNode)); + when(entryNode.body()).thenReturn("(http://netconfcentral.org/ns/toaster?revision=2009-11-20)toastDone"); + when(((LeafSetNode) child).body()).thenReturn(Sets.newHashSet(entryNode)); children.add(child); - final NormalizedNode normalizedNode = mock(NormalizedNode.class, + final NormalizedNode normalizedNode = mock(NormalizedNode.class, Mockito.withSettings().extraInterfaces(ContainerNode.class)); doReturn(normalizedNode).when(payload).getData(); - doReturn(children).when(normalizedNode).getValue(); + doReturn(children).when(normalizedNode).body(); // register notification final NormalizedNodeContext context = this.restconfImpl @@ -196,6 +209,49 @@ public class RestconfImplTest { assertNotNull(context); } + /** + * Tests stream entry node. + */ + @Test + public void toStreamEntryNodeTest() { + final Module restconfModule = this.controllerContext.getRestconfModule(); + final DataSchemaNode streamSchemaNode = this.controllerContext + .getRestconfModuleRestConfSchemaNode(restconfModule, Draft02.RestConfModule.STREAM_LIST_SCHEMA_NODE); + final ListSchemaNode listStreamSchemaNode = (ListSchemaNode) streamSchemaNode; + final DataContainerNodeBuilder streamNodeValues = + SchemaAwareBuilders.mapEntryBuilder(listStreamSchemaNode); + List instanceDataChildrenByName = + ControllerContext.findInstanceDataChildrenByName(listStreamSchemaNode, "name"); + final DataSchemaNode nameSchemaNode = Iterables.getFirst(instanceDataChildrenByName, null); + streamNodeValues.withChild(SchemaAwareBuilders.leafBuilder((LeafSchemaNode) nameSchemaNode) + .withValue("") + .build()); + + instanceDataChildrenByName = + ControllerContext.findInstanceDataChildrenByName(listStreamSchemaNode, "description"); + final DataSchemaNode descriptionSchemaNode = Iterables.getFirst(instanceDataChildrenByName, null); + streamNodeValues.withChild(SchemaAwareBuilders.leafBuilder((LeafSchemaNode) nameSchemaNode) + .withValue("DESCRIPTION_PLACEHOLDER") + .build()); + + instanceDataChildrenByName = + ControllerContext.findInstanceDataChildrenByName(listStreamSchemaNode, "replay-support"); + final DataSchemaNode replaySupportSchemaNode = Iterables.getFirst(instanceDataChildrenByName, null); + streamNodeValues.withChild( + SchemaAwareBuilders.leafBuilder((LeafSchemaNode) replaySupportSchemaNode).withValue(Boolean.TRUE).build()); + + instanceDataChildrenByName = + ControllerContext.findInstanceDataChildrenByName(listStreamSchemaNode, "replay-log-creation-time"); + final DataSchemaNode replayLogCreationTimeSchemaNode = Iterables.getFirst(instanceDataChildrenByName, null); + streamNodeValues.withChild( + SchemaAwareBuilders.leafBuilder((LeafSchemaNode) replayLogCreationTimeSchemaNode).withValue("").build()); + instanceDataChildrenByName = ControllerContext.findInstanceDataChildrenByName(listStreamSchemaNode, "events"); + final DataSchemaNode eventsSchemaNode = Iterables.getFirst(instanceDataChildrenByName, null); + streamNodeValues.withChild( + SchemaAwareBuilders.leafBuilder((LeafSchemaNode) eventsSchemaNode).withValue(Empty.getInstance()).build()); + assertNotNull(streamNodeValues.build()); + } + /** * Subscribe for notification stream of toaster module. */