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());
}
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"));
}
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"));
}
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;
}
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;
}
Aggregations