Search in sources :

Example 1 with NestedList

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.two.level.list.top.level.list.NestedList 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)

Example 2 with NestedList

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

the class LazyBindingListTest method testSingletonList.

@Test
public void testSingletonList() {
    final TopLevelList expected = new TopLevelListBuilder().setName("test").setNestedList(List.of(new NestedListBuilder().setName(String.valueOf("one")).build())).build();
    final TopLevelList actual = thereAndBackAgain(InstanceIdentifier.create(Top.class).child(TopLevelList.class, expected.key()), expected);
    final List<NestedList> list = actual.getNestedList();
    assertThat(list, not(instanceOf(LazyBindingList.class)));
    assertEquals(expected.getNestedList(), list);
}
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) 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)

Example 3 with NestedList

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

the class QueryBuilderTest method bar.

@Test
public void bar() {
    final Stopwatch sw = Stopwatch.createStarted();
    final QueryExpression<TopLevelList> query = factory.querySubtree(InstanceIdentifier.create(Top.class)).extractChild(TopLevelList.class).matching().childObject(NestedList.class).leaf(NestedList::getName).contains("foo").and().leaf(TopLevelList::getName).valueEquals("bar").build();
    LOG.info("Query built in {}", sw);
    assertEquals(0, execute(query).getItems().size());
}
Also used : TopLevelList(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.two.level.list.TopLevelList) Stopwatch(com.google.common.base.Stopwatch) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)3 TopLevelList (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.two.level.list.TopLevelList)3 TopLevelListBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.two.level.list.TopLevelListBuilder)2 NestedList (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.two.level.list.top.level.list.NestedList)2 NestedListBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.two.level.list.top.level.list.NestedListBuilder)2 Stopwatch (com.google.common.base.Stopwatch)1 ArrayList (java.util.ArrayList)1