2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 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.apache.commons.lang3.tuple.ImmutablePair;
25 import org.junit.Assert;
26 import org.junit.Before;
27 import org.junit.Test;
28 import org.mockito.InjectMocks;
29 import org.mockito.Mockito;
30 import org.mockito.MockitoAnnotations;
31 import org.openecomp.sdc.ElementOperationMock;
32 import org.openecomp.sdc.be.auditing.impl.AuditingManager;
33 import org.openecomp.sdc.be.datamodel.api.HighestFilterEnum;
34 import org.openecomp.sdc.be.model.operations.StorageException;
35 import org.openecomp.sdc.be.components.csar.CsarBusinessLogic;
36 import org.openecomp.sdc.be.components.csar.CsarInfo;
37 import org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic.ArtifactOperationEnum;
38 import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
39 import org.openecomp.sdc.be.components.impl.generic.GenericTypeBusinessLogic;
40 import org.openecomp.sdc.be.components.lifecycle.LifecycleBusinessLogic;
41 import org.openecomp.sdc.be.components.lifecycle.LifecycleChangeInfoWithAction;
42 import org.openecomp.sdc.be.components.validation.UserValidations;
43 import org.openecomp.sdc.be.config.ConfigurationManager;
44 import org.openecomp.sdc.be.dao.api.ActionStatus;
45 import org.openecomp.sdc.be.dao.jsongraph.TitanDao;
46 import org.openecomp.sdc.be.dao.titan.TitanOperationStatus;
47 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
48 import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
49 import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
50 import org.openecomp.sdc.be.impl.ComponentsUtils;
51 import org.openecomp.sdc.be.impl.WebAppContextWrapper;
52 import org.openecomp.sdc.be.model.ArtifactDefinition;
53 import org.openecomp.sdc.be.model.Component;
54 import org.openecomp.sdc.be.model.DataTypeDefinition;
55 import org.openecomp.sdc.be.model.InputDefinition;
56 import org.openecomp.sdc.be.model.LifeCycleTransitionEnum;
57 import org.openecomp.sdc.be.model.LifecycleStateEnum;
58 import org.openecomp.sdc.be.model.PropertyDefinition;
59 import org.openecomp.sdc.be.model.Resource;
60 import org.openecomp.sdc.be.model.User;
61 import org.openecomp.sdc.be.model.cache.ApplicationDataTypeCache;
62 import org.openecomp.sdc.be.model.jsontitan.operations.NodeTemplateOperation;
63 import org.openecomp.sdc.be.model.jsontitan.operations.NodeTypeOperation;
64 import org.openecomp.sdc.be.model.jsontitan.operations.TopologyTemplateOperation;
65 import org.openecomp.sdc.be.model.jsontitan.operations.ToscaOperationFacade;
66 import org.openecomp.sdc.be.model.operations.api.ICapabilityTypeOperation;
67 import org.openecomp.sdc.be.model.operations.api.IElementOperation;
68 import org.openecomp.sdc.be.model.operations.api.IInterfaceLifecycleOperation;
69 import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
70 import org.openecomp.sdc.be.model.operations.impl.CacheMangerOperation;
71 import org.openecomp.sdc.be.model.operations.impl.CsarOperation;
72 import org.openecomp.sdc.be.model.operations.impl.GraphLockOperation;
73 import org.openecomp.sdc.be.model.operations.impl.PropertyOperation;
74 import org.openecomp.sdc.be.model.tosca.ToscaPropertyType;
75 import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
76 import org.openecomp.sdc.be.tosca.CsarUtils.NonMetaArtifactInfo;
77 import org.openecomp.sdc.be.user.Role;
78 import org.openecomp.sdc.be.user.UserBusinessLogic;
79 import org.openecomp.sdc.common.api.ArtifactGroupTypeEnum;
80 import org.openecomp.sdc.common.api.ArtifactTypeEnum;
81 import org.openecomp.sdc.common.api.ConfigurationSource;
82 import org.openecomp.sdc.common.api.Constants;
83 import org.openecomp.sdc.common.impl.ExternalConfiguration;
84 import org.openecomp.sdc.common.impl.FSConfigurationSource;
85 import org.openecomp.sdc.common.util.GeneralUtility;
86 import org.openecomp.sdc.common.util.ValidationUtils;
87 import org.openecomp.sdc.exception.ResponseFormat;
88 import org.slf4j.Logger;
89 import org.slf4j.LoggerFactory;
90 import org.springframework.web.context.WebApplicationContext;
92 import javax.servlet.ServletContext;
93 import java.io.IOException;
94 import java.lang.reflect.Method;
95 import java.util.ArrayList;
96 import java.util.EnumMap;
97 import java.util.HashMap;
98 import java.util.List;
100 import java.util.stream.Collectors;
101 import java.util.stream.Stream;
103 import static org.junit.Assert.assertEquals;
104 import static org.junit.Assert.assertFalse;
105 import static org.junit.Assert.assertNotNull;
106 import static org.junit.Assert.assertTrue;
107 import static org.mockito.ArgumentMatchers.any;
108 import static org.mockito.ArgumentMatchers.anyObject;
109 import static org.mockito.ArgumentMatchers.anyString;
110 import static org.mockito.ArgumentMatchers.eq;
111 import static org.mockito.Mockito.when;
113 import static org.assertj.core.api.Java6Assertions.assertThat;
114 import static org.junit.Assert.assertEquals;
115 import static org.junit.Assert.assertFalse;
116 import static org.junit.Assert.assertNotEquals;
117 import static org.junit.Assert.assertNotNull;
118 import static org.junit.Assert.assertTrue;
119 import static org.mockito.ArgumentMatchers.any;
120 import static org.mockito.ArgumentMatchers.eq;
121 import static org.mockito.Mockito.times;
123 public class ResourceBusinessLogicTest {
125 private static final Logger log = LoggerFactory.getLogger(ResourceBusinessLogicTest.class);
126 private static final String RESOURCE_CATEGORY1 = "Network Layer 2-3";
127 private static final String RESOURCE_SUBCATEGORY = "Router";
129 private static final String UPDATED_SUBCATEGORY = "Gateway";
131 private String resourceId = "resourceId1";
132 private String operationId = "uniqueId1";
133 Resource resourceUpdate;
135 private static final String RESOURCE_NAME = "My-Resource_Name with space";
136 private static final String RESOURCE_TOSCA_NAME = "My-Resource_Tosca_Name";
137 private static final String GENERIC_VF_NAME = "org.openecomp.resource.abstract.nodes.VF";
138 private static final String GENERIC_CR_NAME = "org.openecomp.resource.abstract.nodes.CR";
139 private static final String GENERIC_PNF_NAME = "org.openecomp.resource.abstract.nodes.PNF";
141 final ServletContext servletContext = Mockito.mock(ServletContext.class);
142 IElementOperation mockElementDao;
143 TitanDao mockTitanDao = Mockito.mock(TitanDao.class);
144 UserBusinessLogic mockUserAdmin = Mockito.mock(UserBusinessLogic.class);
145 ToscaOperationFacade toscaOperationFacade = Mockito.mock(ToscaOperationFacade.class);
146 NodeTypeOperation nodeTypeOperation = Mockito.mock(NodeTypeOperation.class);
147 NodeTemplateOperation nodeTemplateOperation = Mockito.mock(NodeTemplateOperation.class);
148 TopologyTemplateOperation topologyTemplateOperation = Mockito.mock(TopologyTemplateOperation.class);
149 final LifecycleBusinessLogic lifecycleBl = Mockito.mock(LifecycleBusinessLogic.class);
150 final ICapabilityTypeOperation capabilityTypeOperation = Mockito.mock(ICapabilityTypeOperation.class);
151 final PropertyOperation propertyOperation = Mockito.mock(PropertyOperation.class);
152 final ApplicationDataTypeCache applicationDataTypeCache = Mockito.mock(ApplicationDataTypeCache.class);
153 WebAppContextWrapper webAppContextWrapper = Mockito.mock(WebAppContextWrapper.class);
154 UserValidations userValidations = Mockito.mock(UserValidations.class);
155 WebApplicationContext webAppContext = Mockito.mock(WebApplicationContext.class);
156 IInterfaceLifecycleOperation interfaceTypeOperation = Mockito.mock(IInterfaceLifecycleOperation.class);
159 ResourceBusinessLogic bl = new ResourceBusinessLogic();
160 ResponseFormatManager responseManager = null;
161 GraphLockOperation graphLockOperation = Mockito.mock(GraphLockOperation.class);
163 Resource resourceResponse = null;
164 Resource genericVF = null;
165 Resource genericCR = null;
166 Resource genericVFC = null;
167 Resource genericPNF = null;
168 ComponentsUtils componentsUtils;
169 ArtifactsBusinessLogic artifactManager = new ArtifactsBusinessLogic();
170 CsarOperation csarOperation = Mockito.mock(CsarOperation.class);
172 CsarBusinessLogic csarBusinessLogic = new CsarBusinessLogic();
173 Map<String, DataTypeDefinition> emptyDataTypes = new HashMap<>();
174 private GenericTypeBusinessLogic genericTypeBusinessLogic = Mockito.mock(GenericTypeBusinessLogic.class);
175 CacheMangerOperation cacheManager = Mockito.mock(CacheMangerOperation.class);
176 List<Resource> reslist;
178 public ResourceBusinessLogicTest() {
182 public void setup() {
183 MockitoAnnotations.initMocks(this);
184 Mockito.reset(propertyOperation);
186 ExternalConfiguration.setAppName("catalog-be");
188 // init Configuration
189 String appConfigDir = "src/test/resources/config/catalog-be";
190 ConfigurationSource configurationSource = new FSConfigurationSource(ExternalConfiguration.getChangeListener(), appConfigDir);
191 ConfigurationManager configurationManager = new ConfigurationManager(configurationSource);
192 componentsUtils = new ComponentsUtils(Mockito.mock(AuditingManager.class));
195 mockElementDao = new ElementOperationMock();
197 // User data and management
199 user.setUserId("jh0003");
200 user.setFirstName("Jimmi");
201 user.setLastName("Hendrix");
202 user.setRole(Role.ADMIN.name());
204 Either<User, ActionStatus> eitherGetUser = Either.left(user);
205 when(mockUserAdmin.getUser("jh0003", false)).thenReturn(eitherGetUser);
206 when(userValidations.validateUserExists(eq(user.getUserId()), anyString(), eq(false))).thenReturn(user);
207 when(userValidations.validateUserNotEmpty(eq(user), anyString())).thenReturn(user);
208 // Servlet Context attributes
209 when(servletContext.getAttribute(Constants.CONFIGURATION_MANAGER_ATTR)).thenReturn(configurationManager);
210 when(servletContext.getAttribute(Constants.WEB_APPLICATION_CONTEXT_WRAPPER_ATTR)).thenReturn(webAppContextWrapper);
211 when(webAppContextWrapper.getWebAppContext(servletContext)).thenReturn(webAppContext);
212 when(webAppContext.getBean(IElementOperation.class)).thenReturn(mockElementDao);
214 Either<Integer, StorageOperationStatus> eitherCountRoot = Either.left(1);
215 Either<Boolean, StorageOperationStatus> eitherFalse = Either.left(true);
216 when(toscaOperationFacade.validateComponentNameExists("Root", ResourceTypeEnum.VFC, ComponentTypeEnum.RESOURCE)).thenReturn(eitherFalse);
219 Either<Boolean, StorageOperationStatus> eitherCountExist = Either.left(true);
220 when(toscaOperationFacade.validateComponentNameExists("alreadyExists", ResourceTypeEnum.VFC, ComponentTypeEnum.RESOURCE)).thenReturn(eitherCountExist);
222 Either<Boolean, StorageOperationStatus> eitherCount = Either.left(false);
223 when(toscaOperationFacade.validateComponentNameExists(eq(RESOURCE_NAME), any(ResourceTypeEnum.class), eq(ComponentTypeEnum.RESOURCE))).thenReturn(eitherCount);
224 /*when(toscaOperationFacade.validateComponentNameExists(RESOURCE_NAME, ResourceTypeEnum.VF, ComponentTypeEnum.RESOURCE)).thenReturn(eitherCount);
225 when(toscaOperationFacade.validateComponentNameExists(RESOURCE_NAME, ResourceTypeEnum.PNF, ComponentTypeEnum.RESOURCE)).thenReturn(eitherCount);
226 when(toscaOperationFacade.validateComponentNameExists(RESOURCE_NAME, ResourceTypeEnum.CR, ComponentTypeEnum.RESOURCE)).thenReturn(eitherCount);*/
227 Either<Boolean, StorageOperationStatus> validateDerivedExists = Either.left(true);
228 when(toscaOperationFacade.validateToscaResourceNameExists("Root")).thenReturn(validateDerivedExists);
230 Either<Boolean, StorageOperationStatus> validateDerivedNotExists = Either.left(false);
231 when(toscaOperationFacade.validateToscaResourceNameExists("kuku")).thenReturn(validateDerivedNotExists);
232 when(graphLockOperation.lockComponent(Mockito.anyString(), eq(NodeTypeEnum.Resource))).thenReturn(StorageOperationStatus.OK);
233 when(graphLockOperation.lockComponentByName(Mockito.anyString(), eq(NodeTypeEnum.Resource))).thenReturn(StorageOperationStatus.OK);
236 resourceResponse = createResourceObject(true);
237 Either<Resource, StorageOperationStatus> eitherCreate = Either.left(resourceResponse);
238 Either<Integer, StorageOperationStatus> eitherValidate = Either.left(null);
239 when(toscaOperationFacade.createToscaComponent(any(Resource.class))).thenReturn(eitherCreate);
240 Map<String, DataTypeDefinition> emptyDataTypes = new HashMap<>();
241 when(applicationDataTypeCache.getAll()).thenReturn(Either.left(emptyDataTypes));
242 when(mockTitanDao.commit()).thenReturn(TitanOperationStatus.OK);
245 artifactManager.setNodeTemplateOperation(nodeTemplateOperation);
246 bl = new ResourceBusinessLogic();
247 bl.setElementDao(mockElementDao);
248 bl.setUserAdmin(mockUserAdmin);
249 bl.setCapabilityTypeOperation(capabilityTypeOperation);
250 bl.setComponentsUtils(componentsUtils);
251 bl.setLifecycleManager(lifecycleBl);
252 bl.setGraphLockOperation(graphLockOperation);
253 bl.setArtifactsManager(artifactManager);
254 bl.setPropertyOperation(propertyOperation);
255 bl.setTitanGenericDao(mockTitanDao);
256 bl.setApplicationDataTypeCache(applicationDataTypeCache);
257 bl.setCacheManagerOperation(cacheManager);
258 bl.setGenericTypeBusinessLogic(genericTypeBusinessLogic);
259 toscaOperationFacade.setNodeTypeOperation(nodeTypeOperation);
260 toscaOperationFacade.setTopologyTemplateOperation(topologyTemplateOperation);
261 bl.setToscaOperationFacade(toscaOperationFacade);
262 bl.setUserValidations(userValidations);
263 bl.setInterfaceTypeOperation(interfaceTypeOperation);
265 csarBusinessLogic.setCsarOperation(csarOperation);
266 Resource resourceCsar = createResourceObjectCsar(true);
267 setCanWorkOnResource(resourceCsar);
268 Either<Component, StorageOperationStatus> oldResourceRes = Either.left(resourceCsar);
269 when(toscaOperationFacade.getToscaFullElement(resourceCsar.getUniqueId())).thenReturn(oldResourceRes);
270 responseManager = ResponseFormatManager.getInstance();
272 reslist = new ArrayList<Resource>();
273 reslist.add(resourceResponse);
274 reslist.add(genericVF);
275 reslist.add(genericCR);
276 reslist.add(genericVFC);
277 reslist.add(genericPNF);
278 Either<List<Resource>, StorageOperationStatus> returneval= Either.left(reslist);
279 when(toscaOperationFacade.getAllCertifiedResources(true, true)).thenReturn(returneval);
280 when(toscaOperationFacade.validateComponentNameUniqueness("Resource", ResourceTypeEnum.CR, ComponentTypeEnum.RESOURCE)).thenReturn(Either.left(true));
281 Either<List<Resource>, StorageOperationStatus> returnevalexception= Either.right(StorageOperationStatus.BAD_REQUEST);
282 when(toscaOperationFacade.getAllCertifiedResources(false, false)).thenReturn(returnevalexception);
286 private Resource createResourceObject(boolean afterCreate) {
287 Resource resource = new Resource();
288 resource.setName(RESOURCE_NAME);
289 resource.setToscaResourceName(RESOURCE_TOSCA_NAME);
290 resource.addCategory(RESOURCE_CATEGORY1, RESOURCE_SUBCATEGORY);
291 resource.setDescription("My short description");
292 List<String> tgs = new ArrayList<>();
294 tgs.add(resource.getName());
295 resource.setTags(tgs);
296 List<String> template = new ArrayList<>();
297 template.add("Root");
298 resource.setDerivedFrom(template);
299 resource.setVendorName("Motorola");
300 resource.setVendorRelease("1.0.0");
301 resource.setContactId("ya5467");
302 resource.setIcon("MyIcon");
305 resource.setName(resource.getName());
306 resource.setVersion("0.1");
307 resource.setUniqueId(resource.getName().toLowerCase() + ":" + resource.getVersion());
308 resource.setCreatorUserId(user.getUserId());
309 resource.setCreatorFullName(user.getFirstName() + " " + user.getLastName());
310 resource.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
315 private Resource createResourceObjectCsar(boolean afterCreate) {
316 Resource resource = new Resource();
317 resource.setName(RESOURCE_NAME);
318 resource.addCategory(RESOURCE_CATEGORY1, RESOURCE_SUBCATEGORY);
319 resource.setDescription("My short description");
320 List<String> tgs = new ArrayList<>();
322 tgs.add(resource.getName());
323 resource.setTags(tgs);
324 List<String> template = new ArrayList<>();
325 template.add("Root");
326 resource.setDerivedFrom(template);
327 resource.setVendorName("Motorola");
328 resource.setVendorRelease("1.0.0");
329 resource.setResourceVendorModelNumber("");
330 resource.setContactId("ya5467");
331 resource.setIcon("MyIcon");
332 resource.setCsarUUID("valid_vf.csar");
333 resource.setCsarVersion("1");
336 resource.setName(resource.getName());
337 resource.setVersion("0.1");
339 resource.setUniqueId(resource.getName().toLowerCase() + ":" + resource.getVersion());
340 resource.setCreatorUserId(user.getUserId());
341 resource.setCreatorFullName(user.getFirstName() + " " + user.getLastName());
342 resource.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
347 private Resource setCanWorkOnResource(Resource resource) {
348 resource.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
349 resource.setLastUpdaterUserId(user.getUserId());
354 public void testHappyScenario() {
355 validateUserRoles(Role.ADMIN, Role.DESIGNER);
356 Resource resource = createResourceObject(false);
357 Resource createdResource = null;
359 createdResource= bl.createResource(resource, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
360 assertThat(createResourceObject(true)).isEqualTo(createdResource);
361 } catch(ComponentException e){
362 assertThat(new Integer(200)).isEqualTo(e.getResponseFormat().getStatus());
367 public void testUpdateHappyScenario() {
368 Resource resource = createResourceObjectCsar(true);
369 setCanWorkOnResource(resource);
370 validateUserRoles(Role.ADMIN, Role.DESIGNER);
371 Either<Resource, StorageOperationStatus> resourceLinkedToCsarRes = Either.left(resource);
372 when(toscaOperationFacade.getLatestComponentByCsarOrName(ComponentTypeEnum.RESOURCE, resource.getCsarUUID(), resource.getSystemName())).thenReturn(resourceLinkedToCsarRes);
373 Either<Boolean, StorageOperationStatus> validateDerivedExists = Either.left(true);
374 when(toscaOperationFacade.validateToscaResourceNameExists("Root")).thenReturn(validateDerivedExists);
375 Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
376 when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
377 Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
378 when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
379 Resource createdResource = null;
381 createdResource= bl.validateAndUpdateResourceFromCsar(resource, user, null, null, resource.getUniqueId());
382 assertThat(resource.getUniqueId()).isEqualTo(createdResource.getUniqueId());
383 } catch(ComponentException e){
384 assertThat(new Integer(200)).isEqualTo(e.getResponseFormat().getStatus());
390 public void testFailedResourceValidations() {
391 testResourceNameExist();
392 testResourceNameEmpty();
393 // testResourceNameExceedsLimit();
394 testResourceNameWrongFormat();
395 testResourceDescExceedsLimitCreate();
396 testResourceDescNotEnglish();
397 testResourceDescriptionEmpty();
398 testResourceDescriptionMissing();
399 testResourceIconMissing();
400 testResourceIconInvalid();
401 testResourceIconExceedsLimit();
402 testResourceTagNotExist();
403 testResourceTagEmpty();
404 testTagsExceedsLimitCreate();
405 testTagsNoServiceName();
408 testContactIdTooLong();
409 testContactIdWrongFormatCreate();
410 testResourceContactIdEmpty();
411 testResourceContactIdMissing();
412 testVendorNameExceedsLimit();
413 testVendorNameWrongFormatCreate();
414 testVendorReleaseWrongFormat();
415 testVendorReleaseExceedsLimitCreate();
416 testResourceVendorModelNumberExceedsLimit();
417 testResourceVendorNameMissing();
418 testResourceVendorReleaseMissing();
419 testResourceCategoryExist();
420 testResourceBadCategoryCreate();
421 testHappyScenarioCostLicenseType();
422 testCostWrongFormatCreate();
423 testLicenseTypeWrongFormatCreate();
424 testResourceTemplateNotExist();
425 testResourceTemplateEmpty();
426 testResourceTemplateInvalid();
429 private void testResourceNameExist() {
430 String resourceName = "alreadyExists";
431 Resource resourceExist = createResourceObject(false);
432 resourceExist.setName(resourceName);
433 resourceExist.getTags().add(resourceName);
434 validateUserRoles(Role.ADMIN, Role.DESIGNER);
436 bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
437 } catch (ComponentException e) {
438 assertComponentException(e, ActionStatus.COMPONENT_NAME_ALREADY_EXIST, ComponentTypeEnum.RESOURCE.getValue(), resourceName);
442 private void testResourceNameEmpty() {
443 Resource resourceExist = createResourceObject(false);
444 resourceExist.setName(null);
447 bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
448 } catch (ComponentException e) {
449 assertComponentException(e, ActionStatus.MISSING_COMPONENT_NAME, ComponentTypeEnum.RESOURCE.getValue());
453 private void testResourceNameExceedsLimit() {
454 Resource resourceExccedsNameLimit = createResourceObject(false);
455 // 51 chars, the limit is 50
456 String tooLongResourceName = "zCRCAWjqte0DtgcAAMmcJcXeNubeX1p1vOZNTShAHOYNAHvV3iK";
457 resourceExccedsNameLimit.setName(tooLongResourceName);
460 bl.createResource(resourceExccedsNameLimit, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
461 } catch (ComponentException e) {
462 assertComponentException(e, ActionStatus.COMPONENT_NAME_EXCEEDS_LIMIT, ComponentTypeEnum.RESOURCE.getValue(), "" + ValidationUtils.COMPONENT_NAME_MAX_LENGTH);
466 private void testResourceNameWrongFormat() {
467 Resource resource = createResourceObject(false);
469 String nameWrongFormat = "ljg?fd";
470 resource.setName(nameWrongFormat);
473 bl.createResource(resource, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
474 } catch (ComponentException e) {
475 assertComponentException(e, ActionStatus.INVALID_COMPONENT_NAME, ComponentTypeEnum.RESOURCE.getValue());
479 // Resource name - end
480 // Resource description - start
481 private void testResourceDescExceedsLimitCreate() {
482 Resource resourceExccedsDescLimit = createResourceObject(false);
483 // 1025 chars, the limit is 1024
484 String tooLongResourceDesc = "1GUODojQ0sGzKR4NP7e5j82ADQ3KHTVOaezL95qcbuaqDtjZhAQGQ3iFwKAy580K4WiiXs3u3zq7RzXcSASl5fm0RsWtCMOIDP"
485 + "AOf9Tf2xtXxPCuCIMCR5wOGnNTaFxgnJEHAGxilBhZDgeMNHmCN1rMK5B5IRJOnZxcpcL1NeG3APTCIMP1lNAxngYulDm9heFSBc8TfXAADq7703AvkJT0QPpGq2z2P"
486 + "tlikcAnIjmWgfC5Tm7UH462BAlTyHg4ExnPPL4AO8c92VrD7kZSgSqiy73cN3gLT8uigkKrUgXQFGVUFrXVyyQXYtVM6bLBeuCGQf4C2j8lkNg6M0J3PC0PzMRoinOxk"
487 + "Ae2teeCtVcIj4A1KQo3210j8q2v7qQU69Mabsa6DT9FgE4rcrbiFWrg0Zto4SXWD3o1eJA9o29lTg6kxtklH3TuZTmpi5KVp1NFhS1RpnqF83tzv4mZLKsx7Zh1fEgYvRFwx1"
488 + "ar3RolyDfNoZiGBGTMsZzz7RPFBf2hTnLmNqVGQnHKhhGj0Y5s8t2cbqbO2nmHiJb9uaUVrCGypgbAcJL3KPOBfAVW8PcpmNj4yVjI3L4x5zHjmGZbp9vKshEQODcrmcgsYAoKqe"
489 + "uu5u7jk8XVxEfQ0m5qL8UOErXPlJovSmKUmP5B5T0w299zIWDYCzSoNasHpHjOMDLAiDDeHbozUOn9t3Qou00e9POq4RMM0VnIx1H38nJoJZz2XH8CI5YMQe7oTagaxgQTF2aa0qaq2"
490 + "V6nJsfRGRklGjNhFFYP2cS4Xv2IJO9DSX6LTXOmENrGVJJvMOZcvnBaZPfoAHN0LU4i1SoepLzulIxnZBfkUWFJgZ5wQ0Bco2GC1HMqzW21rwy4XHRxXpXbmW8LVyoA1KbnmVmROycU4"
491 + "scTZ62IxIcIWCVeMjBIcTviXULbPUyqlfEPXWr8IMJtpAaELWgyquPClAREMDs2b9ztKmUeXlMccFES1XWbFTrhBHhmmDyVReEgCwfokrUFR13LTUK1k8I6OEHOs";
493 resourceExccedsDescLimit.setDescription(tooLongResourceDesc);
495 bl.createResource(resourceExccedsDescLimit, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
496 } catch (ComponentException e) {
497 assertComponentException(e, ActionStatus.COMPONENT_DESCRIPTION_EXCEEDS_LIMIT, ComponentTypeEnum.RESOURCE.getValue(), "" + ValidationUtils.COMPONENT_DESCRIPTION_MAX_LENGTH);
501 private void testResourceDescNotEnglish() {
502 Resource notEnglish = createResourceObject(false);
504 String notEnglishDesc = "\uC2B5";
505 notEnglish.setDescription(notEnglishDesc);
508 bl.createResource(notEnglish, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
509 } catch (ComponentException e) {
510 assertComponentException(e, ActionStatus.COMPONENT_INVALID_DESCRIPTION, ComponentTypeEnum.RESOURCE.getValue());
514 private void testResourceDescriptionEmpty() {
515 Resource resourceExist = createResourceObject(false);
516 resourceExist.setDescription("");
519 bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
520 } catch (ComponentException e) {
521 assertComponentException(e, ActionStatus.COMPONENT_MISSING_DESCRIPTION, ComponentTypeEnum.RESOURCE.getValue());
525 private void testResourceDescriptionMissing() {
526 Resource resourceExist = createResourceObject(false);
527 resourceExist.setDescription(null);
530 bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
531 } catch (ComponentException e) {
532 assertComponentException(e, ActionStatus.COMPONENT_MISSING_DESCRIPTION, ComponentTypeEnum.RESOURCE.getValue());
535 // Resource description - end
536 // Resource icon start
538 private void testResourceIconMissing() {
539 Resource resourceExist = createResourceObject(false);
540 resourceExist.setIcon(null);
543 bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
544 } catch (ComponentException e) {
545 assertComponentException(e, ActionStatus.COMPONENT_MISSING_ICON, ComponentTypeEnum.RESOURCE.getValue());
549 private void testResourceIconInvalid() {
550 Resource resourceExist = createResourceObject(false);
551 resourceExist.setIcon("kjk3453^&");
554 bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
555 } catch (ComponentException e) {
556 assertComponentException(e, ActionStatus.COMPONENT_INVALID_ICON, ComponentTypeEnum.RESOURCE.getValue());
560 private void testResourceIconExceedsLimit() {
561 Resource resourceExist = createResourceObject(false);
562 resourceExist.setIcon("dsjfhskdfhskjdhfskjdhkjdhfkshdfksjsdkfhsdfsdfsdfsfsdfsf");
564 bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
565 } catch (ComponentException e) {
566 assertComponentException(e, ActionStatus.COMPONENT_ICON_EXCEEDS_LIMIT, ComponentTypeEnum.RESOURCE.getValue(), "" + ValidationUtils.ICON_MAX_LENGTH);
571 // Resource tags - start
572 private void testResourceTagNotExist() {
573 Resource resourceExist = createResourceObject(false);
574 resourceExist.setTags(null);
576 bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
577 } catch (ComponentException e) {
578 assertComponentException(e, ActionStatus.COMPONENT_MISSING_TAGS);
582 private void testResourceTagEmpty() {
583 Resource resourceExist = createResourceObject(false);
584 resourceExist.setTags(new ArrayList<>());
586 bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
587 } catch (ComponentException e) {
588 assertComponentException(e, ActionStatus.COMPONENT_MISSING_TAGS);
592 private void testTagsExceedsLimitCreate() {
593 Resource resourceExccedsNameLimit = createResourceObject(false);
594 String tag1 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjQ";
595 String tag2 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjW";
596 String tag3 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjE";
597 String tag4 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjb";
598 String tag5 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjr";
599 String tag6 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjf";
600 String tag7 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjg";
601 String tag8 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjd";
602 String tag9 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjf";
603 String tag10 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjg";
604 String tag11 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjh";
605 String tag12 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjj";
606 String tag13 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjk";
607 String tag14 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjs";
608 String tag15 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjz";
609 String tag16 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjx";
610 String tag17 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBj2";
611 String tag18 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBj3";
612 String tag19 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBj4";
613 String tag20 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBj5";
614 String tag21 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBj0";
616 List<String> tagsList = new ArrayList<>();
638 tagsList.add(resourceExccedsNameLimit.getName());
640 resourceExccedsNameLimit.setTags(tagsList);
642 bl.createResource(resourceExccedsNameLimit, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
643 } catch (ComponentException e) {
644 assertComponentException(e, ActionStatus.COMPONENT_TAGS_EXCEED_LIMIT, "" + ValidationUtils.TAG_LIST_MAX_LENGTH);
648 private void testTagsSingleExceedsLimit() {
649 Resource resourceExccedsNameLimit = createResourceObject(false);
650 String tag1 = "afzs2qLBb5X6tZhiunkcEwiFX1qRQY8YZl3y3Du5M5xeQY5Nq9afcFHDZ9HaURw43gH27nAUWM36bMbMylwTFSzzNV8NO4v4ripe6Q15Vc2nPOFI";
651 String tag2 = resourceExccedsNameLimit.getName();
652 List<String> tagsList = new ArrayList<>();
656 resourceExccedsNameLimit.setTags(tagsList);
658 bl.createResource(resourceExccedsNameLimit, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
659 } catch (ComponentException e) {
660 assertComponentException(e, ActionStatus.COMPONENT_SINGLE_TAG_EXCEED_LIMIT, "" + ValidationUtils.TAG_MAX_LENGTH);
664 private void testTagsNoServiceName() {
665 Resource serviceExccedsNameLimit = createResourceObject(false);
666 String tag1 = "afzs2qLBb";
667 List<String> tagsList = new ArrayList<>();
669 serviceExccedsNameLimit.setTags(tagsList);
671 bl.createResource(serviceExccedsNameLimit, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
672 } catch (ComponentException e) {
673 assertComponentException(e, ActionStatus.COMPONENT_INVALID_TAGS_NO_COMP_NAME);
677 private void testInvalidTag() {
678 Resource serviceExccedsNameLimit = createResourceObject(false);
679 String tag1 = "afzs2qLBb%#%";
680 List<String> tagsList = new ArrayList<>();
682 serviceExccedsNameLimit.setTags(tagsList);
684 bl.createResource(serviceExccedsNameLimit, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
685 } catch (ComponentException e) {
686 assertComponentException(e, ActionStatus.INVALID_FIELD_FORMAT, new String[]{"Resource", "tag"});
690 // Resource tags - stop
691 // Resource contact start
693 private void testContactIdTooLong() {
694 Resource resourceContactId = createResourceObject(false);
695 // 59 chars instead of 50
696 String contactIdTooLong = "thisNameIsVeryLongAndExeccedsTheNormalLengthForContactId";
697 resourceContactId.setContactId(contactIdTooLong);
700 bl.createResource(resourceContactId, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
701 } catch (ComponentException e) {
702 assertComponentException(e, ActionStatus.COMPONENT_INVALID_CONTACT, ComponentTypeEnum.RESOURCE.getValue());
706 private void testContactIdWrongFormatCreate() {
707 Resource resourceContactId = createResourceObject(false);
708 // 3 letters and 3 digits and special characters
709 String contactIdFormatWrong = "yrt134!!!";
710 resourceContactId.setContactId(contactIdFormatWrong);
712 bl.createResource(resourceContactId, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
713 } catch (ComponentException e) {
714 assertComponentException(e, ActionStatus.COMPONENT_INVALID_CONTACT, ComponentTypeEnum.RESOURCE.getValue());
718 private void testResourceContactIdEmpty() {
719 Resource resourceExist = createResourceObject(false);
720 resourceExist.setContactId("");
722 bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
723 } catch (ComponentException e) {
724 assertComponentException(e, ActionStatus.COMPONENT_MISSING_CONTACT, ComponentTypeEnum.RESOURCE.getValue());
728 private void testResourceContactIdMissing() {
729 Resource resourceExist = createResourceObject(false);
730 resourceExist.setContactId(null);
732 bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
733 } catch (ComponentException e) {
734 assertComponentException(e, ActionStatus.COMPONENT_MISSING_CONTACT, ComponentTypeEnum.RESOURCE.getValue());
738 private void testVendorNameExceedsLimit() {
739 Resource resourceExccedsVendorNameLimit = createResourceObject(false);
740 String tooLongVendorName = "h1KSyJh9Eh1KSyJh9Eh1KSyJh9Eh1KSyJh9Eh1KSyJh9Eh1KSyJh9Eh1KSyJh9Eh1KSyJh9E";
741 resourceExccedsVendorNameLimit.setVendorName(tooLongVendorName);
743 bl.createResource(resourceExccedsVendorNameLimit, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
744 } catch (ComponentException e) {
745 assertComponentException(e, ActionStatus.VENDOR_NAME_EXCEEDS_LIMIT, "" + ValidationUtils.VENDOR_NAME_MAX_LENGTH);
749 private void testResourceVendorModelNumberExceedsLimit() {
750 Resource resourceExccedsVendorModelNumberLimit = createResourceObject(false);
751 String tooLongVendorModelNumber = "h1KSyJh9Eh1KSyJh9Eh1KSyJh9Eh1KSyJh9Eh1KSyJh9Eh1KSyJh9Eh1KSyJh9Eh1KSyJh9E";
752 resourceExccedsVendorModelNumberLimit.setResourceVendorModelNumber(tooLongVendorModelNumber);
754 bl.createResource(resourceExccedsVendorModelNumberLimit, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
755 } catch (ComponentException e) {
756 assertComponentException(e, ActionStatus.RESOURCE_VENDOR_MODEL_NUMBER_EXCEEDS_LIMIT, "" + ValidationUtils.RESOURCE_VENDOR_MODEL_NUMBER_MAX_LENGTH);
760 private void testVendorNameWrongFormatCreate() {
761 Resource resource = createResourceObject(false);
763 String nameWrongFormat = "ljg*fd";
764 resource.setVendorName(nameWrongFormat);
766 bl.createResource(resource, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
767 } catch (ComponentException e) {
768 assertComponentException(e, ActionStatus.INVALID_VENDOR_NAME);
772 private void testVendorReleaseWrongFormat() {
773 Resource resource = createResourceObject(false);
775 String nameWrongFormat = "1>2";
776 resource.setVendorRelease(nameWrongFormat);
778 bl.createResource(resource, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
779 } catch (ComponentException e) {
780 assertComponentException(e, ActionStatus.INVALID_VENDOR_RELEASE);
784 private void testVendorReleaseExceedsLimitCreate() {
785 Resource resourceExccedsNameLimit = createResourceObject(false);
786 String tooLongVendorRelease = "h1KSyJh9Eh1KSyJh9Eh1KSyJh9Eh1KSyJh9E";
787 resourceExccedsNameLimit.setVendorRelease(tooLongVendorRelease);
789 bl.createResource(resourceExccedsNameLimit, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
790 } catch (ComponentException e) {
791 assertComponentException(e, ActionStatus.VENDOR_RELEASE_EXCEEDS_LIMIT, "" + ValidationUtils.VENDOR_RELEASE_MAX_LENGTH);
795 private void testResourceVendorNameMissing() {
796 Resource resourceExist = createResourceObject(false);
797 resourceExist.setVendorName(null);
799 bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
800 } catch (ComponentException e) {
801 assertComponentException(e, ActionStatus.MISSING_VENDOR_NAME);
805 private void testResourceVendorReleaseMissing() {
806 Resource resourceExist = createResourceObject(false);
807 resourceExist.setVendorRelease(null);
809 bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
810 } catch (ComponentException e) {
811 assertComponentException(e, ActionStatus.MISSING_VENDOR_RELEASE);
815 // Resource vendor name/release stop
817 private void testResourceCategoryExist() {
818 Resource resourceExist = createResourceObject(false);
819 resourceExist.setCategories(null);
821 bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
822 } catch (ComponentException e) {
823 assertComponentException(e, ActionStatus.COMPONENT_MISSING_CATEGORY, ComponentTypeEnum.RESOURCE.getValue());
827 private void testResourceBadCategoryCreate() {
829 Resource resourceExist = createResourceObject(false);
830 resourceExist.setCategories(null);
831 resourceExist.addCategory("koko", "koko");
833 bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
834 } catch (ComponentException e) {
835 assertComponentException(e, ActionStatus.COMPONENT_INVALID_CATEGORY, ComponentTypeEnum.RESOURCE.getValue());
841 private void testHappyScenarioCostLicenseType() {
842 Resource createResourceObject = createResourceObject(false);
843 Resource createResourceObjectAfterCreate = createResourceObject(true);
844 // Adding cost and licenseType to basic mock
845 Either<Resource, StorageOperationStatus> eitherCreate = Either.left(createResourceObjectAfterCreate);
846 when(toscaOperationFacade.createToscaComponent(any(Resource.class))).thenReturn(eitherCreate);
848 String cost = "123.456";
849 String licenseType = "User";
850 createResourceObject.setCost(cost);
851 createResourceObject.setLicenseType(licenseType);
852 Resource createdResource;
854 createdResource = bl.createResource(createResourceObject, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
855 createResourceObjectAfterCreate.setCost(cost);
856 createResourceObjectAfterCreate.setLicenseType(licenseType);
857 assertThat(createResourceObjectAfterCreate).isEqualTo(createdResource);
858 }catch(ComponentException e){
859 assertThat(new Integer(200)).isEqualTo(e.getResponseFormat().getStatus());
863 private void testCostWrongFormatCreate() {
864 Resource resourceCost = createResourceObject(false);
865 // Comma instead of fullstop
866 String cost = "12356,464";
867 resourceCost.setCost(cost);
869 bl.createResource(resourceCost, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
870 } catch (ComponentException e) {
871 assertComponentException(e, ActionStatus.INVALID_CONTENT);
876 // License type start
877 private void testLicenseTypeWrongFormatCreate() {
878 Resource resourceLicenseType = createResourceObject(false);
880 String licenseType = "cpu";
881 resourceLicenseType.setLicenseType(licenseType);
883 bl.createResource(resourceLicenseType, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
884 } catch (ComponentException e) {
885 assertComponentException(e, ActionStatus.INVALID_CONTENT);
890 // Derived from start
891 private void testResourceTemplateNotExist() {
892 Resource resourceExist = createResourceObject(false);
893 List<String> list = null;
894 resourceExist.setDerivedFrom(list);
896 bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
897 } catch (ComponentException e) {
898 assertComponentException(e, ActionStatus.MISSING_DERIVED_FROM_TEMPLATE);
902 private void testResourceTemplateEmpty() {
903 Resource resourceExist = createResourceObject(false);
904 resourceExist.setDerivedFrom(new ArrayList<>());
906 bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
907 } catch (ComponentException e) {
908 assertComponentException(e, ActionStatus.MISSING_DERIVED_FROM_TEMPLATE);
912 private void testResourceTemplateInvalid() {
913 Resource resourceExist = createResourceObject(false);
914 ArrayList<String> derivedFrom = new ArrayList<>();
915 derivedFrom.add("kuku");
916 resourceExist.setDerivedFrom(derivedFrom);
918 bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
919 } catch (ComponentException e) {
920 assertComponentException(e, ActionStatus.PARENT_RESOURCE_NOT_FOUND);
924 private void assertComponentException(ComponentException e, ActionStatus expectedStatus, String... variables) {
925 ResponseFormat actualResponse = e.getResponseFormat() != null ?
926 e.getResponseFormat() : componentsUtils.getResponseFormat(e.getActionStatus(), e.getParams());
927 assertResponse(actualResponse, expectedStatus, variables);
930 private void assertResponse(ResponseFormat actualResponse, ActionStatus expectedStatus, String... variables) {
931 ResponseFormat expectedResponse = responseManager.getResponseFormat(expectedStatus, variables);
932 assertThat(expectedResponse.getStatus()).isEqualTo(actualResponse.getStatus());
933 assertThat(expectedResponse.getFormattedMessage()).isEqualTo(actualResponse.getFormattedMessage());
936 private void assertResponse(Either<Resource, ResponseFormat> createResponse, ActionStatus expectedStatus, String... variables) {
937 assertResponse(createResponse.right().value(), expectedStatus, variables);
940 // UPDATE tests - start
943 public void testResourceNameWrongFormat_UPDATE() {
944 Resource resource = createResourceObject(true);
945 Resource updatedResource = createResourceObject(true);
947 // this is in order to prevent failing with 403 earlier
948 Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
949 when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
951 String nameWrongFormat = "ljg*fd";
952 updatedResource.setName(nameWrongFormat);
954 Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
955 when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
957 bl.updateResourceMetadata(resource.getUniqueId(), updatedResource, null, user, false);
958 } catch (ComponentException e) {
959 assertComponentException(e, ActionStatus.INVALID_COMPONENT_NAME, ComponentTypeEnum.RESOURCE.getValue());
964 public void testResourceNameAfterCertify_UPDATE() {
965 Resource resource = createResourceObject(true);
966 Resource updatedResource = createResourceObject(true);
968 // this is in order to prevent failing with 403 earlier
969 Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
970 // when(resourceOperation.getResource_tx(resource.getUniqueId(),false)).thenReturn(eitherUpdate);
971 when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
974 updatedResource.setName(name);
975 resource.setVersion("1.0");
977 Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
978 when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
980 bl.updateResourceMetadata(resource.getUniqueId(), updatedResource, null, user, false);
981 } catch (ComponentException e) {
982 assertComponentException(e, ActionStatus.RESOURCE_NAME_CANNOT_BE_CHANGED);
987 public void testResourceNameAlreadyExist_UPDATE() {
988 Resource resource = createResourceObject(true);
989 Resource updatedResource = createResourceObject(true);
991 // this is in order to prevent failing with 403 earlier
992 Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
993 when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
995 String resourceName = "alreadyExists";
996 updatedResource.setName(resourceName);
997 Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(updatedResource);
998 when(toscaOperationFacade.updateToscaElement(updatedResource)).thenReturn(dataModelResponse);
1000 bl.updateResourceMetadata(resource.getUniqueId(), updatedResource, null, user, false);
1001 } catch (ComponentException e) {
1002 assertComponentException(e, ActionStatus.COMPONENT_NAME_ALREADY_EXIST, ComponentTypeEnum.RESOURCE.getValue(), resourceName);
1009 public void testResourceDescExceedsLimit_UPDATE() {
1010 Resource resource = createResourceObject(true);
1011 Resource updatedResource = createResourceObject(true);
1013 // this is in order to prevent failing with 403 earlier
1014 Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
1015 when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
1017 // 1025 chars, the limit is 1024
1018 String tooLongResourceDesc = "1GUODojQ0sGzKR4NP7e5j82ADQ3KHTVOaezL95qcbuaqDtjZhAQGQ3iFwKAy580K4WiiXs3u3zq7RzXcSASl5fm0RsWtCMOIDP"
1019 + "AOf9Tf2xtXxPCuCIMCR5wOGnNTaFxgnJEHAGxilBhZDgeMNHmCN1rMK5B5IRJOnZxcpcL1NeG3APTCIMP1lNAxngYulDm9heFSBc8TfXAADq7703AvkJT0QPpGq2z2P"
1020 + "tlikcAnIjmWgfC5Tm7UH462BAlTyHg4ExnPPL4AO8c92VrD7kZSgSqiy73cN3gLT8uigkKrUgXQFGVUFrXVyyQXYtVM6bLBeuCGQf4C2j8lkNg6M0J3PC0PzMRoinOxk"
1021 + "Ae2teeCtVcIj4A1KQo3210j8q2v7qQU69Mabsa6DT9FgE4rcrbiFWrg0Zto4SXWD3o1eJA9o29lTg6kxtklH3TuZTmpi5KVp1NFhS1RpnqF83tzv4mZLKsx7Zh1fEgYvRFwx1"
1022 + "ar3RolyDfNoZiGBGTMsZzz7RPFBf2hTnLmNqVGQnHKhhGj0Y5s8t2cbqbO2nmHiJb9uaUVrCGypgbAcJL3KPOBfAVW8PcpmNj4yVjI3L4x5zHjmGZbp9vKshEQODcrmcgsYAoKqe"
1023 + "uu5u7jk8XVxEfQ0m5qL8UOErXPlJovSmKUmP5B5T0w299zIWDYCzSoNasHpHjOMDLAiDDeHbozUOn9t3Qou00e9POq4RMM0VnIx1H38nJoJZz2XH8CI5YMQe7oTagaxgQTF2aa0qaq2"
1024 + "V6nJsfRGRklGjNhFFYP2cS4Xv2IJO9DSX6LTXOmENrGVJJvMOZcvnBaZPfoAHN0LU4i1SoepLzulIxnZBfkUWFJgZ5wQ0Bco2GC1HMqzW21rwy4XHRxXpXbmW8LVyoA1KbnmVmROycU4"
1025 + "scTZ62IxIcIWCVeMjBIcTviXULbPUyqlfEPXWr8IMJtpAaELWgyquPClAREMDs2b9ztKmUeXlMccFES1XWbFTrhBHhmmDyVReEgCwfokrUFR13LTUK1k8I6OEHOs";
1026 updatedResource.setDescription(tooLongResourceDesc);
1027 Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
1028 when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
1030 bl.updateResourceMetadata(resource.getUniqueId(), updatedResource, null, user, false);
1031 } catch (ComponentException e) {
1032 assertComponentException(e, ActionStatus.COMPONENT_DESCRIPTION_EXCEEDS_LIMIT, ComponentTypeEnum.RESOURCE.getValue(), "" + ValidationUtils.COMPONENT_DESCRIPTION_MAX_LENGTH);
1037 public void testIconWrongFormat_UPDATE() {
1038 Resource resource = createResourceObject(true);
1039 Resource updatedResource = createResourceObject(true);
1041 // this is in order to prevent failing with 403 earlier
1042 Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
1043 when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
1046 String icon = "icon.jpg";
1047 updatedResource.setIcon(icon);
1048 Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
1049 when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
1051 bl.updateResourceMetadata(resource.getUniqueId(), updatedResource, null, user, false);
1052 } catch (ComponentException e) {
1053 assertComponentException(e, ActionStatus.COMPONENT_INVALID_ICON, ComponentTypeEnum.RESOURCE.getValue());
1058 public void testIconAfterCertify_UPDATE() {
1059 Resource resource = createResourceObject(true);
1060 Resource updatedResource = createResourceObject(true);
1062 // this is in order to prevent failing with 403 earlier
1063 Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
1064 when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
1067 String icon = "icon";
1068 updatedResource.setIcon(icon);
1070 resource.setVersion("1.0");
1072 Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
1073 when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
1075 bl.updateResourceMetadata(resource.getUniqueId(), updatedResource, null, user, false);
1076 } catch (ComponentException e) {
1077 assertComponentException(e, ActionStatus.RESOURCE_ICON_CANNOT_BE_CHANGED);
1082 public void testTagsExceedsLimit_UPDATE() {
1083 Resource resource = createResourceObject(true);
1084 Resource updatedResource = createResourceObject(true);
1086 // this is in order to prevent failing with 403 earlier
1087 Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
1088 when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
1090 String tag1 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjQ";
1091 String tag2 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjW";
1092 String tag3 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjE";
1093 String tag4 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjb";
1094 String tag5 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjr";
1095 String tag6 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjf";
1096 String tag7 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjg";
1097 String tag8 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjd";
1098 String tag9 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjf";
1099 String tag10 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjg";
1100 String tag11 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjh";
1101 String tag12 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjj";
1102 String tag13 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjk";
1103 String tag14 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjs";
1104 String tag15 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjz";
1105 String tag16 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjx";
1106 String tag17 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBj2";
1107 String tag18 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBj3";
1108 String tag19 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBj4";
1109 String tag20 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBj5";
1110 String tag21 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBj0";
1112 List<String> tagsList = new ArrayList<>();
1122 tagsList.add(tag10);
1123 tagsList.add(tag11);
1124 tagsList.add(tag12);
1125 tagsList.add(tag13);
1126 tagsList.add(tag14);
1127 tagsList.add(tag15);
1128 tagsList.add(tag16);
1129 tagsList.add(tag17);
1130 tagsList.add(tag18);
1131 tagsList.add(tag19);
1132 tagsList.add(tag20);
1133 tagsList.add(tag21);
1134 tagsList.add(resource.getName());
1136 updatedResource.setTags(tagsList);
1137 Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
1138 when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
1140 bl.updateResourceMetadata(resource.getUniqueId(), updatedResource, null, user, false);
1141 } catch (ComponentException e) {
1142 assertComponentException(e, ActionStatus.COMPONENT_TAGS_EXCEED_LIMIT, "" + ValidationUtils.TAG_LIST_MAX_LENGTH);
1147 public void testVendorNameWrongFormat_UPDATE() {
1148 Resource resource = createResourceObject(true);
1149 Resource updatedResource = createResourceObject(true);
1151 // this is in order to prevent failing with 403 earlier
1152 Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
1153 when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
1156 String nameWrongFormat = "ljg*fd";
1157 updatedResource.setVendorName(nameWrongFormat);
1158 Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
1159 when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
1161 bl.updateResourceMetadata(resource.getUniqueId(), updatedResource, null, user, false);
1162 } catch (ComponentException e) {
1163 assertComponentException(e, ActionStatus.INVALID_VENDOR_NAME);
1168 public void testVendorNameWrongFormat() {
1169 Resource resource = createResourceObject(true);
1170 Resource updatedResource = createResourceObject(true);
1172 // this is in order to prevent failing with 403 earlier
1173 Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
1174 when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
1177 String nameWrongFormat = "ljg*fd";
1178 updatedResource.setVendorName(nameWrongFormat);
1179 resource.setVersion("1.0");
1181 Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
1182 when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
1184 bl.updateResourceMetadata(resource.getUniqueId(), updatedResource, null, user, false);
1185 } catch (ComponentException e) {
1186 assertComponentException(e, ActionStatus.INVALID_VENDOR_NAME);
1191 public void testVendorReleaseExceedsLimit_UPDATE() {
1192 Resource resource = createResourceObject(true);
1193 Resource updatedResource = createResourceObject(true);
1195 // this is in order to prevent failing with 403 earlier
1196 Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
1197 when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
1198 // 129 chars, the limit is 128
1199 String tooLongVendorRelease = "h1KSyJh9EspI8SPwAGu4VETfqWejeanuB1PCJBxJmJncYnrW0lnsEFFVRIukRJkwlOVnZCy8p38tjhANeZq3BGMHIawWR6ICl8Wi9mikRYALWgvJug00JrlQ0iPVKPLxy";
1200 updatedResource.setVendorRelease(tooLongVendorRelease);
1201 Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
1202 when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
1204 bl.updateResourceMetadata(resource.getUniqueId(), updatedResource, null, user, false);
1205 } catch (ComponentException e) {
1206 assertComponentException(e, ActionStatus.VENDOR_RELEASE_EXCEEDS_LIMIT, "" + ValidationUtils.VENDOR_RELEASE_MAX_LENGTH);
1211 public void testResourceBadCategory_UPDATE() {
1212 Resource resource = createResourceObject(true);
1213 Resource updatedResource = createResourceObject(true);
1215 // this is in order to prevent failing with 403 earlier
1216 Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
1217 when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
1219 String resourceId = resource.getUniqueId();
1220 String badCategory = "ddfds";
1221 updatedResource.setCategories(null);
1222 updatedResource.addCategory(badCategory, "fikt");
1223 Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
1224 when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
1226 bl.updateResourceMetadata(resourceId, updatedResource, null, user, false);
1227 } catch (ComponentException e) {
1228 assertComponentException(e, ActionStatus.COMPONENT_INVALID_CATEGORY, ComponentTypeEnum.RESOURCE.getValue());
1233 public void testResourceCategoryAfterCertify_UPDATE() {
1234 Resource resource = createResourceObject(true);
1235 Resource updatedResource = createResourceObject(true);
1237 // this is in order to prevent failing with 403 earlier
1238 Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
1239 when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
1241 String resourceId = resource.getUniqueId();
1242 updatedResource.setCategories(null);
1243 updatedResource.addCategory(RESOURCE_CATEGORY1, UPDATED_SUBCATEGORY);
1244 resource.setVersion("1.0");
1246 Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
1247 when(toscaOperationFacade.updateToscaElement(updatedResource)).thenReturn(dataModelResponse);
1249 bl.updateResourceMetadata(resourceId, updatedResource, null, user, false);
1250 } catch (ComponentException e) {
1251 assertComponentException(e, ActionStatus.RESOURCE_CATEGORY_CANNOT_BE_CHANGED);
1255 // Derived from start
1257 public void testResourceTemplateNotExist_UPDATE() {
1258 Resource resource = createResourceObject(true);
1259 Resource updatedResource = createResourceObject(true);
1261 // this is in order to prevent failing with 403 earlier
1262 Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
1263 when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
1264 String resourceId = resource.getUniqueId();
1266 List<String> list = null;
1267 updatedResource.setDerivedFrom(list);
1268 Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
1269 when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
1271 bl.updateResourceMetadata(resourceId, updatedResource, null, user, false);
1272 } catch (ComponentException e) {
1273 assertComponentException(e, ActionStatus.MISSING_DERIVED_FROM_TEMPLATE);
1278 public void testResourceTemplateEmpty_UPDATE() {
1279 Resource resource = createResourceObject(true);
1280 Resource updatedResource = createResourceObject(true);
1281 String resourceId = resource.getUniqueId();
1283 // this is in order to prevent failing with 403 earlier
1284 Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
1285 when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
1287 updatedResource.setDerivedFrom(new ArrayList<>());
1288 Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
1289 when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
1291 bl.updateResourceMetadata(resourceId, updatedResource, null, user, false);
1292 } catch (ComponentException e) {
1293 assertComponentException(e, ActionStatus.MISSING_DERIVED_FROM_TEMPLATE);
1298 public void testResourceTemplateInvalid_UPDATE() {
1299 Resource resource = createResourceObject(true);
1300 Resource updatedResource = createResourceObject(true);
1301 String resourceId = resource.getUniqueId();
1303 // this is in order to prevent failing with 403 earlier
1304 Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
1305 when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
1307 ArrayList<String> derivedFrom = new ArrayList<>();
1308 derivedFrom.add("kuku");
1309 updatedResource.setDerivedFrom(derivedFrom);
1310 Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
1311 when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
1313 bl.updateResourceMetadata(resourceId, updatedResource, null, user, false);
1314 } catch (ComponentException e) {
1315 assertComponentException(e, ActionStatus.PARENT_RESOURCE_NOT_FOUND);
1320 public void testResourceTemplateCertify_UPDATE_HAPPY() {
1321 Resource resource = createResourceObject(true);
1322 Resource updatedResource = createResourceObject(true);
1323 String resourceId = resource.getUniqueId();
1325 // this is in order to prevent failing with 403 earlier
1326 Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
1327 when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
1329 Either<Boolean, StorageOperationStatus> isToscaNameExtending = Either.left(true);
1330 when(toscaOperationFacade.validateToscaResourceNameExtends(Mockito.anyString(), Mockito.anyString())).thenReturn(isToscaNameExtending);
1332 Either<Map<String, PropertyDefinition>, StorageOperationStatus> findPropertiesOfNode = Either.left(new HashMap<>());
1333 when(propertyOperation.deleteAllPropertiesAssociatedToNode(any(NodeTypeEnum.class), Mockito.anyString())).thenReturn(findPropertiesOfNode);
1335 resource.setVersion("1.0");
1337 ArrayList<String> derivedFrom = new ArrayList<>();
1338 derivedFrom.add("tosca.nodes.Root");
1339 updatedResource.setDerivedFrom(derivedFrom);
1340 Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(updatedResource);
1341 when(toscaOperationFacade.updateToscaElement(updatedResource)).thenReturn(dataModelResponse);
1342 Resource createdResource = bl.updateResourceMetadata(resourceId, updatedResource, null, user, false);
1343 assertThat(createdResource).isNotNull();
1347 public void testResourceTemplateCertify_UPDATE_SAD() {
1348 Resource resource = createResourceObject(true);
1349 Resource updatedResource = createResourceObject(true);
1350 String resourceId = resource.getUniqueId();
1352 // this is in order to prevent failing with 403 earlier
1353 Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
1354 when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
1356 Either<Boolean, StorageOperationStatus> isToscaNameExtending = Either.left(false);
1357 when(toscaOperationFacade.validateToscaResourceNameExtends(Mockito.anyString(), Mockito.anyString()))
1358 .thenReturn(isToscaNameExtending);
1360 resource.setVersion("1.0");
1362 ArrayList<String> derivedFrom = new ArrayList<>();
1363 derivedFrom.add("tosca.nodes.Root");
1364 updatedResource.setDerivedFrom(derivedFrom);
1365 Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
1366 when(toscaOperationFacade.updateToscaElement(updatedResource)).thenReturn(dataModelResponse);
1367 Either<Map<String, PropertyDefinition>, StorageOperationStatus> findPropertiesOfNode = Either.left(new HashMap<>());
1368 when(propertyOperation.deleteAllPropertiesAssociatedToNode(any(NodeTypeEnum.class), Mockito.anyString())).thenReturn(findPropertiesOfNode);
1371 bl.updateResourceMetadata(resourceId, updatedResource, null, user, false);
1372 } catch (ComponentException e) {
1373 assertComponentException(e, ActionStatus.PARENT_RESOURCE_DOES_NOT_EXTEND);
1376 // Derived from stop
1379 public void createOrUpdateResourceAlreadyCheckout() {
1380 Resource resourceExist = createResourceObject(false);
1381 validateUserRoles(Role.ADMIN, Role.DESIGNER);
1382 Resource createdResource = bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
1383 createdResource.setLastUpdaterUserId(user.getUserId());
1384 assertThat(createdResource).isNotNull();
1385 Either<Resource, StorageOperationStatus> getLatestResult = Either.left(createdResource);
1386 Either<Component, StorageOperationStatus> getCompLatestResult = Either.left(createdResource);
1387 when(toscaOperationFacade.getLatestByToscaResourceName(resourceExist.getToscaResourceName())).thenReturn(getCompLatestResult);
1388 when(toscaOperationFacade.overrideComponent(any(Resource.class), any(Resource.class))).thenReturn(getLatestResult);
1390 Resource resourceToUpdtae = createResourceObject(false);
1392 ImmutablePair<Resource, ActionStatus> createOrUpdateResource = bl.createOrUpdateResourceByImport(resourceToUpdtae, user, false, false, false, null, null, false);
1393 assertNotNull(createOrUpdateResource);
1395 Mockito.verify(toscaOperationFacade, Mockito.times(1)).overrideComponent(any(Resource.class), any(Resource.class));
1396 Mockito.verify(lifecycleBl, Mockito.times(0)).changeState(Mockito.anyString(), eq(user), eq(LifeCycleTransitionEnum.CHECKOUT), any(LifecycleChangeInfoWithAction.class), Mockito.anyBoolean(), Mockito.anyBoolean());
1401 public void createOrUpdateResourceCertified() {
1402 Resource resourceExist = createResourceObject(false);
1403 validateUserRoles(Role.ADMIN, Role.DESIGNER);
1404 Resource createdResource = bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
1406 assertThat(createdResource).isNotNull();
1407 createdResource.setLifecycleState(LifecycleStateEnum.CERTIFIED);
1408 createdResource.setVersion("1.0");
1410 Either<Resource, StorageOperationStatus> getLatestResult = Either.left(createdResource);
1411 Either<Component, StorageOperationStatus> getCompLatestResult = Either.left(createdResource);
1412 when(toscaOperationFacade.getLatestByToscaResourceName(resourceExist.getToscaResourceName())).thenReturn(getCompLatestResult); when(toscaOperationFacade.overrideComponent(any(Resource.class), any(Resource.class))).thenReturn(getLatestResult);
1414 when(lifecycleBl.changeState(Mockito.anyString(), eq(user), eq(LifeCycleTransitionEnum.CHECKOUT), any(LifecycleChangeInfoWithAction.class), Mockito.anyBoolean(), Mockito.anyBoolean())).thenReturn(Either.left(createdResource));
1416 Resource resourceToUpdtae = createResourceObject(false);
1418 ImmutablePair<Resource, ActionStatus> createOrUpdateResource = bl.createOrUpdateResourceByImport(resourceToUpdtae, user, false, false, false, null, null, false);
1419 assertNotNull(createOrUpdateResource);
1421 Mockito.verify(toscaOperationFacade, Mockito.times(1)).overrideComponent(any(Resource.class), any(Resource.class));
1422 Mockito.verify(lifecycleBl, Mockito.times(1)).changeState(Mockito.anyString(), eq(user), eq(LifeCycleTransitionEnum.CHECKOUT), any(LifecycleChangeInfoWithAction.class), Mockito.anyBoolean(), Mockito.anyBoolean());
1427 public void createOrUpdateResourceNotExist() {
1428 Resource resourceToUpdtae = createResourceObject(false);
1430 Either<Component, StorageOperationStatus> getLatestResult = Either.right(StorageOperationStatus.NOT_FOUND);
1431 when(toscaOperationFacade.getLatestByName(resourceToUpdtae.getName())).thenReturn(getLatestResult);
1433 Either<Component, StorageOperationStatus> getLatestToscaNameResult = Either.right(StorageOperationStatus.NOT_FOUND);
1434 when(toscaOperationFacade.getLatestByToscaResourceName(resourceToUpdtae.getToscaResourceName())).thenReturn(getLatestToscaNameResult);
1436 ImmutablePair<Resource, ActionStatus> createOrUpdateResource = bl.createOrUpdateResourceByImport(resourceToUpdtae, user, false, false, false, null, null, false);
1437 assertThat(createOrUpdateResource).isNotNull();
1439 Mockito.verify(toscaOperationFacade, times(1)).createToscaComponent(eq(resourceToUpdtae));
1440 Mockito.verify(toscaOperationFacade, Mockito.times(0)).overrideComponent(any(Resource.class), any(Resource.class));
1441 Mockito.verify(lifecycleBl, Mockito.times(0)).changeState(Mockito.anyString(), eq(user), eq(LifeCycleTransitionEnum.CHECKOUT), any(LifecycleChangeInfoWithAction.class), Mockito.anyBoolean(), Mockito.anyBoolean());
1446 public void updateNestedResource_typeIsNew() throws IOException {
1447 Resource resourceToUpdate = createResourceObject(false);
1448 String nodeName = Constants.USER_DEFINED_RESOURCE_NAMESPACE_PREFIX + "." + "abc";
1449 String jsonContent = ImportUtilsTest.loadFileNameToJsonString("normative-types-new-webServer.yml");
1450 CsarInfo csarInfo = new CsarInfo(user, "abcd1234", new HashMap<>(),
1451 RESOURCE_NAME, "template name", jsonContent, true);
1452 String nestedResourceName = bl.buildNestedToscaResourceName(resourceToUpdate.getResourceType().name(), csarInfo.getVfResourceName(), nodeName).getRight();
1453 when(toscaOperationFacade.getLatestByName(resourceToUpdate.getName())).thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
1454 when(toscaOperationFacade.getLatestByToscaResourceName(resourceToUpdate.getToscaResourceName())).thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
1455 when(toscaOperationFacade.getLatestByToscaResourceName(nestedResourceName)).thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
1457 ImmutablePair<Resource, ActionStatus> createOrUpdateResource = bl.createOrUpdateResourceByImport(resourceToUpdate, user, false, false, false, csarInfo,
1459 assertThat(createOrUpdateResource).isNotNull();
1461 Mockito.verify(toscaOperationFacade, times(1)).createToscaComponent(eq(resourceToUpdate));
1462 Mockito.verify(toscaOperationFacade, times(0)).overrideComponent(any(Resource.class), any(Resource.class));
1463 Mockito.verify(lifecycleBl, times(0)).changeState(Mockito.anyString(), eq(user), eq(LifeCycleTransitionEnum.CHECKOUT), any(LifecycleChangeInfoWithAction.class), Mockito.anyBoolean(), Mockito.anyBoolean());
1467 public void updateNestedResource_typeExists() throws IOException {
1468 Resource resourceToUpdate = createResourceObject(false);
1469 setCanWorkOnResource(resourceResponse);
1470 String nodeName = Constants.USER_DEFINED_RESOURCE_NAMESPACE_PREFIX + "." + "abc";
1471 String jsonContent = ImportUtilsTest.loadFileNameToJsonString("normative-types-new-webServer.yml");
1472 CsarInfo csarInfo = new CsarInfo(user, "abcd1234", new HashMap<>(),
1473 RESOURCE_NAME, "template name", jsonContent, true);
1474 String nestedResourceName = bl.buildNestedToscaResourceName(resourceToUpdate.getResourceType().name(), csarInfo.getVfResourceName(), nodeName).getRight();
1475 when(toscaOperationFacade.getLatestByName(resourceToUpdate.getName())).thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
1476 when(toscaOperationFacade.getLatestByToscaResourceName(resourceToUpdate.getToscaResourceName())).thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
1477 when(toscaOperationFacade.getLatestByToscaResourceName(nestedResourceName)).thenReturn(Either.left(resourceResponse));
1478 when(toscaOperationFacade.overrideComponent(any(Resource.class), any(Resource.class))).thenReturn(Either.left(resourceResponse));
1480 ImmutablePair<Resource, ActionStatus> createOrUpdateResource = bl.createOrUpdateResourceByImport(resourceToUpdate, user, false, false, false, csarInfo,
1482 assertThat(createOrUpdateResource).isNotNull();
1483 Mockito.verify(toscaOperationFacade, times(1)).overrideComponent(any(Resource.class), any(Resource.class));
1484 Mockito.verify(lifecycleBl, times(0)).changeState(Mockito.anyString(), eq(user), eq(LifeCycleTransitionEnum.CHECKOUT), any(LifecycleChangeInfoWithAction.class), Mockito.anyBoolean(), Mockito.anyBoolean());
1488 public void testValidatePropertiesDefaultValues_SuccessfullWithoutProperties() {
1489 Resource basic = createResourceObject(true);
1491 Either<Boolean, ResponseFormat> validatePropertiesDefaultValues = bl.validatePropertiesDefaultValues(basic);
1492 assertTrue(validatePropertiesDefaultValues.isLeft());
1496 public void testValidatePropertiesDefaultValues_SuccessfullWithProperties() {
1497 Resource basic = createResourceObject(true);
1498 PropertyDefinition property = new PropertyDefinition();
1499 property.setName("myProperty");
1500 property.setType(ToscaPropertyType.INTEGER.getType());
1501 property.setDefaultValue("1");
1502 List<PropertyDefinition> properties = new ArrayList<>();
1503 properties.add(property);
1504 basic.setProperties(properties);
1505 when(propertyOperation.isPropertyTypeValid(property)).thenReturn(true);
1506 when(propertyOperation.isPropertyDefaultValueValid(property, emptyDataTypes)).thenReturn(true);
1507 Either<Boolean, ResponseFormat> validatePropertiesDefaultValues = bl.validatePropertiesDefaultValues(basic);
1508 assertTrue(validatePropertiesDefaultValues.isLeft());
1512 public void testValidatePropertiesDefaultValues_FailedWithProperties() {
1513 Resource basic = createResourceObject(true);
1514 PropertyDefinition property = new PropertyDefinition();
1515 property.setName("myProperty");
1516 property.setType(ToscaPropertyType.INTEGER.getType());
1517 property.setDefaultValue("1.5");
1518 List<PropertyDefinition> properties = new ArrayList<>();
1519 properties.add(property);
1520 basic.setProperties(properties);
1522 when(propertyOperation.isPropertyDefaultValueValid(property, emptyDataTypes)).thenReturn(false);
1523 Either<Boolean, ResponseFormat> validatePropertiesDefaultValues = bl.validatePropertiesDefaultValues(basic);
1524 assertTrue(validatePropertiesDefaultValues.isRight());
1528 @SuppressWarnings("unchecked")
1530 public void testFindVfCsarArtifactsToHandle() {
1532 Class<ResourceBusinessLogic> targetClass = ResourceBusinessLogic.class;
1533 String methodName = "findVfCsarArtifactsToHandle";
1534 Resource resource = new Resource();
1535 String deploymentArtifactToUpdateFileName = "deploymentArtifactToUpdate.yaml";
1536 String deploymentArtifactToDeleteFileName = "deploymentArtifactToDelete.yaml";
1537 String deploymentArtifactToCreateFileName = "deploymentArtifactToCreate.yaml";
1539 String artifactInfoToUpdateFileName = "infoArtifactToUpdate.yaml";
1540 String artifactInfoToDeleteFileName = "infoArtifactToDelete.yaml";
1541 String artifactInfoToNotDeleteFileName = "infoArtifactNotToDelete.yaml";
1542 String artifactInfoToCreateFileName = "infoArtifactToCreate.yaml";
1544 byte[] oldPayloadData = "oldPayloadData".getBytes();
1545 byte[] newPayloadData = "newPayloadData".getBytes();
1546 Map<String, ArtifactDefinition> deploymentArtifacts = new HashMap<>();
1548 ArtifactDefinition deploymentArtifactToUpdate = new ArtifactDefinition();
1549 deploymentArtifactToUpdate.setMandatory(false);
1550 deploymentArtifactToUpdate.setArtifactName(deploymentArtifactToUpdateFileName);
1551 deploymentArtifactToUpdate.setArtifactType("SNMP_POLL");
1552 deploymentArtifactToUpdate.setPayload(oldPayloadData);
1553 deploymentArtifactToUpdate.setArtifactChecksum(GeneralUtility.calculateMD5Base64EncodedByByteArray(oldPayloadData));
1555 ArtifactDefinition deploymentArtifactToDelete = new ArtifactDefinition();
1556 deploymentArtifactToDelete.setMandatory(false);
1557 deploymentArtifactToDelete.setArtifactName(deploymentArtifactToDeleteFileName);
1558 deploymentArtifactToDelete.setArtifactType("SNMP_TRAP");
1559 deploymentArtifactToDelete.setPayload(oldPayloadData);
1560 deploymentArtifactToDelete.setArtifactChecksum(GeneralUtility.calculateMD5Base64EncodedByByteArray(oldPayloadData));
1562 ArtifactDefinition deploymentArtifactToIgnore = new ArtifactDefinition();
1564 deploymentArtifacts.put(ValidationUtils.normalizeArtifactLabel(deploymentArtifactToUpdate.getArtifactName()), deploymentArtifactToUpdate);
1565 deploymentArtifacts.put(ValidationUtils.normalizeArtifactLabel(deploymentArtifactToDelete.getArtifactName()), deploymentArtifactToDelete);
1566 deploymentArtifacts.put("ignore", deploymentArtifactToIgnore);
1568 Map<String, ArtifactDefinition> artifacts = new HashMap<>();
1570 ArtifactDefinition artifactToUpdate = new ArtifactDefinition();
1571 artifactToUpdate.setMandatory(false);
1572 artifactToUpdate.setArtifactName(artifactInfoToUpdateFileName);
1573 artifactToUpdate.setArtifactType("SNMP_POLL");
1574 artifactToUpdate.setPayload(oldPayloadData);
1575 artifactToUpdate.setArtifactChecksum(GeneralUtility.calculateMD5Base64EncodedByByteArray(oldPayloadData));
1577 ArtifactDefinition artifactToDelete = new ArtifactDefinition();
1578 artifactToDelete.setMandatory(false);
1579 artifactToDelete.setArtifactName(artifactInfoToDeleteFileName);
1580 artifactToDelete.setArtifactType("SNMP_TRAP");
1581 artifactToDelete.setPayload(oldPayloadData);
1582 artifactToDelete.setArtifactChecksum(GeneralUtility.calculateMD5Base64EncodedByByteArray(oldPayloadData));
1583 artifactToDelete.setIsFromCsar(true);
1585 ArtifactDefinition artifactToNotDelete = new ArtifactDefinition();
1586 artifactToNotDelete.setMandatory(false);
1587 artifactToNotDelete.setArtifactName(artifactInfoToNotDeleteFileName);
1588 artifactToNotDelete.setArtifactType("SNMP_TRAP");
1589 artifactToNotDelete.setPayload(oldPayloadData);
1590 artifactToNotDelete.setArtifactChecksum(GeneralUtility.calculateMD5Base64EncodedByByteArray(oldPayloadData));
1591 artifactToNotDelete.setIsFromCsar(false);
1593 ArtifactDefinition artifactToIgnore = new ArtifactDefinition();
1595 artifacts.put(ValidationUtils.normalizeArtifactLabel(artifactToUpdate.getArtifactName()), artifactToUpdate);
1596 artifacts.put(ValidationUtils.normalizeArtifactLabel(artifactToDelete.getArtifactName()), artifactToDelete);
1597 artifacts.put(ValidationUtils.normalizeArtifactLabel(artifactToNotDelete.getArtifactName()), artifactToNotDelete);
1598 artifacts.put("ignore", artifactToIgnore);
1600 resource.setDeploymentArtifacts(deploymentArtifacts);
1601 resource.setArtifacts(artifacts);
1603 List<NonMetaArtifactInfo> artifactPathAndNameList = new ArrayList<>();
1604 NonMetaArtifactInfo deploymentArtifactInfoToUpdate = new NonMetaArtifactInfo(deploymentArtifactToUpdate.getArtifactName(), null,
1605 ArtifactTypeEnum.findType(deploymentArtifactToUpdate.getArtifactType()), ArtifactGroupTypeEnum.DEPLOYMENT,
1606 newPayloadData, deploymentArtifactToUpdate.getArtifactName(), false);
1608 NonMetaArtifactInfo informationalArtifactInfoToUpdate = new NonMetaArtifactInfo(artifactToUpdate.getArtifactName(), null,
1609 ArtifactTypeEnum.findType(artifactToUpdate.getArtifactType()), ArtifactGroupTypeEnum.DEPLOYMENT,
1610 newPayloadData, artifactToUpdate.getArtifactName(), false);
1612 NonMetaArtifactInfo informationalArtifactInfoToUpdateFromCsar = new NonMetaArtifactInfo(artifactToUpdate.getArtifactName(), null,
1613 ArtifactTypeEnum.findType(artifactToUpdate.getArtifactType()), ArtifactGroupTypeEnum.INFORMATIONAL,
1614 newPayloadData, artifactToUpdate.getArtifactName(), true);
1616 NonMetaArtifactInfo deploymentArtifactInfoToUpdateFromCsar = new NonMetaArtifactInfo(artifactToUpdate.getArtifactName(), null,
1617 ArtifactTypeEnum.findType(artifactToUpdate.getArtifactType()), ArtifactGroupTypeEnum.DEPLOYMENT,
1618 newPayloadData, artifactToUpdate.getArtifactName(), true);
1620 NonMetaArtifactInfo deploymentArtifactInfoToCreate = new NonMetaArtifactInfo(deploymentArtifactToCreateFileName, null,
1621 ArtifactTypeEnum.OTHER, ArtifactGroupTypeEnum.DEPLOYMENT, newPayloadData, deploymentArtifactToCreateFileName, false);
1623 NonMetaArtifactInfo informationalArtifactInfoToCreate = new NonMetaArtifactInfo(artifactInfoToCreateFileName, null,
1624 ArtifactTypeEnum.OTHER, ArtifactGroupTypeEnum.INFORMATIONAL,
1625 newPayloadData, artifactInfoToCreateFileName, false);
1627 artifactPathAndNameList.add(deploymentArtifactInfoToUpdate);
1628 artifactPathAndNameList.add(informationalArtifactInfoToUpdate);
1629 artifactPathAndNameList.add(deploymentArtifactInfoToCreate);
1630 artifactPathAndNameList.add(informationalArtifactInfoToCreate);
1631 artifactPathAndNameList.add(informationalArtifactInfoToUpdateFromCsar);
1632 artifactPathAndNameList.add(deploymentArtifactInfoToUpdateFromCsar);
1634 Object[] argObjects = {resource, artifactPathAndNameList, user};
1635 Class[] argClasses = {Resource.class, List.class, User.class};
1637 Method method = targetClass.getDeclaredMethod(methodName, argClasses);
1638 method.setAccessible(true);
1639 Either<EnumMap<ArtifactOperationEnum, List<NonMetaArtifactInfo>>, ResponseFormat> findVfCsarArtifactsToHandleRes =
1640 (Either<EnumMap<ArtifactOperationEnum, List<NonMetaArtifactInfo>>, ResponseFormat>) method.invoke(bl, argObjects);
1641 assertTrue(findVfCsarArtifactsToHandleRes.isLeft());
1642 EnumMap<ArtifactOperationEnum, List<NonMetaArtifactInfo>> foundVfArtifacts = findVfCsarArtifactsToHandleRes.left().value();
1643 assertEquals(4, foundVfArtifacts.get(ArtifactOperationEnum.CREATE).size());
1644 assertEquals(4, foundVfArtifacts.get(ArtifactOperationEnum.UPDATE).size());
1645 assertEquals(1, foundVfArtifacts.get(ArtifactOperationEnum.DELETE).size());
1647 } catch (Exception e) {
1648 e.printStackTrace();
1653 public void testVFGeneratedInputs() {
1654 validateUserRoles(Role.ADMIN, Role.DESIGNER);
1655 Resource resource = createVF();
1656 List<InputDefinition> inputs = resource.getInputs();
1657 assertEquals(6, inputs.size());
1658 for (InputDefinition input : inputs) {
1659 assertThat(input.getOwnerId()).isNotNull();
1661 assertEquals(resource.getDerivedFromGenericType(), genericVF.getToscaResourceName());
1662 assertEquals(resource.getDerivedFromGenericVersion(), genericVF.getVersion());
1666 public void testCRGeneratedInputs() {
1667 validateUserRoles(Role.ADMIN, Role.DESIGNER);
1668 Resource resource = createCR();
1669 List<InputDefinition> inputs = resource.getInputs();
1670 assertEquals(3, inputs.size());
1671 for (InputDefinition input : inputs) {
1672 assertThat(input.getOwnerId()).isNotNull();
1674 assertEquals(resource.getDerivedFromGenericType(), genericCR.getToscaResourceName());
1675 assertEquals(resource.getDerivedFromGenericVersion(), genericCR.getVersion());
1679 public void testVFUpdateGenericInputsToLatestOnCheckout() {
1680 validateUserRoles(Role.ADMIN, Role.DESIGNER);
1681 //create a VF that is derived from generic version 1.0
1682 Resource resource = createVF();
1683 // create a new generic version without properties
1684 genericVF.setVersion("2.0");
1685 genericVF.setProperties(null);
1686 String currentDerivedFromVersion = resource.getDerivedFromGenericVersion();
1687 List<InputDefinition> currentInputs = resource.getInputs();
1688 //verify previous inputs ownerId fields exist - user may not delete generated inputs
1689 assertEquals(6, currentInputs.stream().filter(p -> null != p.getOwnerId()).collect(Collectors.toList()).size());
1690 Either<Boolean, ResponseFormat> upgradeToLatestGeneric = bl.shouldUpgradeToLatestGeneric(resource);
1692 assertTrue(upgradeToLatestGeneric.isLeft());
1693 //verify update required and valid
1694 assertTrue(upgradeToLatestGeneric.left().value());
1695 //verify version was upgraded
1696 assertNotEquals(resource.getDerivedFromGenericVersion(), currentDerivedFromVersion);
1697 //verify inputs were not deleted
1698 assertEquals(6, resource.getInputs().size());
1699 //verify inputs ownerId fields were removed - user may delete/edit inputs
1700 assertEquals(6, resource.getInputs()
1702 .filter(p -> null == p.getOwnerId())
1703 .collect(Collectors.toList())
1709 public void testVFUpdateGenericInputsToLatestOnCheckoutNotPerformed() {
1711 //create a VF that is derived from generic version 1.0
1712 validateUserRoles(Role.ADMIN, Role.DESIGNER);
1713 Resource resource = createVF();
1715 //add an input to the VF
1716 PropertyDefinition newProp = new PropertyDefinition();
1717 newProp.setType("integer");
1718 newProp.setName("newProp");
1719 resource.getInputs().add(new InputDefinition(newProp));
1721 //create a new generic version with a new property which has the same name as a user defined input on the VF with a different type
1722 genericVF.setVersion("2.0");
1723 newProp.setType("string");
1724 genericVF.setProperties(new ArrayList<>());
1725 genericVF.getProperties().add(newProp);
1726 when(genericTypeBusinessLogic.fetchDerivedFromGenericType(resource)).thenReturn(Either.left(genericVF));
1727 when(genericTypeBusinessLogic.convertGenericTypePropertiesToInputsDefintion(genericVF.getProperties(), genericVF.getUniqueId())).thenCallRealMethod();
1728 String currentDerivedFromVersion = resource.getDerivedFromGenericVersion();
1729 assertEquals(6, resource.getInputs()
1731 .filter(p -> null != p.getOwnerId())
1732 .collect(Collectors.toList())
1734 Either<Boolean, ResponseFormat> upgradeToLatestGeneric = bl.shouldUpgradeToLatestGeneric(resource);
1736 assertTrue(upgradeToLatestGeneric.isLeft());
1737 //verify update is invalid an void
1738 assertFalse(upgradeToLatestGeneric.left().value());
1739 //verify version was not upgraded
1740 assertEquals(resource.getDerivedFromGenericVersion(), currentDerivedFromVersion);
1741 //verify inputs were not removed
1742 assertEquals(7, resource.getInputs().size());
1743 //verify user defined input exists
1744 assertEquals(1, resource.getInputs()
1746 .filter(p -> null == p.getOwnerId())
1747 .collect(Collectors.toList())
1749 assertEquals("integer", resource.getInputs()
1751 .filter(p -> null == p.getOwnerId())
1758 public void testPNFGeneratedInputsNoGeneratedInformationalArtifacts() {
1759 validateUserRoles(Role.ADMIN, Role.DESIGNER);
1760 Resource resource = createPNF();
1761 List<InputDefinition> inputs = resource.getInputs();
1762 assertEquals(3, inputs.size());
1763 for (InputDefinition input : inputs) {
1764 assertThat(input.getOwnerId()).isNotNull();
1766 assertEquals(resource.getDerivedFromGenericType(), genericPNF.getToscaResourceName());
1767 assertEquals(resource.getDerivedFromGenericVersion(), genericPNF.getVersion());
1768 assertEquals(0, resource.getArtifacts().size());
1772 private Resource createVF() {
1774 genericVF = setupGenericTypeMock(GENERIC_VF_NAME);
1775 when(toscaOperationFacade.getLatestCertifiedNodeTypeByToscaResourceName(GENERIC_VF_NAME)).thenReturn(Either.left(genericVF));
1776 Resource resource = createResourceObject(true);
1777 resource.setDerivedFrom(null);
1778 resource.setResourceType(ResourceTypeEnum.VF);
1779 when(toscaOperationFacade.createToscaComponent(resource)).thenReturn(Either.left(resource));
1780 when(genericTypeBusinessLogic.fetchDerivedFromGenericType(resource)).thenReturn(Either.left(genericVF));
1781 when(genericTypeBusinessLogic.generateInputsFromGenericTypeProperties(genericVF)).thenCallRealMethod();
1782 when(genericTypeBusinessLogic.convertGenericTypePropertiesToInputsDefintion(genericVF.getProperties(), resource.getUniqueId())).thenCallRealMethod();
1783 Resource createdResource = bl.createResource(resource, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
1784 assertThat(createdResource).isNotNull();
1785 return createdResource;
1789 private Resource createCR() {
1791 genericCR = setupGenericTypeMock(GENERIC_CR_NAME);
1792 when(toscaOperationFacade.getLatestCertifiedNodeTypeByToscaResourceName(GENERIC_CR_NAME)).thenReturn(Either.left(genericCR));
1793 Resource resource = createResourceObject(true);
1794 resource.setDerivedFrom(null);
1795 resource.setResourceType(ResourceTypeEnum.CR);
1796 when(toscaOperationFacade.createToscaComponent(resource)).thenReturn(Either.left(resource));
1797 when(genericTypeBusinessLogic.fetchDerivedFromGenericType(resource)).thenReturn(Either.left(genericCR));
1798 when(genericTypeBusinessLogic.generateInputsFromGenericTypeProperties(genericCR)).thenCallRealMethod();
1799 when(genericTypeBusinessLogic.convertGenericTypePropertiesToInputsDefintion(genericCR.getProperties(), resource.getUniqueId())).thenCallRealMethod();
1800 Resource createdResource = bl.createResource(resource, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
1801 assertThat(createdResource).isNotNull();
1802 return createdResource;
1805 private Resource createPNF() {
1807 genericPNF = setupGenericTypeMock(GENERIC_PNF_NAME);
1808 when(toscaOperationFacade.getLatestCertifiedNodeTypeByToscaResourceName(GENERIC_PNF_NAME)).thenReturn(Either.left(genericPNF));
1809 Resource resource = createResourceObject(true);
1810 resource.setDerivedFrom(null);
1811 resource.setResourceType(ResourceTypeEnum.PNF);
1812 when(toscaOperationFacade.createToscaComponent(resource)).thenReturn(Either.left(resource));
1813 when(genericTypeBusinessLogic.fetchDerivedFromGenericType(resource)).thenReturn(Either.left(genericPNF));
1814 when(genericTypeBusinessLogic.generateInputsFromGenericTypeProperties(genericPNF)).thenCallRealMethod();
1815 when(genericTypeBusinessLogic.convertGenericTypePropertiesToInputsDefintion(genericPNF.getProperties(), resource.getUniqueId())).thenCallRealMethod();
1816 Resource createdResource = bl.createResource(resource, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
1817 assertThat(createdResource).isNotNull();
1818 return createdResource;
1822 private Map<String, String> getGenericPropertiesByToscaName(String toscaName) {
1823 HashMap<String, String> PNFProps = new HashMap<String, String>() {{
1824 put("nf_function", "string");
1825 put("nf_role", "string");
1826 put("nf_type", "string");
1829 HashMap<String, String> CRProps = new HashMap<String, String>() {{
1830 put("cr_function", "string");
1831 put("cr_role", "string");
1832 put("cr_type", "string");
1835 HashMap<String, String> VFProps = new HashMap<String, String>() {{
1837 put("availability_zone_max_count", "integer");
1838 put("min_instances", "integer");
1839 put("max_instances", "integer");
1842 if (toscaName.contains("PNF")) return PNFProps;
1843 if (toscaName.contains("CR")) return CRProps;
1844 if (toscaName.contains("VF")) return VFProps;
1846 return new HashMap<>();
1850 private Resource setupGenericTypeMock(String toscaName) {
1852 Resource genericType = createResourceObject(true);
1853 genericType.setVersion("1.0");
1854 genericType.setToscaResourceName(toscaName);
1855 List<PropertyDefinition> genericProps = new ArrayList<>();
1856 Map<String, String> genericPropsMap = getGenericPropertiesByToscaName(toscaName);
1857 genericPropsMap.forEach((name, type) -> {
1858 PropertyDefinition prop = new PropertyDefinition();
1861 genericProps.add(prop);
1864 genericType.setProperties(genericProps);
1868 private void validateUserRoles(Role... roles) {
1869 List<Role> listOfRoles = Stream.of(roles).collect(Collectors.toList());
1874 public void testgetAllCertifiedResources() throws Exception {
1875 List<Resource> list = bl.getAllCertifiedResources(true, HighestFilterEnum.HIGHEST_ONLY, "USER");
1876 Assert.assertEquals(reslist,list);
1879 @Test(expected = StorageException.class)
1880 public void testgetAllCertifiedResources_exception() throws Exception {
1881 List<Resource> list = bl.getAllCertifiedResources(false, HighestFilterEnum.NON_HIGHEST_ONLY, "USER");
1882 Assert.assertEquals(reslist,list);
1886 public void testvalidateResourceNameExists() throws Exception {
1887 Either<Map<String, Boolean>, ResponseFormat> res = bl.validateResourceNameExists("Resource", ResourceTypeEnum.CR, "jh0003");
1888 Assert.assertEquals(true,res.isLeft());