Search in sources :

Example 36 with NormalizedNodeContext

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

the class TestXmlBodyReaderMountPoint method moduleDataTest.

@Test
public void moduleDataTest() throws Exception {
    final DataSchemaNode dataSchemaNode = schemaContext.getDataChildByName(QName.create(INSTANCE_IDENTIFIER_MODULE_QNAME, "cont"));
    final String uri = "instance-identifier-module:cont/yang-ext:mount/instance-identifier-module:cont";
    mockBodyReader(uri, this.xmlBodyReader, false);
    final InputStream inputStream = TestXmlBodyReaderMountPoint.class.getResourceAsStream("/instanceidentifier/xml/xmldata.xml");
    final NormalizedNodeContext returnValue = this.xmlBodyReader.readFrom(null, null, null, this.mediaType, null, inputStream);
    checkMountPointNormalizedNodeContext(returnValue);
    checkExpectValueNormalizeNodeContext(dataSchemaNode, returnValue);
}
Also used : DataSchemaNode(org.opendaylight.yangtools.yang.model.api.DataSchemaNode) InputStream(java.io.InputStream) NormalizedNodeContext(org.opendaylight.netconf.sal.rest.impl.NormalizedNodeContext) Test(org.junit.Test)

Example 37 with NormalizedNodeContext

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

the class TestXmlBodyReaderMountPoint 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.xmlBodyReader, true);
    final InputStream inputStream = TestXmlBodyReaderMountPoint.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 YangInstanceIdentifier yangCont = YangInstanceIdentifier.of(QName.create(contNode.getIdentifier().getNodeType(), "cont"));
    final Optional<DataContainerChild> contDataNodePotential = contNode.findChildByArg(yangCont.getLastPathArgument());
    assertTrue(contDataNodePotential.isPresent());
    final ContainerNode contDataNode = (ContainerNode) contDataNodePotential.get();
    final YangInstanceIdentifier yangLeaf = YangInstanceIdentifier.of(QName.create(contDataNode.getIdentifier().getNodeType(), "lf"));
    final Optional<DataContainerChild> leafDataNode = contDataNode.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 38 with NormalizedNodeContext

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

the class TestXmlBodyWriter method rpcModuleInputTest.

@Test
public void rpcModuleInputTest() throws Exception {
    final String uri = "invoke-rpc-module:rpc-test";
    final String pathToInputFile = "/invoke-rpc/xml/rpc-output.xml";
    final NormalizedNodeContext nnContext = TestRestconfUtils.loadNormalizedContextFromXmlFile(pathToInputFile, uri, controllerContext);
    final OutputStream output = new ByteArrayOutputStream();
    this.xmlBodyWriter.writeTo(nnContext, null, null, null, this.mediaType, null, output);
    assertTrue(output.toString().contains("lf-test"));
}
Also used : 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 39 with NormalizedNodeContext

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

the class NnToXmlWithDataFromSeveralModulesTest method dataFromSeveralModulesToXmlTest.

@Test
public void dataFromSeveralModulesToXmlTest() throws WebApplicationException, IOException, URISyntaxException {
    final NormalizedNodeContext normalizedNodeContext = prepareNormalizedNodeContext();
    final OutputStream output = new ByteArrayOutputStream();
    xmlBodyWriter.writeTo(normalizedNodeContext, null, null, null, mediaType, null, output);
    final String outputString = output.toString();
    // data
    assertTrue(outputString.contains("<data xmlns=" + '"' + "urn:ietf:params:xml:ns:netconf:base:1.0" + '"' + '>'));
    // cont m2
    assertTrue(outputString.contains("<cont_m2 xmlns=" + '"' + "module:two" + '"' + '>'));
    assertTrue(outputString.contains("<lf1_m2>lf1 m2 value</lf1_m2>"));
    assertTrue(outputString.contains("<contB_m2/>"));
    assertTrue(outputString.contains("</cont_m2>"));
    // cont m1
    assertTrue(outputString.contains("<cont_m1 xmlns=" + '"' + "module:one" + '"' + '>'));
    assertTrue(outputString.contains("<contB_m1/>"));
    assertTrue(outputString.contains("<lf1_m1>lf1 m1 value</lf1_m1>"));
    assertTrue(outputString.contains("</cont_m1>"));
    // end
    assertTrue(output.toString().contains("</data>"));
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) NormalizedNodeContext(org.opendaylight.netconf.sal.rest.impl.NormalizedNodeContext) Test(org.junit.Test) AbstractBodyReaderTest(org.opendaylight.controller.sal.rest.impl.test.providers.AbstractBodyReaderTest)

Example 40 with NormalizedNodeContext

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

the class TestJsonBodyReaderMountPoint method moduleDataTest.

@Test
public void moduleDataTest() throws Exception {
    final DataSchemaNode dataSchemaNode = schemaContext.getDataChildByName(QName.create(INSTANCE_IDENTIFIER_MODULE_QNAME, "cont"));
    final String uri = "instance-identifier-module:cont/yang-ext:mount/instance-identifier-module:cont";
    mockBodyReader(uri, this.jsonBodyReader, false);
    final InputStream inputStream = TestJsonBodyReaderMountPoint.class.getResourceAsStream("/instanceidentifier/json/jsondata.json");
    final NormalizedNodeContext returnValue = this.jsonBodyReader.readFrom(null, null, null, this.mediaType, null, inputStream);
    checkMountPointNormalizedNodeContext(returnValue);
    checkExpectValueNormalizeNodeContext(dataSchemaNode, returnValue);
}
Also used : DataSchemaNode(org.opendaylight.yangtools.yang.model.api.DataSchemaNode) InputStream(java.io.InputStream) 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