Bump mdsal to 5.0.2
[openflowplugin.git] / openflowplugin-impl / src / test / java / org / opendaylight / openflowplugin / impl / services / sal / SalRoleServiceImplTest.java
index 20f26350002ead576f5c7125fec4fb7d99f9a0e4..59827b7cff3f708a5daa455142e81bf96a8decfe 100644 (file)
@@ -8,12 +8,10 @@
 package org.opendaylight.openflowplugin.impl.services.sal;
 
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 
 import com.google.common.util.concurrent.ListenableFuture;
-import java.math.BigInteger;
 import java.util.concurrent.Future;
 import java.util.concurrent.TimeUnit;
 import org.junit.Before;
@@ -21,7 +19,6 @@ import org.junit.Test;
 import org.mockito.Mock;
 import org.mockito.Mockito;
 import org.mockito.MockitoAnnotations;
-import org.opendaylight.openflowjava.protocol.api.connection.ConnectionAdapter;
 import org.opendaylight.openflowjava.protocol.api.connection.OutboundQueue;
 import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext;
 import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
@@ -47,13 +44,12 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.role.service.rev150727.SetR
 import org.opendaylight.yang.gen.v1.urn.opendaylight.role.service.rev150727.SetRoleInputBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.role.service.rev150727.SetRoleOutput;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import org.opendaylight.yangtools.yang.common.RpcError.ErrorType;
 import org.opendaylight.yangtools.yang.common.RpcResult;
 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
+import org.opendaylight.yangtools.yang.common.Uint32;
+import org.opendaylight.yangtools.yang.common.Uint64;
+import org.opendaylight.yangtools.yang.common.Uint8;
 
-/**
- * Created by kramesha on 8/27/15.
- */
 public class SalRoleServiceImplTest {
 
     @Mock
@@ -62,9 +58,6 @@ public class SalRoleServiceImplTest {
     @Mock
     private DeviceContext mockDeviceContext;
 
-    @Mock
-    private ConnectionAdapter mockConnectionAdapter;
-
     @Mock
     private FeaturesReply mockFeaturesReply;
 
@@ -89,16 +82,14 @@ public class SalRoleServiceImplTest {
     @Mock
     private OutboundQueue mockOutboundQueue;
 
-    private NodeId testNodeId = new NodeId(Uri.getDefaultInstance("openflow:1"));
-
-    private static short testVersion = 4;
+    private final NodeId testNodeId = new NodeId(Uri.getDefaultInstance("openflow:1"));
 
     private static long testXid = 100L;
 
-    private static final String ROLEREQUESTFAILED =
-            org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ErrorType.ROLEREQUESTFAILED.name();
+    private static final String ROLEREQUESTFAILED = org.opendaylight.yang.gen.v1.urn
+            .opendaylight.openflow.common.types.rev130731.ErrorType.ROLEREQUESTFAILED.name();
 
-    private static final String ROLES_UNSUPPORTED = "Device reported error type "+ ROLEREQUESTFAILED +" code UNSUP";
+    private static final String ROLES_UNSUPPORTED = "Device reported error type " + ROLEREQUESTFAILED + " code UNSUP";
 
     private NodeRef nodeRef;
 
@@ -106,7 +97,8 @@ public class SalRoleServiceImplTest {
     public void setup() {
         MockitoAnnotations.initMocks(this);
         Mockito.when(mockDeviceInfo.getNodeId()).thenReturn(testNodeId);
-        Mockito.when(mockDeviceInfo.getDatapathId()).thenReturn(BigInteger.TEN);
+        Mockito.when(mockDeviceInfo.getDatapathId()).thenReturn(Uint64.valueOf(10));
+        Uint8 testVersion = Uint8.valueOf(4);
         Mockito.when(mockFeaturesOutput.getVersion()).thenReturn(testVersion);
         Mockito.when(mockDeviceContext.getDeviceState()).thenReturn(mockDeviceState);
         Mockito.when(mockDeviceContext.getDeviceInfo()).thenReturn(mockDeviceInfo);
@@ -116,13 +108,14 @@ public class SalRoleServiceImplTest {
         Mockito.when(mockFeaturesReply.getVersion()).thenReturn(testVersion);
         Mockito.when(mockDeviceContext.getMessageSpy()).thenReturn(mockMessageSpy);
         Mockito.when(mockRequestContextStack.<RoleRequestOutput>createRequestContext()).thenReturn(mockRequestContext);
-        Mockito.when(mockRequestContext.getXid()).thenReturn(new Xid(testXid));
+        Mockito.when(mockRequestContext.getXid()).thenReturn(new Xid(Uint32.valueOf(testXid)));
         Mockito.when(mockConnectionContext.getOutboundQueueProvider()).thenReturn(mockOutboundQueue);
-        Mockito.when(mockDeviceContext.getPrimaryConnectionContext().getConnectionState()).thenReturn(ConnectionContext.CONNECTION_STATE.WORKING);
+        Mockito.when(mockDeviceContext.getPrimaryConnectionContext().getConnectionState())
+                .thenReturn(ConnectionContext.CONNECTION_STATE.WORKING);
 
         NodeKey key = new NodeKey(testNodeId);
-        InstanceIdentifier<Node> path = InstanceIdentifier.<Nodes>builder(Nodes.class)
-                .<Node, NodeKey>child(Node.class, key)
+        InstanceIdentifier<Node> path = InstanceIdentifier.builder(Nodes.class)
+                .child(Node.class, key)
                 .build();
         nodeRef = new NodeRef(path);
 
@@ -130,8 +123,8 @@ public class SalRoleServiceImplTest {
 
     @Test
     public void testSetRole() throws Exception {
-        RoleRequestOutput roleRequestOutput = (new RoleRequestOutputBuilder())
-                .setXid(testXid).setGenerationId(BigInteger.valueOf(1)).build();
+        RoleRequestOutput roleRequestOutput = new RoleRequestOutputBuilder()
+                .setXid(testXid).setGenerationId(Uint64.ONE).build();
         ListenableFuture<RpcResult<RoleRequestOutput>> futureOutput =
                 RpcResultBuilder.<RoleRequestOutput>success().withResult(roleRequestOutput).buildFuture();
 
@@ -153,41 +146,16 @@ public class SalRoleServiceImplTest {
 
         SetRoleOutput setRoleOutput = roleOutputRpcResult.getResult();
         assertNotNull(setRoleOutput);
-        assertEquals(BigInteger.valueOf(testXid), setRoleOutput.getTransactionId().getValue());
-
-    }
-
-    @Test
-    public void testSetRoleUnsupported() throws Exception {
-        ListenableFuture<RpcResult<RoleRequestOutput>> futureOutput =
-                RpcResultBuilder.<RoleRequestOutput>failed()
-                        .withError(ErrorType.APPLICATION, ROLES_UNSUPPORTED)
-                        .buildFuture();
-
-        Mockito.when(mockRequestContext.getFuture()).thenReturn(futureOutput);
+        assertEquals(Uint64.valueOf(testXid), setRoleOutput.getTransactionId().getValue());
 
-        SalRoleService salRoleService = new SalRoleServiceImpl(mockRequestContextStack, mockDeviceContext);
-
-        SetRoleInput setRoleInput = new SetRoleInputBuilder()
-                .setControllerRole(OfpRole.BECOMESLAVE)
-                .setNode(nodeRef)
-                .build();
-
-        Future<RpcResult<SetRoleOutput>> future = salRoleService.setRole(setRoleInput);
-
-        RpcResult<SetRoleOutput> roleOutputRpcResult = future.get(5, TimeUnit.SECONDS);
-        assertNotNull("RpcResult from future cannot be null.", roleOutputRpcResult);
-        assertFalse("RpcResult from future is successful.", roleOutputRpcResult.isSuccessful());
-        assertEquals(ROLES_UNSUPPORTED, roleOutputRpcResult
-                .getErrors().iterator().next().getMessage());
     }
 
     @Test
     public void testDuplicateRoles() throws Exception {
         // set role to slave
 
-        RoleRequestOutput roleRequestOutput = (new RoleRequestOutputBuilder())
-                .setXid(testXid).setGenerationId(BigInteger.valueOf(1)).build();
+        RoleRequestOutput roleRequestOutput = new RoleRequestOutputBuilder()
+                .setXid(testXid).setGenerationId(Uint64.ONE).build();
         ListenableFuture<RpcResult<RoleRequestOutput>> futureOutput =
                 RpcResultBuilder.<RoleRequestOutput>success().withResult(roleRequestOutput).buildFuture();
 
@@ -208,7 +176,7 @@ public class SalRoleServiceImplTest {
 
         SetRoleOutput setRoleOutput = roleOutputRpcResult.getResult();
         assertNotNull(setRoleOutput);
-        assertEquals(BigInteger.valueOf(testXid), setRoleOutput.getTransactionId().getValue());
+        assertEquals(Uint64.valueOf(testXid), setRoleOutput.getTransactionId().getValue());
 
         // make another role change with the same role - slave
         Future<RpcResult<SetRoleOutput>> future2 = salRoleService.setRole(setRoleInput);