Search in sources :

Example 81 with NormalizedNodeContext

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

the class TestJsonBodyReaderMountPoint method rpcModuleInputTest.

@Test
public void rpcModuleInputTest() throws Exception {
    final String uri = "instance-identifier-module:cont/yang-ext:mount/invoke-rpc-module:rpc-test";
    mockBodyReader(uri, this.jsonBodyReader, true);
    final InputStream inputStream = TestJsonBodyReaderMountPoint.class.getResourceAsStream("/invoke-rpc/json/rpc-input.json");
    final NormalizedNodeContext returnValue = this.jsonBodyReader.readFrom(null, null, null, this.mediaType, null, inputStream);
    checkNormalizedNodeContext(returnValue);
    final ContainerNode inputNode = (ContainerNode) returnValue.getData();
    final YangInstanceIdentifier yangCont = YangInstanceIdentifier.of(QName.create(inputNode.getIdentifier().getNodeType(), "cont"));
    final Optional<DataContainerChild> contDataNode = inputNode.findChildByArg(yangCont.getLastPathArgument());
    assertTrue(contDataNode.isPresent());
    assertTrue(contDataNode.get() instanceof ContainerNode);
    final YangInstanceIdentifier yangleaf = YangInstanceIdentifier.of(QName.create(inputNode.getIdentifier().getNodeType(), "lf"));
    final Optional<DataContainerChild> leafDataNode = ((ContainerNode) contDataNode.get()).findChildByArg(yangleaf.getLastPathArgument());
    assertTrue(leafDataNode.isPresent());
    assertTrue("lf-test".equalsIgnoreCase(leafDataNode.get().body().toString()));
}
Also used : DataContainerChild(org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild) InputStream(java.io.InputStream) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) NormalizedNodeContext(org.opendaylight.netconf.sal.rest.impl.NormalizedNodeContext) Test(org.junit.Test)

Example 82 with NormalizedNodeContext

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

the class TestJsonBodyWriter method rpcModuleInputTest.

@Test
public void rpcModuleInputTest() throws Exception {
    final String uri = "invoke-rpc-module:rpc-test";
    mockBodyReader(uri, this.jsonBodyReader, true);
    final InputStream inputStream = TestJsonBodyWriter.class.getResourceAsStream("/invoke-rpc/json/rpc-output.json");
    final NormalizedNodeContext returnValue = this.jsonBodyReader.readFrom(null, null, null, this.mediaType, null, inputStream);
    final OutputStream output = new ByteArrayOutputStream();
    this.jsonBodyWriter.writeTo(returnValue, null, null, null, this.mediaType, null, output);
    assertTrue(output.toString().contains("lf-test"));
}
Also used : InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) NormalizedNodeContext(org.opendaylight.netconf.sal.rest.impl.NormalizedNodeContext) Test(org.junit.Test)

Example 83 with NormalizedNodeContext

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

the class TestXmlBodyReader method findBarContainerUsingNamespaceTest.

/**
 * Test when container with the same name is placed in two modules (foo-module and bar-module). Namespace must be
 * used to distinguish between them to find correct one. Check if container was found not only according to its name
 * but also by correct namespace used in payload.
 */
@Test
public void findBarContainerUsingNamespaceTest() throws Exception {
    mockBodyReader("", this.xmlBodyReader, true);
    final InputStream inputStream = TestXmlBodyReader.class.getResourceAsStream("/instanceidentifier/xml/xmlDataFindBarContainer.xml");
    final NormalizedNodeContext returnValue = this.xmlBodyReader.readFrom(null, null, null, this.mediaType, null, inputStream);
    // check return value
    checkNormalizedNodeContext(returnValue);
    // check if container was found both according to its name and namespace
    assertEquals("Not correct container found, name was ignored", "foo-bar-container", returnValue.getData().getIdentifier().getNodeType().getLocalName());
    assertEquals("Not correct container found, namespace was ignored", "bar:module", returnValue.getData().getIdentifier().getNodeType().getNamespace().toString());
}
Also used : InputStream(java.io.InputStream) NormalizedNodeContext(org.opendaylight.netconf.sal.rest.impl.NormalizedNodeContext) Test(org.junit.Test)

Example 84 with NormalizedNodeContext

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

the class TestXmlBodyReader method rpcModuleInputTest.

@Test
public void rpcModuleInputTest() throws Exception {
    final String uri = "invoke-rpc-module:rpc-test";
    mockBodyReader(uri, this.xmlBodyReader, true);
    final InputStream inputStream = TestXmlBodyReader.class.getResourceAsStream("/invoke-rpc/xml/rpc-input.xml");
    final NormalizedNodeContext returnValue = this.xmlBodyReader.readFrom(null, null, null, this.mediaType, null, inputStream);
    checkNormalizedNodeContext(returnValue);
    final ContainerNode contNode = (ContainerNode) returnValue.getData();
    final Optional<DataContainerChild> contDataNodePotential = contNode.findChildByArg(new NodeIdentifier(QName.create(contNode.getIdentifier().getNodeType(), "cont")));
    assertTrue(contDataNodePotential.isPresent());
    final ContainerNode contDataNode = (ContainerNode) contDataNodePotential.get();
    final Optional<DataContainerChild> leafDataNode = contDataNode.findChildByArg(new NodeIdentifier(QName.create(contDataNode.getIdentifier().getNodeType(), "lf")));
    assertTrue(leafDataNode.isPresent());
    assertTrue("lf-test".equalsIgnoreCase(leafDataNode.get().body().toString()));
}
Also used : DataContainerChild(org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild) InputStream(java.io.InputStream) NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) NormalizedNodeContext(org.opendaylight.netconf.sal.rest.impl.NormalizedNodeContext) Test(org.junit.Test)

Example 85 with NormalizedNodeContext

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

the class TestXmlBodyReader method moduleSubContainerDataPutTest.

@Test
public void moduleSubContainerDataPutTest() throws Exception {
    final DataSchemaNode dataSchemaNode = schemaContext.getDataChildByName(QName.create(INSTANCE_IDENTIFIER_MODULE_QNAME, "cont"));
    final QName cont1QName = QName.create(dataSchemaNode.getQName(), "cont1");
    final YangInstanceIdentifier dataII = YangInstanceIdentifier.of(dataSchemaNode.getQName()).node(cont1QName);
    final DataSchemaNode dataSchemaNodeOnPath = ((DataNodeContainer) dataSchemaNode).getDataChildByName(cont1QName);
    final String uri = "instance-identifier-module:cont/cont1";
    mockBodyReader(uri, this.xmlBodyReader, false);
    final InputStream inputStream = TestXmlBodyReader.class.getResourceAsStream("/instanceidentifier/xml/xml_sub_container.xml");
    final NormalizedNodeContext returnValue = this.xmlBodyReader.readFrom(null, null, null, this.mediaType, null, inputStream);
    checkNormalizedNodeContext(returnValue);
    checkExpectValueNormalizeNodeContext(dataSchemaNodeOnPath, returnValue, dataII);
}
Also used : DataSchemaNode(org.opendaylight.yangtools.yang.model.api.DataSchemaNode) QName(org.opendaylight.yangtools.yang.common.QName) InputStream(java.io.InputStream) DataNodeContainer(org.opendaylight.yangtools.yang.model.api.DataNodeContainer) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) NormalizedNodeContext(org.opendaylight.netconf.sal.rest.impl.NormalizedNodeContext) 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