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 java.util.Arrays;
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;
26 public class ServiceCreateValidationTest {
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());
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")
48 .setCustomerCode(Arrays.asList("Some customer-code"))
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")
58 .setCustomerCode(Arrays.asList("Some customer-code"))
60 OperationResult result =
61 ServiceCreateValidation.validateServiceCreateRequest(new ServiceInput(input), RpcActions.ServiceCreate);
62 Assert.assertEquals(false, result.isSuccess());
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());
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")
85 .setCustomerCode(Arrays.asList("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());
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")
103 .setCustomerCode(Arrays.asList("Some customer-code"))
105 OperationResult result =
106 ServiceCreateValidation.validateServiceCreateRequest(new ServiceInput(input), RpcActions.ServiceCreate);
107 Assert.assertEquals(true, result.isSuccess());