use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.two.level.list.top.level.list.NestedListBuilder 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());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.two.level.list.top.level.list.NestedListBuilder 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());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.two.level.list.top.level.list.NestedListBuilder in project mdsal by opendaylight.
the class NormalizedNodeSerializeDeserializeTest method orderedLisFromNormalized.
@Test
public void orderedLisFromNormalized() {
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();
final Entry<InstanceIdentifier<?>, DataObject> entry = codecContext.fromNormalizedNode(BI_TOP_LEVEL_LIST_FOO_PATH, foo);
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();
assertEquals(topLevelList, entry.getValue());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.two.level.list.top.level.list.NestedListBuilder 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);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.two.level.list.top.level.list.NestedListBuilder in project mdsal by opendaylight.
the class LazyBindingMapTest method testLookupValue.
@Test
public void testLookupValue() {
final Map<TopLevelListKey, TopLevelList> list = prepareData().getTopLevelList();
for (TopLevelList val : TOP.getTopLevelList().values()) {
assertTrue(list.containsValue(val));
}
assertFalse(list.containsValue(new TopLevelListBuilder().setName("blah").build()));
// We checked this key, but this is a different object
assertFalse(list.containsValue(new TopLevelListBuilder(TOP.getTopLevelList().values().iterator().next()).setNestedList(List.of(new NestedListBuilder().setName("foo").build())).build()));
}
Aggregations