Merge "ROADM To ROADM Path Calculation"
[transportpce.git] / servicehandler / src / test / java / org / opendaylight / transportpce / servicehandler / ModelMappingUtilsTest.java
1 /*
2  * Copyright © 2018 Orange, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.transportpce.servicehandler;
9
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;
35
36
37 public class ModelMappingUtilsTest extends AbstractTest {
38
39     private PathComputationRequestOutput pathComputationRequestOutput;
40     private ServiceReconfigureInput serviceReconfigureInput;
41     private PCEServiceWrapper pceServiceWrapper;
42
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(),
49             true);
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())
67                 .build())
68             .setCustomerCode(Arrays.asList("Some customer-code"))
69             .build())
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())
76                 .build())
77             .setCustomerCode(Arrays.asList("Some customer-code"))
78             .build())
79         .build();
80
81     }
82
83     @Test
84     public void mappingServicesNullServiceCreateInput() {
85         Services services = ModelMappingUtils.mappingServices(null, null);
86         Assert.assertEquals(new ServicesBuilder().build(), services);
87     }
88
89     @Test
90     public void mappingServiceNotNullServiceReconfigureInput() {
91         Services services = ModelMappingUtils.mappingServices(null, serviceReconfigureInput);
92         Assert.assertEquals("service 1", services.getServiceName());
93     }
94
95     @Test
96     public void mappingServiceValid() {
97         Services services = ModelMappingUtils.mappingServices(ServiceDataUtils.buildServiceCreateInput(),
98             serviceReconfigureInput);
99         Assert.assertEquals("service 1", services.getServiceName());
100     }
101
102     @Test
103     public void mappingServicesPathNullServiceCreateInput() {
104         ServicePaths services = ModelMappingUtils.mappingServicePaths(null, null,
105             this.pathComputationRequestOutput);
106         Assert.assertEquals(new ServicePathsBuilder().build(), services);
107     }
108
109     /*@Test
110     public void mappingServicePathsValid() {
111         ServiceCreateInput input = new ServiceCreateInputBuilder(ServiceDataUtils.buildServiceCreateInput())
112             .setHardConstraints(new HardConstraintsBuilder()
113                 .setCoRoutingOrGeneral(new CoRoutingBuilder()
114                     .setCoRouting(new org.opendaylight.yang.gen.v1.http.org.openroadm.routing
115                         .constrains.rev161014.constraints.co.routing.or.general.co.routing
116                         .CoRoutingBuilder().setExistingService(
117                         Arrays.asList("Some existing-service")).build())
118                     .build())
119                 .setCustomerCode(Arrays.asList("Some customer-code"))
120                 .build()).setSoftConstraints(new SoftConstraintsBuilder()
121                 .setCoRoutingOrGeneral(new CoRoutingBuilder()
122                     .setCoRouting(new org.opendaylight.yang.gen.v1.http.org.openroadm.routing
123                         .constrains.rev161014.constraints.co.routing.or.general.co.routing
124                         .CoRoutingBuilder().setExistingService(
125                         Arrays.asList("Some existing-service")).build())
126                     .build())
127                 .setCustomerCode(Arrays.asList("Some customer-code"))
128                 .build()).build();
129         ServicePaths servicePaths = ModelMappingUtils.mappingServicePaths(input, serviceReconfigureInput,
130             this.pathComputationRequestOutput);
131         Assert.assertEquals("service 1", servicePaths.getServicePathName());
132     }*/
133
134 }