Catalog alignment
[sdc.git] / catalog-be / src / test / java / org / openecomp / sdc / be / components / impl / ServiceValidationsTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20
21 package org.openecomp.sdc.be.components.impl;
22
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;
30
31 import static org.assertj.core.api.Assertions.assertThat;
32 import static org.junit.Assert.fail;
33
34 public class ServiceValidationsTest extends ServiceBussinessLogicBaseTestSetup {
35
36     @Test
37     public void testInvalidEnvironmentContext() {
38         Service newService = createServiceObject(false);
39         newService.setEnvironmentContext("not valid");
40         try {
41             bl.createService(newService, user);
42         } catch (ComponentException exp) {
43             assertComponentException(exp, ActionStatus.INVALID_ENVIRONMENT_CONTEXT, "not valid");
44             return;
45         }
46         fail();
47     }
48
49     @Test
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");
55     }
56
57     @Test
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");
62     }
63
64     @Test
65     public void testInvalidInstantiationType() {
66         Service newService = createServiceObject(false);
67         newService.setInstantiationType("not valid");
68         try {
69             bl.createService(newService, user);
70         } catch (ComponentException exp) {
71             assertComponentException(exp, ActionStatus.INVALID_INSTANTIATION_TYPE, "not valid");
72             return;
73         }
74         fail();
75     }
76
77     @Test
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");
83     }
84
85     @Test
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");
91     }
92
93     @Test
94     public void testInvalidServiceRole() {
95         Service newService = createServiceObject(false);
96         newService.setServiceRole("gsg*");
97         try {
98             bl.createService(newService, user);
99         } catch (ComponentException exp) {
100             assertComponentException(exp, ActionStatus.INVALID_PROPERY, SERVICE_ROLE);
101             return;
102         }
103         fail();
104     }
105
106     @Test
107     public void testTooLongServiceRole() {
108         Service newService = createServiceObject(false);
109         newService.setServiceRole("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
110         try {
111             bl.createService(newService, user);
112         } catch (ComponentException exp) {
113             assertComponentException(exp, ActionStatus.PROPERTY_EXCEEDS_LIMIT, SERVICE_ROLE);
114             return;
115         }
116         fail();
117     }
118
119     @Test
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");
125     }
126
127     @Test
128     public void testInvalidServiceType() {
129         Service newService = createServiceObject(false);
130         newService.setServiceType("gsg*");
131         try {
132             bl.createService(newService, user);
133         } catch (ComponentException exp) {
134             assertComponentException(exp, ActionStatus.INVALID_PROPERY, SERVICE_TYPE);
135             return;
136         }
137         fail();
138     }
139
140     @Test
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");
146     }
147
148     @Test
149     public void testTooLongServiceType() {
150         Service newService = createServiceObject(false);
151         newService.setServiceType("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
152         try {
153             bl.createService(newService, user);
154         } catch (ComponentException exp) {
155             assertComponentException(exp, ActionStatus.PROPERTY_EXCEEDS_LIMIT, SERVICE_TYPE);
156             return;
157         }
158         fail();
159     }
160
161     @Test
162     public void testEcompGeneratedNamingIsMissing() {
163         Service newService = createServiceObject(false);
164         newService.setEcompGeneratedNaming(null);
165         try {
166             bl.createService(newService, user);
167         } catch (ComponentException exp) {
168             assertComponentException(exp, ActionStatus.MISSING_ECOMP_GENERATED_NAMING);
169             return;
170         }
171         fail();
172
173     }
174
175     @Test
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("");
182     }
183
184     @Test
185     public void testInvalidNamingPolicy() {
186         Service newService = createServiceObject(false);
187         newService.setNamingPolicy("פוליסי");
188         try {
189             bl.createService(newService, user);
190         } catch (ComponentException exp) {
191             assertComponentException(exp, ActionStatus.INVALID_NAMING_POLICY);
192             return;
193         }
194         fail();
195     }
196
197     @Test
198     public void testTooLongNamingPolicy() {
199         Service newService = createServiceObject(false);
200         newService.setNamingPolicy("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
201         try {
202             bl.createService(newService, user);
203         } catch (ComponentException exp) {
204             assertComponentException(exp, ActionStatus.NAMING_POLICY_EXCEEDS_LIMIT, "100");
205             return;
206         }
207         fail();
208     }
209 }