Search in sources :

Example 1 with ContainerBuilder

use of org.opendaylight.yang.gen.v1.urn.test.opendaylight.mdsal298.rev180129.ContainerBuilder in project mdsal by opendaylight.

the class Mdsal298Test method testKeyedDataTreeModification.

@Test
public void testKeyedDataTreeModification() throws InterruptedException, ExecutionException {
    final DataTreeChangeListener<Container> listener = assertWrittenContainer(Container.QNAME, Container.class, new ContainerBuilder().build());
    final DOMDataTreeWriteTransaction domTx = getDomBroker().newWriteOnlyTransaction();
    domTx.put(CONFIGURATION, YangInstanceIdentifier.create(CONTAINER_NID).node(Keyed.QNAME), Builders.orderedMapBuilder().withNodeIdentifier(new NodeIdentifier(Keyed.QNAME)).addChild(Builders.mapEntryBuilder().withNodeIdentifier(NodeIdentifierWithPredicates.of(Keyed.QNAME, FOO_QNAME, "foo")).addChild(ImmutableNodes.leafNode(FOO_QNAME, "foo")).build()).addChild(Builders.mapEntryBuilder().withNodeIdentifier(NodeIdentifierWithPredicates.of(Keyed.QNAME, FOO_QNAME, "bar")).addChild(ImmutableNodes.leafNode(FOO_QNAME, "bar")).build()).build());
    domTx.commit().get();
    final ArgumentCaptor<Collection> captor = ArgumentCaptor.forClass(Collection.class);
    verify(listener).onDataTreeChanged(captor.capture());
    Collection<DataTreeModification<Container>> capture = captor.getValue();
    assertEquals(1, capture.size());
    final DataTreeModification<Container> change = capture.iterator().next();
    assertEquals(CONTAINER_TID, change.getRootPath());
    final DataObjectModification<Container> changedContainer = change.getRootNode();
    assertEquals(Item.of(Container.class), changedContainer.getIdentifier());
    assertEquals(ModificationType.SUBTREE_MODIFIED, changedContainer.getModificationType());
    final Container containerAfter = changedContainer.getDataAfter();
    assertEquals(new ContainerBuilder().setKeyed(List.of(new KeyedBuilder().setFoo("foo").withKey(new KeyedKey("foo")).build(), new KeyedBuilder().setFoo("bar").withKey(new KeyedKey("bar")).build())).build(), containerAfter);
    final Collection<? extends DataObjectModification<?>> changedChildren = changedContainer.getModifiedChildren();
    assertEquals(2, changedChildren.size());
    final Iterator<? extends DataObjectModification<?>> it = changedChildren.iterator();
    final DataObjectModification<?> changedChild1 = it.next();
    assertEquals(ModificationType.WRITE, changedChild1.getModificationType());
    assertEquals(List.of(), changedChild1.getModifiedChildren());
    final Keyed child1After = (Keyed) changedChild1.getDataAfter();
    assertEquals("foo", child1After.getFoo());
    final DataObjectModification<?> changedChild2 = it.next();
    assertEquals(ModificationType.WRITE, changedChild2.getModificationType());
    assertEquals(List.of(), changedChild2.getModifiedChildren());
    final Keyed child2After = (Keyed) changedChild2.getDataAfter();
    assertEquals("bar", child2After.getFoo());
}
Also used : DataTreeModification(org.opendaylight.mdsal.binding.api.DataTreeModification) KeyedKey(org.opendaylight.yang.gen.v1.urn.test.opendaylight.mdsal298.rev180129.container.KeyedKey) DOMDataTreeWriteTransaction(org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction) Keyed(org.opendaylight.yang.gen.v1.urn.test.opendaylight.mdsal298.rev180129.container.Keyed) Container(org.opendaylight.yang.gen.v1.urn.test.opendaylight.mdsal298.rev180129.Container) ContainerBuilder(org.opendaylight.yang.gen.v1.urn.test.opendaylight.mdsal298.rev180129.ContainerBuilder) KeyedBuilder(org.opendaylight.yang.gen.v1.urn.test.opendaylight.mdsal298.rev180129.container.KeyedBuilder) NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) Collection(java.util.Collection) AbstractDataBrokerTest(org.opendaylight.mdsal.binding.dom.adapter.test.AbstractDataBrokerTest) Test(org.junit.Test)

Example 2 with ContainerBuilder

use of org.opendaylight.yang.gen.v1.urn.test.opendaylight.mdsal298.rev180129.ContainerBuilder in project mdsal by opendaylight.

the class TestListSquashing method testUserOrderedList.

@Test
public void testUserOrderedList() {
    final Keyed keyed = new KeyedBuilder().withKey(new KeyedKey("a")).build();
    final Unkeyed unkeyed = new UnkeyedBuilder().build();
    final Container cont = new ContainerBuilder().setKeyed(List.of(keyed)).setUnkeyed(List.of(unkeyed)).build();
    // Non-empty Lists should be retained
    assertEquals(List.of(keyed), cont.getKeyed());
    assertEquals(List.of(unkeyed), cont.getUnkeyed());
}
Also used : Container(org.opendaylight.yang.gen.v1.urn.test.opendaylight.mdsal298.rev180129.Container) KeyedBuilder(org.opendaylight.yang.gen.v1.urn.test.opendaylight.mdsal298.rev180129.container.KeyedBuilder) ContainerBuilder(org.opendaylight.yang.gen.v1.urn.test.opendaylight.mdsal298.rev180129.ContainerBuilder) KeyedKey(org.opendaylight.yang.gen.v1.urn.test.opendaylight.mdsal298.rev180129.container.KeyedKey) UnkeyedBuilder(org.opendaylight.yang.gen.v1.urn.test.opendaylight.mdsal298.rev180129.container.UnkeyedBuilder) Keyed(org.opendaylight.yang.gen.v1.urn.test.opendaylight.mdsal298.rev180129.container.Keyed) Unkeyed(org.opendaylight.yang.gen.v1.urn.test.opendaylight.mdsal298.rev180129.container.Unkeyed) Test(org.junit.Test)

Example 3 with ContainerBuilder

use of org.opendaylight.yang.gen.v1.urn.test.opendaylight.mdsal298.rev180129.ContainerBuilder in project mdsal by opendaylight.

the class NormalizedNodeSerializeDeserializeTest method augmentMultipleChoices.

@Test
public void augmentMultipleChoices() {
    final QName augmentChoice1QName = AugmentChoice1.QNAME;
    final QName augmentChoice2QName = QName.create(augmentChoice1QName, "augment-choice2");
    final QName containerQName = QName.create(augmentChoice1QName, "case11-choice-case-container");
    final QName leafQName = QName.create(augmentChoice1QName, "case11-choice-case-leaf");
    final AugmentationIdentifier aug1Id = new AugmentationIdentifier(Set.of(augmentChoice1QName));
    final AugmentationIdentifier aug2Id = new AugmentationIdentifier(Set.of(augmentChoice2QName));
    final NodeIdentifier augmentChoice1Id = new NodeIdentifier(augmentChoice1QName);
    final NodeIdentifier augmentChoice2Id = new NodeIdentifier(augmentChoice2QName);
    final NodeIdentifier containerId = new NodeIdentifier(containerQName);
    final TopBuilder tBuilder = new TopBuilder();
    final TopChoiceAugment1Builder tca1Builder = new TopChoiceAugment1Builder();
    final Case1Builder c1Builder = new Case1Builder();
    final TopChoiceAugment2Builder tca2Builder = new TopChoiceAugment2Builder();
    final Case11Builder c11Builder = new Case11Builder();
    final Case11ChoiceCaseContainerBuilder cccc1Builder = new Case11ChoiceCaseContainerBuilder();
    cccc1Builder.setCase11ChoiceCaseLeaf("leaf-value");
    c11Builder.setCase11ChoiceCaseContainer(cccc1Builder.build());
    tca2Builder.setAugmentChoice2(c11Builder.build());
    c1Builder.addAugmentation(tca2Builder.build());
    tca1Builder.setAugmentChoice1(c1Builder.build());
    tBuilder.addAugmentation(tca1Builder.build());
    final Top top = tBuilder.build();
    final Entry<YangInstanceIdentifier, NormalizedNode> biResult = codecContext.toNormalizedNode(InstanceIdentifier.create(Top.class), top);
    final NormalizedNode topNormalized = containerBuilder().withNodeIdentifier(new NodeIdentifier(TOP_QNAME)).withChild(augmentationBuilder().withNodeIdentifier(aug1Id).withChild(choiceBuilder().withNodeIdentifier(augmentChoice1Id).withChild(augmentationBuilder().withNodeIdentifier(aug2Id).withChild(choiceBuilder().withNodeIdentifier(augmentChoice2Id).withChild(containerBuilder().withNodeIdentifier(containerId).withChild(leafNode(leafQName, "leaf-value")).build()).build()).build()).build()).build()).build();
    assertEquals(BI_TOP_PATH, biResult.getKey());
    assertEquals(topNormalized, biResult.getValue());
    final Entry<InstanceIdentifier<?>, DataObject> baResult = codecContext.fromNormalizedNode(BI_TOP_PATH, topNormalized);
    assertEquals(InstanceIdentifier.create(Top.class), baResult.getKey());
    assertEquals(top, baResult.getValue());
}
Also used : AugmentationIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.AugmentationIdentifier) TopBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.TopBuilder) Case1Builder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.augment.rev140709.top.choice.augment1.augment.choice1.Case1Builder) QName(org.opendaylight.yangtools.yang.common.QName) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) DataObject(org.opendaylight.yangtools.yang.binding.DataObject) Case11Builder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.augment.rev140709.top.choice.augment2.augment.choice2.Case11Builder) Top(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.Top) TopChoiceAugment1Builder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.augment.rev140709.TopChoiceAugment1Builder) TopChoiceAugment2Builder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.augment.rev140709.TopChoiceAugment2Builder) NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) Case11ChoiceCaseContainerBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.augment.rev140709.top.choice.augment2.augment.choice2.case11.Case11ChoiceCaseContainerBuilder) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) Test(org.junit.Test)

Example 4 with ContainerBuilder

use of org.opendaylight.yang.gen.v1.urn.test.opendaylight.mdsal298.rev180129.ContainerBuilder in project mdsal by opendaylight.

the class Mdsal298Test method testUnkeyedDataTreeModification.

@Test
public void testUnkeyedDataTreeModification() throws InterruptedException, ExecutionException {
    final DataTreeChangeListener<Container> listener = assertWrittenContainer(Container.QNAME, Container.class, new ContainerBuilder().build());
    final DOMDataTreeWriteTransaction domTx = getDomBroker().newWriteOnlyTransaction();
    domTx.put(CONFIGURATION, YangInstanceIdentifier.create(CONTAINER_NID).node(Unkeyed.QNAME), Builders.unkeyedListBuilder().withNodeIdentifier(new NodeIdentifier(Unkeyed.QNAME)).withChild(Builders.unkeyedListEntryBuilder().withNodeIdentifier(new NodeIdentifier(Unkeyed.QNAME)).addChild(ImmutableNodes.leafNode(FOO_QNAME, "foo")).build()).withChild(Builders.unkeyedListEntryBuilder().withNodeIdentifier(new NodeIdentifier(Unkeyed.QNAME)).addChild(ImmutableNodes.leafNode(FOO_QNAME, "bar")).build()).build());
    domTx.commit().get();
    final ArgumentCaptor<Collection> captor = ArgumentCaptor.forClass(Collection.class);
    verify(listener).onDataTreeChanged(captor.capture());
    Collection<DataTreeModification<Container>> capture = captor.getValue();
    assertEquals(1, capture.size());
    final DataTreeModification<Container> change = capture.iterator().next();
    assertEquals(CONTAINER_TID, change.getRootPath());
    final DataObjectModification<Container> changedContainer = change.getRootNode();
    assertEquals(Item.of(Container.class), changedContainer.getIdentifier());
    assertEquals(ModificationType.WRITE, changedContainer.getModificationType());
    final Container containerAfter = changedContainer.getDataAfter();
    assertEquals(new ContainerBuilder().setUnkeyed(List.of(new UnkeyedBuilder().setFoo("foo").build(), new UnkeyedBuilder().setFoo("bar").build())).build(), containerAfter);
    final Collection<? extends DataObjectModification<?>> changedChildren = changedContainer.getModifiedChildren();
    assertEquals(0, changedChildren.size());
}
Also used : DataTreeModification(org.opendaylight.mdsal.binding.api.DataTreeModification) UnkeyedBuilder(org.opendaylight.yang.gen.v1.urn.test.opendaylight.mdsal298.rev180129.container.UnkeyedBuilder) DOMDataTreeWriteTransaction(org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction) Container(org.opendaylight.yang.gen.v1.urn.test.opendaylight.mdsal298.rev180129.Container) ContainerBuilder(org.opendaylight.yang.gen.v1.urn.test.opendaylight.mdsal298.rev180129.ContainerBuilder) NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) Collection(java.util.Collection) AbstractDataBrokerTest(org.opendaylight.mdsal.binding.dom.adapter.test.AbstractDataBrokerTest) Test(org.junit.Test)

Example 5 with ContainerBuilder

use of org.opendaylight.yang.gen.v1.urn.test.opendaylight.mdsal298.rev180129.ContainerBuilder in project mdsal by opendaylight.

the class TestListSquashing method testEmptyUserOrderedList.

@Test
public void testEmptyUserOrderedList() {
    final Container cont = new ContainerBuilder().setKeyed(List.of()).setUnkeyed(List.of()).build();
    // Empty Lists should become null
    assertNull(cont.getKeyed());
    assertNull(cont.getUnkeyed());
}
Also used : Container(org.opendaylight.yang.gen.v1.urn.test.opendaylight.mdsal298.rev180129.Container) ContainerBuilder(org.opendaylight.yang.gen.v1.urn.test.opendaylight.mdsal298.rev180129.ContainerBuilder) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)5 Container (org.opendaylight.yang.gen.v1.urn.test.opendaylight.mdsal298.rev180129.Container)4 ContainerBuilder (org.opendaylight.yang.gen.v1.urn.test.opendaylight.mdsal298.rev180129.ContainerBuilder)4 NodeIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier)3 Collection (java.util.Collection)2 DataTreeModification (org.opendaylight.mdsal.binding.api.DataTreeModification)2 AbstractDataBrokerTest (org.opendaylight.mdsal.binding.dom.adapter.test.AbstractDataBrokerTest)2 DOMDataTreeWriteTransaction (org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction)2 Keyed (org.opendaylight.yang.gen.v1.urn.test.opendaylight.mdsal298.rev180129.container.Keyed)2 KeyedBuilder (org.opendaylight.yang.gen.v1.urn.test.opendaylight.mdsal298.rev180129.container.KeyedBuilder)2 KeyedKey (org.opendaylight.yang.gen.v1.urn.test.opendaylight.mdsal298.rev180129.container.KeyedKey)2 UnkeyedBuilder (org.opendaylight.yang.gen.v1.urn.test.opendaylight.mdsal298.rev180129.container.UnkeyedBuilder)2 TopChoiceAugment1Builder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.augment.rev140709.TopChoiceAugment1Builder)1 TopChoiceAugment2Builder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.augment.rev140709.TopChoiceAugment2Builder)1 Case1Builder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.augment.rev140709.top.choice.augment1.augment.choice1.Case1Builder)1 Case11Builder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.augment.rev140709.top.choice.augment2.augment.choice2.Case11Builder)1 Case11ChoiceCaseContainerBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.augment.rev140709.top.choice.augment2.augment.choice2.case11.Case11ChoiceCaseContainerBuilder)1 Top (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.Top)1 TopBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.TopBuilder)1 Unkeyed (org.opendaylight.yang.gen.v1.urn.test.opendaylight.mdsal298.rev180129.container.Unkeyed)1