Update MRI upstreams for Phosphorus
[openflowplugin.git] / openflowplugin-impl / src / test / java / org / opendaylight / openflowplugin / impl / translator / FlowRemovedTranslatorTest.java
index b12cdb23ca9ee239d1ee79d214b851364d658e16..a686ee52320d92edc70e3699a995a4adbb699ae7 100644 (file)
@@ -5,19 +5,17 @@
  * 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.translator;
 
 import static org.junit.Assert.assertEquals;
 import static org.mockito.Mockito.when;
 
-import java.math.BigInteger;
 import java.util.Collections;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.mockito.Mock;
-import org.mockito.runners.MockitoJUnitRunner;
+import org.mockito.junit.MockitoJUnitRunner;
 import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
 import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
 import org.opendaylight.openflowplugin.api.openflow.device.DeviceState;
@@ -28,18 +26,22 @@ 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.openflow.common.types.rev130731.FlowRemovedReason;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowWildcardsV10;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.grouping.MatchBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.v10.grouping.MatchV10Builder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowRemovedMessageBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
+import org.opendaylight.yangtools.yang.common.Uint16;
+import org.opendaylight.yangtools.yang.common.Uint32;
+import org.opendaylight.yangtools.yang.common.Uint64;
+import org.opendaylight.yangtools.yang.common.Uint8;
 
 /**
- * Test of {@link AggregatedFlowStatisticsTranslator}
+ * Test of {@link AggregatedFlowStatisticsTranslator}.
  */
 @RunWith(MockitoJUnitRunner.class)
 public class FlowRemovedTranslatorTest {
@@ -63,35 +65,34 @@ public class FlowRemovedTranslatorTest {
     @Mock
     private FlowWildcardsV10 flowWildcards;
 
-    private KeyedInstanceIdentifier<Node, NodeKey> nodeId;
-
     @Before
-    public void setUp() throws Exception {
-        nodeId = InstanceIdentifier.create(Nodes.class)
+    public void setUp() {
+        final KeyedInstanceIdentifier<Node, NodeKey> nodeId = InstanceIdentifier.create(Nodes.class)
                 .child(Node.class, new NodeKey(new NodeId("dummyNodeId")));
 
         final ConvertorManager convertorManager = ConvertorManagerFactory.createDefaultManager();
         translator = new FlowRemovedTranslator(convertorManager);
         translatorV10 = new FlowRemovedV10Translator(convertorManager);
 
-        when(deviceContext.getDeviceState()).thenReturn(deviceState);
+        when(deviceInfo.getVersion()).thenReturn(Uint8.ONE);
         when(deviceInfo.getNodeInstanceIdentifier()).thenReturn(nodeId);
-        when(features.getDatapathId()).thenReturn(BigInteger.TEN);
     }
 
     @Test
-    public void testTranslate() throws Exception {
-        org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowRemoved flowRemovedMessage = buildMessage(false);
+    public void testTranslate() {
+        org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowRemoved flowRemovedMessage =
+                buildMessage(false);
         final FlowRemoved flowRemoved = translator.translate(flowRemovedMessage, deviceInfo, null);
 
         assertEquals(flowRemovedMessage.getCookie(), flowRemoved.getCookie().getValue());
         assertEquals(flowRemovedMessage.getPriority(), flowRemoved.getPriority());
-        assertEquals((long)flowRemovedMessage.getTableId().getValue(), (long)flowRemoved.getTableId());
+        assertEquals(flowRemovedMessage.getTableId().getValue().toJava(), flowRemoved.getTableId().toJava());
     }
 
     @Test
-    public void testTranslateV10() throws Exception {
-        org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowRemoved flowRemovedMessage = buildMessage(true);
+    public void testTranslateV10() {
+        org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowRemoved flowRemovedMessage =
+                buildMessage(true);
         final FlowRemoved flowRemoved = translatorV10.translate(flowRemovedMessage, deviceInfo, null);
 
         assertEquals(flowRemovedMessage.getCookie(), flowRemoved.getCookie().getValue());
@@ -99,16 +100,18 @@ public class FlowRemovedTranslatorTest {
         assertEquals((short)0, flowRemoved.getTableId().shortValue());
     }
 
-    private org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowRemoved buildMessage(boolean isV10) {
+    private org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowRemoved
+            buildMessage(final boolean isV10) {
         FlowRemovedMessageBuilder builder = new FlowRemovedMessageBuilder()
-                .setCookie(BigInteger.ONE)
-                .setPriority(1);
+                .setCookie(Uint64.ONE)
+                .setReason(FlowRemovedReason.OFPRRGROUPDELETE)
+                .setPriority(Uint16.ONE);
 
         if (isV10) {
             builder.setMatchV10(new MatchV10Builder().setWildcards(flowWildcards).build());
         } else {
-            builder.setMatch(new MatchBuilder().setMatchEntry(Collections.<MatchEntry>emptyList()).build())
-                .setTableId(new TableId(42L));
+            builder.setMatch(new MatchBuilder().setMatchEntry(Collections.emptyList()).build())
+                .setTableId(new TableId(Uint32.valueOf(42)));
         }
 
         return builder.build();