Search in sources :

Example 21 with NormalizedNodeContext

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

the class JsonToNnTest method emptyDataReadTest.

@Test
public void emptyDataReadTest() throws Exception {
    final NormalizedNodeContext normalizedNodeContext = prepareNNC("/json-to-nn/empty-data.json", "array-with-null-yang:cont");
    assertNotNull(normalizedNodeContext);
    assertEquals("cont", normalizedNodeContext.getData().getIdentifier().getNodeType().getLocalName());
    final String dataTree = NormalizedNodes.toStringTree(normalizedNodeContext.getData());
    assertTrue(dataTree.contains("lflst1"));
    assertTrue(dataTree.contains("lflst2 45"));
    RestconfDocumentedException exception = null;
    mockBodyReader("array-with-null-yang:cont", this.jsonBodyReader, false);
    final InputStream inputStream = this.getClass().getResourceAsStream("/json-to-nn/empty-data.json1");
    try {
        this.jsonBodyReader.readFrom(null, null, null, this.mediaType, null, inputStream);
    } catch (final RestconfDocumentedException e) {
        exception = e;
    }
    assertNotNull(exception);
    assertEquals("Error parsing input: null", exception.getErrors().get(0).getErrorMessage());
}
Also used : RestconfDocumentedException(org.opendaylight.restconf.common.errors.RestconfDocumentedException) InputStream(java.io.InputStream) NormalizedNodeContext(org.opendaylight.netconf.sal.rest.impl.NormalizedNodeContext) Test(org.junit.Test) AbstractBodyReaderTest(org.opendaylight.controller.sal.rest.impl.test.providers.AbstractBodyReaderTest)

Example 22 with NormalizedNodeContext

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

the class JsonToNnTest method nullArrayToSimpleNodeWithNullValueTest.

@Test
public void nullArrayToSimpleNodeWithNullValueTest() throws Exception {
    final NormalizedNodeContext normalizedNodeContext = prepareNNC("/json-to-nn/array-with-null.json", "array-with-null-yang:cont");
    assertNotNull(normalizedNodeContext);
    assertEquals("cont", normalizedNodeContext.getData().getIdentifier().getNodeType().getLocalName());
    final String dataTree = NormalizedNodes.toStringTree(normalizedNodeContext.getData());
    assertTrue(dataTree.contains("lf"));
    assertTrue(dataTree.contains("empty"));
}
Also used : NormalizedNodeContext(org.opendaylight.netconf.sal.rest.impl.NormalizedNodeContext) Test(org.junit.Test) AbstractBodyReaderTest(org.opendaylight.controller.sal.rest.impl.test.providers.AbstractBodyReaderTest)

Example 23 with NormalizedNodeContext

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

the class JsonToNnTest method dataAugmentedTest.

@Test
public void dataAugmentedTest() throws Exception {
    NormalizedNodeContext normalizedNodeContext = prepareNNC("/common/augment/json/dataa.json", "main:cont");
    assertNotNull(normalizedNodeContext);
    assertEquals("cont", normalizedNodeContext.getData().getIdentifier().getNodeType().getLocalName());
    String dataTree = NormalizedNodes.toStringTree(normalizedNodeContext.getData());
    assertTrue(dataTree.contains("cont1"));
    assertTrue(dataTree.contains("lf11 lf11 value from a"));
    normalizedNodeContext = prepareNNC("/common/augment/json/datab.json", "main:cont");
    assertNotNull(normalizedNodeContext);
    assertEquals("cont", normalizedNodeContext.getData().getIdentifier().getNodeType().getLocalName());
    dataTree = NormalizedNodes.toStringTree(normalizedNodeContext.getData());
    assertTrue(dataTree.contains("cont1"));
    assertTrue(dataTree.contains("lf11 lf11 value from b"));
}
Also used : NormalizedNodeContext(org.opendaylight.netconf.sal.rest.impl.NormalizedNodeContext) Test(org.junit.Test) AbstractBodyReaderTest(org.opendaylight.controller.sal.rest.impl.test.providers.AbstractBodyReaderTest)

Example 24 with NormalizedNodeContext

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

the class JsonToNnTest method prepareNNC.

private NormalizedNodeContext prepareNNC(final String jsonPath, final String uri) throws Exception {
    try {
        mockBodyReader(uri, this.jsonBodyReader, false);
    } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
        LOG.warn("Operation failed due to: {}", e.getMessage());
    }
    final InputStream inputStream = this.getClass().getResourceAsStream(jsonPath);
    NormalizedNodeContext normalizedNodeContext = null;
    try {
        normalizedNodeContext = this.jsonBodyReader.readFrom(null, null, null, this.mediaType, null, inputStream);
    } catch (WebApplicationException e) {
    // TODO Auto-generated catch block
    }
    return normalizedNodeContext;
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) InputStream(java.io.InputStream) NormalizedNodeContext(org.opendaylight.netconf.sal.rest.impl.NormalizedNodeContext)

Example 25 with NormalizedNodeContext

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

the class NnToJsonLeafrefType method toJson.

private String toJson(final String xmlDataPath) throws Exception {
    final String uri = "main-module:cont";
    final String pathToInputFile = xmlDataPath;
    final NormalizedNodeContext testNN = TestRestconfUtils.loadNormalizedContextFromXmlFile(pathToInputFile, uri, controllerContext);
    final OutputStream output = new ByteArrayOutputStream();
    jsonBodyWriter.writeTo(testNN, null, null, null, mediaType, null, output);
    final String jsonOutput = output.toString();
    return jsonOutput;
}
Also used : OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) NormalizedNodeContext(org.opendaylight.netconf.sal.rest.impl.NormalizedNodeContext)

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