Search in sources :

Example 1 with NormalizedNodeContext

use of org.opendaylight.netconf.sal.rest.impl.NormalizedNodeContext in project netconf by opendaylight.

the class RestconfImplTest method testRpcForMountpoint.

@Test
public void testRpcForMountpoint() throws Exception {
    final UriInfo uriInfo = mock(UriInfo.class);
    doReturn(new MultivaluedHashMap<>()).when(uriInfo).getQueryParameters(anyBoolean());
    final NormalizedNodeContext ctx = mock(NormalizedNodeContext.class);
    final InstanceIdentifierContext<?> iiCtx = mock(InstanceIdentifierContext.class);
    doReturn(iiCtx).when(ctx).getInstanceIdentifierContext();
    final SchemaNode schemaNode = mock(SchemaNode.class);
    doReturn(schemaNode).when(iiCtx).getSchemaNode();
    doReturn(QName.create("namespace", "2010-10-10", "localname")).when(schemaNode).getQName();
    final DOMMountPoint mount = mock(DOMMountPoint.class);
    doReturn(mount).when(iiCtx).getMountPoint();
    final DOMRpcService rpcService = mock(DOMRpcService.class);
    doReturn(Optional.of(rpcService)).when(mount).getService(DOMRpcService.class);
    doReturn(immediateFluentFuture(mock(DOMRpcResult.class))).when(rpcService).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(QName.class), any());
}
Also used : ListSchemaNode(org.opendaylight.yangtools.yang.model.api.ListSchemaNode) SchemaNode(org.opendaylight.yangtools.yang.model.api.SchemaNode) DataSchemaNode(org.opendaylight.yangtools.yang.model.api.DataSchemaNode) LeafSchemaNode(org.opendaylight.yangtools.yang.model.api.LeafSchemaNode) DOMRpcService(org.opendaylight.mdsal.dom.api.DOMRpcService) QName(org.opendaylight.yangtools.yang.common.QName) DOMMountPoint(org.opendaylight.mdsal.dom.api.DOMMountPoint) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) UriInfo(javax.ws.rs.core.UriInfo) NormalizedNodeContext(org.opendaylight.netconf.sal.rest.impl.NormalizedNodeContext) Test(org.junit.Test)

Example 2 with NormalizedNodeContext

use of org.opendaylight.netconf.sal.rest.impl.NormalizedNodeContext in project netconf by opendaylight.

the class RestconfImplTest method createNotificationStreamTest.

/**
 * Create notification stream for toaster module.
 */
@Test
public void createNotificationStreamTest() {
    final NormalizedNodeContext payload = mock(NormalizedNodeContext.class);
    final InstanceIdentifierContext<?> iiCtx = mock(InstanceIdentifierContext.class);
    doReturn(iiCtx).when(payload).getInstanceIdentifierContext();
    final SchemaNode schemaNode = mock(SchemaNode.class, Mockito.withSettings().extraInterfaces(RpcDefinition.class));
    doReturn(schemaNode).when(iiCtx).getSchemaNode();
    doReturn(QName.create("urn:opendaylight:params:xml:ns:yang:controller:md:sal:remote", "2014-01-14", "create-notification-stream")).when(schemaNode).getQName();
    doReturn(null).when(iiCtx).getMountPoint();
    final Set<DataContainerChild> children = new HashSet<>();
    final DataContainerChild child = mock(DataContainerChild.class, Mockito.withSettings().extraInterfaces(LeafSetNode.class));
    final LeafSetEntryNode entryNode = mock(LeafSetEntryNode.class);
    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, Mockito.withSettings().extraInterfaces(ContainerNode.class));
    doReturn(normalizedNode).when(payload).getData();
    doReturn(children).when(normalizedNode).body();
    // register notification
    final NormalizedNodeContext context = this.restconfImpl.invokeRpc("sal-remote:create-notification-stream", payload, null);
    assertNotNull(context);
}
Also used : ListSchemaNode(org.opendaylight.yangtools.yang.model.api.ListSchemaNode) SchemaNode(org.opendaylight.yangtools.yang.model.api.SchemaNode) DataSchemaNode(org.opendaylight.yangtools.yang.model.api.DataSchemaNode) LeafSchemaNode(org.opendaylight.yangtools.yang.model.api.LeafSchemaNode) LeafSetEntryNode(org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode) RpcDefinition(org.opendaylight.yangtools.yang.model.api.RpcDefinition) DataContainerChild(org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) LeafSetNode(org.opendaylight.yangtools.yang.data.api.schema.LeafSetNode) NormalizedNodeContext(org.opendaylight.netconf.sal.rest.impl.NormalizedNodeContext) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 3 with NormalizedNodeContext

use of org.opendaylight.netconf.sal.rest.impl.NormalizedNodeContext in project netconf by opendaylight.

the class RestPutConfigTest method testPutConfigDataCheckOnlyLastElement.

@Test
public void testPutConfigDataCheckOnlyLastElement() {
    final String identifier = "test-interface:interfaces/interface/key/sub-interface/subkey";
    final InstanceIdentifierContext<?> iiCx = this.controllerCx.toInstanceIdentifier(identifier);
    final MapEntryNode data = Mockito.mock(MapEntryNode.class);
    final QName qName = QName.create("urn:ietf:params:xml:ns:yang:test-interface", "2014-07-01", "sub-interface");
    final QName qNameSubKey = QName.create("urn:ietf:params:xml:ns:yang:test-interface", "2014-07-01", "sub-name");
    final NodeIdentifierWithPredicates identWithPredicates = NodeIdentifierWithPredicates.of(qName, qNameSubKey, "subkey");
    Mockito.when(data.getIdentifier()).thenReturn(identWithPredicates);
    final NormalizedNodeContext payload = new NormalizedNodeContext(iiCx, data);
    mockingBrokerPut(iiCx.getInstanceIdentifier(), data);
    final UriInfo uriInfo = Mockito.mock(UriInfo.class);
    final MultivaluedMap<String, String> value = Mockito.mock(MultivaluedMap.class);
    Mockito.when(value.entrySet()).thenReturn(new HashSet<>());
    Mockito.when(uriInfo.getQueryParameters()).thenReturn(value);
    this.restconfService.updateConfigurationData(identifier, payload, uriInfo);
}
Also used : QName(org.opendaylight.yangtools.yang.common.QName) MapEntryNode(org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode) NodeIdentifierWithPredicates(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates) UriInfo(javax.ws.rs.core.UriInfo) NormalizedNodeContext(org.opendaylight.netconf.sal.rest.impl.NormalizedNodeContext) Test(org.junit.Test)

Example 4 with NormalizedNodeContext

use of org.opendaylight.netconf.sal.rest.impl.NormalizedNodeContext in project netconf by opendaylight.

the class RestPutConfigTest method testPutConfigData.

@Test
public void testPutConfigData() {
    final String identifier = "test-interface:interfaces/interface/key";
    final InstanceIdentifierContext<?> iiCx = this.controllerCx.toInstanceIdentifier(identifier);
    final MapEntryNode data = Mockito.mock(MapEntryNode.class);
    final QName qName = QName.create("urn:ietf:params:xml:ns:yang:test-interface", "2014-07-01", "interface");
    final QName qNameKey = QName.create("urn:ietf:params:xml:ns:yang:test-interface", "2014-07-01", "name");
    final NodeIdentifierWithPredicates identWithPredicates = NodeIdentifierWithPredicates.of(qName, qNameKey, "key");
    Mockito.when(data.getIdentifier()).thenReturn(identWithPredicates);
    final NormalizedNodeContext payload = new NormalizedNodeContext(iiCx, data);
    mockingBrokerPut(iiCx.getInstanceIdentifier(), data);
    final UriInfo uriInfo = Mockito.mock(UriInfo.class);
    final MultivaluedMap<String, String> value = Mockito.mock(MultivaluedMap.class);
    Mockito.when(value.entrySet()).thenReturn(new HashSet<>());
    Mockito.when(uriInfo.getQueryParameters()).thenReturn(value);
    this.restconfService.updateConfigurationData(identifier, payload, uriInfo);
}
Also used : QName(org.opendaylight.yangtools.yang.common.QName) MapEntryNode(org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode) NodeIdentifierWithPredicates(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates) UriInfo(javax.ws.rs.core.UriInfo) NormalizedNodeContext(org.opendaylight.netconf.sal.rest.impl.NormalizedNodeContext) Test(org.junit.Test)

Example 5 with NormalizedNodeContext

use of org.opendaylight.netconf.sal.rest.impl.NormalizedNodeContext in project netconf by opendaylight.

the class RestconfDocumentedExceptionMapperTest method testToResponseWithStatusOnly.

@Test
@Ignore
public void testToResponseWithStatusOnly() throws Exception {
    // The StructuredDataToJsonProvider should throw a
    // RestconfDocumentedException with no data
    when(mockRestConf.readOperationalData(any(String.class), any(UriInfo.class))).thenReturn(new NormalizedNodeContext(null, null));
    final Response resp = target("/operational/foo").request(MediaType.APPLICATION_JSON).get();
    verifyResponse(resp, MediaType.TEXT_PLAIN, Status.NOT_FOUND);
}
Also used : Response(javax.ws.rs.core.Response) UriInfo(javax.ws.rs.core.UriInfo) NormalizedNodeContext(org.opendaylight.netconf.sal.rest.impl.NormalizedNodeContext) Ignore(org.junit.Ignore) JerseyTest(org.glassfish.jersey.test.JerseyTest) Test(org.junit.Test)

Aggregations

NormalizedNodeContext (org.opendaylight.netconf.sal.rest.impl.NormalizedNodeContext)105 Test (org.junit.Test)70 InputStream (java.io.InputStream)36 AbstractBodyReaderTest (org.opendaylight.controller.sal.rest.impl.test.providers.AbstractBodyReaderTest)34 DataSchemaNode (org.opendaylight.yangtools.yang.model.api.DataSchemaNode)34 QName (org.opendaylight.yangtools.yang.common.QName)25 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)22 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)21 NodeIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier)18 RestconfDocumentedException (org.opendaylight.restconf.common.errors.RestconfDocumentedException)13 LeafSchemaNode (org.opendaylight.yangtools.yang.model.api.LeafSchemaNode)13 Module (org.opendaylight.yangtools.yang.model.api.Module)12 ByteArrayOutputStream (java.io.ByteArrayOutputStream)9 OutputStream (java.io.OutputStream)9 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)9 ContainerSchemaNode (org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode)9 UriInfo (javax.ws.rs.core.UriInfo)8 DOMMountPoint (org.opendaylight.mdsal.dom.api.DOMMountPoint)8 QNameModule (org.opendaylight.yangtools.yang.common.QNameModule)8 IOException (java.io.IOException)7