Add pce-constraint-mode enum in pce yang model
[transportpce.git] / servicehandler / src / test / java / org / opendaylight / transportpce / servicehandler / service / ServiceDataStoreOperationsImplTest.java
index dc7c46d69e9069f3c2c97751396d1222519bf92e..70981716f45ac879ba0ef567a8cfea46a9cd8e58 100644 (file)
  */
 package org.opendaylight.transportpce.servicehandler.service;
 
-import java.util.Optional;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.opendaylight.transportpce.servicehandler.service.ServiceDataStoreOperationsImpl.LogMessages;
 
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import java.util.Optional;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.opendaylight.mdsal.binding.api.DataBroker;
 import org.opendaylight.transportpce.common.OperationResult;
 import org.opendaylight.transportpce.common.ResponseCodes;
 import org.opendaylight.transportpce.servicehandler.ServiceInput;
 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.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.types.rev161014.State;
-import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceCreateInput;
-import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.TempServiceCreateInput;
-import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.service.list.Services;
-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.opendaylight.transportpce.pce.rev230925.PathComputationRequestOutput;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev230925.PathComputationRequestOutputBuilder;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev230925.service.path.rpc.result.PathDescription;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev230526.configuration.response.common.ConfigurationResponseCommon;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev230526.configuration.response.common.ConfigurationResponseCommonBuilder;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.common.state.types.rev191129.State;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.equipment.states.types.rev191129.AdminStates;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ServiceCreateInput;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.TempServiceCreateInput;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.service.list.Services;
+import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev230501.path.description.AToZDirectionBuilder;
+import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev230501.path.description.ZToADirectionBuilder;
+import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev220118.response.parameters.sp.ResponseParameters;
+import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev220118.response.parameters.sp.ResponseParametersBuilder;
+import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev220118.response.parameters.sp.response.parameters.PathDescriptionBuilder;
+import org.opendaylight.yangtools.yang.common.Uint32;
+
+//writeOrModifyOrDeleteServiceList deprecated method should not raise warnings in tests
+@SuppressWarnings("deprecation")
 public class ServiceDataStoreOperationsImplTest extends AbstractTest {
 
     private ServiceDataStoreOperationsImpl serviceDataStoreOperations;
 
-    @Before
-    public void init() {
+    @BeforeEach
+    void init() {
         DataBroker dataBroker = this.getNewDataBroker();
         this.serviceDataStoreOperations = new ServiceDataStoreOperationsImpl(dataBroker);
     }
 
     @Test
-    public void modifyIfServiceNotPresent() {
-        OperationResult result =
-                this.serviceDataStoreOperations.modifyService("service 1", State.InService, State.InService);
-        Assert.assertFalse(result.isSuccess());
-        Assert.assertEquals("Service " + "service 1" + " is not present!", result.getResultMessage());
+    void modifyIfServiceNotPresent() {
+        OperationResult result = this.serviceDataStoreOperations
+            .modifyService("service 1", State.InService, AdminStates.InService);
+        assertFalse(result.isSuccess());
+        assertEquals(LogMessages.SERVICE_NOT_FOUND, result.getResultMessage());
     }
 
     @Test
-    public void writeOrModifyOrDeleteServiceListNotPresentWithNoWriteChoice() {
-
+    void writeOrModifyOrDeleteServiceListNotPresentWithNoWriteChoice() {
         ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput();
         ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder()
                 .setRequestId("request 1").setAckFinalIndicator(ResponseCodes.FINAL_ACK_NO)
                 .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("PCE calculation in progress").build();
         PathComputationRequestOutput pathComputationRequestOutput = new PathComputationRequestOutputBuilder()
                 .setConfigurationResponseCommon(configurationResponseCommon).build();
-        String result = serviceDataStoreOperations.writeOrModifyOrDeleteServiceList("serviceCreateInput",
-            createInput, pathComputationRequestOutput, 3);
-
-        Assert.assertEquals("Service is not present ! ", result);
+        String result = serviceDataStoreOperations
+            .writeOrModifyOrDeleteServiceList("serviceCreateInput", createInput, pathComputationRequestOutput, 3);
+        assertEquals(LogMessages.SERVICE_NOT_FOUND, result);
     }
 
     @Test
-    public void writeOrModifyOrDeleteServiceListNotPresentWithWriteChoice() {
-
+    void writeOrModifyOrDeleteServiceListNotPresentWithWriteChoice() {
         ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput();
         ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder()
                 .setRequestId("request 1").setAckFinalIndicator(ResponseCodes.FINAL_ACK_NO)
                 .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("PCE calculation in progress").build();
         PathComputationRequestOutput pathComputationRequestOutput = new PathComputationRequestOutputBuilder()
                 .setConfigurationResponseCommon(configurationResponseCommon).build();
-        String result = serviceDataStoreOperations.writeOrModifyOrDeleteServiceList("service 1",
-            createInput, pathComputationRequestOutput, 2);
-
-        Assert.assertNull(result);
+        String result = serviceDataStoreOperations
+            .writeOrModifyOrDeleteServiceList("service 1", createInput, pathComputationRequestOutput, 2);
+        assertNull(result);
     }
 
     @Test
-    public void writeOrModifyOrDeleteServiceListPresentWithModifyChoice() {
+    void writeOrModifyOrDeleteServiceListPresentWithModifyChoice() {
         ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput();
         ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder()
                 .setRequestId("request 1").setAckFinalIndicator(ResponseCodes.FINAL_ACK_NO)
                 .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("PCE calculation in progress").build();
         PathComputationRequestOutput pathComputationRequestOutput = new PathComputationRequestOutputBuilder()
                 .setConfigurationResponseCommon(configurationResponseCommon).build();
-        OperationResult createOutput = this.serviceDataStoreOperations.createService(createInput);
-        String result = serviceDataStoreOperations.writeOrModifyOrDeleteServiceList("service 1",
-            createInput, pathComputationRequestOutput, 0);
-        Assert.assertNull(result);
+        this.serviceDataStoreOperations.createService(createInput);
+        String result = serviceDataStoreOperations
+            .writeOrModifyOrDeleteServiceList("service 1", createInput, pathComputationRequestOutput, 0);
+        assertNull(result);
     }
 
     @Test
-    public void writeOrModifyOrDeleteServiceListPresentWithDeleteChoice() {
+    void writeOrModifyOrDeleteServiceListPresentWithDeleteChoice() {
         ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput();
         ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder()
                 .setRequestId("request 1").setAckFinalIndicator(ResponseCodes.FINAL_ACK_NO)
                 .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("PCE calculation in progress").build();
         PathComputationRequestOutput pathComputationRequestOutput = new PathComputationRequestOutputBuilder()
                 .setConfigurationResponseCommon(configurationResponseCommon).build();
-        OperationResult createOutput = this.serviceDataStoreOperations.createService(createInput);
-        String result = serviceDataStoreOperations.writeOrModifyOrDeleteServiceList("service 1",
-            createInput, pathComputationRequestOutput, 1);
-        Assert.assertNull(result);
+        this.serviceDataStoreOperations.createService(createInput);
+        String result = serviceDataStoreOperations
+            .writeOrModifyOrDeleteServiceList("service 1", createInput, pathComputationRequestOutput, 1);
+        assertNull(result);
     }
 
     @Test
-    public void writeOrModifyOrDeleteServiceListPresentWithNoValidChoice() {
+    void writeOrModifyOrDeleteServiceListPresentWithNoValidChoice() {
         ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput();
         ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder()
                 .setRequestId("request 1").setAckFinalIndicator(ResponseCodes.FINAL_ACK_NO)
                 .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("PCE calculation in progress").build();
         PathComputationRequestOutput pathComputationRequestOutput = new PathComputationRequestOutputBuilder()
                 .setConfigurationResponseCommon(configurationResponseCommon).build();
-        OperationResult createOutput = this.serviceDataStoreOperations.createService(createInput);
-        String result = serviceDataStoreOperations.writeOrModifyOrDeleteServiceList("service 1",
-            createInput, pathComputationRequestOutput, 2);
-        Assert.assertNull(result);
-
+        this.serviceDataStoreOperations.createService(createInput);
+        String result = serviceDataStoreOperations
+            .writeOrModifyOrDeleteServiceList("service 1",createInput, pathComputationRequestOutput, 2);
+        assertNull(result);
     }
 
     @Test
-    public void getServiceFromEmptyDataStoreShouldBeEmpty() {
+    void getServiceFromEmptyDataStoreShouldBeEmpty() {
         Optional<Services> optService = this.serviceDataStoreOperations.getService("service 1");
-        Assert.assertFalse(optService.isPresent());
+        assertFalse(optService.isPresent());
     }
 
     @Test
-    public void createServiceShouldBeSuccessForValidInput() {
+    void createServiceShouldBeSuccessForValidInput() {
         ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput();
         OperationResult result = this.serviceDataStoreOperations.createService(createInput);
-        Assert.assertTrue(result.isSuccess());
+        assertTrue(result.isSuccess());
     }
 
     @Test
-    public void getServiceShouldReturnTheCorrectServiceForTheCreatedService() {
+    void getServiceShouldReturnTheCorrectServiceForTheCreatedService() {
         ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput();
         this.serviceDataStoreOperations.createService(createInput);
 
         Optional<Services> optService = this.serviceDataStoreOperations.getService(createInput.getServiceName());
-        Assert.assertTrue(optService.isPresent());
-        Assert.assertEquals(createInput.getServiceName(), optService.get().getServiceName());
+        assertTrue(optService.isPresent());
+        assertEquals(createInput.getServiceName(), optService.orElseThrow().getServiceName());
     }
 
     @Test
-    public void deleteServiceShouldBeSuccessfulForDeletingService() {
+    void deleteServiceShouldBeSuccessfulForDeletingService() {
         ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput();
         this.serviceDataStoreOperations.createService(createInput);
         OperationResult result = this.serviceDataStoreOperations.deleteService(createInput.getServiceName());
-        Assert.assertTrue(result.isSuccess());
+        assertTrue(result.isSuccess());
     }
 
-//    @Test
-//    public void deleteServiceShouldBeFailedIfServiceDoNotExists() {
-//        OperationResult result = this.serviceDataStoreOperations.deleteService("Any service");
-//        Assert.assertFalse(result.isSuccess());
-//    }
+    @Test
+    void deleteServiceShouldBeSuccessEvenIfServiceDoNotExists() {
+        OperationResult result = this.serviceDataStoreOperations.deleteService("Any service");
+        assertTrue(result.isSuccess());
+    }
 
     @Test
-    public void modifyServiceIsSuccessfulForPresentService() {
+    void modifyServiceIsSuccessfulForPresentService() {
         ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput();
         this.serviceDataStoreOperations.createService(createInput);
         OperationResult result = this.serviceDataStoreOperations.modifyService(createInput.getServiceName(),
-            State.InService, State.InService);
-        Assert.assertTrue(result.isSuccess());
+            State.InService, AdminStates.InService);
+        assertTrue(result.isSuccess());
     }
 
     @Test
-    public void getTempServiceFromEmptyDataStoreShouldBeEmpty() {
-        Optional<org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.temp.service.list
+    void getTempServiceFromEmptyDataStoreShouldBeEmpty() {
+        Optional<org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.temp.service.list
                 .Services> optService = this.serviceDataStoreOperations.getTempService("service 1");
-        Assert.assertFalse(optService.isPresent());
+        assertFalse(optService.isPresent());
     }
 
     @Test
-    public void createTempServiceShouldBeSuccessForValidInput() {
+    void createTempServiceShouldBeSuccessForValidInput() {
         TempServiceCreateInput createInput = ServiceDataUtils.buildTempServiceCreateInput();
-        OperationResult result = this.serviceDataStoreOperations.createTempService(createInput);
-        Assert.assertTrue(result.isSuccess());
+        PathDescription pathDescription = ServiceDataUtils.createPathDescription(0,1, 0, 1);
+        OperationResult result = this.serviceDataStoreOperations.createTempService(createInput, pathDescription);
+        assertTrue(result.isSuccess());
     }
 
     @Test
-    public void getTempServiceShouldReturnTheCorrectTempServiceForTheCreatedService() {
+    void getTempServiceShouldReturnTheCorrectTempServiceForTheCreatedService() {
         TempServiceCreateInput createInput = ServiceDataUtils.buildTempServiceCreateInput();
-        this.serviceDataStoreOperations.createTempService(createInput);
+        PathDescription pathDescription = ServiceDataUtils.createPathDescription(0,1, 0, 1);
+        this.serviceDataStoreOperations.createTempService(createInput, pathDescription);
 
-        Optional<org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.temp.service.list
+        Optional<org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.temp.service.list
                 .Services> optService = this.serviceDataStoreOperations.getTempService(createInput.getCommonId());
-        Assert.assertTrue(optService.isPresent());
-        Assert.assertEquals(createInput.getCommonId(), optService.get().getCommonId());
+        assertTrue(optService.isPresent());
+        assertEquals(createInput.getCommonId(), optService.orElseThrow().getCommonId());
     }
 
     @Test
-    public void deleteTempServiceShouldBeSuccessfulForDeletingTempService() {
+    void deleteTempServiceShouldBeSuccessfulForDeletingTempService() {
         TempServiceCreateInput createInput = ServiceDataUtils.buildTempServiceCreateInput();
-        this.serviceDataStoreOperations.createTempService(createInput);
+        PathDescription pathDescription = ServiceDataUtils.createPathDescription(0,1, 0, 1);
+        this.serviceDataStoreOperations.createTempService(createInput, pathDescription);
         OperationResult result = this.serviceDataStoreOperations.deleteTempService(createInput.getCommonId());
-        Assert.assertTrue(result.isSuccess());
+        assertTrue(result.isSuccess());
     }
 
     @Test
-    public void modifyTempServiceIsSuccessfulForPresentTempService() {
+    void modifyTempServiceIsSuccessfulForPresentTempService() {
         TempServiceCreateInput createInput = ServiceDataUtils.buildTempServiceCreateInput();
-        this.serviceDataStoreOperations.createTempService(createInput);
-        OperationResult result = this.serviceDataStoreOperations.modifyTempService(createInput.getCommonId(),
-            State.InService, State.InService);
-        Assert.assertTrue(result.isSuccess());
+        PathDescription pathDescription = ServiceDataUtils.createPathDescription(0,1, 0, 1);
+        this.serviceDataStoreOperations.createTempService(createInput, pathDescription);
+        OperationResult result = this.serviceDataStoreOperations.modifyTempService(
+            createInput.getCommonId(), State.InService, AdminStates.InService);
+        assertTrue(result.isSuccess());
     }
 
     @Test
-    public void createServicePathShouldBeSuccessfulForValidInput() {
+    void createServicePathShouldBeSuccessfulForValidInput() {
         ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput();
         this.serviceDataStoreOperations.createService(createInput);
         ServiceInput serviceInput = new ServiceInput(createInput);
@@ -222,19 +229,21 @@ public class ServiceDataStoreOperationsImplTest extends AbstractTest {
                 .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())
+                .setAToZDirection(new AToZDirectionBuilder()
+                        .setAToZWavelengthNumber(Uint32.valueOf(1)).setRate(Uint32.valueOf(1)).build())
+                .setZToADirection(new ZToADirectionBuilder()
+                        .setZToAWavelengthNumber(Uint32.valueOf(1)).setRate(Uint32.valueOf(1)).build()).build())
             .build();
         PathComputationRequestOutput pathComputationRequestOutput = new PathComputationRequestOutputBuilder()
             .setConfigurationResponseCommon(configurationResponseCommon).setResponseParameters(responseParameters)
             .build();
-        OperationResult result =
-            this.serviceDataStoreOperations.createServicePath(serviceInput, pathComputationRequestOutput);
-        Assert.assertTrue(result.isSuccess());
+        OperationResult result = this.serviceDataStoreOperations
+            .createServicePath(serviceInput, pathComputationRequestOutput);
+        assertTrue(result.isSuccess());
     }
 
     @Test
-    public void createServicePathShouldFailForInvalidInput() {
+    void createServicePathShouldFailForInvalidInput() {
         ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput();
         this.serviceDataStoreOperations.createService(createInput);
         ServiceInput serviceInput = new ServiceInput(createInput);
@@ -245,13 +254,13 @@ public class ServiceDataStoreOperationsImplTest extends AbstractTest {
         PathComputationRequestOutput pathComputationRequestOutput = new PathComputationRequestOutputBuilder()
             .setConfigurationResponseCommon(configurationResponseCommon).setResponseParameters(responseParameters)
             .build();
-        OperationResult result =
-            this.serviceDataStoreOperations.createServicePath(serviceInput, pathComputationRequestOutput);
-        Assert.assertFalse(result.isSuccess());
+        OperationResult result = this.serviceDataStoreOperations
+            .createServicePath(serviceInput, pathComputationRequestOutput);
+        assertFalse(result.isSuccess());
     }
 
     @Test
-    public void deleteServicePathShouldBeSuccessForDeletingServicePath() {
+    void deleteServicePathShouldBeSuccessForDeletingServicePath() {
         ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput();
         this.serviceDataStoreOperations.createService(createInput);
         ServiceInput serviceInput = new ServiceInput(createInput);
@@ -260,8 +269,10 @@ public class ServiceDataStoreOperationsImplTest extends AbstractTest {
             .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())
+                .setAToZDirection(new AToZDirectionBuilder()
+                        .setAToZWavelengthNumber(Uint32.valueOf(1)).setRate(Uint32.valueOf(1)).build())
+                .setZToADirection(new ZToADirectionBuilder()
+                        .setZToAWavelengthNumber(Uint32.valueOf(1)).setRate(Uint32.valueOf(1)).build()).build())
             .build();
         PathComputationRequestOutput pathComputationRequestOutput = new PathComputationRequestOutputBuilder()
             .setConfigurationResponseCommon(configurationResponseCommon).setResponseParameters(responseParameters)
@@ -269,6 +280,6 @@ public class ServiceDataStoreOperationsImplTest extends AbstractTest {
         this.serviceDataStoreOperations.createServicePath(serviceInput, pathComputationRequestOutput);
 
         OperationResult result = this.serviceDataStoreOperations.deleteServicePath(serviceInput.getServiceName());
-        Assert.assertTrue(result.isSuccess());
+        assertTrue(result.isSuccess());
     }
-}
+}
\ No newline at end of file