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;
13 import java.time.OffsetDateTime;
14 import java.time.ZoneOffset;
15 import java.time.format.DateTimeFormatter;
16 import java.util.Arrays;
17 import java.util.concurrent.CountDownLatch;
18 import java.util.concurrent.ExecutionException;
19 import java.util.concurrent.Executors;
20 import org.junit.After;
21 import org.junit.Assert;
22 import org.junit.Before;
23 import org.junit.Test;
24 import org.opendaylight.transportpce.common.ResponseCodes;
25 import org.opendaylight.transportpce.servicehandler.utils.ServiceDataUtils;
26 import org.opendaylight.transportpce.test.AbstractTest;
27 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev200128.PathComputationRequestOutput;
28 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev200128.PathComputationRequestOutputBuilder;
29 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev190531.ConnectionType;
30 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev190531.configuration.response.common.ConfigurationResponseCommon;
31 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev190531.configuration.response.common.ConfigurationResponseCommonBuilder;
32 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev190531.sdnc.request.header.SdncRequestHeaderBuilder;
33 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev190531.RpcStatus;
34 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev190329.constraints.co.routing.or.general.CoRoutingBuilder;
35 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev190329.routing.constraints.HardConstraintsBuilder;
36 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev190329.routing.constraints.SoftConstraintsBuilder;
37 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceCreateInput;
38 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceCreateInputBuilder;
39 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceCreateOutput;
40 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceDeleteInput;
41 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceDeleteInputBuilder;
42 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceDeleteOutput;
43 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceFeasibilityCheckInput;
44 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceFeasibilityCheckInputBuilder;
45 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceFeasibilityCheckOutput;
46 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceReconfigureInput;
47 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceReconfigureInputBuilder;
48 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceRerouteInput;
49 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceRerouteInputBuilder;
50 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceRestorationInput;
51 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceRestorationInputBuilder;
52 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceRestorationOutput;
53 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.TempServiceCreateInput;
54 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.TempServiceCreateInputBuilder;
55 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.TempServiceCreateOutput;
56 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.service.list.Services;
57 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.service.list.ServicesBuilder;
58 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.service.list.ServicesKey;
59 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev200629.path.description.AToZDirectionBuilder;
60 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev200629.path.description.ZToADirectionBuilder;
61 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev200128.response.parameters.sp.ResponseParameters;
62 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev200128.response.parameters.sp.ResponseParametersBuilder;
63 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev200128.response.parameters.sp.response.parameters.PathDescriptionBuilder;
64 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev171017.service.path.list.ServicePaths;
65 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev171017.service.path.list.ServicePathsBuilder;
66 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev171017.service.path.list.ServicePathsKey;
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;
69 import org.opendaylight.yangtools.yang.common.Uint32;
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(Uint32.valueOf(1))
130 .setRate(Uint32.valueOf(1)).build())
131 .setZToADirection(new ZToADirectionBuilder().setZToAWavelengthNumber(Uint32.valueOf(1))
132 .setRate(Uint32.valueOf(1)).build()).build())
134 return new PathComputationRequestOutputBuilder().setConfigurationResponseCommon(configurationResponseCommon)
135 .setResponseParameters(responseParameters).build();
139 //TODO : is this unit test relevant ?
140 public void mappingServicesNullServiceCreateInput() {
141 Services services = ModelMappingUtils.mappingServices(null, null);
142 Assert.assertEquals(new ServicesBuilder().withKey(new ServicesKey("unknown")).build(), services);
146 public void mappingServiceNotNullServiceReconfigureInput() {
147 Services services = ModelMappingUtils.mappingServices(null, buildServiceConfigurationInput());
148 Assert.assertEquals("service 1", services.getServiceName());
152 public void mappingServiceValid() {
153 Services services = ModelMappingUtils.mappingServices(ServiceDataUtils.buildServiceCreateInput(),
155 Assert.assertEquals("service 1", services.getServiceName());
159 //TODO : is this unit test relevant ?
160 public void mappingServicesPathNullServiceCreateInput() {
161 ServicePaths services = ModelMappingUtils.mappingServicePaths(null, buildPathComputationOutput());
162 Assert.assertEquals(new ServicePathsBuilder().withKey(new ServicePathsKey("unknown")).build(), services);
166 public void mappingServicePathWithServiceInputWithHardConstraints() {
167 ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInputWithHardConstraints();
168 ServiceInput serviceInput = new ServiceInput(createInput);
169 ServicePaths services = ModelMappingUtils.mappingServicePaths(serviceInput, buildPathComputationOutput());
170 Assert.assertEquals(serviceInput.getServiceName(), services.getServicePathName());
171 Assert.assertNotNull(services.getHardConstraints());
175 public void mappingServicePathWithServiceInputWithSoftConstraints() {
176 ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInputWithSoftConstraints();
177 ServiceInput serviceInput = new ServiceInput(createInput);
178 ServicePaths services = ModelMappingUtils.mappingServicePaths(serviceInput, buildPathComputationOutput());
179 Assert.assertEquals(serviceInput.getServiceName(), services.getServicePathName());
180 Assert.assertNotNull(services.getSoftConstraints());
184 public void createServiceDeleteInputWithServiceRerouteInput() {
185 ServiceRerouteInput serviceRerouteinput = new ServiceRerouteInputBuilder().setServiceName("reroute").build();
186 Services services = new ServicesBuilder()
187 .withKey(new ServicesKey("reroute"))
188 .setSdncRequestHeader(new SdncRequestHeaderBuilder().setRequestId("123").build()).build();
189 org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev201125.ServiceDeleteInput
191 ModelMappingUtils.createServiceDeleteInput(serviceRerouteinput, services);
192 Assert.assertEquals("reroute", serviceDeleteInput.getServiceName());
193 Assert.assertEquals("123", serviceDeleteInput.getServiceHandlerHeader().getRequestId());
197 public void createServiceDeleteInputWithServiceReconfigureInput() {
198 ServiceReconfigureInput serviceReconfigureInput = new ServiceReconfigureInputBuilder()
199 .setServiceName("reconf").build();
200 org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev201125.ServiceDeleteInput
202 ModelMappingUtils.createServiceDeleteInput(serviceReconfigureInput);
203 Assert.assertEquals("reconf", serviceDeleteInput.getServiceName());
204 Assert.assertEquals("reconf-reconfigure", serviceDeleteInput.getServiceHandlerHeader().getRequestId());
208 public void createServiceDeleteInputWithServiceRestorationInput() {
209 Services services = new ServicesBuilder()
210 .withKey(new ServicesKey("rest"))
211 .setSdncRequestHeader(new SdncRequestHeaderBuilder().setRequestId("123").build()).build();
212 ServiceRestorationInput serviceRestorationInput =
213 new ServiceRestorationInputBuilder().setServiceName("rest").build();
214 org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev201125.ServiceDeleteInput
216 ModelMappingUtils.createServiceDeleteInput(serviceRestorationInput, services);
217 Assert.assertEquals("rest", serviceDeleteInput.getServiceName());
218 Assert.assertEquals("123", serviceDeleteInput.getServiceHandlerHeader().getRequestId());
222 public void createDeleteServiceReplyWithServiceDeleteInputWithSdncHeader()
223 throws ExecutionException, InterruptedException {
224 ServiceDeleteInput input = new ServiceDeleteInputBuilder()
225 .setSdncRequestHeader(new SdncRequestHeaderBuilder().setRequestId("12").build()).build();
226 ListenableFuture<RpcResult<ServiceDeleteOutput>> serviceDeleteOutputF =
227 ModelMappingUtils.createDeleteServiceReply(input, "ack", "message", "200");
228 serviceDeleteOutputF.addListener(new Runnable() {
232 endSignal.countDown();
237 RpcResult<ServiceDeleteOutput> serviceDeleteOutput = serviceDeleteOutputF.get();
238 Assert.assertEquals("200", serviceDeleteOutput.getResult().getConfigurationResponseCommon().getResponseCode());
240 "ack", serviceDeleteOutput.getResult().getConfigurationResponseCommon().getAckFinalIndicator());
242 "message", serviceDeleteOutput.getResult().getConfigurationResponseCommon().getResponseMessage());
243 Assert.assertEquals("12", serviceDeleteOutput.getResult().getConfigurationResponseCommon().getRequestId());
247 public void createDeleteServiceReplyWithServiceDeleteInputWithoutSdncHeader()
248 throws ExecutionException, InterruptedException {
249 ServiceDeleteInput input = new ServiceDeleteInputBuilder().build();
250 ListenableFuture<RpcResult<ServiceDeleteOutput>> serviceDeleteOutputF =
251 ModelMappingUtils.createDeleteServiceReply(input, "ack", "message", "200");
252 serviceDeleteOutputF.addListener(new Runnable() {
256 endSignal.countDown();
261 RpcResult<ServiceDeleteOutput> serviceDeleteOutput = serviceDeleteOutputF.get();
262 Assert.assertEquals("200", serviceDeleteOutput.getResult().getConfigurationResponseCommon().getResponseCode());
264 "ack", serviceDeleteOutput.getResult().getConfigurationResponseCommon().getAckFinalIndicator());
266 "message", serviceDeleteOutput.getResult().getConfigurationResponseCommon().getResponseMessage());
267 Assert.assertNull(serviceDeleteOutput.getResult().getConfigurationResponseCommon().getRequestId());
271 public void createCreateServiceReplyWithServiceCreatInputWithSdncRequestHeader()
272 throws ExecutionException, InterruptedException {
273 ServiceCreateInput input =
274 new ServiceCreateInputBuilder()
275 .setSdncRequestHeader(new SdncRequestHeaderBuilder().setRequestId("12").build()).build();
276 ListenableFuture<RpcResult<ServiceCreateOutput>> serviceCreatOutputF =
277 ModelMappingUtils.createCreateServiceReply(input, "ack", "message", "200");
278 serviceCreatOutputF.addListener(new Runnable() {
282 endSignal.countDown();
287 RpcResult<ServiceCreateOutput> serviceCreatOutput = serviceCreatOutputF.get();
288 Assert.assertEquals("200", serviceCreatOutput.getResult().getConfigurationResponseCommon().getResponseCode());
290 "ack", serviceCreatOutput.getResult().getConfigurationResponseCommon().getAckFinalIndicator());
292 "message", serviceCreatOutput.getResult().getConfigurationResponseCommon().getResponseMessage());
293 Assert.assertEquals("12", serviceCreatOutput.getResult().getConfigurationResponseCommon().getRequestId());
297 public void createCreateServiceReplyWithServiceCreatInputWithoutSdncRequestHeader()
298 throws ExecutionException, InterruptedException {
299 ServiceCreateInput input = new ServiceCreateInputBuilder().build();
300 ListenableFuture<RpcResult<ServiceCreateOutput>> serviceCreatOutputF =
301 ModelMappingUtils.createCreateServiceReply(input, "ack", "message", "200");
302 serviceCreatOutputF.addListener(new Runnable() {
306 endSignal.countDown();
311 RpcResult<ServiceCreateOutput> serviceCreatOutput = serviceCreatOutputF.get();
312 Assert.assertEquals("200", serviceCreatOutput.getResult().getConfigurationResponseCommon().getResponseCode());
314 "ack", serviceCreatOutput.getResult().getConfigurationResponseCommon().getAckFinalIndicator());
316 "message", serviceCreatOutput.getResult().getConfigurationResponseCommon().getResponseMessage());
317 Assert.assertNull(serviceCreatOutput.getResult().getConfigurationResponseCommon().getRequestId());
321 public void createCreateServiceReplyWithTempServiceCreatInputWithSdncRequestHeader()
322 throws ExecutionException, InterruptedException {
323 TempServiceCreateInput input =
324 new TempServiceCreateInputBuilder()
325 .setSdncRequestHeader(new SdncRequestHeaderBuilder().setRequestId("12").build()).build();
326 ListenableFuture<RpcResult<TempServiceCreateOutput>> serviceCreatOutputF =
327 ModelMappingUtils.createCreateServiceReply(input, "ack", "message", "200");
328 serviceCreatOutputF.addListener(new Runnable() {
332 endSignal.countDown();
337 RpcResult<TempServiceCreateOutput> serviceCreatOutput = serviceCreatOutputF.get();
338 Assert.assertEquals("200", serviceCreatOutput.getResult().getConfigurationResponseCommon().getResponseCode());
340 "ack", serviceCreatOutput.getResult().getConfigurationResponseCommon().getAckFinalIndicator());
342 "message", serviceCreatOutput.getResult().getConfigurationResponseCommon().getResponseMessage());
343 Assert.assertEquals("12", serviceCreatOutput.getResult().getConfigurationResponseCommon().getRequestId());
347 public void createCreateServiceReplyWithTempServiceCreatInputWithoutSdncRequestHeader()
348 throws ExecutionException, InterruptedException {
349 TempServiceCreateInput input = new TempServiceCreateInputBuilder().build();
350 ListenableFuture<RpcResult<TempServiceCreateOutput>> serviceCreatOutputF =
351 ModelMappingUtils.createCreateServiceReply(input, "ack", "message", "200");
352 serviceCreatOutputF.addListener(new Runnable() {
356 endSignal.countDown();
361 RpcResult<TempServiceCreateOutput> serviceCreatOutput = serviceCreatOutputF.get();
362 Assert.assertEquals("200", serviceCreatOutput.getResult().getConfigurationResponseCommon().getResponseCode());
364 "ack", serviceCreatOutput.getResult().getConfigurationResponseCommon().getAckFinalIndicator());
366 "message", serviceCreatOutput.getResult().getConfigurationResponseCommon().getResponseMessage());
367 Assert.assertNull(serviceCreatOutput.getResult().getConfigurationResponseCommon().getRequestId());
371 public void createCreateServiceReplyWithServiceFeasibilityCheckInputWithSdncRequestHeader()
372 throws ExecutionException, InterruptedException {
373 ServiceFeasibilityCheckInput input =
374 new ServiceFeasibilityCheckInputBuilder()
375 .setSdncRequestHeader(new SdncRequestHeaderBuilder().setRequestId("12").build()).build();
376 ListenableFuture<RpcResult<ServiceFeasibilityCheckOutput>> serviceCreatOutputF =
377 ModelMappingUtils.createCreateServiceReply(input, "ack", "message", "200");
378 serviceCreatOutputF.addListener(new Runnable() {
382 endSignal.countDown();
387 RpcResult<ServiceFeasibilityCheckOutput> serviceCreatOutput = serviceCreatOutputF.get();
388 Assert.assertEquals("200", serviceCreatOutput.getResult().getConfigurationResponseCommon().getResponseCode());
390 "ack", serviceCreatOutput.getResult().getConfigurationResponseCommon().getAckFinalIndicator());
392 "message", serviceCreatOutput.getResult().getConfigurationResponseCommon().getResponseMessage());
393 Assert.assertEquals("12", serviceCreatOutput.getResult().getConfigurationResponseCommon().getRequestId());
397 public void createCreateServiceReplyWithServiceFeasibilityCheckInputWithoutSdncRequestHeader()
398 throws ExecutionException, InterruptedException {
399 ServiceFeasibilityCheckInput input = new ServiceFeasibilityCheckInputBuilder().build();
400 ListenableFuture<RpcResult<ServiceFeasibilityCheckOutput>> serviceCreatOutputF =
401 ModelMappingUtils.createCreateServiceReply(input, "ack", "message", "200");
402 serviceCreatOutputF.addListener(new Runnable() {
406 endSignal.countDown();
411 RpcResult<ServiceFeasibilityCheckOutput> serviceCreatOutput = serviceCreatOutputF.get();
412 Assert.assertEquals("200", serviceCreatOutput.getResult().getConfigurationResponseCommon().getResponseCode());
414 "ack", serviceCreatOutput.getResult().getConfigurationResponseCommon().getAckFinalIndicator());
416 "message", serviceCreatOutput.getResult().getConfigurationResponseCommon().getResponseMessage());
417 Assert.assertNull(serviceCreatOutput.getResult().getConfigurationResponseCommon().getRequestId());
421 public void testCreateRestoreServiceReply() throws ExecutionException, InterruptedException {
422 ListenableFuture<RpcResult<ServiceRestorationOutput>> serviceRestorationOutputF =
423 ModelMappingUtils.createRestoreServiceReply("message", RpcStatus.Failed);
424 serviceRestorationOutputF.addListener(new Runnable() {
428 endSignal.countDown();
433 RpcResult<ServiceRestorationOutput> serviceRestorationOutput = serviceRestorationOutputF.get();
434 Assert.assertEquals("message", serviceRestorationOutput.getResult().getStatusMessage());