Merge "Use ${project.version} for internal dependencies"
[ovsdb.git] / openstack / net-virt-providers / src / test / java / org / opendaylight / ovsdb / openstack / netvirt / providers / openflow13 / services / ArpResponderServiceTest.java
index e3d7cc43f62123f420f5bb3acbd610eb90fbf4a6..a36ae769e35af63ee129631a5cb3c511a10d342c 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015 Inocybe and others.  All rights reserved.
+ * Copyright (c) 2015, 2016 Inocybe 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,
@@ -24,18 +24,18 @@ import org.mockito.InjectMocks;
 import org.mockito.Mock;
 import org.mockito.runners.MockitoJUnitRunner;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
 import org.opendaylight.ovsdb.openstack.netvirt.api.Action;
-import org.opendaylight.ovsdb.openstack.netvirt.providers.openflow13.MdsalConsumer;
-import org.opendaylight.ovsdb.openstack.netvirt.providers.openflow13.PipelineOrchestrator;
-import org.opendaylight.ovsdb.plugin.api.OvsdbConfigurationService;
-import org.opendaylight.ovsdb.plugin.api.OvsdbConnectionService;
-import org.opendaylight.ovsdb.plugin.api.Status;
-import org.opendaylight.ovsdb.plugin.api.StatusCode;
+import org.opendaylight.ovsdb.openstack.netvirt.api.Status;
+import org.opendaylight.ovsdb.openstack.netvirt.api.StatusCode;
+import org.opendaylight.ovsdb.openstack.netvirt.providers.openflow13.Service;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 
 import com.google.common.util.concurrent.CheckedFuture;
@@ -45,46 +45,45 @@ import com.google.common.util.concurrent.CheckedFuture;
  * Unit test for {@link ArpResponderService}
  */
 @RunWith(MockitoJUnitRunner.class)
+@SuppressWarnings("unchecked")
 public class ArpResponderServiceTest {
 
     @InjectMocks private ArpResponderService arpResponderService = new ArpResponderService();
 
-    @Mock private MdsalConsumer mdsalConsumer;
+    @Mock private DataBroker dataBroker;
 
     private static final String HOST_ADDRESS = "121.0.0.1";
     private static final String MAC_ADDRESS = "87:1D:5E:02:40:B7";
 
     @Test
     public void testProgramStaticArpEntry() throws Exception {
+        arpResponderService.setService(Service.ARP_RESPONDER);
+
         InetAddress ipAddress = mock(InetAddress.class);
         when(ipAddress.getHostAddress()).thenReturn(HOST_ADDRESS);
 
+        WriteTransaction transaction = mock(WriteTransaction.class);
+        when(dataBroker.newWriteOnlyTransaction()).thenReturn(transaction);
         CheckedFuture<Void, TransactionCommitFailedException> commitFuture = mock(CheckedFuture.class);
+        when(transaction.submit()).thenReturn(commitFuture);
 
-        ReadWriteTransaction readWriteTransaction = mock(ReadWriteTransaction.class);
-        when(readWriteTransaction.submit()).thenReturn(commitFuture);
-
-        WriteTransaction writeTransaction = mock(WriteTransaction.class);
-        when(writeTransaction.submit()).thenReturn(commitFuture);
+        NodeBuilder nodeBuilder = mock(NodeBuilder.class);
+        when(nodeBuilder.getKey()).thenReturn(mock(NodeKey.class));
 
-        DataBroker dataBroker = mock(DataBroker.class);
-        when(dataBroker.newReadWriteTransaction()).thenReturn(readWriteTransaction);
-        when(dataBroker.newWriteOnlyTransaction()).thenReturn(writeTransaction);
+        FlowBuilder flowBuilder = mock(FlowBuilder.class);
+        when(flowBuilder.getKey()).thenReturn(mock(FlowKey.class));
 
-        when(mdsalConsumer.getDataBroker()).thenReturn(dataBroker);
+        // test Action.ADD
+        assertEquals("Error, did not return the expected StatusCode", new Status(StatusCode.SUCCESS), arpResponderService.programStaticArpEntry(Long.valueOf(12), "2", MAC_ADDRESS, ipAddress, Action.ADD));
 
-        // test for Action.ADD
-        assertEquals("Error, did not return the expected StatusCode", new Status(StatusCode.SUCCESS), arpResponderService.programStaticArpEntry(mock(Node.class), Long.valueOf(12), "2", MAC_ADDRESS, ipAddress, Action.ADD));
-
-        verify(readWriteTransaction, times(2)).put(any(LogicalDatastoreType.class), any(InstanceIdentifier.class), any(Node.class), anyBoolean());
-        verify(readWriteTransaction, times(1)).submit();
+        verify(transaction, times(2)).put(any(LogicalDatastoreType.class), any(InstanceIdentifier.class), any(Node.class), anyBoolean());
+        verify(transaction, times(1)).submit();
         verify(commitFuture, times(1)).get();
 
-        // test other Action, here Action.DELETE
-        assertEquals("Error, did not return the expected StatusCode", new Status(StatusCode.SUCCESS), arpResponderService.programStaticArpEntry(mock(Node.class), Long.valueOf(12), "2", MAC_ADDRESS, ipAddress, Action.DELETE));
+        // test Action.DELETE
+        assertEquals("Error, did not return the expected StatusCode", new Status(StatusCode.SUCCESS), arpResponderService.programStaticArpEntry(Long.valueOf(12), "2", MAC_ADDRESS, ipAddress, Action.DELETE));
 
-        verify(writeTransaction, times(1)).delete(any(LogicalDatastoreType.class), any(InstanceIdentifier.class));
+        verify(transaction, times(1)).delete(any(LogicalDatastoreType.class), any(InstanceIdentifier.class));
         verify(commitFuture, times(2)).get(); // 1 + 1 above
     }
-
 }