use of org.opendaylight.netconf.sal.rest.impl.NormalizedNodeContext in project netconf by opendaylight.
the class NnInstanceIdentifierToXmlTest method nnAsYangInstanceIdentifierAugmentLeafList.
@Test
public void nnAsYangInstanceIdentifierAugmentLeafList() throws Exception {
final NormalizedNodeContext normalizedNodeContext = prepareNNCLeafList();
final OutputStream output = new ByteArrayOutputStream();
xmlBodyWriter.writeTo(normalizedNodeContext, null, null, null, mediaType, null, output);
assertNotNull(output);
final String outputJson = output.toString();
assertTrue(outputJson.contains("<cont xmlns="));
assertTrue(outputJson.contains('"' + "instance:identifier:module" + '"'));
assertTrue(outputJson.contains(">"));
assertTrue(outputJson.contains("<cont1>"));
assertTrue(outputJson.contains("<lf11 xmlns="));
assertTrue(outputJson.contains('"' + "augment:module:leaf:list" + '"'));
assertTrue(outputJson.contains(">"));
assertTrue(outputJson.contains("/instanceidentifier/"));
assertTrue(outputJson.contains("</lf11>"));
assertTrue(outputJson.contains("<lflst11 xmlns="));
assertTrue(outputJson.contains('"' + "augment:module:leaf:list" + '"'));
assertTrue(outputJson.contains(">"));
assertTrue(outputJson.contains("lflst11 value"));
assertTrue(outputJson.contains("</lflst11>"));
assertTrue(outputJson.contains("</cont1>"));
assertTrue(outputJson.contains("</cont>"));
}
use of org.opendaylight.netconf.sal.rest.impl.NormalizedNodeContext in project netconf by opendaylight.
the class NnInstanceIdentifierToXmlTest method prepareNNCLeafList.
private static NormalizedNodeContext prepareNNCLeafList() throws URISyntaxException {
final QName cont = QName.create("instance:identifier:module", "2014-01-17", "cont");
final QName cont1 = QName.create("instance:identifier:module", "2014-01-17", "cont1");
final QName lflst11 = QName.create("augment:module:leaf:list", "2014-01-17", "lflst11");
final QName lf11 = QName.create("augment:module:leaf:list", "2014-01-17", "lf11");
final YangInstanceIdentifier yII = YangInstanceIdentifier.builder().node(cont).build();
final DataSchemaNode schemaCont = schemaContext.getDataChildByName(cont);
final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> dataCont = SchemaAwareBuilders.containerBuilder((ContainerSchemaNode) schemaCont);
final DataSchemaNode schemaCont1 = ((ContainerSchemaNode) schemaCont).getDataChildByName(cont1);
final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> dataCont1 = SchemaAwareBuilders.containerBuilder((ContainerSchemaNode) schemaCont1);
final List<DataSchemaNode> instanceLfLst11 = ControllerContext.findInstanceDataChildrenByName((DataNodeContainer) schemaCont1, lflst11.getLocalName());
final DataSchemaNode lfLst11Schema = Iterables.getFirst(instanceLfLst11, null);
final ListNodeBuilder<Object, SystemLeafSetNode<Object>> lfLst11Data = SchemaAwareBuilders.leafSetBuilder((LeafListSchemaNode) lfLst11Schema);
lfLst11Data.withChild(SchemaAwareBuilders.leafSetEntryBuilder((LeafListSchemaNode) lfLst11Schema).withValue("lflst11 value").build());
dataCont1.withChild(lfLst11Data.build());
final List<DataSchemaNode> instanceLf11 = ControllerContext.findInstanceDataChildrenByName((DataNodeContainer) schemaCont1, lf11.getLocalName());
final DataSchemaNode lf11Schema = Iterables.getFirst(instanceLf11, null);
dataCont1.withChild(SchemaAwareBuilders.leafBuilder((LeafSchemaNode) lf11Schema).withValue("/instanceidentifier/").build());
dataCont.withChild(dataCont1.build());
final NormalizedNodeContext testNormalizedNodeContext = new NormalizedNodeContext(new InstanceIdentifierContext<>(yII, schemaCont, null, schemaContext), dataCont.build());
return testNormalizedNodeContext;
}
use of org.opendaylight.netconf.sal.rest.impl.NormalizedNodeContext in project netconf by opendaylight.
the class NnInstanceIdentifierToXmlTest method preparNNC.
private static NormalizedNodeContext preparNNC() {
final QName cont = QName.create("instance:identifier:module", "2014-01-17", "cont");
final QName cont1 = QName.create("instance:identifier:module", "2014-01-17", "cont1");
final QName lst11 = QName.create("augment:module", "2014-01-17", "lst11");
final QName lf11 = QName.create("augment:augment:module", "2014-01-17", "lf111");
final QName lf12 = QName.create("augment:augment:module", "2014-01-17", "lf112");
final QName keyvalue111 = QName.create("augment:module", "2014-01-17", "keyvalue111");
final QName keyvalue112 = QName.create("augment:module", "2014-01-17", "keyvalue112");
final YangInstanceIdentifier yII = YangInstanceIdentifier.builder().node(cont).build();
final DataSchemaNode schemaCont = schemaContext.getDataChildByName(cont);
final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> dataCont = SchemaAwareBuilders.containerBuilder((ContainerSchemaNode) schemaCont);
final DataSchemaNode schemaCont1 = ((ContainerSchemaNode) schemaCont).getDataChildByName(cont1);
final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> dataCont1 = SchemaAwareBuilders.containerBuilder((ContainerSchemaNode) schemaCont1);
final List<DataSchemaNode> instanceLst11 = ControllerContext.findInstanceDataChildrenByName((DataNodeContainer) schemaCont1, lst11.getLocalName());
final DataSchemaNode lst11Schema = Iterables.getFirst(instanceLst11, null);
final CollectionNodeBuilder<MapEntryNode, SystemMapNode> dataLst11 = SchemaAwareBuilders.mapBuilder((ListSchemaNode) lst11Schema);
final DataContainerNodeBuilder<NodeIdentifierWithPredicates, MapEntryNode> dataLst11Vaule = SchemaAwareBuilders.mapEntryBuilder((ListSchemaNode) lst11Schema);
dataLst11Vaule.withChild(buildLeaf(lst11Schema, keyvalue111, dataLst11, "keyvalue111"));
dataLst11Vaule.withChild(buildLeaf(lst11Schema, keyvalue112, dataLst11, "keyvalue112"));
dataLst11Vaule.withChild(buildLeaf(lst11Schema, lf11, dataLst11, "/cont/cont1/lf12"));
dataLst11Vaule.withChild(buildLeaf(lst11Schema, lf12, dataLst11, "lf12 value"));
dataLst11.withChild(dataLst11Vaule.build());
dataCont1.withChild(dataLst11.build());
dataCont.withChild(dataCont1.build());
return new NormalizedNodeContext(new InstanceIdentifierContext<>(yII, schemaCont, null, schemaContext), dataCont.build());
}
use of org.opendaylight.netconf.sal.rest.impl.NormalizedNodeContext in project netconf by opendaylight.
the class TestRestconfUtils method loadNormalizedContextFromXmlFile.
@SuppressWarnings("checkstyle:IllegalCatch")
public static NormalizedNodeContext loadNormalizedContextFromXmlFile(final String pathToInputFile, final String uri, final ControllerContext controllerContext) {
final InstanceIdentifierContext<?> iiContext = controllerContext.toInstanceIdentifier(uri);
final InputStream inputStream = TestJsonBodyWriter.class.getResourceAsStream(pathToInputFile);
try {
final Document doc = UntrustedXML.newDocumentBuilder().parse(inputStream);
final NormalizedNode nn = parse(iiContext, doc);
return new NormalizedNodeContext(iiContext, nn);
} catch (final Exception e) {
LOG.error("Load xml file " + pathToInputFile + " fail.", e);
}
return null;
}
use of org.opendaylight.netconf.sal.rest.impl.NormalizedNodeContext in project netconf by opendaylight.
the class TestJsonBodyReader method moduleSubContainerAugmentDataPostTest.
@Test
public void moduleSubContainerAugmentDataPostTest() throws Exception {
final DataSchemaNode dataSchemaNode = schemaContext.getDataChildByName(QName.create(INSTANCE_IDENTIFIER_MODULE_QNAME, "cont"));
final Module augmentModule = schemaContext.findModules(XMLNamespace.of("augment:module")).iterator().next();
final QName contAugmentQName = QName.create(augmentModule.getQNameModule(), "cont-augment");
final YangInstanceIdentifier.AugmentationIdentifier augII = new YangInstanceIdentifier.AugmentationIdentifier(Sets.newHashSet(contAugmentQName));
final YangInstanceIdentifier dataII = YangInstanceIdentifier.of(dataSchemaNode.getQName()).node(augII).node(contAugmentQName);
final String uri = "instance-identifier-module:cont";
mockBodyReader(uri, this.jsonBodyReader, true);
final InputStream inputStream = TestXmlBodyReader.class.getResourceAsStream("/instanceidentifier/json/json_augment_container.json");
final NormalizedNodeContext returnValue = this.jsonBodyReader.readFrom(null, null, null, this.mediaType, null, inputStream);
checkNormalizedNodeContext(returnValue);
checkExpectValueNormalizeNodeContext(dataSchemaNode, returnValue, dataII);
}
Aggregations