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.Ignore;
24 import org.junit.Test;
25 import org.opendaylight.transportpce.common.ResponseCodes;
26 import org.opendaylight.transportpce.servicehandler.utils.ServiceDataUtils;
27 import org.opendaylight.transportpce.test.AbstractTest;
28 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev200128.PathComputationRequestOutput;
29 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev200128.PathComputationRequestOutputBuilder;
30 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev190531.ConnectionType;
31 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev190531.configuration.response.common.ConfigurationResponseCommon;
32 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev190531.configuration.response.common.ConfigurationResponseCommonBuilder;
33 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev190531.sdnc.request.header.SdncRequestHeaderBuilder;
34 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev190531.RpcStatus;
35 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev190329.constraints.co.routing.or.general.CoRoutingBuilder;
36 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev190329.routing.constraints.HardConstraintsBuilder;
37 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev190329.routing.constraints.SoftConstraintsBuilder;
38 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceCreateInput;
39 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceCreateInputBuilder;
40 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceCreateOutput;
41 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceDeleteInput;
42 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceDeleteInputBuilder;
43 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceDeleteOutput;
44 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceFeasibilityCheckInput;
45 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceFeasibilityCheckInputBuilder;
46 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceFeasibilityCheckOutput;
47 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceReconfigureInput;
48 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceReconfigureInputBuilder;
49 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceRerouteInput;
50 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceRerouteInputBuilder;
51 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceRestorationInput;
52 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceRestorationInputBuilder;
53 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceRestorationOutput;
54 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.TempServiceCreateInput;
55 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.TempServiceCreateInputBuilder;
56 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.TempServiceCreateOutput;
57 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.service.list.Services;
58 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.service.list.ServicesBuilder;
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.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DateAndTime;
67 import org.opendaylight.yangtools.yang.common.RpcResult;
68 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 public void mappingServicesNullServiceCreateInput() {
140 Services services = ModelMappingUtils.mappingServices(null, null);
141 Assert.assertEquals(new ServicesBuilder().build(), services);
145 public void mappingServiceNotNullServiceReconfigureInput() {
146 Services services = ModelMappingUtils.mappingServices(null, buildServiceConfigurationInput());
147 Assert.assertEquals("service 1", services.getServiceName());
151 public void mappingServiceValid() {
152 Services services = ModelMappingUtils.mappingServices(ServiceDataUtils.buildServiceCreateInput(),
154 Assert.assertEquals("service 1", services.getServiceName());
158 public void mappingServicesPathNullServiceCreateInput() {
159 ServicePaths services = ModelMappingUtils.mappingServicePaths(null, buildPathComputationOutput());
160 Assert.assertEquals(new ServicePathsBuilder().build(), services);
164 public void mappingServicePathWithServiceInputWithHardConstraints() {
165 ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInputWithHardConstraints();
166 ServiceInput serviceInput = new ServiceInput(createInput);
167 ServicePaths services = ModelMappingUtils.mappingServicePaths(serviceInput, buildPathComputationOutput());
168 Assert.assertEquals(serviceInput.getServiceName(), services.getServicePathName());
169 Assert.assertNotNull(services.getHardConstraints());
173 public void mappingServicePathWithServiceInputWithSoftConstraints() {
174 ServiceCreateInput createInput = ServiceDataUtils.buildServiceCreateInputWithSoftConstraints();
175 ServiceInput serviceInput = new ServiceInput(createInput);
176 ServicePaths services = ModelMappingUtils.mappingServicePaths(serviceInput, buildPathComputationOutput());
177 Assert.assertEquals(serviceInput.getServiceName(), services.getServicePathName());
178 Assert.assertNotNull(services.getSoftConstraints());
182 public void createServiceDeleteInputWithServiceRerouteInput() {
183 ServiceRerouteInput serviceRerouteinput = new ServiceRerouteInputBuilder().setServiceName("reroute").build();
184 Services services = new ServicesBuilder()
185 .setSdncRequestHeader(new SdncRequestHeaderBuilder().setRequestId("123").build()).build();
186 org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev200520.ServiceDeleteInput
188 ModelMappingUtils.createServiceDeleteInput(serviceRerouteinput, services);
189 Assert.assertEquals("reroute", serviceDeleteInput.getServiceName());
190 Assert.assertEquals("123", serviceDeleteInput.getServiceHandlerHeader().getRequestId());
194 public void createServiceDeleteInputWithServiceReconfigureInput() {
195 ServiceReconfigureInput serviceReconfigureInput = new ServiceReconfigureInputBuilder()
196 .setServiceName("reconf").build();
197 org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev200520.ServiceDeleteInput
199 ModelMappingUtils.createServiceDeleteInput(serviceReconfigureInput);
200 Assert.assertEquals("reconf", serviceDeleteInput.getServiceName());
201 Assert.assertEquals("reconf-reconfigure", serviceDeleteInput.getServiceHandlerHeader().getRequestId());
205 public void createServiceDeleteInputWithServiceRestorationInput() {
206 Services services = new ServicesBuilder()
207 .setSdncRequestHeader(new SdncRequestHeaderBuilder().setRequestId("123").build()).build();
208 ServiceRestorationInput serviceRestorationInput =
209 new ServiceRestorationInputBuilder().setServiceName("rest").build();
210 org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev200520.ServiceDeleteInput
212 ModelMappingUtils.createServiceDeleteInput(serviceRestorationInput, services);
213 Assert.assertEquals("rest", serviceDeleteInput.getServiceName());
214 Assert.assertEquals("123", serviceDeleteInput.getServiceHandlerHeader().getRequestId());
218 public void createDeleteServiceReplyWithServiceDeleteInputWithSdncHeader()
219 throws ExecutionException, InterruptedException {
220 ServiceDeleteInput input = new ServiceDeleteInputBuilder()
221 .setSdncRequestHeader(new SdncRequestHeaderBuilder().setRequestId("12").build()).build();
222 ListenableFuture<RpcResult<ServiceDeleteOutput>> serviceDeleteOutputF =
223 ModelMappingUtils.createDeleteServiceReply(input, "ack", "message", "200");
224 serviceDeleteOutputF.addListener(new Runnable() {
228 endSignal.countDown();
233 RpcResult<ServiceDeleteOutput> serviceDeleteOutput = serviceDeleteOutputF.get();
234 Assert.assertEquals("200", serviceDeleteOutput.getResult().getConfigurationResponseCommon().getResponseCode());
236 "ack", serviceDeleteOutput.getResult().getConfigurationResponseCommon().getAckFinalIndicator());
238 "message", serviceDeleteOutput.getResult().getConfigurationResponseCommon().getResponseMessage());
239 Assert.assertEquals("12", serviceDeleteOutput.getResult().getConfigurationResponseCommon().getRequestId());
243 public void createDeleteServiceReplyWithServiceDeleteInputWithoutSdncHeader()
244 throws ExecutionException, InterruptedException {
245 ServiceDeleteInput input = new ServiceDeleteInputBuilder().build();
246 ListenableFuture<RpcResult<ServiceDeleteOutput>> serviceDeleteOutputF =
247 ModelMappingUtils.createDeleteServiceReply(input, "ack", "message", "200");
248 serviceDeleteOutputF.addListener(new Runnable() {
252 endSignal.countDown();
257 RpcResult<ServiceDeleteOutput> serviceDeleteOutput = serviceDeleteOutputF.get();
258 Assert.assertEquals("200", serviceDeleteOutput.getResult().getConfigurationResponseCommon().getResponseCode());
260 "ack", serviceDeleteOutput.getResult().getConfigurationResponseCommon().getAckFinalIndicator());
262 "message", serviceDeleteOutput.getResult().getConfigurationResponseCommon().getResponseMessage());
263 Assert.assertNull(serviceDeleteOutput.getResult().getConfigurationResponseCommon().getRequestId());
267 public void createCreateServiceReplyWithServiceCreatInputWithSdncRequestHeader()
268 throws ExecutionException, InterruptedException {
269 ServiceCreateInput input =
270 new ServiceCreateInputBuilder()
271 .setSdncRequestHeader(new SdncRequestHeaderBuilder().setRequestId("12").build()).build();
272 ListenableFuture<RpcResult<ServiceCreateOutput>> serviceCreatOutputF =
273 ModelMappingUtils.createCreateServiceReply(input, "ack", "message", "200");
274 serviceCreatOutputF.addListener(new Runnable() {
278 endSignal.countDown();
283 RpcResult<ServiceCreateOutput> serviceCreatOutput = serviceCreatOutputF.get();
284 Assert.assertEquals("200", serviceCreatOutput.getResult().getConfigurationResponseCommon().getResponseCode());
286 "ack", serviceCreatOutput.getResult().getConfigurationResponseCommon().getAckFinalIndicator());
288 "message", serviceCreatOutput.getResult().getConfigurationResponseCommon().getResponseMessage());
289 Assert.assertEquals("12", serviceCreatOutput.getResult().getConfigurationResponseCommon().getRequestId());
293 public void createCreateServiceReplyWithServiceCreatInputWithoutSdncRequestHeader()
294 throws ExecutionException, InterruptedException {
295 ServiceCreateInput input = new ServiceCreateInputBuilder().build();
296 ListenableFuture<RpcResult<ServiceCreateOutput>> serviceCreatOutputF =
297 ModelMappingUtils.createCreateServiceReply(input, "ack", "message", "200");
298 serviceCreatOutputF.addListener(new Runnable() {
302 endSignal.countDown();
307 RpcResult<ServiceCreateOutput> serviceCreatOutput = serviceCreatOutputF.get();
308 Assert.assertEquals("200", serviceCreatOutput.getResult().getConfigurationResponseCommon().getResponseCode());
310 "ack", serviceCreatOutput.getResult().getConfigurationResponseCommon().getAckFinalIndicator());
312 "message", serviceCreatOutput.getResult().getConfigurationResponseCommon().getResponseMessage());
313 Assert.assertNull(serviceCreatOutput.getResult().getConfigurationResponseCommon().getRequestId());
317 public void createCreateServiceReplyWithTempServiceCreatInputWithSdncRequestHeader()
318 throws ExecutionException, InterruptedException {
319 TempServiceCreateInput input =
320 new TempServiceCreateInputBuilder()
321 .setSdncRequestHeader(new SdncRequestHeaderBuilder().setRequestId("12").build()).build();
322 ListenableFuture<RpcResult<TempServiceCreateOutput>> serviceCreatOutputF =
323 ModelMappingUtils.createCreateServiceReply(input, "ack", "message", "200");
324 serviceCreatOutputF.addListener(new Runnable() {
328 endSignal.countDown();
333 RpcResult<TempServiceCreateOutput> serviceCreatOutput = serviceCreatOutputF.get();
334 Assert.assertEquals("200", serviceCreatOutput.getResult().getConfigurationResponseCommon().getResponseCode());
336 "ack", serviceCreatOutput.getResult().getConfigurationResponseCommon().getAckFinalIndicator());
338 "message", serviceCreatOutput.getResult().getConfigurationResponseCommon().getResponseMessage());
339 Assert.assertEquals("12", serviceCreatOutput.getResult().getConfigurationResponseCommon().getRequestId());
343 public void createCreateServiceReplyWithTempServiceCreatInputWithoutSdncRequestHeader()
344 throws ExecutionException, InterruptedException {
345 TempServiceCreateInput input = new TempServiceCreateInputBuilder().build();
346 ListenableFuture<RpcResult<TempServiceCreateOutput>> serviceCreatOutputF =
347 ModelMappingUtils.createCreateServiceReply(input, "ack", "message", "200");
348 serviceCreatOutputF.addListener(new Runnable() {
352 endSignal.countDown();
357 RpcResult<TempServiceCreateOutput> serviceCreatOutput = serviceCreatOutputF.get();
358 Assert.assertEquals("200", serviceCreatOutput.getResult().getConfigurationResponseCommon().getResponseCode());
360 "ack", serviceCreatOutput.getResult().getConfigurationResponseCommon().getAckFinalIndicator());
362 "message", serviceCreatOutput.getResult().getConfigurationResponseCommon().getResponseMessage());
363 Assert.assertNull(serviceCreatOutput.getResult().getConfigurationResponseCommon().getRequestId());
367 public void createCreateServiceReplyWithServiceFeasibilityCheckInputWithSdncRequestHeader()
368 throws ExecutionException, InterruptedException {
369 ServiceFeasibilityCheckInput input =
370 new ServiceFeasibilityCheckInputBuilder()
371 .setSdncRequestHeader(new SdncRequestHeaderBuilder().setRequestId("12").build()).build();
372 ListenableFuture<RpcResult<ServiceFeasibilityCheckOutput>> serviceCreatOutputF =
373 ModelMappingUtils.createCreateServiceReply(input, "ack", "message", "200");
374 serviceCreatOutputF.addListener(new Runnable() {
378 endSignal.countDown();
383 RpcResult<ServiceFeasibilityCheckOutput> serviceCreatOutput = serviceCreatOutputF.get();
384 Assert.assertEquals("200", serviceCreatOutput.getResult().getConfigurationResponseCommon().getResponseCode());
386 "ack", serviceCreatOutput.getResult().getConfigurationResponseCommon().getAckFinalIndicator());
388 "message", serviceCreatOutput.getResult().getConfigurationResponseCommon().getResponseMessage());
389 Assert.assertEquals("12", serviceCreatOutput.getResult().getConfigurationResponseCommon().getRequestId());
393 public void createCreateServiceReplyWithServiceFeasibilityCheckInputWithoutSdncRequestHeader()
394 throws ExecutionException, InterruptedException {
395 ServiceFeasibilityCheckInput input = new ServiceFeasibilityCheckInputBuilder().build();
396 ListenableFuture<RpcResult<ServiceFeasibilityCheckOutput>> serviceCreatOutputF =
397 ModelMappingUtils.createCreateServiceReply(input, "ack", "message", "200");
398 serviceCreatOutputF.addListener(new Runnable() {
402 endSignal.countDown();
407 RpcResult<ServiceFeasibilityCheckOutput> serviceCreatOutput = serviceCreatOutputF.get();
408 Assert.assertEquals("200", serviceCreatOutput.getResult().getConfigurationResponseCommon().getResponseCode());
410 "ack", serviceCreatOutput.getResult().getConfigurationResponseCommon().getAckFinalIndicator());
412 "message", serviceCreatOutput.getResult().getConfigurationResponseCommon().getResponseMessage());
413 Assert.assertNull(serviceCreatOutput.getResult().getConfigurationResponseCommon().getRequestId());
417 public void testCreateRestoreServiceReply() throws ExecutionException, InterruptedException {
418 ListenableFuture<RpcResult<ServiceRestorationOutput>> serviceRestorationOutputF =
419 ModelMappingUtils.createRestoreServiceReply("message", RpcStatus.Failed);
420 serviceRestorationOutputF.addListener(new Runnable() {
424 endSignal.countDown();
429 RpcResult<ServiceRestorationOutput> serviceRestorationOutput = serviceRestorationOutputF.get();
430 Assert.assertEquals("message", serviceRestorationOutput.getResult().getStatusMessage());