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.validation;
10 import static org.junit.jupiter.api.Assertions.assertEquals;
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.rev211210.RpcActions;
19 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.constraints.CoRoutingBuilder;
20 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.constraints.co.routing.ServiceIdentifierListBuilder;
21 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.routing.constraints.HardConstraintsBuilder;
22 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.routing.constraints.SoftConstraintsBuilder;
23 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.ServiceCreateInput;
24 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.ServiceCreateInputBuilder;
27 public class ServiceCreateValidationTest {
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());
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.rev211210
45 .constraints.co.routing.ServiceIdentifierListKey("Some existing-service"),
46 new ServiceIdentifierListBuilder().setServiceIdentifier("Some existing-service")
49 .setCustomerCode(Set.of("Some customer-code"))
51 .setSoftConstraints(new SoftConstraintsBuilder()
52 .setCoRouting(new CoRoutingBuilder()
53 .setServiceIdentifierList(Map.of(
54 new org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210
55 .constraints.co.routing.ServiceIdentifierListKey("Some existing-service"),
56 new ServiceIdentifierListBuilder().setServiceIdentifier("Some existing-service")
59 .setCustomerCode(Set.of("Some customer-code"))
61 OperationResult result = ServiceCreateValidation
62 .validateServiceCreateRequest(new ServiceInput(input), RpcActions.ServiceCreate);
63 assertEquals(false, result.isSuccess());
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());
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.rev211210
82 .constraints.co.routing.ServiceIdentifierListKey("Some existing-service"),
83 new ServiceIdentifierListBuilder().setServiceIdentifier("Some existing-service")
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());
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.rev211210
100 .constraints.co.routing.ServiceIdentifierListKey("Some existing-service"),
101 new ServiceIdentifierListBuilder().setServiceIdentifier("Some existing-service")
104 .setCustomerCode(Set.of("Some customer-code"))
106 OperationResult result = ServiceCreateValidation
107 .validateServiceCreateRequest(new ServiceInput(input), RpcActions.ServiceCreate);
108 assertEquals(true, result.isSuccess());