HONEYCOMB-116: utility for stubbing jvpp methods
[honeycomb.git] / v3po / v3po2vpp / src / test / java / io / fd / honeycomb / translate / v3po / interfacesstate / InterfaceCustomizerTest.java
index b6ef0ec..acc407b 100644 (file)
@@ -18,18 +18,19 @@ package io.fd.honeycomb.translate.v3po.interfacesstate;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.fail;
+import static org.mockito.Matchers.any;
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.verifyZeroInteractions;
+import static org.mockito.Mockito.when;
 
 import io.fd.honeycomb.translate.spi.read.ReaderCustomizer;
 import io.fd.honeycomb.translate.v3po.DisabledInterfacesManager;
 import io.fd.honeycomb.translate.v3po.test.ContextTestUtils;
-import io.fd.honeycomb.translate.v3po.test.InterfaceTestUtils;
-import io.fd.honeycomb.vpp.test.read.ListReaderCustomizerTest;
 import io.fd.honeycomb.translate.v3po.util.NamingContext;
+import io.fd.honeycomb.vpp.test.read.ListReaderCustomizerTest;
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.List;
@@ -44,6 +45,7 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.openvpp.jvpp.VppInvocationException;
 import org.openvpp.jvpp.core.dto.SwInterfaceDetails;
+import org.openvpp.jvpp.core.dto.SwInterfaceDetailsReplyDump;
 import org.openvpp.jvpp.core.dto.SwInterfaceDump;
 
 public class InterfaceCustomizerTest extends
@@ -86,6 +88,12 @@ public class InterfaceCustomizerTest extends
         verify(builder).setInterface(value);
     }
 
+    public void whenSwInterfaceDumpThenReturn(final List<SwInterfaceDetails> interfaceList) {
+        final SwInterfaceDetailsReplyDump reply = new SwInterfaceDetailsReplyDump();
+        reply.swInterfaceDetails = interfaceList;
+        when(api.swInterfaceDump(any(SwInterfaceDump.class))).thenReturn(future(reply));
+    }
+
     private void verifySwInterfaceDumpWasInvoked(final int nameFilterValid, final String ifaceName,
                                                  final int dumpIfcsInvocationCount)
         throws VppInvocationException {
@@ -114,7 +122,7 @@ public class InterfaceCustomizerTest extends
         iface.l2AddressLength = 6;
         iface.l2Address = new byte[iface.l2AddressLength];
         final List<SwInterfaceDetails> interfaceList = Collections.singletonList(iface);
-        InterfaceTestUtils.whenSwInterfaceDumpThenReturn(api, interfaceList);
+        whenSwInterfaceDumpThenReturn(interfaceList);
 
         getCustomizer().readCurrentAttributes(id, builder, ctx);
 
@@ -129,7 +137,7 @@ public class InterfaceCustomizerTest extends
             .child(Interface.class, new InterfaceKey(ifaceName));
         final InterfaceBuilder builder = getCustomizer().getBuilder(id);
 
-        InterfaceTestUtils.whenSwInterfaceDumpThenReturn(api, Collections.emptyList());
+        whenSwInterfaceDumpThenReturn(Collections.emptyList());
 
         try {
             getCustomizer().readCurrentAttributes(id, builder, ctx);
@@ -153,7 +161,7 @@ public class InterfaceCustomizerTest extends
         iface.supSwIfIndex = 1;
         iface.subId = 1;
         final List<SwInterfaceDetails> interfaceList = Collections.singletonList(iface);
-        InterfaceTestUtils.whenSwInterfaceDumpThenReturn(api, interfaceList);
+        whenSwInterfaceDumpThenReturn(interfaceList);
 
         getCustomizer().readCurrentAttributes(id, builder, ctx);
 
@@ -177,7 +185,7 @@ public class InterfaceCustomizerTest extends
         swSubIf1.subId = 1;
         swSubIf1.supSwIfIndex = 1;
         swSubIf1.interfaceName = SUB_IFACE_NAME.getBytes();
-        InterfaceTestUtils.whenSwInterfaceDumpThenReturn(api, Arrays.asList(swIf0, swIf1, swSubIf1));
+        whenSwInterfaceDumpThenReturn(Arrays.asList(swIf0, swIf1, swSubIf1));
 
         final List<InterfaceKey> expectedIds = Arrays.asList(new InterfaceKey(IFACE0_NAME), new InterfaceKey(
             IFACE1_NAME));
@@ -202,7 +210,7 @@ public class InterfaceCustomizerTest extends
         final SwInterfaceDetails swIf1 = new SwInterfaceDetails();
         swIf1.swIfIndex = 1;
         swIf1.interfaceName = IFACE1_NAME.getBytes();
-        InterfaceTestUtils.whenSwInterfaceDumpThenReturn(api, Arrays.asList(swIf0, swIf1));
+        whenSwInterfaceDumpThenReturn(Arrays.asList(swIf0, swIf1));
 
         final List<InterfaceKey> expectedIds = Arrays.asList(new InterfaceKey(IFACE0_NAME));
         final List<InterfaceKey> actualIds = getCustomizer().getAllIds(id, ctx);