use of org.opendaylight.netconf.sal.rest.impl.NormalizedNodeContext in project netconf by opendaylight.
the class NnToXmlWithChoiceTest method cnSnToXmlWithYangChoice.
@Test
public void cnSnToXmlWithYangChoice() throws Exception {
NormalizedNodeContext normalizedNodeContext = prepareNNC("lf1", "String data1");
OutputStream output = new ByteArrayOutputStream();
xmlBodyWriter.writeTo(normalizedNodeContext, null, null, null, mediaType, null, output);
assertTrue(output.toString().contains("<lf1>String data1</lf1>"));
normalizedNodeContext = prepareNNC("lf2", "String data2");
output = new ByteArrayOutputStream();
xmlBodyWriter.writeTo(normalizedNodeContext, null, null, null, mediaType, null, output);
assertTrue(output.toString().contains("<lf2>String data2</lf2>"));
}
use of org.opendaylight.netconf.sal.rest.impl.NormalizedNodeContext in project netconf by opendaylight.
the class NnToXmlWithChoiceTest method prepareNNC.
private static NormalizedNodeContext prepareNNC(final String name, final Object value) {
final QName contQname = QName.create("module:with:choice", "2013-12-18", "cont");
final QName lf = QName.create("module:with:choice", "2013-12-18", name);
final QName choA = QName.create("module:with:choice", "2013-12-18", "choA");
final YangInstanceIdentifier yII = YangInstanceIdentifier.builder().node(contQname).build();
final DataSchemaNode contSchemaNode = schemaContext.getDataChildByName(contQname);
final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> dataContainerNodeAttrBuilder = SchemaAwareBuilders.containerBuilder((ContainerSchemaNode) contSchemaNode);
final DataSchemaNode choiceSchemaNode = ((ContainerSchemaNode) contSchemaNode).getDataChildByName(choA);
assertTrue(choiceSchemaNode instanceof ChoiceSchemaNode);
final DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> dataChoice = SchemaAwareBuilders.choiceBuilder((ChoiceSchemaNode) choiceSchemaNode);
final List<DataSchemaNode> instanceLf = ControllerContext.findInstanceDataChildrenByName((DataNodeContainer) contSchemaNode, lf.getLocalName());
final DataSchemaNode schemaLf = Iterables.getFirst(instanceLf, null);
dataChoice.withChild(SchemaAwareBuilders.leafBuilder((LeafSchemaNode) schemaLf).withValue(value).build());
dataContainerNodeAttrBuilder.withChild(dataChoice.build());
final NormalizedNodeContext testNormalizedNodeContext = new NormalizedNodeContext(new InstanceIdentifierContext<>(yII, contSchemaNode, null, schemaContext), dataContainerNodeAttrBuilder.build());
return testNormalizedNodeContext;
}
use of org.opendaylight.netconf.sal.rest.impl.NormalizedNodeContext in project netconf by opendaylight.
the class RestPutListDataTest method putListDataTest.
public void putListDataTest(final String uriKey1, final String uriKey2, final String payloadKey1, final Short payloadKey2) {
final QName lstWithCompositeKey = QName.create(TEST_MODULE_NS_STRING, TEST_MODULE_REVISION, "lst-with-composite-key");
final QName key1 = QName.create(TEST_MODULE_NS_STRING, TEST_MODULE_REVISION, "key1");
final QName key2 = QName.create(TEST_MODULE_NS_STRING, TEST_MODULE_REVISION, "key2");
final DataSchemaNode testNodeSchemaNode = schemaContextTestModule.getDataChildByName(lstWithCompositeKey);
assertTrue(testNodeSchemaNode != null);
assertTrue(testNodeSchemaNode instanceof ListSchemaNode);
final DataContainerNodeBuilder<NodeIdentifierWithPredicates, MapEntryNode> testNodeContainer = SchemaAwareBuilders.mapEntryBuilder((ListSchemaNode) testNodeSchemaNode);
List<DataSchemaNode> testChildren = ControllerContext.findInstanceDataChildrenByName((ListSchemaNode) testNodeSchemaNode, key1.getLocalName());
assertTrue(testChildren != null);
final DataSchemaNode testLeafKey1SchemaNode = Iterables.getFirst(testChildren, null);
assertTrue(testLeafKey1SchemaNode != null);
assertTrue(testLeafKey1SchemaNode instanceof LeafSchemaNode);
final NormalizedNodeBuilder<NodeIdentifier, Object, LeafNode<Object>> leafKey1 = SchemaAwareBuilders.leafBuilder((LeafSchemaNode) testLeafKey1SchemaNode);
leafKey1.withValue(payloadKey1);
testNodeContainer.withChild(leafKey1.build());
if (payloadKey2 != null) {
testChildren = ControllerContext.findInstanceDataChildrenByName((ListSchemaNode) testNodeSchemaNode, key2.getLocalName());
assertTrue(testChildren != null);
final DataSchemaNode testLeafKey2SchemaNode = Iterables.getFirst(testChildren, null);
assertTrue(testLeafKey2SchemaNode != null);
assertTrue(testLeafKey2SchemaNode instanceof LeafSchemaNode);
final NormalizedNodeBuilder<NodeIdentifier, Object, LeafNode<Object>> leafKey2 = SchemaAwareBuilders.leafBuilder((LeafSchemaNode) testLeafKey2SchemaNode);
leafKey2.withValue(payloadKey2);
testNodeContainer.withChild(leafKey2.build());
}
final NormalizedNodeContext testCompositeContext = new NormalizedNodeContext(new InstanceIdentifierContext<>(null, testNodeSchemaNode, null, schemaContextTestModule), testNodeContainer.build());
final UriInfo uriInfo = Mockito.mock(UriInfo.class);
restconfImpl.updateConfigurationData(toUri(uriKey1, uriKey2), testCompositeContext, uriInfo);
}
use of org.opendaylight.netconf.sal.rest.impl.NormalizedNodeContext in project netconf by opendaylight.
the class JsonLeafrefToNnTest method jsonIdentityrefToNormalizeNode.
@Test
public void jsonIdentityrefToNormalizeNode() throws Exception {
final String uri = "leafref-module:cont";
mockBodyReader(uri, this.jsonBodyReader, false);
final InputStream inputStream = this.getClass().getResourceAsStream("/json-to-nn/leafref/json/data.json");
final NormalizedNodeContext normalizedNodeContext = this.jsonBodyReader.readFrom(null, null, null, this.mediaType, null, inputStream);
assertEquals("cont", normalizedNodeContext.getData().getIdentifier().getNodeType().getLocalName());
final String dataTree = NormalizedNodes.toStringTree(normalizedNodeContext.getData());
assertTrue(dataTree.contains("lf2 121"));
}
use of org.opendaylight.netconf.sal.rest.impl.NormalizedNodeContext in project netconf by opendaylight.
the class JsonToNnTest method multipleItemsInListTest.
@Test
public void multipleItemsInListTest() throws Exception {
final NormalizedNodeContext normalizedNodeContext = prepareNNC("/json-to-nn/multiple-items-in-list.json", "multiple-items-yang:lst");
assertNotNull(normalizedNodeContext);
assertEquals("lst", normalizedNodeContext.getData().getIdentifier().getNodeType().getLocalName());
verityMultipleItemsInList(normalizedNodeContext);
}
Aggregations