From 20f7414d1d07d4627923cc6a6ad31f8e9522558f Mon Sep 17 00:00:00 2001 From: Jozef Gloncak Date: Tue, 22 Sep 2015 15:29:06 +0200 Subject: [PATCH] BUG-4340: raise test coverage to 80% - services related - salFlowService related tests - flowCapableTransaction + packetProcessing related tests - salTableService related test Change-Id: I8215494765c78bb2f3197f3420a41ca76ed23cfc Signed-off-by: Jozef Gloncak --- ...FlowCapableTransactionServiceImplTest.java | 56 +++++++ .../PacketProcessingServiceImplTest.java | 87 ++++++++++ .../impl/services/SalFlowServiceImplTest.java | 31 ++++ .../services/SalTableServiceImplTest.java | 155 ++++++++++++------ .../impl/services/ServiceMocking.java | 52 ++++-- 5 files changed, 310 insertions(+), 71 deletions(-) create mode 100644 openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/FlowCapableTransactionServiceImplTest.java create mode 100644 openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/PacketProcessingServiceImplTest.java diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/FlowCapableTransactionServiceImplTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/FlowCapableTransactionServiceImplTest.java new file mode 100644 index 0000000000..5239335897 --- /dev/null +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/FlowCapableTransactionServiceImplTest.java @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowplugin.impl.services; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.verify; + +import org.junit.Test; +import org.opendaylight.openflowplugin.api.openflow.device.Xid; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev150304.SendBarrierInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev150304.SendBarrierInputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader; + +/** + * Test for {@link FlowCapableTransactionServiceImpl}. + */ +public class FlowCapableTransactionServiceImplTest extends ServiceMocking { + + private static final Long DUMMY_XID_VALUE = 100L; + FlowCapableTransactionServiceImpl flowCapableTransactionService; + + @Override + protected void setup() { + flowCapableTransactionService = new FlowCapableTransactionServiceImpl(mockedRequestContextStack, mockedDeviceContext); + } + + @Test + public void testBuildRequest() throws Exception { + SendBarrierInput sendBarrierInput = buildSendBarrierInput(); + + final OfHeader request = flowCapableTransactionService.buildRequest(new Xid(DUMMY_XID_VALUE), sendBarrierInput); + assertEquals(DUMMY_XID_VALUE, request.getXid()); + assertTrue(request instanceof BarrierInput); + } + + @Test + public void testSendBarrier() throws Exception { + SendBarrierInput sendBarrierInput = buildSendBarrierInput(); + flowCapableTransactionService.sendBarrier(sendBarrierInput); + verify(mockedRequestContextStack).createRequestContext(); + } + + private SendBarrierInput buildSendBarrierInput() { + return new SendBarrierInputBuilder() + .setNode(new NodeRef(mockedDeviceState.getNodeInstanceIdentifier())).build(); + } +} \ No newline at end of file diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/PacketProcessingServiceImplTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/PacketProcessingServiceImplTest.java new file mode 100644 index 0000000000..cad3b6968d --- /dev/null +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/PacketProcessingServiceImplTest.java @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowplugin.impl.services; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.verify; + +import org.junit.Test; +import org.opendaylight.openflowplugin.api.OFConstants; +import org.opendaylight.openflowplugin.api.openflow.device.Xid; +import org.opendaylight.openflowplugin.openflow.md.util.OpenflowPortsUtil; +import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId; +import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorRef; +import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId; +import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef; +import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes; +import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector; +import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnectorKey; +import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node; +import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.OutputActionCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketOutInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.TransmitPacketInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.TransmitPacketInputBuilder; +import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier; + +/** + * Test for {@link PacketProcessingServiceImpl}. + */ +public class PacketProcessingServiceImplTest extends ServiceMocking { + + private static final Long DUMMY_XID_VALUE = 100L; + public static final String ULTIMATE_PAYLOAD = "What do you get when you multiply six by nine?"; + + private PacketProcessingServiceImpl packetProcessingService; + private KeyedInstanceIdentifier pathToNodeconnector; + + @Override + protected void setup() { + packetProcessingService = new PacketProcessingServiceImpl(mockedRequestContextStack, mockedDeviceContext); + pathToNodeconnector = KeyedInstanceIdentifier.create(Nodes.class) + .child(Node.class, new NodeKey(new NodeId("ofp-ut:123"))) + .child(NodeConnector.class, new NodeConnectorKey(new NodeConnectorId("ofp-ut:123:1"))); + OpenflowPortsUtil.init(); + } + + @Test + public void testTransmitPacket() throws Exception { + TransmitPacketInput transmitPacketInput = buildTransmitPacketInput(); + packetProcessingService.transmitPacket(transmitPacketInput); + verify(mockedRequestContextStack).createRequestContext(); + } + + @Test + public void testBuildRequest() throws Exception { + TransmitPacketInput transmitPacketInput = buildTransmitPacketInput(); + + final OfHeader request = packetProcessingService.buildRequest(new Xid(DUMMY_XID_VALUE), transmitPacketInput); + assertEquals(DUMMY_XID_VALUE, request.getXid()); + assertTrue(request instanceof PacketOutInput); + final PacketOutInput input = (PacketOutInput) request; + assertEquals(OFConstants.OFP_NO_BUFFER, input.getBufferId()); + assertEquals(1, input.getAction().size()); + assertEquals(OutputActionCase.class, input.getAction().get(0).getActionChoice().getImplementedInterface()); + + final OutputActionCase actionChoice = (OutputActionCase) input.getAction().get(0).getActionChoice(); + assertEquals(1, actionChoice.getOutputAction().getPort().getValue().intValue()); + assertEquals(ULTIMATE_PAYLOAD, new String(input.getData())); + } + + private TransmitPacketInput buildTransmitPacketInput() { + TransmitPacketInputBuilder transmitPacketInputBld = new TransmitPacketInputBuilder() + .setBufferId(OFConstants.OFP_NO_BUFFER) + .setNode(new NodeRef(mockedDeviceState.getNodeInstanceIdentifier())) + .setPayload(ULTIMATE_PAYLOAD.getBytes()) + .setEgress(new NodeConnectorRef(pathToNodeconnector)); + return transmitPacketInputBld.build(); + } +} \ No newline at end of file diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/SalFlowServiceImplTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/SalFlowServiceImplTest.java index d77aa5cd80..76c7ac43ce 100644 --- a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/SalFlowServiceImplTest.java +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/SalFlowServiceImplTest.java @@ -4,6 +4,7 @@ package org.opendaylight.openflowplugin.impl.services; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; +import com.google.common.util.concurrent.Futures; import java.math.BigInteger; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; @@ -36,7 +37,9 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.ta import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowKey; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlowInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlowOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.flow.update.OriginalFlow; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.flow.update.UpdatedFlow; @@ -123,6 +126,34 @@ public class SalFlowServiceImplTest extends TestCase { addFlow(null); } + @Test + public void testAddFlowFailCallback() throws Exception { + AddFlowInput mockedAddFlowInput = createFlowMock(AddFlowInput.class); + Mockito.doReturn(Futures.>immediateFailedFuture(new Exception("ut-failed-response"))) + .when(requestContext).getFuture(); + + final Future> rpcResultFuture = salFlowService.addFlow(mockedAddFlowInput); + + assertNotNull(rpcResultFuture); + final RpcResult addFlowOutputRpcResult = rpcResultFuture.get(); + assertNotNull(addFlowOutputRpcResult); + assertFalse(addFlowOutputRpcResult.isSuccessful()); + } + + @Test + public void testRemoveFlowFailCallback() throws Exception { + RemoveFlowInput mockedRemoveFlowInput = createFlowMock(RemoveFlowInput.class); + Mockito.doReturn(Futures.>immediateFailedFuture(new Exception("ut-failed-response"))) + .when(requestContext).getFuture(); + + final Future> rpcResultFuture = salFlowService.removeFlow(mockedRemoveFlowInput); + + assertNotNull(rpcResultFuture); + final RpcResult removeFlowOutputRpcResult = rpcResultFuture.get(); + assertNotNull(removeFlowOutputRpcResult); + assertFalse(removeFlowOutputRpcResult.isSuccessful()); + } + @Test public void testAddFlowWithItemLifecycle() throws Exception { addFlow(mock(ItemLifecycleListener.class)); diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/SalTableServiceImplTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/SalTableServiceImplTest.java index faeaa73707..188cb7816d 100644 --- a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/SalTableServiceImplTest.java +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/SalTableServiceImplTest.java @@ -1,84 +1,133 @@ package org.opendaylight.openflowplugin.impl.services; -import junit.framework.TestCase; -import org.junit.Before; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import com.google.common.util.concurrent.FutureCallback; +import com.google.common.util.concurrent.SettableFuture; +import java.math.BigInteger; +import java.util.Collections; +import java.util.List; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.Future; +import org.junit.Assert; import org.junit.Test; -import org.junit.runner.RunWith; +import org.mockito.Matchers; import org.mockito.Mock; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.Mockito; +import org.mockito.invocation.InvocationOnMock; +import org.mockito.stubbing.Answer; import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry; -import org.opendaylight.openflowjava.protocol.api.connection.ConnectionAdapter; -import org.opendaylight.openflowjava.protocol.api.connection.OutboundQueue; import org.opendaylight.openflowplugin.api.OFConstants; -import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext; -import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext; -import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack; -import org.opendaylight.openflowplugin.api.openflow.rpc.RpcContext; -import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.MessageSpy; -import org.opendaylight.openflowplugin.impl.registry.flow.DeviceFlowRegistryImpl; -import org.opendaylight.openflowplugin.impl.rpc.RpcContextImpl; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FeaturesReply; +import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.EventIdentifier; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReply; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessageBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyTableFeaturesCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.table.features._case.MultipartReplyTableFeaturesBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.table.features._case.multipart.reply.table.features.TableFeaturesBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.table.features.properties.grouping.TableFeatureProperties; import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.UpdateTableInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.UpdateTableInputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.UpdateTableOutput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.table.update.UpdatedTable; import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.table.update.UpdatedTableBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.TableFeatures; import org.opendaylight.yangtools.yang.common.RpcResult; +import org.opendaylight.yangtools.yang.common.RpcResultBuilder; -import java.math.BigInteger; -import java.util.Collections; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.Future; - -import static org.mockito.Mockito.when; - -@RunWith(MockitoJUnitRunner.class) -public class SalTableServiceImplTest extends TestCase { +public class SalTableServiceImplTest extends ServiceMocking { private static final BigInteger DUMMY_DATAPATH_ID = new BigInteger("444"); private static final Short DUMMY_VERSION = OFConstants.OFP_VERSION_1_3; private static final int DUMMY_MAX_REQUEST = 88; - @Mock - RequestContextStack mockedRequestContextStack; - @Mock - DeviceContext mockedDeviceContext; - @Mock - ConnectionContext mockedPrimConnectionContext; - @Mock - FeaturesReply mockedFeatures; - @Mock - ConnectionAdapter mockedConnectionAdapter; - @Mock - MessageSpy mockedMessagSpy; @Mock RpcProviderRegistry mockedRpcProviderRegistry; - @Mock - OutboundQueue mockedOutboundQueue; - @Before - public void initialization() { - when(mockedFeatures.getDatapathId()).thenReturn(DUMMY_DATAPATH_ID); - when(mockedFeatures.getVersion()).thenReturn(DUMMY_VERSION); + private SettableFuture handleResultFuture; + private SalTableServiceImpl salTableService; + + @Override + public void setup() { + handleResultFuture = SettableFuture.create(); + when(mockedRequestContext.getFuture()).thenReturn(handleResultFuture); + Mockito.doAnswer(new Answer() { + @Override + public Void answer(InvocationOnMock invocation) throws Throwable { + final FutureCallback callback = (FutureCallback) invocation.getArguments()[2]; + callback.onSuccess(null); + return null; + } + }) + .when(mockedOutboundQueue).commitEntry( + Matchers.anyLong(), Matchers.any(), Matchers.>any()); - when(mockedPrimConnectionContext.getFeatures()).thenReturn(mockedFeatures); - when(mockedPrimConnectionContext.getConnectionAdapter()).thenReturn(mockedConnectionAdapter); - when(mockedPrimConnectionContext.getOutboundQueueProvider()).thenReturn(mockedOutboundQueue); + salTableService = new SalTableServiceImpl(mockedRequestContextStack, mockedDeviceContext); + } - when(mockedDeviceContext.getPrimaryConnectionContext()).thenReturn(mockedPrimConnectionContext); + @Test + public void testUpdateTableFail1() throws ExecutionException, InterruptedException { + Mockito.doAnswer(new Answer() { + @Override + public Void answer(InvocationOnMock invocation) throws Throwable { + final RpcResult> rpcResult = RpcResultBuilder.>failed().build(); + handleResultFuture.set(rpcResult); + return null; + } + }).when(multiMessageCollector).endCollecting(Matchers.any()); - when(mockedDeviceContext.getMessageSpy()).thenReturn(mockedMessagSpy); - when(mockedDeviceContext.getDeviceFlowRegistry()).thenReturn(new DeviceFlowRegistryImpl()); + final Future> rpcResultFuture = salTableService.updateTable(prepareUpdateTable()); + Assert.assertNotNull(rpcResultFuture); + verify(mockedRequestContextStack).createRequestContext(); } @Test - public void testUpdateTable() throws ExecutionException, InterruptedException { - final RpcContextImpl rpcContext = new RpcContextImpl(mockedMessagSpy, - mockedRpcProviderRegistry, mockedDeviceContext, DUMMY_MAX_REQUEST); - final SalTableServiceImpl salTableService = new SalTableServiceImpl(rpcContext, mockedDeviceContext); + public void testUpdateTableFail2() throws ExecutionException, InterruptedException { + Mockito.doAnswer(new Answer() { + @Override + public Void answer(InvocationOnMock invocation) throws Throwable { + final RpcResult> rpcResult = RpcResultBuilder.success(Collections.emptyList()) + .build(); + handleResultFuture.set(rpcResult); + return null; + } + }).when(multiMessageCollector).endCollecting(Matchers.any()); + + final Future> rpcResultFuture = salTableService.updateTable(prepareUpdateTable()); + Assert.assertNotNull(rpcResultFuture); + verify(mockedRequestContextStack).createRequestContext(); + } + + @Test + public void testUpdateTableSuccess() throws ExecutionException, InterruptedException { + Mockito.doAnswer(new Answer() { + @Override + public Void answer(InvocationOnMock invocation) throws Throwable { + TableFeaturesBuilder tableFeaturesBld = new TableFeaturesBuilder() + .setTableId((short) 0) + .setName("Zafod") + .setMaxEntries(42L) + .setTableFeatureProperties(Collections.emptyList()); + MultipartReplyTableFeaturesBuilder mpTableFeaturesBld = new MultipartReplyTableFeaturesBuilder() + .setTableFeatures(Collections.singletonList(tableFeaturesBld.build())); + MultipartReplyTableFeaturesCaseBuilder mpBodyBld = new MultipartReplyTableFeaturesCaseBuilder() + .setMultipartReplyTableFeatures(mpTableFeaturesBld.build()); + MultipartReplyMessageBuilder mpResultBld = new MultipartReplyMessageBuilder() + .setType(MultipartType.OFPMPTABLEFEATURES) + .setMultipartReplyBody(mpBodyBld.build()) + .setXid(21L); + final RpcResult> rpcResult = RpcResultBuilder + .success(Collections.singletonList((MultipartReply) mpResultBld.build())) + .build(); + handleResultFuture.set(rpcResult); + return null; + } + }).when(multiMessageCollector).endCollecting(Matchers.any()); + final Future> rpcResultFuture = salTableService.updateTable(prepareUpdateTable()); - assertNotNull(rpcResultFuture); + Assert.assertNotNull(rpcResultFuture); + verify(mockedRequestContextStack).createRequestContext(); } private UpdateTableInput prepareUpdateTable() { diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/ServiceMocking.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/ServiceMocking.java index d87792b578..2e3a73ad40 100644 --- a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/ServiceMocking.java +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/ServiceMocking.java @@ -1,36 +1,42 @@ package org.opendaylight.openflowplugin.impl.services; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.ListenableFuture; import io.netty.util.HashedWheelTimer; +import java.math.BigInteger; +import java.util.List; import org.junit.Before; import org.junit.runner.RunWith; +import org.mockito.Matchers; import org.mockito.Mock; import org.mockito.runners.MockitoJUnitRunner; import org.opendaylight.openflowjava.protocol.api.connection.ConnectionAdapter; import org.opendaylight.openflowjava.protocol.api.connection.OutboundQueue; import org.opendaylight.openflowplugin.api.OFConstants; import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext; -import org.opendaylight.openflowplugin.api.openflow.device.*; +import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext; +import org.opendaylight.openflowplugin.api.openflow.device.DeviceState; +import org.opendaylight.openflowplugin.api.openflow.device.RequestContext; +import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack; +import org.opendaylight.openflowplugin.api.openflow.device.Xid; import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceInitializationPhaseHandler; +import org.opendaylight.openflowplugin.api.openflow.device.handlers.MultiMsgCollector; import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.MessageSpy; import org.opendaylight.openflowplugin.impl.registry.flow.DeviceFlowRegistryImpl; import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId; import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes; import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node; import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey; -import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.AddMeterOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FeaturesReply; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReply; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier; import org.opendaylight.yangtools.yang.common.RpcResult; import org.opendaylight.yangtools.yang.common.RpcResultBuilder; -import java.math.BigInteger; - -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - @RunWith(MockitoJUnitRunner.class) public abstract class ServiceMocking { private static final BigInteger DUMMY_DATAPATH_ID = new BigInteger("444"); @@ -38,31 +44,33 @@ public abstract class ServiceMocking { private static final Long DUMMY_XID_VALUE = 2121L; private static final Xid DUMMY_XID = new Xid(DUMMY_XID_VALUE); - private static final String DUMMY_NODE_ID = "dummyNodeID"; + protected static final String DUMMY_NODE_ID = "dummyNodeID"; private static final KeyedInstanceIdentifier NODE_II = InstanceIdentifier.create(Nodes.class).child(Node.class, new NodeKey(new NodeId(DUMMY_NODE_ID))); @Mock - RequestContextStack mockedRequestContextStack; + protected RequestContextStack mockedRequestContextStack; @Mock - ConnectionContext mockedPrimConnectionContext; + protected ConnectionContext mockedPrimConnectionContext; @Mock - FeaturesReply mockedFeatures; + protected FeaturesReply mockedFeatures; @Mock - ConnectionAdapter mockedConnectionAdapter; + protected ConnectionAdapter mockedConnectionAdapter; @Mock - MessageSpy mockedMessagSpy; + protected MessageSpy mockedMessagSpy; @Mock - DeviceContext mockedDeviceContext; + protected DeviceContext mockedDeviceContext; @Mock - DeviceState mockedDeviceState; + protected DeviceState mockedDeviceState; @Mock - DeviceInitializationPhaseHandler mockedDevicePhaseHandler; + protected DeviceInitializationPhaseHandler mockedDevicePhaseHandler; @Mock - RequestContext mockedRequestContext; + protected RequestContext mockedRequestContext; @Mock - OutboundQueue mockedOutboundQueue; + protected OutboundQueue mockedOutboundQueue; + @Mock + protected MultiMsgCollector multiMessageCollector; @Before public void initialization() { @@ -79,11 +87,19 @@ public abstract class ServiceMocking { when(mockedDeviceState.getNodeInstanceIdentifier()).thenReturn(NODE_II); + when(mockedDeviceContext.getPrimaryConnectionContext()).thenReturn(mockedPrimConnectionContext); when(mockedDeviceContext.getMessageSpy()).thenReturn(mockedMessagSpy); when(mockedDeviceContext.getDeviceFlowRegistry()).thenReturn(new DeviceFlowRegistryImpl()); when(mockedDeviceContext.getDeviceState()).thenReturn(mockedDeviceState); when(mockedDeviceContext.getTimer()).thenReturn(mock(HashedWheelTimer.class)); + when(mockedDeviceContext.getMultiMsgCollector(Matchers.>>any())).thenReturn(multiMessageCollector); + + setup(); + } + + protected void setup() { + //NOOP - to be overloaded } -- 2.36.6