Search in sources :

Example 21 with SystemMapNode

use of org.opendaylight.yangtools.yang.data.api.schema.SystemMapNode in project yangtools by opendaylight.

the class Bug5968MergeTest method mergeInvalidContainerTest.

@Test
public void mergeInvalidContainerTest() throws DataValidationFailedException {
    final DataTree inMemoryDataTree = emptyDataTree(SCHEMA_CONTEXT);
    final SystemMapNode myList = createMap(true);
    final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> root = Builders.containerBuilder().withNodeIdentifier(new NodeIdentifier(ROOT)).withChild(myList);
    final DataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification();
    modificationTree.merge(YangInstanceIdentifier.of(ROOT), root.build());
    try {
        modificationTree.ready();
        inMemoryDataTree.validate(modificationTree);
        final DataTreeCandidate prepare = inMemoryDataTree.prepare(modificationTree);
        inMemoryDataTree.commit(prepare);
        fail("Should fail due to missing mandatory leaf.");
    } catch (final IllegalArgumentException e) {
        assertEquals("Node (bug5968?revision=2016-07-28)my-list[{(bug5968?revision=2016-07-28)list-id=1}] is " + "missing mandatory descendant /(bug5968?revision=2016-07-28)mandatory-leaf", e.getMessage());
    }
}
Also used : DataTreeModification(org.opendaylight.yangtools.yang.data.tree.api.DataTreeModification) DataTreeCandidate(org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidate) SystemMapNode(org.opendaylight.yangtools.yang.data.api.schema.SystemMapNode) DataTree(org.opendaylight.yangtools.yang.data.tree.api.DataTree) NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) Test(org.junit.Test)

Example 22 with SystemMapNode

use of org.opendaylight.yangtools.yang.data.api.schema.SystemMapNode in project yangtools by opendaylight.

the class Bug2690Test method testWriteMerge1.

@Test
public void testWriteMerge1() throws DataValidationFailedException {
    final MapEntryNode fooEntryNode = ImmutableNodes.mapEntry(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 1);
    final MapEntryNode barEntryNode = ImmutableNodes.mapEntry(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 2);
    final SystemMapNode mapNode1 = ImmutableNodes.mapNodeBuilder().withNodeIdentifier(new NodeIdentifier(TestModel.OUTER_LIST_QNAME)).withChild(fooEntryNode).build();
    final SystemMapNode mapNode2 = ImmutableNodes.mapNodeBuilder().withNodeIdentifier(new NodeIdentifier(TestModel.OUTER_LIST_QNAME)).withChild(barEntryNode).build();
    final ContainerNode cont1 = Builders.containerBuilder().withNodeIdentifier(new NodeIdentifier(TestModel.TEST_QNAME)).withChild(mapNode1).build();
    final ContainerNode cont2 = Builders.containerBuilder().withNodeIdentifier(new NodeIdentifier(TestModel.TEST_QNAME)).withChild(mapNode2).build();
    final DataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification();
    modificationTree.write(TestModel.TEST_PATH, cont1);
    modificationTree.merge(TestModel.TEST_PATH, cont2);
    commit(modificationTree);
    final DataTreeSnapshot snapshotAfterTx = inMemoryDataTree.takeSnapshot();
    final DataTreeModification modificationAfterTx = snapshotAfterTx.newModification();
    final Optional<NormalizedNode> readNode = modificationAfterTx.readNode(TestModel.OUTER_LIST_PATH);
    assertTrue(readNode.isPresent());
    assertEquals(2, ((NormalizedNodeContainer<?>) readNode.get()).size());
}
Also used : DataTreeModification(org.opendaylight.yangtools.yang.data.tree.api.DataTreeModification) SystemMapNode(org.opendaylight.yangtools.yang.data.api.schema.SystemMapNode) NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) DataTreeSnapshot(org.opendaylight.yangtools.yang.data.tree.api.DataTreeSnapshot) MapEntryNode(org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) Test(org.junit.Test)

Example 23 with SystemMapNode

use of org.opendaylight.yangtools.yang.data.api.schema.SystemMapNode in project yangtools by opendaylight.

the class Bug4295Test method firstModification.

private void firstModification() throws DataValidationFailedException {
    /*  MERGE */
    SystemMapNode outerListNode = ImmutableNodes.mapNodeBuilder().withNodeIdentifier(NodeIdentifier.create(outerList)).withChild(createOuterListEntry("1", "o-1")).withChild(createOuterListEntry("2", "o-2")).withChild(createOuterListEntry("3", "o-3")).build();
    ContainerNode rootContainerNode = createRootContainerBuilder().withChild(createSubRootContainerBuilder().withChild(outerListNode).build()).build();
    YangInstanceIdentifier path = YangInstanceIdentifier.of(root);
    DataTreeModification modification = inMemoryDataTree.takeSnapshot().newModification();
    modification.merge(path, rootContainerNode);
    /*  WRITE INNER LIST WITH ENTRIES*/
    SystemMapNode innerListNode = createInnerListBuilder().withChild(createInnerListEntry("a", "i-a")).withChild(createInnerListEntry("b", "i-b")).build();
    path = YangInstanceIdentifier.of(root).node(subRoot).node(outerList).node(createOuterListEntryPath("2")).node(innerList);
    modification.write(path, innerListNode);
    /*  COMMIT */
    modification.ready();
    inMemoryDataTree.validate(modification);
    inMemoryDataTree.commit(inMemoryDataTree.prepare(modification));
}
Also used : DataTreeModification(org.opendaylight.yangtools.yang.data.tree.api.DataTreeModification) SystemMapNode(org.opendaylight.yangtools.yang.data.api.schema.SystemMapNode) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)

Example 24 with SystemMapNode

use of org.opendaylight.yangtools.yang.data.api.schema.SystemMapNode in project yangtools by opendaylight.

the class BuilderTest method immutableMapNodeBuilderTest.

@Test
public void immutableMapNodeBuilderTest() {
    final LinkedList<MapEntryNode> mapEntryNodeColl = new LinkedList<>();
    mapEntryNodeColl.add(LIST_MAIN_CHILD_3);
    final CollectionNodeBuilder<MapEntryNode, SystemMapNode> collectionNodeBuilder = ImmutableMapNodeBuilder.create(1);
    assertNotNull(collectionNodeBuilder);
    collectionNodeBuilder.withNodeIdentifier(NODE_IDENTIFIER_LEAF_LIST);
    collectionNodeBuilder.withValue(mapEntryNodeColl);
    final SystemMapNode mapNode = collectionNodeBuilder.build();
    assertNotNull(Builders.mapBuilder(mapNode));
}
Also used : SystemMapNode(org.opendaylight.yangtools.yang.data.api.schema.SystemMapNode) MapEntryNode(org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 25 with SystemMapNode

use of org.opendaylight.yangtools.yang.data.api.schema.SystemMapNode in project yangtools by opendaylight.

the class ImmutableNormalizedNodeStreamWriterTest method buildOuterContainerNode.

private NormalizedNode buildOuterContainerNode() {
    // my-container-1
    SystemMapNode myKeyedListNode = Builders.mapBuilder().withNodeIdentifier(new NodeIdentifier(myKeyedList)).withChild(Builders.mapEntryBuilder().withNodeIdentifier(NodeIdentifierWithPredicates.of(myKeyedList, myKeyLeaf, "listkeyvalue1")).withChild(Builders.leafBuilder().withNodeIdentifier(new NodeIdentifier(myLeafInList1)).withValue("listleafvalue1").build()).withChild(Builders.leafBuilder().withNodeIdentifier(new NodeIdentifier(myLeafInList2)).withValue("listleafvalue2").build()).build()).withChild(Builders.mapEntryBuilder().withNodeIdentifier(NodeIdentifierWithPredicates.of(myKeyedList, myKeyLeaf, "listkeyvalue2")).withChild(Builders.leafBuilder().withNodeIdentifier(new NodeIdentifier(myLeafInList1)).withValue("listleafvalue12").build()).withChild(Builders.leafBuilder().withNodeIdentifier(new NodeIdentifier(myLeafInList2)).withValue("listleafvalue22").build()).build()).build();
    UserMapNode myOrderedListNode = Builders.orderedMapBuilder().withNodeIdentifier(new NodeIdentifier(myOrderedList)).withChild(Builders.mapEntryBuilder().withNodeIdentifier(NodeIdentifierWithPredicates.of(myOrderedList, myKeyLeafInOrderedList, "olistkeyvalue1")).withChild(Builders.leafBuilder().withNodeIdentifier(new NodeIdentifier(myLeafInOrderedList1)).withValue("olistleafvalue1").build()).withChild(Builders.leafBuilder().withNodeIdentifier(new NodeIdentifier(myLeafInOrderedList2)).withValue("olistleafvalue2").build()).build()).withChild(Builders.mapEntryBuilder().withNodeIdentifier(NodeIdentifierWithPredicates.of(myOrderedList, myKeyLeafInOrderedList, "olistkeyvalue2")).withChild(Builders.leafBuilder().withNodeIdentifier(new NodeIdentifier(myLeafInOrderedList1)).withValue("olistleafvalue12").build()).withChild(Builders.leafBuilder().withNodeIdentifier(new NodeIdentifier(myLeafInOrderedList2)).withValue("olistleafvalue22").build()).build()).build();
    final UnkeyedListEntryNode unkeyedListEntry = Builders.unkeyedListEntryBuilder().withNodeIdentifier(new NodeIdentifier(myLeafInUnkeyedList)).withChild(ImmutableNodes.leafNode(myLeafInUnkeyedList, "foo")).build();
    final List<UnkeyedListEntryNode> unkeyedListEntries = new ArrayList<>();
    unkeyedListEntries.add(unkeyedListEntry);
    UnkeyedListNode myUnkeyedListNode = Builders.unkeyedListBuilder().withNodeIdentifier(new NodeIdentifier(myUnkeyedList)).withValue(unkeyedListEntries).build();
    LeafNode<?> myLeaf1Node = Builders.leafBuilder().withNodeIdentifier(new NodeIdentifier(myLeaf1)).withValue("value1").build();
    LeafSetNode<?> myLeafListNode = Builders.leafSetBuilder().withNodeIdentifier(new NodeIdentifier(myLeafList)).withChild(Builders.leafSetEntryBuilder().withNodeIdentifier(new NodeWithValue<>(myLeafList, "lflvalue1")).withValue("lflvalue1").build()).withChild(Builders.leafSetEntryBuilder().withNodeIdentifier(new NodeWithValue<>(myLeafList, "lflvalue2")).withValue("lflvalue2").build()).build();
    LeafSetNode<?> myOrderedLeafListNode = Builders.orderedLeafSetBuilder().withNodeIdentifier(new NodeIdentifier(myOrderedLeafList)).withChild(Builders.leafSetEntryBuilder().withNodeIdentifier(new NodeWithValue<>(myOrderedLeafList, "olflvalue1")).withValue("olflvalue1").build()).withChild(Builders.leafSetEntryBuilder().withNodeIdentifier(new NodeWithValue<>(myOrderedLeafList, "olflvalue2")).withValue("olflvalue2").build()).build();
    ContainerNode myContainer1Node = Builders.containerBuilder().withNodeIdentifier(new NodeIdentifier(myContainer1)).withChild(myKeyedListNode).withChild(myOrderedListNode).withChild(myUnkeyedListNode).withChild(myLeaf1Node).withChild(myLeafListNode).withChild(myOrderedLeafListNode).build();
    // my-container-2
    ContainerNode innerContainerNode = Builders.containerBuilder().withNodeIdentifier(new NodeIdentifier(innerContainer)).withChild(Builders.leafBuilder().withNodeIdentifier(new NodeIdentifier(myLeaf2)).withValue("value2").build()).build();
    LeafNode<?> myLeaf3Node = Builders.leafBuilder().withNodeIdentifier(new NodeIdentifier(myLeaf3)).withValue("value3").build();
    ChoiceNode myChoiceNode = Builders.choiceBuilder().withNodeIdentifier(new NodeIdentifier(myChoice)).withChild(Builders.leafBuilder().withNodeIdentifier(new NodeIdentifier(myLeafInCase2)).withValue("case2value").build()).build();
    DOMSourceAnyxmlNode myAnyxmlNode = Builders.anyXmlBuilder().withNodeIdentifier(new NodeIdentifier(myAnyxml)).withValue(anyxmlDomSource).build();
    ContainerNode myContainer2Node = Builders.containerBuilder().withNodeIdentifier(new NodeIdentifier(myContainer2)).withChild(innerContainerNode).withChild(myLeaf3Node).withChild(myChoiceNode).withChild(myAnyxmlNode).build();
    // my-container-3
    Map<QName, Object> keys = new HashMap<>();
    keys.put(myFirstKeyLeaf, "listkeyvalue1");
    keys.put(mySecondKeyLeaf, "listkeyvalue2");
    MapNode myDoublyKeyedListNode = Builders.mapBuilder().withNodeIdentifier(new NodeIdentifier(myDoublyKeyedList)).withChild(Builders.mapEntryBuilder().withNodeIdentifier(NodeIdentifierWithPredicates.of(myDoublyKeyedList, keys)).withChild(Builders.leafBuilder().withNodeIdentifier(new NodeIdentifier(myLeafInList3)).withValue("listleafvalue1").build()).build()).build();
    AugmentationNode myDoublyKeyedListAugNode = Builders.augmentationBuilder().withNodeIdentifier(new AugmentationIdentifier(ImmutableSet.of(myDoublyKeyedList))).withChild(myDoublyKeyedListNode).build();
    ContainerNode myContainer3Node = Builders.containerBuilder().withNodeIdentifier(new NodeIdentifier(myContainer3)).withChild(myDoublyKeyedListAugNode).build();
    AugmentationNode myContainer3AugNode = Builders.augmentationBuilder().withNodeIdentifier(new AugmentationIdentifier(ImmutableSet.of(myContainer3))).withChild(myContainer3Node).build();
    ContainerNode outerContainerNode = Builders.containerBuilder().withNodeIdentifier(new NodeIdentifier(outerContainer)).withChild(myContainer1Node).withChild(myContainer2Node).withChild(myContainer3AugNode).build();
    return outerContainerNode;
}
Also used : AugmentationIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.AugmentationIdentifier) SystemMapNode(org.opendaylight.yangtools.yang.data.api.schema.SystemMapNode) DOMSourceAnyxmlNode(org.opendaylight.yangtools.yang.data.api.schema.DOMSourceAnyxmlNode) HashMap(java.util.HashMap) QName(org.opendaylight.yangtools.yang.common.QName) ArrayList(java.util.ArrayList) UnkeyedListEntryNode(org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListEntryNode) MapNode(org.opendaylight.yangtools.yang.data.api.schema.MapNode) SystemMapNode(org.opendaylight.yangtools.yang.data.api.schema.SystemMapNode) UserMapNode(org.opendaylight.yangtools.yang.data.api.schema.UserMapNode) NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) ChoiceNode(org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode) NodeWithValue(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeWithValue) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) UserMapNode(org.opendaylight.yangtools.yang.data.api.schema.UserMapNode) AugmentationNode(org.opendaylight.yangtools.yang.data.api.schema.AugmentationNode) UnkeyedListNode(org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListNode)

Aggregations

SystemMapNode (org.opendaylight.yangtools.yang.data.api.schema.SystemMapNode)34 NodeIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier)23 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)21 MapEntryNode (org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode)21 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)12 Test (org.junit.Test)11 DataTreeModification (org.opendaylight.yangtools.yang.data.tree.api.DataTreeModification)9 MapNode (org.opendaylight.yangtools.yang.data.api.schema.MapNode)8 UserMapNode (org.opendaylight.yangtools.yang.data.api.schema.UserMapNode)8 DataSchemaNode (org.opendaylight.yangtools.yang.model.api.DataSchemaNode)8 NodeIdentifierWithPredicates (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates)7 ListSchemaNode (org.opendaylight.yangtools.yang.model.api.ListSchemaNode)7 LeafNode (org.opendaylight.yangtools.yang.data.api.schema.LeafNode)6 DataTreeCandidate (org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidate)6 CollectionNodeBuilder (org.opendaylight.yangtools.yang.data.api.schema.builder.CollectionNodeBuilder)5 DataTree (org.opendaylight.yangtools.yang.data.tree.api.DataTree)5 QName (org.opendaylight.yangtools.yang.common.QName)4 DataContainerChild (org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild)4 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)4 LeafListSchemaNode (org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode)4