Migrate servicehandler module to JUnit5
[transportpce.git] / servicehandler / src / test / java / org / opendaylight / transportpce / servicehandler / service / RendererServiceWrapperTest.java
index ff4404cd3c7b706ffe14d3c08fe2c3abe3948ff8..47bf4f486a0597cfce8e033654a59da7f12deab1 100644 (file)
@@ -7,18 +7,18 @@
  */
 package org.opendaylight.transportpce.servicehandler.service;
 
+import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyNoInteractions;
+import static org.mockito.Mockito.when;
 
 import com.google.common.util.concurrent.ListenableFuture;
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
 import org.mockito.InjectMocks;
 import org.mockito.Mock;
-import org.mockito.Mockito;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.jupiter.MockitoExtension;
 import org.opendaylight.mdsal.binding.api.NotificationPublishService;
 import org.opendaylight.transportpce.common.ResponseCodes;
 import org.opendaylight.transportpce.renderer.provisiondevice.RendererServiceOperations;
@@ -42,6 +42,7 @@ import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.TempSer
  * @author Martial Coulibaly ( martial.coulibaly@gfi.com ) on behalf of Orange
  *
  */
+@ExtendWith(MockitoExtension.class)
 public class RendererServiceWrapperTest extends AbstractTest {
     @Mock
     private RendererServiceOperations rendererServiceOperationsMock;
@@ -50,115 +51,98 @@ public class RendererServiceWrapperTest extends AbstractTest {
     @InjectMocks
     private RendererServiceWrapper rendererServiceWrapperMock;
 
-    private AutoCloseable closeable;
-
-    @Before
-    public void openMocks() throws NoSuchMethodException {
-        closeable = MockitoAnnotations.openMocks(this);
-    }
 
     @Test
-    public void performRendererNullServiceHandlerHeader() {
-        ServiceDeleteInput input = ServiceDataUtils.buildServiceDeleteInput();
-        org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210915.ServiceDeleteInput
-            serviceDeleteInput =
-                ModelMappingUtils.createServiceDeleteInput(new ServiceInput(input));
+    void performRendererNullServiceHandlerHeader() {
+        var serviceDeleteInput = ModelMappingUtils
+            .createServiceDeleteInput(new ServiceInput(ServiceDataUtils.buildServiceDeleteInput()));
         serviceDeleteInput = new ServiceDeleteInputBuilder(serviceDeleteInput).setServiceHandlerHeader(null).build();
         ServiceDeleteOutput response = this.rendererServiceWrapperMock.performRenderer(serviceDeleteInput,
                 ServiceNotificationTypes.ServiceDeleteResult, null);
-        Assert.assertEquals(ResponseCodes.FINAL_ACK_YES,
+        assertEquals(ResponseCodes.FINAL_ACK_YES,
                 response.getConfigurationResponseCommon().getAckFinalIndicator());
-        Assert.assertEquals(ResponseCodes.RESPONSE_FAILED,
+        assertEquals(ResponseCodes.RESPONSE_FAILED,
                 response.getConfigurationResponseCommon().getResponseCode());
-        Mockito.verifyNoInteractions(this.rendererServiceOperationsMock);
+        verifyNoInteractions(this.rendererServiceOperationsMock);
     }
 
     @Test
-    public void performRendererNullServiceName() {
-        ServiceDeleteInput input = ServiceDataUtils.buildServiceDeleteInput();
-        org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210915.ServiceDeleteInput
-            serviceDeleteInput =
-                ModelMappingUtils.createServiceDeleteInput(new ServiceInput(input));
+    void performRendererNullServiceName() {
+        var serviceDeleteInput = ModelMappingUtils
+            .createServiceDeleteInput(new ServiceInput(ServiceDataUtils.buildServiceDeleteInput()));
         serviceDeleteInput = new ServiceDeleteInputBuilder(serviceDeleteInput).setServiceName(null).build();
-        ServiceDeleteOutput response = this.rendererServiceWrapperMock.performRenderer(serviceDeleteInput,
-                ServiceNotificationTypes.ServiceDeleteResult, null);
-        Assert.assertEquals(ResponseCodes.FINAL_ACK_YES,
-                response.getConfigurationResponseCommon().getAckFinalIndicator());
-        Assert.assertEquals(ResponseCodes.RESPONSE_FAILED,
-                response.getConfigurationResponseCommon().getResponseCode());
-        Mockito.verifyNoInteractions(this.rendererServiceOperationsMock);
+        ServiceDeleteOutput response = this.rendererServiceWrapperMock
+            .performRenderer(serviceDeleteInput, ServiceNotificationTypes.ServiceDeleteResult, null);
+        assertEquals(ResponseCodes.FINAL_ACK_YES, response.getConfigurationResponseCommon().getAckFinalIndicator());
+        assertEquals(ResponseCodes.RESPONSE_FAILED, response.getConfigurationResponseCommon().getResponseCode());
+        verifyNoInteractions(this.rendererServiceOperationsMock);
     }
 
     @Test
-    public void performRendererNullCommonId() {
-        TempServiceDeleteInput input = ServiceDataUtils.buildTempServiceDeleteInput();
-        input = new TempServiceDeleteInputBuilder(input).setCommonId(null).build();
-        ServiceDeleteOutput response =
-                this.rendererServiceWrapperMock.performRenderer(input, ServiceNotificationTypes.ServiceDeleteResult);
-        Assert.assertEquals(ResponseCodes.FINAL_ACK_YES,
-                response.getConfigurationResponseCommon().getAckFinalIndicator());
-        Assert.assertEquals(ResponseCodes.RESPONSE_FAILED,
-                response.getConfigurationResponseCommon().getResponseCode());
-        Mockito.verifyNoInteractions(this.rendererServiceOperationsMock);
+    void performRendererNullCommonId() {
+        TempServiceDeleteInput input = new TempServiceDeleteInputBuilder(ServiceDataUtils.buildTempServiceDeleteInput())
+            .setCommonId(null).build();
+        ServiceDeleteOutput response = this.rendererServiceWrapperMock
+            .performRenderer(input, ServiceNotificationTypes.ServiceDeleteResult);
+        assertEquals(ResponseCodes.FINAL_ACK_YES, response.getConfigurationResponseCommon().getAckFinalIndicator());
+        assertEquals(ResponseCodes.RESPONSE_FAILED, response.getConfigurationResponseCommon().getResponseCode());
+        verifyNoInteractions(this.rendererServiceOperationsMock);
     }
 
-
     @Test
-    public void performRendererValid() {
+    void performRendererValid() {
         ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder()
-                .setRequestId("request 1").setAckFinalIndicator(ResponseCodes.FINAL_ACK_NO)
-                .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("Renderer service delete in progress")
-                .build();
+            .setRequestId("request 1").setAckFinalIndicator(ResponseCodes.FINAL_ACK_NO)
+            .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("Renderer service delete in progress")
+            .build();
         ServiceDeleteOutput output = new ServiceDeleteOutputBuilder()
-                .setConfigurationResponseCommon(configurationResponseCommon).build();
+            .setConfigurationResponseCommon(configurationResponseCommon).build();
         ListenableFuture<ServiceDeleteOutput> response = ServiceDataUtils.returnFuture(output);
-        Mockito.when(this.rendererServiceOperationsMock.serviceDelete(any(
-                org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210915
-                .ServiceDeleteInput.class), any())).thenReturn(response);
+        when(this.rendererServiceOperationsMock.serviceDelete(any(
+                org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210915.ServiceDeleteInput
+                    .class), any()))
+            .thenReturn(response);
         ServiceDeleteInput input = ServiceDataUtils.buildServiceDeleteInput();
-        org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210915.ServiceDeleteInput
-            serviceDeleteInput =
-                ModelMappingUtils.createServiceDeleteInput(new ServiceInput(input));
-        ServiceDeleteOutput rendereResponse = this.rendererServiceWrapperMock.performRenderer(serviceDeleteInput,
-                ServiceNotificationTypes.ServiceDeleteResult, null);
-        Assert.assertEquals(ResponseCodes.FINAL_ACK_NO,
-                rendereResponse.getConfigurationResponseCommon().getAckFinalIndicator());
-        Assert.assertEquals(ResponseCodes.RESPONSE_OK,
-                rendereResponse.getConfigurationResponseCommon().getResponseCode());
-        Assert.assertEquals("Renderer service delete in progress",
-                rendereResponse.getConfigurationResponseCommon().getResponseMessage());
+        var serviceDeleteInput = ModelMappingUtils.createServiceDeleteInput(new ServiceInput(input));
+        ServiceDeleteOutput rendereResponse = this.rendererServiceWrapperMock
+            .performRenderer(serviceDeleteInput, ServiceNotificationTypes.ServiceDeleteResult, null);
+        assertEquals(
+            ResponseCodes.FINAL_ACK_NO,
+            rendereResponse.getConfigurationResponseCommon().getAckFinalIndicator());
+        assertEquals(ResponseCodes.RESPONSE_OK, rendereResponse.getConfigurationResponseCommon().getResponseCode());
+        assertEquals(
+            "Renderer service delete in progress",
+            rendereResponse.getConfigurationResponseCommon().getResponseMessage());
         verify(this.rendererServiceOperationsMock).serviceDelete(any(
-                org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210915
-                        .ServiceDeleteInput.class), any());
+                org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210915.ServiceDeleteInput
+                    .class), any());
     }
 
     @Test
-    public void performRendererTempValid() {
+    void performRendererTempValid() {
         ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder()
-                .setRequestId("request 1").setAckFinalIndicator(ResponseCodes.FINAL_ACK_NO)
-                .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("Renderer service delete in progress")
-                .build();
+            .setRequestId("request 1").setAckFinalIndicator(ResponseCodes.FINAL_ACK_NO)
+            .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("Renderer service delete in progress")
+            .build();
         ServiceDeleteOutput output = new ServiceDeleteOutputBuilder()
-                .setConfigurationResponseCommon(configurationResponseCommon).build();
+            .setConfigurationResponseCommon(configurationResponseCommon).build();
         ListenableFuture<ServiceDeleteOutput> response = ServiceDataUtils.returnFuture(output);
-        Mockito.when(this.rendererServiceOperationsMock.serviceDelete(any(
-                org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210915
-                .ServiceDeleteInput.class), any())).thenReturn(response);
+        when(this.rendererServiceOperationsMock.serviceDelete(any(
+                org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210915.ServiceDeleteInput
+                    .class), any()))
+            .thenReturn(response);
         TempServiceDeleteInput input = ServiceDataUtils.buildTempServiceDeleteInput();
-        ServiceDeleteOutput rendereResponse = this.rendererServiceWrapperMock.performRenderer(input,
-                ServiceNotificationTypes.ServiceDeleteResult);
-        Assert.assertEquals(ResponseCodes.FINAL_ACK_NO,
-                rendereResponse.getConfigurationResponseCommon().getAckFinalIndicator());
-        Assert.assertEquals(ResponseCodes.RESPONSE_OK,
-                rendereResponse.getConfigurationResponseCommon().getResponseCode());
-        Assert.assertEquals("Renderer service delete in progress",
-                rendereResponse.getConfigurationResponseCommon().getResponseMessage());
+        ServiceDeleteOutput rendereResponse = this.rendererServiceWrapperMock
+            .performRenderer(input, ServiceNotificationTypes.ServiceDeleteResult);
+        assertEquals(
+            ResponseCodes.FINAL_ACK_NO,
+            rendereResponse.getConfigurationResponseCommon().getAckFinalIndicator());
+        assertEquals(ResponseCodes.RESPONSE_OK, rendereResponse.getConfigurationResponseCommon().getResponseCode());
+        assertEquals(
+            "Renderer service delete in progress",
+            rendereResponse.getConfigurationResponseCommon().getResponseMessage());
         verify(this.rendererServiceOperationsMock).serviceDelete(any(
                 org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210915.ServiceDeleteInput
                     .class), any());
     }
-
-    @After public void releaseMocks() throws Exception {
-        closeable.close();
-    }
-}
+}
\ No newline at end of file