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.rev170426.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.rev170426.service.path.list.ServicePaths;
33 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev170426.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 this.pathComputationRequestOutput);
87 Assert.assertEquals(new ServicesBuilder().build(), services);
91 public void mappingServiceNotNullServiceReconfigureInput() {
92 Services services = ModelMappingUtils.mappingServices(null, serviceReconfigureInput,
93 this.pathComputationRequestOutput);
94 Assert.assertEquals("service 1", services.getServiceName());
98 public void mappingServiceValid() {
99 Services services = ModelMappingUtils.mappingServices(ServiceDataUtils.buildServiceCreateInput(),
100 serviceReconfigureInput,
101 this.pathComputationRequestOutput);
102 Assert.assertEquals("service 1", services.getServiceName());
106 public void mappingServicesPathNullServiceCreateInput() {
107 ServicePaths services = ModelMappingUtils.mappingServicePaths(null, null,
108 this.pathComputationRequestOutput);
109 Assert.assertEquals(new ServicePathsBuilder().build(), services);
113 public void mappingServicePathsValid() {
114 ServiceCreateInput input = new ServiceCreateInputBuilder(ServiceDataUtils.buildServiceCreateInput())
115 .setHardConstraints(new HardConstraintsBuilder()
116 .setCoRoutingOrGeneral(new CoRoutingBuilder()
117 .setCoRouting(new org.opendaylight.yang.gen.v1.http.org.openroadm.routing
118 .constrains.rev161014.constraints.co.routing.or.general.co.routing
119 .CoRoutingBuilder().setExistingService(
120 Arrays.asList("Some existing-service")).build())
122 .setCustomerCode(Arrays.asList("Some customer-code"))
123 .build()).setSoftConstraints(new SoftConstraintsBuilder()
124 .setCoRoutingOrGeneral(new CoRoutingBuilder()
125 .setCoRouting(new org.opendaylight.yang.gen.v1.http.org.openroadm.routing
126 .constrains.rev161014.constraints.co.routing.or.general.co.routing
127 .CoRoutingBuilder().setExistingService(
128 Arrays.asList("Some existing-service")).build())
130 .setCustomerCode(Arrays.asList("Some customer-code"))
132 ServicePaths servicePaths = ModelMappingUtils.mappingServicePaths(input, serviceReconfigureInput,
133 this.pathComputationRequestOutput);
134 Assert.assertEquals("service 1", servicePaths.getServicePathName());