diff options
author | Maros Marsalek <mmarsale@cisco.com> | 2016-04-12 10:12:58 +0200 |
---|---|---|
committer | Maros Marsalek <mmarsale@cisco.com> | 2016-04-12 10:12:58 +0200 |
commit | 9ac68bac54d95b0342cab52bf39a4321f1f42d79 (patch) | |
tree | 33f9b1ec3b58bba22c5280583e51d12f9b7b4943 /v3po/impl/src/test | |
parent | cc86c2244707ea980f63ad859ee4eb33d861a511 (diff) |
HONEYCOMB-9: Simplify reader APIs, remove list of DataObjects
Change-Id: I0cb3f20ef4595b0143dcc7e0ad5475f121a9cc86
Signed-off-by: Maros Marsalek <mmarsale@cisco.com>
Diffstat (limited to 'v3po/impl/src/test')
3 files changed, 42 insertions, 53 deletions
diff --git a/v3po/impl/src/test/java/io/fd/honeycomb/v3po/impl/data/VppOperationalDataTreeTest.java b/v3po/impl/src/test/java/io/fd/honeycomb/v3po/impl/data/VppOperationalDataTreeTest.java index 62ddf5ca0..f4b2faa3e 100644 --- a/v3po/impl/src/test/java/io/fd/honeycomb/v3po/impl/data/VppOperationalDataTreeTest.java +++ b/v3po/impl/src/test/java/io/fd/honeycomb/v3po/impl/data/VppOperationalDataTreeTest.java @@ -28,7 +28,6 @@ import static org.mockito.MockitoAnnotations.initMocks; import com.google.common.base.Optional; import com.google.common.util.concurrent.CheckedFuture; import io.fd.honeycomb.v3po.impl.trans.r.ReaderRegistry; -import java.util.Collections; import java.util.Map; import org.junit.Before; import org.junit.Test; @@ -79,7 +78,7 @@ public class VppOperationalDataTreeTest { doReturn(id).when(serializer).fromYangInstanceIdentifier(yangId); final DataObject dataObject = mock(DataObject.class); - doReturn(Collections.singletonList(dataObject)).when(reader).read(id); + doReturn(Optional.of(dataObject)).when(reader).read(id); when(serializer.toNormalizedNode(id, dataObject)).thenReturn(entry); final DataContainerChild<?, ?> expectedValue = mock(DataContainerChild.class); diff --git a/v3po/impl/src/test/java/io/fd/honeycomb/v3po/impl/vppstate/VppStateTest.java b/v3po/impl/src/test/java/io/fd/honeycomb/v3po/impl/vppstate/VppStateTest.java index cdb3024d8..f44ca52c8 100644 --- a/v3po/impl/src/test/java/io/fd/honeycomb/v3po/impl/vppstate/VppStateTest.java +++ b/v3po/impl/src/test/java/io/fd/honeycomb/v3po/impl/vppstate/VppStateTest.java @@ -17,13 +17,16 @@ package io.fd.honeycomb.v3po.impl.vppstate; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.mockito.Matchers.anyString; +import com.google.common.base.Optional; import com.google.common.base.Predicate; import com.google.common.collect.Iterables; import com.google.common.collect.Multimap; import io.fd.honeycomb.v3po.impl.trans.r.VppReader; +import io.fd.honeycomb.v3po.impl.trans.r.impl.CompositeListVppReader; import io.fd.honeycomb.v3po.impl.trans.r.impl.CompositeRootVppReader; import io.fd.honeycomb.v3po.impl.trans.r.util.DelegatingReaderRegistry; import java.util.Collections; @@ -42,6 +45,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.state.Version; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.state.VersionBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.state.bridge.domains.BridgeDomain; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.state.bridge.domains.BridgeDomainBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.state.bridge.domains.BridgeDomainKey; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.state.bridge.domains.bridge.domain.L2Fib; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.state.bridge.domains.bridge.domain.L2FibKey; @@ -162,20 +166,19 @@ public class VppStateTest { @Test public void testReadSpecific() throws Exception { - final List<? extends DataObject> read = readerRegistry.read(InstanceIdentifier.create(VppState.class)); - assertEquals(read.size(), 1); - assertVersion((VppState) read.get(0)); + final Optional<? extends DataObject> read = readerRegistry.read(InstanceIdentifier.create(VppState.class)); + assertTrue(read.isPresent()); + assertVersion((VppState) read.get()); } @Test public void testReadBridgeDomains() throws Exception { - VppState readRoot = (VppState) readerRegistry.read(InstanceIdentifier.create(VppState.class)).get(0); + VppState readRoot = (VppState) readerRegistry.read(InstanceIdentifier.create(VppState.class)).get(); - List<? extends DataObject> read = + Optional<? extends DataObject> read = readerRegistry.read(InstanceIdentifier.create(VppState.class).child(BridgeDomains.class)); -// System.err.println(read); - assertEquals(read.size(), 1); - assertEquals(readRoot.getBridgeDomains(), read.get(0)); + assertTrue(read.isPresent()); + assertEquals(readRoot.getBridgeDomains(), read.get()); } /** @@ -184,86 +187,68 @@ public class VppStateTest { @Test public void testReadL2Fib() throws Exception { // Deep child without a dedicated reader with specific l2fib key - List<? extends DataObject> read = + Optional<? extends DataObject> read = readerRegistry.read(InstanceIdentifier.create(VppState.class).child(BridgeDomains.class).child( BridgeDomain.class, new BridgeDomainKey("bdn1")) .child(L2Fib.class, new L2FibKey(new PhysAddress("01:02:03:04:05:06")))); -// System.err.println(read); - assertEquals(read.size(), 1); + assertTrue(read.isPresent()); // non existing l2fib read = readerRegistry.read(InstanceIdentifier.create(VppState.class).child(BridgeDomains.class).child( BridgeDomain.class, new BridgeDomainKey("bdn1")) .child(L2Fib.class, new L2FibKey(new PhysAddress("FF:FF:FF:04:05:06")))); -// System.err.println(read); - assertEquals(read.size(), 0); - } - - /** - * L2fib does not have a dedicated reader, relying on auto filtering - */ - @Test - public void testReadL2FibAll() throws Exception { - // Deep child without a dedicated reader - final InstanceIdentifier<L2Fib> id = InstanceIdentifier.create(VppState.class).child(BridgeDomains.class).child( - BridgeDomain.class, new BridgeDomainKey("bdn1")).child(L2Fib.class); - final List<? extends DataObject> read = readerRegistry.read(id); -// System.err.println(read); - assertEquals(read.toString(), read.size(), 2); - - // test if direct read returns the same value - final List<? extends DataObject> read2 = vppStateReader.read(id); -// System.err.println(read); - assertEquals(read, read2); + assertFalse(read.isPresent()); } @Test public void testReadBridgeDomainAll() throws Exception { - VppState readRoot = (VppState) readerRegistry.read(InstanceIdentifier.create(VppState.class)).get(0); + VppState readRoot = (VppState) readerRegistry.read(InstanceIdentifier.create(VppState.class)).get(); - final List<? extends DataObject> read = - readerRegistry.read(InstanceIdentifier.create(VppState.class).child(BridgeDomains.class).child( + final CompositeListVppReader<BridgeDomain, BridgeDomainKey, BridgeDomainBuilder> bridgeDomainReader = + VppStateUtils.getBridgeDomainReader(api); + + final List<BridgeDomain> read = + bridgeDomainReader.readList(InstanceIdentifier.create(VppState.class).child(BridgeDomains.class).child( BridgeDomain.class)); -// System.err.println(read); - assertEquals(read.size(), 2); + assertEquals(readRoot.getBridgeDomains().getBridgeDomain(), read); } @Test public void testReadBridgeDomain() throws Exception { - VppState readRoot = (VppState) readerRegistry.read(InstanceIdentifier.create(VppState.class)).get(0); + VppState readRoot = (VppState) readerRegistry.read(InstanceIdentifier.create(VppState.class)).get(); - final List<? extends DataObject> read = + final Optional<? extends DataObject> read = readerRegistry.read(InstanceIdentifier.create(VppState.class).child(BridgeDomains.class).child( BridgeDomain.class, new BridgeDomainKey("bdn1"))); - assertEquals(read.size(), 1); + assertTrue(read.isPresent()); assertEquals(Iterables.find(readRoot.getBridgeDomains().getBridgeDomain(), new Predicate<BridgeDomain>() { @Override public boolean apply(final BridgeDomain input) { return input.getKey().getName().equals("bdn1"); } - }), read.get(0)); + }), read.get()); } + // FIXME @Ignore("Bridge domain customizer does not check whether the bd exists or not and fails with NPE, add it there") @Test public void testReadBridgeDomainNotExisting() throws Exception { - final List<? extends DataObject> read = + final Optional<? extends DataObject> read = readerRegistry.read(InstanceIdentifier.create(VppState.class).child(BridgeDomains.class).child( BridgeDomain.class, new BridgeDomainKey("NOT EXISTING"))); - assertEquals(read.size(), 0); + assertFalse(read.isPresent()); } @Test public void testReadVersion() throws Exception { - VppState readRoot = (VppState) readerRegistry.read(InstanceIdentifier.create(VppState.class)).get(0); + VppState readRoot = (VppState) readerRegistry.read(InstanceIdentifier.create(VppState.class)).get(); - List<? extends DataObject> read = + Optional<? extends DataObject> read = readerRegistry.read(InstanceIdentifier.create(VppState.class).child(Version.class)); -// System.err.println(read); - assertEquals(read.size(), 1); - assertEquals(readRoot.getVersion(), read.get(0)); + assertTrue(read.isPresent()); + assertEquals(readRoot.getVersion(), read.get()); } }
\ No newline at end of file diff --git a/v3po/impl/src/test/java/io/fd/honeycomb/v3po/impl/vppstate/VppStateUtils.java b/v3po/impl/src/test/java/io/fd/honeycomb/v3po/impl/vppstate/VppStateUtils.java index e700d2e1f..73113174c 100644 --- a/v3po/impl/src/test/java/io/fd/honeycomb/v3po/impl/vppstate/VppStateUtils.java +++ b/v3po/impl/src/test/java/io/fd/honeycomb/v3po/impl/vppstate/VppStateUtils.java @@ -49,10 +49,8 @@ final class VppStateUtils { final ChildVppReader<Version> versionReader = new CompositeChildVppReader<>( Version.class, new VersionCustomizer(vppApi)); - final CompositeListVppReader<BridgeDomain, BridgeDomainKey, BridgeDomainBuilder> - bridgeDomainReader = new CompositeListVppReader<>( - BridgeDomain.class, - new BridgeDomainCustomizer(vppApi)); + final CompositeListVppReader<BridgeDomain, BridgeDomainKey, BridgeDomainBuilder> bridgeDomainReader = + getBridgeDomainReader(vppApi); final ChildVppReader<BridgeDomains> bridgeDomainsReader = new CompositeChildVppReader<>( BridgeDomains.class, @@ -69,4 +67,11 @@ final class VppStateUtils { VppRWUtils.<VppState>emptyAugReaderList(), new ReflexiveRootReaderCustomizer<>(VppStateBuilder.class)); } + + static CompositeListVppReader<BridgeDomain, BridgeDomainKey, BridgeDomainBuilder> getBridgeDomainReader( + final @Nonnull vppApi vppApi) { + return new CompositeListVppReader<>( + BridgeDomain.class, + new BridgeDomainCustomizer(vppApi)); + } } |