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.transportpce.b.c._interface.pathdescription.rev171017.path.description.AToZDirectionBuilder;
59 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.path.description.ZToADirectionBuilder;
60 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev200128.response.parameters.sp.ResponseParameters;
61 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev200128.response.parameters.sp.ResponseParametersBuilder;
62 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev200128.response.parameters.sp.response.parameters.PathDescriptionBuilder;
63 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev171017.service.path.list.ServicePaths;
64 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev171017.service.path.list.ServicePathsBuilder;
65 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DateAndTime;
66 import org.opendaylight.yangtools.yang.common.RpcResult;
69 public class ModelMappingUtilsTest extends AbstractTest {
71 private ListeningExecutorService executorService;
72 private CountDownLatch endSignal;
73 private static final int NUM_THREADS = 5;
74 private boolean callbackRan;
78 executorService = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(NUM_THREADS));
79 endSignal = new CountDownLatch(1);
84 public void tearDown() {
85 executorService.shutdownNow();
88 private ServiceReconfigureInput buildServiceConfigurationInput() {
89 DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssxxx");
90 OffsetDateTime offsetDateTime = OffsetDateTime.now(ZoneOffset.UTC);
91 OffsetDateTime offsetDateTime2 = offsetDateTime.plusDays(10);
92 return new ServiceReconfigureInputBuilder().setNewServiceName("service 1")
93 .setServiceName("service 1").setCommonId("common id").setConnectionType(ConnectionType.Service)
94 .setCustomer("customer").setCustomerContact("customer contact").setDueDate(new DateAndTime(
95 dtf.format(offsetDateTime)))
96 .setEndDate(new DateAndTime(dtf.format(offsetDateTime2)))
97 .setNcCode("nc node").setNciCode("nci node").setSecondaryNciCode("secondry").setOperatorContact("operator")
98 .setServiceAEnd(ServiceDataUtils.getServiceAEndBuildReconfigure().build())
99 .setServiceZEnd(ServiceDataUtils.getServiceZEndBuildReconfigure().build())
100 .setHardConstraints(new HardConstraintsBuilder()
101 .setCoRoutingOrGeneral(new CoRoutingBuilder()
102 .setCoRouting(new org.opendaylight.yang.gen.v1.http.org.openroadm.routing
103 .constrains.rev190329.constraints.co.routing.or.general.co.routing
104 .CoRoutingBuilder().setExistingService(
105 Arrays.asList("Some existing-service")).build())
107 .setCustomerCode(Arrays.asList("Some customer-code"))
109 .setSoftConstraints(new SoftConstraintsBuilder()
110 .setCoRoutingOrGeneral(new CoRoutingBuilder()
111 .setCoRouting(new org.opendaylight.yang.gen.v1.http.org.openroadm.routing
112 .constrains.rev190329.constraints.co.routing.or.general.co.routing
113 .CoRoutingBuilder().setExistingService(
114 Arrays.asList("Some existing-service")).build())
116 .setCustomerCode(Arrays.asList("Some customer-code"))
121 private PathComputationRequestOutput buildPathComputationOutput() {
122 ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder()
123 .setRequestId("request 1").setAckFinalIndicator(ResponseCodes.FINAL_ACK_NO)
124 .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("PCE calculation in progress").build();
125 ResponseParameters responseParameters = new ResponseParametersBuilder()
126 .setPathDescription(new PathDescriptionBuilder()
127 .setAToZDirection(new AToZDirectionBuilder().setAToZWavelengthNumber(1L).setRate(1L).build())
128 .setZToADirection(new ZToADirectionBuilder().setZToAWavelengthNumber(1L).setRate(1L).build()).build())
130 return new PathComputationRequestOutputBuilder().setConfigurationResponseCommon(configurationResponseCommon)
131 .setResponseParameters(responseParameters).build();
135 public void mappingServicesNullServiceCreateInput() {
136 Services services = ModelMappingUtils.mappingServices(null, null);
137 Assert.assertEquals(new ServicesBuilder().build(), services);
141 public void mappingServiceNotNullServiceReconfigureInput() {
142 Services services = ModelMappingUtils.mappingServices(null, buildServiceConfigurationInput());
143 Assert.assertEquals("service 1", services.getServiceName());
147 public void mappingServiceValid() {
148 Services services = ModelMappingUtils.mappingServices(ServiceDataUtils.buildServiceCreateInput(),
150 Assert.assertEquals("service 1", services.getServiceName());
154 public void mappingServicesPathNullServiceCreateInput() {
155 ServicePaths services = ModelMappingUtils.mappingServicePaths(null, buildPathComputationOutput());
156 Assert.assertEquals(new ServicePathsBuilder().build(), services);
160 public void mappingServicePathWithServiceInputWithHardConstraints() {
161 ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInputWithHardConstraints();
162 ServiceInput serviceInput = new ServiceInput(createInput);
163 ServicePaths services = ModelMappingUtils.mappingServicePaths(serviceInput, buildPathComputationOutput());
164 Assert.assertEquals(serviceInput.getServiceName(), services.getServicePathName());
165 Assert.assertNotNull(services.getHardConstraints());
169 public void mappingServicePathWithServiceInputWithSoftConstraints() {
170 ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInputWithSoftConstraints();
171 ServiceInput serviceInput = new ServiceInput(createInput);
172 ServicePaths services = ModelMappingUtils.mappingServicePaths(serviceInput, buildPathComputationOutput());
173 Assert.assertEquals(serviceInput.getServiceName(), services.getServicePathName());
174 Assert.assertNotNull(services.getSoftConstraints());
178 public void createServiceDeleteInputWithServiceRerouteInput() {
179 ServiceRerouteInput serviceRerouteinput = new ServiceRerouteInputBuilder().setServiceName("reroute").build();
180 Services services = new ServicesBuilder()
181 .setSdncRequestHeader(new SdncRequestHeaderBuilder().setRequestId("123").build()).build();
182 org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev200520.ServiceDeleteInput
184 ModelMappingUtils.createServiceDeleteInput(serviceRerouteinput, services);
185 Assert.assertEquals("reroute", serviceDeleteInput.getServiceName());
186 Assert.assertEquals("123", serviceDeleteInput.getServiceHandlerHeader().getRequestId());
190 public void createServiceDeleteInputWithServiceReconfigureInput() {
191 ServiceReconfigureInput serviceReconfigureInput = new ServiceReconfigureInputBuilder()
192 .setServiceName("reconf").build();
193 org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev200520.ServiceDeleteInput
195 ModelMappingUtils.createServiceDeleteInput(serviceReconfigureInput);
196 Assert.assertEquals("reconf", serviceDeleteInput.getServiceName());
197 Assert.assertEquals("reconf-reconfigure", serviceDeleteInput.getServiceHandlerHeader().getRequestId());
201 public void createServiceDeleteInputWithServiceRestorationInput() {
202 Services services = new ServicesBuilder()
203 .setSdncRequestHeader(new SdncRequestHeaderBuilder().setRequestId("123").build()).build();
204 ServiceRestorationInput serviceRestorationInput =
205 new ServiceRestorationInputBuilder().setServiceName("rest").build();
206 org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev200520.ServiceDeleteInput
208 ModelMappingUtils.createServiceDeleteInput(serviceRestorationInput, services);
209 Assert.assertEquals("rest", serviceDeleteInput.getServiceName());
210 Assert.assertEquals("123", serviceDeleteInput.getServiceHandlerHeader().getRequestId());
214 public void createDeleteServiceReplyWithServiceDeleteInputWithSdncHeader()
215 throws ExecutionException, InterruptedException {
216 ServiceDeleteInput input = new ServiceDeleteInputBuilder()
217 .setSdncRequestHeader(new SdncRequestHeaderBuilder().setRequestId("12").build()).build();
218 ListenableFuture<RpcResult<ServiceDeleteOutput>> serviceDeleteOutputF =
219 ModelMappingUtils.createDeleteServiceReply(input, "ack", "message", "200");
220 serviceDeleteOutputF.addListener(new Runnable() {
224 endSignal.countDown();
229 RpcResult<ServiceDeleteOutput> serviceDeleteOutput = serviceDeleteOutputF.get();
230 Assert.assertEquals("200", serviceDeleteOutput.getResult().getConfigurationResponseCommon().getResponseCode());
232 "ack", serviceDeleteOutput.getResult().getConfigurationResponseCommon().getAckFinalIndicator());
234 "message", serviceDeleteOutput.getResult().getConfigurationResponseCommon().getResponseMessage());
235 Assert.assertEquals("12", serviceDeleteOutput.getResult().getConfigurationResponseCommon().getRequestId());
239 public void createDeleteServiceReplyWithServiceDeleteInputWithoutSdncHeader()
240 throws ExecutionException, InterruptedException {
241 ServiceDeleteInput input = new ServiceDeleteInputBuilder().build();
242 ListenableFuture<RpcResult<ServiceDeleteOutput>> serviceDeleteOutputF =
243 ModelMappingUtils.createDeleteServiceReply(input, "ack", "message", "200");
244 serviceDeleteOutputF.addListener(new Runnable() {
248 endSignal.countDown();
253 RpcResult<ServiceDeleteOutput> serviceDeleteOutput = serviceDeleteOutputF.get();
254 Assert.assertEquals("200", serviceDeleteOutput.getResult().getConfigurationResponseCommon().getResponseCode());
256 "ack", serviceDeleteOutput.getResult().getConfigurationResponseCommon().getAckFinalIndicator());
258 "message", serviceDeleteOutput.getResult().getConfigurationResponseCommon().getResponseMessage());
259 Assert.assertNull(serviceDeleteOutput.getResult().getConfigurationResponseCommon().getRequestId());
263 public void createCreateServiceReplyWithServiceCreatInputWithSdncRequestHeader()
264 throws ExecutionException, InterruptedException {
265 ServiceCreateInput input =
266 new ServiceCreateInputBuilder()
267 .setSdncRequestHeader(new SdncRequestHeaderBuilder().setRequestId("12").build()).build();
268 ListenableFuture<RpcResult<ServiceCreateOutput>> serviceCreatOutputF =
269 ModelMappingUtils.createCreateServiceReply(input, "ack", "message", "200");
270 serviceCreatOutputF.addListener(new Runnable() {
274 endSignal.countDown();
279 RpcResult<ServiceCreateOutput> serviceCreatOutput = serviceCreatOutputF.get();
280 Assert.assertEquals("200", serviceCreatOutput.getResult().getConfigurationResponseCommon().getResponseCode());
282 "ack", serviceCreatOutput.getResult().getConfigurationResponseCommon().getAckFinalIndicator());
284 "message", serviceCreatOutput.getResult().getConfigurationResponseCommon().getResponseMessage());
285 Assert.assertEquals("12", serviceCreatOutput.getResult().getConfigurationResponseCommon().getRequestId());
289 public void createCreateServiceReplyWithServiceCreatInputWithoutSdncRequestHeader()
290 throws ExecutionException, InterruptedException {
291 ServiceCreateInput input = new ServiceCreateInputBuilder().build();
292 ListenableFuture<RpcResult<ServiceCreateOutput>> serviceCreatOutputF =
293 ModelMappingUtils.createCreateServiceReply(input, "ack", "message", "200");
294 serviceCreatOutputF.addListener(new Runnable() {
298 endSignal.countDown();
303 RpcResult<ServiceCreateOutput> serviceCreatOutput = serviceCreatOutputF.get();
304 Assert.assertEquals("200", serviceCreatOutput.getResult().getConfigurationResponseCommon().getResponseCode());
306 "ack", serviceCreatOutput.getResult().getConfigurationResponseCommon().getAckFinalIndicator());
308 "message", serviceCreatOutput.getResult().getConfigurationResponseCommon().getResponseMessage());
309 Assert.assertNull(serviceCreatOutput.getResult().getConfigurationResponseCommon().getRequestId());
313 public void createCreateServiceReplyWithTempServiceCreatInputWithSdncRequestHeader()
314 throws ExecutionException, InterruptedException {
315 TempServiceCreateInput input =
316 new TempServiceCreateInputBuilder()
317 .setSdncRequestHeader(new SdncRequestHeaderBuilder().setRequestId("12").build()).build();
318 ListenableFuture<RpcResult<TempServiceCreateOutput>> serviceCreatOutputF =
319 ModelMappingUtils.createCreateServiceReply(input, "ack", "message", "200");
320 serviceCreatOutputF.addListener(new Runnable() {
324 endSignal.countDown();
329 RpcResult<TempServiceCreateOutput> serviceCreatOutput = serviceCreatOutputF.get();
330 Assert.assertEquals("200", serviceCreatOutput.getResult().getConfigurationResponseCommon().getResponseCode());
332 "ack", serviceCreatOutput.getResult().getConfigurationResponseCommon().getAckFinalIndicator());
334 "message", serviceCreatOutput.getResult().getConfigurationResponseCommon().getResponseMessage());
335 Assert.assertEquals("12", serviceCreatOutput.getResult().getConfigurationResponseCommon().getRequestId());
339 public void createCreateServiceReplyWithTempServiceCreatInputWithoutSdncRequestHeader()
340 throws ExecutionException, InterruptedException {
341 TempServiceCreateInput input = new TempServiceCreateInputBuilder().build();
342 ListenableFuture<RpcResult<TempServiceCreateOutput>> serviceCreatOutputF =
343 ModelMappingUtils.createCreateServiceReply(input, "ack", "message", "200");
344 serviceCreatOutputF.addListener(new Runnable() {
348 endSignal.countDown();
353 RpcResult<TempServiceCreateOutput> serviceCreatOutput = serviceCreatOutputF.get();
354 Assert.assertEquals("200", serviceCreatOutput.getResult().getConfigurationResponseCommon().getResponseCode());
356 "ack", serviceCreatOutput.getResult().getConfigurationResponseCommon().getAckFinalIndicator());
358 "message", serviceCreatOutput.getResult().getConfigurationResponseCommon().getResponseMessage());
359 Assert.assertNull(serviceCreatOutput.getResult().getConfigurationResponseCommon().getRequestId());
363 public void createCreateServiceReplyWithServiceFeasibilityCheckInputWithSdncRequestHeader()
364 throws ExecutionException, InterruptedException {
365 ServiceFeasibilityCheckInput input =
366 new ServiceFeasibilityCheckInputBuilder()
367 .setSdncRequestHeader(new SdncRequestHeaderBuilder().setRequestId("12").build()).build();
368 ListenableFuture<RpcResult<ServiceFeasibilityCheckOutput>> serviceCreatOutputF =
369 ModelMappingUtils.createCreateServiceReply(input, "ack", "message", "200");
370 serviceCreatOutputF.addListener(new Runnable() {
374 endSignal.countDown();
379 RpcResult<ServiceFeasibilityCheckOutput> serviceCreatOutput = serviceCreatOutputF.get();
380 Assert.assertEquals("200", serviceCreatOutput.getResult().getConfigurationResponseCommon().getResponseCode());
382 "ack", serviceCreatOutput.getResult().getConfigurationResponseCommon().getAckFinalIndicator());
384 "message", serviceCreatOutput.getResult().getConfigurationResponseCommon().getResponseMessage());
385 Assert.assertEquals("12", serviceCreatOutput.getResult().getConfigurationResponseCommon().getRequestId());
389 public void createCreateServiceReplyWithServiceFeasibilityCheckInputWithoutSdncRequestHeader()
390 throws ExecutionException, InterruptedException {
391 ServiceFeasibilityCheckInput input = new ServiceFeasibilityCheckInputBuilder().build();
392 ListenableFuture<RpcResult<ServiceFeasibilityCheckOutput>> serviceCreatOutputF =
393 ModelMappingUtils.createCreateServiceReply(input, "ack", "message", "200");
394 serviceCreatOutputF.addListener(new Runnable() {
398 endSignal.countDown();
403 RpcResult<ServiceFeasibilityCheckOutput> serviceCreatOutput = serviceCreatOutputF.get();
404 Assert.assertEquals("200", serviceCreatOutput.getResult().getConfigurationResponseCommon().getResponseCode());
406 "ack", serviceCreatOutput.getResult().getConfigurationResponseCommon().getAckFinalIndicator());
408 "message", serviceCreatOutput.getResult().getConfigurationResponseCommon().getResponseMessage());
409 Assert.assertNull(serviceCreatOutput.getResult().getConfigurationResponseCommon().getRequestId());
413 public void testCreateRestoreServiceReply() throws ExecutionException, InterruptedException {
414 ListenableFuture<RpcResult<ServiceRestorationOutput>> serviceRestorationOutputF =
415 ModelMappingUtils.createRestoreServiceReply("message", RpcStatus.Failed);
416 serviceRestorationOutputF.addListener(new Runnable() {
420 endSignal.countDown();
425 RpcResult<ServiceRestorationOutput> serviceRestorationOutput = serviceRestorationOutputF.get();
426 Assert.assertEquals("message", serviceRestorationOutput.getResult().getStatusMessage());