Merge "Removed useless method"
[openflowplugin.git] / openflowplugin-impl / src / test / java / org / opendaylight / openflowplugin / impl / services / ServiceMocking.java
index 71d17ccf54a80b2ef629eae80db4bf0356e15a95..d87792b57869391f07dc96af70c2de8854dcf1f6 100644 (file)
@@ -1,20 +1,30 @@
 package org.opendaylight.openflowplugin.impl.services;
 
+import com.google.common.util.concurrent.Futures;
+import com.google.common.util.concurrent.ListenableFuture;
 import io.netty.util.HashedWheelTimer;
 import org.junit.Before;
 import org.junit.runner.RunWith;
 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.DeviceContext;
-import org.opendaylight.openflowplugin.api.openflow.device.DeviceState;
-import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
+import org.opendaylight.openflowplugin.api.openflow.device.*;
 import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceInitializationPhaseHandler;
 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.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;
 
@@ -25,6 +35,13 @@ import static org.mockito.Mockito.when;
 public abstract class 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 Long DUMMY_XID_VALUE = 2121L;
+    private static final Xid DUMMY_XID = new Xid(DUMMY_XID_VALUE);
+
+    private static final String DUMMY_NODE_ID = "dummyNodeID";
+    private static final KeyedInstanceIdentifier<Node, NodeKey> NODE_II
+            = InstanceIdentifier.create(Nodes.class).child(Node.class, new NodeKey(new NodeId(DUMMY_NODE_ID)));
+
 
     @Mock
     RequestContextStack mockedRequestContextStack;
@@ -42,15 +59,25 @@ public abstract class ServiceMocking {
     DeviceState mockedDeviceState;
     @Mock
     DeviceInitializationPhaseHandler mockedDevicePhaseHandler;
+    @Mock
+    RequestContext mockedRequestContext;
+    @Mock
+    OutboundQueue mockedOutboundQueue;
 
     @Before
     public void initialization() {
+        when(mockedRequestContextStack.createRequestContext()).thenReturn(mockedRequestContext);
+        when(mockedRequestContext.getXid()).thenReturn(DUMMY_XID);
+
         when(mockedFeatures.getDatapathId()).thenReturn(DUMMY_DATAPATH_ID);
         when(mockedFeatures.getVersion()).thenReturn(DUMMY_VERSION);
 
         when(mockedPrimConnectionContext.getFeatures()).thenReturn(mockedFeatures);
         when(mockedPrimConnectionContext.getConnectionAdapter()).thenReturn(mockedConnectionAdapter);
         when(mockedPrimConnectionContext.getConnectionState()).thenReturn(ConnectionContext.CONNECTION_STATE.WORKING);
+        when(mockedPrimConnectionContext.getOutboundQueueProvider()).thenReturn(mockedOutboundQueue);
+
+        when(mockedDeviceState.getNodeInstanceIdentifier()).thenReturn(NODE_II);
 
         when(mockedDeviceContext.getPrimaryConnectionContext()).thenReturn(mockedPrimConnectionContext);
         when(mockedDeviceContext.getMessageSpy()).thenReturn(mockedMessagSpy);
@@ -59,4 +86,10 @@ public abstract class ServiceMocking {
         when(mockedDeviceContext.getTimer()).thenReturn(mock(HashedWheelTimer.class));
     }
 
+
+    protected  <T> void mockSuccessfulFuture() {
+        ListenableFuture<RpcResult<T>> dummySuccessfulFuture = Futures.immediateFuture(RpcResultBuilder.success((T) null).build());
+        when(mockedRequestContext.getFuture()).thenReturn(dummySuccessfulFuture);
+    }
+
 }