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 java.time.OffsetDateTime;
11 import java.time.ZoneOffset;
12 import java.time.format.DateTimeFormatter;
13 import java.util.Arrays;
14 import org.junit.Assert;
15 import org.junit.Test;
16 import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
17 import org.opendaylight.transportpce.pce.service.PathComputationService;
18 import org.opendaylight.transportpce.pce.service.PathComputationServiceImpl;
19 import org.opendaylight.transportpce.pce.utils.NotificationPublishServiceMock;
20 import org.opendaylight.transportpce.servicehandler.service.PCEServiceWrapper;
21 import org.opendaylight.transportpce.servicehandler.utils.ServiceDataUtils;
22 import org.opendaylight.transportpce.test.AbstractTest;
23 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev171017.PathComputationRequestOutput;
24 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.ConnectionType;
25 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev161014.constraints.co.routing.or.general.CoRoutingBuilder;
26 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev161014.routing.constraints.HardConstraintsBuilder;
27 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev161014.routing.constraints.SoftConstraintsBuilder;
28 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceReconfigureInput;
29 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceReconfigureInputBuilder;
30 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.service.list.Services;
31 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.service.list.ServicesBuilder;
32 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev171017.service.path.list.ServicePaths;
33 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev171017.service.path.list.ServicePathsBuilder;
34 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DateAndTime;
37 public class ModelMappingUtilsTest extends AbstractTest {
39 private PathComputationRequestOutput pathComputationRequestOutput;
40 private ServiceReconfigureInput serviceReconfigureInput;
41 private PCEServiceWrapper pceServiceWrapper;
43 public ModelMappingUtilsTest() {
44 NotificationPublishService notificationPublishService = new NotificationPublishServiceMock();
45 PathComputationService pathComputationService = new PathComputationServiceImpl(getDataBroker(),
46 notificationPublishService);
47 pceServiceWrapper = new PCEServiceWrapper(pathComputationService);
48 this.pathComputationRequestOutput = pceServiceWrapper.performPCE(ServiceDataUtils.buildServiceCreateInput(),
50 DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssxxx");
51 OffsetDateTime offsetDateTime = OffsetDateTime.now(ZoneOffset.UTC);
52 OffsetDateTime offsetDateTime2 = offsetDateTime.plusDays(10);
53 this.serviceReconfigureInput = new ServiceReconfigureInputBuilder().setNewServiceName("service 1")
54 .setServiceName("service 1").setCommonId("common id").setConnectionType(ConnectionType.Service)
55 .setCustomer("customer").setCustomerContact("customer contact").setDueDate(new DateAndTime(
56 dtf.format(offsetDateTime)))
57 .setEndDate(new DateAndTime(dtf.format(offsetDateTime2)))
58 .setNcCode("nc node").setNciCode("nci node").setSecondaryNciCode("secondry").setOperatorContact("operator")
59 .setServiceAEnd(ServiceDataUtils.getServiceAEndBuildReconfigure().build())
60 .setServiceZEnd(ServiceDataUtils.getServiceZEndBuildReconfigure().build())
61 .setHardConstraints(new HardConstraintsBuilder()
62 .setCoRoutingOrGeneral(new CoRoutingBuilder()
63 .setCoRouting(new org.opendaylight.yang.gen.v1.http.org.openroadm.routing
64 .constrains.rev161014.constraints.co.routing.or.general.co.routing
65 .CoRoutingBuilder().setExistingService(
66 Arrays.asList("Some existing-service")).build())
68 .setCustomerCode(Arrays.asList("Some customer-code"))
70 .setSoftConstraints(new SoftConstraintsBuilder()
71 .setCoRoutingOrGeneral(new CoRoutingBuilder()
72 .setCoRouting(new org.opendaylight.yang.gen.v1.http.org.openroadm.routing
73 .constrains.rev161014.constraints.co.routing.or.general.co.routing
74 .CoRoutingBuilder().setExistingService(
75 Arrays.asList("Some existing-service")).build())
77 .setCustomerCode(Arrays.asList("Some customer-code"))
84 public void mappingServicesNullServiceCreateInput() {
85 Services services = ModelMappingUtils.mappingServices(null, null);
86 Assert.assertEquals(new ServicesBuilder().build(), services);
90 public void mappingServiceNotNullServiceReconfigureInput() {
91 Services services = ModelMappingUtils.mappingServices(null, serviceReconfigureInput);
92 Assert.assertEquals("service 1", services.getServiceName());
96 public void mappingServiceValid() {
97 Services services = ModelMappingUtils.mappingServices(ServiceDataUtils.buildServiceCreateInput(),
98 serviceReconfigureInput);
99 Assert.assertEquals("service 1", services.getServiceName());
103 public void mappingServicesPathNullServiceCreateInput() {
104 ServicePaths services = ModelMappingUtils.mappingServicePaths(null, this.pathComputationRequestOutput);
105 Assert.assertEquals(new ServicePathsBuilder().build(), services);
109 public void mappingServicePathsValid() {
110 ServiceCreateInput input = new ServiceCreateInputBuilder(ServiceDataUtils.buildServiceCreateInput())
111 .setHardConstraints(new HardConstraintsBuilder()
112 .setCoRoutingOrGeneral(new CoRoutingBuilder()
113 .setCoRouting(new org.opendaylight.yang.gen.v1.http.org.openroadm.routing
114 .constrains.rev161014.constraints.co.routing.or.general.co.routing
115 .CoRoutingBuilder().setExistingService(
116 Arrays.asList("Some existing-service")).build())
118 .setCustomerCode(Arrays.asList("Some customer-code"))
119 .build()).setSoftConstraints(new SoftConstraintsBuilder()
120 .setCoRoutingOrGeneral(new CoRoutingBuilder()
121 .setCoRouting(new org.opendaylight.yang.gen.v1.http.org.openroadm.routing
122 .constrains.rev161014.constraints.co.routing.or.general.co.routing
123 .CoRoutingBuilder().setExistingService(
124 Arrays.asList("Some existing-service")).build())
126 .setCustomerCode(Arrays.asList("Some customer-code"))
128 ServicePaths servicePaths = ModelMappingUtils.mappingServicePaths(input, serviceReconfigureInput,
129 this.pathComputationRequestOutput);
130 Assert.assertEquals("service 1", servicePaths.getServicePathName());