summaryrefslogtreecommitdiffstats
path: root/vpp-common/vpp-translate-test
diff options
context:
space:
mode:
authorMarek Gradzki <mgradzki@cisco.com>2016-09-26 08:20:34 +0200
committerMarek Gradzki <mgradzki@cisco.com>2016-09-26 08:20:34 +0200
commita7e61b5d5abc604df214cd268b8443138717e9af (patch)
tree5ccd62bd6afb5cc95198a45d6323c7c426b3e38f /vpp-common/vpp-translate-test
parentd3e26e08584c1ec07344a43479bf6b46b83a9dfe (diff)
HONEYCOMB-116: generic merge test for reader customizers
Change-Id: I5c2505e6b3bcf622312f8dc324912507f6519a5b Signed-off-by: Marek Gradzki <mgradzki@cisco.com>
Diffstat (limited to 'vpp-common/vpp-translate-test')
-rw-r--r--vpp-common/vpp-translate-test/src/main/java/io/fd/honeycomb/vpp/test/read/ListReaderCustomizerTest.java24
-rw-r--r--vpp-common/vpp-translate-test/src/main/java/io/fd/honeycomb/vpp/test/read/ReaderCustomizerTest.java21
2 files changed, 34 insertions, 11 deletions
diff --git a/vpp-common/vpp-translate-test/src/main/java/io/fd/honeycomb/vpp/test/read/ListReaderCustomizerTest.java b/vpp-common/vpp-translate-test/src/main/java/io/fd/honeycomb/vpp/test/read/ListReaderCustomizerTest.java
index 0509ef9e5..8917c02db 100644
--- a/vpp-common/vpp-translate-test/src/main/java/io/fd/honeycomb/vpp/test/read/ListReaderCustomizerTest.java
+++ b/vpp-common/vpp-translate-test/src/main/java/io/fd/honeycomb/vpp/test/read/ListReaderCustomizerTest.java
@@ -16,15 +16,16 @@
package io.fd.honeycomb.vpp.test.read;
-import static org.junit.Assert.assertNotNull;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
import io.fd.honeycomb.translate.spi.read.ListReaderCustomizer;
-import org.junit.Test;
+import java.lang.reflect.Method;
+import java.util.List;
import org.opendaylight.yangtools.concepts.Builder;
import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.binding.Identifiable;
import org.opendaylight.yangtools.yang.binding.Identifier;
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
/**
* Generic test for classes implementing {@link ListReaderCustomizer} interface.
@@ -36,8 +37,10 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
public abstract class ListReaderCustomizerTest<D extends DataObject & Identifiable<K>, K extends Identifier<D>, B extends Builder<D>> extends
ReaderCustomizerTest<D, B> {
- protected ListReaderCustomizerTest(Class<D> dataObjectClass) {
- super(dataObjectClass);
+ protected ListReaderCustomizerTest(
+ final Class<D> dataObjectClass,
+ final Class<? extends Builder<? extends DataObject>> parentBuilderClass) {
+ super(dataObjectClass, parentBuilderClass);
}
@Override
@@ -45,8 +48,13 @@ public abstract class ListReaderCustomizerTest<D extends DataObject & Identifiab
return ListReaderCustomizer.class.cast(super.getCustomizer());
}
- @Test
- public void testGetBuilder() throws Exception {
- assertNotNull(getCustomizer().getBuilder(InstanceIdentifier.create(dataObjectClass)));
+ @Override
+ public void testMerge() throws Exception {
+ final Builder<? extends DataObject> parentBuilder = mock(parentBuilderClass);
+ final List<D> value = (List<D>) mock(List.class);
+ getCustomizer().merge(parentBuilder, value);
+
+ final Method method = parentBuilderClass.getMethod("set" + dataObjectClass.getSimpleName(), List.class);
+ method.invoke(verify(parentBuilder), value);
}
}
diff --git a/vpp-common/vpp-translate-test/src/main/java/io/fd/honeycomb/vpp/test/read/ReaderCustomizerTest.java b/vpp-common/vpp-translate-test/src/main/java/io/fd/honeycomb/vpp/test/read/ReaderCustomizerTest.java
index 6486c8eb9..22dc2b6fd 100644
--- a/vpp-common/vpp-translate-test/src/main/java/io/fd/honeycomb/vpp/test/read/ReaderCustomizerTest.java
+++ b/vpp-common/vpp-translate-test/src/main/java/io/fd/honeycomb/vpp/test/read/ReaderCustomizerTest.java
@@ -17,6 +17,8 @@
package io.fd.honeycomb.vpp.test.read;
import static org.junit.Assert.assertNotNull;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
import io.fd.honeycomb.translate.MappingContext;
import io.fd.honeycomb.translate.ModificationCache;
@@ -26,6 +28,7 @@ import io.fd.honeycomb.translate.read.ReadContext;
import io.fd.honeycomb.translate.spi.read.ReaderCustomizer;
import io.fd.honeycomb.vpp.test.util.FutureProducer;
import io.fd.honeycomb.vpp.test.util.NamingContextHelper;
+import java.lang.reflect.Method;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
@@ -52,12 +55,16 @@ public abstract class ReaderCustomizerTest<D extends DataObject, B extends Build
@Mock
protected MappingContext mappingContext;
- protected ModificationCache cache;
+ protected final Class<? extends Builder<? extends DataObject>> parentBuilderClass;
protected final Class<D> dataObjectClass;
+ protected ModificationCache cache;
protected ReaderCustomizer<D, B> customizer;
- protected ReaderCustomizerTest(Class<D> dataObjectClass) {
+ public ReaderCustomizerTest(
+ final Class<D> dataObjectClass,
+ final Class<? extends Builder<? extends DataObject>> parentBuilderClass) {
this.dataObjectClass = dataObjectClass;
+ this.parentBuilderClass = parentBuilderClass;
}
@Before
@@ -87,5 +94,13 @@ public abstract class ReaderCustomizerTest<D extends DataObject, B extends Build
assertNotNull(customizer.getBuilder(InstanceIdentifier.create(dataObjectClass)));
}
- // TODO HONEYCOMB-116: create generic testMerge()
+ @Test
+ public void testMerge() throws Exception {
+ final Builder<? extends DataObject> parentBuilder = mock(parentBuilderClass);
+ final D value = mock(dataObjectClass);
+ getCustomizer().merge(parentBuilder, value);
+
+ final Method method = parentBuilderClass.getMethod("set" + dataObjectClass.getSimpleName(), dataObjectClass);
+ method.invoke(verify(parentBuilder), value);
+ }
}