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;
11 import static org.junit.jupiter.api.Assertions.assertEquals;
12 import static org.junit.jupiter.api.Assertions.assertNotNull;
13 import static org.junit.jupiter.api.Assertions.assertNull;
15 import com.google.common.util.concurrent.ListenableFuture;
16 import com.google.common.util.concurrent.ListeningExecutorService;
17 import com.google.common.util.concurrent.MoreExecutors;
18 import java.time.OffsetDateTime;
19 import java.time.ZoneOffset;
20 import java.time.format.DateTimeFormatter;
23 import java.util.concurrent.CountDownLatch;
24 import java.util.concurrent.ExecutionException;
25 import java.util.concurrent.Executors;
26 import org.junit.jupiter.api.AfterEach;
27 import org.junit.jupiter.api.BeforeEach;
28 import org.junit.jupiter.api.Test;
29 import org.opendaylight.transportpce.common.ResponseCodes;
30 import org.opendaylight.transportpce.servicehandler.utils.ServiceDataUtils;
31 import org.opendaylight.transportpce.test.AbstractTest;
32 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220808.PathComputationRequestOutput;
33 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220808.PathComputationRequestOutputBuilder;
34 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev211210.ConnectionType;
35 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev211210.configuration.response.common.ConfigurationResponseCommonBuilder;
36 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev211210.sdnc.request.header.SdncRequestHeaderBuilder;
37 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.constraints.CoRoutingBuilder;
38 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.constraints.co.routing.ServiceIdentifierListBuilder;
39 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.routing.constraints.HardConstraintsBuilder;
40 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.routing.constraints.SoftConstraintsBuilder;
41 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.ServiceCreateInput;
42 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.ServiceCreateInputBuilder;
43 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.ServiceCreateOutput;
44 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.ServiceDeleteInput;
45 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.ServiceDeleteInputBuilder;
46 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.ServiceDeleteOutput;
47 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.ServiceFeasibilityCheckInput;
48 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.ServiceFeasibilityCheckInputBuilder;
49 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.ServiceFeasibilityCheckOutput;
50 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.ServiceReconfigureInput;
51 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.ServiceReconfigureInputBuilder;
52 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.ServiceRerouteInput;
53 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.ServiceRerouteInputBuilder;
54 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.ServiceRestorationInput;
55 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.ServiceRestorationInputBuilder;
56 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.ServiceRestorationOutput;
57 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.TempServiceCreateInput;
58 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.TempServiceCreateInputBuilder;
59 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.TempServiceCreateOutput;
60 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.service.list.Services;
61 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.service.list.ServicesBuilder;
62 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.service.list.ServicesKey;
63 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev210705.path.description.AToZDirectionBuilder;
64 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev210705.path.description.ZToADirectionBuilder;
65 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev220118.response.parameters.sp.ResponseParametersBuilder;
66 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev220118.response.parameters.sp.response.parameters.PathDescriptionBuilder;
67 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev171017.service.path.list.ServicePaths;
68 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev171017.service.path.list.ServicePathsBuilder;
69 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev171017.service.path.list.ServicePathsKey;
70 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DateAndTime;
71 import org.opendaylight.yangtools.yang.common.RpcResult;
72 import org.opendaylight.yangtools.yang.common.Uint32;
74 public class ModelMappingUtilsTest extends AbstractTest {
76 private ListeningExecutorService executorService;
77 private CountDownLatch endSignal;
78 private static final int NUM_THREADS = 5;
82 executorService = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(NUM_THREADS));
83 endSignal = new CountDownLatch(1);
88 executorService.shutdownNow();
91 private ServiceReconfigureInput buildServiceConfigurationInput() {
92 return new ServiceReconfigureInputBuilder()
93 .setNewServiceName("service 1").setServiceName("service 1").setCommonId("common id")
94 .setConnectionType(ConnectionType.Service).setCustomer("customer").setCustomerContact("customer contact")
95 .setDueDate(new DateAndTime(DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssxxx")
96 .format(OffsetDateTime.now(ZoneOffset.UTC))))
97 .setEndDate(new DateAndTime(DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssxxx")
98 .format(OffsetDateTime.now(ZoneOffset.UTC).plusDays(10))))
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 .setCustomerCode(Set.of("Some customer-code"))
104 .setCoRouting(new CoRoutingBuilder()
105 .setServiceIdentifierList(Map.of(
106 new org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210
107 .constraints.co.routing.ServiceIdentifierListKey("Some existing-service"),
108 new ServiceIdentifierListBuilder().setServiceIdentifier("Some existing-service")
112 .setSoftConstraints(new SoftConstraintsBuilder()
113 .setCustomerCode(Set.of("Some customer-code"))
114 .setCoRouting(new CoRoutingBuilder()
115 .setServiceIdentifierList(Map.of(
116 new org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210
117 .constraints.co.routing.ServiceIdentifierListKey("Some existing-service"),
118 new ServiceIdentifierListBuilder().setServiceIdentifier("Some existing-service")
125 private PathComputationRequestOutput buildPathComputationOutput() {
126 return new PathComputationRequestOutputBuilder()
127 .setConfigurationResponseCommon(new ConfigurationResponseCommonBuilder()
128 .setRequestId("request 1")
129 .setAckFinalIndicator(ResponseCodes.FINAL_ACK_NO)
130 .setResponseCode(ResponseCodes.RESPONSE_OK)
131 .setResponseMessage("PCE calculation in progress")
133 .setResponseParameters(new ResponseParametersBuilder()
134 .setPathDescription(new PathDescriptionBuilder()
135 .setAToZDirection(new AToZDirectionBuilder()
136 .setAToZWavelengthNumber(Uint32.valueOf(1))
137 .setRate(Uint32.valueOf(1))
139 .setZToADirection(new ZToADirectionBuilder()
140 .setZToAWavelengthNumber(Uint32.valueOf(1))
141 .setRate(Uint32.valueOf(1))
149 //TODO : is this unit test relevant ?
150 void mappingServicesNullServiceCreateInput() {
151 Services services = ModelMappingUtils.mappingServices(null, null);
152 assertEquals(new ServicesBuilder().withKey(new ServicesKey("unknown")).build(), services);
156 void mappingServiceNotNullServiceReconfigureInput() {
157 Services services = ModelMappingUtils.mappingServices(null, buildServiceConfigurationInput());
158 assertEquals("service 1", services.getServiceName());
162 void mappingServiceValid() {
163 Services services = ModelMappingUtils.mappingServices(ServiceDataUtils.buildServiceCreateInput(), null);
164 assertEquals("service 1", services.getServiceName());
168 //TODO : is this unit test relevant ?
169 void mappingServicesPathNullServiceCreateInput() {
170 ServicePaths services = ModelMappingUtils.mappingServicePaths(null, buildPathComputationOutput());
171 assertEquals(new ServicePathsBuilder().withKey(new ServicePathsKey("unknown")).build(), services);
175 void mappingServicePathWithServiceInputWithHardConstraints() {
176 ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInputWithHardConstraints();
177 ServiceInput serviceInput = new ServiceInput(createInput);
178 ServicePaths services = ModelMappingUtils.mappingServicePaths(serviceInput, buildPathComputationOutput());
179 assertEquals(serviceInput.getServiceName(), services.getServicePathName());
180 assertNotNull(services.getHardConstraints());
184 void mappingServicePathWithServiceInputWithSoftConstraints() {
185 ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInputWithSoftConstraints();
186 ServiceInput serviceInput = new ServiceInput(createInput);
187 ServicePaths services = ModelMappingUtils.mappingServicePaths(serviceInput, buildPathComputationOutput());
188 assertEquals(serviceInput.getServiceName(), services.getServicePathName());
189 assertNotNull(services.getSoftConstraints());
193 void createServiceDeleteInputWithServiceRerouteInput() {
194 ServiceRerouteInput serviceRerouteinput = new ServiceRerouteInputBuilder().setServiceName("reroute").build();
195 Services services = new ServicesBuilder()
196 .withKey(new ServicesKey("reroute"))
197 .setSdncRequestHeader(new SdncRequestHeaderBuilder().setRequestId("123").build())
199 var serviceDeleteInput = ModelMappingUtils.createServiceDeleteInput(serviceRerouteinput, services);
200 assertEquals("reroute", serviceDeleteInput.getServiceName());
201 assertEquals("123", serviceDeleteInput.getServiceHandlerHeader().getRequestId());
205 void createServiceDeleteInputWithServiceReconfigureInput() {
206 ServiceReconfigureInput serviceReconfigureInput = new ServiceReconfigureInputBuilder()
207 .setServiceName("reconf")
209 var serviceDeleteInput = ModelMappingUtils.createServiceDeleteInput(serviceReconfigureInput);
210 assertEquals("reconf", serviceDeleteInput.getServiceName());
211 assertEquals("reconf-reconfigure", serviceDeleteInput.getServiceHandlerHeader().getRequestId());
215 void createServiceDeleteInputWithServiceRestorationInput() {
216 Services services = new ServicesBuilder()
217 .withKey(new ServicesKey("rest"))
218 .setSdncRequestHeader(new SdncRequestHeaderBuilder().setRequestId("123").build())
220 ServiceRestorationInput serviceRestorationInput = new ServiceRestorationInputBuilder()
221 .setServiceName("rest")
223 var serviceDeleteInput = ModelMappingUtils.createServiceDeleteInput(serviceRestorationInput, services);
224 assertEquals("rest", serviceDeleteInput.getServiceName());
225 assertEquals("123", serviceDeleteInput.getServiceHandlerHeader().getRequestId());
229 void createDeleteServiceReplyWithServiceDeleteInputWithSdncHeader()
230 throws ExecutionException, InterruptedException {
231 ServiceDeleteInput input = new ServiceDeleteInputBuilder()
232 .setSdncRequestHeader(new SdncRequestHeaderBuilder().setRequestId("12").build())
234 ListenableFuture<RpcResult<ServiceDeleteOutput>> serviceDeleteOutputF =
235 ModelMappingUtils.createDeleteServiceReply(input, "ack", "message", "200");
236 serviceDeleteOutputF.addListener(new Runnable() {
239 endSignal.countDown();
244 RpcResult<ServiceDeleteOutput> serviceDeleteOutput = serviceDeleteOutputF.get();
245 assertEquals("200", serviceDeleteOutput.getResult().getConfigurationResponseCommon().getResponseCode());
246 assertEquals("ack", serviceDeleteOutput.getResult().getConfigurationResponseCommon().getAckFinalIndicator());
247 assertEquals("message", serviceDeleteOutput.getResult().getConfigurationResponseCommon().getResponseMessage());
248 assertEquals("12", serviceDeleteOutput.getResult().getConfigurationResponseCommon().getRequestId());
252 void createDeleteServiceReplyWithServiceDeleteInputWithoutSdncHeader()
253 throws ExecutionException, InterruptedException {
254 ServiceDeleteInput input = new ServiceDeleteInputBuilder().build();
255 ListenableFuture<RpcResult<ServiceDeleteOutput>> serviceDeleteOutputF =
256 ModelMappingUtils.createDeleteServiceReply(input, "ack", "message", "200");
257 serviceDeleteOutputF.addListener(new Runnable() {
260 endSignal.countDown();
265 RpcResult<ServiceDeleteOutput> serviceDeleteOutput = serviceDeleteOutputF.get();
266 assertEquals("200", serviceDeleteOutput.getResult().getConfigurationResponseCommon().getResponseCode());
267 assertEquals("ack", serviceDeleteOutput.getResult().getConfigurationResponseCommon().getAckFinalIndicator());
268 assertEquals("message", serviceDeleteOutput.getResult().getConfigurationResponseCommon().getResponseMessage());
269 assertNull(serviceDeleteOutput.getResult().getConfigurationResponseCommon().getRequestId());
273 void createCreateServiceReplyWithServiceCreatInputWithSdncRequestHeader()
274 throws ExecutionException, InterruptedException {
275 ServiceCreateInput input = new ServiceCreateInputBuilder()
276 .setSdncRequestHeader(new SdncRequestHeaderBuilder().setRequestId("12").build())
278 ListenableFuture<RpcResult<ServiceCreateOutput>> serviceCreatOutputF =
279 ModelMappingUtils.createCreateServiceReply(input, "ack", "message", "200");
280 serviceCreatOutputF.addListener(new Runnable() {
283 endSignal.countDown();
288 RpcResult<ServiceCreateOutput> serviceCreatOutput = serviceCreatOutputF.get();
289 assertEquals("200", serviceCreatOutput.getResult().getConfigurationResponseCommon().getResponseCode());
290 assertEquals("ack", serviceCreatOutput.getResult().getConfigurationResponseCommon().getAckFinalIndicator());
291 assertEquals("message", serviceCreatOutput.getResult().getConfigurationResponseCommon().getResponseMessage());
292 assertEquals("12", serviceCreatOutput.getResult().getConfigurationResponseCommon().getRequestId());
296 void createCreateServiceReplyWithServiceCreatInputWithoutSdncRequestHeader()
297 throws ExecutionException, InterruptedException {
298 ServiceCreateInput input = new ServiceCreateInputBuilder().build();
299 ListenableFuture<RpcResult<ServiceCreateOutput>> serviceCreatOutputF =
300 ModelMappingUtils.createCreateServiceReply(input, "ack", "message", "200");
301 serviceCreatOutputF.addListener(new Runnable() {
304 endSignal.countDown();
309 RpcResult<ServiceCreateOutput> serviceCreatOutput = serviceCreatOutputF.get();
310 assertEquals("200", serviceCreatOutput.getResult().getConfigurationResponseCommon().getResponseCode());
311 assertEquals("ack", serviceCreatOutput.getResult().getConfigurationResponseCommon().getAckFinalIndicator());
312 assertEquals("message", serviceCreatOutput.getResult().getConfigurationResponseCommon().getResponseMessage());
313 assertNull(serviceCreatOutput.getResult().getConfigurationResponseCommon().getRequestId());
317 void createCreateServiceReplyWithTempServiceCreatInputWithSdncRequestHeader()
318 throws ExecutionException, InterruptedException {
319 TempServiceCreateInput input = new TempServiceCreateInputBuilder()
320 .setSdncRequestHeader(new SdncRequestHeaderBuilder().setRequestId("12").build())
322 ListenableFuture<RpcResult<TempServiceCreateOutput>> serviceCreatOutputF =
323 ModelMappingUtils.createCreateServiceReply(input, "ack", "message", "200");
324 serviceCreatOutputF.addListener(new Runnable() {
327 endSignal.countDown();
332 RpcResult<TempServiceCreateOutput> serviceCreatOutput = serviceCreatOutputF.get();
333 assertEquals("200", serviceCreatOutput.getResult().getConfigurationResponseCommon().getResponseCode());
334 assertEquals("ack", serviceCreatOutput.getResult().getConfigurationResponseCommon().getAckFinalIndicator());
335 assertEquals("message", serviceCreatOutput.getResult().getConfigurationResponseCommon().getResponseMessage());
336 assertEquals("12", serviceCreatOutput.getResult().getConfigurationResponseCommon().getRequestId());
340 void createCreateServiceReplyWithTempServiceCreatInputWithoutSdncRequestHeader()
341 throws ExecutionException, InterruptedException {
342 TempServiceCreateInput input = new TempServiceCreateInputBuilder().build();
343 ListenableFuture<RpcResult<TempServiceCreateOutput>> serviceCreatOutputF =
344 ModelMappingUtils.createCreateServiceReply(input, "ack", "message", "200");
345 serviceCreatOutputF.addListener(new Runnable() {
348 endSignal.countDown();
353 RpcResult<TempServiceCreateOutput> serviceCreatOutput = serviceCreatOutputF.get();
354 assertEquals("200", serviceCreatOutput.getResult().getConfigurationResponseCommon().getResponseCode());
355 assertEquals("ack", serviceCreatOutput.getResult().getConfigurationResponseCommon().getAckFinalIndicator());
356 assertEquals("message", serviceCreatOutput.getResult().getConfigurationResponseCommon().getResponseMessage());
357 assertNull(serviceCreatOutput.getResult().getConfigurationResponseCommon().getRequestId());
361 void createCreateServiceReplyWithServiceFeasibilityCheckInputWithSdncRequestHeader()
362 throws ExecutionException, InterruptedException {
363 ServiceFeasibilityCheckInput input = new ServiceFeasibilityCheckInputBuilder()
364 .setSdncRequestHeader(new SdncRequestHeaderBuilder().setRequestId("12").build())
366 ListenableFuture<RpcResult<ServiceFeasibilityCheckOutput>> serviceCreatOutputF =
367 ModelMappingUtils.createCreateServiceReply(input, "ack", "message", "200");
368 serviceCreatOutputF.addListener(new Runnable() {
371 endSignal.countDown();
376 RpcResult<ServiceFeasibilityCheckOutput> serviceCreatOutput = serviceCreatOutputF.get();
377 assertEquals("200", serviceCreatOutput.getResult().getConfigurationResponseCommon().getResponseCode());
378 assertEquals("ack", serviceCreatOutput.getResult().getConfigurationResponseCommon().getAckFinalIndicator());
379 assertEquals("message", serviceCreatOutput.getResult().getConfigurationResponseCommon().getResponseMessage());
380 assertEquals("12", serviceCreatOutput.getResult().getConfigurationResponseCommon().getRequestId());
384 void createCreateServiceReplyWithServiceFeasibilityCheckInputWithoutSdncRequestHeader()
385 throws ExecutionException, InterruptedException {
386 ServiceFeasibilityCheckInput input = new ServiceFeasibilityCheckInputBuilder().build();
387 ListenableFuture<RpcResult<ServiceFeasibilityCheckOutput>> serviceCreatOutputF =
388 ModelMappingUtils.createCreateServiceReply(input, "ack", "message", "200");
389 serviceCreatOutputF.addListener(new Runnable() {
392 endSignal.countDown();
397 RpcResult<ServiceFeasibilityCheckOutput> serviceCreatOutput = serviceCreatOutputF.get();
398 assertEquals("200", serviceCreatOutput.getResult().getConfigurationResponseCommon().getResponseCode());
399 assertEquals("ack", serviceCreatOutput.getResult().getConfigurationResponseCommon().getAckFinalIndicator());
400 assertEquals("message", serviceCreatOutput.getResult().getConfigurationResponseCommon().getResponseMessage());
401 assertNull(serviceCreatOutput.getResult().getConfigurationResponseCommon().getRequestId());
405 void testCreateRestoreServiceReply() throws ExecutionException, InterruptedException {
406 ListenableFuture<RpcResult<ServiceRestorationOutput>> serviceRestorationOutputF =
407 ModelMappingUtils.createRestoreServiceReply("message");
408 serviceRestorationOutputF.addListener(new Runnable() {
411 endSignal.countDown();