import org.opendaylight.openflowplugin.api.openflow.registry.flow.FlowRegistryKey;
import org.opendaylight.openflowplugin.api.openflow.rpc.listener.ItemLifecycleListener;
import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.MessageSpy;
+import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorManager;
+import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorManagerFactory;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table;
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.AddFlowInputBuilder;
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.RemoveFlowInputBuilder;
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.OriginalFlowBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.flow.update.UpdatedFlow;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.flow.update.UpdatedFlowBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowRef;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
when(mockedDeviceContext.getDeviceState()).thenReturn(mockedDeviceState);
when(mockedDeviceContext.getDeviceInfo()).thenReturn(mockedDeviceInfo);
- salFlowService = new SalFlowServiceImpl(mockedRequestContextStack, mockedDeviceContext);
+ final ConvertorManager convertorManager = ConvertorManagerFactory.createDefaultManager();
+ salFlowService = new SalFlowServiceImpl(mockedRequestContextStack, mockedDeviceContext, convertorManager);
}
@Test
@Test
public void testAddFlowFailCallback() throws Exception {
- AddFlowInput mockedAddFlowInput = createFlowMock(AddFlowInput.class);
+ AddFlowInput mockedAddFlowInput = new AddFlowInputBuilder()
+ .setMatch(match)
+ .setTableId((short)1)
+ .build();
+
Mockito.doReturn(Futures.<RequestContext<Object>>immediateFailedFuture(new Exception("ut-failed-response")))
.when(requestContext).getFuture();
@Test
public void testRemoveFlowFailCallback() throws Exception {
- RemoveFlowInput mockedRemoveFlowInput = createFlowMock(RemoveFlowInput.class);
+ RemoveFlowInput mockedRemoveFlowInput = new RemoveFlowInputBuilder()
+ .setMatch(match)
+ .build();
+
Mockito.doReturn(Futures.<RequestContext<Object>>immediateFailedFuture(new Exception("ut-failed-response")))
.when(requestContext).getFuture();
}
private void addFlow(final ItemLifecycleListener itemLifecycleListener) throws ExecutionException, InterruptedException {
- AddFlowInput mockedAddFlowInput = createFlowMock(AddFlowInput.class);
+ AddFlowInput mockedAddFlowInput = new AddFlowInputBuilder()
+ .setMatch(match)
+ .setTableId((short)1)
+ .build();
+
salFlowService.setItemLifecycleListener(itemLifecycleListener);
mockingFlowRegistryLookup();
}
private void removeFlow(final ItemLifecycleListener itemLifecycleListener) throws Exception {
- RemoveFlowInput mockedRemoveFlowInput = createFlowMock(RemoveFlowInput.class);
+ RemoveFlowInput mockedRemoveFlowInput = new RemoveFlowInputBuilder()
+ .setMatch(match)
+ .setTableId((short)1)
+ .build();
if (itemLifecycleListener != null) {
salFlowService.setItemLifecycleListener(itemLifecycleListener);
private void updateFlow(final ItemLifecycleListener itemLifecycleListener) throws Exception {
UpdateFlowInput mockedUpdateFlowInput = mock(UpdateFlowInput.class);
- UpdatedFlow mockedUpdateFlow = createFlowMock(UpdatedFlow.class);
+ UpdatedFlow mockedUpdateFlow = new UpdatedFlowBuilder()
+ .setMatch(match)
+ .setTableId((short)1)
+ .build();
+
when(mockedUpdateFlowInput.getUpdatedFlow()).thenReturn(mockedUpdateFlow);
FlowRef mockedFlowRef = mock(FlowRef.class);
Mockito.doReturn(TABLE_II.child(Flow.class, new FlowKey(new FlowId(DUMMY_FLOW_ID)))).when(mockedFlowRef).getValue();
when(mockedUpdateFlowInput.getFlowRef()).thenReturn(mockedFlowRef);
- OriginalFlow mockedOriginalFlow = createFlowMock(OriginalFlow.class);
+ OriginalFlow mockedOriginalFlow = new OriginalFlowBuilder()
+ .setMatch(match)
+ .setTableId((short)1)
+ .build();
+
when(mockedUpdateFlowInput.getOriginalFlow()).thenReturn(mockedOriginalFlow);
if (itemLifecycleListener != null) {
when(mockedFlowDescriptor.getFlowId()).thenReturn(flowId);
when(mockedFlowDescriptor.getTableKey()).thenReturn(new TableKey(DUMMY_TABLE_ID));
- when(deviceFlowRegistry.storeIfNecessary(Matchers.any(FlowRegistryKey.class))).thenReturn(flowId);
- when(deviceFlowRegistry.retrieveIdForFlow(Matchers.any(FlowRegistryKey.class))).thenReturn(mockedFlowDescriptor);
+ when(deviceFlowRegistry.retrieveDescriptor(Matchers.any(FlowRegistryKey.class))).thenReturn(mockedFlowDescriptor);
}
private <T extends DataObject> void verifyOutput(Future<RpcResult<T>> rpcResultFuture) throws ExecutionException, InterruptedException {
assertNotNull(addFlowOutputRpcResult);
assertTrue(addFlowOutputRpcResult.isSuccessful());
}
-
- private <T extends org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.Flow> T createFlowMock(Class<T> flowClazz) {
- T mockedFlow = mock(flowClazz);
- when(mockedFlow.getMatch()).thenReturn(match);
- return mockedFlow;
- }
}