ServiceHandler unit testing update
[transportpce.git] / servicehandler / src / test / java / org / opendaylight / transportpce / servicehandler / MappingConstraintsTest.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.util.Arrays;
11 import org.junit.Assert;
12 import org.junit.Test;
13 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev161014.constraints.co.routing.or.general.CoRoutingBuilder;
14 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev161014.routing.constraints.HardConstraints;
15 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev161014.routing.constraints.HardConstraintsBuilder;
16 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev161014.routing.constraints.SoftConstraints;
17 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev161014.routing.constraints.SoftConstraintsBuilder;
18
19
20
21 public class MappingConstraintsTest {
22
23     private MappingConstraints mappingConstraints;
24     private HardConstraints hardConstraints;
25     private SoftConstraints softConstraints;
26
27
28     public MappingConstraintsTest() {
29         this.hardConstraints = new HardConstraintsBuilder()
30         .setCoRoutingOrGeneral(new CoRoutingBuilder()
31         .setCoRouting(new org.opendaylight.yang.gen.v1.http.org.openroadm.routing
32             .constrains.rev161014.constraints.co.routing.or.general.co.routing
33             .CoRoutingBuilder().setExistingService(
34             Arrays.asList("Some existing-service")).build())
35         .build())
36         .setCustomerCode(Arrays.asList("Some customer-code"))
37         .build();
38
39         this.softConstraints = new SoftConstraintsBuilder()
40             .setCoRoutingOrGeneral(new CoRoutingBuilder()
41                 .setCoRouting(new org.opendaylight.yang.gen.v1.http.org.openroadm.routing
42                     .constrains.rev161014.constraints.co.routing.or.general.co.routing
43                     .CoRoutingBuilder().setExistingService(
44                     Arrays.asList("Some existing-service")).build())
45                 .build())
46             .setCustomerCode(Arrays.asList("Some customer-code"))
47             .build();
48
49         this.mappingConstraints = new MappingConstraints(hardConstraints, softConstraints);
50     }
51
52     @Test
53     public void serviceToServicePathConstarintsNullHardConstraints() {
54         this.mappingConstraints = new MappingConstraints(null, softConstraints);
55         this.mappingConstraints.serviceToServicePathConstarints();
56         Assert.assertEquals(null, this.mappingConstraints.getServiceHardConstraints());
57         Assert.assertEquals(null, this.mappingConstraints.getServicePathHardConstraints());
58     }
59
60     @Test
61     public void serviceToServicePathConstarintsNullSoftConstraints() {
62         this.mappingConstraints = new MappingConstraints(hardConstraints, null);
63         this.mappingConstraints.serviceToServicePathConstarints();
64         Assert.assertEquals(null, this.mappingConstraints.getServiceSoftConstraints());
65         Assert.assertEquals(null, this.mappingConstraints.getServicePathSoftConstraints());
66     }
67
68     @Test
69     public void serviceToServicePathConstarintsNullConstraints() {
70         this.mappingConstraints = new MappingConstraints(hardConstraints, softConstraints);
71         this.mappingConstraints.setServiceHardConstraints(null);
72         this.mappingConstraints.setServiceSoftConstraints(null);
73         this.mappingConstraints.serviceToServicePathConstarints();
74         Assert.assertEquals(null, this.mappingConstraints.getServiceHardConstraints());
75         Assert.assertEquals(null, this.mappingConstraints.getServicePathHardConstraints());
76         Assert.assertEquals(null, this.mappingConstraints.getServiceSoftConstraints());
77         Assert.assertEquals(null, this.mappingConstraints.getServicePathSoftConstraints());
78     }
79
80     @Test
81     public void serviceToServicePathConstarintsNotNullConstraints() {
82         this.mappingConstraints = new MappingConstraints(hardConstraints, softConstraints);
83         this.mappingConstraints.serviceToServicePathConstarints();
84         Assert.assertEquals(this.hardConstraints.getCoRoutingOrGeneral(), this.mappingConstraints
85             .getServiceHardConstraints().getCoRoutingOrGeneral());
86         Assert.assertEquals(softConstraints, this.mappingConstraints.getServiceSoftConstraints());
87         Assert.assertEquals(null, this.mappingConstraints.getServicePathSoftConstraints());
88     }
89
90     @Test
91     public void serviceToServicePathConstarintsParameterizedConstructor() {
92         this.mappingConstraints = new MappingConstraints(
93             new org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface
94             .routing.constraints.rev170426.routing.constraints.sp.HardConstraintsBuilder()
95             .setCustomerCode(Arrays.asList("Some customer-code"))
96             .setCoRoutingOrGeneral(new org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing
97                 .constraints.rev170426.constraints.sp.co.routing.or.general.CoRoutingBuilder()
98                 .setCoRouting(new org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing
99                     .constraints.rev170426.constraints.sp.co.routing.or.general.co.routing.CoRoutingBuilder()
100                     .setExistingService(Arrays.asList("Some existing-service"))
101                     .build())
102                 .build()).build(),
103             new org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface
104                 .routing.constraints.rev170426.routing.constraints.sp.SoftConstraintsBuilder()
105                 .setCustomerCode(Arrays.asList("Some customer-code"))
106                 .setCoRoutingOrGeneral(new org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing
107                     .constraints.rev170426.constraints.sp.co.routing.or.general.CoRoutingBuilder()
108                     .setCoRouting(new org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing
109                         .constraints.rev170426.constraints.sp.co.routing.or.general.co.routing.CoRoutingBuilder()
110                         .setExistingService(Arrays.asList("Some existing-service"))
111                         .build())
112                     .build()).build());
113
114         this.mappingConstraints.serviceToServicePathConstarints();
115         Assert.assertEquals(new org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing
116             .constraints.rev170426.constraints.sp.co.routing.or.general.CoRoutingBuilder()
117             .setCoRouting(new org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing
118                 .constraints.rev170426.constraints.sp.co.routing.or.general.co.routing.CoRoutingBuilder()
119                 .setExistingService(Arrays.asList("Some existing-service"))
120                 .build())
121             .build(), this.mappingConstraints.getServicePathHardConstraints().getCoRoutingOrGeneral());
122         Assert.assertEquals(new org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface
123             .routing.constraints.rev170426.routing.constraints.sp.SoftConstraintsBuilder()
124             .setCustomerCode(Arrays.asList("Some customer-code"))
125             .setCoRoutingOrGeneral(new org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing
126                 .constraints.rev170426.constraints.sp.co.routing.or.general.CoRoutingBuilder()
127                 .setCoRouting(new org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing
128                     .constraints.rev170426.constraints.sp.co.routing.or.general.co.routing.CoRoutingBuilder()
129                     .setExistingService(Arrays.asList("Some existing-service"))
130                     .build())
131                 .build()).build(), this.mappingConstraints.getServicePathSoftConstraints());
132
133     }
134
135 }