Search in sources :

Example 76 with NormalizedNodeContext

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>"));
}
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 77 with NormalizedNodeContext

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;
}
Also used : 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) ChoiceNode(org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) ChoiceSchemaNode(org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode)

Example 78 with NormalizedNodeContext

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);
}
Also used : DataSchemaNode(org.opendaylight.yangtools.yang.model.api.DataSchemaNode) QName(org.opendaylight.yangtools.yang.common.QName) LeafSchemaNode(org.opendaylight.yangtools.yang.model.api.LeafSchemaNode) NodeIdentifierWithPredicates(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates) MapEntryNode(org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode) NormalizedNodeContext(org.opendaylight.netconf.sal.rest.impl.NormalizedNodeContext) ListSchemaNode(org.opendaylight.yangtools.yang.model.api.ListSchemaNode) NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) LeafNode(org.opendaylight.yangtools.yang.data.api.schema.LeafNode) UriInfo(javax.ws.rs.core.UriInfo)

Example 79 with NormalizedNodeContext

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

Example 80 with NormalizedNodeContext

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

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