From e14bba1b91c605df2106d3068f92168a2abd5d87 Mon Sep 17 00:00:00 2001 From: "guillaume.lambert" Date: Mon, 17 Sep 2018 15:10:38 +0200 Subject: [PATCH] remove stubs bundles from build process move stubrenderer implementation to servicehandler test folder. Change-Id: I8a284ea6445421aecbcd99a804274c5f20017e7d Signed-off-by: guillaume.lambert --- features/features-transportpce/pom.xml | 4 +- features/odl-transportpce/pom.xml | 8 +- features/pom.xml | 2 +- pom.xml | 2 +- servicehandler/pom.xml | 2 +- .../servicehandler/ModelMappingUtils.java | 83 ++++++++++------ .../impl/ServicehandlerImpl.java | 54 +++++++---- .../impl/ServiceHandlerImplTest.java | 90 +++++++++++++++--- .../mappers/PathDescriptionConverter.java | 37 -------- .../mappers/ServiceAEndConverter.java | 45 --------- .../mappers/ServiceDeleteInputConverter.java | 36 ------- .../mappers/ServiceDeleteOutputConverter.java | 39 -------- ...ceImplementationRequestInputConverter.java | 43 --------- ...eImplementationRequestOutputConverter.java | 35 ------- .../mappers/ServiceZEndConverter.java | 46 --------- .../ServiceDataStoreOperationsImplTest.java | 2 +- .../stub/StubRendererServiceOperations.java | 27 ++---- .../stub/StubrendererCompliancyCheck.java | 95 +++++++++++++++++++ .../servicehandler/stub/StubrendererImpl.java | 88 +++++++++++++++++ 19 files changed, 364 insertions(+), 374 deletions(-) delete mode 100644 servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/mappers/PathDescriptionConverter.java delete mode 100644 servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/mappers/ServiceAEndConverter.java delete mode 100644 servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/mappers/ServiceDeleteInputConverter.java delete mode 100644 servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/mappers/ServiceDeleteOutputConverter.java delete mode 100644 servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/mappers/ServiceImplementationRequestInputConverter.java delete mode 100644 servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/mappers/ServiceImplementationRequestOutputConverter.java delete mode 100644 servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/mappers/ServiceZEndConverter.java create mode 100644 servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/stub/StubrendererCompliancyCheck.java create mode 100644 servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/stub/StubrendererImpl.java diff --git a/features/features-transportpce/pom.xml b/features/features-transportpce/pom.xml index 8e96c85fd..94158a3e0 100644 --- a/features/features-transportpce/pom.xml +++ b/features/features-transportpce/pom.xml @@ -43,12 +43,12 @@ and is available at http://www.eclipse.org/legal/epl-v10.html INTERNAL features xml - + diff --git a/features/odl-transportpce/pom.xml b/features/odl-transportpce/pom.xml index 9f254689e..9487097d6 100644 --- a/features/odl-transportpce/pom.xml +++ b/features/odl-transportpce/pom.xml @@ -88,13 +88,13 @@ and is available at http://www.eclipse.org/legal/epl-v10.html INTERNAL features xml - + org.opendaylight.transportpce transportpce-common @@ -125,7 +125,7 @@ and is available at http://www.eclipse.org/legal/epl-v10.html INTERNAL transportpce-servicehandler ${project.version} - + diff --git a/features/pom.xml b/features/pom.xml index 6ab23c37e..94d1555e2 100644 --- a/features/pom.xml +++ b/features/pom.xml @@ -26,7 +26,7 @@ and is available at http://www.eclipse.org/legal/epl-v10.html INTERNAL features-transportpce odl-transportpce-api odl-transportpce-ordmodels - odl-transportpce-stubmodels + odl-transportpce diff --git a/pom.xml b/pom.xml index d82ad3288..f731e05e9 100644 --- a/pom.xml +++ b/pom.xml @@ -36,7 +36,7 @@ and is available at http://www.eclipse.org/legal/epl-v10.html INTERNAL renderer networkmodel olm - tests + pce servicehandler features diff --git a/servicehandler/pom.xml b/servicehandler/pom.xml index fabded4dd..7963a9858 100644 --- a/servicehandler/pom.xml +++ b/servicehandler/pom.xml @@ -94,7 +94,7 @@ Author: Martial Coulibaly on behalf of Orange ${project.groupId} - transportpce-stubrenderer + transportpce-renderer ${project.version} diff --git a/servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/ModelMappingUtils.java b/servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/ModelMappingUtils.java index e5b44c40d..1f3ff47f7 100644 --- a/servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/ModelMappingUtils.java +++ b/servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/ModelMappingUtils.java @@ -21,6 +21,7 @@ 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.Topology; import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.service.TopologyBuilder; import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev161014.LifecycleState; +import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev161014.RpcStatus; 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.ServiceCreateOutput; @@ -29,6 +30,9 @@ import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.Service import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceDeleteOutput; import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceDeleteOutputBuilder; import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceReconfigureInput; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceRerouteInput; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceRerouteOutput; +import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceRerouteOutputBuilder; 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.openroadm.topology.rev161014.topology.AToZ; @@ -116,6 +120,15 @@ public final class ModelMappingUtils { return builder.build(); } + public static org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev170426 + .ServiceDeleteInput createServiceDeleteInput(ServiceRerouteInput serviceRerouteInput, Services service) { + ServiceDeleteInputBuilder builder = new ServiceDeleteInputBuilder(); + builder.setServiceName(serviceRerouteInput.getServiceName()); + builder.setServiceHandlerHeader(new ServiceHandlerHeaderBuilder().setRequestId( + service.getSdncRequestHeader().getRequestId()).build()); + return builder.build(); + } + public static ServiceAEnd createServiceAEnd( org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.service.create.input .ServiceAEnd serviceAEnd) { @@ -173,6 +186,17 @@ public final class ModelMappingUtils { return RpcResultBuilder.success(output).buildFuture(); } + + public static ListenableFuture> createRerouteServiceReply(ServiceRerouteInput input, + String finalAck, String message, RpcStatus rpcStatus) { + ServiceRerouteOutputBuilder output = new ServiceRerouteOutputBuilder() + .setHardConstraints(null) + .setSoftConstraints(null) + .setStatusMessage(message) + .setStatus(rpcStatus); + return RpcResultBuilder.success(output.build()).buildFuture(); + } + public static ListenableFuture> createCreateServiceReply(ServiceCreateInput input, String finalAck, String message, String responseCode) { @@ -238,40 +262,41 @@ public final class ModelMappingUtils { .setSoftConstraints(serviceReconfigureInput.getSoftConstraints()) .setLifecycleState(LifecycleState.Planned).setServiceAEnd(aend).setServiceZEnd(zend); } + if (output != null) { + org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev170426.response + .parameters.sp.ResponseParameters responseParameters = output.getResponseParameters(); + if (responseParameters != null) { + // service.setPceMetric(responseParameters.getPceMetric()); + org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev170426 + .response.parameters.sp.response.parameters.PathDescription pathDescription = + responseParameters.getPathDescription(); + if (pathDescription != null) { + List atozList = new ArrayList<>(); + List ztoaList = new ArrayList<>(); - org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev170426.response - .parameters.sp.ResponseParameters responseParameters = output.getResponseParameters(); - if (responseParameters != null) { - // service.setPceMetric(responseParameters.getPceMetric()); - org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev170426 - .response.parameters.sp.response.parameters.PathDescription pathDescription = - responseParameters.getPathDescription(); - if (pathDescription != null) { - List atozList = new ArrayList<>(); - List ztoaList = new ArrayList<>(); + for (org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev170426 + .path.description.atoz.direction.AToZ tmp : pathDescription.getAToZDirection().getAToZ()) { - for (org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev170426 - .path.description.atoz.direction.AToZ tmp : pathDescription.getAToZDirection().getAToZ()) { + AToZKey key = new AToZKey(tmp.key().getId()); + AToZ atoz = new AToZBuilder().setId(tmp.getId()).withKey(key) + // .setResource(tmp.getResource()) + .build(); + atozList.add(atoz); + } - AToZKey key = new AToZKey(tmp.key().getId()); - AToZ atoz = new AToZBuilder().setId(tmp.getId()).withKey(key) - // .setResource(tmp.getResource()) - .build(); - atozList.add(atoz); - } + for (org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev170426 + .path.description.ztoa.direction.ZToA + tmp : pathDescription.getZToADirection().getZToA()) { + ZToAKey key = new ZToAKey(tmp.key().getId()); + ZToA ztoa = new ZToABuilder().setId(tmp.getId()).withKey(key) + // .setResource(tmp.getResource()) + .build(); + ztoaList.add(ztoa); + } - for (org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev170426 - .path.description.ztoa.direction.ZToA - tmp : pathDescription.getZToADirection().getZToA()) { - ZToAKey key = new ZToAKey(tmp.key().getId()); - ZToA ztoa = new ZToABuilder().setId(tmp.getId()).withKey(key) - // .setResource(tmp.getResource()) - .build(); - ztoaList.add(ztoa); + Topology topology = new TopologyBuilder().setAToZ(atozList).setZToA(ztoaList).build(); + service.setTopology(topology); } - - Topology topology = new TopologyBuilder().setAToZ(atozList).setZToA(ztoaList).build(); - service.setTopology(topology); } } return service.build(); diff --git a/servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/impl/ServicehandlerImpl.java b/servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/impl/ServicehandlerImpl.java index b81e9b4d5..48583b38f 100644 --- a/servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/impl/ServicehandlerImpl.java +++ b/servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/impl/ServicehandlerImpl.java @@ -14,8 +14,6 @@ import java.time.format.DateTimeFormatter; import java.util.Optional; import java.util.concurrent.ExecutionException; import org.opendaylight.controller.md.sal.binding.api.DataBroker; -import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction; -import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; import org.opendaylight.transportpce.common.OperationResult; import org.opendaylight.transportpce.common.ResponseCodes; import org.opendaylight.transportpce.pce.service.PathComputationService; @@ -45,7 +43,6 @@ import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.Service 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.ServiceFeasibilityCheckOutput; -import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceList; import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceReconfigureInput; import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceReconfigureOutput; import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceRerouteConfirmInput; @@ -68,10 +65,8 @@ import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.service import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.service.delete.input.ServiceDeleteReqInfo.TailRetention; import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.service.delete.input.ServiceDeleteReqInfoBuilder; 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.ServicesKey; import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev170426.ServiceImplementationRequestInput; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DateAndTime; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.opendaylight.yangtools.yang.common.RpcResult; import org.opendaylight.yangtools.yang.common.RpcResultBuilder; import org.slf4j.Logger; @@ -204,12 +199,17 @@ public class ServicehandlerImpl implements OrgOpenroadmServiceService { //Check presence of service to be deleted String serviceName = input.getServiceDeleteReqInfo().getServiceName(); - Optional service = this.serviceDataStoreOperations.getService(serviceName); - if (!service.isPresent()) { - message = "Service '" + serviceName + "' does not exist in datastore"; - LOG.error(message); - return ModelMappingUtils.createDeleteServiceReply(input, ResponseCodes.FINAL_ACK_YES, - message, ResponseCodes.RESPONSE_FAILED); + LOG.info("serviceName : {}", serviceName); + try { + Optional service = this.serviceDataStoreOperations.getService(serviceName); + if (!service.isPresent()) { + message = "Service '" + serviceName + "' does not exist in datastore"; + LOG.error(message); + return ModelMappingUtils.createDeleteServiceReply(input, ResponseCodes.FINAL_ACK_YES, + message, ResponseCodes.RESPONSE_FAILED); + } + } catch (NullPointerException e) { + LOG.info("failed to get service '{}' from datastore : ", serviceName, e); } LOG.debug("Service '{}' present in datastore !", serviceName); @@ -273,12 +273,10 @@ public class ServicehandlerImpl implements OrgOpenroadmServiceService { @Override public ListenableFuture> serviceReroute(ServiceRerouteInput input) { - InstanceIdentifier servicesIID = InstanceIdentifier.create(ServiceList.class) - .child(Services.class, new ServicesKey(input.getServiceName())); - ReadOnlyTransaction rtx = this.db.newReadOnlyTransaction(); - Optional servicesObject; + LOG.info("RPC service reroute received"); + String message = ""; try { - servicesObject = rtx.read(LogicalDatastoreType.OPERATIONAL, servicesIID).get().toJavaUtil(); + Optional servicesObject = this.serviceDataStoreOperations.getService(input.getServiceName()); if (servicesObject.isPresent()) { ServiceDeleteInputBuilder deleteInputBldr = new ServiceDeleteInputBuilder(); DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssxxx"); @@ -294,8 +292,14 @@ public class ServicehandlerImpl implements OrgOpenroadmServiceService { sdncBuilder.setRpcAction(RpcActions.ServiceDelete); deleteInputBldr.setSdncRequestHeader(sdncBuilder.build()); // Calling delete service - serviceDelete(deleteInputBldr.build()); + ServiceDeleteOutput serviceDeleteOutput = serviceDelete(deleteInputBldr.build()).get().getResult(); // Calling create request now + if (!ResponseCodes.RESPONSE_OK + .equals(serviceDeleteOutput.getConfigurationResponseCommon().getResponseCode())) { + message = "Service delete failed!"; + return ModelMappingUtils.createRerouteServiceReply(input, ResponseCodes.FINAL_ACK_YES, + message, RpcStatus.Failed); + } ServiceCreateInputBuilder serviceCreateBldr = new ServiceCreateInputBuilder(); serviceCreateBldr.setServiceName(input.getServiceName() + 2); serviceCreateBldr.setCommonId(servicesObject.get().getCommonId()); @@ -315,19 +319,27 @@ public class ServicehandlerImpl implements OrgOpenroadmServiceService { ServiceZEndBuilder serviceZendBuilder = new ServiceZEndBuilder(servicesObject.get().getServiceZEnd()); serviceCreateBldr.setServiceZEnd(serviceZendBuilder.build()); serviceCreateBldr.setSoftConstraints(servicesObject.get().getSoftConstraints()); - serviceCreate(serviceCreateBldr.build()); + ServiceCreateOutput serviceCreateOutput = serviceCreate(serviceCreateBldr.build()).get().getResult(); + if (!ResponseCodes.RESPONSE_OK + .equals(serviceCreateOutput.getConfigurationResponseCommon().getResponseCode())) { + message = "Service create failed!"; + return ModelMappingUtils.createRerouteServiceReply(input, ResponseCodes.FINAL_ACK_YES, + message, RpcStatus.Failed); + } ServiceRerouteOutputBuilder output = new ServiceRerouteOutputBuilder() .setHardConstraints(null).setSoftConstraints(null).setStatus( org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev161014.RpcStatus.Successful) - .setStatusMessage("Success"); + .setStatusMessage("Service reroute successfully !"); return RpcResultBuilder.success(output).buildFuture(); + } else { + LOG.error("Service '{}' is not present", input.getServiceName()); + message = "Service '" + input.getServiceName() + "' is not present"; } } catch (InterruptedException | ExecutionException e) { LOG.info("Exception caught" , e); } ServiceRerouteOutputBuilder output = new ServiceRerouteOutputBuilder() - .setHardConstraints(null).setSoftConstraints(null).setStatus(RpcStatus.Failed).setStatusMessage("Failure"); - + .setHardConstraints(null).setSoftConstraints(null).setStatus(RpcStatus.Failed).setStatusMessage(message); return RpcResultBuilder.success(output).buildFuture(); } diff --git a/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/impl/ServiceHandlerImplTest.java b/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/impl/ServiceHandlerImplTest.java index 1967a8ba9..104d1713c 100644 --- a/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/impl/ServiceHandlerImplTest.java +++ b/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/impl/ServiceHandlerImplTest.java @@ -112,15 +112,37 @@ public class ServiceHandlerImplTest extends AbstractTest { this.pathComputationService = new PathComputationServiceImpl(getDataBroker(), notificationPublishService); PceTestUtils.writeTopologyIntoDataStore(getDataBroker(), getDataStoreContextUtil(), "topologyData/NW-simple-topology.xml"); - this.rendererServiceOperations = new StubRendererServiceOperations(notificationPublishService); + this.rendererServiceOperations = new StubRendererServiceOperations(); } @Test public void testCreateServiceValid() throws ExecutionException, InterruptedException { ServiceCreateInput serviceInput = ServiceDataUtils.buildServiceCreateInput(); + ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder() + .setAckFinalIndicator(ResponseCodes.FINAL_ACK_YES).setRequestId("1") + .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("success").build(); + PathComputationRequestOutput pathComputationRequestOutput = new PathComputationRequestOutputBuilder( + PceTestData.getPCE_simpletopology_test1_result((long) 5)) + .setConfigurationResponseCommon(configurationResponseCommon).build(); + + Mockito.when(this.pceServiceWrapperMock.performPCE(serviceInput, true)) + .thenReturn(pathComputationRequestOutput); + Mockito.when(this.serviceDataStoreOperationsMock.createService(any(ServiceCreateInput.class), + any(PathComputationRequestOutput.class))).thenReturn(OperationResult.ok("Successful")); + Mockito.when(this.serviceDataStoreOperationsMock.createServicePath(any(ServiceCreateInput.class), + any(PathComputationRequestOutput.class))).thenReturn(OperationResult.ok("Successful")); + ConfigurationResponseCommon configurationResponseCommon2 = new ConfigurationResponseCommonBuilder() + .setAckFinalIndicator(ResponseCodes.FINAL_ACK_YES).setRequestId("1") + .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("successful").build(); + Mockito.when( + this.rendererServiceOperationsMock.serviceImplementation(any(ServiceImplementationRequestInput.class))) + .thenReturn(new ServiceImplementationRequestOutputBuilder() + .setConfigurationResponseCommon(configurationResponseCommon2).build()); + Mockito.when(this.serviceDataStoreOperationsMock.modifyService(serviceInput.getServiceName(), + State.InService, State.InService)).thenReturn(OperationResult.ok("successful")); - Future> output0 = this.serviceHandler.serviceCreate(serviceInput); + Future> output0 = this.serviceHandlerImplMock.serviceCreate(serviceInput); Assert.assertNotNull(output0); Assert.assertTrue(output0.get().isSuccessful()); Assert.assertEquals(output0.get().getResult(), @@ -941,8 +963,7 @@ public class ServiceHandlerImplTest extends AbstractTest { Optional service = Optional.of(new ServicesBuilder().setServiceName("service 1").build()); Mockito.when(this.serviceDataStoreOperationsMock.getService("service 1")).thenReturn(service); org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev170426 - .ServiceDeleteInput input = ModelMappingUtils - .createServiceDeleteInput(serviceDeleteInput); + .ServiceDeleteInput input = ModelMappingUtils.createServiceDeleteInput(serviceDeleteInput); ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder() .setAckFinalIndicator(ResponseCodes.FINAL_ACK_YES).setRequestId("1") .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("success").build(); @@ -964,25 +985,70 @@ public class ServiceHandlerImplTest extends AbstractTest { } @Test - public void rerouteServiceIsNotePresent() throws ExecutionException, InterruptedException { + public void rerouteServiceIsNotPresent() throws ExecutionException, InterruptedException { ServiceRerouteInput input = ServiceDataUtils.buildServiceRerouteInput(); ServiceRerouteOutput result = this.serviceHandler.serviceReroute(input).get().getResult(); Assert.assertEquals(result.getStatus(), RpcStatus.Failed); - Assert.assertEquals(result.getStatusMessage(), "Failure"); + Assert.assertEquals(result.getStatusMessage(), "Service 'service 1' is not present"); } @Test public void rerouteServiceIfserviceIsPresent() throws ExecutionException, InterruptedException { - ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInput(); - ServiceCreateOutput createOutput = this.serviceHandler.serviceCreate(createInput).get().getResult(); - ServiceRerouteInput input = ServiceDataUtils.buildServiceRerouteInput(); - ServiceRerouteOutput result = this.serviceHandler.serviceReroute(input).get().getResult(); + ServiceRerouteInput serviceRerouteinput = ServiceDataUtils.buildServiceRerouteInput(); + ServiceDeleteInput serviceDeleteInput = ServiceDataUtils.buildServiceDeleteInput(); + ServiceCreateInput serviceInput = ServiceDataUtils.buildServiceCreateInput(); + + /** Mock RPC service-delete. */ + Services serviceMock = ModelMappingUtils.mappingServices(serviceInput, null, null); + Optional service = Optional.of(serviceMock); + Mockito.when(this.serviceDataStoreOperationsMock.getService(any(String.class))).thenReturn(service); + org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev170426 + .ServiceDeleteInput input = ModelMappingUtils.createServiceDeleteInput(serviceRerouteinput, service.get()); + ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder() + .setAckFinalIndicator(ResponseCodes.FINAL_ACK_YES).setRequestId("1") + .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("success").build(); + org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev170426 + .ServiceDeleteOutput output = new org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface + .servicepath.rev170426.ServiceDeleteOutputBuilder() + .setConfigurationResponseCommon(configurationResponseCommon).build(); + Mockito.when(this.rendererServiceOperationsMock.serviceDelete(input)).thenReturn(output); + Mockito.when(this.serviceDataStoreOperationsMock + .deleteServicePath(serviceDeleteInput.getServiceDeleteReqInfo().getServiceName())) + .thenReturn(OperationResult.ok("success")); + Mockito.when(this.serviceDataStoreOperationsMock + .deleteService(serviceDeleteInput.getServiceDeleteReqInfo().getServiceName())) + .thenReturn(OperationResult.ok("success")); + + ConfigurationResponseCommon configurationResponseCommon2 = new ConfigurationResponseCommonBuilder() + .setAckFinalIndicator(ResponseCodes.FINAL_ACK_YES).setRequestId("1") + .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("success").build(); + PathComputationRequestOutput pathComputationRequestOutput = new PathComputationRequestOutputBuilder( + PceTestData.getPCE_simpletopology_test1_result((long) 5)) + .setConfigurationResponseCommon(configurationResponseCommon2).build(); + + /** Mock RPC service-create. */ + Mockito.when(this.pceServiceWrapperMock.performPCE(any(ServiceCreateInput.class), any(Boolean.class))) + .thenReturn(pathComputationRequestOutput); + Mockito.when(this.serviceDataStoreOperationsMock.createService(any(ServiceCreateInput.class), + any(PathComputationRequestOutput.class))).thenReturn(OperationResult.ok("Successful")); + Mockito.when(this.serviceDataStoreOperationsMock.createServicePath(any(ServiceCreateInput.class), + any(PathComputationRequestOutput.class))).thenReturn(OperationResult.ok("Successful")); + ConfigurationResponseCommon configurationResponseCommon3 = new ConfigurationResponseCommonBuilder() + .setAckFinalIndicator(ResponseCodes.FINAL_ACK_YES).setRequestId("1") + .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("successful").build(); + Mockito.when( + this.rendererServiceOperationsMock.serviceImplementation(any(ServiceImplementationRequestInput.class))) + .thenReturn(new ServiceImplementationRequestOutputBuilder() + .setConfigurationResponseCommon(configurationResponseCommon3).build()); + Mockito.when(this.serviceDataStoreOperationsMock.modifyService(any(String.class), any(State.class), + any(State.class))).thenReturn(OperationResult.ok("successful")); + + ServiceRerouteOutput result = this.serviceHandlerImplMock.serviceReroute(serviceRerouteinput).get().getResult(); Assert.assertEquals(org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev161014.RpcStatus.Successful, result.getStatus()); - Assert.assertEquals("Success", result.getStatusMessage()); - + Assert.assertEquals("Service reroute successfully !", result.getStatusMessage()); } } diff --git a/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/mappers/PathDescriptionConverter.java b/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/mappers/PathDescriptionConverter.java deleted file mode 100644 index c1a949f57..000000000 --- a/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/mappers/PathDescriptionConverter.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright © 2018 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.mappers; - -import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.stubrenderer.rev170426.service.implementation.request.input.PathDescription; -import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.stubrenderer.rev170426.service.implementation.request.input.PathDescriptionBuilder; - -public final class PathDescriptionConverter { - - public static PathDescription getStub(org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface - .servicepath.rev170426.service.implementation.request.input.PathDescription concrete) { - PathDescriptionBuilder stubBuilder = new PathDescriptionBuilder(); - stubBuilder.setAToZDirection(concrete.getAToZDirection()); - stubBuilder.setZToADirection(concrete.getZToADirection()); - return stubBuilder.build(); - } - - - public static org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev170426.service - .implementation.request.input.PathDescription getConcrete(PathDescription stub) { - org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev170426.service - .implementation.request.input.PathDescriptionBuilder concreteBuilder = new org.opendaylight.yang.gen.v1 - .http.org.transportpce.b.c._interface.servicepath.rev170426.service.implementation.request.input - .PathDescriptionBuilder(); - concreteBuilder.setAToZDirection(stub.getAToZDirection()); - concreteBuilder.setZToADirection(stub.getZToADirection()); - return concreteBuilder.build(); - } - - private PathDescriptionConverter() { - } -} diff --git a/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/mappers/ServiceAEndConverter.java b/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/mappers/ServiceAEndConverter.java deleted file mode 100644 index 471d0974f..000000000 --- a/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/mappers/ServiceAEndConverter.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright © 2018 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.mappers; - -import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.stubrenderer.rev170426.service.implementation.request.input.ServiceAEnd; -import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.stubrenderer.rev170426.service.implementation.request.input.ServiceAEndBuilder; - -public final class ServiceAEndConverter { - - public static ServiceAEnd getStub(org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath - .rev170426.service.implementation.request.input.ServiceAEnd concrete) { - ServiceAEndBuilder stubBuilder = new ServiceAEndBuilder(); - stubBuilder.setClli(concrete.getClli()); - stubBuilder.setNodeId(concrete.getNodeId()); - stubBuilder.setRxDirection(concrete.getRxDirection()); - stubBuilder.setServiceFormat(concrete.getServiceFormat()); - stubBuilder.setServiceRate(concrete.getServiceRate()); - stubBuilder.setTxDirection(concrete.getTxDirection()); - return stubBuilder.build(); - } - - - public static org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev170426.service - .implementation.request.input.ServiceAEnd getConcrete(ServiceAEnd stub) { - org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev170426.service.implementation - .request.input.ServiceAEndBuilder concreteBuilder = new org.opendaylight.yang.gen.v1.http.org - .transportpce.b.c._interface.servicepath.rev170426.service.implementation.request.input - .ServiceAEndBuilder(); - concreteBuilder.setClli(stub.getClli()); - concreteBuilder.setNodeId(stub.getNodeId()); - concreteBuilder.setRxDirection(stub.getRxDirection()); - concreteBuilder.setServiceFormat(stub.getServiceFormat()); - concreteBuilder.setServiceRate(stub.getServiceRate()); - concreteBuilder.setTxDirection(stub.getTxDirection()); - return concreteBuilder.build(); - } - - private ServiceAEndConverter() { - } -} diff --git a/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/mappers/ServiceDeleteInputConverter.java b/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/mappers/ServiceDeleteInputConverter.java deleted file mode 100644 index 412afb814..000000000 --- a/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/mappers/ServiceDeleteInputConverter.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright © 2018 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.mappers; - -import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.stubrenderer.rev170426.ServiceDeleteInput; -import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.stubrenderer.rev170426.ServiceDeleteInputBuilder; - -public final class ServiceDeleteInputConverter { - - public static ServiceDeleteInput getStub(org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface - .servicepath.rev170426.ServiceDeleteInput concrete) { - ServiceDeleteInputBuilder stubBuilder = new ServiceDeleteInputBuilder(); - stubBuilder.setServiceHandlerHeader(concrete.getServiceHandlerHeader()); - stubBuilder.setServiceName(concrete.getServiceName()); - return stubBuilder.build(); - } - - - public static org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev170426 - .ServiceDeleteInput getConcrete(ServiceDeleteInput stub) { - org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev170426 - .ServiceDeleteInputBuilder concreteBuilder = new org.opendaylight.yang.gen.v1.http.org.transportpce - .b.c._interface.servicepath.rev170426.ServiceDeleteInputBuilder(); - concreteBuilder.setServiceHandlerHeader(stub.getServiceHandlerHeader()); - concreteBuilder.setServiceName(stub.getServiceName()); - return concreteBuilder.build(); - } - - private ServiceDeleteInputConverter() { - } -} diff --git a/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/mappers/ServiceDeleteOutputConverter.java b/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/mappers/ServiceDeleteOutputConverter.java deleted file mode 100644 index b6ea691ae..000000000 --- a/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/mappers/ServiceDeleteOutputConverter.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright © 2018 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.mappers; - -import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.stubrenderer.rev170426.ServiceDeleteOutput; -import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.stubrenderer.rev170426.ServiceDeleteOutputBuilder; - -public final class ServiceDeleteOutputConverter { - - public static ServiceDeleteOutput - getStub( - org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev170426.ServiceDeleteOutput - concrete - ) { - ServiceDeleteOutputBuilder stubBuilder = new ServiceDeleteOutputBuilder(); - stubBuilder.setConfigurationResponseCommon(concrete.getConfigurationResponseCommon()); - return stubBuilder.build(); - } - - - public static - org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev170426.ServiceDeleteOutput - getConcrete(ServiceDeleteOutput stub) { - org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev170426 - .ServiceDeleteOutputBuilder concreteBuilder = - new org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev170426 - .ServiceDeleteOutputBuilder(); - concreteBuilder.setConfigurationResponseCommon(stub.getConfigurationResponseCommon()); - return concreteBuilder.build(); - } - - private ServiceDeleteOutputConverter() { - } -} diff --git a/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/mappers/ServiceImplementationRequestInputConverter.java b/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/mappers/ServiceImplementationRequestInputConverter.java deleted file mode 100644 index 985cb64c9..000000000 --- a/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/mappers/ServiceImplementationRequestInputConverter.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright © 2018 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.mappers; - -import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.stubrenderer.rev170426.ServiceImplementationRequestInput; -import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.stubrenderer.rev170426.ServiceImplementationRequestInputBuilder; - -public final class ServiceImplementationRequestInputConverter { - - public static ServiceImplementationRequestInput getStub(org.opendaylight.yang.gen.v1.http.org.transportpce - .b.c._interface.servicepath.rev170426.ServiceImplementationRequestInput concrete) { - ServiceImplementationRequestInputBuilder stubBuilder = new ServiceImplementationRequestInputBuilder(); - stubBuilder.setServiceHandlerHeader(concrete.getServiceHandlerHeader()); - stubBuilder.setPathDescription(PathDescriptionConverter.getStub(concrete.getPathDescription())); - stubBuilder.setServiceName(concrete.getServiceName()); - stubBuilder.setServiceAEnd(ServiceAEndConverter.getStub(concrete.getServiceAEnd())); - stubBuilder.setServiceZEnd(ServiceZEndConverter.getStub(concrete.getServiceZEnd())); - return stubBuilder.build(); - } - - - public static org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev170426 - .ServiceImplementationRequestInput getConcrete(ServiceImplementationRequestInput stub) { - org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev170426 - .ServiceImplementationRequestInputBuilder concreteBuilder = new org.opendaylight.yang.gen.v1.http.org - .transportpce.b.c._interface.servicepath.rev170426.ServiceImplementationRequestInputBuilder(); - concreteBuilder.setServiceHandlerHeader(stub.getServiceHandlerHeader()); - concreteBuilder.setPathDescription(PathDescriptionConverter.getConcrete(stub.getPathDescription())); - concreteBuilder.setServiceName(stub.getServiceName()); - concreteBuilder.setServiceAEnd(ServiceAEndConverter.getConcrete(stub.getServiceAEnd())); - concreteBuilder.setServiceZEnd(ServiceZEndConverter.getConcrete(stub.getServiceZEnd())); - return concreteBuilder.build(); - } - - private ServiceImplementationRequestInputConverter() { - } - -} diff --git a/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/mappers/ServiceImplementationRequestOutputConverter.java b/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/mappers/ServiceImplementationRequestOutputConverter.java deleted file mode 100644 index 61aa49650..000000000 --- a/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/mappers/ServiceImplementationRequestOutputConverter.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright © 2018 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.mappers; - -import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.stubrenderer.rev170426.ServiceImplementationRequestOutput; -import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.stubrenderer.rev170426.ServiceImplementationRequestOutputBuilder; - -public final class ServiceImplementationRequestOutputConverter { - - public static ServiceImplementationRequestOutput getStub(org.opendaylight.yang.gen.v1.http.org.transportpce - .b.c._interface.servicepath.rev170426.ServiceImplementationRequestOutput concrete) { - ServiceImplementationRequestOutputBuilder stubBuilder = new ServiceImplementationRequestOutputBuilder(); - stubBuilder.setConfigurationResponseCommon(concrete.getConfigurationResponseCommon()); - return stubBuilder.build(); - } - - - public static org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev170426 - .ServiceImplementationRequestOutput getConcrete(ServiceImplementationRequestOutput stub) { - org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev170426 - .ServiceImplementationRequestOutputBuilder concreteBuilder = new org.opendaylight.yang.gen.v1.http.org - .transportpce.b.c._interface.servicepath.rev170426.ServiceImplementationRequestOutputBuilder(); - concreteBuilder.setConfigurationResponseCommon(stub.getConfigurationResponseCommon()); - return concreteBuilder.build(); - } - - private ServiceImplementationRequestOutputConverter() { - } - -} diff --git a/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/mappers/ServiceZEndConverter.java b/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/mappers/ServiceZEndConverter.java deleted file mode 100644 index c830b2dda..000000000 --- a/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/mappers/ServiceZEndConverter.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright © 2018 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.mappers; - -import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.stubrenderer.rev170426.service.implementation.request.input.ServiceZEnd; -import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.stubrenderer.rev170426.service.implementation.request.input.ServiceZEndBuilder; - -public final class ServiceZEndConverter { - public static ServiceZEnd getStub( - org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev170426.service.implementation - .request.input.ServiceZEnd concrete) { - ServiceZEndBuilder stubBuilder = new ServiceZEndBuilder(); - stubBuilder.setClli(concrete.getClli()); - stubBuilder.setNodeId(concrete.getNodeId()); - stubBuilder.setRxDirection(concrete.getRxDirection()); - stubBuilder.setServiceFormat(concrete.getServiceFormat()); - stubBuilder.setServiceRate(concrete.getServiceRate()); - stubBuilder.setTxDirection(concrete.getTxDirection()); - return stubBuilder.build(); - } - - - public static - org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev170426.service.implementation - .request.input.ServiceZEnd getConcrete(ServiceZEnd stub) { - org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev170426.service.implementation - .request.input.ServiceZEndBuilder concreteBuilder = - new org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev170426.service - .implementation.request.input.ServiceZEndBuilder(); - concreteBuilder.setClli(stub.getClli()); - concreteBuilder.setNodeId(stub.getNodeId()); - concreteBuilder.setRxDirection(stub.getRxDirection()); - concreteBuilder.setServiceFormat(stub.getServiceFormat()); - concreteBuilder.setServiceRate(stub.getServiceRate()); - concreteBuilder.setTxDirection(stub.getTxDirection()); - return concreteBuilder.build(); - } - - private ServiceZEndConverter(){ - } -} diff --git a/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/service/ServiceDataStoreOperationsImplTest.java b/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/service/ServiceDataStoreOperationsImplTest.java index 9ec0a651c..60616616a 100644 --- a/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/service/ServiceDataStoreOperationsImplTest.java +++ b/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/service/ServiceDataStoreOperationsImplTest.java @@ -38,7 +38,7 @@ public class ServiceDataStoreOperationsImplTest extends AbstractTest { PathComputationService pathComputationService = new PathComputationServiceImpl(getDataBroker(), notificationPublishService); this.pceServiceWrapper = new PCEServiceWrapper(pathComputationService); - this.rendererServiceOperations = new StubRendererServiceOperations(notificationPublishService); + this.rendererServiceOperations = new StubRendererServiceOperations(); this.serviceHandler = new ServicehandlerImpl(getDataBroker(), pathComputationService, this.rendererServiceOperations); } diff --git a/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/stub/StubRendererServiceOperations.java b/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/stub/StubRendererServiceOperations.java index 6db468c39..37c926b29 100644 --- a/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/stub/StubRendererServiceOperations.java +++ b/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/stub/StubRendererServiceOperations.java @@ -7,16 +7,9 @@ */ package org.opendaylight.transportpce.servicehandler.stub; +import com.google.common.util.concurrent.ListenableFuture; import java.util.concurrent.ExecutionException; -import java.util.concurrent.Future; - -import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService; import org.opendaylight.transportpce.renderer.provisiondevice.RendererServiceOperations; -import org.opendaylight.transportpce.servicehandler.mappers.ServiceDeleteInputConverter; -import org.opendaylight.transportpce.servicehandler.mappers.ServiceDeleteOutputConverter; -import org.opendaylight.transportpce.servicehandler.mappers.ServiceImplementationRequestInputConverter; -import org.opendaylight.transportpce.servicehandler.mappers.ServiceImplementationRequestOutputConverter; -import org.opendaylight.transportpce.stubrenderer.impl.StubrendererImpl; import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev170426.ServiceDeleteInput; import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev170426.ServiceDeleteOutput; import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev170426.ServiceImplementationRequestInput; @@ -27,19 +20,13 @@ import org.slf4j.LoggerFactory; public class StubRendererServiceOperations implements RendererServiceOperations { private static final Logger LOG = LoggerFactory.getLogger(StubRendererServiceOperations.class); - private StubrendererImpl stubrenderer; - - public StubRendererServiceOperations(NotificationPublishService notificationPublishService) { - this.stubrenderer = new StubrendererImpl(notificationPublishService); - } @Override public ServiceImplementationRequestOutput serviceImplementation(ServiceImplementationRequestInput input) { - Future> rpcResultFuture = this.stubrenderer - .serviceImplementationRequest(ServiceImplementationRequestInputConverter.getStub(input)); + ListenableFuture> rpcResultFuture = StubrendererImpl + .serviceImplementation(input); try { - return ServiceImplementationRequestOutputConverter.getConcrete(rpcResultFuture.get().getResult()); + return rpcResultFuture.get().getResult(); } catch (InterruptedException e) { LOG.error("RPC serviceImplementation failed !",e); } catch (ExecutionException e) { @@ -50,11 +37,9 @@ public class StubRendererServiceOperations implements RendererServiceOperations @Override public ServiceDeleteOutput serviceDelete(ServiceDeleteInput input) { - Future> rpcResultFuture = this.stubrenderer - .serviceDelete(ServiceDeleteInputConverter.getStub(input)); + ListenableFuture> rpcResultFuture = StubrendererImpl.serviceDelete(input); try { - return ServiceDeleteOutputConverter.getConcrete(rpcResultFuture.get().getResult()); + return rpcResultFuture.get().getResult(); } catch (InterruptedException e) { LOG.error("RPC serviceDelete failed !",e); } catch (ExecutionException e) { diff --git a/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/stub/StubrendererCompliancyCheck.java b/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/stub/StubrendererCompliancyCheck.java new file mode 100644 index 000000000..1fe514c5b --- /dev/null +++ b/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/stub/StubrendererCompliancyCheck.java @@ -0,0 +1,95 @@ +/* + * Copyright © 2017 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.stub; + +import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev170426.service.handler.header.ServiceHandlerHeader; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Class for checking service sdnc-request-header compliancy. + * + * @author Martial Coulibaly on behalf of Orange + * + */ +public class StubrendererCompliancyCheck { + /** Logging. */ + private static final Logger LOG = LoggerFactory.getLogger(StubrendererCompliancyCheck.class); + /** SdncRequestHeader. */ + private ServiceHandlerHeader serviceHandlerHeader; + /** Service Name. */ + private String serviceName; + /** Response message from procedure. */ + private String message; + + + public StubrendererCompliancyCheck(String serviceName,ServiceHandlerHeader serviceHandlerHeader) { + this.serviceName = serviceName; + this.serviceHandlerHeader = serviceHandlerHeader; + this.setMessage(""); + } + + /** + * Check if a String is not null and not equal to void. + * + * @param value + * String value + * @return true if String ok false if not + */ + public Boolean checkString(String value) { + Boolean result = false; + if (value != null && value.compareTo("") != 0) { + result = true; + } + return result; + + } + + /** + * Check Compliancy of Service request. + * + * @param contype + * Boolean to check connection Type + * @param servicehandler + * Boolean to check sndcRequestHeader + * + * @return true if String ok false if not + */ + public Boolean check(Boolean contype, Boolean servicehandler) { + Boolean result = true; + if (!checkString(serviceName)) { + result = false; + message = "Service Name is not set"; + LOG.info(message); + } + if (servicehandler) { + if (serviceHandlerHeader != null) { + String requestId = serviceHandlerHeader.getRequestId(); + if (!checkString(requestId)) { + result = false; + message = "Service serviceHandlerHeader 'request-id' is not set"; + LOG.info(message); + } + } else { + result = false; + message = "Service serviceHandlerHeader is not set "; + LOG.info(message); + } + } + return result; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } +} diff --git a/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/stub/StubrendererImpl.java b/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/stub/StubrendererImpl.java new file mode 100644 index 000000000..ccdf7d3c9 --- /dev/null +++ b/servicehandler/src/test/java/org/opendaylight/transportpce/servicehandler/stub/StubrendererImpl.java @@ -0,0 +1,88 @@ +/* + * Copyright © 2017 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.stub; + +import com.google.common.util.concurrent.ListenableFuture; +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.transportpce.b.c._interface.servicepath.rev170426.ServiceDeleteInput; +import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev170426.ServiceDeleteOutput; +import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev170426.ServiceDeleteOutputBuilder; +import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev170426.ServiceImplementationRequestInput; +import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev170426.ServiceImplementationRequestOutput; +import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev170426.ServiceImplementationRequestOutputBuilder; +import org.opendaylight.yangtools.yang.common.RpcResult; +import org.opendaylight.yangtools.yang.common.RpcResultBuilder; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + + +/** + * Class to implement StubrendererService. + * @author Martial Coulibaly ( martial.coulibaly@gfi.com ) on behalf of Orange + * + */ +public final class StubrendererImpl { + /** Logging. */ + private static final Logger LOG = LoggerFactory.getLogger(StubrendererImpl.class); + /** check service sdnc-request-header compliancy. */ + + private StubrendererImpl() { + + } + + + public static ListenableFuture> serviceDelete(ServiceDeleteInput input) { + LOG.info("ServiceDelete request ..."); + String message = ""; + String responseCode = null; + try { + LOG.info("Wait for 1s til beginning the Renderer serviceDelete request"); + Thread.sleep(1000); //sleep for 1s + } catch (InterruptedException e) { + message = "deleting service failed !"; + LOG.error("deleting service failed !", e); + responseCode = "500"; + } + ConfigurationResponseCommonBuilder configurationResponseCommon = new ConfigurationResponseCommonBuilder() + .setAckFinalIndicator("yes") + .setRequestId(input.getServiceHandlerHeader().getRequestId()) + .setResponseCode(responseCode) + .setResponseMessage(message); + ServiceDeleteOutput output = new ServiceDeleteOutputBuilder() + .setConfigurationResponseCommon(configurationResponseCommon.build()) + .build(); + return RpcResultBuilder.success(output).buildFuture(); + } + + public static ListenableFuture> + serviceImplementation(ServiceImplementationRequestInput input) { + LOG.info("serviceImplementation request ..."); + String message = ""; + String responseCode = null; + try { + LOG.info("Wait for 1s til beginning the Renderer serviceDelete request"); + Thread.sleep(1000); //sleep for 1s + } catch (InterruptedException e) { + message = "implementing service failed !"; + LOG.error(message); + responseCode = "500"; + } + ConfigurationResponseCommonBuilder configurationResponseCommon = new ConfigurationResponseCommonBuilder() + .setAckFinalIndicator("yes") + .setRequestId(input.getServiceHandlerHeader().getRequestId()) + .setResponseCode(responseCode) + .setResponseMessage(message); + ServiceImplementationRequestOutput output = new ServiceImplementationRequestOutputBuilder() + .setConfigurationResponseCommon(configurationResponseCommon.build()) + .build(); + return RpcResultBuilder.success(output).buildFuture(); + } +} -- 2.36.6