2 * Copyright © 2018 Orange, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.transportpce.servicehandler;
10 import com.google.common.util.concurrent.ListenableFuture;
11 import com.google.common.util.concurrent.ListeningExecutorService;
12 import com.google.common.util.concurrent.MoreExecutors;
14 import java.time.OffsetDateTime;
15 import java.time.ZoneOffset;
16 import java.time.format.DateTimeFormatter;
17 import java.util.Arrays;
18 import java.util.concurrent.CountDownLatch;
19 import java.util.concurrent.ExecutionException;
20 import java.util.concurrent.Executors;
22 import org.junit.After;
23 import org.junit.Assert;
24 import org.junit.Before;
25 import org.junit.Test;
26 import org.opendaylight.transportpce.common.ResponseCodes;
27 import org.opendaylight.transportpce.servicehandler.utils.ServiceDataUtils;
28 import org.opendaylight.transportpce.test.AbstractTest;
29 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev200128.PathComputationRequestOutput;
30 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev200128.PathComputationRequestOutputBuilder;
31 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev190531.ConnectionType;
32 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev190531.configuration.response.common.ConfigurationResponseCommon;
33 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev190531.configuration.response.common.ConfigurationResponseCommonBuilder;
34 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev190531.sdnc.request.header.SdncRequestHeaderBuilder;
35 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev190531.RpcStatus;
36 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev190329.constraints.co.routing.or.general.CoRoutingBuilder;
37 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev190329.routing.constraints.HardConstraintsBuilder;
38 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev190329.routing.constraints.SoftConstraintsBuilder;
39 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceCreateInput;
40 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceCreateInputBuilder;
41 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceCreateOutput;
42 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceDeleteInput;
43 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceDeleteInputBuilder;
44 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceDeleteOutput;
45 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceFeasibilityCheckInput;
46 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceFeasibilityCheckInputBuilder;
47 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceFeasibilityCheckOutput;
48 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceReconfigureInput;
49 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceReconfigureInputBuilder;
50 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceRerouteInput;
51 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceRerouteInputBuilder;
52 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceRestorationInput;
53 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceRestorationInputBuilder;
54 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceRestorationOutput;
55 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.TempServiceCreateInput;
56 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.TempServiceCreateInputBuilder;
57 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.TempServiceCreateOutput;
58 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.service.list.Services;
59 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.service.list.ServicesBuilder;
60 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.path.description.AToZDirectionBuilder;
61 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.path.description.ZToADirectionBuilder;
62 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev200128.response.parameters.sp.ResponseParameters;
63 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev200128.response.parameters.sp.ResponseParametersBuilder;
64 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev200128.response.parameters.sp.response.parameters.PathDescriptionBuilder;
65 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev171017.service.path.list.ServicePaths;
66 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev171017.service.path.list.ServicePathsBuilder;
67 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DateAndTime;
68 import org.opendaylight.yangtools.yang.common.RpcResult;
71 public class ModelMappingUtilsTest extends AbstractTest {
73 private ListeningExecutorService executorService;
74 private CountDownLatch endSignal;
75 private static final int NUM_THREADS = 5;
76 private boolean callbackRan;
80 executorService = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(NUM_THREADS));
81 endSignal = new CountDownLatch(1);
86 public void tearDown() {
87 executorService.shutdownNow();
90 private ServiceReconfigureInput buildServiceConfigurationInput() {
91 DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssxxx");
92 OffsetDateTime offsetDateTime = OffsetDateTime.now(ZoneOffset.UTC);
93 OffsetDateTime offsetDateTime2 = offsetDateTime.plusDays(10);
94 return new ServiceReconfigureInputBuilder().setNewServiceName("service 1")
95 .setServiceName("service 1").setCommonId("common id").setConnectionType(ConnectionType.Service)
96 .setCustomer("customer").setCustomerContact("customer contact").setDueDate(new DateAndTime(
97 dtf.format(offsetDateTime)))
98 .setEndDate(new DateAndTime(dtf.format(offsetDateTime2)))
99 .setNcCode("nc node").setNciCode("nci node").setSecondaryNciCode("secondry").setOperatorContact("operator")
100 .setServiceAEnd(ServiceDataUtils.getServiceAEndBuildReconfigure().build())
101 .setServiceZEnd(ServiceDataUtils.getServiceZEndBuildReconfigure().build())
102 .setHardConstraints(new HardConstraintsBuilder()
103 .setCoRoutingOrGeneral(new CoRoutingBuilder()
104 .setCoRouting(new org.opendaylight.yang.gen.v1.http.org.openroadm.routing
105 .constrains.rev190329.constraints.co.routing.or.general.co.routing
106 .CoRoutingBuilder().setExistingService(
107 Arrays.asList("Some existing-service")).build())
109 .setCustomerCode(Arrays.asList("Some customer-code"))
111 .setSoftConstraints(new SoftConstraintsBuilder()
112 .setCoRoutingOrGeneral(new CoRoutingBuilder()
113 .setCoRouting(new org.opendaylight.yang.gen.v1.http.org.openroadm.routing
114 .constrains.rev190329.constraints.co.routing.or.general.co.routing
115 .CoRoutingBuilder().setExistingService(
116 Arrays.asList("Some existing-service")).build())
118 .setCustomerCode(Arrays.asList("Some customer-code"))
123 private PathComputationRequestOutput buildPathComputationOutput() {
124 ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder()
125 .setRequestId("request 1").setAckFinalIndicator(ResponseCodes.FINAL_ACK_NO)
126 .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("PCE calculation in progress").build();
127 ResponseParameters responseParameters = new ResponseParametersBuilder()
128 .setPathDescription(new PathDescriptionBuilder()
129 .setAToZDirection(new AToZDirectionBuilder().setAToZWavelengthNumber(1L).setRate(1L).build())
130 .setZToADirection(new ZToADirectionBuilder().setZToAWavelengthNumber(1L).setRate(1L).build()).build())
132 return new PathComputationRequestOutputBuilder().setConfigurationResponseCommon(configurationResponseCommon)
133 .setResponseParameters(responseParameters).build();
137 public void mappingServicesNullServiceCreateInput() {
138 Services services = ModelMappingUtils.mappingServices(null, null);
139 Assert.assertEquals(new ServicesBuilder().build(), services);
143 public void mappingServiceNotNullServiceReconfigureInput() {
144 Services services = ModelMappingUtils.mappingServices(null, buildServiceConfigurationInput());
145 Assert.assertEquals("service 1", services.getServiceName());
149 public void mappingServiceValid() {
150 Services services = ModelMappingUtils.mappingServices(ServiceDataUtils.buildServiceCreateInput(),
152 Assert.assertEquals("service 1", services.getServiceName());
156 public void mappingServicesPathNullServiceCreateInput() {
157 ServicePaths services = ModelMappingUtils.mappingServicePaths(null, buildPathComputationOutput());
158 Assert.assertEquals(new ServicePathsBuilder().build(), services);
162 public void mappingServicePathWithServiceInputWithHardConstraints() {
163 ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInputWithHardConstraints();
164 ServiceInput serviceInput = new ServiceInput(createInput);
165 ServicePaths services = ModelMappingUtils.mappingServicePaths(serviceInput, buildPathComputationOutput());
166 Assert.assertEquals(serviceInput.getServiceName(), services.getServicePathName());
167 Assert.assertNotNull(services.getHardConstraints());
171 public void mappingServicePathWithServiceInputWithSoftConstraints() {
172 ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInputWithSoftConstraints();
173 ServiceInput serviceInput = new ServiceInput(createInput);
174 ServicePaths services = ModelMappingUtils.mappingServicePaths(serviceInput, buildPathComputationOutput());
175 Assert.assertEquals(serviceInput.getServiceName(), services.getServicePathName());
176 Assert.assertNotNull(services.getSoftConstraints());
180 public void createServiceDeleteInputWithServiceRerouteInput() {
181 ServiceRerouteInput serviceRerouteinput = new ServiceRerouteInputBuilder().setServiceName("reroute").build();
182 Services services = new ServicesBuilder()
183 .setSdncRequestHeader(new SdncRequestHeaderBuilder().setRequestId("123").build()).build();
184 org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017.ServiceDeleteInput
186 ModelMappingUtils.createServiceDeleteInput(serviceRerouteinput, services);
187 Assert.assertEquals("reroute", serviceDeleteInput.getServiceName());
188 Assert.assertEquals("123", serviceDeleteInput.getServiceHandlerHeader().getRequestId());
192 public void createServiceDeleteInputWithServiceReconfigureInput() {
193 ServiceReconfigureInput serviceReconfigureInput = new ServiceReconfigureInputBuilder()
194 .setServiceName("reconf").build();
195 org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017.ServiceDeleteInput
197 ModelMappingUtils.createServiceDeleteInput(serviceReconfigureInput);
198 Assert.assertEquals("reconf", serviceDeleteInput.getServiceName());
199 Assert.assertEquals("reconf-reconfigure", serviceDeleteInput.getServiceHandlerHeader().getRequestId());
203 public void createServiceDeleteInputWithServiceRestorationInput() {
204 Services services = new ServicesBuilder()
205 .setSdncRequestHeader(new SdncRequestHeaderBuilder().setRequestId("123").build()).build();
206 ServiceRestorationInput serviceRestorationInput =
207 new ServiceRestorationInputBuilder().setServiceName("rest").build();
208 org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017.ServiceDeleteInput
210 ModelMappingUtils.createServiceDeleteInput(serviceRestorationInput, services);
211 Assert.assertEquals("rest", serviceDeleteInput.getServiceName());
212 Assert.assertEquals("123", serviceDeleteInput.getServiceHandlerHeader().getRequestId());
216 public void createDeleteServiceReplyWithServiceDeleteInputWithSdncHeader()
217 throws ExecutionException, InterruptedException {
218 ServiceDeleteInput input = new ServiceDeleteInputBuilder()
219 .setSdncRequestHeader(new SdncRequestHeaderBuilder().setRequestId("12").build()).build();
220 ListenableFuture<RpcResult<ServiceDeleteOutput>> serviceDeleteOutputF =
221 ModelMappingUtils.createDeleteServiceReply(input, "ack", "message", "200");
222 serviceDeleteOutputF.addListener(new Runnable() {
226 endSignal.countDown();
231 RpcResult<ServiceDeleteOutput> serviceDeleteOutput = serviceDeleteOutputF.get();
232 Assert.assertEquals("200", serviceDeleteOutput.getResult().getConfigurationResponseCommon().getResponseCode());
234 "ack", serviceDeleteOutput.getResult().getConfigurationResponseCommon().getAckFinalIndicator());
236 "message", serviceDeleteOutput.getResult().getConfigurationResponseCommon().getResponseMessage());
237 Assert.assertEquals("12", serviceDeleteOutput.getResult().getConfigurationResponseCommon().getRequestId());
241 public void createDeleteServiceReplyWithServiceDeleteInputWithoutSdncHeader()
242 throws ExecutionException, InterruptedException {
243 ServiceDeleteInput input = new ServiceDeleteInputBuilder().build();
244 ListenableFuture<RpcResult<ServiceDeleteOutput>> serviceDeleteOutputF =
245 ModelMappingUtils.createDeleteServiceReply(input, "ack", "message", "200");
246 serviceDeleteOutputF.addListener(new Runnable() {
250 endSignal.countDown();
255 RpcResult<ServiceDeleteOutput> serviceDeleteOutput = serviceDeleteOutputF.get();
256 Assert.assertEquals("200", serviceDeleteOutput.getResult().getConfigurationResponseCommon().getResponseCode());
258 "ack", serviceDeleteOutput.getResult().getConfigurationResponseCommon().getAckFinalIndicator());
260 "message", serviceDeleteOutput.getResult().getConfigurationResponseCommon().getResponseMessage());
261 Assert.assertNull(serviceDeleteOutput.getResult().getConfigurationResponseCommon().getRequestId());
265 public void createCreateServiceReplyWithServiceCreatInputWithSdncRequestHeader()
266 throws ExecutionException, InterruptedException {
267 ServiceCreateInput input =
268 new ServiceCreateInputBuilder()
269 .setSdncRequestHeader(new SdncRequestHeaderBuilder().setRequestId("12").build()).build();
270 ListenableFuture<RpcResult<ServiceCreateOutput>> serviceCreatOutputF =
271 ModelMappingUtils.createCreateServiceReply(input, "ack", "message", "200");
272 serviceCreatOutputF.addListener(new Runnable() {
276 endSignal.countDown();
281 RpcResult<ServiceCreateOutput> serviceCreatOutput = serviceCreatOutputF.get();
282 Assert.assertEquals("200", serviceCreatOutput.getResult().getConfigurationResponseCommon().getResponseCode());
284 "ack", serviceCreatOutput.getResult().getConfigurationResponseCommon().getAckFinalIndicator());
286 "message", serviceCreatOutput.getResult().getConfigurationResponseCommon().getResponseMessage());
287 Assert.assertEquals("12", serviceCreatOutput.getResult().getConfigurationResponseCommon().getRequestId());
291 public void createCreateServiceReplyWithServiceCreatInputWithoutSdncRequestHeader()
292 throws ExecutionException, InterruptedException {
293 ServiceCreateInput input = new ServiceCreateInputBuilder().build();
294 ListenableFuture<RpcResult<ServiceCreateOutput>> serviceCreatOutputF =
295 ModelMappingUtils.createCreateServiceReply(input, "ack", "message", "200");
296 serviceCreatOutputF.addListener(new Runnable() {
300 endSignal.countDown();
305 RpcResult<ServiceCreateOutput> serviceCreatOutput = serviceCreatOutputF.get();
306 Assert.assertEquals("200", serviceCreatOutput.getResult().getConfigurationResponseCommon().getResponseCode());
308 "ack", serviceCreatOutput.getResult().getConfigurationResponseCommon().getAckFinalIndicator());
310 "message", serviceCreatOutput.getResult().getConfigurationResponseCommon().getResponseMessage());
311 Assert.assertNull(serviceCreatOutput.getResult().getConfigurationResponseCommon().getRequestId());
315 public void createCreateServiceReplyWithTempServiceCreatInputWithSdncRequestHeader()
316 throws ExecutionException, InterruptedException {
317 TempServiceCreateInput input =
318 new TempServiceCreateInputBuilder()
319 .setSdncRequestHeader(new SdncRequestHeaderBuilder().setRequestId("12").build()).build();
320 ListenableFuture<RpcResult<TempServiceCreateOutput>> serviceCreatOutputF =
321 ModelMappingUtils.createCreateServiceReply(input, "ack", "message", "200");
322 serviceCreatOutputF.addListener(new Runnable() {
326 endSignal.countDown();
331 RpcResult<TempServiceCreateOutput> serviceCreatOutput = serviceCreatOutputF.get();
332 Assert.assertEquals("200", serviceCreatOutput.getResult().getConfigurationResponseCommon().getResponseCode());
334 "ack", serviceCreatOutput.getResult().getConfigurationResponseCommon().getAckFinalIndicator());
336 "message", serviceCreatOutput.getResult().getConfigurationResponseCommon().getResponseMessage());
337 Assert.assertEquals("12", serviceCreatOutput.getResult().getConfigurationResponseCommon().getRequestId());
341 public void createCreateServiceReplyWithTempServiceCreatInputWithoutSdncRequestHeader()
342 throws ExecutionException, InterruptedException {
343 TempServiceCreateInput input = new TempServiceCreateInputBuilder().build();
344 ListenableFuture<RpcResult<TempServiceCreateOutput>> serviceCreatOutputF =
345 ModelMappingUtils.createCreateServiceReply(input, "ack", "message", "200");
346 serviceCreatOutputF.addListener(new Runnable() {
350 endSignal.countDown();
355 RpcResult<TempServiceCreateOutput> serviceCreatOutput = serviceCreatOutputF.get();
356 Assert.assertEquals("200", serviceCreatOutput.getResult().getConfigurationResponseCommon().getResponseCode());
358 "ack", serviceCreatOutput.getResult().getConfigurationResponseCommon().getAckFinalIndicator());
360 "message", serviceCreatOutput.getResult().getConfigurationResponseCommon().getResponseMessage());
361 Assert.assertNull(serviceCreatOutput.getResult().getConfigurationResponseCommon().getRequestId());
365 public void createCreateServiceReplyWithServiceFeasibilityCheckInputWithSdncRequestHeader()
366 throws ExecutionException, InterruptedException {
367 ServiceFeasibilityCheckInput input =
368 new ServiceFeasibilityCheckInputBuilder()
369 .setSdncRequestHeader(new SdncRequestHeaderBuilder().setRequestId("12").build()).build();
370 ListenableFuture<RpcResult<ServiceFeasibilityCheckOutput>> serviceCreatOutputF =
371 ModelMappingUtils.createCreateServiceReply(input, "ack", "message", "200");
372 serviceCreatOutputF.addListener(new Runnable() {
376 endSignal.countDown();
381 RpcResult<ServiceFeasibilityCheckOutput> serviceCreatOutput = serviceCreatOutputF.get();
382 Assert.assertEquals("200", serviceCreatOutput.getResult().getConfigurationResponseCommon().getResponseCode());
384 "ack", serviceCreatOutput.getResult().getConfigurationResponseCommon().getAckFinalIndicator());
386 "message", serviceCreatOutput.getResult().getConfigurationResponseCommon().getResponseMessage());
387 Assert.assertEquals("12", serviceCreatOutput.getResult().getConfigurationResponseCommon().getRequestId());
391 public void createCreateServiceReplyWithServiceFeasibilityCheckInputWithoutSdncRequestHeader()
392 throws ExecutionException, InterruptedException {
393 ServiceFeasibilityCheckInput input = new ServiceFeasibilityCheckInputBuilder().build();
394 ListenableFuture<RpcResult<ServiceFeasibilityCheckOutput>> serviceCreatOutputF =
395 ModelMappingUtils.createCreateServiceReply(input, "ack", "message", "200");
396 serviceCreatOutputF.addListener(new Runnable() {
400 endSignal.countDown();
405 RpcResult<ServiceFeasibilityCheckOutput> serviceCreatOutput = serviceCreatOutputF.get();
406 Assert.assertEquals("200", serviceCreatOutput.getResult().getConfigurationResponseCommon().getResponseCode());
408 "ack", serviceCreatOutput.getResult().getConfigurationResponseCommon().getAckFinalIndicator());
410 "message", serviceCreatOutput.getResult().getConfigurationResponseCommon().getResponseMessage());
411 Assert.assertNull(serviceCreatOutput.getResult().getConfigurationResponseCommon().getRequestId());
415 public void testCreateRestoreServiceReply() throws ExecutionException, InterruptedException {
416 ListenableFuture<RpcResult<ServiceRestorationOutput>> serviceRestorationOutputF =
417 ModelMappingUtils.createRestoreServiceReply("message", RpcStatus.Failed);
418 serviceRestorationOutputF.addListener(new Runnable() {
422 endSignal.countDown();
427 RpcResult<ServiceRestorationOutput> serviceRestorationOutput = serviceRestorationOutputF.get();
428 Assert.assertEquals("message", serviceRestorationOutput.getResult().getStatusMessage());