use of org.opendaylight.yangtools.yang.model.api.DataNodeContainer in project netconf by opendaylight.
the class ControllerContext method getDataNodeContainerFor.
public DataNodeContainer getDataNodeContainerFor(final YangInstanceIdentifier path) {
checkPreconditions();
final Iterable<PathArgument> elements = path.getPathArguments();
final PathArgument head = elements.iterator().next();
final QName startQName = head.getNodeType();
final Module initialModule = globalSchema.findModule(startQName.getModule()).orElse(null);
DataNodeContainer node = initialModule;
for (final PathArgument element : elements) {
final QName _nodeType = element.getNodeType();
final DataSchemaNode potentialNode = childByQName(node, _nodeType);
if (potentialNode == null || !isListOrContainer(potentialNode)) {
return null;
}
node = (DataNodeContainer) potentialNode;
}
return node;
}
use of org.opendaylight.yangtools.yang.model.api.DataNodeContainer in project netconf by opendaylight.
the class TestJsonBodyReader method moduleSubContainerDataPutTest.
@Test
public void moduleSubContainerDataPutTest() throws Exception {
final DataSchemaNode dataSchemaNode = schemaContext.getDataChildByName(QName.create(INSTANCE_IDENTIFIER_MODULE_QNAME, "cont"));
final QName cont1QName = QName.create(dataSchemaNode.getQName(), "cont1");
final YangInstanceIdentifier dataII = YangInstanceIdentifier.of(dataSchemaNode.getQName()).node(cont1QName);
final DataSchemaNode dataSchemaNodeOnPath = ((DataNodeContainer) dataSchemaNode).getDataChildByName(cont1QName);
final String uri = "instance-identifier-module:cont/cont1";
mockBodyReader(uri, this.jsonBodyReader, false);
final InputStream inputStream = TestJsonBodyReader.class.getResourceAsStream("/instanceidentifier/json/json_sub_container.json");
final NormalizedNodeContext returnValue = this.jsonBodyReader.readFrom(null, null, null, this.mediaType, null, inputStream);
checkNormalizedNodeContext(returnValue);
checkExpectValueNormalizeNodeContext(dataSchemaNodeOnPath, returnValue, dataII);
}
use of org.opendaylight.yangtools.yang.model.api.DataNodeContainer in project netconf by opendaylight.
the class TestXmlBodyReaderMountPoint method checkExpectValueNormalizeNodeContext.
protected void checkExpectValueNormalizeNodeContext(final DataSchemaNode dataSchemaNode, final NormalizedNodeContext nnContext, final QName qualifiedName) {
YangInstanceIdentifier dataNodeIdent = YangInstanceIdentifier.of(dataSchemaNode.getQName());
final DOMMountPoint mountPoint = nnContext.getInstanceIdentifierContext().getMountPoint();
final DataSchemaNode mountDataSchemaNode = modelContext(mountPoint).getDataChildByName(dataSchemaNode.getQName());
assertNotNull(mountDataSchemaNode);
if (qualifiedName != null && dataSchemaNode instanceof DataNodeContainer) {
final DataSchemaNode child = ((DataNodeContainer) dataSchemaNode).getDataChildByName(qualifiedName);
dataNodeIdent = YangInstanceIdentifier.builder(dataNodeIdent).node(child.getQName()).build();
assertTrue(nnContext.getInstanceIdentifierContext().getSchemaNode().equals(child));
} else {
assertTrue(mountDataSchemaNode.equals(dataSchemaNode));
}
assertNotNull(NormalizedNodes.findNode(nnContext.getData(), dataNodeIdent));
}
use of org.opendaylight.yangtools.yang.model.api.DataNodeContainer in project netconf by opendaylight.
the class NnToXmlTest method prepareLeafrefData.
private static NormalizedNodeContext prepareLeafrefData() {
final QName cont = QName.create("basic:module", "2013-12-02", "cont");
final QName lfBoolean = QName.create("basic:module", "2013-12-02", "lfBoolean");
final QName lfLfref = QName.create("basic:module", "2013-12-02", "lfLfref");
final YangInstanceIdentifier yII = YangInstanceIdentifier.builder().node(cont).build();
final DataSchemaNode contSchema = schemaContext.getDataChildByName(cont);
final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> contData = SchemaAwareBuilders.containerBuilder((ContainerSchemaNode) contSchema);
List<DataSchemaNode> instanceLf = ControllerContext.findInstanceDataChildrenByName((DataNodeContainer) contSchema, lfBoolean.getLocalName());
DataSchemaNode schemaLf = Iterables.getFirst(instanceLf, null);
contData.withChild(SchemaAwareBuilders.leafBuilder((LeafSchemaNode) schemaLf).withValue(Boolean.TRUE).build());
instanceLf = ControllerContext.findInstanceDataChildrenByName((DataNodeContainer) contSchema, lfLfref.getLocalName());
schemaLf = Iterables.getFirst(instanceLf, null);
contData.withChild(SchemaAwareBuilders.leafBuilder((LeafSchemaNode) schemaLf).withValue("true").build());
final NormalizedNodeContext testNormalizedNodeContext = new NormalizedNodeContext(new InstanceIdentifierContext<>(yII, contSchema, null, schemaContext), contData.build());
return testNormalizedNodeContext;
}
use of org.opendaylight.yangtools.yang.model.api.DataNodeContainer in project netconf by opendaylight.
the class JsonBodyReaderTest method moduleSubContainerDataPutTest.
@Test
public void moduleSubContainerDataPutTest() throws Exception {
final DataSchemaNode dataSchemaNode = schemaContext.getDataChildByName(QName.create(INSTANCE_IDENTIFIER_MODULE_QNAME, "cont"));
final QName cont1QName = QName.create(dataSchemaNode.getQName(), "cont1");
final YangInstanceIdentifier dataII = YangInstanceIdentifier.of(dataSchemaNode.getQName()).node(cont1QName);
final DataSchemaNode dataSchemaNodeOnPath = ((DataNodeContainer) dataSchemaNode).getDataChildByName(cont1QName);
final String uri = "instance-identifier-module:cont/cont1";
mockBodyReader(uri, jsonBodyReader, false);
final NormalizedNodePayload payload = jsonBodyReader.readFrom(null, null, null, mediaType, null, JsonBodyReaderTest.class.getResourceAsStream("/instanceidentifier/json/json_sub_container.json"));
checkNormalizedNodePayload(payload);
checkExpectValueNormalizeNodeContext(dataSchemaNodeOnPath, payload, dataII);
}
Aggregations