Update project version for Chlorine release train
[transportpce.git] / servicehandler / src / test / java / org / opendaylight / transportpce / servicehandler / validation / ServiceCreateValidationTest.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.validation;
9
10 import java.util.Map;
11 import java.util.Set;
12 import org.junit.Assert;
13 import org.junit.Test;
14 import org.opendaylight.transportpce.common.OperationResult;
15 import org.opendaylight.transportpce.servicehandler.ServiceInput;
16 import org.opendaylight.transportpce.servicehandler.utils.ServiceDataUtils;
17 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev211210.RpcActions;
18 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.constraints.CoRoutingBuilder;
19 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.constraints.co.routing.ServiceIdentifierListBuilder;
20 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.routing.constraints.HardConstraintsBuilder;
21 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.routing.constraints.SoftConstraintsBuilder;
22 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.ServiceCreateInput;
23 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.ServiceCreateInputBuilder;
24
25
26 public class ServiceCreateValidationTest {
27
28     @Test
29     public void validateServiceCreateRequestIfCommonIdNull() {
30         ServiceCreateInput input = new ServiceCreateInputBuilder(ServiceDataUtils.buildServiceCreateInput())
31             .setCommonId(null).build();
32         OperationResult result =
33                 ServiceCreateValidation.validateServiceCreateRequest(new ServiceInput(input), RpcActions.ServiceCreate);
34         Assert.assertEquals(true, result.isSuccess());
35     }
36
37     @Test
38     public void validateServiceCreateRequestIfConstraintsNotNull() {
39         ServiceCreateInput input = new ServiceCreateInputBuilder(ServiceDataUtils.buildServiceCreateInput())
40             .setHardConstraints(new HardConstraintsBuilder()
41                 .setCoRouting(new CoRoutingBuilder()
42                     .setServiceIdentifierList(Map.of(
43                         new org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210
44                             .constraints.co.routing.ServiceIdentifierListKey("Some existing-service"),
45                         new ServiceIdentifierListBuilder().setServiceIdentifier("Some existing-service")
46                             .build()))
47                     .build())
48                 .setCustomerCode(Set.of("Some customer-code"))
49                 .build())
50             .setSoftConstraints(new SoftConstraintsBuilder()
51                 .setCoRouting(new CoRoutingBuilder()
52                     .setServiceIdentifierList(Map.of(
53                         new org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210
54                             .constraints.co.routing.ServiceIdentifierListKey("Some existing-service"),
55                         new ServiceIdentifierListBuilder().setServiceIdentifier("Some existing-service")
56                             .build()))
57                     .build())
58                 .setCustomerCode(Set.of("Some customer-code"))
59                 .build()).build();
60         OperationResult result =
61                 ServiceCreateValidation.validateServiceCreateRequest(new ServiceInput(input), RpcActions.ServiceCreate);
62         Assert.assertEquals(false, result.isSuccess());
63     }
64
65     @Test
66     public void validateServiceCreateRequestIfConstraintsNull() {
67         ServiceCreateInput input = new ServiceCreateInputBuilder(ServiceDataUtils.buildServiceCreateInput())
68             .setSoftConstraints(null).setHardConstraints(null).build();
69         OperationResult result =
70                 ServiceCreateValidation.validateServiceCreateRequest(new ServiceInput(input), RpcActions.ServiceCreate);
71         Assert.assertEquals(true, result.isSuccess());
72     }
73
74     @Test
75     public void validateServiceCreateRequestIfHardConstraintsNull() {
76         ServiceCreateInput input = new ServiceCreateInputBuilder(ServiceDataUtils.buildServiceCreateInput())
77             .setSoftConstraints(new SoftConstraintsBuilder()
78                 .setCoRouting(new CoRoutingBuilder()
79                     .setServiceIdentifierList(Map.of(
80                         new org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210
81                             .constraints.co.routing.ServiceIdentifierListKey("Some existing-service"),
82                         new ServiceIdentifierListBuilder().setServiceIdentifier("Some existing-service")
83                             .build()))
84                     .build())
85                 .setCustomerCode(Set.of("Some customer-code"))
86                 .build()).setHardConstraints(null).build();
87         OperationResult result =
88                 ServiceCreateValidation.validateServiceCreateRequest(new ServiceInput(input), RpcActions.ServiceCreate);
89         Assert.assertEquals(true, result.isSuccess());
90     }
91
92     @Test
93     public void validateServiceCreateRequestIfSoftConstraintsNull() {
94         ServiceCreateInput input = new ServiceCreateInputBuilder(ServiceDataUtils.buildServiceCreateInput())
95             .setSoftConstraints(null).setHardConstraints(new HardConstraintsBuilder()
96                 .setCoRouting(new CoRoutingBuilder()
97                     .setServiceIdentifierList(Map.of(
98                         new org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210
99                             .constraints.co.routing.ServiceIdentifierListKey("Some existing-service"),
100                         new ServiceIdentifierListBuilder().setServiceIdentifier("Some existing-service")
101                             .build()))
102                     .build())
103                 .setCustomerCode(Set.of("Some customer-code"))
104                 .build()).build();
105         OperationResult result =
106                 ServiceCreateValidation.validateServiceCreateRequest(new ServiceInput(input), RpcActions.ServiceCreate);
107         Assert.assertEquals(true, result.isSuccess());
108     }
109 }