Search in sources :

Example 26 with NormalizedNodeContext

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>"));
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) NormalizedNodeContext(org.opendaylight.netconf.sal.rest.impl.NormalizedNodeContext) Test(org.junit.Test) AbstractBodyReaderTest(org.opendaylight.controller.sal.rest.impl.test.providers.AbstractBodyReaderTest)

Example 27 with NormalizedNodeContext

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;
}
Also used : SystemLeafSetNode(org.opendaylight.yangtools.yang.data.api.schema.SystemLeafSetNode) LeafListSchemaNode(org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode) DataSchemaNode(org.opendaylight.yangtools.yang.model.api.DataSchemaNode) QName(org.opendaylight.yangtools.yang.common.QName) LeafSchemaNode(org.opendaylight.yangtools.yang.model.api.LeafSchemaNode) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) NormalizedNodeContext(org.opendaylight.netconf.sal.rest.impl.NormalizedNodeContext) ContainerSchemaNode(org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode) NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)

Example 28 with NormalizedNodeContext

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());
}
Also used : SystemMapNode(org.opendaylight.yangtools.yang.data.api.schema.SystemMapNode) DataSchemaNode(org.opendaylight.yangtools.yang.model.api.DataSchemaNode) QName(org.opendaylight.yangtools.yang.common.QName) MapEntryNode(org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode) NodeIdentifierWithPredicates(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) NormalizedNodeContext(org.opendaylight.netconf.sal.rest.impl.NormalizedNodeContext) ContainerSchemaNode(org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode) NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)

Example 29 with NormalizedNodeContext

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;
}
Also used : InputStream(java.io.InputStream) Document(org.w3c.dom.Document) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) URISyntaxException(java.net.URISyntaxException) XMLStreamException(javax.xml.stream.XMLStreamException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException) NormalizedNodeContext(org.opendaylight.netconf.sal.rest.impl.NormalizedNodeContext)

Example 30 with NormalizedNodeContext

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);
}
Also used : DataSchemaNode(org.opendaylight.yangtools.yang.model.api.DataSchemaNode) QName(org.opendaylight.yangtools.yang.common.QName) InputStream(java.io.InputStream) QNameModule(org.opendaylight.yangtools.yang.common.QNameModule) Module(org.opendaylight.yangtools.yang.model.api.Module) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) NormalizedNodeContext(org.opendaylight.netconf.sal.rest.impl.NormalizedNodeContext) Test(org.junit.Test)

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