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;
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.DeviceInfo;
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.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;
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.protocol.rev130731.FeaturesReply;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput;
import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
private SalFlowServiceImpl salFlowService;
@Mock
- DeviceState mockedDeviceState;
+ private DeviceState mockedDeviceState;
+ @Mock
+ private DeviceInfo mockedDeviceInfo;
@Mock
private DeviceFlowRegistry deviceFlowRegistry;
+ @Mock
+ private GetFeaturesOutput mockedFeaturesOutput;
@Before
public void initialization() {
when(mockedFeatures.getDatapathId()).thenReturn(DUMMY_DATAPATH_ID);
when(mockedFeatures.getVersion()).thenReturn(DUMMY_VERSION);
+ when(mockedFeaturesOutput.getDatapathId()).thenReturn(DUMMY_DATAPATH_ID);
+ when(mockedFeaturesOutput.getVersion()).thenReturn(DUMMY_VERSION);
when(mockedPrimConnectionContext.getFeatures()).thenReturn(mockedFeatures);
when(mockedPrimConnectionContext.getConnectionAdapter()).thenReturn(mockedConnectionAdapter);
when(requestContext.getXid()).thenReturn(new Xid(84L));
when(requestContext.getFuture()).thenReturn(RpcResultBuilder.success().buildFuture());
- salFlowService = new SalFlowServiceImpl(mockedRequestContextStack, mockedDeviceContext);
-
-
- when(mockedDeviceState.getNodeInstanceIdentifier()).thenReturn(NODE_II);
+ when(mockedDeviceInfo.getNodeInstanceIdentifier()).thenReturn(NODE_II);
+ when(mockedDeviceInfo.getDatapathId()).thenReturn(DUMMY_DATAPATH_ID);
+ when(mockedDeviceInfo.getVersion()).thenReturn(DUMMY_VERSION);
when(mockedDeviceContext.getDeviceState()).thenReturn(mockedDeviceState);
+ when(mockedDeviceContext.getDeviceInfo()).thenReturn(mockedDeviceInfo);
+
+ salFlowService = new SalFlowServiceImpl(mockedRequestContextStack, mockedDeviceContext);
}
@Test
addFlow(null);
}
+ @Test
+ public void testAddFlowFailCallback() throws Exception {
+ AddFlowInput mockedAddFlowInput = createFlowMock(AddFlowInput.class);
+ Mockito.doReturn(Futures.<RequestContext<Object>>immediateFailedFuture(new Exception("ut-failed-response")))
+ .when(requestContext).getFuture();
+
+ mockingFlowRegistryLookup();
+ final Future<RpcResult<AddFlowOutput>> 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.<RequestContext<Object>>immediateFailedFuture(new Exception("ut-failed-response")))
+ .when(requestContext).getFuture();
+
+ final Future<RpcResult<RemoveFlowOutput>> 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));
AddFlowInput mockedAddFlowInput = createFlowMock(AddFlowInput.class);
salFlowService.setItemLifecycleListener(itemLifecycleListener);
+ mockingFlowRegistryLookup();
verifyOutput(salFlowService.addFlow(mockedAddFlowInput));
if (itemLifecycleListener != null) {
Mockito.verify(itemLifecycleListener).onAdded(Matchers.<KeyedInstanceIdentifier<Flow, FlowKey>>any(), Matchers.<Flow>any());
verifyOutput(salFlowService.updateFlow(mockedUpdateFlowInput));
if (itemLifecycleListener != null) {
- Mockito.verify(itemLifecycleListener).onAdded(Matchers.<KeyedInstanceIdentifier<Flow, FlowKey>>any(), Matchers.<Flow>any());
- Mockito.verify(itemLifecycleListener).onRemoved(Matchers.<KeyedInstanceIdentifier<Flow, FlowKey>>any());
+ Mockito.verify(itemLifecycleListener).onUpdated(Matchers.<KeyedInstanceIdentifier<Flow, FlowKey>>any(), Matchers.<Flow>any());
}
}
private void mockingFlowRegistryLookup() {
FlowDescriptor mockedFlowDescriptor = mock(FlowDescriptor.class);
- when(mockedFlowDescriptor.getFlowId()).thenReturn(new FlowId(DUMMY_FLOW_ID));
+ FlowId flowId = new FlowId(DUMMY_FLOW_ID);
+ 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);
}