UT for ServicehandlerImpl update
[transportpce.git] / servicehandler / src / test / java / org / opendaylight / transportpce / servicehandler / impl / ServicehandlerImplTest.java
index 3dd14172827a3ac270f7608f47146005bf3fb207..793402ac6be0c53250077e971011c319209370de 100644 (file)
@@ -7,10 +7,17 @@
  */
 package org.opendaylight.transportpce.servicehandler.impl;
 
+import static org.mockito.ArgumentMatchers.any;
+
 import com.google.common.util.concurrent.Futures;
 import com.google.common.util.concurrent.ListenableFuture;
 import com.google.common.util.concurrent.ListeningExecutorService;
 import com.google.common.util.concurrent.MoreExecutors;
+
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Executors;
+
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
@@ -27,16 +34,18 @@ import org.opendaylight.transportpce.servicehandler.listeners.RendererListenerIm
 import org.opendaylight.transportpce.servicehandler.service.ServiceDataStoreOperationsImpl;
 import org.opendaylight.transportpce.servicehandler.utils.ServiceDataUtils;
 import org.opendaylight.transportpce.test.AbstractTest;
-import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.*;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceCreateInput;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceCreateInputBuilder;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceCreateOutput;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceDeleteInput;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceDeleteInputBuilder;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceDeleteOutput;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceFeasibilityCheckInput;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceFeasibilityCheckInputBuilder;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceFeasibilityCheckOutput;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.service.delete.input.ServiceDeleteReqInfoBuilder;
 import org.opendaylight.yangtools.yang.common.RpcResult;
 
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.Executors;
-
-import static org.mockito.ArgumentMatchers.any;
-
 public class ServicehandlerImplTest extends AbstractTest  {
 
     @Mock
@@ -69,9 +78,11 @@ public class ServicehandlerImplTest extends AbstractTest  {
 
     @Test
     public void createServiceShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException {
-        ServicehandlerImpl servicehandlerImpl = new ServicehandlerImpl(getNewDataBroker(), pathComputationService, rendererServiceOperations,
+        ServicehandlerImpl servicehandlerImpl =
+            new ServicehandlerImpl(getNewDataBroker(), pathComputationService, rendererServiceOperations,
                 notificationPublishService, pceListenerImpl, rendererListenerImpl, null);
-        ListenableFuture<RpcResult<ServiceCreateOutput>> result =  servicehandlerImpl.serviceCreate(new ServiceCreateInputBuilder().build());
+        ListenableFuture<RpcResult<ServiceCreateOutput>> result =
+            servicehandlerImpl.serviceCreate(new ServiceCreateInputBuilder().build());
         result.addListener(new Runnable() {
             @Override
             public void run() {
@@ -83,14 +94,17 @@ public class ServicehandlerImplTest extends AbstractTest  {
         endSignal.await();
 
         RpcResult<ServiceCreateOutput> rpcResult = result.get();
-        Assert.assertEquals(ResponseCodes.RESPONSE_FAILED, rpcResult.getResult().getConfigurationResponseCommon().getResponseCode());
+        Assert.assertEquals(
+            ResponseCodes.RESPONSE_FAILED, rpcResult.getResult().getConfigurationResponseCommon().getResponseCode());
     }
 
     @Test
-    public void createServiceShouldBeSuccessfulWhenPreformPCESuccessful() throws ExecutionException, InterruptedException {
+    public void createServiceShouldBeSuccessfulWhenPreformPCESuccessful()
+        throws ExecutionException, InterruptedException {
         ServiceCreateInput input = ServiceDataUtils.buildServiceCreateInput();
         Mockito.when(pathComputationService.pathComputationRequest(any())).thenReturn(Futures.immediateFuture(any()));
-        ServicehandlerImpl servicehandlerImpl = new ServicehandlerImpl(getNewDataBroker(), pathComputationService, rendererServiceOperations,
+        ServicehandlerImpl servicehandlerImpl =
+            new ServicehandlerImpl(getNewDataBroker(), pathComputationService, rendererServiceOperations,
                 notificationPublishService, pceListenerImpl, rendererListenerImpl, null);
         ListenableFuture<RpcResult<ServiceCreateOutput>> result =  servicehandlerImpl.serviceCreate(input);
         result.addListener(new Runnable() {
@@ -104,14 +118,17 @@ public class ServicehandlerImplTest extends AbstractTest  {
         endSignal.await();
 
         RpcResult<ServiceCreateOutput> rpcResult = result.get();
-        Assert.assertEquals(ResponseCodes.RESPONSE_OK, rpcResult.getResult().getConfigurationResponseCommon().getResponseCode());
+        Assert.assertEquals(
+            ResponseCodes.RESPONSE_OK, rpcResult.getResult().getConfigurationResponseCommon().getResponseCode());
     }
 
     @Test
     public void deleteServiceShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException {
-        ServicehandlerImpl servicehandlerImpl = new ServicehandlerImpl(getNewDataBroker(), pathComputationService, rendererServiceOperations,
+        ServicehandlerImpl servicehandlerImpl =
+            new ServicehandlerImpl(getNewDataBroker(), pathComputationService, rendererServiceOperations,
                 notificationPublishService, pceListenerImpl, rendererListenerImpl, null);
-        ListenableFuture<RpcResult<ServiceDeleteOutput>> result = servicehandlerImpl.serviceDelete(new ServiceDeleteInputBuilder()
+        ListenableFuture<RpcResult<ServiceDeleteOutput>> result =
+             servicehandlerImpl.serviceDelete(new ServiceDeleteInputBuilder()
                 .setServiceDeleteReqInfo(new ServiceDeleteReqInfoBuilder().setServiceName("").build()).build());
         result.addListener(new Runnable() {
             @Override
@@ -124,13 +141,15 @@ public class ServicehandlerImplTest extends AbstractTest  {
         endSignal.await();
 
         RpcResult<ServiceDeleteOutput> rpcResult = result.get();
-        Assert.assertEquals(ResponseCodes.RESPONSE_FAILED, rpcResult.getResult().getConfigurationResponseCommon().getResponseCode());
+        Assert.assertEquals(
+            ResponseCodes.RESPONSE_FAILED, rpcResult.getResult().getConfigurationResponseCommon().getResponseCode());
     }
 
     @Test
     public void deleteServiceShouldBeFailedWithNonExistService() throws ExecutionException, InterruptedException {
         ServiceDeleteInput input = ServiceDataUtils.buildServiceDeleteInput();
-        ServicehandlerImpl servicehandlerImpl = new ServicehandlerImpl(getNewDataBroker(), pathComputationService, rendererServiceOperations,
+        ServicehandlerImpl servicehandlerImpl =
+            new ServicehandlerImpl(getNewDataBroker(), pathComputationService, rendererServiceOperations,
                 notificationPublishService, pceListenerImpl, rendererListenerImpl, null);
         ListenableFuture<RpcResult<ServiceDeleteOutput>> result = servicehandlerImpl.serviceDelete(input);
         result.addListener(new Runnable() {
@@ -144,14 +163,16 @@ public class ServicehandlerImplTest extends AbstractTest  {
         endSignal.await();
 
         RpcResult<ServiceDeleteOutput> rpcResult = result.get();
-        Assert.assertEquals(ResponseCodes.RESPONSE_FAILED, rpcResult.getResult().getConfigurationResponseCommon().getResponseCode());
+        Assert.assertEquals(
+            ResponseCodes.RESPONSE_FAILED, rpcResult.getResult().getConfigurationResponseCommon().getResponseCode());
     }
 
     @Test
     public void deleteServiceShouldBeSuccessForExistingService() throws ExecutionException, InterruptedException {
         DataBroker dataBroker = getNewDataBroker();
         Mockito.when(rendererServiceOperations.serviceDelete(any())).thenReturn(Futures.immediateFuture(any()));
-        ServicehandlerImpl servicehandlerImpl = new ServicehandlerImpl(dataBroker, pathComputationService, rendererServiceOperations,
+        ServicehandlerImpl servicehandlerImpl =
+            new ServicehandlerImpl(dataBroker, pathComputationService, rendererServiceOperations,
                 notificationPublishService, pceListenerImpl, rendererListenerImpl, null);
         ServiceDataStoreOperationsImpl serviceDataStoreOperations = new ServiceDataStoreOperationsImpl(dataBroker);
         ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput();
@@ -169,6 +190,58 @@ public class ServicehandlerImplTest extends AbstractTest  {
         endSignal.await();
 
         RpcResult<ServiceDeleteOutput> rpcResult = result.get();
-        Assert.assertEquals(ResponseCodes.RESPONSE_OK, rpcResult.getResult().getConfigurationResponseCommon().getResponseCode());
+        Assert.assertEquals(
+            ResponseCodes.RESPONSE_OK, rpcResult.getResult().getConfigurationResponseCommon().getResponseCode());
+    }
+
+
+    @Test
+    public void serviceFeasibilityCheckShouldBeFailedWithEmptyInput() throws ExecutionException, InterruptedException {
+        ServicehandlerImpl servicehandlerImpl =
+                new ServicehandlerImpl(getNewDataBroker(), pathComputationService, rendererServiceOperations,
+                        notificationPublishService, pceListenerImpl, rendererListenerImpl, null);
+        ListenableFuture<RpcResult<ServiceFeasibilityCheckOutput>> result =
+                servicehandlerImpl.serviceFeasibilityCheck(new ServiceFeasibilityCheckInputBuilder().build());
+        result.addListener(new Runnable() {
+            @Override
+            public void run() {
+                callbackRan = true;
+                endSignal.countDown();
+            }
+        }, executorService);
+
+        endSignal.await();
+
+        RpcResult<ServiceFeasibilityCheckOutput> rpcResult = result.get();
+        Assert.assertEquals(
+            ResponseCodes.RESPONSE_FAILED, rpcResult.getResult().getConfigurationResponseCommon().getResponseCode());
+    }
+
+    @Test
+    public void serviceFeasibilityCheckShouldBeSuccessfulWhenPreformPCESuccessful()
+            throws ExecutionException, InterruptedException {
+        ServiceFeasibilityCheckInput input = ServiceDataUtils.buildServiceFeasibilityCheckInput();
+        Mockito.when(pathComputationService.pathComputationRequest(any())).thenReturn(Futures.immediateFuture(any()));
+        ServicehandlerImpl servicehandlerImpl =
+                new ServicehandlerImpl(getNewDataBroker(), pathComputationService, rendererServiceOperations,
+                        notificationPublishService, pceListenerImpl, rendererListenerImpl, null);
+        ListenableFuture<RpcResult<ServiceFeasibilityCheckOutput>> result =
+            servicehandlerImpl.serviceFeasibilityCheck(input);
+        result.addListener(new Runnable() {
+            @Override
+            public void run() {
+                callbackRan = true;
+                endSignal.countDown();
+            }
+        }, executorService);
+
+        endSignal.await();
+
+        RpcResult<ServiceFeasibilityCheckOutput> rpcResult = result.get();
+        Assert.assertEquals(
+                ResponseCodes.RESPONSE_OK, rpcResult.getResult().getConfigurationResponseCommon().getResponseCode());
     }
+
+
+
 }