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 static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertFalse;
25 import static org.junit.Assert.assertNotNull;
26 import static org.junit.Assert.assertTrue;
27 import static org.mockito.Mockito.when;
29 import java.lang.reflect.Method;
30 import java.util.ArrayList;
31 import java.util.EnumMap;
32 import java.util.HashMap;
33 import java.util.List;
36 import java.util.regex.Pattern;
37 import java.util.stream.Collectors;
39 import javax.servlet.ServletContext;
41 import org.apache.commons.lang3.tuple.ImmutablePair;
42 import org.junit.Assert;
43 import org.junit.Before;
44 import org.junit.Ignore;
45 import org.junit.Test;
46 import org.mockito.InjectMocks;
47 import org.mockito.Mockito;
48 import org.mockito.MockitoAnnotations;
49 import org.openecomp.sdc.ElementOperationMock;
50 import org.openecomp.sdc.be.auditing.api.IAuditingManager;
51 import org.openecomp.sdc.be.auditing.impl.AuditingLogFormatUtil;
52 import org.openecomp.sdc.be.auditing.impl.AuditingManager;
53 import org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic.ArtifactOperationEnum;
54 import org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic.ArtifactOperationInfo;
55 import org.openecomp.sdc.be.components.lifecycle.LifecycleBusinessLogic;
56 import org.openecomp.sdc.be.components.lifecycle.LifecycleChangeInfoWithAction;
57 import org.openecomp.sdc.be.config.ConfigurationManager;
58 import org.openecomp.sdc.be.dao.api.ActionStatus;
59 import org.openecomp.sdc.be.dao.jsongraph.TitanDao;
60 import org.openecomp.sdc.be.datamodel.api.HighestFilterEnum;
61 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
62 import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
63 import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
64 import org.openecomp.sdc.be.impl.ComponentsUtils;
65 import org.openecomp.sdc.be.impl.WebAppContextWrapper;
66 import org.openecomp.sdc.be.info.ArtifactTemplateInfo;
67 import org.openecomp.sdc.be.info.MergedArtifactInfo;
68 import org.openecomp.sdc.be.model.ArtifactDefinition;
69 import org.openecomp.sdc.be.model.CapabilityDefinition;
70 import org.openecomp.sdc.be.model.Component;
71 import org.openecomp.sdc.be.model.ComponentInstance;
72 import org.openecomp.sdc.be.model.ComponentInstanceInput;
73 import org.openecomp.sdc.be.model.ComponentInstanceProperty;
74 import org.openecomp.sdc.be.model.CsarInfo;
75 import org.openecomp.sdc.be.model.DataTypeDefinition;
76 import org.openecomp.sdc.be.model.GroupDefinition;
77 import org.openecomp.sdc.be.model.GroupProperty;
78 import org.openecomp.sdc.be.model.GroupTypeDefinition;
79 import org.openecomp.sdc.be.model.HeatParameterDefinition;
80 import org.openecomp.sdc.be.model.InputDefinition;
81 import org.openecomp.sdc.be.model.LifeCycleTransitionEnum;
82 import org.openecomp.sdc.be.model.LifecycleStateEnum;
83 import org.openecomp.sdc.be.model.NodeTypeInfo;
84 import org.openecomp.sdc.be.model.ParsedToscaYamlInfo;
85 import org.openecomp.sdc.be.model.PropertyDefinition;
86 import org.openecomp.sdc.be.model.RequirementCapabilityRelDef;
87 import org.openecomp.sdc.be.model.RequirementDefinition;
88 import org.openecomp.sdc.be.model.Resource;
89 import org.openecomp.sdc.be.model.UploadCapInfo;
90 import org.openecomp.sdc.be.model.UploadComponentInstanceInfo;
91 import org.openecomp.sdc.be.model.UploadPropInfo;
92 import org.openecomp.sdc.be.model.UploadReqInfo;
93 import org.openecomp.sdc.be.model.UploadResourceInfo;
94 import org.openecomp.sdc.be.model.User;
95 import org.openecomp.sdc.be.model.cache.ApplicationDataTypeCache;
96 import org.openecomp.sdc.be.model.category.CategoryDefinition;
97 import org.openecomp.sdc.be.model.category.SubCategoryDefinition;
98 import org.openecomp.sdc.be.model.jsontitan.operations.NodeTemplateOperation;
99 import org.openecomp.sdc.be.model.jsontitan.operations.NodeTypeOperation;
100 import org.openecomp.sdc.be.model.jsontitan.operations.TopologyTemplateOperation;
101 import org.openecomp.sdc.be.model.jsontitan.operations.ToscaOperationFacade;
102 import org.openecomp.sdc.be.model.operations.api.ICacheMangerOperation;
103 import org.openecomp.sdc.be.model.operations.api.ICapabilityTypeOperation;
104 import org.openecomp.sdc.be.model.operations.api.IElementOperation;
105 import org.openecomp.sdc.be.model.operations.api.IPropertyOperation;
106 import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
107 import org.openecomp.sdc.be.model.operations.impl.CacheMangerOperation;
108 import org.openecomp.sdc.be.model.operations.impl.CsarOperation;
109 import org.openecomp.sdc.be.model.operations.impl.GraphLockOperation;
110 import org.openecomp.sdc.be.model.tosca.ToscaPropertyType;
111 import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
112 import org.openecomp.sdc.be.tosca.CsarUtils.NonMetaArtifactInfo;
113 import org.openecomp.sdc.be.ui.model.UiComponentDataTransfer;
114 import org.openecomp.sdc.be.user.IUserBusinessLogic;
115 import org.openecomp.sdc.be.user.Role;
116 import org.openecomp.sdc.be.user.UserBusinessLogic;
117 import org.openecomp.sdc.common.api.ArtifactGroupTypeEnum;
118 import org.openecomp.sdc.common.api.ArtifactTypeEnum;
119 import org.openecomp.sdc.common.api.ConfigurationSource;
120 import org.openecomp.sdc.common.api.Constants;
121 import org.openecomp.sdc.common.datastructure.AuditingFieldsKeysEnum;
122 import org.openecomp.sdc.common.impl.ExternalConfiguration;
123 import org.openecomp.sdc.common.impl.FSConfigurationSource;
124 import org.openecomp.sdc.common.util.GeneralUtility;
125 import org.openecomp.sdc.common.util.ValidationUtils;
126 import org.openecomp.sdc.exception.ResponseFormat;
127 import org.slf4j.Logger;
128 import org.slf4j.LoggerFactory;
129 import org.springframework.web.context.WebApplicationContext;
131 import com.att.nsa.cambria.test.support.CambriaBatchingPublisherMock.Entry;
132 import com.google.common.base.Equivalence.Wrapper;
133 import com.netflix.astyanax.connectionpool.Operation;
135 import fj.data.Either;
137 public class ResourceBusinessLogicTest {
139 private static Logger log = LoggerFactory.getLogger(ResourceBusinessLogicTest.class.getName());
140 public static final String RESOURCE_CATEGORY = "Network Layer 2-3/Router";
141 public static final String RESOURCE_CATEGORY1 = "Network Layer 2-3";
142 public static final String RESOURCE_SUBCATEGORY = "Router";
144 public static final String UPDATED_CATEGORY = "Network Layer 2-3/Gateway";
145 public static final String UPDATED_SUBCATEGORY = "Gateway";
147 public static final String RESOURCE_NAME = "My-Resource_Name with space";
148 private static final String GENERIC_VF_NAME = "org.openecomp.resource.abstract.nodes.VF";
149 private static final String GENERIC_VFC_NAME = "org.openecomp.resource.abstract.nodes.VFC";
150 private static final String GENERIC_PNF_NAME = "org.openecomp.resource.abstract.nodes.PNF";
152 final ServletContext servletContext = Mockito.mock(ServletContext.class);
153 IAuditingManager iAuditingManager = null;
154 IElementOperation mockElementDao;
155 TitanDao mockTitanDao = Mockito.mock(TitanDao.class);
156 UserBusinessLogic mockUserAdmin = Mockito.mock(UserBusinessLogic.class);
157 ToscaOperationFacade toscaOperationFacade = Mockito.mock(ToscaOperationFacade.class);
158 NodeTypeOperation nodeTypeOperation = Mockito.mock(NodeTypeOperation.class);
159 NodeTemplateOperation nodeTemplateOperation = Mockito.mock(NodeTemplateOperation.class);
160 TopologyTemplateOperation topologyTemplateOperation = Mockito.mock(TopologyTemplateOperation.class);
161 final LifecycleBusinessLogic lifecycleBl = Mockito.mock(LifecycleBusinessLogic.class);
162 final ICapabilityTypeOperation capabilityTypeOperation = Mockito.mock(ICapabilityTypeOperation.class);
163 final IPropertyOperation propertyOperation = Mockito.mock(IPropertyOperation.class);
164 final ApplicationDataTypeCache applicationDataTypeCache = Mockito.mock(ApplicationDataTypeCache.class);
165 WebAppContextWrapper webAppContextWrapper = Mockito.mock(WebAppContextWrapper.class);
166 WebApplicationContext webAppContext = Mockito.mock(WebApplicationContext.class);
167 AuditingLogFormatUtil auditingLogFormatter = Mockito.mock(AuditingLogFormatUtil.class);
169 ResourceBusinessLogic bl = new ResourceBusinessLogic();
170 ResponseFormatManager responseManager = null;
171 AuditingManager auditingManager = Mockito.mock(AuditingManager.class);
172 GraphLockOperation graphLockOperation = Mockito.mock(GraphLockOperation.class);
174 Resource resourceResponse = null;
175 Resource genericVF = null;
176 Resource genericVFC = null;
177 Resource genericPNF = null;
178 ComponentsUtils componentsUtils = new ComponentsUtils();
179 ArtifactsBusinessLogic artifactManager = new ArtifactsBusinessLogic();
180 CsarOperation csarOperation = Mockito.mock(CsarOperation.class);
181 Map<String, DataTypeDefinition> emptyDataTypes = new HashMap<String, DataTypeDefinition>();
183 CacheMangerOperation cacheManager = Mockito.mock(CacheMangerOperation.class);
185 public ResourceBusinessLogicTest() {
190 public void setup() {
191 MockitoAnnotations.initMocks(this);
192 Mockito.reset(propertyOperation);
194 ExternalConfiguration.setAppName("catalog-be");
196 // Init Configuration
197 String appConfigDir = "src/test/resources/config/catalog-be";
198 ConfigurationSource configurationSource = new FSConfigurationSource(ExternalConfiguration.getChangeListener(),
200 ConfigurationManager configurationManager = new ConfigurationManager(configurationSource);
203 mockElementDao = new ElementOperationMock();
205 // User data and management
207 user.setUserId("jh0003");
208 user.setFirstName("Jimmi");
209 user.setLastName("Hendrix");
210 user.setRole(Role.ADMIN.name());
212 Either<User, ActionStatus> eitherGetUser = Either.left(user);
213 when(mockUserAdmin.getUser("jh0003", false)).thenReturn(eitherGetUser);
215 // Servlet Context attributes
216 when(servletContext.getAttribute(Constants.CONFIGURATION_MANAGER_ATTR)).thenReturn(configurationManager);
217 when(servletContext.getAttribute(Constants.WEB_APPLICATION_CONTEXT_WRAPPER_ATTR))
218 .thenReturn(webAppContextWrapper);
219 when(webAppContextWrapper.getWebAppContext(servletContext)).thenReturn(webAppContext);
220 when(webAppContext.getBean(IElementOperation.class)).thenReturn(mockElementDao);
222 Either<Integer, StorageOperationStatus> eitherCountRoot = Either.left(1);
223 Either<Boolean, StorageOperationStatus> eitherFalse = Either.left(true);
224 when(toscaOperationFacade.validateComponentNameExists("Root", ResourceTypeEnum.VFC, ComponentTypeEnum.RESOURCE))
225 .thenReturn(eitherFalse);
227 Either<Boolean, StorageOperationStatus> eitherCountExist = Either.left(true);
228 when(toscaOperationFacade.validateComponentNameExists("alreadyExists", ResourceTypeEnum.VFC,
229 ComponentTypeEnum.RESOURCE)).thenReturn(eitherCountExist);
231 Either<Boolean, StorageOperationStatus> eitherCount = Either.left(false);
232 when(toscaOperationFacade.validateComponentNameExists(RESOURCE_NAME, ResourceTypeEnum.VFC,
233 ComponentTypeEnum.RESOURCE)).thenReturn(eitherCount);
234 when(toscaOperationFacade.validateComponentNameExists(RESOURCE_NAME, ResourceTypeEnum.VF,
235 ComponentTypeEnum.RESOURCE)).thenReturn(eitherCount);
236 when(toscaOperationFacade.validateComponentNameExists(RESOURCE_NAME, ResourceTypeEnum.PNF,
237 ComponentTypeEnum.RESOURCE)).thenReturn(eitherCount);
239 Either<Boolean, StorageOperationStatus> validateDerivedExists = Either.left(true);
240 when(toscaOperationFacade.validateToscaResourceNameExists("Root")).thenReturn(validateDerivedExists);
242 Either<Boolean, StorageOperationStatus> validateDerivedNotExists = Either.left(false);
243 when(toscaOperationFacade.validateToscaResourceNameExists("kuku")).thenReturn(validateDerivedNotExists);
244 when(graphLockOperation.lockComponent(Mockito.anyString(), Mockito.eq(NodeTypeEnum.Resource)))
245 .thenReturn(StorageOperationStatus.OK);
246 when(graphLockOperation.lockComponentByName(Mockito.anyString(), Mockito.eq(NodeTypeEnum.Resource)))
247 .thenReturn(StorageOperationStatus.OK);
250 resourceResponse = createResourceObject(true);
251 Either<Resource, StorageOperationStatus> eitherCreate = Either.left(resourceResponse);
252 Either<Integer, StorageOperationStatus> eitherValidate = Either.left(null);
253 when(toscaOperationFacade.createToscaComponent(Mockito.any(Resource.class))).thenReturn(eitherCreate);
254 when(toscaOperationFacade.validateCsarUuidUniqueness(Mockito.anyString())).thenReturn(eitherValidate);
255 Map<String, DataTypeDefinition> emptyDataTypes = new HashMap<String, DataTypeDefinition>();
256 when(applicationDataTypeCache.getAll()).thenReturn(Either.left(emptyDataTypes));
259 artifactManager.nodeTemplateOperation = nodeTemplateOperation;
260 bl = new ResourceBusinessLogic();
261 bl.setElementDao(mockElementDao);
262 bl.setUserAdmin(mockUserAdmin);
263 bl.setCapabilityTypeOperation(capabilityTypeOperation);
264 componentsUtils.Init();
265 componentsUtils.setAuditingManager(auditingManager);
266 bl.setComponentsUtils(componentsUtils);
267 bl.setLifecycleManager(lifecycleBl);
268 bl.setGraphLockOperation(graphLockOperation);
269 bl.setArtifactsManager(artifactManager);
270 bl.setPropertyOperation(propertyOperation);
271 bl.setTitanGenericDao(mockTitanDao);
272 bl.setApplicationDataTypeCache(applicationDataTypeCache);
273 bl.setCsarOperation(csarOperation);
274 bl.setCacheManagerOperation(cacheManager);
275 toscaOperationFacade.setNodeTypeOperation(nodeTypeOperation);
276 toscaOperationFacade.setTopologyTemplateOperation(topologyTemplateOperation);
277 bl.setToscaOperationFacade(toscaOperationFacade);
278 Resource resourceCsar = createResourceObjectCsar(true);
279 setCanWorkOnResource(resourceCsar);
280 Either<Component, StorageOperationStatus> oldResourceRes = Either.left(resourceCsar);
281 when(toscaOperationFacade.getToscaElement(resourceCsar.getUniqueId())).thenReturn(oldResourceRes);
282 responseManager = ResponseFormatManager.getInstance();
286 private Resource createResourceObject(boolean afterCreate) {
287 Resource resource = new Resource();
288 resource.setName(RESOURCE_NAME);
289 resource.addCategory(RESOURCE_CATEGORY1, RESOURCE_SUBCATEGORY);
290 resource.setDescription("My short description");
291 List<String> tgs = new ArrayList<String>();
293 tgs.add(resource.getName());
294 resource.setTags(tgs);
295 List<String> template = new ArrayList<String>();
296 template.add("Root");
297 resource.setDerivedFrom(template);
298 resource.setVendorName("Motorola");
299 resource.setVendorRelease("1.0.0");
300 resource.setContactId("ya5467");
301 resource.setIcon("MyIcon");
304 resource.setName(resource.getName());
305 resource.setVersion("0.1");
306 resource.setUniqueId(resource.getName().toLowerCase() + ":" + resource.getVersion());
307 resource.setCreatorUserId(user.getUserId());
308 resource.setCreatorFullName(user.getFirstName() + " " + user.getLastName());
309 resource.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
314 private Resource createResourceObjectCsar(boolean afterCreate) {
315 Resource resource = new Resource();
316 resource.setName(RESOURCE_NAME);
317 resource.addCategory(RESOURCE_CATEGORY1, RESOURCE_SUBCATEGORY);
318 resource.setDescription("My short description");
319 List<String> tgs = new ArrayList<String>();
321 tgs.add(resource.getName());
322 resource.setTags(tgs);
323 List<String> template = new ArrayList<String>();
324 template.add("Root");
325 resource.setDerivedFrom(template);
326 resource.setVendorName("Motorola");
327 resource.setVendorRelease("1.0.0");
328 resource.setResourceVendorModelNumber("");
329 resource.setContactId("ya5467");
330 resource.setIcon("MyIcon");
331 resource.setCsarUUID("valid_vf.csar");
332 resource.setCsarVersion("1");
335 resource.setName(resource.getName());
336 resource.setVersion("0.1");
338 resource.setUniqueId(resource.getName().toLowerCase() + ":" + resource.getVersion());
339 resource.setCreatorUserId(user.getUserId());
340 resource.setCreatorFullName(user.getFirstName() + " " + user.getLastName());
341 resource.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
346 private Resource setCanWorkOnResource(Resource resource) {
347 resource.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
348 resource.setLastUpdaterUserId(user.getUserId());
353 public void testHappyScenario() {
354 Resource resource = createResourceObject(false);
355 Either<Resource, ResponseFormat> createResponse = bl.createResource(resource,
356 AuditingActionEnum.CREATE_RESOURCE, user, null, null);
358 if (createResponse.isRight()) {
359 assertEquals(new Integer(200), createResponse.right().value().getStatus());
361 assertEquals(createResourceObject(true), createResponse.left().value());
365 public void testUpdateHappyScenario() {
366 Resource resource = createResourceObjectCsar(true);
367 setCanWorkOnResource(resource);
369 Either<Resource, StorageOperationStatus> resourceLinkedToCsarRes = Either.left(resource);
370 when(toscaOperationFacade.getLatestComponentByCsarOrName(ComponentTypeEnum.RESOURCE, resource.getCsarUUID(),
371 resource.getSystemName())).thenReturn(resourceLinkedToCsarRes);
372 Either<Boolean, StorageOperationStatus> validateDerivedExists = Either.left(true);
373 when(toscaOperationFacade.validateToscaResourceNameExists("Root")).thenReturn(validateDerivedExists);
375 Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
376 when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
377 Either<Resource, ResponseFormat> updateResponse = bl.validateAndUpdateResourceFromCsar(resource, user, null,
378 null, resource.getUniqueId());
379 if (updateResponse.isRight()) {
380 assertEquals(new Integer(200), updateResponse.right().value().getStatus());
382 assertEquals(resource.getUniqueId(), updateResponse.left().value().getUniqueId());
385 /* CREATE validations - start ***********************/
386 // Resource name - start
389 public void testFailedResourceValidations() {
390 testResourceNameExist();
391 testResourceNameEmpty();
392 // testResourceNameExceedsLimit();
393 testResourceNameWrongFormat();
394 testResourceDescExceedsLimitCreate();
395 testResourceDescNotEnglish();
396 testResourceDescriptionEmpty();
397 testResourceDescriptionMissing();
398 testResourceIconMissing();
399 testResourceIconInvalid();
400 testResourceIconExceedsLimit();
401 testResourceTagNotExist();
402 testResourceTagEmpty();
403 testTagsExceedsLimitCreate();
404 testTagsNoServiceName();
407 testContactIdTooLong();
408 testContactIdWrongFormatCreate();
409 testResourceContactIdEmpty();
410 testResourceContactIdMissing();
411 testVendorNameExceedsLimit();
412 testVendorNameWrongFormatCreate();
413 testVendorReleaseWrongFormat();
414 testVendorReleaseExceedsLimitCreate();
415 testResourceVendorModelNumberExceedsLimit();
416 testResourceVendorNameMissing();
417 testResourceVendorReleaseMissing();
418 testResourceCategoryExist();
419 testResourceBadCategoryCreate();
420 testHappyScenarioCostLicenseType();
421 testCostWrongFormatCreate();
422 testLicenseTypeWrongFormatCreate();
423 testResourceTemplateNotExist();
424 testResourceTemplateEmpty();
425 testResourceTemplateInvalid();
428 private void testResourceNameExist() {
429 String resourceName = "alreadyExists";
430 Resource resourceExist = createResourceObject(false);
431 resourceExist.setName(resourceName);
432 resourceExist.getTags().add(resourceName);
434 Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceExist,
435 AuditingActionEnum.CREATE_RESOURCE, user, null, null);
436 assertResponse(createResponse, ActionStatus.COMPONENT_NAME_ALREADY_EXIST, ComponentTypeEnum.RESOURCE.getValue(),
440 private void testResourceNameEmpty() {
441 Resource resourceExist = createResourceObject(false);
442 resourceExist.setName(null);
444 Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceExist,
445 AuditingActionEnum.CREATE_RESOURCE, user, null, null);
446 assertResponse(createResponse, ActionStatus.MISSING_COMPONENT_NAME, ComponentTypeEnum.RESOURCE.getValue());
449 private void testResourceNameExceedsLimit() {
450 Resource resourceExccedsNameLimit = createResourceObject(false);
451 // 51 chars, the limit is 50
452 String tooLongResourceName = "zCRCAWjqte0DtgcAAMmcJcXeNubeX1p1vOZNTShAHOYNAHvV3iK";
453 resourceExccedsNameLimit.setName(tooLongResourceName);
455 Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceExccedsNameLimit,
456 AuditingActionEnum.CREATE_RESOURCE, user, null, null);
457 assertTrue(createResponse.isRight());
458 assertResponse(createResponse, ActionStatus.COMPONENT_NAME_EXCEEDS_LIMIT, ComponentTypeEnum.RESOURCE.getValue(),
459 "" + ValidationUtils.COMPONENT_NAME_MAX_LENGTH);
462 private void testResourceNameWrongFormat() {
463 Resource resource = createResourceObject(false);
465 String nameWrongFormat = "ljg?fd";
466 resource.setName(nameWrongFormat);
468 Either<Resource, ResponseFormat> createResponse = bl.createResource(resource,
469 AuditingActionEnum.CREATE_RESOURCE, user, null, null);
470 assertTrue(createResponse.isRight());
471 assertResponse(createResponse, ActionStatus.INVALID_COMPONENT_NAME, ComponentTypeEnum.RESOURCE.getValue());
474 // Resource name - end
475 // Resource description - start
476 private void testResourceDescExceedsLimitCreate() {
477 Resource resourceExccedsDescLimit = createResourceObject(false);
478 // 1025 chars, the limit is 1024
479 String tooLongResourceDesc = "1GUODojQ0sGzKR4NP7e5j82ADQ3KHTVOaezL95qcbuaqDtjZhAQGQ3iFwKAy580K4WiiXs3u3zq7RzXcSASl5fm0RsWtCMOIDP"
480 + "AOf9Tf2xtXxPCuCIMCR5wOGnNTaFxgnJEHAGxilBhZDgeMNHmCN1rMK5B5IRJOnZxcpcL1NeG3APTCIMP1lNAxngYulDm9heFSBc8TfXAADq7703AvkJT0QPpGq2z2P"
481 + "tlikcAnIjmWgfC5Tm7UH462BAlTyHg4ExnPPL4AO8c92VrD7kZSgSqiy73cN3gLT8uigkKrUgXQFGVUFrXVyyQXYtVM6bLBeuCGQf4C2j8lkNg6M0J3PC0PzMRoinOxk"
482 + "Ae2teeCtVcIj4A1KQo3210j8q2v7qQU69Mabsa6DT9FgE4rcrbiFWrg0Zto4SXWD3o1eJA9o29lTg6kxtklH3TuZTmpi5KVp1NFhS1RpnqF83tzv4mZLKsx7Zh1fEgYvRFwx1"
483 + "ar3RolyDfNoZiGBGTMsZzz7RPFBf2hTnLmNqVGQnHKhhGj0Y5s8t2cbqbO2nmHiJb9uaUVrCGypgbAcJL3KPOBfAVW8PcpmNj4yVjI3L4x5zHjmGZbp9vKshEQODcrmcgsYAoKqe"
484 + "uu5u7jk8XVxEfQ0m5qL8UOErXPlJovSmKUmP5B5T0w299zIWDYCzSoNasHpHjOMDLAiDDeHbozUOn9t3Qou00e9POq4RMM0VnIx1H38nJoJZz2XH8CI5YMQe7oTagaxgQTF2aa0qaq2"
485 + "V6nJsfRGRklGjNhFFYP2cS4Xv2IJO9DSX6LTXOmENrGVJJvMOZcvnBaZPfoAHN0LU4i1SoepLzulIxnZBfkUWFJgZ5wQ0Bco2GC1HMqzW21rwy4XHRxXpXbmW8LVyoA1KbnmVmROycU4"
486 + "scTZ62IxIcIWCVeMjBIcTviXULbPUyqlfEPXWr8IMJtpAaELWgyquPClAREMDs2b9ztKmUeXlMccFES1XWbFTrhBHhmmDyVReEgCwfokrUFR13LTUK1k8I6OEHOs";
488 resourceExccedsDescLimit.setDescription(tooLongResourceDesc);
490 Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceExccedsDescLimit,
491 AuditingActionEnum.CREATE_RESOURCE, user, null, null);
492 assertTrue(createResponse.isRight());
493 assertResponse(createResponse, ActionStatus.COMPONENT_DESCRIPTION_EXCEEDS_LIMIT,
494 ComponentTypeEnum.RESOURCE.getValue(), "" + ValidationUtils.COMPONENT_DESCRIPTION_MAX_LENGTH);
497 private void testResourceDescNotEnglish() {
498 Resource notEnglish = createResourceObject(false);
500 String notEnglishDesc = "\uC2B5";
501 notEnglish.setDescription(notEnglishDesc);
503 Either<Resource, ResponseFormat> createResponse = bl.createResource(notEnglish,
504 AuditingActionEnum.CREATE_RESOURCE, user, null, null);
505 assertTrue(createResponse.isRight());
506 assertResponse(createResponse, ActionStatus.COMPONENT_INVALID_DESCRIPTION,
507 ComponentTypeEnum.RESOURCE.getValue());
510 private void testResourceDescriptionEmpty() {
511 Resource resourceExist = createResourceObject(false);
512 resourceExist.setDescription("");
514 Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceExist,
515 AuditingActionEnum.CREATE_RESOURCE, user, null, null);
516 assertTrue(createResponse.isRight());
518 assertResponse(createResponse, ActionStatus.COMPONENT_MISSING_DESCRIPTION,
519 ComponentTypeEnum.RESOURCE.getValue());
522 private void testResourceDescriptionMissing() {
523 Resource resourceExist = createResourceObject(false);
524 resourceExist.setDescription(null);
526 Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceExist,
527 AuditingActionEnum.CREATE_RESOURCE, user, null, null);
528 assertTrue(createResponse.isRight());
530 assertResponse(createResponse, ActionStatus.COMPONENT_MISSING_DESCRIPTION,
531 ComponentTypeEnum.RESOURCE.getValue());
533 // Resource description - end
534 // Resource icon start
536 private void testResourceIconMissing() {
537 Resource resourceExist = createResourceObject(false);
538 resourceExist.setIcon(null);
540 Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceExist,
541 AuditingActionEnum.CREATE_RESOURCE, user, null, null);
542 assertTrue(createResponse.isRight());
544 assertResponse(createResponse, ActionStatus.COMPONENT_MISSING_ICON, ComponentTypeEnum.RESOURCE.getValue());
547 private void testResourceIconInvalid() {
548 Resource resourceExist = createResourceObject(false);
549 resourceExist.setIcon("kjk3453^&");
551 Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceExist,
552 AuditingActionEnum.CREATE_RESOURCE, user, null, null);
553 assertTrue(createResponse.isRight());
555 assertResponse(createResponse, ActionStatus.COMPONENT_INVALID_ICON, ComponentTypeEnum.RESOURCE.getValue());
558 private void testResourceIconExceedsLimit() {
559 Resource resourceExist = createResourceObject(false);
560 resourceExist.setIcon("dsjfhskdfhskjdhfskjdhkjdhfkshdfksjsdkfhsdfsdfsdfsfsdfsf");
562 Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceExist,
563 AuditingActionEnum.CREATE_RESOURCE, user, null, null);
564 assertTrue(createResponse.isRight());
566 assertResponse(createResponse, ActionStatus.COMPONENT_ICON_EXCEEDS_LIMIT, ComponentTypeEnum.RESOURCE.getValue(),
567 "" + ValidationUtils.ICON_MAX_LENGTH);
571 // Resource tags - start
572 private void testResourceTagNotExist() {
573 Resource resourceExist = createResourceObject(false);
574 resourceExist.setTags(null);
576 Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceExist,
577 AuditingActionEnum.CREATE_RESOURCE, user, null, null);
578 assertTrue(createResponse.isRight());
580 assertResponse(createResponse, ActionStatus.COMPONENT_MISSING_TAGS);
583 private void testResourceTagEmpty() {
584 Resource resourceExist = createResourceObject(false);
585 resourceExist.setTags(new ArrayList<String>());
587 Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceExist,
588 AuditingActionEnum.CREATE_RESOURCE, user, null, null);
589 assertTrue(createResponse.isRight());
591 assertResponse(createResponse, ActionStatus.COMPONENT_MISSING_TAGS);
594 private void testTagsExceedsLimitCreate() {
595 Resource resourceExccedsNameLimit = createResourceObject(false);
596 String tag1 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjQ";
597 String tag2 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjW";
598 String tag3 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjE";
599 String tag4 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjb";
600 String tag5 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjr";
601 String tag6 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjf";
602 String tag7 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjg";
603 String tag8 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjd";
604 String tag9 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjf";
605 String tag10 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjg";
606 String tag11 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjh";
607 String tag12 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjj";
608 String tag13 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjk";
609 String tag14 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjs";
610 String tag15 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjz";
611 String tag16 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjx";
612 String tag17 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBj2";
613 String tag18 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBj3";
614 String tag19 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBj4";
615 String tag20 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBj5";
616 String tag21 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBj0";
618 List<String> tagsList = new ArrayList<String>();
640 tagsList.add(resourceExccedsNameLimit.getName());
642 resourceExccedsNameLimit.setTags(tagsList);
644 Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceExccedsNameLimit,
645 AuditingActionEnum.CREATE_RESOURCE, user, null, null);
646 assertTrue(createResponse.isRight());
647 assertResponse(createResponse, ActionStatus.COMPONENT_TAGS_EXCEED_LIMIT,
648 "" + ValidationUtils.TAG_LIST_MAX_LENGTH);
652 private void testTagsSingleExceedsLimit() {
653 Resource resourceExccedsNameLimit = createResourceObject(false);
654 String tag1 = "afzs2qLBb5X6tZhiunkcEwiFX1qRQY8YZl3y3Du5M5xeQY5Nq9afcFHDZ9HaURw43gH27nAUWM36bMbMylwTFSzzNV8NO4v4ripe6Q15Vc2nPOFI";
655 String tag2 = resourceExccedsNameLimit.getName();
656 List<String> tagsList = new ArrayList<String>();
660 resourceExccedsNameLimit.setTags(tagsList);
662 Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceExccedsNameLimit,
663 AuditingActionEnum.CREATE_RESOURCE, user, null, null);
664 assertTrue(createResponse.isRight());
665 assertResponse(createResponse, ActionStatus.COMPONENT_SINGLE_TAG_EXCEED_LIMIT,
666 "" + ValidationUtils.TAG_MAX_LENGTH);
670 private void testTagsNoServiceName() {
671 Resource serviceExccedsNameLimit = createResourceObject(false);
672 String tag1 = "afzs2qLBb";
673 List<String> tagsList = new ArrayList<String>();
675 serviceExccedsNameLimit.setTags(tagsList);
677 Either<Resource, ResponseFormat> createResponse = bl.createResource(serviceExccedsNameLimit,
678 AuditingActionEnum.CREATE_RESOURCE, user, null, null);
679 assertTrue(createResponse.isRight());
680 assertResponse(createResponse, ActionStatus.COMPONENT_INVALID_TAGS_NO_COMP_NAME);
684 private void testInvalidTag() {
685 Resource serviceExccedsNameLimit = createResourceObject(false);
686 String tag1 = "afzs2qLBb%#%";
687 List<String> tagsList = new ArrayList<String>();
689 serviceExccedsNameLimit.setTags(tagsList);
691 Either<Resource, ResponseFormat> createResponse = bl.createResource(serviceExccedsNameLimit,
692 AuditingActionEnum.CREATE_RESOURCE, user, null, null);
693 assertTrue(createResponse.isRight());
694 assertResponse(createResponse, ActionStatus.INVALID_FIELD_FORMAT, new String[] { "Resource", "tag" });
698 // Resource tags - stop
699 // Resource contact start
701 private void testContactIdTooLong() {
702 Resource resourceContactId = createResourceObject(false);
703 // 59 chars instead of 50
704 String contactIdTooLong = "thisNameIsVeryLongAndExeccedsTheNormalLengthForContactId";
705 resourceContactId.setContactId(contactIdTooLong);
707 Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceContactId,
708 AuditingActionEnum.CREATE_RESOURCE, user, null, null);
709 assertTrue(createResponse.isRight());
710 assertResponse(createResponse, ActionStatus.COMPONENT_INVALID_CONTACT, ComponentTypeEnum.RESOURCE.getValue());
713 private void testContactIdWrongFormatCreate() {
714 Resource resourceContactId = createResourceObject(false);
715 // 3 letters and 3 digits and special characters
716 String contactIdFormatWrong = "yrt134!!!";
717 resourceContactId.setContactId(contactIdFormatWrong);
719 Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceContactId,
720 AuditingActionEnum.CREATE_RESOURCE, user, null, null);
721 assertTrue(createResponse.isRight());
722 assertResponse(createResponse, ActionStatus.COMPONENT_INVALID_CONTACT, ComponentTypeEnum.RESOURCE.getValue());
725 private void testResourceContactIdEmpty() {
726 Resource resourceExist = createResourceObject(false);
727 resourceExist.setContactId("");
729 Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceExist,
730 AuditingActionEnum.CREATE_RESOURCE, user, null, null);
731 assertTrue(createResponse.isRight());
733 assertResponse(createResponse, ActionStatus.COMPONENT_MISSING_CONTACT, ComponentTypeEnum.RESOURCE.getValue());
736 private void testResourceContactIdMissing() {
737 Resource resourceExist = createResourceObject(false);
738 resourceExist.setContactId(null);
740 Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceExist,
741 AuditingActionEnum.CREATE_RESOURCE, user, null, null);
742 assertTrue(createResponse.isRight());
744 assertResponse(createResponse, ActionStatus.COMPONENT_MISSING_CONTACT, ComponentTypeEnum.RESOURCE.getValue());
747 private void testVendorNameExceedsLimit() {
748 Resource resourceExccedsVendorNameLimit = createResourceObject(false);
749 String tooLongVendorName = "h1KSyJh9Eh1KSyJh9Eh1KSyJh9Eh1KSyJh9Eh1KSyJh9Eh1KSyJh9Eh1KSyJh9Eh1KSyJh9E";
750 resourceExccedsVendorNameLimit.setVendorName(tooLongVendorName);
752 Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceExccedsVendorNameLimit,
753 AuditingActionEnum.CREATE_RESOURCE, user, null, null);
754 assertTrue(createResponse.isRight());
755 assertResponse(createResponse, ActionStatus.VENDOR_NAME_EXCEEDS_LIMIT,
756 "" + ValidationUtils.VENDOR_NAME_MAX_LENGTH);
759 private void testResourceVendorModelNumberExceedsLimit() {
760 Resource resourceExccedsVendorModelNumberLimit = createResourceObject(false);
761 String tooLongVendorModelNumber = "h1KSyJh9Eh1KSyJh9Eh1KSyJh9Eh1KSyJh9Eh1KSyJh9Eh1KSyJh9Eh1KSyJh9Eh1KSyJh9E";
762 resourceExccedsVendorModelNumberLimit.setResourceVendorModelNumber(tooLongVendorModelNumber);
764 Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceExccedsVendorModelNumberLimit,
765 AuditingActionEnum.CREATE_RESOURCE, user, null, null);
766 assertTrue(createResponse.isRight());
767 assertResponse(createResponse, ActionStatus.RESOURCE_VENDOR_MODEL_NUMBER_EXCEEDS_LIMIT,
768 "" + ValidationUtils.RESOURCE_VENDOR_MODEL_NUMBER_MAX_LENGTH);
771 private void testVendorNameWrongFormatCreate() {
772 Resource resource = createResourceObject(false);
774 String nameWrongFormat = "ljg*fd";
775 resource.setVendorName(nameWrongFormat);
777 Either<Resource, ResponseFormat> createResponse = bl.createResource(resource,
778 AuditingActionEnum.CREATE_RESOURCE, user, null, null);
779 assertTrue(createResponse.isRight());
780 assertResponse(createResponse, ActionStatus.INVALID_VENDOR_NAME);
783 private void testVendorReleaseWrongFormat() {
784 Resource resource = createResourceObject(false);
786 String nameWrongFormat = "1>2";
787 resource.setVendorRelease(nameWrongFormat);
789 Either<Resource, ResponseFormat> createResponse = bl.createResource(resource,
790 AuditingActionEnum.CREATE_RESOURCE, user, null, null);
791 assertTrue(createResponse.isRight());
792 assertResponse(createResponse, ActionStatus.INVALID_VENDOR_RELEASE);
796 private void testVendorReleaseExceedsLimitCreate() {
797 Resource resourceExccedsNameLimit = createResourceObject(false);
798 String tooLongVendorRelease = "h1KSyJh9Eh1KSyJh9Eh1KSyJh9Eh1KSyJh9E";
799 resourceExccedsNameLimit.setVendorRelease(tooLongVendorRelease);
801 Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceExccedsNameLimit,
802 AuditingActionEnum.CREATE_RESOURCE, user, null, null);
803 assertTrue(createResponse.isRight());
804 assertResponse(createResponse, ActionStatus.VENDOR_RELEASE_EXCEEDS_LIMIT,
805 "" + ValidationUtils.VENDOR_RELEASE_MAX_LENGTH);
808 private void testResourceVendorNameMissing() {
809 Resource resourceExist = createResourceObject(false);
810 resourceExist.setVendorName(null);
812 Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceExist,
813 AuditingActionEnum.CREATE_RESOURCE, user, null, null);
814 assertTrue(createResponse.isRight());
816 assertResponse(createResponse, ActionStatus.MISSING_VENDOR_NAME);
819 private void testResourceVendorReleaseMissing() {
820 Resource resourceExist = createResourceObject(false);
821 resourceExist.setVendorRelease(null);
823 Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceExist,
824 AuditingActionEnum.CREATE_RESOURCE, user, null, null);
825 assertTrue(createResponse.isRight());
827 assertResponse(createResponse, ActionStatus.MISSING_VENDOR_RELEASE);
830 // Resource vendor name/release stop
832 private void testResourceCategoryExist() {
833 Resource resourceExist = createResourceObject(false);
834 resourceExist.setCategories(null);
836 Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceExist,
837 AuditingActionEnum.CREATE_RESOURCE, user, null, null);
838 assertTrue(createResponse.isRight());
840 assertResponse(createResponse, ActionStatus.COMPONENT_MISSING_CATEGORY, ComponentTypeEnum.RESOURCE.getValue());
843 private void testResourceBadCategoryCreate() {
845 Resource resourceExist = createResourceObject(false);
846 resourceExist.setCategories(null);
847 resourceExist.addCategory("koko", "koko");
849 Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceExist,
850 AuditingActionEnum.CREATE_RESOURCE, user, null, null);
851 assertTrue(createResponse.isRight());
853 assertResponse(createResponse, ActionStatus.COMPONENT_INVALID_CATEGORY, ComponentTypeEnum.RESOURCE.getValue());
858 private void testHappyScenarioCostLicenseType() {
859 Resource createResourceObject = createResourceObject(false);
860 Resource createResourceObjectAfterCreate = createResourceObject(true);
861 // Adding cost and licenseType to basic mock
862 Either<Resource, StorageOperationStatus> eitherCreate = Either.left(createResourceObjectAfterCreate);
863 when(toscaOperationFacade.createToscaComponent(Mockito.any(Resource.class))).thenReturn(eitherCreate);
865 String cost = "123.456";
866 String licenseType = "User";
867 createResourceObject.setCost(cost);
868 createResourceObject.setLicenseType(licenseType);
869 Either<Resource, ResponseFormat> createResponse = bl.createResource(createResourceObject,
870 AuditingActionEnum.CREATE_RESOURCE, user, null, null);
872 if (createResponse.isRight()) {
873 assertEquals(new Integer(200), createResponse.right().value().getStatus());
875 createResourceObjectAfterCreate.setCost(cost);
876 createResourceObjectAfterCreate.setLicenseType(licenseType);
877 assertEquals(createResourceObjectAfterCreate, createResponse.left().value());
880 private void testCostWrongFormatCreate() {
881 Resource resourceCost = createResourceObject(false);
882 // Comma instead of fullstop
883 String cost = "12356,464";
884 resourceCost.setCost(cost);
886 Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceCost,
887 AuditingActionEnum.CREATE_RESOURCE, user, null, null);
888 assertTrue(createResponse.isRight());
889 assertResponse(createResponse, ActionStatus.INVALID_CONTENT);
893 // License type start
894 private void testLicenseTypeWrongFormatCreate() {
895 Resource resourceLicenseType = createResourceObject(false);
897 String licenseType = "cpu";
898 resourceLicenseType.setLicenseType(licenseType);
900 Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceLicenseType,
901 AuditingActionEnum.CREATE_RESOURCE, user, null, null);
902 assertTrue(createResponse.isRight());
903 assertResponse(createResponse, ActionStatus.INVALID_CONTENT);
907 // Derived from start
908 private void testResourceTemplateNotExist() {
909 Resource resourceExist = createResourceObject(false);
910 List<String> list = null;
911 resourceExist.setDerivedFrom(list);
913 Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceExist,
914 AuditingActionEnum.CREATE_RESOURCE, user, null, null);
915 assertTrue(createResponse.isRight());
917 assertResponse(createResponse, ActionStatus.MISSING_DERIVED_FROM_TEMPLATE);
920 private void testResourceTemplateEmpty() {
921 Resource resourceExist = createResourceObject(false);
922 resourceExist.setDerivedFrom(new ArrayList<String>());
924 Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceExist,
925 AuditingActionEnum.CREATE_RESOURCE, user, null, null);
926 assertTrue(createResponse.isRight());
928 assertResponse(createResponse, ActionStatus.MISSING_DERIVED_FROM_TEMPLATE);
931 private void testResourceTemplateInvalid() {
932 Resource resourceExist = createResourceObject(false);
933 ArrayList<String> derivedFrom = new ArrayList<String>();
934 derivedFrom.add("kuku");
935 resourceExist.setDerivedFrom(derivedFrom);
937 Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceExist,
938 AuditingActionEnum.CREATE_RESOURCE, user, null, null);
939 assertTrue(createResponse.isRight());
941 assertResponse(createResponse, ActionStatus.PARENT_RESOURCE_NOT_FOUND);
945 private void assertResponse(Either<Resource, ResponseFormat> createResponse, ActionStatus expectedStatus,
946 String... variables) {
947 ResponseFormat expectedResponse = responseManager.getResponseFormat(expectedStatus, variables);
948 ResponseFormat actualResponse = createResponse.right().value();
949 assertEquals(expectedResponse.getStatus(), actualResponse.getStatus());
950 assertEquals("assert error description", expectedResponse.getFormattedMessage(),
951 actualResponse.getFormattedMessage());
954 // UPDATE tests - start
957 public void testResourceNameWrongFormat_UPDATE() {
958 Resource resource = createResourceObject(true);
959 Resource updatedResource = createResourceObject(true);
961 // this is in order to prevent failing with 403 earlier
962 Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
963 when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
965 String nameWrongFormat = "ljg*fd";
966 updatedResource.setName(nameWrongFormat);
968 Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
969 when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
971 Either<Resource, ResponseFormat> createResponse = bl.updateResourceMetadata(resource.getUniqueId(),
972 updatedResource, null, user, false);
973 assertTrue(createResponse.isRight());
974 assertResponse(createResponse, ActionStatus.INVALID_COMPONENT_NAME, ComponentTypeEnum.RESOURCE.getValue());
979 public void testResourceNameAfterCertify_UPDATE() {
980 Resource resource = createResourceObject(true);
981 Resource updatedResource = createResourceObject(true);
983 // this is in order to prevent failing with 403 earlier
984 Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
985 // when(resourceOperation.getResource_tx(resource.getUniqueId(),false)).thenReturn(eitherUpdate);
986 when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
989 updatedResource.setName(name);
990 resource.setVersion("1.0");
992 Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
993 when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
995 Either<Resource, ResponseFormat> createResponse = bl.updateResourceMetadata(resource.getUniqueId(),
996 updatedResource, null, user, false);
997 assertTrue(createResponse.isRight());
998 assertResponse(createResponse, ActionStatus.RESOURCE_NAME_CANNOT_BE_CHANGED);
1003 public void testResourceNameExceedsLimit_UPDATE() {
1004 Resource resource = createResourceObject(true);
1005 Resource updatedResource = createResourceObject(true);
1007 // this is in order to prevent failing with 403 earlier
1008 Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
1009 when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
1011 // 51 chars, the limit is 50
1012 String tooLongResourceName = "zCRCAWjqte0DtgcAAMmcJcXeNubeX1p1vOZNTShAHOYNAHvV3iK";
1013 updatedResource.setName(tooLongResourceName);
1014 Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
1015 when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
1017 Either<Resource, ResponseFormat> createResponse = bl.updateResourceMetadata(resource.getUniqueId(),
1018 updatedResource, null, user, false);
1019 assertTrue(createResponse.isRight());
1020 assertResponse(createResponse, ActionStatus.COMPONENT_NAME_EXCEEDS_LIMIT, ComponentTypeEnum.RESOURCE.getValue(),
1021 "" + ValidationUtils.COMPONENT_NAME_MAX_LENGTH);
1025 public void testResourceNameAlreadyExist_UPDATE() {
1026 Resource resource = createResourceObject(true);
1027 Resource updatedResource = createResourceObject(true);
1029 // this is in order to prevent failing with 403 earlier
1030 Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
1031 when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
1033 String resourceName = "alreadyExists";
1034 updatedResource.setName(resourceName);
1035 Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(updatedResource);
1036 when(toscaOperationFacade.updateToscaElement(updatedResource)).thenReturn(dataModelResponse);
1037 Either<Resource, ResponseFormat> createResponse = bl.updateResourceMetadata(resource.getUniqueId(),
1038 updatedResource, null, user, false);
1039 assertTrue(createResponse.isRight());
1040 assertResponse(createResponse, ActionStatus.COMPONENT_NAME_ALREADY_EXIST, ComponentTypeEnum.RESOURCE.getValue(),
1047 public void testResourceDescExceedsLimit_UPDATE() {
1048 Resource resource = createResourceObject(true);
1049 Resource updatedResource = createResourceObject(true);
1051 // this is in order to prevent failing with 403 earlier
1052 Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
1053 when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
1055 // 1025 chars, the limit is 1024
1056 String tooLongResourceDesc = "1GUODojQ0sGzKR4NP7e5j82ADQ3KHTVOaezL95qcbuaqDtjZhAQGQ3iFwKAy580K4WiiXs3u3zq7RzXcSASl5fm0RsWtCMOIDP"
1057 + "AOf9Tf2xtXxPCuCIMCR5wOGnNTaFxgnJEHAGxilBhZDgeMNHmCN1rMK5B5IRJOnZxcpcL1NeG3APTCIMP1lNAxngYulDm9heFSBc8TfXAADq7703AvkJT0QPpGq2z2P"
1058 + "tlikcAnIjmWgfC5Tm7UH462BAlTyHg4ExnPPL4AO8c92VrD7kZSgSqiy73cN3gLT8uigkKrUgXQFGVUFrXVyyQXYtVM6bLBeuCGQf4C2j8lkNg6M0J3PC0PzMRoinOxk"
1059 + "Ae2teeCtVcIj4A1KQo3210j8q2v7qQU69Mabsa6DT9FgE4rcrbiFWrg0Zto4SXWD3o1eJA9o29lTg6kxtklH3TuZTmpi5KVp1NFhS1RpnqF83tzv4mZLKsx7Zh1fEgYvRFwx1"
1060 + "ar3RolyDfNoZiGBGTMsZzz7RPFBf2hTnLmNqVGQnHKhhGj0Y5s8t2cbqbO2nmHiJb9uaUVrCGypgbAcJL3KPOBfAVW8PcpmNj4yVjI3L4x5zHjmGZbp9vKshEQODcrmcgsYAoKqe"
1061 + "uu5u7jk8XVxEfQ0m5qL8UOErXPlJovSmKUmP5B5T0w299zIWDYCzSoNasHpHjOMDLAiDDeHbozUOn9t3Qou00e9POq4RMM0VnIx1H38nJoJZz2XH8CI5YMQe7oTagaxgQTF2aa0qaq2"
1062 + "V6nJsfRGRklGjNhFFYP2cS4Xv2IJO9DSX6LTXOmENrGVJJvMOZcvnBaZPfoAHN0LU4i1SoepLzulIxnZBfkUWFJgZ5wQ0Bco2GC1HMqzW21rwy4XHRxXpXbmW8LVyoA1KbnmVmROycU4"
1063 + "scTZ62IxIcIWCVeMjBIcTviXULbPUyqlfEPXWr8IMJtpAaELWgyquPClAREMDs2b9ztKmUeXlMccFES1XWbFTrhBHhmmDyVReEgCwfokrUFR13LTUK1k8I6OEHOs";
1064 updatedResource.setDescription(tooLongResourceDesc);
1065 Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
1066 when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
1067 Either<Resource, ResponseFormat> createResponse = bl.updateResourceMetadata(resource.getUniqueId(),
1068 updatedResource, null, user, false);
1069 assertTrue(createResponse.isRight());
1070 assertResponse(createResponse, ActionStatus.COMPONENT_DESCRIPTION_EXCEEDS_LIMIT,
1071 ComponentTypeEnum.RESOURCE.getValue(), "" + ValidationUtils.COMPONENT_DESCRIPTION_MAX_LENGTH);
1076 public void testIconWrongFormat_UPDATE() {
1077 Resource resource = createResourceObject(true);
1078 Resource updatedResource = createResourceObject(true);
1080 // this is in order to prevent failing with 403 earlier
1081 Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
1082 when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
1085 String icon = "icon.jpg";
1086 updatedResource.setIcon(icon);
1087 Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
1088 when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
1090 Either<Resource, ResponseFormat> createResponse = bl.updateResourceMetadata(resource.getUniqueId(),
1091 updatedResource, null, user, false);
1092 assertTrue(createResponse.isRight());
1093 assertResponse(createResponse, ActionStatus.COMPONENT_INVALID_ICON, ComponentTypeEnum.RESOURCE.getValue());
1098 public void testIconAfterCertify_UPDATE() {
1099 Resource resource = createResourceObject(true);
1100 Resource updatedResource = createResourceObject(true);
1102 // this is in order to prevent failing with 403 earlier
1103 Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
1104 when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
1107 String icon = "icon";
1108 updatedResource.setIcon(icon);
1110 resource.setVersion("1.0");
1112 Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
1113 when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
1114 Either<Resource, ResponseFormat> createResponse = bl.updateResourceMetadata(resource.getUniqueId(),
1115 updatedResource, null, user, false);
1116 assertTrue(createResponse.isRight());
1117 assertResponse(createResponse, ActionStatus.RESOURCE_ICON_CANNOT_BE_CHANGED);
1122 public void testTagsExceedsLimit_UPDATE() {
1123 Resource resource = createResourceObject(true);
1124 Resource updatedResource = createResourceObject(true);
1126 // this is in order to prevent failing with 403 earlier
1127 Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
1128 when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
1130 String tag1 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjQ";
1131 String tag2 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjW";
1132 String tag3 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjE";
1133 String tag4 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjb";
1134 String tag5 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjr";
1135 String tag6 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjf";
1136 String tag7 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjg";
1137 String tag8 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjd";
1138 String tag9 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjf";
1139 String tag10 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjg";
1140 String tag11 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjh";
1141 String tag12 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjj";
1142 String tag13 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjk";
1143 String tag14 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjs";
1144 String tag15 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjz";
1145 String tag16 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjx";
1146 String tag17 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBj2";
1147 String tag18 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBj3";
1148 String tag19 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBj4";
1149 String tag20 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBj5";
1150 String tag21 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBj0";
1152 List<String> tagsList = new ArrayList<String>();
1162 tagsList.add(tag10);
1163 tagsList.add(tag11);
1164 tagsList.add(tag12);
1165 tagsList.add(tag13);
1166 tagsList.add(tag14);
1167 tagsList.add(tag15);
1168 tagsList.add(tag16);
1169 tagsList.add(tag17);
1170 tagsList.add(tag18);
1171 tagsList.add(tag19);
1172 tagsList.add(tag20);
1173 tagsList.add(tag21);
1174 tagsList.add(resource.getName());
1176 updatedResource.setTags(tagsList);
1177 Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
1178 when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
1179 Either<Resource, ResponseFormat> createResponse = bl.updateResourceMetadata(resource.getUniqueId(),
1180 updatedResource, null, user, false);
1181 assertTrue(createResponse.isRight());
1183 assertResponse(createResponse, ActionStatus.COMPONENT_TAGS_EXCEED_LIMIT,
1184 "" + ValidationUtils.TAG_LIST_MAX_LENGTH);
1188 public void testVendorNameWrongFormat_UPDATE() {
1189 Resource resource = createResourceObject(true);
1190 Resource updatedResource = createResourceObject(true);
1192 // this is in order to prevent failing with 403 earlier
1193 Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
1194 when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
1197 String nameWrongFormat = "ljg*fd";
1198 updatedResource.setVendorName(nameWrongFormat);
1199 Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
1200 when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
1201 Either<Resource, ResponseFormat> createResponse = bl.updateResourceMetadata(resource.getUniqueId(),
1202 updatedResource, null, user, false);
1203 assertTrue(createResponse.isRight());
1204 assertResponse(createResponse, ActionStatus.INVALID_VENDOR_NAME);
1209 public void testVendorNameAfterCertify_UPDATE() {
1210 Resource resource = createResourceObject(true);
1211 Resource updatedResource = createResourceObject(true);
1213 // this is in order to prevent failing with 403 earlier
1214 Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
1215 when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
1218 String nameWrongFormat = "ljg*fd";
1219 updatedResource.setVendorName(nameWrongFormat);
1220 resource.setVersion("1.0");
1222 Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
1223 when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
1224 Either<Resource, ResponseFormat> createResponse = bl.updateResourceMetadata(resource.getUniqueId(),
1225 updatedResource, null, user, false);
1226 assertTrue(createResponse.isRight());
1227 assertResponse(createResponse, ActionStatus.RESOURCE_VENDOR_NAME_CANNOT_BE_CHANGED);
1232 public void testVendorReleaseExceedsLimit_UPDATE() {
1233 Resource resource = createResourceObject(true);
1234 Resource updatedResource = createResourceObject(true);
1236 // this is in order to prevent failing with 403 earlier
1237 Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
1238 when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
1239 // 129 chars, the limit is 128
1240 String tooLongVendorRelease = "h1KSyJh9EspI8SPwAGu4VETfqWejeanuB1PCJBxJmJncYnrW0lnsEFFVRIukRJkwlOVnZCy8p38tjhANeZq3BGMHIawWR6ICl8Wi9mikRYALWgvJug00JrlQ0iPVKPLxy";
1241 updatedResource.setVendorRelease(tooLongVendorRelease);
1242 Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
1243 when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
1244 Either<Resource, ResponseFormat> createResponse = bl.updateResourceMetadata(resource.getUniqueId(),
1245 updatedResource, null, user, false);
1246 assertTrue(createResponse.isRight());
1247 assertResponse(createResponse, ActionStatus.VENDOR_RELEASE_EXCEEDS_LIMIT,
1248 "" + ValidationUtils.VENDOR_RELEASE_MAX_LENGTH);
1252 public void testContactIdWrongFormat_UPDATE() {
1253 Resource resource = createResourceObject(true);
1254 Resource updatedResource = createResourceObject(true);
1256 // this is in order to prevent failing with 403 earlier
1257 Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
1258 when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
1260 String resourceId = resource.getUniqueId();
1261 // 3 letters and 3 digits
1262 String contactIdTooLong = "yrt134";
1263 updatedResource.setContactId(contactIdTooLong);
1264 Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
1265 when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
1266 Either<Resource, ResponseFormat> createResponse = bl.updateResourceMetadata(resourceId, updatedResource, null,
1268 assertTrue(createResponse.isRight());
1270 assertResponse(createResponse, ActionStatus.COMPONENT_INVALID_CONTACT, ComponentTypeEnum.RESOURCE.getValue());
1274 public void testResourceBadCategory_UPDATE() {
1275 Resource resource = createResourceObject(true);
1276 Resource updatedResource = createResourceObject(true);
1278 // this is in order to prevent failing with 403 earlier
1279 Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
1280 when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
1282 String resourceId = resource.getUniqueId();
1283 String badCategory = "ddfds";
1284 updatedResource.setCategories(null);
1285 updatedResource.addCategory(badCategory, "fikt");
1286 Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
1287 when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
1288 Either<Resource, ResponseFormat> createResponse = bl.updateResourceMetadata(resourceId, updatedResource, null,
1290 assertTrue(createResponse.isRight());
1292 assertResponse(createResponse, ActionStatus.COMPONENT_INVALID_CATEGORY, ComponentTypeEnum.RESOURCE.getValue());
1296 public void testResourceCategoryAfterCertify_UPDATE() {
1297 Resource resource = createResourceObject(true);
1298 Resource updatedResource = createResourceObject(true);
1300 // this is in order to prevent failing with 403 earlier
1301 Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
1302 when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
1304 String resourceId = resource.getUniqueId();
1305 updatedResource.setCategories(null);
1306 updatedResource.addCategory(RESOURCE_CATEGORY1, UPDATED_SUBCATEGORY);
1307 resource.setVersion("1.0");
1309 Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
1310 when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
1311 Either<Resource, ResponseFormat> createResponse = bl.updateResourceMetadata(resourceId, updatedResource, null,
1313 assertTrue(createResponse.isRight());
1315 assertResponse(createResponse, ActionStatus.RESOURCE_CATEGORY_CANNOT_BE_CHANGED);
1318 // Derived from start
1320 public void testResourceTemplateNotExist_UPDATE() {
1321 Resource resource = createResourceObject(true);
1322 Resource updatedResource = createResourceObject(true);
1324 // this is in order to prevent failing with 403 earlier
1325 Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
1326 when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
1327 String resourceId = resource.getUniqueId();
1329 List<String> list = null;
1330 updatedResource.setDerivedFrom(list);
1331 Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
1332 when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
1333 Either<Resource, ResponseFormat> createResponse = bl.updateResourceMetadata(resourceId, updatedResource, null,
1335 assertTrue(createResponse.isRight());
1337 assertResponse(createResponse, ActionStatus.MISSING_DERIVED_FROM_TEMPLATE);
1341 public void testResourceTemplateEmpty_UPDATE() {
1342 Resource resource = createResourceObject(true);
1343 Resource updatedResource = createResourceObject(true);
1344 String resourceId = resource.getUniqueId();
1346 // this is in order to prevent failing with 403 earlier
1347 Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
1348 when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
1350 updatedResource.setDerivedFrom(new ArrayList<String>());
1351 Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
1352 when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
1353 Either<Resource, ResponseFormat> createResponse = bl.updateResourceMetadata(resourceId, updatedResource, null,
1355 assertTrue(createResponse.isRight());
1357 assertResponse(createResponse, ActionStatus.MISSING_DERIVED_FROM_TEMPLATE);
1361 public void testResourceTemplateInvalid_UPDATE() {
1362 Resource resource = createResourceObject(true);
1363 Resource updatedResource = createResourceObject(true);
1364 String resourceId = resource.getUniqueId();
1366 // this is in order to prevent failing with 403 earlier
1367 Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
1368 when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
1370 ArrayList<String> derivedFrom = new ArrayList<String>();
1371 derivedFrom.add("kuku");
1372 updatedResource.setDerivedFrom(derivedFrom);
1373 Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
1374 when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
1375 Either<Resource, ResponseFormat> createResponse = bl.updateResourceMetadata(resourceId, updatedResource, null,
1377 assertTrue(createResponse.isRight());
1379 assertResponse(createResponse, ActionStatus.PARENT_RESOURCE_NOT_FOUND);
1383 public void testResourceTemplateCertify_UPDATE_HAPPY() {
1384 Resource resource = createResourceObject(true);
1385 Resource updatedResource = createResourceObject(true);
1386 String resourceId = resource.getUniqueId();
1388 // this is in order to prevent failing with 403 earlier
1389 Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
1390 when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
1392 Either<Boolean, StorageOperationStatus> isToscaNameExtending = Either.left(true);
1393 when(toscaOperationFacade.validateToscaResourceNameExtends(Mockito.anyString(), Mockito.anyString()))
1394 .thenReturn(isToscaNameExtending);
1396 Either<Map<String, PropertyDefinition>, StorageOperationStatus> findPropertiesOfNode = Either
1397 .left(new HashMap<>());
1398 when(propertyOperation.deleteAllPropertiesAssociatedToNode(Mockito.any(NodeTypeEnum.class),
1399 Mockito.anyString())).thenReturn(findPropertiesOfNode);
1401 resource.setVersion("1.0");
1403 ArrayList<String> derivedFrom = new ArrayList<String>();
1404 derivedFrom.add("tosca.nodes.Root");
1405 updatedResource.setDerivedFrom(derivedFrom);
1406 Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(updatedResource);
1407 when(toscaOperationFacade.updateToscaElement(updatedResource)).thenReturn(dataModelResponse);
1408 Either<Resource, ResponseFormat> createResponse = bl.updateResourceMetadata(resourceId, updatedResource, null,
1410 assertTrue(createResponse.isLeft());
1414 public void testResourceTemplateCertify_UPDATE_SAD() {
1415 Resource resource = createResourceObject(true);
1416 Resource updatedResource = createResourceObject(true);
1417 String resourceId = resource.getUniqueId();
1419 // this is in order to prevent failing with 403 earlier
1420 Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
1421 when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
1423 Either<Boolean, StorageOperationStatus> isToscaNameExtending = Either.left(false);
1424 when(toscaOperationFacade.validateToscaResourceNameExtends(Mockito.anyString(), Mockito.anyString()))
1425 .thenReturn(isToscaNameExtending);
1427 resource.setVersion("1.0");
1429 ArrayList<String> derivedFrom = new ArrayList<String>();
1430 derivedFrom.add("tosca.nodes.Root");
1431 updatedResource.setDerivedFrom(derivedFrom);
1432 Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
1433 when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
1434 Either<Resource, ResponseFormat> createResponse = bl.updateResourceMetadata(resourceId, updatedResource, null,
1436 assertTrue(createResponse.isRight());
1438 assertResponse(createResponse, ActionStatus.PARENT_RESOURCE_DOES_NOT_EXTEND);
1440 // Derived from stop
1443 public void createOrUpdateResourceAlreadyCheckout() {
1444 Resource resourceExist = createResourceObject(false);
1446 Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceExist,
1447 AuditingActionEnum.CREATE_RESOURCE, user, null, null);
1449 createResponse.left().value().setLastUpdaterUserId(user.getUserId());
1450 assertTrue(createResponse.isLeft());
1452 Either<Component, StorageOperationStatus> getLatestResult = Either.left(createResponse.left().value());
1453 when(toscaOperationFacade.getLatestByName(resourceExist.getName())).thenReturn(getLatestResult);
1454 when(toscaOperationFacade.overrideComponent(Mockito.any(Component.class), Mockito.any(Component.class)))
1455 .thenReturn(getLatestResult);
1457 Resource resourceToUpdtae = createResourceObject(false);
1459 Either<ImmutablePair<Resource, ActionStatus>, ResponseFormat> createOrUpdateResource = bl
1460 .createOrUpdateResourceByImport(resourceToUpdtae, user, false, false, false, null);
1461 assertTrue(createOrUpdateResource.isLeft());
1463 Mockito.verify(toscaOperationFacade, Mockito.times(1)).overrideComponent(Mockito.any(Resource.class),
1464 Mockito.any(Resource.class));
1465 Mockito.verify(lifecycleBl, Mockito.times(0)).changeState(Mockito.anyString(), Mockito.eq(user),
1466 Mockito.eq(LifeCycleTransitionEnum.CHECKOUT), Mockito.any(LifecycleChangeInfoWithAction.class),
1467 Mockito.anyBoolean(), Mockito.anyBoolean());
1472 public void createOrUpdateResourceCertified() {
1473 Resource resourceExist = createResourceObject(false);
1475 Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceExist,
1476 AuditingActionEnum.CREATE_RESOURCE, user, null, null);
1478 assertTrue(createResponse.isLeft());
1479 Resource certifiedResource = createResponse.left().value();
1480 certifiedResource.setLifecycleState(LifecycleStateEnum.CERTIFIED);
1481 certifiedResource.setVersion("1.0");
1483 Either<Component, StorageOperationStatus> getLatestResult = Either.left(certifiedResource);
1484 when(toscaOperationFacade.getLatestByName(resourceExist.getName())).thenReturn(getLatestResult);
1485 when(toscaOperationFacade.overrideComponent(Mockito.any(Component.class), Mockito.any(Component.class)))
1486 .thenReturn(getLatestResult);
1488 when(lifecycleBl.changeState(Mockito.anyString(), Mockito.eq(user),
1489 Mockito.eq(LifeCycleTransitionEnum.CHECKOUT), Mockito.any(LifecycleChangeInfoWithAction.class),
1490 Mockito.anyBoolean(), Mockito.anyBoolean())).thenReturn(createResponse);
1492 Resource resourceToUpdtae = createResourceObject(false);
1494 Either<ImmutablePair<Resource, ActionStatus>, ResponseFormat> createOrUpdateResource = bl
1495 .createOrUpdateResourceByImport(resourceToUpdtae, user, false, false, false, null);
1496 assertTrue(createOrUpdateResource.isLeft());
1498 Mockito.verify(toscaOperationFacade, Mockito.times(1)).overrideComponent(Mockito.any(Component.class),
1499 Mockito.any(Component.class));
1500 Mockito.verify(lifecycleBl, Mockito.times(1)).changeState(Mockito.anyString(), Mockito.eq(user),
1501 Mockito.eq(LifeCycleTransitionEnum.CHECKOUT), Mockito.any(LifecycleChangeInfoWithAction.class),
1502 Mockito.anyBoolean(), Mockito.anyBoolean());
1507 public void createOrUpdateResourceNotExist() {
1508 Resource resourceToUpdtae = createResourceObject(false);
1510 Either<Component, StorageOperationStatus> getLatestResult = Either.right(StorageOperationStatus.NOT_FOUND);
1511 when(toscaOperationFacade.getLatestByName(resourceToUpdtae.getName())).thenReturn(getLatestResult);
1513 Either<Component, StorageOperationStatus> getLatestToscaNameResult = Either
1514 .right(StorageOperationStatus.NOT_FOUND);
1515 when(toscaOperationFacade.getLatestByToscaResourceName(resourceToUpdtae.getToscaResourceName()))
1516 .thenReturn(getLatestToscaNameResult);
1518 Either<ImmutablePair<Resource, ActionStatus>, ResponseFormat> createOrUpdateResource = bl
1519 .createOrUpdateResourceByImport(resourceToUpdtae, user, false, false, false, null);
1520 assertTrue(createOrUpdateResource.isLeft());
1522 Mockito.verify(toscaOperationFacade, Mockito.times(0)).overrideComponent(Mockito.any(Component.class),
1523 Mockito.any(Component.class));
1524 Mockito.verify(lifecycleBl, Mockito.times(0)).changeState(Mockito.anyString(), Mockito.eq(user),
1525 Mockito.eq(LifeCycleTransitionEnum.CHECKOUT), Mockito.any(LifecycleChangeInfoWithAction.class),
1526 Mockito.anyBoolean(), Mockito.anyBoolean());
1531 public void testValidatePropertiesDefaultValues_SuccessfullWithoutProperties() {
1532 Resource basic = createResourceObject(true);
1534 Either<Boolean, ResponseFormat> validatePropertiesDefaultValues = bl.validatePropertiesDefaultValues(basic);
1535 assertTrue(validatePropertiesDefaultValues.isLeft());
1539 public void testValidatePropertiesDefaultValues_SuccessfullWithProperties() {
1540 Resource basic = createResourceObject(true);
1541 PropertyDefinition property = new PropertyDefinition();
1542 property.setName("myProperty");
1543 property.setType(ToscaPropertyType.INTEGER.getType());
1544 property.setDefaultValue("1");
1545 List<PropertyDefinition> properties = new ArrayList<>();
1546 properties.add(property);
1547 basic.setProperties(properties);
1548 when(propertyOperation.isPropertyTypeValid(property)).thenReturn(true);
1549 when(propertyOperation.isPropertyDefaultValueValid(property, emptyDataTypes)).thenReturn(true);
1550 Either<Boolean, ResponseFormat> validatePropertiesDefaultValues = bl.validatePropertiesDefaultValues(basic);
1551 assertTrue(validatePropertiesDefaultValues.isLeft());
1555 public void testValidatePropertiesDefaultValues_FailedWithProperties() {
1556 Resource basic = createResourceObject(true);
1557 PropertyDefinition property = new PropertyDefinition();
1558 property.setName("myProperty");
1559 property.setType(ToscaPropertyType.INTEGER.getType());
1560 property.setDefaultValue("1.5");
1561 List<PropertyDefinition> properties = new ArrayList<>();
1562 properties.add(property);
1563 basic.setProperties(properties);
1565 when(propertyOperation.isPropertyDefaultValueValid(property, emptyDataTypes)).thenReturn(false);
1566 Either<Boolean, ResponseFormat> validatePropertiesDefaultValues = bl.validatePropertiesDefaultValues(basic);
1567 assertTrue(validatePropertiesDefaultValues.isRight());
1571 // public void testDeleteMarkedResourcesNoResources() {
1572 // List<GraphVertex> ids = new ArrayList<>();
1573 // Either<List<GraphVertex>, StorageOperationStatus> eitherNoResources =
1574 // Either.left(ids);
1575 // when(topologyTemplateOperation.getAllComponentsMarkedForDeletion(ComponentTypeEnum.RESOURCE)).thenReturn(eitherNoResources);
1577 // Either<List<String>, ResponseFormat> deleteMarkedResources =
1578 // bl.deleteMarkedComponents();
1579 // assertTrue(deleteMarkedResources.isLeft());
1580 // assertTrue(deleteMarkedResources.left().value().isEmpty());
1582 // Mockito.verify(artifactManager,
1583 // Mockito.times(0)).deleteAllComponentArtifactsIfNotOnGraph(Mockito.anyList());
1588 // public void testDeleteMarkedResources() {
1589 // List<String> ids = new ArrayList<String>();
1590 // String resourceInUse = "123";
1591 // ids.add(resourceInUse);
1592 // String resourceFree = "456";
1593 // ids.add(resourceFree);
1594 // Either<List<String>, StorageOperationStatus> eitherNoResources =
1595 // Either.left(ids);
1596 // when(toscaOperationFacade.getAllComponentsMarkedForDeletion()).thenReturn(eitherNoResources);
1598 // Either<Boolean, StorageOperationStatus> resourceInUseResponse =
1599 // Either.left(true);
1600 // Either<Boolean, StorageOperationStatus> resourceFreeResponse =
1601 // Either.left(false);
1603 // List<ArtifactDefinition> artifacts = new ArrayList<ArtifactDefinition>();
1604 // Either<List<ArtifactDefinition>, StorageOperationStatus>
1605 // getArtifactsResponse = Either.left(artifacts);
1606 // when(toscaOperationFacade.getComponentArtifactsForDelete(resourceFree,
1607 // NodeTypeEnum.Resource, true)).thenReturn(getArtifactsResponse);
1609 // when(toscaOperationFacade.isComponentInUse(resourceFree)).thenReturn(resourceFreeResponse);
1610 // when(toscaOperationFacade.isComponentInUse(resourceInUse)).thenReturn(resourceInUseResponse);
1612 // Either<Component, StorageOperationStatus> eitherDelete = Either.left(new
1614 // when(toscaOperationFacade.deleteToscaComponent(resourceFree)).thenReturn(eitherDelete);
1616 // when(artifactManager.deleteAllComponentArtifactsIfNotOnGraph(artifacts)).thenReturn(StorageOperationStatus.OK);
1617 // List<String> deletedComponents = new ArrayList<>();
1618 // deletedComponents.add(resourceFree);
1619 // when(toscaOperationFacade.deleteMarkedElements(ComponentTypeEnum.RESOURCE)).thenReturn(Either.left(deletedComponents));
1621 // Either<List<String>, ResponseFormat> deleteMarkedResources =
1622 // bl.deleteMarkedComponents();
1623 // assertTrue(deleteMarkedResources.isLeft());
1624 // List<String> resourceIdList = deleteMarkedResources.left().value();
1625 // assertFalse(resourceIdList.isEmpty());
1626 // assertTrue(resourceIdList.contains(resourceFree));
1627 // assertFalse(resourceIdList.contains(resourceInUse));
1629 // Mockito.verify(artifactManager,
1630 // Mockito.times(1)).deleteAllComponentArtifactsIfNotOnGraph(artifacts);
1634 @SuppressWarnings("unchecked")
1636 public void testFindVfCsarArtifactsToHandle() {
1638 Class<ResourceBusinessLogic> targetClass = ResourceBusinessLogic.class;
1639 String methodName = "findVfCsarArtifactsToHandle";
1640 Resource resource = new Resource();
1641 String deploymentArtifactToUpdateFileName = "deploymentArtifactToUpdate.yaml";
1642 String deploymentArtifactToDeleteFileName = "deploymentArtifactToDelete.yaml";
1643 String deploymentArtifactToCreateFileName = "deploymentArtifactToCreate.yaml";
1645 String artifactInfoToUpdateFileName = "infoArtifactToUpdate.yaml";
1646 String artifactInfoToDeleteFileName = "infoArtifactToDelete.yaml";
1647 String artifactInfoToCreateFileName = "infoArtifactToCreate.yaml";
1649 byte[] oldPayloadData = "oldPayloadData".getBytes();
1650 byte[] newPayloadData = "newPayloadData".getBytes();
1651 Map<String, ArtifactDefinition> deploymentArtifacts = new HashMap<>();
1653 ArtifactDefinition deploymentArtifactToUpdate = new ArtifactDefinition();
1654 deploymentArtifactToUpdate.setMandatory(false);
1655 deploymentArtifactToUpdate.setArtifactName(deploymentArtifactToUpdateFileName);
1656 deploymentArtifactToUpdate.setArtifactType("SNMP_POLL");
1657 deploymentArtifactToUpdate.setPayload(oldPayloadData);
1658 deploymentArtifactToUpdate
1659 .setArtifactChecksum(GeneralUtility.calculateMD5Base64EncodedByByteArray(oldPayloadData));
1661 ArtifactDefinition deploymentArtifactToDelete = new ArtifactDefinition();
1662 deploymentArtifactToDelete.setMandatory(false);
1663 deploymentArtifactToDelete.setArtifactName(deploymentArtifactToDeleteFileName);
1664 deploymentArtifactToDelete.setArtifactType("SNMP_TRAP");
1665 deploymentArtifactToDelete.setPayload(oldPayloadData);
1666 deploymentArtifactToDelete
1667 .setArtifactChecksum(GeneralUtility.calculateMD5Base64EncodedByByteArray(oldPayloadData));
1669 ArtifactDefinition deploymentArtifactToIgnore = new ArtifactDefinition();
1671 deploymentArtifacts.put(ValidationUtils.normalizeArtifactLabel(deploymentArtifactToUpdate.getArtifactName()),
1672 deploymentArtifactToUpdate);
1673 deploymentArtifacts.put(ValidationUtils.normalizeArtifactLabel(deploymentArtifactToDelete.getArtifactName()),
1674 deploymentArtifactToDelete);
1675 deploymentArtifacts.put("ignore", deploymentArtifactToIgnore);
1677 Map<String, ArtifactDefinition> artifacts = new HashMap<>();
1679 ArtifactDefinition artifactToUpdate = new ArtifactDefinition();
1680 artifactToUpdate.setMandatory(false);
1681 artifactToUpdate.setArtifactName(artifactInfoToUpdateFileName);
1682 artifactToUpdate.setArtifactType("SNMP_POLL");
1683 artifactToUpdate.setPayload(oldPayloadData);
1684 artifactToUpdate.setArtifactChecksum(GeneralUtility.calculateMD5Base64EncodedByByteArray(oldPayloadData));
1686 ArtifactDefinition artifactToDelete = new ArtifactDefinition();
1687 artifactToDelete.setMandatory(false);
1688 artifactToDelete.setArtifactName(artifactInfoToDeleteFileName);
1689 artifactToDelete.setArtifactType("SNMP_TRAP");
1690 artifactToDelete.setPayload(oldPayloadData);
1691 artifactToDelete.setArtifactChecksum(GeneralUtility.calculateMD5Base64EncodedByByteArray(oldPayloadData));
1693 ArtifactDefinition artifactToIgnore = new ArtifactDefinition();
1695 artifacts.put(ValidationUtils.normalizeArtifactLabel(artifactToUpdate.getArtifactName()), artifactToUpdate);
1696 artifacts.put(ValidationUtils.normalizeArtifactLabel(artifactToDelete.getArtifactName()), artifactToDelete);
1697 artifacts.put("ignore", artifactToIgnore);
1699 resource.setDeploymentArtifacts(deploymentArtifacts);
1700 resource.setArtifacts(artifacts);
1702 List<NonMetaArtifactInfo> artifactPathAndNameList = new ArrayList<>();
1703 NonMetaArtifactInfo deploymentArtifactInfoToUpdate = new NonMetaArtifactInfo(
1704 deploymentArtifactToUpdate.getArtifactName(), null,
1705 ArtifactTypeEnum.findType(deploymentArtifactToUpdate.getArtifactType()),
1706 ArtifactGroupTypeEnum.DEPLOYMENT, newPayloadData, deploymentArtifactToUpdate.getArtifactName());
1708 NonMetaArtifactInfo informationalArtifactInfoToUpdate = new NonMetaArtifactInfo(
1709 artifactToUpdate.getArtifactName(), null, ArtifactTypeEnum.findType(artifactToUpdate.getArtifactType()),
1710 ArtifactGroupTypeEnum.DEPLOYMENT, newPayloadData, artifactToUpdate.getArtifactName());
1712 NonMetaArtifactInfo deploymentArtifactInfoToCreate = new NonMetaArtifactInfo(deploymentArtifactToCreateFileName,
1713 null, ArtifactTypeEnum.OTHER, ArtifactGroupTypeEnum.DEPLOYMENT, newPayloadData,
1714 deploymentArtifactToCreateFileName);
1716 NonMetaArtifactInfo informationalArtifactInfoToCreate = new NonMetaArtifactInfo(artifactInfoToCreateFileName,
1717 null, ArtifactTypeEnum.OTHER, ArtifactGroupTypeEnum.DEPLOYMENT, newPayloadData,
1718 artifactInfoToCreateFileName);
1720 artifactPathAndNameList.add(deploymentArtifactInfoToUpdate);
1721 artifactPathAndNameList.add(informationalArtifactInfoToUpdate);
1722 artifactPathAndNameList.add(deploymentArtifactInfoToCreate);
1723 artifactPathAndNameList.add(informationalArtifactInfoToCreate);
1725 Object[] argObjects = { resource, artifactPathAndNameList, user };
1726 Class[] argClasses = { Resource.class, List.class, User.class };
1728 Method method = targetClass.getDeclaredMethod(methodName, argClasses);
1729 method.setAccessible(true);
1730 Either<EnumMap<ArtifactOperationEnum, List<NonMetaArtifactInfo>>, ResponseFormat> findVfCsarArtifactsToHandleRes = (Either<EnumMap<ArtifactOperationEnum, List<NonMetaArtifactInfo>>, ResponseFormat>) method
1731 .invoke(bl, argObjects);
1732 assertTrue(findVfCsarArtifactsToHandleRes.isLeft());
1733 EnumMap<ArtifactOperationEnum, List<NonMetaArtifactInfo>> foundVfArtifacts = findVfCsarArtifactsToHandleRes
1735 assertTrue(foundVfArtifacts.get(ArtifactOperationEnum.Create).size() == 2);
1736 assertTrue(foundVfArtifacts.get(ArtifactOperationEnum.Update).size() == 2);
1737 assertTrue(foundVfArtifacts.get(ArtifactOperationEnum.Create).size() == 2);
1739 } catch (Exception e) {
1740 e.printStackTrace();
1744 @SuppressWarnings("rawtypes")
1746 public void testBuildNestedVfcToscaNamespace() {
1748 Class<ResourceBusinessLogic> targetClass = ResourceBusinessLogic.class;
1749 String methodName = "buildNestedVfcToscaNamespace";
1750 String nodeTypeFullName = "org.openecomp.resource.abstract.nodes.heat.FEAdd_On_Module_vLBAgentTemplate";
1751 String expectedNestedVfcToscaNamespace = "org.openecomp.resource.vfc.nodes.heat.FEAdd_On_Module_vLBAgentTemplate";
1752 Object[] argObjects = { nodeTypeFullName };
1753 Class[] argClasses = { String.class };
1755 Method method = targetClass.getDeclaredMethod(methodName, argClasses);
1756 method.setAccessible(true);
1757 String actualNestedVfcToscaNamespace = (String) method.invoke(bl, argObjects);
1758 assertTrue(!actualNestedVfcToscaNamespace.isEmpty());
1759 assertTrue(actualNestedVfcToscaNamespace.equals(expectedNestedVfcToscaNamespace));
1761 } catch (Exception e) {
1762 e.printStackTrace();
1766 @SuppressWarnings("rawtypes")
1768 public void testBuildNestedVfcToscaResourceName() {
1770 Class<ResourceBusinessLogic> targetClass = ResourceBusinessLogic.class;
1771 String methodName = "buildNestedVfcToscaResourceName";
1772 String vfResourceName = "vfname";
1773 String nodeTypeFullName = "org.openecomp.resource.abstract.nodes.heat.FEAdd_On_Module_vLBAgentTemplate";
1774 String expectedNestedVfcToscaResourceName = "org.openecomp.resource.vfc.vfname.abstract.nodes.heat.FEAdd_On_Module_vLBAgentTemplate";
1775 Object[] argObjects = { vfResourceName, nodeTypeFullName };
1776 Class[] argClasses = { String.class, String.class };
1778 Method method = targetClass.getDeclaredMethod(methodName, argClasses);
1779 method.setAccessible(true);
1780 String actualNestedVfcToscaResourceName = (String) method.invoke(bl, argObjects);
1781 assertTrue(!actualNestedVfcToscaResourceName.isEmpty());
1782 assertTrue(actualNestedVfcToscaResourceName.equals(expectedNestedVfcToscaResourceName));
1784 } catch (Exception e) {
1785 e.printStackTrace();
1789 @SuppressWarnings("rawtypes")
1791 public void testBuildNestedSubstituteYamlName() {
1793 Class<ResourceBusinessLogic> targetClass = ResourceBusinessLogic.class;
1794 String methodName = "buildNestedSubstituteYamlName";
1795 String nodeTypeFullName = "org.openecomp.resource.abstract.nodes.heat.FEAdd_On_Module_vLBAgentTemplate";
1796 String expectedNestedSubstituteYamlName = "Definitions/FEAdd_On_Module_vLBAgentTemplateServiceTemplate.yaml";
1797 Object[] argObjects = { nodeTypeFullName };
1798 Class[] argClasses = { String.class };
1800 Method method = targetClass.getDeclaredMethod(methodName, argClasses);
1801 method.setAccessible(true);
1802 String actualNestedSubstituteYamlName = (String) method.invoke(bl, argObjects);
1803 assertTrue(!actualNestedSubstituteYamlName.isEmpty());
1804 assertTrue(actualNestedSubstituteYamlName.equals(expectedNestedSubstituteYamlName));
1806 } catch (Exception e) {
1807 e.printStackTrace();
1812 public void testVFGeneratedInputs() {
1814 Resource resource = createVF();
1815 List<InputDefinition> inputs = resource.getInputs();
1816 assertTrue(8 == inputs.size());
1817 for (InputDefinition input : inputs) {
1818 assertNotNull(input.getOwnerId());
1820 assertTrue(resource.getDerivedFromGenericType().equals(genericVF.getToscaResourceName()));
1821 assertTrue(resource.getDerivedFromGenericVersion().equals(genericVF.getVersion()));
1825 public void testVFUpdateGenericInputsToLatestOnCheckout() {
1827 // create a VF that is derived from generic version 1.0
1828 Resource resource = createVF();
1829 // create a new generic version without properties
1830 genericVF.setVersion("2.0");
1831 genericVF.setProperties(null);
1832 String currentDerivedFromVersion = resource.getDerivedFromGenericVersion();
1833 List<InputDefinition> currentInputs = resource.getInputs();
1834 // verify previous inputs ownerId fields exist - user may not delete
1836 assertTrue(8 == currentInputs.stream().filter(p -> null != p.getOwnerId()).collect(Collectors.toList()).size());
1837 Either<Boolean, ResponseFormat> upgradeToLatestGeneric = bl.shouldUpgradeToLatestGeneric(resource);
1839 assertTrue(upgradeToLatestGeneric.isLeft());
1840 // verify update required and valid
1841 assertTrue(upgradeToLatestGeneric.left().value());
1842 // verify version was upgraded
1843 assertFalse(resource.getDerivedFromGenericVersion().equals(currentDerivedFromVersion));
1844 // verify inputs were not deleted
1845 assertTrue(8 == resource.getInputs().size());
1846 // verify inputs ownerId fields were removed - user may delete/edit
1848 assertTrue(8 == resource.getInputs().stream().filter(p -> null == p.getOwnerId()).collect(Collectors.toList())
1853 public void testVFUpdateGenericInputsToLatestOnCheckoutNotPerformed() {
1855 // create a VF that is derived from generic version 1.0
1856 Resource resource = createVF();
1858 // add an input to the VF
1859 PropertyDefinition newProp = new PropertyDefinition();
1860 newProp.setType("integer");
1861 newProp.setName("newProp");
1862 resource.getInputs().add(new InputDefinition(newProp));
1864 // create a new generic version with a new property which has the same
1865 // name as a user defined input on the VF with a different type
1866 genericVF.setVersion("2.0");
1867 newProp.setType("string");
1868 genericVF.setProperties(new ArrayList<PropertyDefinition>());
1869 genericVF.getProperties().add(newProp);
1871 String currentDerivedFromVersion = resource.getDerivedFromGenericVersion();
1872 assertTrue(8 == resource.getInputs().stream().filter(p -> null != p.getOwnerId()).collect(Collectors.toList())
1874 Either<Boolean, ResponseFormat> upgradeToLatestGeneric = bl.shouldUpgradeToLatestGeneric(resource);
1876 assertTrue(upgradeToLatestGeneric.isLeft());
1877 // verify update is invalid an void
1878 assertFalse(upgradeToLatestGeneric.left().value());
1879 // verify version was not upgraded
1880 assertTrue(resource.getDerivedFromGenericVersion().equals(currentDerivedFromVersion));
1881 // verify inputs were not removed
1882 assertTrue(9 == resource.getInputs().size());
1883 // verify user defined input exists
1884 assertTrue(1 == resource.getInputs().stream().filter(p -> null == p.getOwnerId()).collect(Collectors.toList())
1886 assertTrue(resource.getInputs().stream().filter(p -> null == p.getOwnerId()).findAny().get().getType()
1887 .equals("integer"));
1891 public void testPNFGeneratedInputsNoGeneratedInformationalArtifacts() {
1893 Resource resource = createPNF();
1894 List<InputDefinition> inputs = resource.getInputs();
1895 assertTrue(8 == inputs.size());
1896 for (InputDefinition input : inputs) {
1897 assertNotNull(input.getOwnerId());
1899 assertTrue(resource.getDerivedFromGenericType().equals(genericPNF.getToscaResourceName()));
1900 assertTrue(resource.getDerivedFromGenericVersion().equals(genericPNF.getVersion()));
1901 assertTrue(0 == resource.getArtifacts().size());
1904 private Resource createVF() {
1906 genericVF = setupGenericTypeMock(GENERIC_VF_NAME);
1907 when(toscaOperationFacade.getLatestCertifiedNodeTypeByToscaResourceName(GENERIC_VF_NAME))
1908 .thenReturn(Either.left(genericVF));
1909 Resource resource = createResourceObject(true);
1910 resource.setDerivedFrom(null);
1911 resource.setResourceType(ResourceTypeEnum.VF);
1912 when(toscaOperationFacade.createToscaComponent(resource)).thenReturn(Either.left(resource));
1913 Either<Resource, ResponseFormat> createResponse = bl.createResource(resource,
1914 AuditingActionEnum.CREATE_RESOURCE, user, null, null);
1915 assertTrue(createResponse.isLeft());
1916 return createResponse.left().value();
1919 private Resource createPNF() {
1921 genericPNF = setupGenericTypeMock(GENERIC_PNF_NAME);
1922 when(toscaOperationFacade.getLatestCertifiedNodeTypeByToscaResourceName(GENERIC_PNF_NAME))
1923 .thenReturn(Either.left(genericPNF));
1924 Resource resource = createResourceObject(true);
1925 resource.setDerivedFrom(null);
1926 resource.setResourceType(ResourceTypeEnum.PNF);
1927 when(toscaOperationFacade.createToscaComponent(resource)).thenReturn(Either.left(resource));
1928 Either<Resource, ResponseFormat> createResponse = bl.createResource(resource,
1929 AuditingActionEnum.CREATE_RESOURCE, user, null, null);
1930 assertTrue(createResponse.isLeft());
1931 return createResponse.left().value();
1934 private Resource setupGenericTypeMock(String toscaName) {
1936 Resource genericType = createResourceObject(true);
1937 genericType.setVersion("1.0");
1938 genericType.setToscaResourceName(toscaName);
1939 String[] propNames = { "nf_function", "nf_role", "nf_naming_code", "nf_type", "nf_naming",
1940 "availability_zone_max_count", "min_instances", "max_instances" };
1941 String[] propTypes = { "string", "string", "string", "string", "org.openecomp.datatypes.Naming", "integer",
1942 "integer", "integer" };
1943 List<PropertyDefinition> genericProps = new ArrayList<>();
1944 for (int i = 0; i < 8; ++i) {
1945 PropertyDefinition prop = new PropertyDefinition();
1946 prop.setName(propNames[i]);
1947 prop.setType(propTypes[i]);
1948 genericProps.add(prop);
1950 genericType.setProperties(genericProps);
1954 private ResourceBusinessLogic createTestSubject() {
1955 return new ResourceBusinessLogic();
1959 public void testGetCsarOperation() throws Exception {
1960 ResourceBusinessLogic testSubject;
1961 CsarOperation result;
1964 testSubject = createTestSubject();
1965 result = testSubject.getCsarOperation();
1969 public void testSetCsarOperation() throws Exception {
1970 ResourceBusinessLogic testSubject;
1971 CsarOperation csarOperation = null;
1974 testSubject = createTestSubject();
1975 testSubject.setCsarOperation(csarOperation);
1980 public void testGetLifecycleBusinessLogic() throws Exception {
1981 ResourceBusinessLogic testSubject;
1982 LifecycleBusinessLogic result;
1985 testSubject = createTestSubject();
1986 result = testSubject.getLifecycleBusinessLogic();
1991 public void testSetLifecycleManager() throws Exception {
1992 ResourceBusinessLogic testSubject;
1993 LifecycleBusinessLogic lifecycleBusinessLogic = null;
1996 testSubject = createTestSubject();
1997 testSubject.setLifecycleManager(lifecycleBusinessLogic);
2002 public void testGetElementDao() throws Exception {
2003 ResourceBusinessLogic testSubject;
2004 IElementOperation result;
2007 testSubject = createTestSubject();
2008 result = testSubject.getElementDao();
2013 public void testSetElementDao() throws Exception {
2014 ResourceBusinessLogic testSubject;
2015 IElementOperation elementDao = null;
2018 testSubject = createTestSubject();
2019 testSubject.setElementDao(elementDao);
2024 public void testGetUserAdmin() throws Exception {
2025 ResourceBusinessLogic testSubject;
2026 IUserBusinessLogic result;
2029 testSubject = createTestSubject();
2030 result = testSubject.getUserAdmin();
2035 public void testSetUserAdmin() throws Exception {
2036 ResourceBusinessLogic testSubject;
2037 UserBusinessLogic userAdmin = null;
2040 testSubject = createTestSubject();
2041 testSubject.setUserAdmin(userAdmin);
2046 public void testGetComponentsUtils() throws Exception {
2047 ResourceBusinessLogic testSubject;
2048 ComponentsUtils result;
2051 testSubject = createTestSubject();
2052 result = testSubject.getComponentsUtils();
2057 public void testSetComponentsUtils() throws Exception {
2058 ResourceBusinessLogic testSubject;
2059 ComponentsUtils componentsUtils = null;
2062 testSubject = createTestSubject();
2063 testSubject.setComponentsUtils(componentsUtils);
2068 public void testGetArtifactsManager() throws Exception {
2069 ResourceBusinessLogic testSubject;
2070 ArtifactsBusinessLogic result;
2073 testSubject = createTestSubject();
2074 result = testSubject.getArtifactsManager();
2079 public void testSetArtifactsManager() throws Exception {
2080 ResourceBusinessLogic testSubject;
2081 ArtifactsBusinessLogic artifactsManager = null;
2084 testSubject = createTestSubject();
2085 testSubject.setArtifactsManager(artifactsManager);
2090 public void testSetPropertyOperation() throws Exception {
2091 ResourceBusinessLogic testSubject;
2092 IPropertyOperation propertyOperation = null;
2095 testSubject = createTestSubject();
2096 testSubject.setPropertyOperation(propertyOperation);
2101 public void testGetApplicationDataTypeCache() throws Exception {
2102 ResourceBusinessLogic testSubject;
2103 ApplicationDataTypeCache result;
2106 testSubject = createTestSubject();
2107 result = testSubject.getApplicationDataTypeCache();
2112 public void testSetApplicationDataTypeCache() throws Exception {
2113 ResourceBusinessLogic testSubject;
2114 ApplicationDataTypeCache applicationDataTypeCache = null;
2117 testSubject = createTestSubject();
2118 testSubject.setApplicationDataTypeCache(applicationDataTypeCache);
2122 public void testSetDeploymentArtifactsPlaceHolder() throws Exception {
2123 ResourceBusinessLogic testSubject;
2124 Component component = new Resource() {
2129 testSubject = createTestSubject();
2130 testSubject.setDeploymentArtifactsPlaceHolder(component, user);
2136 public void testValidateVendorReleaseName_1() throws Exception {
2137 ResourceBusinessLogic testSubject;
2138 String vendorRelease = "";
2139 Either<Boolean, ResponseFormat> result;
2142 testSubject = createTestSubject();
2143 vendorRelease = null;
2144 result = testSubject.validateVendorReleaseName(vendorRelease);
2145 Assert.assertEquals(false, result.left().value());
2155 public void testGetCapabilityTypeOperation() throws Exception {
2156 ResourceBusinessLogic testSubject;
2157 ICapabilityTypeOperation result;
2160 testSubject = createTestSubject();
2161 result = testSubject.getCapabilityTypeOperation();
2166 public void testSetCapabilityTypeOperation() throws Exception {
2167 ResourceBusinessLogic testSubject;
2168 ICapabilityTypeOperation capabilityTypeOperation = null;
2171 testSubject = createTestSubject();
2172 testSubject.setCapabilityTypeOperation(capabilityTypeOperation);
2177 public void testValidatePropertiesDefaultValues() throws Exception {
2178 ResourceBusinessLogic testSubject;
2179 Resource resource = new Resource();
2180 Either<Boolean, ResponseFormat> result;
2183 testSubject = createTestSubject();
2184 result = testSubject.validatePropertiesDefaultValues(resource);
2189 public void testGetComponentInstanceBL() throws Exception {
2190 ResourceBusinessLogic testSubject;
2191 ComponentInstanceBusinessLogic result;
2194 testSubject = createTestSubject();
2195 result = testSubject.getComponentInstanceBL();
2201 public void testGetComponentInstancesFilteredByPropertiesAndInputs() throws Exception {
2202 ResourceBusinessLogic testSubject;
2203 String componentId = "";
2204 ComponentTypeEnum componentTypeEnum = null;
2206 String searchText = "";
2207 Either<List<ComponentInstance>, ResponseFormat> result;
2210 testSubject = createTestSubject();
2211 result = testSubject.getComponentInstancesFilteredByPropertiesAndInputs(componentId, componentTypeEnum, userId,
2218 public void testGetCacheManagerOperation() throws Exception {
2219 ResourceBusinessLogic testSubject;
2220 ICacheMangerOperation result;
2223 testSubject = createTestSubject();
2224 result = testSubject.getCacheManagerOperation();
2229 public void testSetCacheManagerOperation() throws Exception {
2230 ResourceBusinessLogic testSubject;
2231 ICacheMangerOperation cacheManagerOperation = null;
2234 testSubject = createTestSubject();
2235 testSubject.setCacheManagerOperation(cacheManagerOperation);
2240 public void testGetElementDao_1() throws Exception {
2241 ResourceBusinessLogic testSubject;IElementOperation result;
2244 testSubject=createTestSubject();result=testSubject.getElementDao();
2249 public void testGetAllCertifiedResources() throws Exception {
2250 ResourceBusinessLogic testSubject;boolean getAbstract = false;
2251 HighestFilterEnum highestFilter = null;
2253 Either<List<Resource>,ResponseFormat> result;
2260 public void testValidateResourceNameExists() throws Exception {
2261 ResourceBusinessLogic testSubject;String resourceName = "";
2262 ResourceTypeEnum resourceTypeEnum = null;
2264 Either<Map<String,Boolean>,ResponseFormat> result;
2271 public void testCreateResource() throws Exception {
2272 ResourceBusinessLogic testSubject;Resource resource = null;
2273 AuditingActionEnum auditingAction = null;
2275 Map<String,byte[]> csarUIPayload = null;
2276 String payloadName = "";
2277 Either<Resource,ResponseFormat> result;
2280 testSubject=createTestSubject();payloadName = null;
2283 testSubject=createTestSubject();payloadName = "";
2288 public void testValidateAndUpdateResourceFromCsar() throws Exception {
2289 ResourceBusinessLogic testSubject;Resource resource = null;
2291 Map<String,byte[]> csarUIPayload = null;
2292 String payloadName = "";
2293 String resourceUniqueId = "";
2294 Either<Resource,ResponseFormat> result;
2297 testSubject=createTestSubject();payloadName = null;
2300 testSubject=createTestSubject();payloadName = "";
2314 public void testCreateResourceFromCsar() throws Exception {
2315 ResourceBusinessLogic testSubject;Resource resource = null;
2317 Either<Map<String,byte[]>,StorageOperationStatus> csarUIPayload = null;
2318 String csarUUID = "";
2319 Either<Resource,ResponseFormat> result;
2322 testSubject=createTestSubject();csarUIPayload = null;
2332 public void testCreateResourcesFromYamlNodeTypesList() throws Exception {
2333 ResourceBusinessLogic testSubject;String yamlName = "";
2334 Resource resource = null;
2335 Map<String,Object> mappedToscaTemplate = null;
2336 boolean needLock = false;
2337 Map<String,EnumMap<ArtifactOperationEnum,List<ArtifactDefinition>>> nodeTypesArtifactsToHandle = null;
2338 List<ArtifactDefinition> nodeTypesNewCreatedArtifacts = null;
2339 Map<String,NodeTypeInfo> nodeTypesInfo = null;
2340 CsarInfo csarInfo = null;
2341 Either<Map<String,Resource>,ResponseFormat> result;
2352 public void testValidateResourceCreationFromNodeType() throws Exception {
2353 ResourceBusinessLogic testSubject;Resource resource = null;
2354 User creator = null;
2355 Either<Boolean,ResponseFormat> result;
2362 public void testCreateResourceFromNodeType() throws Exception {
2363 ResourceBusinessLogic testSubject;String nodeTypeYaml = "";
2364 UploadResourceInfo resourceMetaData = null;
2365 User creator = null;
2366 boolean isInTransaction = false;
2367 boolean needLock = false;
2368 Map<ArtifactOperationEnum,List<ArtifactDefinition>> nodeTypeArtifactsToHandle = null;
2369 List<ArtifactDefinition> nodeTypesNewCreatedArtifacts = null;
2370 boolean forceCertificationAllowed = false;
2371 CsarInfo csarInfo = null;
2372 Either<ImmutablePair<Resource,ActionStatus>,ResponseFormat> result;