import io.fd.honeycomb.v3po.translate.v3po.util.TranslateUtils;
import io.fd.honeycomb.v3po.translate.write.WriteContext;
import io.fd.honeycomb.v3po.translate.write.WriteFailedException;
+import java.util.List;
+import java.util.concurrent.CompletionStage;
+import javax.annotation.Nonnull;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.Interfaces;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceKey;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import javax.annotation.Nonnull;
-import java.util.List;
-import java.util.concurrent.CompletionStage;
-
/**
* Ietf interface write customizer that only caches interface objects for child writers
*/
import java.util.stream.Collectors;
/**
- * Customizer for reading ietf-interfaces:interfaces-state/interface
+ * Customizer for reading ietf-interfaces:interfaces-state/interface.
*/
public class InterfaceCustomizer extends FutureJVppCustomizer
implements ListReaderCustomizer<Interface, InterfaceKey, InterfaceBuilder> {
private static final Logger LOG = LoggerFactory.getLogger(InterfaceCustomizer.class);
- public static final String DUMPED_IFCS_CONTEXT_KEY = InterfaceCustomizer.class.getName() + "dumpedInterfacesDuringGetAllIds";
+ public static final String DUMPED_IFCS_CONTEXT_KEY =
+ InterfaceCustomizer.class.getName() + "dumpedInterfacesDuringGetAllIds";
private final NamingContext interfaceContext;
// Pass cached details from getAllIds to getDetails to avoid additional dumps
final SwInterfaceDetails iface = InterfaceUtils.getVppInterfaceDetails(getFutureJVpp(), id, key.getName(),
- interfaceContext.getIndex(key.getName(), ctx.getMappingContext()), ctx.getModificationCache());
+ interfaceContext.getIndex(key.getName(), ctx.getMappingContext()), ctx.getModificationCache());
LOG.debug("Interface details for interface: {}, details: {}", key.getName(), iface);
builder.setName(key.getName());
builder.setType(InterfaceUtils.getInterfaceType(new String(iface.interfaceName).intern()));
builder.setIfIndex(InterfaceUtils.vppIfIndexToYang(iface.swIfIndex));
- builder.setAdminStatus(1 == iface.adminUpDown ? AdminStatus.Up : AdminStatus.Down);
- builder.setOperStatus(1 == iface.linkUpDown ? OperStatus.Up : OperStatus.Down);
+ builder.setAdminStatus(1 == iface.adminUpDown
+ ? AdminStatus.Up
+ : AdminStatus.Down);
+ builder.setOperStatus(1 == iface.linkUpDown
+ ? OperStatus.Up
+ : OperStatus.Down);
if (0 != iface.linkSpeed) {
builder.setSpeed(InterfaceUtils.vppInterfaceSpeedToYang(iface.linkSpeed));
}
@Nonnull
@SuppressWarnings("unchecked")
- public static Map<Integer, SwInterfaceDetails> getCachedInterfaceDump(final @Nonnull ModificationCache ctx) {
+ public static Map<Integer, SwInterfaceDetails> getCachedInterfaceDump(@Nonnull final ModificationCache ctx) {
return ctx.get(DUMPED_IFCS_CONTEXT_KEY) == null
- ? new HashMap<>() // allow customizers to update the cache
- : (Map<Integer, SwInterfaceDetails>) ctx.get(DUMPED_IFCS_CONTEXT_KEY);
+ ? new HashMap<>()
+ // allow customizers to update the cache
+ : (Map<Integer, SwInterfaceDetails>) ctx.get(DUMPED_IFCS_CONTEXT_KEY);
}
@Nonnull
final CompletableFuture<SwInterfaceDetailsReplyDump> swInterfaceDetailsReplyDumpCompletableFuture =
getFutureJVpp().swInterfaceDump(request).toCompletableFuture();
- final SwInterfaceDetailsReplyDump ifaces = TranslateUtils.getReply(swInterfaceDetailsReplyDumpCompletableFuture);
+ final SwInterfaceDetailsReplyDump ifaces =
+ TranslateUtils.getReply(swInterfaceDetailsReplyDumpCompletableFuture);
if (null == ifaces || null == ifaces.swInterfaceDetails) {
- LOG.debug("No interfaces found in VPP");
+ LOG.debug("No interfaces for :{} found in VPP", id);
return Collections.emptyList();
}
// Cache interfaces dump in per-tx context to later be used in readCurrentAttributes
context.getModificationCache().put(DUMPED_IFCS_CONTEXT_KEY, ifaces.swInterfaceDetails.stream()
- .collect(Collectors.toMap(t -> t.swIfIndex, swInterfaceDetails -> swInterfaceDetails)));
+ .collect(Collectors.toMap(t -> t.swIfIndex, swInterfaceDetails -> swInterfaceDetails)));
interfacesKeys = ifaces.swInterfaceDetails.stream()
- .filter(elt -> elt != null)
- .map((elt) -> {
- // Store interface name from VPP in context if not yet present
- if (!interfaceContext.containsName(elt.swIfIndex, context.getMappingContext())) {
- interfaceContext.addName(elt.swIfIndex, TranslateUtils.toString(elt.interfaceName), context.getMappingContext());
- }
- LOG.trace("Interface with name: {}, VPP name: {} and index: {} found in VPP",
- interfaceContext.getName(elt.swIfIndex, context.getMappingContext()), elt.interfaceName, elt.swIfIndex);
-
- return new InterfaceKey(interfaceContext.getName(elt.swIfIndex, context.getMappingContext()));
- })
- .collect(Collectors.toList());
+ .filter(elt -> elt != null)
+ .map((elt) -> {
+ // Store interface name from VPP in context if not yet present
+ if (!interfaceContext.containsName(elt.swIfIndex, context.getMappingContext())) {
+ interfaceContext.addName(elt.swIfIndex, TranslateUtils.toString(elt.interfaceName),
+ context.getMappingContext());
+ }
+ LOG.trace("Interface with name: {}, VPP name: {} and index: {} found in VPP",
+ interfaceContext.getName(elt.swIfIndex, context.getMappingContext()), elt.interfaceName,
+ elt.swIfIndex);
+
+ return new InterfaceKey(interfaceContext.getName(elt.swIfIndex, context.getMappingContext()));
+ })
+ .collect(Collectors.toList());
LOG.debug("Interfaces found in VPP: {}", interfacesKeys);
return interfacesKeys;
} catch (VppBaseCallException e) {
- LOG.warn("Unable to get all interface IDs", e);
- throw new ReadFailedException( id, e);
+ LOG.warn("getAllIds for id :{} failed with exception ", id, e);
+ throw new ReadFailedException(id, e);
}
}
@Override
public void merge(@Nonnull final org.opendaylight.yangtools.concepts.Builder<? extends DataObject> builder,
- @Nonnull final List<Interface> readData) {
+ @Nonnull final List<Interface> readData) {
((InterfacesStateBuilder) builder).setInterface(readData);
}
throw new IllegalArgumentException("Unable to find interface " + name);
}
} catch (VppBaseCallException e) {
- LOG.warn("getVppInterfaceDetails exception :", e);
- throw new ReadFailedException(id);
+ LOG.warn("getVppInterfaceDetails for id :{} and name :{} failed with exception :", id, name, e);
+ throw new ReadFailedException(id, e);
}
// SwInterfaceDump's name filter does prefix match, so we need additional filtering:
builder.setTapName(TranslateUtils.toString(swInterfaceTapDetails.devName));
LOG.debug("Tap interface: {}, id: {} attributes read as: {}", key.getName(), index, builder);
} catch (VppBaseCallException e) {
- LOG.warn("Failed to readCurrentAttributes for: {}", id);
- throw new ReadFailedException(id);
+ LOG.warn("Failed to readCurrentAttributes for: {}", id, e);
+ throw new ReadFailedException(id, e);
}
}
}
LOG.debug("Vhost user interface: {}, id: {} attributes read as: {}", key.getName(), index, builder);
} catch (VppBaseCallException e) {
- LOG.warn("Failed to readCurrentAttributes for: {}", id);
- throw new ReadFailedException(id);
+ LOG.warn("Failed to readCurrentAttributes for: {}", id, e);
+ throw new ReadFailedException(id, e);
}
}
}
package io.fd.honeycomb.v3po.translate.v3po.vpp;
+import static com.google.common.base.Preconditions.checkArgument;
+import static com.google.common.base.Preconditions.checkNotNull;
+
import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
import io.fd.honeycomb.v3po.translate.spi.write.ListWriterCustomizer;
import io.fd.honeycomb.v3po.translate.v3po.util.TranslateUtils;
import io.fd.honeycomb.v3po.translate.write.WriteContext;
import io.fd.honeycomb.v3po.translate.write.WriteFailedException;
+import java.util.List;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.BridgeDomains;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.bridge.domains.BridgeDomain;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.bridge.domains.BridgeDomainKey;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import javax.annotation.Nonnull;
-import javax.annotation.Nullable;
-import java.util.List;
-
-import static com.google.common.base.Preconditions.checkArgument;
-import static com.google.common.base.Preconditions.checkNotNull;
-
public class BridgeDomainCustomizer
extends FutureJVppCustomizer
implements ListWriterCustomizer<BridgeDomain, BridgeDomainKey> {
@Override
public void writeCurrentAttributes(@Nonnull final InstanceIdentifier<BridgeDomain> id,
@Nonnull final BridgeDomain dataBefore,
- @Nonnull final WriteContext ctx) throws WriteFailedException.CreateFailedException {
+ @Nonnull final WriteContext ctx)
+ throws WriteFailedException.CreateFailedException {
LOG.debug("writeCurrentAttributes: id={}, current={}, ctx={}", id, dataBefore, ctx);
final String bdName = dataBefore.getName();
try {
- // FIXME we need the bd index to be returned by VPP or we should have a counter field (maybe in context similar to artificial name)
+ // FIXME we need the bd index to be returned by VPP or we should have a counter field
+ // (maybe in context similar to artificial name)
// Here we assign the next available ID from bdContext's perspective
int index = 1;
while(bdContext.containsName(index, ctx.getMappingContext())) {
import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.openvpp.jvpp.VppBaseCallException;
-import org.openvpp.jvpp.VppCallbackException;
-import org.openvpp.jvpp.VppInvocationException;
import org.openvpp.jvpp.dto.ShowVersion;
import org.openvpp.jvpp.dto.ShowVersionReply;
import org.openvpp.jvpp.future.FutureJVpp;
builder.setBuildDate(TranslateUtils.toString(reply.buildDate));
builder.setBuildDirectory(TranslateUtils.toString(reply.buildDirectory));
} catch (VppBaseCallException e) {
- throw new ReadFailedException(id);
+ throw new ReadFailedException(id, e);
}
}
package io.fd.honeycomb.v3po.translate.v3po.interfaces;
+import static io.fd.honeycomb.v3po.translate.v3po.test.ContextTestUtils.getMapping;
+import static junit.framework.TestCase.assertTrue;
+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.verify;
+import static org.mockito.MockitoAnnotations.initMocks;
+
import com.google.common.base.Optional;
import io.fd.honeycomb.v3po.translate.MappingContext;
import io.fd.honeycomb.v3po.translate.v3po.test.TestHelperUtils;
import io.fd.honeycomb.v3po.translate.v3po.util.TagRewriteOperation;
import io.fd.honeycomb.v3po.translate.write.WriteContext;
import io.fd.honeycomb.v3po.translate.write.WriteFailedException;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutionException;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.Interfaces;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceKey;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.*;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.SubinterfaceAugmentation;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527._802dot1q;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev150527.interfaces._interface.SubInterfaces;
import org.openvpp.jvpp.dto.L2InterfaceVlanTagRewriteReply;
import org.openvpp.jvpp.future.FutureJVpp;
-import java.util.concurrent.CompletableFuture;
-import java.util.concurrent.ExecutionException;
-
-import static io.fd.honeycomb.v3po.translate.v3po.test.ContextTestUtils.getMapping;
-import static junit.framework.TestCase.assertTrue;
-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.verify;
-import static org.mockito.MockitoAnnotations.initMocks;
-
public class RewriteCustomizerTest {
@Mock
return builder.build();
}
- private L2InterfaceVlanTagRewrite generateL2InterfaceVlanTagRewrite(final int swIfIndex, final TagRewriteOperation op) {
+ private L2InterfaceVlanTagRewrite generateL2InterfaceVlanTagRewrite(final int swIfIndex,
+ final TagRewriteOperation op) {
final L2InterfaceVlanTagRewrite request = new L2InterfaceVlanTagRewrite();
request.swIfIndex = swIfIndex;
request.vtrOp = op.ordinal();
/**
* Positive response
*/
- private void whenL2InterfaceVlanTagRewriteThen() throws ExecutionException, InterruptedException, VppInvocationException {
+ private void whenL2InterfaceVlanTagRewriteThenSuccess()
+ throws ExecutionException, InterruptedException, VppInvocationException {
final CompletableFuture<L2InterfaceVlanTagRewriteReply> replyFuture = new CompletableFuture<>();
final L2InterfaceVlanTagRewriteReply reply = new L2InterfaceVlanTagRewriteReply();
replyFuture.complete(reply);
/**
* Failure response send
*/
- private void whenL2InterfaceVlanTagRewriteFailedThen(final int retval) throws ExecutionException, InterruptedException, VppInvocationException {
- doReturn(TestHelperUtils.<L2InterfaceVlanTagRewriteReply>createFutureException(retval)).when(api).l2InterfaceVlanTagRewrite(any(L2InterfaceVlanTagRewrite.class));
- }
-
- private void whenL2InterfaceVlanTagRewriteThenSuccess() throws ExecutionException, InterruptedException, VppInvocationException {
- whenL2InterfaceVlanTagRewriteThen();
- }
-
- private void whenL2InterfaceVlanTagRewriteThenFailure() throws ExecutionException, InterruptedException, VppInvocationException {
- whenL2InterfaceVlanTagRewriteFailedThen(-1);
+ private void whenL2InterfaceVlanTagRewriteThenFailure()
+ throws ExecutionException, InterruptedException, VppInvocationException {
+ doReturn(TestHelperUtils.<L2InterfaceVlanTagRewriteReply>createFutureException()).when(api)
+ .l2InterfaceVlanTagRewrite(any(L2InterfaceVlanTagRewrite.class));
}
- private void verifyL2InterfaceVlanTagRewriteWasInvoked(final L2InterfaceVlanTagRewrite expected) throws VppInvocationException {
- ArgumentCaptor<L2InterfaceVlanTagRewrite> argumentCaptor = ArgumentCaptor.forClass(L2InterfaceVlanTagRewrite.class);
+ private void verifyL2InterfaceVlanTagRewriteWasInvoked(final L2InterfaceVlanTagRewrite expected)
+ throws VppInvocationException {
+ ArgumentCaptor<L2InterfaceVlanTagRewrite> argumentCaptor =
+ ArgumentCaptor.forClass(L2InterfaceVlanTagRewrite.class);
verify(api).l2InterfaceVlanTagRewrite(argumentCaptor.capture());
final L2InterfaceVlanTagRewrite actual = argumentCaptor.getValue();
assertEquals(expected.swIfIndex, actual.swIfIndex);
customizer.updateCurrentAttributes(id, before, after, writeContext);
- verifyL2InterfaceVlanTagRewriteWasInvoked(generateL2InterfaceVlanTagRewrite(VLAN_IF_INDEX, TagRewriteOperation.pop_1));
+ verifyL2InterfaceVlanTagRewriteWasInvoked(
+ generateL2InterfaceVlanTagRewrite(VLAN_IF_INDEX, TagRewriteOperation.pop_1));
}
@Test
customizer.updateCurrentAttributes(id, before, after, writeContext);
} catch (WriteFailedException.UpdateFailedException e) {
assertTrue(e.getCause() instanceof VppBaseCallException);
- verifyL2InterfaceVlanTagRewriteWasInvoked(generateL2InterfaceVlanTagRewrite(VLAN_IF_INDEX, TagRewriteOperation.pop_1));
+ verifyL2InterfaceVlanTagRewriteWasInvoked(generateL2InterfaceVlanTagRewrite(VLAN_IF_INDEX,
+ TagRewriteOperation.pop_1));
return;
}
fail("WriteFailedException.UpdateFailedException was expected");
SubinterfaceAugmentation.class).child(SubInterfaces.class).child(SubInterface.class, new SubInterfaceKey(index));
}
- private void whenCreateSubifThen() throws ExecutionException, InterruptedException, VppBaseCallException {
+ private void whenCreateSubifThenSuccess() throws ExecutionException, InterruptedException, VppBaseCallException {
final CompletableFuture<CreateSubifReply> replyFuture = new CompletableFuture<>();
final CreateSubifReply reply = new CreateSubifReply();
replyFuture.complete(reply);
/**
* Failure response send
*/
- private void whenCreateSubifFailedThen(final int retval) throws ExecutionException, InterruptedException, VppBaseCallException {
- doReturn(TestHelperUtils.<CreateSubifReply>createFutureException(retval)).when(api).createSubif(any(CreateSubif.class));
+ private void whenCreateSubifThenFailure() throws ExecutionException, InterruptedException, VppBaseCallException {
+ doReturn(TestHelperUtils.<CreateSubifReply>createFutureException()).when(api).createSubif(any(CreateSubif.class));
}
- private void whenSwInterfaceSetFlagsThen(final int retval) throws ExecutionException, InterruptedException, VppBaseCallException {
+ private void whenSwInterfaceSetFlagsThenSuccess() throws ExecutionException, InterruptedException, VppBaseCallException {
final CompletableFuture<SwInterfaceSetFlagsReply> replyFuture = new CompletableFuture<>();
final SwInterfaceSetFlagsReply reply = new SwInterfaceSetFlagsReply();
replyFuture.complete(reply);
doReturn(replyFuture).when(api).swInterfaceSetFlags(any(SwInterfaceSetFlags.class));
}
- private void whenCreateSubifThenSuccess() throws ExecutionException, InterruptedException, VppBaseCallException {
- whenCreateSubifThen();
- }
-
- private void whenCreateSubifThenFailure() throws ExecutionException, InterruptedException, VppBaseCallException {
- whenCreateSubifFailedThen(-1);
- }
-
- private void whenSwInterfaceSetFlagsThenSuccess() throws ExecutionException, InterruptedException, VppBaseCallException {
- whenSwInterfaceSetFlagsThen(0);
- }
-
private CreateSubif verifyCreateSubifWasInvoked(final CreateSubif expected) throws VppBaseCallException {
ArgumentCaptor<CreateSubif> argumentCaptor = ArgumentCaptor.forClass(CreateSubif.class);
verify(api).createSubif(argumentCaptor.capture());
import static io.fd.honeycomb.v3po.translate.v3po.test.ContextTestUtils.getMapping;
import static io.fd.honeycomb.v3po.translate.v3po.test.ContextTestUtils.getMappingIid;
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.eq;
+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 static org.mockito.MockitoAnnotations.initMocks;
+
import io.fd.honeycomb.v3po.translate.MappingContext;
import io.fd.honeycomb.v3po.translate.ModificationCache;
import io.fd.honeycomb.v3po.translate.v3po.test.TestHelperUtils;
import io.fd.honeycomb.v3po.translate.v3po.util.TranslateUtils;
import io.fd.honeycomb.v3po.translate.write.WriteContext;
import io.fd.honeycomb.v3po.translate.write.WriteFailedException;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.CompletionStage;
+import java.util.concurrent.ExecutionException;
import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.openvpp.jvpp.VppBaseCallException;
import org.openvpp.jvpp.VppInvocationException;
-import org.openvpp.jvpp.dto.*;
+import org.openvpp.jvpp.dto.CreateVhostUserIf;
+import org.openvpp.jvpp.dto.CreateVhostUserIfReply;
+import org.openvpp.jvpp.dto.DeleteVhostUserIf;
+import org.openvpp.jvpp.dto.DeleteVhostUserIfReply;
+import org.openvpp.jvpp.dto.ModifyVhostUserIf;
+import org.openvpp.jvpp.dto.ModifyVhostUserIfReply;
import org.openvpp.jvpp.future.FutureJVpp;
-import java.util.concurrent.CompletableFuture;
-import java.util.concurrent.CompletionStage;
-import java.util.concurrent.ExecutionException;
-
-import static org.junit.Assert.*;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.*;
-import static org.mockito.MockitoAnnotations.initMocks;
-
public class VhostUserCustomizerTest {
@Mock
customizer = new VhostUserCustomizer(api, namingContext);
}
- private void whenCreateVhostUserIfThen() throws ExecutionException, InterruptedException, VppInvocationException {
+ private void whenCreateVhostUserIfThenSuccess()
+ throws ExecutionException, InterruptedException, VppInvocationException {
final CompletionStage<CreateVhostUserIfReply> replyCS = mock(CompletionStage.class);
final CompletableFuture<CreateVhostUserIfReply> replyFuture = mock(CompletableFuture.class);
when(replyCS.toCompletableFuture()).thenReturn(replyFuture);
/**
* Failure response send
*/
- private void whenCreateVhostUserIfFailedThen(final int retval) throws ExecutionException, InterruptedException, VppInvocationException {
- doReturn(TestHelperUtils.<CreateVhostUserIfReply>createFutureException(retval)).when(api).createVhostUserIf(any(CreateVhostUserIf.class));
- }
-
- private void whenCreateVhostUserIfThenSuccess() throws ExecutionException, InterruptedException, VppInvocationException {
- whenCreateVhostUserIfThen();
+ private void whenCreateVhostUserIfThenFailure()
+ throws ExecutionException, InterruptedException, VppInvocationException {
+ doReturn(TestHelperUtils.<CreateVhostUserIfReply>createFutureException()).when(api)
+ .createVhostUserIf(any(CreateVhostUserIf.class));
}
- private void whenVxlanAddDelTunnelThenFailure() throws ExecutionException, InterruptedException, VppInvocationException {
- whenCreateVhostUserIfFailedThen(-1);
- }
-
- private void whenModifyVhostUserIfThen() throws ExecutionException, InterruptedException, VppInvocationException {
+ private void whenModifyVhostUserIfThenSuccess()
+ throws ExecutionException, InterruptedException, VppInvocationException {
final CompletionStage<ModifyVhostUserIfReply> replyCS = mock(CompletionStage.class);
final CompletableFuture<ModifyVhostUserIfReply> replyFuture = mock(CompletableFuture.class);
when(replyCS.toCompletableFuture()).thenReturn(replyFuture);
/**
* Failure response send
*/
- private void whenModifyVhostUserIfFailedThen(final int retval) throws ExecutionException, InterruptedException, VppInvocationException {
- doReturn(TestHelperUtils.<ModifyVhostUserIfReply>createFutureException(retval)).when(api).modifyVhostUserIf(any(ModifyVhostUserIf.class));
- }
-
- private void whenModifyVhostUserIfThenSuccess() throws ExecutionException, InterruptedException, VppInvocationException {
- whenModifyVhostUserIfThen();
+ private void whenModifyVhostUserIfThenFailure()
+ throws ExecutionException, InterruptedException, VppInvocationException {
+ doReturn(TestHelperUtils.<ModifyVhostUserIfReply>createFutureException()).when(api)
+ .modifyVhostUserIf(any(ModifyVhostUserIf.class));
}
- private void whenModifyVhostUserIfThenFailure() throws ExecutionException, InterruptedException, VppInvocationException {
- whenModifyVhostUserIfFailedThen(-1);
- }
-
- private void whenDeleteVhostUserIfThen() throws ExecutionException, InterruptedException, VppInvocationException {
+ private void whenDeleteVhostUserIfThenSuccess()
+ throws ExecutionException, InterruptedException, VppInvocationException {
final CompletionStage<DeleteVhostUserIfReply> replyCS = mock(CompletionStage.class);
final CompletableFuture<DeleteVhostUserIfReply> replyFuture = mock(CompletableFuture.class);
when(replyCS.toCompletableFuture()).thenReturn(replyFuture);
/**
* Failure response send
*/
- private void whenDeleteVhostUserIfFailedThen(final int retval) throws ExecutionException, InterruptedException, VppInvocationException {
- doReturn(TestHelperUtils.<DeleteVhostUserIfReply>createFutureException(retval)).when(api).deleteVhostUserIf(any(DeleteVhostUserIf.class));
- }
-
- private void whenDeleteVhostUserIfThenSuccess() throws ExecutionException, InterruptedException, VppInvocationException {
- whenDeleteVhostUserIfThen();
- }
-
- private void whenDeleteVhostUserIfThenFailure() throws ExecutionException, InterruptedException, VppInvocationException {
- whenDeleteVhostUserIfFailedThen(-1);
+ private void whenDeleteVhostUserIfThenFailure()
+ throws ExecutionException, InterruptedException, VppInvocationException {
+ doReturn(TestHelperUtils.<DeleteVhostUserIfReply>createFutureException()).when(api)
+ .deleteVhostUserIf(any(DeleteVhostUserIf.class));
}
private CreateVhostUserIf verifyCreateVhostUserIfWasInvoked(final VhostUser vhostUser) throws VppInvocationException {
return actual;
}
- private ModifyVhostUserIf verifyModifyVhostUserIfWasInvoked(final VhostUser vhostUser, final int swIfIndex) throws VppInvocationException {
+ private ModifyVhostUserIf verifyModifyVhostUserIfWasInvoked(final VhostUser vhostUser, final int swIfIndex)
+ throws VppInvocationException {
ArgumentCaptor<ModifyVhostUserIf> argumentCaptor = ArgumentCaptor.forClass(ModifyVhostUserIf.class);
verify(api).modifyVhostUserIf(argumentCaptor.capture());
final ModifyVhostUserIf actual = argumentCaptor.getValue();
public void testWriteCurrentAttributesFailed() throws Exception {
final VhostUser vhostUser = generateVhostUser(VhostUserRole.Client, "socketName");
- whenVxlanAddDelTunnelThenFailure();
+ whenCreateVhostUserIfThenFailure();
try {
customizer.writeCurrentAttributes(ID, vhostUser, writeContext);
package io.fd.honeycomb.v3po.translate.v3po.interfaces;
+import static io.fd.honeycomb.v3po.translate.v3po.test.ContextTestUtils.getMapping;
+import static io.fd.honeycomb.v3po.translate.v3po.test.ContextTestUtils.getMappingIid;
+import static java.util.Collections.singletonList;
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.eq;
+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.when;
+import static org.mockito.MockitoAnnotations.initMocks;
+
import com.google.common.base.Optional;
import com.google.common.net.InetAddresses;
import io.fd.honeycomb.v3po.translate.MappingContext;
import io.fd.honeycomb.v3po.translate.v3po.util.NamingContext;
import io.fd.honeycomb.v3po.translate.write.WriteContext;
import io.fd.honeycomb.v3po.translate.write.WriteFailedException;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.CompletionStage;
+import java.util.concurrent.ExecutionException;
import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.openvpp.jvpp.dto.VxlanAddDelTunnelReply;
import org.openvpp.jvpp.future.FutureJVpp;
-import java.util.concurrent.CompletableFuture;
-import java.util.concurrent.CompletionStage;
-import java.util.concurrent.ExecutionException;
-
-import static io.fd.honeycomb.v3po.translate.v3po.test.ContextTestUtils.getMapping;
-import static io.fd.honeycomb.v3po.translate.v3po.test.ContextTestUtils.getMappingIid;
-import static java.util.Collections.singletonList;
-import static org.junit.Assert.*;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.*;
-import static org.mockito.MockitoAnnotations.initMocks;
-
public class VxlanCustomizerTest {
private static final byte ADD_VXLAN = 1;
.augmentation(VppInterfaceAugmentation.class).child(Vxlan.class);
}
- private void whenVxlanAddDelTunnelThen() throws ExecutionException, InterruptedException, VppInvocationException {
+ private void whenVxlanAddDelTunnelThenSuccess() throws ExecutionException, InterruptedException, VppInvocationException {
final CompletionStage<VxlanAddDelTunnelReply> replyCS = mock(CompletionStage.class);
final CompletableFuture<VxlanAddDelTunnelReply> replyFuture = mock(CompletableFuture.class);
when(replyCS.toCompletableFuture()).thenReturn(replyFuture);
/**
* Failure response send
*/
- private void whenVxlanAddDelTunnelFailedThen(final int retval) throws ExecutionException, InterruptedException, VppInvocationException {
- doReturn(TestHelperUtils.<VxlanAddDelTunnelReply>createFutureException(retval)).when(api).vxlanAddDelTunnel(any(VxlanAddDelTunnel.class));
- }
-
- private void whenVxlanAddDelTunnelThenSuccess() throws ExecutionException, InterruptedException, VppInvocationException {
- whenVxlanAddDelTunnelThen();
- }
-
- private void whenVxlanAddDelTunnelThenFailure() throws ExecutionException, InterruptedException, VppInvocationException {
- whenVxlanAddDelTunnelFailedThen(-1);
+ private void whenVxlanAddDelTunnelThenFailure()
+ throws ExecutionException, InterruptedException, VppInvocationException {
+ doReturn(TestHelperUtils.<VxlanAddDelTunnelReply>createFutureException()).when(api)
+ .vxlanAddDelTunnel(any(VxlanAddDelTunnel.class));
}
private VxlanAddDelTunnel verifyVxlanAddDelTunnelWasInvoked(final Vxlan vxlan) throws VppInvocationException {
final VxlanAddDelTunnel actual = argumentCaptor.getValue();
assertEquals(0, actual.isIpv6);
assertEquals(-1, actual.decapNextIndex);
- assertArrayEquals(InetAddresses.forString(vxlan.getSrc().getIpv4Address().getValue()).getAddress(), actual.srcAddress);
- assertArrayEquals(InetAddresses.forString(vxlan.getDst().getIpv4Address().getValue()).getAddress(), actual.dstAddress);
+ assertArrayEquals(InetAddresses.forString(vxlan.getSrc().getIpv4Address().getValue()).getAddress(),
+ actual.srcAddress);
+ assertArrayEquals(InetAddresses.forString(vxlan.getDst().getIpv4Address().getValue()).getAddress(),
+ actual.dstAddress);
assertEquals(vxlan.getEncapVrfId().intValue(), actual.encapVrfId);
assertEquals(vxlan.getVni().getValue().intValue(), actual.vni);
return actual;
}
+
private void verifyVxlanAddWasInvoked(final Vxlan vxlan) throws VppInvocationException {
final VxlanAddDelTunnel actual = verifyVxlanAddDelTunnelWasInvoked(vxlan);
assertEquals(ADD_VXLAN, actual.isAdd);
.augmentation(VppInterfaceAugmentation.class).child(VxlanGpe.class);
}
- private void whenVxlanGpeAddDelTunnelThen() throws ExecutionException, InterruptedException, VppBaseCallException {
+ private void whenVxlanGpeAddDelTunnelThenSuccess()
+ throws ExecutionException, InterruptedException, VppBaseCallException {
final CompletionStage<VxlanGpeAddDelTunnelReply> replyCS = mock(CompletionStage.class);
final CompletableFuture<VxlanGpeAddDelTunnelReply> replyFuture = mock(CompletableFuture.class);
when(replyCS.toCompletableFuture()).thenReturn(replyFuture);
when(api.vxlanGpeAddDelTunnel(any(VxlanGpeAddDelTunnel.class))).thenReturn(replyCS);
}
- private void whenVxlanGpeAddDelTunnelThenSuccess() throws ExecutionException, InterruptedException, VppBaseCallException {
- whenVxlanGpeAddDelTunnelThen();
- }
-
- private void whenVxlanGpeAddDelTunnelThenFailure() throws ExecutionException, InterruptedException, VppBaseCallException {
- whenVxlanGpeAddDelTunnelFailedThen(-1);
- }
-
/**
* Failure response send
*/
- private void whenVxlanGpeAddDelTunnelFailedThen(final int retval) throws ExecutionException, InterruptedException, VppBaseCallException {
- doReturn(TestHelperUtils.<VxlanAddDelTunnelReply>createFutureException(retval)).when(api).vxlanGpeAddDelTunnel(any(VxlanGpeAddDelTunnel.class));
+ private void whenVxlanGpeAddDelTunnelThenFailure()
+ throws ExecutionException, InterruptedException, VppBaseCallException {
+ doReturn(TestHelperUtils.<VxlanAddDelTunnelReply>createFutureException()).when(api)
+ .vxlanGpeAddDelTunnel(any(VxlanGpeAddDelTunnel.class));
}
- private VxlanGpeAddDelTunnel verifyVxlanGpeAddDelTunnelWasInvoked(final VxlanGpe vxlanGpe) throws VppBaseCallException{
+ private VxlanGpeAddDelTunnel verifyVxlanGpeAddDelTunnelWasInvoked(final VxlanGpe vxlanGpe)
+ throws VppBaseCallException {
ArgumentCaptor<VxlanGpeAddDelTunnel> argumentCaptor = ArgumentCaptor.forClass(VxlanGpeAddDelTunnel.class);
verify(api).vxlanGpeAddDelTunnel(argumentCaptor.capture());
final VxlanGpeAddDelTunnel actual = argumentCaptor.getValue();
assertEquals(0, actual.isIpv6);
- assertArrayEquals(InetAddresses.forString(vxlanGpe.getLocal().getIpv4Address().getValue()).getAddress(), actual.local);
- assertArrayEquals(InetAddresses.forString(vxlanGpe.getRemote().getIpv4Address().getValue()).getAddress(), actual.remote);
+ assertArrayEquals(InetAddresses.forString(vxlanGpe.getLocal().getIpv4Address().getValue()).getAddress(),
+ actual.local);
+ assertArrayEquals(InetAddresses.forString(vxlanGpe.getRemote().getIpv4Address().getValue()).getAddress(),
+ actual.remote);
assertEquals(vxlanGpe.getVni().getValue().intValue(), actual.vni);
assertEquals(vxlanGpe.getNextProtocol().getIntValue(), actual.protocol);
assertEquals(vxlanGpe.getEncapVrfId().intValue(), actual.encapVrfId);
assertEquals(vxlanGpe.getDecapVrfId().intValue(), actual.decapVrfId);
return actual;
}
- private void verifyVxlanGpeAddWasInvoked(final VxlanGpe vxlanGpe) throws VppBaseCallException{
+
+ private void verifyVxlanGpeAddWasInvoked(final VxlanGpe vxlanGpe) throws VppBaseCallException {
final VxlanGpeAddDelTunnel actual = verifyVxlanGpeAddDelTunnelWasInvoked(vxlanGpe);
assertEquals(ADD_VXLAN_GPE, actual.isAdd);
}
assertTrue(e.getCause() instanceof VppBaseCallException);
verifyVxlanGpeAddWasInvoked(vxlanGpe);
// Mapping not stored due to failure
- verify(mappingContext, times(0)).put(eq(getMappingIid(ifaceName, "test-instance")), eq(getMapping(ifaceName, 0).get()));
+ verify(mappingContext, times(0))
+ .put(eq(getMappingIid(ifaceName, "test-instance")), eq(getMapping(ifaceName, 0).get()));
return;
}
fail("WriteFailedException.CreateFailedException was expected");
import java.util.concurrent.CompletableFuture;
public class TestHelperUtils {
+ private final static int ERROR_RETVAL = -1;
+
/**
* Static helper method for creation of Exception failure state in CompletableFuture object
- * @param retval result of the operation in exception
+ * with retval = -1
* @return CompletableFuture with VppCallbackException as a cause
*/
- public static CompletableFuture<? extends JVppReply> createFutureException(final int retval) {
+ public static CompletableFuture<? extends JVppReply> createFutureException() {
final CompletableFuture<? extends JVppReply> replyFuture = new CompletableFuture<>();
- replyFuture.completeExceptionally(new VppCallbackException("test-call", 1, retval));
+ replyFuture.completeExceptionally(new VppCallbackException("test-call", 1, ERROR_RETVAL));
return replyFuture;
}
}
import static io.fd.honeycomb.v3po.translate.v3po.test.ContextTestUtils.getMapping;
import static io.fd.honeycomb.v3po.translate.v3po.test.ContextTestUtils.getMappingIid;
+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.never;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+import static org.mockito.MockitoAnnotations.initMocks;
+
import com.google.common.base.Optional;
import io.fd.honeycomb.v3po.translate.MappingContext;
import io.fd.honeycomb.v3po.translate.ModificationCache;
import io.fd.honeycomb.v3po.translate.v3po.util.NamingContext;
import io.fd.honeycomb.v3po.translate.write.WriteContext;
import io.fd.honeycomb.v3po.translate.write.WriteFailedException;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.CompletionStage;
+import java.util.concurrent.ExecutionException;
import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.openvpp.jvpp.dto.BridgeDomainAddDelReply;
import org.openvpp.jvpp.future.FutureJVpp;
-import java.util.concurrent.CompletableFuture;
-import java.util.concurrent.CompletionStage;
-import java.util.concurrent.ExecutionException;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
-import static org.mockito.Matchers.any;
-import static org.mockito.Mockito.*;
-import static org.mockito.MockitoAnnotations.initMocks;
-
public class BridgeDomainCustomizerTest {
private static final byte ADD_OR_UPDATE_BD = (byte) 1;
.build();
}
- private void verifyBridgeDomainAddOrUpdateWasInvoked(final BridgeDomain bd, final int bdId) throws VppInvocationException {
+ private void verifyBridgeDomainAddOrUpdateWasInvoked(final BridgeDomain bd, final int bdId)
+ throws VppInvocationException {
final byte arpTerm = BridgeDomainTestUtils.booleanToByte(bd.isArpTermination());
final byte flood = BridgeDomainTestUtils.booleanToByte(bd.isFlood());
final byte forward = BridgeDomainTestUtils.booleanToByte(bd.isForward());
assertEquals(ZERO, actual.isAdd);
}
- private void whenBridgeDomainAddDelThen() throws ExecutionException, InterruptedException, VppInvocationException {
+ private void whenBridgeDomainAddDelThenSuccess()
+ throws ExecutionException, InterruptedException, VppInvocationException {
final CompletionStage<BridgeDomainAddDelReply> replyCS = mock(CompletionStage.class);
final CompletableFuture<BridgeDomainAddDelReply> replyFuture = mock(CompletableFuture.class);
when(replyCS.toCompletableFuture()).thenReturn(replyFuture);
when(api.bridgeDomainAddDel(any(BridgeDomainAddDel.class))).thenReturn(replyCS);
}
- private void whenBridgeDomainAddDelFailedThen(final int retval) throws ExecutionException, InterruptedException, VppInvocationException {
- doReturn(TestHelperUtils.<BridgeDomainAddDelReply>createFutureException(retval)).when(api).bridgeDomainAddDel(any(BridgeDomainAddDel.class));
- }
-
- private void whenBridgeDomainAddDelThenSuccess() throws ExecutionException, InterruptedException, VppInvocationException {
- whenBridgeDomainAddDelThen();
- }
-
- private void whenBridgeDomainAddDelThenFailure() throws ExecutionException, InterruptedException, VppInvocationException {
- whenBridgeDomainAddDelFailedThen(-1);
+ private void whenBridgeDomainAddDelThenFailure()
+ throws ExecutionException, InterruptedException, VppInvocationException {
+ doReturn(TestHelperUtils.<BridgeDomainAddDelReply>createFutureException()).when(api)
+ .bridgeDomainAddDel(any(BridgeDomainAddDel.class));
}
@Test
final int bdId = 1;
final String bdName = "bd1";
final BridgeDomain bd = generateBridgeDomain(bdName);
- doReturn(Optional.absent()).when(mappingContext).read(getMappingIid(bdName, "test-instance").firstIdentifierOf(Mappings.class));
+ doReturn(Optional.absent()).when(mappingContext)
+ .read(getMappingIid(bdName, "test-instance").firstIdentifierOf(Mappings.class));
whenBridgeDomainAddDelThenSuccess();
final BridgeDomain bd = generateBridgeDomain(bdName);
// Returning no Mappings for "test-instance" makes bdContext.containsName() return false
- doReturn(Optional.absent()).when(mappingContext).read(getMappingIid(bdName, "test-instance").firstIdentifierOf(Mappings.class));
+ doReturn(Optional.absent()).when(mappingContext)
+ .read(getMappingIid(bdName, "test-instance").firstIdentifierOf(Mappings.class));
whenBridgeDomainAddDelThenFailure();
whenBridgeDomainAddDelThenSuccess();
- customizer.updateCurrentAttributes(BridgeDomainTestUtils.bdIdentifierForName(bdName), dataBefore, dataAfter, ctx);
+ customizer
+ .updateCurrentAttributes(BridgeDomainTestUtils.bdIdentifierForName(bdName), dataBefore, dataAfter, ctx);
verifyBridgeDomainAddOrUpdateWasInvoked(dataAfter, bdId);
}
@Test
public void testUpdateUnknownBridgeDomain() throws Exception {
final String bdName = "bd1";
- final BridgeDomain bdBefore = generateBridgeDomain(bdName, 0, 1, 0 ,1, 0);
- final BridgeDomain bdAfter = generateBridgeDomain(bdName, 1, 1, 0 ,1, 0);
+ final BridgeDomain bdBefore = generateBridgeDomain(bdName, 0, 1, 0, 1, 0);
+ final BridgeDomain bdAfter = generateBridgeDomain(bdName, 1, 1, 0, 1, 0);
doReturn(Optional.absent()).when(mappingContext).read(getMappingIid(bdName, "test-instance"));
try {
- customizer.updateCurrentAttributes(BridgeDomainTestUtils.bdIdentifierForName(bdName), bdBefore, bdAfter, ctx);
+ customizer
+ .updateCurrentAttributes(BridgeDomainTestUtils.bdIdentifierForName(bdName), bdBefore, bdAfter, ctx);
} catch (IllegalArgumentException e) {
verify(api, never()).bridgeDomainAddDel(any(BridgeDomainAddDel.class));
return;
whenBridgeDomainAddDelThenFailure();
try {
- customizer.updateCurrentAttributes(BridgeDomainTestUtils.bdIdentifierForName(bdName), bdBefore, bdAfter, ctx);
+ customizer
+ .updateCurrentAttributes(BridgeDomainTestUtils.bdIdentifierForName(bdName), bdBefore, bdAfter, ctx);
} catch (WriteFailedException.UpdateFailedException e) {
verifyBridgeDomainAddOrUpdateWasInvoked(bdAfter, bdId);
return;