Search in sources :

Example 26 with TopLevelList

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.two.level.list.TopLevelList in project mdsal by opendaylight.

the class ListInsertionDataChangeListenerTest method mergeTopNodeSubtreeListeners.

@Test
public void mergeTopNodeSubtreeListeners() {
    final TopLevelList topBar = topLevelList(TOP_BAR_KEY);
    final TopLevelList topFoo = topLevelList(TOP_FOO_KEY);
    final TestListener<Top> topListener = createListener(CONFIGURATION, TOP, added(TOP, top(topLevelList(TOP_FOO_KEY))), topSubtreeModified(topFoo, topBar));
    final TestListener<TopLevelList> allListener = createListener(CONFIGURATION, WILDCARDED, added(TOP_FOO, topFoo), added(TOP_BAR, topBar));
    final TestListener<TopLevelList> fooListener = createListener(CONFIGURATION, TOP_FOO, added(TOP_FOO, topFoo));
    final TestListener<TopLevelList> barListener = createListener(CONFIGURATION, TOP_BAR, added(TOP_BAR, topBar));
    ReadWriteTransaction writeTx = getDataBroker().newReadWriteTransaction();
    writeTx.merge(CONFIGURATION, TOP, top(topLevelList(TOP_BAR_KEY)));
    assertCommit(writeTx.commit());
    topListener.verify();
    allListener.verify();
    fooListener.verify();
    barListener.verify();
}
Also used : Top(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.Top) TopLevelList(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.two.level.list.TopLevelList) ReadWriteTransaction(org.opendaylight.mdsal.binding.api.ReadWriteTransaction) AbstractDataTreeChangeListenerTest(org.opendaylight.mdsal.binding.dom.adapter.test.AbstractDataTreeChangeListenerTest) Test(org.junit.Test)

Example 27 with TopLevelList

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.two.level.list.TopLevelList in project mdsal by opendaylight.

the class ListInsertionDataChangeListenerTest method topSubtreeModified.

private static Function<DataTreeModification<Top>, Boolean> topSubtreeModified(final TopLevelList topFoo, final TopLevelList topBar) {
    return match(ModificationType.SUBTREE_MODIFIED, TOP, (Function<Top, Boolean>) dataBefore -> Objects.equals(top(topFoo), dataBefore), dataAfter -> {
        Set<TopLevelList> expList = new HashSet<>(top(topBar, topFoo).getTopLevelList().values());
        Set<TopLevelList> actualList = dataAfter.getTopLevelList().values().stream().map(list -> new TopLevelListBuilder(list).build()).collect(Collectors.toSet());
        return expList.equals(actualList);
    });
}
Also used : AbstractDataTreeChangeListenerTest(org.opendaylight.mdsal.binding.dom.adapter.test.AbstractDataTreeChangeListenerTest) ImmutableSet(com.google.common.collect.ImmutableSet) ReadWriteTransaction(org.opendaylight.mdsal.binding.api.ReadWriteTransaction) ListsBindingUtils.top(org.opendaylight.mdsal.binding.test.model.util.ListsBindingUtils.top) ListsBindingUtils.topLevelList(org.opendaylight.mdsal.binding.test.model.util.ListsBindingUtils.topLevelList) CONFIGURATION(org.opendaylight.mdsal.common.api.LogicalDatastoreType.CONFIGURATION) WriteTransaction(org.opendaylight.mdsal.binding.api.WriteTransaction) BindingReflections(org.opendaylight.mdsal.binding.spec.reflect.BindingReflections) Set(java.util.Set) Test(org.junit.Test) Top(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.Top) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) TopLevelListBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.two.level.list.TopLevelListBuilder) HashSet(java.util.HashSet) Objects(java.util.Objects) YangModuleInfo(org.opendaylight.yangtools.yang.binding.YangModuleInfo) TopLevelList(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.two.level.list.TopLevelList) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) DataTreeModification(org.opendaylight.mdsal.binding.api.DataTreeModification) TOP_FOO_KEY(org.opendaylight.mdsal.binding.test.model.util.ListsBindingUtils.TOP_FOO_KEY) TOP_BAR_KEY(org.opendaylight.mdsal.binding.test.model.util.ListsBindingUtils.TOP_BAR_KEY) ModificationType(org.opendaylight.mdsal.binding.api.DataObjectModification.ModificationType) Before(org.junit.Before) TopLevelListBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.two.level.list.TopLevelListBuilder) Top(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.Top) TopLevelList(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.two.level.list.TopLevelList) HashSet(java.util.HashSet)

Example 28 with TopLevelList

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.two.level.list.TopLevelList in project mdsal by opendaylight.

the class Mdsal108Test method testDelete.

@Test
public void testDelete() {
    DataBroker dataBroker = getDataBroker();
    WriteTransaction writeTransaction = dataBroker.newWriteOnlyTransaction();
    final TopLevelList item = new TopLevelListBuilder().setName("name").build();
    TopBuilder builder = new TopBuilder().setTopLevelList(Collections.singletonMap(item.key(), item));
    writeTransaction.put(LogicalDatastoreType.OPERATIONAL, InstanceIdentifier.create(Top.class), builder.build());
    assertCommit(writeTransaction.commit());
    InstanceIdentifier<TopLevelList> id = InstanceIdentifier.builder(Top.class).child(TopLevelList.class, new TopLevelListKey("name")).build();
    ReadWriteTransaction writeTransaction1 = dataBroker.newReadWriteTransaction();
    writeTransaction1.delete(LogicalDatastoreType.OPERATIONAL, id);
    assertCommit(writeTransaction1.commit());
    ReadWriteTransaction writeTransaction2 = dataBroker.newReadWriteTransaction();
    writeTransaction2.delete(LogicalDatastoreType.OPERATIONAL, id);
    assertCommit(writeTransaction2.commit());
}
Also used : ReadWriteTransaction(org.opendaylight.mdsal.binding.api.ReadWriteTransaction) WriteTransaction(org.opendaylight.mdsal.binding.api.WriteTransaction) TopLevelListBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.two.level.list.TopLevelListBuilder) TopBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.TopBuilder) Top(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.Top) TopLevelList(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.two.level.list.TopLevelList) ReadWriteTransaction(org.opendaylight.mdsal.binding.api.ReadWriteTransaction) DataBroker(org.opendaylight.mdsal.binding.api.DataBroker) TopLevelListKey(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.two.level.list.TopLevelListKey) Test(org.junit.Test) AbstractDataBrokerTest(org.opendaylight.mdsal.binding.dom.adapter.test.AbstractDataBrokerTest)

Example 29 with TopLevelList

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.two.level.list.TopLevelList in project mdsal by opendaylight.

the class NormalizedNodeSerializeDeserializeTest method orderedLisToNormalized.

@Test
public void orderedLisToNormalized() {
    final TopLevelList topLevelList = new TopLevelListBuilder().withKey(TOP_LEVEL_LIST_FOO_KEY).setNestedList(List.of(new NestedListBuilder().withKey(new NestedListKey("foo")).build(), new NestedListBuilder().withKey(new NestedListKey("bar")).build())).build();
    final Entry<YangInstanceIdentifier, NormalizedNode> entry = codecContext.toNormalizedNode(BA_TOP_LEVEL_LIST, topLevelList);
    final MapEntryNode foo = mapEntryBuilder().withNodeIdentifier(NodeIdentifierWithPredicates.of(TOP_LEVEL_LIST_QNAME, TOP_LEVEL_LIST_KEY_QNAME, TOP_LEVEL_LIST_FOO_KEY_VALUE)).withChild(leafNode(TOP_LEVEL_LIST_KEY_QNAME, TOP_LEVEL_LIST_FOO_KEY_VALUE)).withChild(ImmutableUserMapNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(NESTED_LIST_QNAME)).withChild(mapEntry(NESTED_LIST_QNAME, NESTED_LIST_KEY_QNAME, "foo")).withChild(mapEntry(NESTED_LIST_QNAME, NESTED_LIST_KEY_QNAME, "bar")).build()).build();
    assertEquals(foo, entry.getValue());
}
Also used : TopLevelListBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.two.level.list.TopLevelListBuilder) NestedListKey(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.two.level.list.top.level.list.NestedListKey) TopLevelList(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.two.level.list.TopLevelList) NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) MapEntryNode(org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode) NestedListBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.two.level.list.top.level.list.NestedListBuilder) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) Test(org.junit.Test)

Example 30 with TopLevelList

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.two.level.list.TopLevelList in project mdsal by opendaylight.

the class LazyBindingListTest method testLazyList.

@Test
public void testLazyList() {
    final List<NestedList> nested = new ArrayList<>();
    for (int i = 0; i < 2 * LazyBindingList.LAZY_CUTOFF; ++i) {
        nested.add(new NestedListBuilder().setName(String.valueOf(i)).build());
    }
    final TopLevelList expected = new TopLevelListBuilder().setName("test").setNestedList(nested).build();
    final TopLevelList actual = thereAndBackAgain(InstanceIdentifier.create(Top.class).child(TopLevelList.class, expected.key()), expected);
    final List<NestedList> list = actual.getNestedList();
    assertThat(list, instanceOf(LazyBindingList.class));
    // Equality does all the right things to check happy paths
    assertEquals(expected.getNestedList(), list);
    assertEquals(expected.getNestedList().hashCode(), list.hashCode());
    // Make sure the list performs proper caching
    assertSame(list.get(LazyBindingList.LAZY_CUTOFF), list.get(LazyBindingList.LAZY_CUTOFF));
    // Test throws, just for completeness' sake
    assertThrows(UnsupportedOperationException.class, () -> list.add(null));
    assertThrows(UnsupportedOperationException.class, () -> list.addAll(null));
    assertThrows(UnsupportedOperationException.class, () -> list.addAll(0, null));
    assertThrows(UnsupportedOperationException.class, () -> list.remove(null));
    assertThrows(UnsupportedOperationException.class, () -> list.removeAll(null));
    assertThrows(UnsupportedOperationException.class, () -> list.replaceAll(null));
    assertThrows(UnsupportedOperationException.class, () -> list.retainAll(null));
    assertThrows(UnsupportedOperationException.class, () -> list.sort(null));
    assertThrows(UnsupportedOperationException.class, () -> list.clear());
}
Also used : TopLevelListBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.two.level.list.TopLevelListBuilder) TopLevelList(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.two.level.list.TopLevelList) ArrayList(java.util.ArrayList) NestedList(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.two.level.list.top.level.list.NestedList) NestedListBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.two.level.list.top.level.list.NestedListBuilder) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)61 TopLevelList (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.two.level.list.TopLevelList)32 DataBroker (org.opendaylight.mdsal.binding.api.DataBroker)26 Assert.assertEquals (org.junit.Assert.assertEquals)23 LogicalDatastoreType (org.opendaylight.mdsal.common.api.LogicalDatastoreType)23 InstanceIdentifier (org.opendaylight.yangtools.yang.binding.InstanceIdentifier)22 OptimisticLockFailedException (org.opendaylight.mdsal.common.api.OptimisticLockFailedException)21 TopLevelList (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.two.level.list.TopLevelList)20 WriteTransaction (org.opendaylight.mdsal.binding.api.WriteTransaction)18 DataObject (org.opendaylight.yangtools.yang.binding.DataObject)14 ManagedNewTransactionRunner (org.opendaylight.genius.infra.ManagedNewTransactionRunner)13 ExecutionException (java.util.concurrent.ExecutionException)12 Assert.assertThrows (org.junit.Assert.assertThrows)12 WriteTransaction (org.opendaylight.controller.md.sal.binding.api.WriteTransaction)12 Before (org.junit.Before)11 AbstractDataTreeChangeListenerTest (org.opendaylight.mdsal.binding.dom.adapter.test.AbstractDataTreeChangeListenerTest)11 TopLevelListKey (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.two.level.list.TopLevelListKey)11 IOException (java.io.IOException)10 OPERATIONAL (org.opendaylight.mdsal.binding.util.Datastore.OPERATIONAL)10 TreeComplexUsesAugmentBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.augment.rev140709.TreeComplexUsesAugmentBuilder)10