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