2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.sdc.be.components.impl;
23 import fj.data.Either;
24 import org.junit.Test;
25 import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
26 import org.openecomp.sdc.be.dao.api.ActionStatus;
27 import org.openecomp.sdc.be.model.Service;
28 import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
29 import org.openecomp.sdc.exception.ResponseFormat;
31 import static org.assertj.core.api.Assertions.assertThat;
32 import static org.junit.Assert.fail;
34 public class ServiceValidationsTest extends ServiceBussinessLogicBaseTestSetup {
37 public void testInvalidEnvironmentContext() {
38 Service newService = createServiceObject(false);
39 newService.setEnvironmentContext("not valid");
41 bl.createService(newService, user);
42 } catch (ComponentException exp) {
43 assertComponentException(exp, ActionStatus.INVALID_ENVIRONMENT_CONTEXT, "not valid");
50 public void testValidEnvironmentContext() {
51 Service newService = createServiceObject(false);
52 newService.setEnvironmentContext("Critical_Revenue-Bearing");
53 Either<Service, ResponseFormat> service = bl.validateServiceBeforeCreate(newService, user, AuditingActionEnum.CREATE_RESOURCE);
54 assertThat(service.left().value().getEnvironmentContext()).isEqualTo("Critical_Revenue-Bearing");
58 public void testCreateServiceWithNoEnvironmentContext() {
59 Service newService = createServiceObject(false);
60 Either<Service, ResponseFormat> service = bl.validateServiceBeforeCreate(newService, user, AuditingActionEnum.CREATE_RESOURCE);
61 assertThat(service.left().value().getEnvironmentContext()).isEqualTo("General_Revenue-Bearing");
65 public void testInvalidInstantiationType() {
66 Service newService = createServiceObject(false);
67 newService.setInstantiationType("not valid");
69 bl.createService(newService, user);
70 } catch (ComponentException exp) {
71 assertComponentException(exp, ActionStatus.INVALID_INSTANTIATION_TYPE, "not valid");
78 public void testEmptyInstantiationType() {
79 Service newService = createServiceObject(false);
80 newService.setInstantiationType(null);
81 Either<Service, ResponseFormat> service = bl.validateServiceBeforeCreate(newService, user, AuditingActionEnum.CREATE_RESOURCE);
82 assertThat(service.left().value().getInstantiationType()).isEqualTo("A-la-carte");
86 public void testValidInstantiationType() {
87 Service newService = createServiceObject(false);
88 newService.setInstantiationType("Macro");
89 Either<Service, ResponseFormat> service = bl.validateServiceBeforeCreate(newService, user, AuditingActionEnum.CREATE_RESOURCE);
90 assertThat(service.left().value().getInstantiationType()).isEqualTo("Macro");
94 public void testInvalidServiceRole() {
95 Service newService = createServiceObject(false);
96 newService.setServiceRole("gsg*");
98 bl.createService(newService, user);
99 } catch (ComponentException exp) {
100 assertComponentException(exp, ActionStatus.INVALID_PROPERY, SERVICE_ROLE);
107 public void testTooLongServiceRole() {
108 Service newService = createServiceObject(false);
109 newService.setServiceRole("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
111 bl.createService(newService, user);
112 } catch (ComponentException exp) {
113 assertComponentException(exp, ActionStatus.PROPERTY_EXCEEDS_LIMIT, SERVICE_ROLE);
120 public void testValidServiceRole() {
121 Service newService = createServiceObject(false);
122 newService.setServiceRole("role");
123 Either<Service, ResponseFormat> service = bl.validateServiceBeforeCreate(newService, user, AuditingActionEnum.CREATE_RESOURCE);
124 assertThat(service.left().value().getServiceRole()).isEqualTo("role");
128 public void testInvalidServiceType() {
129 Service newService = createServiceObject(false);
130 newService.setServiceType("gsg*");
132 bl.createService(newService, user);
133 } catch (ComponentException exp) {
134 assertComponentException(exp, ActionStatus.INVALID_PROPERY, SERVICE_TYPE);
141 public void testValidServiceType() {
142 Service newService = createServiceObject(false);
143 newService.setServiceType("type");
144 Either<Service, ResponseFormat> service = bl.validateServiceBeforeCreate(newService, user, AuditingActionEnum.CREATE_RESOURCE);
145 assertThat(service.left().value().getServiceType()).isEqualTo("type");
149 public void testTooLongServiceType() {
150 Service newService = createServiceObject(false);
151 newService.setServiceType("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
153 bl.createService(newService, user);
154 } catch (ComponentException exp) {
155 assertComponentException(exp, ActionStatus.PROPERTY_EXCEEDS_LIMIT, SERVICE_TYPE);
162 public void testEcompGeneratedNamingIsMissing() {
163 Service newService = createServiceObject(false);
164 newService.setEcompGeneratedNaming(null);
166 bl.createService(newService, user);
167 } catch (ComponentException exp) {
168 assertComponentException(exp, ActionStatus.MISSING_ECOMP_GENERATED_NAMING);
176 public void testNamingPolicyWIthEcompNamingFalse() {
177 Service newService = createServiceObject(false);
178 newService.setEcompGeneratedNaming(false);
179 newService.setNamingPolicy("policy");
180 Either<Service, ResponseFormat> service = bl.validateServiceBeforeCreate(newService, user, AuditingActionEnum.CREATE_RESOURCE);
181 assertThat(service.left().value().getNamingPolicy()).isEqualTo("");
185 public void testInvalidNamingPolicy() {
186 Service newService = createServiceObject(false);
187 newService.setNamingPolicy("פוליסי");
189 bl.createService(newService, user);
190 } catch (ComponentException exp) {
191 assertComponentException(exp, ActionStatus.INVALID_NAMING_POLICY);
198 public void testTooLongNamingPolicy() {
199 Service newService = createServiceObject(false);
200 newService.setNamingPolicy("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
202 bl.createService(newService, user);
203 } catch (ComponentException exp) {
204 assertComponentException(exp, ActionStatus.NAMING_POLICY_EXCEEDS_LIMIT, "100");