Increase ServiceHandler Junit coverage 53/82253/1
authorRami <rmohamed.ext@orange.com>
Thu, 16 May 2019 07:19:56 +0000 (09:19 +0200)
committerguillaume.lambert <guillaume.lambert@orange.com>
Mon, 27 May 2019 14:25:32 +0000 (16:25 +0200)
Increase SH UT coverage for
- ModelMappingUtils
- MappingConstraint
- ServiceDataStoreOperation
- ServiceHandlerCompliancyCheck
- ServiceHandlerTxRxcheck

Change-Id: I37449064357888ea60b4c9bc7be62054da2c9c24
Signed-off-by: Rami <rmohamed.ext@orange.com>
servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/ModelMappingUtils.java
servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/MappingConstraintsTest.java
servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/ModelMappingUtilsTest.java
servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/service/ServiceDataStoreOperationsImplTest.java
servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/utils/ServiceDataUtils.java
servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/validation/checks/ServicehandlerCompliancyCheckTest.java
servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/validation/checks/ServicehandlerTxRxCheckTest.java [new file with mode: 0644]

index 102e676c0b7e5caba74dde771bc1fb2b5a709dfb..53675d4b7ca7f247478d4cd158cb213dcdf25035 100644 (file)
@@ -406,12 +406,13 @@ public final class ModelMappingUtils {
             servicePathBuilder.setServicePathName(serviceInput.getServiceName());
             servicePathBuilder.setServiceHandlerHeader(new ServiceHandlerHeaderBuilder()
                     .setRequestId(serviceInput.getSdncRequestHeader().getRequestId()).build());
+            if (output.getResponseParameters().getPathDescription() != null) {
+                PathDescriptionBuilder pathDescBuilder =
+                        new PathDescriptionBuilder(output.getResponseParameters().getPathDescription());
+                servicePathBuilder.setPathDescription(pathDescBuilder.build());
+            }
         }
-        if (output.getResponseParameters().getPathDescription() != null) {
-            PathDescriptionBuilder pathDescBuilder =
-                    new PathDescriptionBuilder(output.getResponseParameters().getPathDescription());
-            servicePathBuilder.setPathDescription(pathDescBuilder.build());
-        }
+
         return servicePathBuilder.build();
     }
 }
index 1fe4ee7de9274fcb7abfebb77677fa52bed7754a..bd64dce8932b7c596497ccaa34f2f13ba2a0f5bc 100644 (file)
@@ -11,6 +11,7 @@ import java.util.Arrays;
 import org.junit.Assert;
 import org.junit.Test;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev161014.constraints.co.routing.or.general.CoRoutingBuilder;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev161014.constraints.co.routing.or.general.GeneralBuilder;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev161014.routing.constraints.HardConstraints;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev161014.routing.constraints.HardConstraintsBuilder;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev161014.routing.constraints.SoftConstraints;
@@ -20,76 +21,89 @@ import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev161
 
 public class MappingConstraintsTest {
 
-    private MappingConstraints mappingConstraints;
-    private HardConstraints hardConstraints;
-    private SoftConstraints softConstraints;
-
+    private HardConstraints buildHardConstraintWithCoRouting() {
+        return new HardConstraintsBuilder()
+                .setCoRoutingOrGeneral(new CoRoutingBuilder()
+                        .setCoRouting(new org.opendaylight.yang.gen.v1.http.org.openroadm.routing
+                                .constrains.rev161014.constraints.co.routing.or.general.co.routing
+                                .CoRoutingBuilder().setExistingService(
+                                Arrays.asList("Some existing-service")).build())
+                        .build())
+                .setCustomerCode(Arrays.asList("Some customer-code"))
+                .build();
+    }
 
-    public MappingConstraintsTest() {
-        this.hardConstraints = new HardConstraintsBuilder()
-        .setCoRoutingOrGeneral(new CoRoutingBuilder()
-        .setCoRouting(new org.opendaylight.yang.gen.v1.http.org.openroadm.routing
-            .constrains.rev161014.constraints.co.routing.or.general.co.routing
-            .CoRoutingBuilder().setExistingService(
-            Arrays.asList("Some existing-service")).build())
-        .build())
-        .setCustomerCode(Arrays.asList("Some customer-code"))
-        .build();
+    private HardConstraints buildHardConstraintWithGeneral() {
+        return new HardConstraintsBuilder()
+                .setCoRoutingOrGeneral(new GeneralBuilder().build())
+                .setCustomerCode(Arrays.asList("Some customer-code"))
+                .build();
+    }
 
-        this.softConstraints = new SoftConstraintsBuilder()
-            .setCoRoutingOrGeneral(new CoRoutingBuilder()
-                .setCoRouting(new org.opendaylight.yang.gen.v1.http.org.openroadm.routing
-                    .constrains.rev161014.constraints.co.routing.or.general.co.routing
-                    .CoRoutingBuilder().setExistingService(
-                    Arrays.asList("Some existing-service")).build())
-                .build())
-            .setCustomerCode(Arrays.asList("Some customer-code"))
-            .build();
+    private SoftConstraints buildSoftConstraintWithCoRouting() {
+        return new SoftConstraintsBuilder()
+                .setCoRoutingOrGeneral(new CoRoutingBuilder()
+                        .setCoRouting(new org.opendaylight.yang.gen.v1.http.org.openroadm.routing
+                                .constrains.rev161014.constraints.co.routing.or.general.co.routing
+                                .CoRoutingBuilder().setExistingService(
+                                Arrays.asList("Some existing-service")).build())
+                        .build())
+                .setCustomerCode(Arrays.asList("Some customer-code"))
+                .build();
+    }
 
-        this.mappingConstraints = new MappingConstraints(hardConstraints, softConstraints);
+    @Test
+    public void serviceToServicePathConstraintsNullHardConstraints() {
+        MappingConstraints mappingConstraints = new MappingConstraints(null, buildSoftConstraintWithCoRouting());
+        mappingConstraints.serviceToServicePathConstarints();
+        Assert.assertNull(mappingConstraints.getServiceHardConstraints());
+        Assert.assertNull(mappingConstraints.getServicePathHardConstraints());
     }
 
     @Test
-    public void serviceToServicePathConstarintsNullHardConstraints() {
-        this.mappingConstraints = new MappingConstraints(null, softConstraints);
-        this.mappingConstraints.serviceToServicePathConstarints();
-        Assert.assertEquals(null, this.mappingConstraints.getServiceHardConstraints());
-        Assert.assertEquals(null, this.mappingConstraints.getServicePathHardConstraints());
+    public void serviceToServicePathConstraintsNullSoftConstraints() {
+        MappingConstraints mappingConstraints = new MappingConstraints(buildHardConstraintWithGeneral(), null);
+        mappingConstraints.serviceToServicePathConstarints();
+        Assert.assertNull(mappingConstraints.getServiceSoftConstraints());
+        Assert.assertNull(mappingConstraints.getServicePathSoftConstraints());
     }
 
     @Test
-    public void serviceToServicePathConstarintsNullSoftConstraints() {
-        this.mappingConstraints = new MappingConstraints(hardConstraints, null);
-        this.mappingConstraints.serviceToServicePathConstarints();
-        Assert.assertEquals(null, this.mappingConstraints.getServiceSoftConstraints());
-        Assert.assertEquals(null, this.mappingConstraints.getServicePathSoftConstraints());
+    public void serviceToServicePathConstraintsNullSoftConstraintsGeneral() {
+        MappingConstraints mappingConstraints = new MappingConstraints(buildHardConstraintWithCoRouting(), null);
+        mappingConstraints.serviceToServicePathConstarints();
+        Assert.assertNull(mappingConstraints.getServiceSoftConstraints());
+        Assert.assertNull(mappingConstraints.getServicePathSoftConstraints());
     }
 
     @Test
-    public void serviceToServicePathConstarintsNullConstraints() {
-        this.mappingConstraints = new MappingConstraints(hardConstraints, softConstraints);
-        this.mappingConstraints.setServiceHardConstraints(null);
-        this.mappingConstraints.setServiceSoftConstraints(null);
-        this.mappingConstraints.serviceToServicePathConstarints();
-        Assert.assertEquals(null, this.mappingConstraints.getServiceHardConstraints());
-        Assert.assertEquals(null, this.mappingConstraints.getServicePathHardConstraints());
-        Assert.assertEquals(null, this.mappingConstraints.getServiceSoftConstraints());
-        Assert.assertEquals(null, this.mappingConstraints.getServicePathSoftConstraints());
+    public void serviceToServicePathConstraintsNullConstraints() {
+        MappingConstraints mappingConstraints =
+            new MappingConstraints(buildHardConstraintWithCoRouting(), buildSoftConstraintWithCoRouting());
+        mappingConstraints.setServiceHardConstraints(null);
+        mappingConstraints.setServiceSoftConstraints(null);
+        mappingConstraints.serviceToServicePathConstarints();
+        Assert.assertNull(mappingConstraints.getServiceHardConstraints());
+        Assert.assertNull(mappingConstraints.getServicePathHardConstraints());
+        Assert.assertNull(mappingConstraints.getServiceSoftConstraints());
+        Assert.assertNull(mappingConstraints.getServicePathSoftConstraints());
     }
 
     @Test
-    public void serviceToServicePathConstarintsNotNullConstraints() {
-        this.mappingConstraints = new MappingConstraints(hardConstraints, softConstraints);
-        this.mappingConstraints.serviceToServicePathConstarints();
-        Assert.assertEquals(this.hardConstraints.getCoRoutingOrGeneral(), this.mappingConstraints
+    public void serviceToServicePathConstraintsNotNullConstraints() {
+        HardConstraints hardConstraints = buildHardConstraintWithCoRouting();
+        SoftConstraints softConstraints = buildSoftConstraintWithCoRouting();
+        MappingConstraints mappingConstraints = new MappingConstraints(hardConstraints, softConstraints);
+        mappingConstraints.serviceToServicePathConstarints();
+        Assert.assertEquals(hardConstraints.getCoRoutingOrGeneral(), mappingConstraints
             .getServiceHardConstraints().getCoRoutingOrGeneral());
-        Assert.assertEquals(softConstraints, this.mappingConstraints.getServiceSoftConstraints());
-        Assert.assertEquals(null, this.mappingConstraints.getServicePathSoftConstraints());
+        Assert.assertEquals(softConstraints, mappingConstraints.getServiceSoftConstraints());
+        Assert.assertNull(mappingConstraints.getServicePathSoftConstraints());
     }
 
     @Test
-    public void serviceToServicePathConstarintsParameterizedConstructor() {
-        this.mappingConstraints = new MappingConstraints(
+    public void serviceToServicePathConstraintsParameterizedConstructor() {
+        MappingConstraints mappingConstraints = new MappingConstraints(
             new org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface
             .routing.constraints.rev171017.routing.constraints.sp.HardConstraintsBuilder()
             .setCustomerCode(Arrays.asList("Some customer-code"))
@@ -111,14 +125,14 @@ public class MappingConstraintsTest {
                         .build())
                     .build()).build());
 
-        this.mappingConstraints.serviceToServicePathConstarints();
+        mappingConstraints.serviceToServicePathConstarints();
         Assert.assertEquals(new org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing
             .constraints.rev171017.constraints.sp.co.routing.or.general.CoRoutingBuilder()
             .setCoRouting(new org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing
                 .constraints.rev171017.constraints.sp.co.routing.or.general.co.routing.CoRoutingBuilder()
                 .setExistingService(Arrays.asList("Some existing-service"))
                 .build())
-            .build(), this.mappingConstraints.getServicePathHardConstraints().getCoRoutingOrGeneral());
+            .build(), mappingConstraints.getServicePathHardConstraints().getCoRoutingOrGeneral());
         Assert.assertEquals(new org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface
             .routing.constraints.rev171017.routing.constraints.sp.SoftConstraintsBuilder()
             .setCustomerCode(Arrays.asList("Some customer-code"))
@@ -128,8 +142,6 @@ public class MappingConstraintsTest {
                     .constraints.rev171017.constraints.sp.co.routing.or.general.co.routing.CoRoutingBuilder()
                     .setExistingService(Arrays.asList("Some existing-service"))
                     .build())
-                .build()).build(), this.mappingConstraints.getServicePathSoftConstraints());
-
+                .build()).build(), mappingConstraints.getServicePathSoftConstraints());
     }
-
 }
index d7e3731370a3110869930a318ac993ceefda5f35..c567b22f74e7ada186775e127ab3ea90412f4f64 100644 (file)
  */
 package org.opendaylight.transportpce.servicehandler;
 
+import com.google.common.util.concurrent.ListenableFuture;
+import com.google.common.util.concurrent.ListeningExecutorService;
+import com.google.common.util.concurrent.MoreExecutors;
+
 import java.time.OffsetDateTime;
 import java.time.ZoneOffset;
 import java.time.format.DateTimeFormatter;
 import java.util.Arrays;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Executors;
+
+import org.junit.After;
 import org.junit.Assert;
+import org.junit.Before;
 import org.junit.Test;
-import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
-import org.opendaylight.transportpce.pce.service.PathComputationService;
-import org.opendaylight.transportpce.pce.service.PathComputationServiceImpl;
-import org.opendaylight.transportpce.pce.utils.NotificationPublishServiceMock;
-import org.opendaylight.transportpce.servicehandler.service.PCEServiceWrapper;
+import org.opendaylight.transportpce.common.ResponseCodes;
 import org.opendaylight.transportpce.servicehandler.utils.ServiceDataUtils;
 import org.opendaylight.transportpce.test.AbstractTest;
 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev171017.PathComputationRequestOutput;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev171017.PathComputationRequestOutputBuilder;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.ConnectionType;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.configuration.response.common.ConfigurationResponseCommon;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.configuration.response.common.ConfigurationResponseCommonBuilder;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.sdnc.request.header.SdncRequestHeaderBuilder;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev161014.RpcStatus;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev161014.constraints.co.routing.or.general.CoRoutingBuilder;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev161014.routing.constraints.HardConstraintsBuilder;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev161014.routing.constraints.SoftConstraintsBuilder;
+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.ServiceReconfigureInput;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceReconfigureInputBuilder;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceRerouteInput;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceRerouteInputBuilder;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceRestorationInput;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceRestorationInputBuilder;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceRestorationOutput;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.TempServiceCreateInput;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.TempServiceCreateInputBuilder;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.TempServiceCreateOutput;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.service.list.Services;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.service.list.ServicesBuilder;
+import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.path.description.AToZDirectionBuilder;
+import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.path.description.ZToADirectionBuilder;
+import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev171016.response.parameters.sp.ResponseParameters;
+import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev171016.response.parameters.sp.ResponseParametersBuilder;
+import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev171016.response.parameters.sp.response.parameters.PathDescriptionBuilder;
 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev171017.service.path.list.ServicePaths;
 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev171017.service.path.list.ServicePathsBuilder;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DateAndTime;
+import org.opendaylight.yangtools.yang.common.RpcResult;
 
 
 public class ModelMappingUtilsTest extends AbstractTest {
 
-    private PathComputationRequestOutput pathComputationRequestOutput;
-    private ServiceReconfigureInput serviceReconfigureInput;
-    private PCEServiceWrapper pceServiceWrapper;
-
-    public ModelMappingUtilsTest() {
-        NotificationPublishService notificationPublishService = new NotificationPublishServiceMock();
-        PathComputationService pathComputationService = new PathComputationServiceImpl(getDataBroker(),
-            notificationPublishService);
-        pceServiceWrapper = new PCEServiceWrapper(pathComputationService, notificationPublishService);
-        this.pathComputationRequestOutput = pceServiceWrapper.performPCE(ServiceDataUtils.buildServiceCreateInput(),
-            true);
+    private ListeningExecutorService executorService;
+    private CountDownLatch endSignal;
+    private static final int NUM_THREADS = 5;
+    private boolean callbackRan;
+
+    @Before
+    public void setUp() {
+        executorService = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(NUM_THREADS));
+        endSignal = new CountDownLatch(1);
+        callbackRan = false;
+    }
+
+    @After
+    public void tearDown() {
+        executorService.shutdownNow();
+    }
+
+    private ServiceReconfigureInput buildServiceConfigurationInput() {
         DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssxxx");
         OffsetDateTime offsetDateTime = OffsetDateTime.now(ZoneOffset.UTC);
         OffsetDateTime offsetDateTime2 = offsetDateTime.plusDays(10);
-        this.serviceReconfigureInput = new ServiceReconfigureInputBuilder().setNewServiceName("service 1")
-        .setServiceName("service 1").setCommonId("common id").setConnectionType(ConnectionType.Service)
-        .setCustomer("customer").setCustomerContact("customer contact").setDueDate(new DateAndTime(
-            dtf.format(offsetDateTime)))
-        .setEndDate(new DateAndTime(dtf.format(offsetDateTime2)))
-        .setNcCode("nc node").setNciCode("nci node").setSecondaryNciCode("secondry").setOperatorContact("operator")
-        .setServiceAEnd(ServiceDataUtils.getServiceAEndBuildReconfigure().build())
-        .setServiceZEnd(ServiceDataUtils.getServiceZEndBuildReconfigure().build())
-        .setHardConstraints(new HardConstraintsBuilder()
-            .setCoRoutingOrGeneral(new CoRoutingBuilder()
-                .setCoRouting(new org.opendaylight.yang.gen.v1.http.org.openroadm.routing
-                    .constrains.rev161014.constraints.co.routing.or.general.co.routing
-                    .CoRoutingBuilder().setExistingService(
-                    Arrays.asList("Some existing-service")).build())
-                .build())
-            .setCustomerCode(Arrays.asList("Some customer-code"))
-            .build())
-        .setSoftConstraints(new SoftConstraintsBuilder()
-            .setCoRoutingOrGeneral(new CoRoutingBuilder()
-                .setCoRouting(new org.opendaylight.yang.gen.v1.http.org.openroadm.routing
-                    .constrains.rev161014.constraints.co.routing.or.general.co.routing
-                    .CoRoutingBuilder().setExistingService(
-                    Arrays.asList("Some existing-service")).build())
-                .build())
-            .setCustomerCode(Arrays.asList("Some customer-code"))
-            .build())
-        .build();
+        return new ServiceReconfigureInputBuilder().setNewServiceName("service 1")
+            .setServiceName("service 1").setCommonId("common id").setConnectionType(ConnectionType.Service)
+            .setCustomer("customer").setCustomerContact("customer contact").setDueDate(new DateAndTime(
+                    dtf.format(offsetDateTime)))
+            .setEndDate(new DateAndTime(dtf.format(offsetDateTime2)))
+            .setNcCode("nc node").setNciCode("nci node").setSecondaryNciCode("secondry").setOperatorContact("operator")
+            .setServiceAEnd(ServiceDataUtils.getServiceAEndBuildReconfigure().build())
+            .setServiceZEnd(ServiceDataUtils.getServiceZEndBuildReconfigure().build())
+            .setHardConstraints(new HardConstraintsBuilder()
+                        .setCoRoutingOrGeneral(new CoRoutingBuilder()
+                                .setCoRouting(new org.opendaylight.yang.gen.v1.http.org.openroadm.routing
+                                        .constrains.rev161014.constraints.co.routing.or.general.co.routing
+                                        .CoRoutingBuilder().setExistingService(
+                                        Arrays.asList("Some existing-service")).build())
+                                .build())
+                        .setCustomerCode(Arrays.asList("Some customer-code"))
+                        .build())
+                .setSoftConstraints(new SoftConstraintsBuilder()
+                        .setCoRoutingOrGeneral(new CoRoutingBuilder()
+                                .setCoRouting(new org.opendaylight.yang.gen.v1.http.org.openroadm.routing
+                                        .constrains.rev161014.constraints.co.routing.or.general.co.routing
+                                        .CoRoutingBuilder().setExistingService(
+                                        Arrays.asList("Some existing-service")).build())
+                                .build())
+                        .setCustomerCode(Arrays.asList("Some customer-code"))
+                        .build())
+                .build();
+    }
 
+    private PathComputationRequestOutput buildPathComputationOutput() {
+        ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder()
+                .setRequestId("request 1").setAckFinalIndicator(ResponseCodes.FINAL_ACK_NO)
+                .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("PCE calculation in progress").build();
+        ResponseParameters responseParameters = new ResponseParametersBuilder()
+            .setPathDescription(new PathDescriptionBuilder()
+                .setAToZDirection(new AToZDirectionBuilder().setAToZWavelengthNumber(1L).setRate(1L).build())
+                .setZToADirection(new ZToADirectionBuilder().setZToAWavelengthNumber(1L).setRate(1L).build()).build())
+            .build();
+        return new PathComputationRequestOutputBuilder().setConfigurationResponseCommon(configurationResponseCommon)
+            .setResponseParameters(responseParameters).build();
     }
 
     @Test
@@ -88,46 +141,290 @@ public class ModelMappingUtilsTest extends AbstractTest {
 
     @Test
     public void mappingServiceNotNullServiceReconfigureInput() {
-        Services services = ModelMappingUtils.mappingServices(null, serviceReconfigureInput);
+        Services services = ModelMappingUtils.mappingServices(null, buildServiceConfigurationInput());
         Assert.assertEquals("service 1", services.getServiceName());
     }
 
     @Test
     public void mappingServiceValid() {
         Services services = ModelMappingUtils.mappingServices(ServiceDataUtils.buildServiceCreateInput(),
-            serviceReconfigureInput);
+                null);
         Assert.assertEquals("service 1", services.getServiceName());
     }
 
     @Test
     public void mappingServicesPathNullServiceCreateInput() {
-        ServicePaths services = ModelMappingUtils.mappingServicePaths(null, this.pathComputationRequestOutput);
+        ServicePaths services = ModelMappingUtils.mappingServicePaths(null, buildPathComputationOutput());
         Assert.assertEquals(new ServicePathsBuilder().build(), services);
     }
 
-    /*@Test
-    public void mappingServicePathsValid() {
-        ServiceCreateInput input = new ServiceCreateInputBuilder(ServiceDataUtils.buildServiceCreateInput())
-            .setHardConstraints(new HardConstraintsBuilder()
-                .setCoRoutingOrGeneral(new CoRoutingBuilder()
-                    .setCoRouting(new org.opendaylight.yang.gen.v1.http.org.openroadm.routing
-                        .constrains.rev161014.constraints.co.routing.or.general.co.routing
-                        .CoRoutingBuilder().setExistingService(
-                        Arrays.asList("Some existing-service")).build())
-                    .build())
-                .setCustomerCode(Arrays.asList("Some customer-code"))
-                .build()).setSoftConstraints(new SoftConstraintsBuilder()
-                .setCoRoutingOrGeneral(new CoRoutingBuilder()
-                    .setCoRouting(new org.opendaylight.yang.gen.v1.http.org.openroadm.routing
-                        .constrains.rev161014.constraints.co.routing.or.general.co.routing
-                        .CoRoutingBuilder().setExistingService(
-                        Arrays.asList("Some existing-service")).build())
-                    .build())
-                .setCustomerCode(Arrays.asList("Some customer-code"))
-                .build()).build();
-        ServicePaths servicePaths = ModelMappingUtils.mappingServicePaths(input, serviceReconfigureInput,
-            this.pathComputationRequestOutput);
-        Assert.assertEquals("service 1", servicePaths.getServicePathName());
-    }*/
+    @Test
+    public void mappingServicePathWithServiceInputWithHardConstraints() {
+        ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInputWithHardConstraints();
+        ServiceInput serviceInput = new ServiceInput(createInput);
+        ServicePaths services = ModelMappingUtils.mappingServicePaths(serviceInput, buildPathComputationOutput());
+        Assert.assertEquals(serviceInput.getServiceName(), services.getServicePathName());
+        Assert.assertNotNull(services.getHardConstraints());
+    }
+
+    @Test
+    public void mappingServicePathWithServiceInputWithSoftConstraints() {
+        ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInputWithSoftConstraints();
+        ServiceInput serviceInput = new ServiceInput(createInput);
+        ServicePaths services = ModelMappingUtils.mappingServicePaths(serviceInput, buildPathComputationOutput());
+        Assert.assertEquals(serviceInput.getServiceName(), services.getServicePathName());
+        Assert.assertNotNull(services.getSoftConstraints());
+    }
+
+    @Test
+    public void createServiceDeleteInputWithServiceRerouteInput() {
+        ServiceRerouteInput serviceRerouteinput = new ServiceRerouteInputBuilder().setServiceName("reroute").build();
+        Services services = new ServicesBuilder()
+            .setSdncRequestHeader(new SdncRequestHeaderBuilder().setRequestId("123").build()).build();
+        org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017.ServiceDeleteInput
+            serviceDeleteInput =
+                    ModelMappingUtils.createServiceDeleteInput(serviceRerouteinput, services);
+        Assert.assertEquals("reroute", serviceDeleteInput.getServiceName());
+        Assert.assertEquals("123", serviceDeleteInput.getServiceHandlerHeader().getRequestId());
+    }
+
+    @Test
+    public void  createServiceDeleteInputWithServiceReconfigureInput() {
+        ServiceReconfigureInput serviceReconfigureInput = new  ServiceReconfigureInputBuilder()
+                .setServiceName("reconf").build();
+        org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017.ServiceDeleteInput
+            serviceDeleteInput =
+                    ModelMappingUtils.createServiceDeleteInput(serviceReconfigureInput);
+        Assert.assertEquals("reconf", serviceDeleteInput.getServiceName());
+        Assert.assertEquals("reconf-reconfigure", serviceDeleteInput.getServiceHandlerHeader().getRequestId());
+    }
+
+    @Test
+    public void createServiceDeleteInputWithServiceRestorationInput() {
+        Services services = new ServicesBuilder()
+            .setSdncRequestHeader(new SdncRequestHeaderBuilder().setRequestId("123").build()).build();
+        ServiceRestorationInput serviceRestorationInput =
+            new ServiceRestorationInputBuilder().setServiceName("rest").build();
+        org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017.ServiceDeleteInput
+            serviceDeleteInput =
+                    ModelMappingUtils.createServiceDeleteInput(serviceRestorationInput, services);
+        Assert.assertEquals("rest", serviceDeleteInput.getServiceName());
+        Assert.assertEquals("123", serviceDeleteInput.getServiceHandlerHeader().getRequestId());
+    }
+
+    @Test
+    public void createDeleteServiceReplyWithServiceDeleteInputWithSdncHeader()
+        throws ExecutionException, InterruptedException  {
+        ServiceDeleteInput input = new ServiceDeleteInputBuilder()
+                .setSdncRequestHeader(new SdncRequestHeaderBuilder().setRequestId("12").build()).build();
+        ListenableFuture<RpcResult<ServiceDeleteOutput>> serviceDeleteOutputF =
+            ModelMappingUtils.createDeleteServiceReply(input, "ack", "message", "200");
+        serviceDeleteOutputF.addListener(new Runnable() {
+            @Override
+            public void run() {
+                callbackRan = true;
+                endSignal.countDown();
+            }
+        }, executorService);
+
+        endSignal.await();
+        RpcResult<ServiceDeleteOutput> serviceDeleteOutput = serviceDeleteOutputF.get();
+        Assert.assertEquals("200", serviceDeleteOutput.getResult().getConfigurationResponseCommon().getResponseCode());
+        Assert.assertEquals(
+            "ack", serviceDeleteOutput.getResult().getConfigurationResponseCommon().getAckFinalIndicator());
+        Assert.assertEquals(
+            "message", serviceDeleteOutput.getResult().getConfigurationResponseCommon().getResponseMessage());
+        Assert.assertEquals("12", serviceDeleteOutput.getResult().getConfigurationResponseCommon().getRequestId());
+    }
+
+    @Test
+    public void createDeleteServiceReplyWithServiceDeleteInputWithoutSdncHeader()
+            throws ExecutionException, InterruptedException  {
+        ServiceDeleteInput input = new ServiceDeleteInputBuilder().build();
+        ListenableFuture<RpcResult<ServiceDeleteOutput>> serviceDeleteOutputF =
+            ModelMappingUtils.createDeleteServiceReply(input, "ack", "message", "200");
+        serviceDeleteOutputF.addListener(new Runnable() {
+            @Override
+            public void run() {
+                callbackRan = true;
+                endSignal.countDown();
+            }
+        }, executorService);
 
+        endSignal.await();
+        RpcResult<ServiceDeleteOutput> serviceDeleteOutput = serviceDeleteOutputF.get();
+        Assert.assertEquals("200", serviceDeleteOutput.getResult().getConfigurationResponseCommon().getResponseCode());
+        Assert.assertEquals(
+            "ack", serviceDeleteOutput.getResult().getConfigurationResponseCommon().getAckFinalIndicator());
+        Assert.assertEquals(
+            "message", serviceDeleteOutput.getResult().getConfigurationResponseCommon().getResponseMessage());
+        Assert.assertNull(serviceDeleteOutput.getResult().getConfigurationResponseCommon().getRequestId());
+    }
+
+    @Test
+    public void createCreateServiceReplyWithServiceCreatInputWithSdncRequestHeader()
+            throws ExecutionException, InterruptedException {
+        ServiceCreateInput input =
+            new ServiceCreateInputBuilder()
+                .setSdncRequestHeader(new SdncRequestHeaderBuilder().setRequestId("12").build()).build();
+        ListenableFuture<RpcResult<ServiceCreateOutput>> serviceCreatOutputF =
+            ModelMappingUtils.createCreateServiceReply(input, "ack", "message", "200");
+        serviceCreatOutputF.addListener(new Runnable() {
+            @Override
+            public void run() {
+                callbackRan = true;
+                endSignal.countDown();
+            }
+        }, executorService);
+
+        endSignal.await();
+        RpcResult<ServiceCreateOutput> serviceCreatOutput = serviceCreatOutputF.get();
+        Assert.assertEquals("200", serviceCreatOutput.getResult().getConfigurationResponseCommon().getResponseCode());
+        Assert.assertEquals(
+            "ack", serviceCreatOutput.getResult().getConfigurationResponseCommon().getAckFinalIndicator());
+        Assert.assertEquals(
+            "message", serviceCreatOutput.getResult().getConfigurationResponseCommon().getResponseMessage());
+        Assert.assertEquals("12", serviceCreatOutput.getResult().getConfigurationResponseCommon().getRequestId());
+    }
+
+    @Test
+    public void createCreateServiceReplyWithServiceCreatInputWithoutSdncRequestHeader()
+        throws ExecutionException, InterruptedException {
+        ServiceCreateInput input = new ServiceCreateInputBuilder().build();
+        ListenableFuture<RpcResult<ServiceCreateOutput>> serviceCreatOutputF =
+            ModelMappingUtils.createCreateServiceReply(input, "ack", "message", "200");
+        serviceCreatOutputF.addListener(new Runnable() {
+            @Override
+            public void run() {
+                callbackRan = true;
+                endSignal.countDown();
+            }
+        }, executorService);
+
+        endSignal.await();
+        RpcResult<ServiceCreateOutput> serviceCreatOutput = serviceCreatOutputF.get();
+        Assert.assertEquals("200", serviceCreatOutput.getResult().getConfigurationResponseCommon().getResponseCode());
+        Assert.assertEquals(
+            "ack", serviceCreatOutput.getResult().getConfigurationResponseCommon().getAckFinalIndicator());
+        Assert.assertEquals(
+            "message", serviceCreatOutput.getResult().getConfigurationResponseCommon().getResponseMessage());
+        Assert.assertNull(serviceCreatOutput.getResult().getConfigurationResponseCommon().getRequestId());
+    }
+
+    @Test
+    public void createCreateServiceReplyWithTempServiceCreatInputWithSdncRequestHeader()
+        throws ExecutionException, InterruptedException {
+        TempServiceCreateInput input =
+            new TempServiceCreateInputBuilder()
+                .setSdncRequestHeader(new SdncRequestHeaderBuilder().setRequestId("12").build()).build();
+        ListenableFuture<RpcResult<TempServiceCreateOutput>> serviceCreatOutputF =
+            ModelMappingUtils.createCreateServiceReply(input, "ack", "message", "200");
+        serviceCreatOutputF.addListener(new Runnable() {
+            @Override
+            public void run() {
+                callbackRan = true;
+                endSignal.countDown();
+            }
+        }, executorService);
+
+        endSignal.await();
+        RpcResult<TempServiceCreateOutput> serviceCreatOutput = serviceCreatOutputF.get();
+        Assert.assertEquals("200", serviceCreatOutput.getResult().getConfigurationResponseCommon().getResponseCode());
+        Assert.assertEquals(
+            "ack", serviceCreatOutput.getResult().getConfigurationResponseCommon().getAckFinalIndicator());
+        Assert.assertEquals(
+            "message", serviceCreatOutput.getResult().getConfigurationResponseCommon().getResponseMessage());
+        Assert.assertEquals("12", serviceCreatOutput.getResult().getConfigurationResponseCommon().getRequestId());
+    }
+
+    @Test
+    public void createCreateServiceReplyWithTempServiceCreatInputWithoutSdncRequestHeader()
+        throws ExecutionException, InterruptedException {
+        TempServiceCreateInput input = new TempServiceCreateInputBuilder().build();
+        ListenableFuture<RpcResult<TempServiceCreateOutput>> serviceCreatOutputF =
+            ModelMappingUtils.createCreateServiceReply(input, "ack", "message", "200");
+        serviceCreatOutputF.addListener(new Runnable() {
+            @Override
+            public void run() {
+                callbackRan = true;
+                endSignal.countDown();
+            }
+        }, executorService);
+
+        endSignal.await();
+        RpcResult<TempServiceCreateOutput> serviceCreatOutput = serviceCreatOutputF.get();
+        Assert.assertEquals("200", serviceCreatOutput.getResult().getConfigurationResponseCommon().getResponseCode());
+        Assert.assertEquals(
+            "ack", serviceCreatOutput.getResult().getConfigurationResponseCommon().getAckFinalIndicator());
+        Assert.assertEquals(
+            "message", serviceCreatOutput.getResult().getConfigurationResponseCommon().getResponseMessage());
+        Assert.assertNull(serviceCreatOutput.getResult().getConfigurationResponseCommon().getRequestId());
+    }
+
+    @Test
+    public void createCreateServiceReplyWithServiceFeasibilityCheckInputWithSdncRequestHeader()
+        throws ExecutionException, InterruptedException {
+        ServiceFeasibilityCheckInput input =
+            new ServiceFeasibilityCheckInputBuilder()
+                .setSdncRequestHeader(new SdncRequestHeaderBuilder().setRequestId("12").build()).build();
+        ListenableFuture<RpcResult<ServiceFeasibilityCheckOutput>> serviceCreatOutputF =
+            ModelMappingUtils.createCreateServiceReply(input, "ack", "message", "200");
+        serviceCreatOutputF.addListener(new Runnable() {
+            @Override
+            public void run() {
+                callbackRan = true;
+                endSignal.countDown();
+            }
+        }, executorService);
+
+        endSignal.await();
+        RpcResult<ServiceFeasibilityCheckOutput> serviceCreatOutput = serviceCreatOutputF.get();
+        Assert.assertEquals("200", serviceCreatOutput.getResult().getConfigurationResponseCommon().getResponseCode());
+        Assert.assertEquals(
+            "ack", serviceCreatOutput.getResult().getConfigurationResponseCommon().getAckFinalIndicator());
+        Assert.assertEquals(
+            "message", serviceCreatOutput.getResult().getConfigurationResponseCommon().getResponseMessage());
+        Assert.assertEquals("12", serviceCreatOutput.getResult().getConfigurationResponseCommon().getRequestId());
+    }
+
+    @Test
+    public void createCreateServiceReplyWithServiceFeasibilityCheckInputWithoutSdncRequestHeader()
+        throws ExecutionException, InterruptedException {
+        ServiceFeasibilityCheckInput input = new ServiceFeasibilityCheckInputBuilder().build();
+        ListenableFuture<RpcResult<ServiceFeasibilityCheckOutput>> serviceCreatOutputF =
+            ModelMappingUtils.createCreateServiceReply(input, "ack", "message", "200");
+        serviceCreatOutputF.addListener(new Runnable() {
+            @Override
+            public void run() {
+                callbackRan = true;
+                endSignal.countDown();
+            }
+        }, executorService);
+
+        endSignal.await();
+        RpcResult<ServiceFeasibilityCheckOutput> serviceCreatOutput = serviceCreatOutputF.get();
+        Assert.assertEquals("200", serviceCreatOutput.getResult().getConfigurationResponseCommon().getResponseCode());
+        Assert.assertEquals(
+            "ack", serviceCreatOutput.getResult().getConfigurationResponseCommon().getAckFinalIndicator());
+        Assert.assertEquals(
+            "message", serviceCreatOutput.getResult().getConfigurationResponseCommon().getResponseMessage());
+        Assert.assertNull(serviceCreatOutput.getResult().getConfigurationResponseCommon().getRequestId());
+    }
+
+    @Test
+    public void testCreateRestoreServiceReply() throws ExecutionException, InterruptedException {
+        ListenableFuture<RpcResult<ServiceRestorationOutput>> serviceRestorationOutputF =
+            ModelMappingUtils.createRestoreServiceReply("message", RpcStatus.Failed);
+        serviceRestorationOutputF.addListener(new Runnable() {
+            @Override
+            public void run() {
+                callbackRan = true;
+                endSignal.countDown();
+            }
+        }, executorService);
+
+        endSignal.await();
+        RpcResult<ServiceRestorationOutput> serviceRestorationOutput = serviceRestorationOutputF.get();
+        Assert.assertEquals("message", serviceRestorationOutput.getResult().getStatusMessage());
+    }
 }
index 4c98e4b84b2f447b78860655862a27827a53818b..dc7c46d69e9069f3c2c97751396d1222519bf92e 100644 (file)
@@ -37,7 +37,6 @@ public class ServiceDataStoreOperationsImplTest extends AbstractTest {
 
     private ServiceDataStoreOperationsImpl serviceDataStoreOperations;
 
-
     @Before
     public void init() {
         DataBroker dataBroker = this.getNewDataBroker();
index 5c1dd3c6a8efcf6328fe82f54e3b4289a56cfaaa..01862ac0b8f008d63f6efbedc879f82def37de25 100644 (file)
@@ -39,6 +39,8 @@ import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev1
 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.service.endpoint.TxDirection;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.service.lgx.LgxBuilder;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.service.port.PortBuilder;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev161014.routing.constraints.HardConstraintsBuilder;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev161014.routing.constraints.SoftConstraintsBuilder;
 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.ServiceDeleteInput;
@@ -96,6 +98,60 @@ public final class ServiceDataUtils {
         return builtInput.build();
     }
 
+    public static ServiceCreateInput buildServiceCreateInputWithHardConstraints() {
+
+        ServiceCreateInputBuilder builtInput = new ServiceCreateInputBuilder();
+        org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.service.create.input
+                .ServiceAEnd serviceAEnd = getServiceAEndBuild()
+                .build();
+        org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.service.create.input
+                .ServiceZEnd serviceZEnd = new org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.service
+                .create.input.ServiceZEndBuilder()
+                .setClli("clli").setServiceFormat(ServiceFormat.OC).setServiceRate((long) 1).setNodeId("XPONDER-3-2")
+                .setTxDirection(getTxDirection())
+                .setRxDirection(getRxDirection())
+                .build();
+
+        builtInput.setCommonId("commonId");
+        builtInput.setConnectionType(ConnectionType.Service);
+        builtInput.setCustomer("Customer");
+        builtInput.setServiceName("service 1");
+        builtInput.setServiceAEnd(serviceAEnd);
+        builtInput.setServiceZEnd(serviceZEnd);
+        builtInput.setSdncRequestHeader(new SdncRequestHeaderBuilder().setRequestId("request 1")
+                .setRpcAction(RpcActions.ServiceCreate).setNotificationUrl("notification url").build());
+        builtInput.setHardConstraints(new HardConstraintsBuilder().build());
+
+        return builtInput.build();
+    }
+
+    public static ServiceCreateInput buildServiceCreateInputWithSoftConstraints() {
+
+        ServiceCreateInputBuilder builtInput = new ServiceCreateInputBuilder();
+        org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.service.create.input
+                .ServiceAEnd serviceAEnd = getServiceAEndBuild()
+                .build();
+        org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.service.create.input
+                .ServiceZEnd serviceZEnd = new org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.service
+                .create.input.ServiceZEndBuilder()
+                .setClli("clli").setServiceFormat(ServiceFormat.OC).setServiceRate((long) 1).setNodeId("XPONDER-3-2")
+                .setTxDirection(getTxDirection())
+                .setRxDirection(getRxDirection())
+                .build();
+
+        builtInput.setCommonId("commonId");
+        builtInput.setConnectionType(ConnectionType.Service);
+        builtInput.setCustomer("Customer");
+        builtInput.setServiceName("service 1");
+        builtInput.setServiceAEnd(serviceAEnd);
+        builtInput.setServiceZEnd(serviceZEnd);
+        builtInput.setSdncRequestHeader(new SdncRequestHeaderBuilder().setRequestId("request 1")
+                .setRpcAction(RpcActions.ServiceCreate).setNotificationUrl("notification url").build());
+        builtInput.setSoftConstraints(new SoftConstraintsBuilder().build());
+
+        return builtInput.build();
+    }
+
     public static PathComputationRequestInput createPceRequestInput(ServiceCreateInput input) {
         MappingConstraints mappingConstraints =
                 new MappingConstraints(input.getHardConstraints(), input.getSoftConstraints());
index 3c9c0aac3758999dc08e900099979bba8977e8ea..e5a986bad91844017cd48f2bd3741565f89d5de5 100644 (file)
@@ -23,9 +23,69 @@ public class ServicehandlerCompliancyCheckTest {
         ComplianceCheckResult result = ServicehandlerCompliancyCheck.check("service 1",
             new SdncRequestHeaderBuilder().setRequestId("1").setRequestSystemId("1").setNotificationUrl("1")
             .setRpcAction(RpcActions.ServiceCreate).build(),
-            ConnectionType.Service,RpcActions.ServiceCreate, true, false);
+            ConnectionType.Service,RpcActions.ServiceCreate, false, false);
 
         Assert.assertEquals("", result.getMessage());
-        Assert.assertEquals(true, result.hasPassed());
+        Assert.assertTrue(result.hasPassed());
+    }
+
+    @Test
+    public void checkServiceNameNull() {
+        ComplianceCheckResult result = ServicehandlerCompliancyCheck.check(null, null,
+                ConnectionType.Service,null, false, false);
+
+        Assert.assertEquals("Service Name (common-id for Temp service) is not set", result.getMessage());
+        Assert.assertFalse(result.hasPassed());
+    }
+
+    @Test
+    public void checkConTypeFalseAndNull() {
+        ComplianceCheckResult result = ServicehandlerCompliancyCheck.check("service 1", null,
+                null,null, true, false);
+        Assert.assertEquals("Service ConnectionType is not set", result.getMessage());
+        Assert.assertFalse(result.hasPassed());
+    }
+
+    @Test
+    public void checkSdncRequestHeaderNull() {
+        ComplianceCheckResult result = ServicehandlerCompliancyCheck.check("service 1", null,
+                ConnectionType.Service,null, true, true);
+
+        Assert.assertEquals("Service sndc-request-header is not set ", result.getMessage());
+        Assert.assertFalse(result.hasPassed());
+    }
+
+    @Test
+    public void checkRequestIdEmptyString() {
+        ComplianceCheckResult result = ServicehandlerCompliancyCheck.check("service 1",
+                new SdncRequestHeaderBuilder().setRequestId("")
+                        .setRpcAction(RpcActions.ServiceCreate).build(),
+                ConnectionType.Service, RpcActions.ServiceCreate, true, true);
+
+        Assert.assertEquals("Service sdncRequestHeader 'request-id' is not set", result.getMessage());
+        Assert.assertFalse(result.hasPassed());
+    }
+
+    @Test
+    public void checkDifferentAction() {
+        ComplianceCheckResult result = ServicehandlerCompliancyCheck.check("service 1",
+                new SdncRequestHeaderBuilder().setRequestId("1")
+                        .setRpcAction(RpcActions.ServiceCreate).build(),
+                ConnectionType.Service, RpcActions.NetworkReOptimization, true, true);
+
+        Assert.assertEquals("Service sdncRequestHeader rpc-action '" + RpcActions.ServiceCreate.name()
+                + "' not equal to '"
+                + RpcActions.NetworkReOptimization.name() + "'", result.getMessage());
+        Assert.assertFalse(result.hasPassed());
+    }
+
+    @Test
+    public void checkServiceActionNull() {
+        ComplianceCheckResult result = ServicehandlerCompliancyCheck.check("service 1",
+                new SdncRequestHeaderBuilder().setRequestId("1").build(),
+                ConnectionType.Service, RpcActions.NetworkReOptimization, true, true);
+
+        Assert.assertEquals("Service sndc-request-header 'rpc-action' is not set ", result.getMessage());
+        Assert.assertFalse(result.hasPassed());
     }
 }
diff --git a/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/validation/checks/ServicehandlerTxRxCheckTest.java b/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/validation/checks/ServicehandlerTxRxCheckTest.java
new file mode 100644 (file)
index 0000000..6e9aac9
--- /dev/null
@@ -0,0 +1,158 @@
+/*
+ * Copyright © 2019 Orange, Inc. 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,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.transportpce.servicehandler.validation.checks;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.opendaylight.transportpce.servicehandler.ServiceEndpointType;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.ServiceFormat;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.service.ServiceAEndBuilder;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.service.endpoint.RxDirectionBuilder;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.service.endpoint.TxDirectionBuilder;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.service.lgx.LgxBuilder;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.service.port.PortBuilder;
+
+public class ServicehandlerTxRxCheckTest {
+
+    @Test
+    public void checkPortShouldBeFalseForNullPort() {
+        Assert.assertFalse(ServicehandlerTxRxCheck.checkPort(null));
+    }
+
+    @Test
+    public void checkLgxShouldBeFalseForNullLgx() {
+        Assert.assertFalse(ServicehandlerTxRxCheck.checkLgx(null));
+    }
+
+    @Test
+    public void checkTxOrRxInfoForNullTx() {
+        ComplianceCheckResult result = ServicehandlerTxRxCheck.checkTxOrRxInfo(null, null);
+
+        Assert.assertFalse(result.hasPassed());
+        Assert.assertEquals("Service TxDirection is not correctly set", result.getMessage());
+    }
+
+    @Test
+    public void checkTxOrRxInfoForNullTxPort() {
+        ComplianceCheckResult result = ServicehandlerTxRxCheck
+                .checkTxOrRxInfo(new TxDirectionBuilder().build(), null);
+
+        Assert.assertFalse(result.hasPassed());
+        Assert.assertEquals("Service TxDirection Port is not correctly set", result.getMessage());
+    }
+
+    @Test
+    public void checkTxOrRxInfoForNullTxLgx() {
+        ComplianceCheckResult result = ServicehandlerTxRxCheck
+            .checkTxOrRxInfo(new TxDirectionBuilder()
+                .setPort(new PortBuilder().setPortDeviceName("q")
+                    .setPortName("n").setPortRack("r").setPortShelf("s").setPortType("t").build()).build(), null);
+
+        Assert.assertFalse(result.hasPassed());
+        Assert.assertEquals("Service TxDirection Lgx is not correctly set", result.getMessage());
+    }
+
+    @Test
+    public void checkTxOrRxInfoForNullRx() {
+        ComplianceCheckResult result = ServicehandlerTxRxCheck
+                .checkTxOrRxInfo(new TxDirectionBuilder()
+                        .setPort(new PortBuilder().setPortDeviceName("q")
+                                .setPortName("n").setPortRack("r").setPortShelf("s").setPortType("t").build())
+                        .setLgx(new LgxBuilder().setLgxDeviceName("l")
+                                .setLgxPortName("p").setLgxPortRack("r").setLgxPortShelf("s").build()).build(), null);
+
+        Assert.assertFalse(result.hasPassed());
+        Assert.assertEquals("Service RxDirection is not correctly set", result.getMessage());
+    }
+
+    @Test
+    public void checkTxOrRxInfoForNullRxPort() {
+        ComplianceCheckResult result = ServicehandlerTxRxCheck
+            .checkTxOrRxInfo(new TxDirectionBuilder()
+                .setPort(new PortBuilder().setPortDeviceName("q")
+                .setPortName("n").setPortRack("r").setPortShelf("s").setPortType("t").build())
+                .setLgx(new LgxBuilder().setLgxDeviceName("l")
+                .setLgxPortName("p").setLgxPortRack("r").setLgxPortShelf("s").build()).build(),
+            new RxDirectionBuilder().build());
+
+        Assert.assertFalse(result.hasPassed());
+        Assert.assertEquals("Service RxDirection Port is not correctly set", result.getMessage());
+    }
+
+    @Test
+    public void checkTxOrRxInfoForNullRxLgx() {
+        ComplianceCheckResult result = ServicehandlerTxRxCheck
+                .checkTxOrRxInfo(new TxDirectionBuilder()
+                        .setPort(new PortBuilder().setPortDeviceName("q")
+                                .setPortName("n").setPortRack("r").setPortShelf("s").setPortType("t").build())
+                        .setLgx(new LgxBuilder().setLgxDeviceName("l")
+                                .setLgxPortName("p").setLgxPortRack("r").setLgxPortShelf("s").build()).build(),
+                        new RxDirectionBuilder().setPort(new PortBuilder().setPortDeviceName("q")
+                                .setPortName("n").setPortRack("r").setPortShelf("s").setPortType("t").build()).build());
+
+        Assert.assertFalse(result.hasPassed());
+        Assert.assertEquals("Service RxDirection Lgx is not correctly set", result.getMessage());
+    }
+
+    @Test
+    public void checkForServiceEndNull() {
+        ComplianceCheckResult result = ServicehandlerTxRxCheck.check(null, ServiceEndpointType.SERVICEAEND);
+
+        Assert.assertFalse(result.hasPassed());
+        Assert.assertEquals(ServiceEndpointType.SERVICEAEND + " is not set", result.getMessage());
+    }
+
+    @Test
+    public void checkForServiceRateNull() {
+        ComplianceCheckResult result =
+            ServicehandlerTxRxCheck.check(new ServiceAEndBuilder().build(), ServiceEndpointType.SERVICEAEND);
+
+        Assert.assertFalse(result.hasPassed());
+        Assert.assertEquals("Service " + ServiceEndpointType.SERVICEAEND + " rate is not set", result.getMessage());
+    }
+
+    @Test
+    public void checkForServiceRateEquals0() {
+        ComplianceCheckResult result = ServicehandlerTxRxCheck.check(
+            new ServiceAEndBuilder().setServiceRate(0L).build(), ServiceEndpointType.SERVICEAEND);
+
+        Assert.assertFalse(result.hasPassed());
+        Assert.assertEquals("Service " + ServiceEndpointType.SERVICEAEND + " rate is not set", result.getMessage());
+    }
+
+    @Test
+    public void checkForServiceFormatNull() {
+        ComplianceCheckResult result = ServicehandlerTxRxCheck.check(
+            new ServiceAEndBuilder().setServiceRate(3L).build(), ServiceEndpointType.SERVICEAEND);
+
+        Assert.assertFalse(result.hasPassed());
+        Assert.assertEquals("Service " + ServiceEndpointType.SERVICEAEND + " format is not set", result.getMessage());
+    }
+
+    @Test
+    public void checkForClliEmpty() {
+        ComplianceCheckResult result = ServicehandlerTxRxCheck.check(new ServiceAEndBuilder()
+            .setServiceRate(3L).setClli("").setServiceFormat(ServiceFormat.Ethernet).build(),
+            ServiceEndpointType.SERVICEAEND);
+
+        Assert.assertFalse(result.hasPassed());
+        Assert.assertEquals(
+            "Service" + ServiceEndpointType.SERVICEAEND + " clli format is not set", result.getMessage());
+    }
+
+    @Test
+    public void checkForFailTxOrRx() {
+        ComplianceCheckResult result = ServicehandlerTxRxCheck.check(new ServiceAEndBuilder()
+            .setServiceRate(3L).setClli("cc").setServiceFormat(ServiceFormat.Ethernet).build(),
+            ServiceEndpointType.SERVICEAEND);
+
+        Assert.assertFalse(result.hasPassed());
+        Assert.assertEquals("Service TxDirection is not correctly set", result.getMessage());
+    }
+}