2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.sdc.be.components.impl;
23 import fj.data.Either;
24 import mockit.Deencapsulation;
25 import org.apache.commons.lang3.tuple.ImmutablePair;
26 import org.junit.Assert;
27 import org.junit.Before;
28 import org.junit.Ignore;
29 import org.junit.Test;
30 import org.mockito.InjectMocks;
31 import org.mockito.Mockito;
32 import org.mockito.MockitoAnnotations;
33 import org.openecomp.sdc.ElementOperationMock;
34 import org.openecomp.sdc.be.auditing.impl.AuditingManager;
35 import org.openecomp.sdc.be.components.InterfaceOperationTestUtils;
36 import org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic.ArtifactOperationEnum;
37 import org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic.ArtifactOperationInfo;
38 import org.openecomp.sdc.be.components.impl.generic.GenericTypeBusinessLogic;
39 import org.openecomp.sdc.be.components.lifecycle.LifecycleBusinessLogic;
40 import org.openecomp.sdc.be.components.lifecycle.LifecycleChangeInfoWithAction;
41 import org.openecomp.sdc.be.components.validation.UserValidations;
42 import org.openecomp.sdc.be.config.ConfigurationManager;
43 import org.openecomp.sdc.be.dao.api.ActionStatus;
44 import org.openecomp.sdc.be.dao.jsongraph.TitanDao;
45 import org.openecomp.sdc.be.dao.titan.TitanOperationStatus;
46 import org.openecomp.sdc.be.datamodel.api.HighestFilterEnum;
47 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
48 import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
49 import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
50 import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
51 import org.openecomp.sdc.be.impl.ComponentsUtils;
52 import org.openecomp.sdc.be.impl.WebAppContextWrapper;
53 import org.openecomp.sdc.be.model.ArtifactDefinition;
54 import org.openecomp.sdc.be.model.CapabilityDefinition;
55 import org.openecomp.sdc.be.model.CapabilityTypeDefinition;
56 import org.openecomp.sdc.be.model.Component;
57 import org.openecomp.sdc.be.model.ComponentInstance;
58 import org.openecomp.sdc.be.model.ComponentInstanceInput;
59 import org.openecomp.sdc.be.model.ComponentInstanceProperty;
60 import org.openecomp.sdc.be.model.CsarInfo;
61 import org.openecomp.sdc.be.model.DataTypeDefinition;
62 import org.openecomp.sdc.be.model.GroupDefinition;
63 import org.openecomp.sdc.be.model.InputDefinition;
64 import org.openecomp.sdc.be.model.InterfaceDefinition;
65 import org.openecomp.sdc.be.model.LifeCycleTransitionEnum;
66 import org.openecomp.sdc.be.model.LifecycleStateEnum;
67 import org.openecomp.sdc.be.model.NodeTypeInfo;
68 import org.openecomp.sdc.be.model.PropertyDefinition;
69 import org.openecomp.sdc.be.model.RequirementDefinition;
70 import org.openecomp.sdc.be.model.Resource;
71 import org.openecomp.sdc.be.model.UploadCapInfo;
72 import org.openecomp.sdc.be.model.UploadComponentInstanceInfo;
73 import org.openecomp.sdc.be.model.UploadPropInfo;
74 import org.openecomp.sdc.be.model.UploadReqInfo;
75 import org.openecomp.sdc.be.model.UploadResourceInfo;
76 import org.openecomp.sdc.be.model.User;
77 import org.openecomp.sdc.be.model.cache.ApplicationDataTypeCache;
78 import org.openecomp.sdc.be.model.category.CategoryDefinition;
79 import org.openecomp.sdc.be.model.category.SubCategoryDefinition;
80 import org.openecomp.sdc.be.model.jsontitan.operations.InterfaceOperation;
81 import org.openecomp.sdc.be.model.jsontitan.operations.NodeTemplateOperation;
82 import org.openecomp.sdc.be.model.jsontitan.operations.NodeTypeOperation;
83 import org.openecomp.sdc.be.model.jsontitan.operations.TopologyTemplateOperation;
84 import org.openecomp.sdc.be.model.jsontitan.operations.ToscaOperationFacade;
85 import org.openecomp.sdc.be.model.operations.api.ICacheMangerOperation;
86 import org.openecomp.sdc.be.model.operations.api.ICapabilityTypeOperation;
87 import org.openecomp.sdc.be.model.operations.api.IElementOperation;
88 import org.openecomp.sdc.be.model.operations.api.IInterfaceLifecycleOperation;
89 import org.openecomp.sdc.be.model.operations.api.IPropertyOperation;
90 import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
91 import org.openecomp.sdc.be.model.operations.impl.CacheMangerOperation;
92 import org.openecomp.sdc.be.model.operations.impl.CsarOperation;
93 import org.openecomp.sdc.be.model.operations.impl.GraphLockOperation;
94 import org.openecomp.sdc.be.model.tosca.ToscaPropertyType;
95 import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
96 import org.openecomp.sdc.be.tosca.CsarUtils.NonMetaArtifactInfo;
97 import org.openecomp.sdc.be.user.IUserBusinessLogic;
98 import org.openecomp.sdc.be.user.Role;
99 import org.openecomp.sdc.be.user.UserBusinessLogic;
100 import org.openecomp.sdc.common.api.ArtifactGroupTypeEnum;
101 import org.openecomp.sdc.common.api.ArtifactTypeEnum;
102 import org.openecomp.sdc.common.api.ConfigurationSource;
103 import org.openecomp.sdc.common.api.Constants;
104 import org.openecomp.sdc.common.datastructure.Wrapper;
105 import org.openecomp.sdc.common.impl.ExternalConfiguration;
106 import org.openecomp.sdc.common.impl.FSConfigurationSource;
107 import org.openecomp.sdc.common.util.GeneralUtility;
108 import org.openecomp.sdc.common.util.ValidationUtils;
109 import org.openecomp.sdc.exception.ResponseFormat;
110 import org.slf4j.Logger;
111 import org.slf4j.LoggerFactory;
112 import org.springframework.web.context.WebApplicationContext;
114 import javax.servlet.ServletContext;
115 import java.lang.reflect.Method;
116 import java.util.ArrayList;
117 import java.util.Collection;
118 import java.util.EnumMap;
119 import java.util.HashMap;
120 import java.util.HashSet;
121 import java.util.List;
122 import java.util.Map;
123 import java.util.Set;
124 import java.util.regex.Pattern;
125 import java.util.stream.Collectors;
126 import java.util.stream.Stream;
128 import static org.junit.Assert.assertEquals;
129 import static org.junit.Assert.assertFalse;
130 import static org.junit.Assert.assertNotNull;
131 import static org.junit.Assert.assertTrue;
132 import static org.mockito.ArgumentMatchers.any;
133 import static org.mockito.ArgumentMatchers.anyObject;
134 import static org.mockito.ArgumentMatchers.anyString;
135 import static org.mockito.ArgumentMatchers.eq;
136 import static org.mockito.Mockito.when;
138 public class ResourceBusinessLogicTest implements InterfaceOperationTestUtils {
140 private static final Logger log = LoggerFactory.getLogger(ResourceBusinessLogicTest.class);
141 public static final String RESOURCE_CATEGORY = "Network Layer 2-3/Router";
142 public static final String RESOURCE_CATEGORY1 = "Network Layer 2-3";
143 public static final String RESOURCE_SUBCATEGORY = "Router";
145 public static final String UPDATED_CATEGORY = "Network Layer 2-3/Gateway";
146 public static final String UPDATED_SUBCATEGORY = "Gateway";
148 private String resourceId = "resourceId1";
149 private String operationId = "uniqueId1";
150 Resource resourceUpdate;
152 public static final String RESOURCE_NAME = "My-Resource_Name with space";
153 private static final String GENERIC_VF_NAME = "org.openecomp.resource.abstract.nodes.VF";
154 private static final String GENERIC_CR_NAME = "org.openecomp.resource.abstract.nodes.CR";
155 private static final String GENERIC_VFC_NAME = "org.openecomp.resource.abstract.nodes.VFC";
156 private static final String GENERIC_PNF_NAME = "org.openecomp.resource.abstract.nodes.PNF";
158 final ServletContext servletContext = Mockito.mock(ServletContext.class);
159 IElementOperation mockElementDao;
160 TitanDao mockTitanDao = Mockito.mock(TitanDao.class);
161 UserBusinessLogic mockUserAdmin = Mockito.mock(UserBusinessLogic.class);
162 ToscaOperationFacade toscaOperationFacade = Mockito.mock(ToscaOperationFacade.class);
163 NodeTypeOperation nodeTypeOperation = Mockito.mock(NodeTypeOperation.class);
164 NodeTemplateOperation nodeTemplateOperation = Mockito.mock(NodeTemplateOperation.class);
165 TopologyTemplateOperation topologyTemplateOperation = Mockito.mock(TopologyTemplateOperation.class);
166 final LifecycleBusinessLogic lifecycleBl = Mockito.mock(LifecycleBusinessLogic.class);
167 final ICapabilityTypeOperation capabilityTypeOperation = Mockito.mock(ICapabilityTypeOperation.class);
168 final IPropertyOperation propertyOperation = Mockito.mock(IPropertyOperation.class);
169 final ApplicationDataTypeCache applicationDataTypeCache = Mockito.mock(ApplicationDataTypeCache.class);
170 WebAppContextWrapper webAppContextWrapper = Mockito.mock(WebAppContextWrapper.class);
171 UserValidations userValidations = Mockito.mock(UserValidations.class);
172 WebApplicationContext webAppContext = Mockito.mock(WebApplicationContext.class);
173 IInterfaceLifecycleOperation interfaceTypeOperation = Mockito.mock(IInterfaceLifecycleOperation.class);
174 InterfaceOperation interfaceOperation = Mockito.mock(InterfaceOperation.class);
177 ResourceBusinessLogic bl = new ResourceBusinessLogic();
178 ResponseFormatManager responseManager = null;
179 GraphLockOperation graphLockOperation = Mockito.mock(GraphLockOperation.class);
181 Resource resourceResponse = null;
182 Resource genericVF = null;
183 Resource genericCR = null;
184 Resource genericVFC = null;
185 Resource genericPNF = null;
186 ComponentsUtils componentsUtils;
187 ArtifactsBusinessLogic artifactManager = new ArtifactsBusinessLogic();
188 CsarOperation csarOperation = Mockito.mock(CsarOperation.class);
189 Map<String, DataTypeDefinition> emptyDataTypes = new HashMap<String, DataTypeDefinition>();
190 private GenericTypeBusinessLogic genericTypeBusinessLogic = Mockito.mock(GenericTypeBusinessLogic.class);
191 CacheMangerOperation cacheManager = Mockito.mock(CacheMangerOperation.class);
193 public ResourceBusinessLogicTest() {
198 public void setup() {
199 MockitoAnnotations.initMocks(this);
200 Mockito.reset(propertyOperation);
202 ExternalConfiguration.setAppName("catalog-be");
204 // init Configuration
205 String appConfigDir = "src/test/resources/config/catalog-be";
206 ConfigurationSource configurationSource = new FSConfigurationSource(ExternalConfiguration.getChangeListener(),
208 ConfigurationManager configurationManager = new ConfigurationManager(configurationSource);
209 componentsUtils = new ComponentsUtils(Mockito.mock(AuditingManager.class));
212 mockElementDao = new ElementOperationMock();
214 // User data and management
216 user.setUserId("jh0003");
217 user.setFirstName("Jimmi");
218 user.setLastName("Hendrix");
219 user.setRole(Role.ADMIN.name());
221 Either<User, ActionStatus> eitherGetUser = Either.left(user);
222 when(mockUserAdmin.getUser("jh0003", false)).thenReturn(eitherGetUser);
223 when(userValidations.validateUserExists(eq(user.getUserId()), anyString(), eq(false)))
224 .thenReturn(Either.left(user));
225 when(userValidations.validateUserNotEmpty(eq(user), anyString())).thenReturn(Either.left(user));
226 // Servlet Context attributes
227 when(servletContext.getAttribute(Constants.CONFIGURATION_MANAGER_ATTR)).thenReturn(configurationManager);
228 when(servletContext.getAttribute(Constants.WEB_APPLICATION_CONTEXT_WRAPPER_ATTR))
229 .thenReturn(webAppContextWrapper);
230 when(webAppContextWrapper.getWebAppContext(servletContext)).thenReturn(webAppContext);
231 when(webAppContext.getBean(IElementOperation.class)).thenReturn(mockElementDao);
233 Either<Integer, StorageOperationStatus> eitherCountRoot = Either.left(1);
234 Either<Boolean, StorageOperationStatus> eitherFalse = Either.left(true);
235 when(toscaOperationFacade.validateComponentNameExists("Root", ResourceTypeEnum.VFC, ComponentTypeEnum.RESOURCE))
236 .thenReturn(eitherFalse);
238 Either<Boolean, StorageOperationStatus> eitherCountExist = Either.left(true);
239 when(toscaOperationFacade.validateComponentNameExists("alreadyExists", ResourceTypeEnum.VFC,
240 ComponentTypeEnum.RESOURCE)).thenReturn(eitherCountExist);
242 Either<Boolean, StorageOperationStatus> eitherCount = Either.left(false);
243 when(toscaOperationFacade.validateComponentNameExists(eq(RESOURCE_NAME), any(ResourceTypeEnum.class),
244 eq(ComponentTypeEnum.RESOURCE))).thenReturn(eitherCount);
245 when(interfaceOperation.updateInterface(anyString(), anyObject()))
246 .thenReturn(Either.left(mockInterfaceDefinitionToReturn(RESOURCE_NAME)));
247 Either<Boolean, StorageOperationStatus> validateDerivedExists = Either.left(true);
248 when(toscaOperationFacade.validateToscaResourceNameExists("Root")).thenReturn(validateDerivedExists);
250 Either<Boolean, StorageOperationStatus> validateDerivedNotExists = Either.left(false);
251 when(toscaOperationFacade.validateToscaResourceNameExists("kuku")).thenReturn(validateDerivedNotExists);
252 when(graphLockOperation.lockComponent(Mockito.anyString(), eq(NodeTypeEnum.Resource)))
253 .thenReturn(StorageOperationStatus.OK);
254 when(graphLockOperation.lockComponentByName(Mockito.anyString(), eq(NodeTypeEnum.Resource)))
255 .thenReturn(StorageOperationStatus.OK);
258 resourceResponse = createResourceObject(true);
259 Either<Resource, StorageOperationStatus> eitherCreate = Either.left(resourceResponse);
260 Either<Integer, StorageOperationStatus> eitherValidate = Either.left(null);
261 when(toscaOperationFacade.createToscaComponent(any(Resource.class))).thenReturn(eitherCreate);
262 when(toscaOperationFacade.validateCsarUuidUniqueness(Mockito.anyString())).thenReturn(eitherValidate);
263 Map<String, DataTypeDefinition> emptyDataTypes = new HashMap<String, DataTypeDefinition>();
264 when(applicationDataTypeCache.getAll()).thenReturn(Either.left(emptyDataTypes));
265 when(mockTitanDao.commit()).thenReturn(TitanOperationStatus.OK);
268 artifactManager.setNodeTemplateOperation(nodeTemplateOperation);
269 bl = new ResourceBusinessLogic();
270 bl.setElementDao(mockElementDao);
271 bl.setUserAdmin(mockUserAdmin);
272 bl.setCapabilityTypeOperation(capabilityTypeOperation);
273 bl.setComponentsUtils(componentsUtils);
274 bl.setLifecycleManager(lifecycleBl);
275 bl.setGraphLockOperation(graphLockOperation);
276 bl.setArtifactsManager(artifactManager);
277 bl.setPropertyOperation(propertyOperation);
278 bl.setTitanGenericDao(mockTitanDao);
279 bl.setApplicationDataTypeCache(applicationDataTypeCache);
280 bl.setCsarOperation(csarOperation);
281 bl.setCacheManagerOperation(cacheManager);
282 bl.setGenericTypeBusinessLogic(genericTypeBusinessLogic);
283 toscaOperationFacade.setNodeTypeOperation(nodeTypeOperation);
284 toscaOperationFacade.setTopologyTemplateOperation(topologyTemplateOperation);
285 bl.setToscaOperationFacade(toscaOperationFacade);
286 bl.setUserValidations(userValidations);
287 bl.setInterfaceTypeOperation(interfaceTypeOperation);
288 bl.setInterfaceOperation(interfaceOperation);
290 Resource resourceCsar = createResourceObjectCsar(true);
291 setCanWorkOnResource(resourceCsar);
292 Either<Component, StorageOperationStatus> oldResourceRes = Either.left(resourceCsar);
293 when(toscaOperationFacade.getToscaFullElement(resourceCsar.getUniqueId())).thenReturn(oldResourceRes);
294 responseManager = ResponseFormatManager.getInstance();
298 private Resource createResourceObject(boolean afterCreate) {
299 Resource resource = new Resource();
300 resource.setName(RESOURCE_NAME);
301 resource.addCategory(RESOURCE_CATEGORY1, RESOURCE_SUBCATEGORY);
302 resource.setDescription("My short description");
303 List<String> tgs = new ArrayList<String>();
305 tgs.add(resource.getName());
306 resource.setTags(tgs);
307 List<String> template = new ArrayList<String>();
308 template.add("Root");
309 resource.setDerivedFrom(template);
310 resource.setVendorName("Motorola");
311 resource.setVendorRelease("1.0.0");
312 resource.setContactId("ya5467");
313 resource.setIcon("MyIcon");
316 resource.setName(resource.getName());
317 resource.setVersion("0.1");
318 resource.setUniqueId(resource.getName().toLowerCase() + ":" + resource.getVersion());
319 resource.setCreatorUserId(user.getUserId());
320 resource.setCreatorFullName(user.getFirstName() + " " + user.getLastName());
321 resource.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
326 private Resource createResourceObjectCsar(boolean afterCreate) {
327 Resource resource = new Resource();
328 resource.setName(RESOURCE_NAME);
329 resource.addCategory(RESOURCE_CATEGORY1, RESOURCE_SUBCATEGORY);
330 resource.setDescription("My short description");
331 List<String> tgs = new ArrayList<String>();
333 tgs.add(resource.getName());
334 resource.setTags(tgs);
335 List<String> template = new ArrayList<String>();
336 template.add("Root");
337 resource.setDerivedFrom(template);
338 resource.setVendorName("Motorola");
339 resource.setVendorRelease("1.0.0");
340 resource.setResourceVendorModelNumber("");
341 resource.setContactId("ya5467");
342 resource.setIcon("MyIcon");
343 resource.setCsarUUID("valid_vf.csar");
344 resource.setCsarVersion("1");
347 resource.setName(resource.getName());
348 resource.setVersion("0.1");
350 resource.setUniqueId(resource.getName().toLowerCase() + ":" + resource.getVersion());
351 resource.setCreatorUserId(user.getUserId());
352 resource.setCreatorFullName(user.getFirstName() + " " + user.getLastName());
353 resource.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
358 private Resource setCanWorkOnResource(Resource resource) {
359 resource.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
360 resource.setLastUpdaterUserId(user.getUserId());
365 public void testHappyScenario() {
366 validateUserRoles(Role.ADMIN, Role.DESIGNER);
367 Resource resource = createResourceObject(false);
368 Either<Resource, ResponseFormat> createResponse = bl.createResource(resource,
369 AuditingActionEnum.CREATE_RESOURCE, user, null, null);
371 if (createResponse.isRight()) {
372 assertEquals(new Integer(200), createResponse.right().value().getStatus());
374 assertEquals(createResourceObject(true), createResponse.left().value());
378 public void testCsarUUIDnotEmpty() {
379 validateUserRoles(Role.ADMIN, Role.DESIGNER);
380 Resource resource = createResourceObject(false);
381 resource.setCsarUUID("asasaas");
382 Either<Integer, StorageOperationStatus> eitherUpdate = Either.left(2);
383 when(toscaOperationFacade.validateCsarUuidUniqueness("asasaas")).thenReturn(eitherUpdate);
384 Either<Resource, ResponseFormat> createResponse = bl.createResource(resource,
385 AuditingActionEnum.CREATE_RESOURCE, user, null, null);
390 public void testUpdateHappyScenario() {
391 Resource resource = createResourceObjectCsar(true);
392 setCanWorkOnResource(resource);
393 validateUserRoles(Role.ADMIN, Role.DESIGNER);
394 Either<Resource, StorageOperationStatus> resourceLinkedToCsarRes = Either.left(resource);
395 when(toscaOperationFacade.getLatestComponentByCsarOrName(ComponentTypeEnum.RESOURCE, resource.getCsarUUID(),
396 resource.getSystemName())).thenReturn(resourceLinkedToCsarRes);
397 Either<Boolean, StorageOperationStatus> validateDerivedExists = Either.left(true);
398 when(toscaOperationFacade.validateToscaResourceNameExists("Root")).thenReturn(validateDerivedExists);
399 Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
400 when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
401 Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
402 when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
403 Either<Resource, ResponseFormat> updateResponse = bl.validateAndUpdateResourceFromCsar(resource, user, null,
404 null, resource.getUniqueId());
405 if (updateResponse.isRight()) {
406 assertEquals(new Integer(200), updateResponse.right().value().getStatus());
408 assertEquals(resource.getUniqueId(), updateResponse.left().value().getUniqueId());
413 public void testFailedResourceValidations() {
414 testResourceNameExist();
415 testResourceNameEmpty();
416 // testResourceNameExceedsLimit();
417 testResourceNameWrongFormat();
418 testResourceDescExceedsLimitCreate();
419 testResourceDescNotEnglish();
420 testResourceDescriptionEmpty();
421 testResourceDescriptionMissing();
422 testResourceIconMissing();
423 testResourceIconInvalid();
424 testResourceIconExceedsLimit();
425 testResourceTagNotExist();
426 testResourceTagEmpty();
427 testTagsExceedsLimitCreate();
428 testTagsNoServiceName();
431 testContactIdTooLong();
432 testContactIdWrongFormatCreate();
433 testResourceContactIdEmpty();
434 testResourceContactIdMissing();
435 testVendorNameExceedsLimit();
436 testVendorNameWrongFormatCreate();
437 testVendorReleaseWrongFormat();
438 testVendorReleaseExceedsLimitCreate();
439 testResourceVendorModelNumberExceedsLimit();
440 testResourceVendorNameMissing();
441 testResourceVendorReleaseMissing();
442 testResourceCategoryExist();
443 testResourceBadCategoryCreate();
444 testHappyScenarioCostLicenseType();
445 testCostWrongFormatCreate();
446 testLicenseTypeWrongFormatCreate();
447 testResourceTemplateNotExist();
448 testResourceTemplateEmpty();
449 testResourceTemplateInvalid();
452 private void testResourceNameExist() {
453 String resourceName = "alreadyExists";
454 Resource resourceExist = createResourceObject(false);
455 resourceExist.setName(resourceName);
456 resourceExist.getTags().add(resourceName);
457 validateUserRoles(Role.ADMIN, Role.DESIGNER);
458 Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceExist,
459 AuditingActionEnum.CREATE_RESOURCE, user, null, null);
460 assertResponse(createResponse, ActionStatus.COMPONENT_NAME_ALREADY_EXIST, ComponentTypeEnum.RESOURCE.getValue(),
464 private void testResourceNameEmpty() {
465 Resource resourceExist = createResourceObject(false);
466 resourceExist.setName(null);
468 Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceExist,
469 AuditingActionEnum.CREATE_RESOURCE, user, null, null);
470 assertResponse(createResponse, ActionStatus.MISSING_COMPONENT_NAME, ComponentTypeEnum.RESOURCE.getValue());
473 private void testResourceNameExceedsLimit() {
474 Resource resourceExccedsNameLimit = createResourceObject(false);
475 // 51 chars, the limit is 50
476 String tooLongResourceName = "zCRCAWjqte0DtgcAAMmcJcXeNubeX1p1vOZNTShAHOYNAHvV3iK";
477 resourceExccedsNameLimit.setName(tooLongResourceName);
479 Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceExccedsNameLimit,
480 AuditingActionEnum.CREATE_RESOURCE, user, null, null);
481 assertTrue(createResponse.isRight());
482 assertResponse(createResponse, ActionStatus.COMPONENT_NAME_EXCEEDS_LIMIT, ComponentTypeEnum.RESOURCE.getValue(),
483 "" + ValidationUtils.COMPONENT_NAME_MAX_LENGTH);
486 private void testResourceNameWrongFormat() {
487 Resource resource = createResourceObject(false);
489 String nameWrongFormat = "ljg?fd";
490 resource.setName(nameWrongFormat);
492 Either<Resource, ResponseFormat> createResponse = bl.createResource(resource,
493 AuditingActionEnum.CREATE_RESOURCE, user, null, null);
494 assertTrue(createResponse.isRight());
495 assertResponse(createResponse, ActionStatus.INVALID_COMPONENT_NAME, ComponentTypeEnum.RESOURCE.getValue());
498 // Resource name - end
499 // Resource description - start
500 private void testResourceDescExceedsLimitCreate() {
501 Resource resourceExccedsDescLimit = createResourceObject(false);
502 // 1025 chars, the limit is 1024
503 String tooLongResourceDesc = "1GUODojQ0sGzKR4NP7e5j82ADQ3KHTVOaezL95qcbuaqDtjZhAQGQ3iFwKAy580K4WiiXs3u3zq7RzXcSASl5fm0RsWtCMOIDP"
504 + "AOf9Tf2xtXxPCuCIMCR5wOGnNTaFxgnJEHAGxilBhZDgeMNHmCN1rMK5B5IRJOnZxcpcL1NeG3APTCIMP1lNAxngYulDm9heFSBc8TfXAADq7703AvkJT0QPpGq2z2P"
505 + "tlikcAnIjmWgfC5Tm7UH462BAlTyHg4ExnPPL4AO8c92VrD7kZSgSqiy73cN3gLT8uigkKrUgXQFGVUFrXVyyQXYtVM6bLBeuCGQf4C2j8lkNg6M0J3PC0PzMRoinOxk"
506 + "Ae2teeCtVcIj4A1KQo3210j8q2v7qQU69Mabsa6DT9FgE4rcrbiFWrg0Zto4SXWD3o1eJA9o29lTg6kxtklH3TuZTmpi5KVp1NFhS1RpnqF83tzv4mZLKsx7Zh1fEgYvRFwx1"
507 + "ar3RolyDfNoZiGBGTMsZzz7RPFBf2hTnLmNqVGQnHKhhGj0Y5s8t2cbqbO2nmHiJb9uaUVrCGypgbAcJL3KPOBfAVW8PcpmNj4yVjI3L4x5zHjmGZbp9vKshEQODcrmcgsYAoKqe"
508 + "uu5u7jk8XVxEfQ0m5qL8UOErXPlJovSmKUmP5B5T0w299zIWDYCzSoNasHpHjOMDLAiDDeHbozUOn9t3Qou00e9POq4RMM0VnIx1H38nJoJZz2XH8CI5YMQe7oTagaxgQTF2aa0qaq2"
509 + "V6nJsfRGRklGjNhFFYP2cS4Xv2IJO9DSX6LTXOmENrGVJJvMOZcvnBaZPfoAHN0LU4i1SoepLzulIxnZBfkUWFJgZ5wQ0Bco2GC1HMqzW21rwy4XHRxXpXbmW8LVyoA1KbnmVmROycU4"
510 + "scTZ62IxIcIWCVeMjBIcTviXULbPUyqlfEPXWr8IMJtpAaELWgyquPClAREMDs2b9ztKmUeXlMccFES1XWbFTrhBHhmmDyVReEgCwfokrUFR13LTUK1k8I6OEHOs";
512 resourceExccedsDescLimit.setDescription(tooLongResourceDesc);
514 Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceExccedsDescLimit,
515 AuditingActionEnum.CREATE_RESOURCE, user, null, null);
516 assertTrue(createResponse.isRight());
517 assertResponse(createResponse, ActionStatus.COMPONENT_DESCRIPTION_EXCEEDS_LIMIT,
518 ComponentTypeEnum.RESOURCE.getValue(), "" + ValidationUtils.COMPONENT_DESCRIPTION_MAX_LENGTH);
521 private void testResourceDescNotEnglish() {
522 Resource notEnglish = createResourceObject(false);
524 String notEnglishDesc = "\uC2B5";
525 notEnglish.setDescription(notEnglishDesc);
527 Either<Resource, ResponseFormat> createResponse = bl.createResource(notEnglish,
528 AuditingActionEnum.CREATE_RESOURCE, user, null, null);
529 assertTrue(createResponse.isRight());
530 assertResponse(createResponse, ActionStatus.COMPONENT_INVALID_DESCRIPTION,
531 ComponentTypeEnum.RESOURCE.getValue());
534 private void testResourceDescriptionEmpty() {
535 Resource resourceExist = createResourceObject(false);
536 resourceExist.setDescription("");
538 Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceExist,
539 AuditingActionEnum.CREATE_RESOURCE, user, null, null);
540 assertTrue(createResponse.isRight());
542 assertResponse(createResponse, ActionStatus.COMPONENT_MISSING_DESCRIPTION,
543 ComponentTypeEnum.RESOURCE.getValue());
546 private void testResourceDescriptionMissing() {
547 Resource resourceExist = createResourceObject(false);
548 resourceExist.setDescription(null);
550 Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceExist,
551 AuditingActionEnum.CREATE_RESOURCE, user, null, null);
552 assertTrue(createResponse.isRight());
554 assertResponse(createResponse, ActionStatus.COMPONENT_MISSING_DESCRIPTION,
555 ComponentTypeEnum.RESOURCE.getValue());
557 // Resource description - end
558 // Resource icon start
560 private void testResourceIconMissing() {
561 Resource resourceExist = createResourceObject(false);
562 resourceExist.setIcon(null);
564 Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceExist,
565 AuditingActionEnum.CREATE_RESOURCE, user, null, null);
566 assertTrue(createResponse.isRight());
568 assertResponse(createResponse, ActionStatus.COMPONENT_MISSING_ICON, ComponentTypeEnum.RESOURCE.getValue());
571 private void testResourceIconInvalid() {
572 Resource resourceExist = createResourceObject(false);
573 resourceExist.setIcon("kjk3453^&");
575 Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceExist,
576 AuditingActionEnum.CREATE_RESOURCE, user, null, null);
577 assertTrue(createResponse.isRight());
579 assertResponse(createResponse, ActionStatus.COMPONENT_INVALID_ICON, ComponentTypeEnum.RESOURCE.getValue());
582 private void testResourceIconExceedsLimit() {
583 Resource resourceExist = createResourceObject(false);
584 resourceExist.setIcon("dsjfhskdfhskjdhfskjdhkjdhfkshdfksjsdkfhsdfsdfsdfsfsdfsf");
586 Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceExist,
587 AuditingActionEnum.CREATE_RESOURCE, user, null, null);
588 assertTrue(createResponse.isRight());
590 assertResponse(createResponse, ActionStatus.COMPONENT_ICON_EXCEEDS_LIMIT, ComponentTypeEnum.RESOURCE.getValue(),
591 "" + ValidationUtils.ICON_MAX_LENGTH);
595 // Resource tags - start
596 private void testResourceTagNotExist() {
597 Resource resourceExist = createResourceObject(false);
598 resourceExist.setTags(null);
600 Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceExist,
601 AuditingActionEnum.CREATE_RESOURCE, user, null, null);
602 assertTrue(createResponse.isRight());
604 assertResponse(createResponse, ActionStatus.COMPONENT_MISSING_TAGS);
607 private void testResourceTagEmpty() {
608 Resource resourceExist = createResourceObject(false);
609 resourceExist.setTags(new ArrayList<String>());
611 Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceExist,
612 AuditingActionEnum.CREATE_RESOURCE, user, null, null);
613 assertTrue(createResponse.isRight());
615 assertResponse(createResponse, ActionStatus.COMPONENT_MISSING_TAGS);
618 private void testTagsExceedsLimitCreate() {
619 Resource resourceExccedsNameLimit = createResourceObject(false);
620 String tag1 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjQ";
621 String tag2 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjW";
622 String tag3 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjE";
623 String tag4 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjb";
624 String tag5 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjr";
625 String tag6 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjf";
626 String tag7 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjg";
627 String tag8 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjd";
628 String tag9 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjf";
629 String tag10 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjg";
630 String tag11 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjh";
631 String tag12 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjj";
632 String tag13 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjk";
633 String tag14 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjs";
634 String tag15 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjz";
635 String tag16 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjx";
636 String tag17 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBj2";
637 String tag18 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBj3";
638 String tag19 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBj4";
639 String tag20 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBj5";
640 String tag21 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBj0";
642 List<String> tagsList = new ArrayList<String>();
664 tagsList.add(resourceExccedsNameLimit.getName());
666 resourceExccedsNameLimit.setTags(tagsList);
668 Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceExccedsNameLimit,
669 AuditingActionEnum.CREATE_RESOURCE, user, null, null);
670 assertTrue(createResponse.isRight());
671 assertResponse(createResponse, ActionStatus.COMPONENT_TAGS_EXCEED_LIMIT,
672 "" + ValidationUtils.TAG_LIST_MAX_LENGTH);
676 private void testTagsNoServiceName() {
677 Resource serviceExccedsNameLimit = createResourceObject(false);
678 String tag1 = "afzs2qLBb";
679 List<String> tagsList = new ArrayList<String>();
681 serviceExccedsNameLimit.setTags(tagsList);
683 Either<Resource, ResponseFormat> createResponse = bl.createResource(serviceExccedsNameLimit,
684 AuditingActionEnum.CREATE_RESOURCE, user, null, null);
685 assertTrue(createResponse.isRight());
686 assertResponse(createResponse, ActionStatus.COMPONENT_INVALID_TAGS_NO_COMP_NAME);
690 private void testInvalidTag() {
691 Resource serviceExccedsNameLimit = createResourceObject(false);
692 String tag1 = "afzs2qLBb%#%";
693 List<String> tagsList = new ArrayList<String>();
695 serviceExccedsNameLimit.setTags(tagsList);
697 Either<Resource, ResponseFormat> createResponse = bl.createResource(serviceExccedsNameLimit,
698 AuditingActionEnum.CREATE_RESOURCE, user, null, null);
699 assertTrue(createResponse.isRight());
700 assertResponse(createResponse, ActionStatus.INVALID_FIELD_FORMAT, new String[] { "Resource", "tag" });
704 // Resource tags - stop
705 // Resource contact start
707 private void testContactIdTooLong() {
708 Resource resourceContactId = createResourceObject(false);
709 // 59 chars instead of 50
710 String contactIdTooLong = "thisNameIsVeryLongAndExeccedsTheNormalLengthForContactId";
711 resourceContactId.setContactId(contactIdTooLong);
713 Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceContactId,
714 AuditingActionEnum.CREATE_RESOURCE, user, null, null);
715 assertTrue(createResponse.isRight());
716 assertResponse(createResponse, ActionStatus.COMPONENT_INVALID_CONTACT, ComponentTypeEnum.RESOURCE.getValue());
719 private void testContactIdWrongFormatCreate() {
720 Resource resourceContactId = createResourceObject(false);
721 // 3 letters and 3 digits and special characters
722 String contactIdFormatWrong = "yrt134!!!";
723 resourceContactId.setContactId(contactIdFormatWrong);
725 Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceContactId,
726 AuditingActionEnum.CREATE_RESOURCE, user, null, null);
727 assertTrue(createResponse.isRight());
728 assertResponse(createResponse, ActionStatus.COMPONENT_INVALID_CONTACT, ComponentTypeEnum.RESOURCE.getValue());
731 private void testResourceContactIdEmpty() {
732 Resource resourceExist = createResourceObject(false);
733 resourceExist.setContactId("");
735 Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceExist,
736 AuditingActionEnum.CREATE_RESOURCE, user, null, null);
737 assertTrue(createResponse.isRight());
739 assertResponse(createResponse, ActionStatus.COMPONENT_MISSING_CONTACT, ComponentTypeEnum.RESOURCE.getValue());
742 private void testResourceContactIdMissing() {
743 Resource resourceExist = createResourceObject(false);
744 resourceExist.setContactId(null);
746 Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceExist,
747 AuditingActionEnum.CREATE_RESOURCE, user, null, null);
748 assertTrue(createResponse.isRight());
750 assertResponse(createResponse, ActionStatus.COMPONENT_MISSING_CONTACT, ComponentTypeEnum.RESOURCE.getValue());
753 private void testVendorNameExceedsLimit() {
754 Resource resourceExccedsVendorNameLimit = createResourceObject(false);
755 String tooLongVendorName = "h1KSyJh9Eh1KSyJh9Eh1KSyJh9Eh1KSyJh9Eh1KSyJh9Eh1KSyJh9Eh1KSyJh9Eh1KSyJh9E";
756 resourceExccedsVendorNameLimit.setVendorName(tooLongVendorName);
758 Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceExccedsVendorNameLimit,
759 AuditingActionEnum.CREATE_RESOURCE, user, null, null);
760 assertTrue(createResponse.isRight());
761 assertResponse(createResponse, ActionStatus.VENDOR_NAME_EXCEEDS_LIMIT,
762 "" + ValidationUtils.VENDOR_NAME_MAX_LENGTH);
765 private void testResourceVendorModelNumberExceedsLimit() {
766 Resource resourceExccedsVendorModelNumberLimit = createResourceObject(false);
767 String tooLongVendorModelNumber = "h1KSyJh9Eh1KSyJh9Eh1KSyJh9Eh1KSyJh9Eh1KSyJh9Eh1KSyJh9Eh1KSyJh9Eh1KSyJh9E";
768 resourceExccedsVendorModelNumberLimit.setResourceVendorModelNumber(tooLongVendorModelNumber);
770 Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceExccedsVendorModelNumberLimit,
771 AuditingActionEnum.CREATE_RESOURCE, user, null, null);
772 assertTrue(createResponse.isRight());
773 assertResponse(createResponse, ActionStatus.RESOURCE_VENDOR_MODEL_NUMBER_EXCEEDS_LIMIT,
774 "" + ValidationUtils.RESOURCE_VENDOR_MODEL_NUMBER_MAX_LENGTH);
777 private void testVendorNameWrongFormatCreate() {
778 Resource resource = createResourceObject(false);
780 String nameWrongFormat = "ljg*fd";
781 resource.setVendorName(nameWrongFormat);
783 Either<Resource, ResponseFormat> createResponse = bl.createResource(resource,
784 AuditingActionEnum.CREATE_RESOURCE, user, null, null);
785 assertTrue(createResponse.isRight());
786 assertResponse(createResponse, ActionStatus.INVALID_VENDOR_NAME);
789 private void testVendorReleaseWrongFormat() {
790 Resource resource = createResourceObject(false);
792 String nameWrongFormat = "1>2";
793 resource.setVendorRelease(nameWrongFormat);
795 Either<Resource, ResponseFormat> createResponse = bl.createResource(resource,
796 AuditingActionEnum.CREATE_RESOURCE, user, null, null);
797 assertTrue(createResponse.isRight());
798 assertResponse(createResponse, ActionStatus.INVALID_VENDOR_RELEASE);
802 private void testVendorReleaseExceedsLimitCreate() {
803 Resource resourceExccedsNameLimit = createResourceObject(false);
804 String tooLongVendorRelease = "h1KSyJh9Eh1KSyJh9Eh1KSyJh9Eh1KSyJh9E";
805 resourceExccedsNameLimit.setVendorRelease(tooLongVendorRelease);
807 Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceExccedsNameLimit,
808 AuditingActionEnum.CREATE_RESOURCE, user, null, null);
809 assertTrue(createResponse.isRight());
810 assertResponse(createResponse, ActionStatus.VENDOR_RELEASE_EXCEEDS_LIMIT,
811 "" + ValidationUtils.VENDOR_RELEASE_MAX_LENGTH);
814 private void testResourceVendorNameMissing() {
815 Resource resourceExist = createResourceObject(false);
816 resourceExist.setVendorName(null);
818 Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceExist,
819 AuditingActionEnum.CREATE_RESOURCE, user, null, null);
820 assertTrue(createResponse.isRight());
822 assertResponse(createResponse, ActionStatus.MISSING_VENDOR_NAME);
825 private void testResourceVendorReleaseMissing() {
826 Resource resourceExist = createResourceObject(false);
827 resourceExist.setVendorRelease(null);
829 Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceExist,
830 AuditingActionEnum.CREATE_RESOURCE, user, null, null);
831 assertTrue(createResponse.isRight());
833 assertResponse(createResponse, ActionStatus.MISSING_VENDOR_RELEASE);
836 // Resource vendor name/release stop
838 private void testResourceCategoryExist() {
839 Resource resourceExist = createResourceObject(false);
840 resourceExist.setCategories(null);
842 Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceExist,
843 AuditingActionEnum.CREATE_RESOURCE, user, null, null);
844 assertTrue(createResponse.isRight());
846 assertResponse(createResponse, ActionStatus.COMPONENT_MISSING_CATEGORY, ComponentTypeEnum.RESOURCE.getValue());
849 private void testResourceBadCategoryCreate() {
851 Resource resourceExist = createResourceObject(false);
852 resourceExist.setCategories(null);
853 resourceExist.addCategory("koko", "koko");
855 Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceExist,
856 AuditingActionEnum.CREATE_RESOURCE, user, null, null);
857 assertTrue(createResponse.isRight());
859 assertResponse(createResponse, ActionStatus.COMPONENT_INVALID_CATEGORY, ComponentTypeEnum.RESOURCE.getValue());
864 private void testHappyScenarioCostLicenseType() {
865 Resource createResourceObject = createResourceObject(false);
866 Resource createResourceObjectAfterCreate = createResourceObject(true);
867 // Adding cost and licenseType to basic mock
868 Either<Resource, StorageOperationStatus> eitherCreate = Either.left(createResourceObjectAfterCreate);
869 when(toscaOperationFacade.createToscaComponent(any(Resource.class))).thenReturn(eitherCreate);
871 String cost = "123.456";
872 String licenseType = "User";
873 createResourceObject.setCost(cost);
874 createResourceObject.setLicenseType(licenseType);
875 Either<Resource, ResponseFormat> createResponse = bl.createResource(createResourceObject,
876 AuditingActionEnum.CREATE_RESOURCE, user, null, null);
878 if (createResponse.isRight()) {
879 assertEquals(new Integer(200), createResponse.right().value().getStatus());
881 createResourceObjectAfterCreate.setCost(cost);
882 createResourceObjectAfterCreate.setLicenseType(licenseType);
883 assertEquals(createResourceObjectAfterCreate, createResponse.left().value());
886 private void testCostWrongFormatCreate() {
887 Resource resourceCost = createResourceObject(false);
888 // Comma instead of fullstop
889 String cost = "12356,464";
890 resourceCost.setCost(cost);
892 Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceCost,
893 AuditingActionEnum.CREATE_RESOURCE, user, null, null);
894 assertTrue(createResponse.isRight());
895 assertResponse(createResponse, ActionStatus.INVALID_CONTENT);
899 // License type start
900 private void testLicenseTypeWrongFormatCreate() {
901 Resource resourceLicenseType = createResourceObject(false);
903 String licenseType = "cpu";
904 resourceLicenseType.setLicenseType(licenseType);
906 Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceLicenseType,
907 AuditingActionEnum.CREATE_RESOURCE, user, null, null);
908 assertTrue(createResponse.isRight());
909 assertResponse(createResponse, ActionStatus.INVALID_CONTENT);
913 // Derived from start
914 private void testResourceTemplateNotExist() {
915 Resource resourceExist = createResourceObject(false);
916 List<String> list = null;
917 resourceExist.setDerivedFrom(list);
919 Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceExist,
920 AuditingActionEnum.CREATE_RESOURCE, user, null, null);
921 assertTrue(createResponse.isRight());
923 assertResponse(createResponse, ActionStatus.MISSING_DERIVED_FROM_TEMPLATE);
926 private void testResourceTemplateEmpty() {
927 Resource resourceExist = createResourceObject(false);
928 resourceExist.setDerivedFrom(new ArrayList<String>());
930 Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceExist,
931 AuditingActionEnum.CREATE_RESOURCE, user, null, null);
932 assertTrue(createResponse.isRight());
934 assertResponse(createResponse, ActionStatus.MISSING_DERIVED_FROM_TEMPLATE);
937 private void testResourceTemplateInvalid() {
938 Resource resourceExist = createResourceObject(false);
939 ArrayList<String> derivedFrom = new ArrayList<String>();
940 derivedFrom.add("kuku");
941 resourceExist.setDerivedFrom(derivedFrom);
943 Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceExist,
944 AuditingActionEnum.CREATE_RESOURCE, user, null, null);
945 assertTrue(createResponse.isRight());
947 assertResponse(createResponse, ActionStatus.PARENT_RESOURCE_NOT_FOUND);
951 private void assertResponse(Either<Resource, ResponseFormat> createResponse, ActionStatus expectedStatus,
952 String... variables) {
953 ResponseFormat expectedResponse = responseManager.getResponseFormat(expectedStatus, variables);
954 ResponseFormat actualResponse = createResponse.right().value();
955 assertEquals(expectedResponse.getStatus(), actualResponse.getStatus());
956 assertEquals("assert error description", expectedResponse.getFormattedMessage(),
957 actualResponse.getFormattedMessage());
960 // UPDATE tests - start
963 public void testResourceNameWrongFormat_UPDATE() {
964 Resource resource = createResourceObject(true);
965 resource.setInterfaces(createMockInterfaceDefinition(RESOURCE_NAME));
966 Resource updatedResource = createResourceObject(true);
968 // this is in order to prevent failing with 403 earlier
969 Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
970 when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
972 String nameWrongFormat = "ljg*fd";
973 updatedResource.setName(nameWrongFormat);
975 Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
976 when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
978 Either<Resource, ResponseFormat> createResponse = bl.updateResourceMetadata(resource.getUniqueId(),
979 updatedResource, null, user, false);
980 assertTrue(createResponse.isRight());
981 assertResponse(createResponse, ActionStatus.INVALID_COMPONENT_NAME, ComponentTypeEnum.RESOURCE.getValue());
986 public void testResourceNameAfterCertify_UPDATE() {
987 Resource resource = createResourceObject(true);
988 resource.setInterfaces(createMockInterfaceDefinition(RESOURCE_NAME));
989 Resource updatedResource = createResourceObject(true);
991 // this is in order to prevent failing with 403 earlier
992 Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
993 // when(resourceOperation.getResource_tx(resource.getUniqueId(),false)).thenReturn(eitherUpdate);
994 when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
997 updatedResource.setName(name);
998 resource.setVersion("1.0");
1000 Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
1001 when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
1003 Either<Resource, ResponseFormat> createResponse = bl.updateResourceMetadata(resource.getUniqueId(),
1004 updatedResource, null, user, false);
1005 assertTrue(createResponse.isRight());
1006 assertResponse(createResponse, ActionStatus.RESOURCE_NAME_CANNOT_BE_CHANGED);
1011 public void testResourceNameExceedsLimit_UPDATE() {
1012 Resource resource = createResourceObject(true);
1013 Resource updatedResource = createResourceObject(true);
1015 // this is in order to prevent failing with 403 earlier
1016 Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
1017 when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
1019 // 51 chars, the limit is 50
1020 String tooLongResourceName = "zCRCAWjqte0DtgcAAMmcJcXeNubeX1p1vOZNTShAHOYNAHvV3iK";
1021 updatedResource.setName(tooLongResourceName);
1022 Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
1023 when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
1025 Either<Resource, ResponseFormat> createResponse = bl.updateResourceMetadata(resource.getUniqueId(),
1026 updatedResource, null, user, false);
1027 assertTrue(createResponse.isRight());
1028 assertResponse(createResponse, ActionStatus.COMPONENT_NAME_EXCEEDS_LIMIT, ComponentTypeEnum.RESOURCE.getValue(),
1029 "" + ValidationUtils.COMPONENT_NAME_MAX_LENGTH);
1033 public void testResourceNameAlreadyExist_UPDATE() {
1034 Resource resource = createResourceObject(true);
1035 resource.setInterfaces(createMockInterfaceDefinition(RESOURCE_NAME));
1037 Resource updatedResource = createResourceObject(true);
1039 // this is in order to prevent failing with 403 earlier
1040 Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
1041 when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
1043 String resourceName = "alreadyExists";
1044 updatedResource.setName(resourceName);
1045 Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(updatedResource);
1046 when(toscaOperationFacade.updateToscaElement(updatedResource)).thenReturn(dataModelResponse);
1047 Either<Resource, ResponseFormat> createResponse = bl.updateResourceMetadata(resource.getUniqueId(),
1048 updatedResource, null, user, false);
1049 assertTrue(createResponse.isRight());
1050 assertResponse(createResponse, ActionStatus.COMPONENT_NAME_ALREADY_EXIST, ComponentTypeEnum.RESOURCE.getValue(),
1057 public void testResourceDescExceedsLimit_UPDATE() {
1058 Resource resource = createResourceObject(true);
1059 Resource updatedResource = createResourceObject(true);
1061 // this is in order to prevent failing with 403 earlier
1062 Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
1063 when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
1065 // 1025 chars, the limit is 1024
1066 String tooLongResourceDesc = "1GUODojQ0sGzKR4NP7e5j82ADQ3KHTVOaezL95qcbuaqDtjZhAQGQ3iFwKAy580K4WiiXs3u3zq7RzXcSASl5fm0RsWtCMOIDP"
1067 + "AOf9Tf2xtXxPCuCIMCR5wOGnNTaFxgnJEHAGxilBhZDgeMNHmCN1rMK5B5IRJOnZxcpcL1NeG3APTCIMP1lNAxngYulDm9heFSBc8TfXAADq7703AvkJT0QPpGq2z2P"
1068 + "tlikcAnIjmWgfC5Tm7UH462BAlTyHg4ExnPPL4AO8c92VrD7kZSgSqiy73cN3gLT8uigkKrUgXQFGVUFrXVyyQXYtVM6bLBeuCGQf4C2j8lkNg6M0J3PC0PzMRoinOxk"
1069 + "Ae2teeCtVcIj4A1KQo3210j8q2v7qQU69Mabsa6DT9FgE4rcrbiFWrg0Zto4SXWD3o1eJA9o29lTg6kxtklH3TuZTmpi5KVp1NFhS1RpnqF83tzv4mZLKsx7Zh1fEgYvRFwx1"
1070 + "ar3RolyDfNoZiGBGTMsZzz7RPFBf2hTnLmNqVGQnHKhhGj0Y5s8t2cbqbO2nmHiJb9uaUVrCGypgbAcJL3KPOBfAVW8PcpmNj4yVjI3L4x5zHjmGZbp9vKshEQODcrmcgsYAoKqe"
1071 + "uu5u7jk8XVxEfQ0m5qL8UOErXPlJovSmKUmP5B5T0w299zIWDYCzSoNasHpHjOMDLAiDDeHbozUOn9t3Qou00e9POq4RMM0VnIx1H38nJoJZz2XH8CI5YMQe7oTagaxgQTF2aa0qaq2"
1072 + "V6nJsfRGRklGjNhFFYP2cS4Xv2IJO9DSX6LTXOmENrGVJJvMOZcvnBaZPfoAHN0LU4i1SoepLzulIxnZBfkUWFJgZ5wQ0Bco2GC1HMqzW21rwy4XHRxXpXbmW8LVyoA1KbnmVmROycU4"
1073 + "scTZ62IxIcIWCVeMjBIcTviXULbPUyqlfEPXWr8IMJtpAaELWgyquPClAREMDs2b9ztKmUeXlMccFES1XWbFTrhBHhmmDyVReEgCwfokrUFR13LTUK1k8I6OEHOs";
1074 updatedResource.setDescription(tooLongResourceDesc);
1075 Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
1076 when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
1077 Either<Resource, ResponseFormat> createResponse = bl.updateResourceMetadata(resource.getUniqueId(),
1078 updatedResource, null, user, false);
1079 assertTrue(createResponse.isRight());
1080 assertResponse(createResponse, ActionStatus.COMPONENT_DESCRIPTION_EXCEEDS_LIMIT,
1081 ComponentTypeEnum.RESOURCE.getValue(), "" + ValidationUtils.COMPONENT_DESCRIPTION_MAX_LENGTH);
1086 public void testIconWrongFormat_UPDATE() {
1087 Resource resource = createResourceObject(true);
1088 Resource updatedResource = createResourceObject(true);
1090 // this is in order to prevent failing with 403 earlier
1091 Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
1092 when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
1095 String icon = "icon.jpg";
1096 updatedResource.setIcon(icon);
1097 Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
1098 when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
1100 Either<Resource, ResponseFormat> createResponse = bl.updateResourceMetadata(resource.getUniqueId(),
1101 updatedResource, null, user, false);
1102 assertTrue(createResponse.isRight());
1103 assertResponse(createResponse, ActionStatus.COMPONENT_INVALID_ICON, ComponentTypeEnum.RESOURCE.getValue());
1108 public void testIconAfterCertify_UPDATE() {
1109 Resource resource = createResourceObject(true);
1110 Resource updatedResource = createResourceObject(true);
1112 // this is in order to prevent failing with 403 earlier
1113 Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
1114 when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
1117 String icon = "icon";
1118 updatedResource.setIcon(icon);
1120 resource.setVersion("1.0");
1122 Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
1123 when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
1124 Either<Resource, ResponseFormat> createResponse = bl.updateResourceMetadata(resource.getUniqueId(),
1125 updatedResource, null, user, false);
1126 assertTrue(createResponse.isRight());
1127 assertResponse(createResponse, ActionStatus.RESOURCE_ICON_CANNOT_BE_CHANGED);
1132 public void testTagsExceedsLimit_UPDATE() {
1133 Resource resource = createResourceObject(true);
1134 Resource updatedResource = createResourceObject(true);
1136 // this is in order to prevent failing with 403 earlier
1137 Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
1138 when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
1140 String tag1 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjQ";
1141 String tag2 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjW";
1142 String tag3 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjE";
1143 String tag4 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjb";
1144 String tag5 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjr";
1145 String tag6 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjf";
1146 String tag7 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjg";
1147 String tag8 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjd";
1148 String tag9 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjf";
1149 String tag10 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjg";
1150 String tag11 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjh";
1151 String tag12 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjj";
1152 String tag13 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjk";
1153 String tag14 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjs";
1154 String tag15 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjz";
1155 String tag16 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjx";
1156 String tag17 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBj2";
1157 String tag18 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBj3";
1158 String tag19 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBj4";
1159 String tag20 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBj5";
1160 String tag21 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBj0";
1162 List<String> tagsList = new ArrayList<String>();
1172 tagsList.add(tag10);
1173 tagsList.add(tag11);
1174 tagsList.add(tag12);
1175 tagsList.add(tag13);
1176 tagsList.add(tag14);
1177 tagsList.add(tag15);
1178 tagsList.add(tag16);
1179 tagsList.add(tag17);
1180 tagsList.add(tag18);
1181 tagsList.add(tag19);
1182 tagsList.add(tag20);
1183 tagsList.add(tag21);
1184 tagsList.add(resource.getName());
1186 updatedResource.setTags(tagsList);
1187 Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
1188 when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
1189 Either<Resource, ResponseFormat> createResponse = bl.updateResourceMetadata(resource.getUniqueId(),
1190 updatedResource, null, user, false);
1191 assertTrue(createResponse.isRight());
1193 assertResponse(createResponse, ActionStatus.COMPONENT_TAGS_EXCEED_LIMIT,
1194 "" + ValidationUtils.TAG_LIST_MAX_LENGTH);
1198 public void testVendorNameWrongFormat_UPDATE() {
1199 Resource resource = createResourceObject(true);
1200 Resource updatedResource = createResourceObject(true);
1202 // this is in order to prevent failing with 403 earlier
1203 Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
1204 when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
1207 String nameWrongFormat = "ljg*fd";
1208 updatedResource.setVendorName(nameWrongFormat);
1209 Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
1210 when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
1211 Either<Resource, ResponseFormat> createResponse = bl.updateResourceMetadata(resource.getUniqueId(),
1212 updatedResource, null, user, false);
1213 assertTrue(createResponse.isRight());
1214 assertResponse(createResponse, ActionStatus.INVALID_VENDOR_NAME);
1219 public void testVendorNameWrongFormat() {
1220 Resource resource = createResourceObject(true);
1221 Resource updatedResource = createResourceObject(true);
1223 // this is in order to prevent failing with 403 earlier
1224 Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
1225 when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
1228 String nameWrongFormat = "ljg*fd";
1229 updatedResource.setVendorName(nameWrongFormat);
1230 resource.setVersion("1.0");
1232 Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
1233 when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
1234 Either<Resource, ResponseFormat> createResponse = bl.updateResourceMetadata(resource.getUniqueId(),
1235 updatedResource, null, user, false);
1236 assertTrue(createResponse.isRight());
1237 assertResponse(createResponse, ActionStatus.INVALID_VENDOR_NAME);
1242 public void testVendorReleaseExceedsLimit_UPDATE() {
1243 Resource resource = createResourceObject(true);
1244 Resource updatedResource = createResourceObject(true);
1246 // this is in order to prevent failing with 403 earlier
1247 Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
1248 when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
1249 // 129 chars, the limit is 128
1250 String tooLongVendorRelease = "h1KSyJh9EspI8SPwAGu4VETfqWejeanuB1PCJBxJmJncYnrW0lnsEFFVRIukRJkwlOVnZCy8p38tjhANeZq3BGMHIawWR6ICl8Wi9mikRYALWgvJug00JrlQ0iPVKPLxy";
1251 updatedResource.setVendorRelease(tooLongVendorRelease);
1252 Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
1253 when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
1254 Either<Resource, ResponseFormat> createResponse = bl.updateResourceMetadata(resource.getUniqueId(),
1255 updatedResource, null, user, false);
1256 assertTrue(createResponse.isRight());
1257 assertResponse(createResponse, ActionStatus.VENDOR_RELEASE_EXCEEDS_LIMIT,
1258 "" + ValidationUtils.VENDOR_RELEASE_MAX_LENGTH);
1262 public void testContactIdWrongFormat_UPDATE() {
1263 Resource resource = createResourceObject(true);
1264 Resource updatedResource = createResourceObject(true);
1266 // this is in order to prevent failing with 403 earlier
1267 Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
1268 when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
1270 String resourceId = resource.getUniqueId();
1271 // 3 letters and 3 digits
1272 String contactIdTooLong = "yrt134";
1273 updatedResource.setContactId(contactIdTooLong);
1274 Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
1275 when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
1276 Either<Resource, ResponseFormat> createResponse = bl.updateResourceMetadata(resourceId, updatedResource, null,
1278 assertTrue(createResponse.isRight());
1280 assertResponse(createResponse, ActionStatus.COMPONENT_INVALID_CONTACT, ComponentTypeEnum.RESOURCE.getValue());
1284 public void testResourceBadCategory_UPDATE() {
1285 Resource resource = createResourceObject(true);
1286 Resource updatedResource = createResourceObject(true);
1288 // this is in order to prevent failing with 403 earlier
1289 Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
1290 when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
1292 String resourceId = resource.getUniqueId();
1293 String badCategory = "ddfds";
1294 updatedResource.setCategories(null);
1295 updatedResource.addCategory(badCategory, "fikt");
1296 Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
1297 when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
1298 Either<Resource, ResponseFormat> createResponse = bl.updateResourceMetadata(resourceId, updatedResource, null,
1300 assertTrue(createResponse.isRight());
1302 assertResponse(createResponse, ActionStatus.COMPONENT_INVALID_CATEGORY, ComponentTypeEnum.RESOURCE.getValue());
1306 public void testResourceCategoryAfterCertify_UPDATE() {
1307 Resource resource = createResourceObject(true);
1308 Resource updatedResource = createResourceObject(true);
1310 // this is in order to prevent failing with 403 earlier
1311 Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
1312 when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
1314 String resourceId = resource.getUniqueId();
1315 updatedResource.setCategories(null);
1316 updatedResource.addCategory(RESOURCE_CATEGORY1, UPDATED_SUBCATEGORY);
1317 resource.setVersion("1.0");
1319 Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
1320 when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
1321 Either<Resource, ResponseFormat> createResponse = bl.updateResourceMetadata(resourceId, updatedResource, null,
1323 assertTrue(createResponse.isRight());
1325 assertResponse(createResponse, ActionStatus.RESOURCE_CATEGORY_CANNOT_BE_CHANGED);
1328 // Derived from start
1330 public void testResourceTemplateNotExist_UPDATE() {
1331 Resource resource = createResourceObject(true);
1332 Resource updatedResource = createResourceObject(true);
1334 // this is in order to prevent failing with 403 earlier
1335 Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
1336 when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
1337 String resourceId = resource.getUniqueId();
1339 List<String> list = null;
1340 updatedResource.setDerivedFrom(list);
1341 Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
1342 when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
1343 Either<Resource, ResponseFormat> createResponse = bl.updateResourceMetadata(resourceId, updatedResource, null,
1345 assertTrue(createResponse.isRight());
1347 assertResponse(createResponse, ActionStatus.MISSING_DERIVED_FROM_TEMPLATE);
1351 public void testResourceTemplateEmpty_UPDATE() {
1352 Resource resource = createResourceObject(true);
1353 Resource updatedResource = createResourceObject(true);
1354 String resourceId = resource.getUniqueId();
1356 // this is in order to prevent failing with 403 earlier
1357 Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
1358 when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
1360 updatedResource.setDerivedFrom(new ArrayList<String>());
1361 Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
1362 when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
1363 Either<Resource, ResponseFormat> createResponse = bl.updateResourceMetadata(resourceId, updatedResource, null,
1365 assertTrue(createResponse.isRight());
1367 assertResponse(createResponse, ActionStatus.MISSING_DERIVED_FROM_TEMPLATE);
1371 public void testResourceTemplateInvalid_UPDATE() {
1372 Resource resource = createResourceObject(true);
1373 Resource updatedResource = createResourceObject(true);
1374 String resourceId = resource.getUniqueId();
1376 // this is in order to prevent failing with 403 earlier
1377 Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
1378 when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
1380 ArrayList<String> derivedFrom = new ArrayList<String>();
1381 derivedFrom.add("kuku");
1382 updatedResource.setDerivedFrom(derivedFrom);
1383 Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
1384 when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
1385 Either<Resource, ResponseFormat> createResponse = bl.updateResourceMetadata(resourceId, updatedResource, null,
1387 assertTrue(createResponse.isRight());
1389 assertResponse(createResponse, ActionStatus.PARENT_RESOURCE_NOT_FOUND);
1393 public void testResourceTemplateCertify_UPDATE_HAPPY() {
1394 Resource resource = createResourceObject(true);
1395 Resource updatedResource = createResourceObject(true);
1396 String resourceId = resource.getUniqueId();
1398 // this is in order to prevent failing with 403 earlier
1399 Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
1400 when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
1402 Either<Boolean, StorageOperationStatus> isToscaNameExtending = Either.left(true);
1403 when(toscaOperationFacade.validateToscaResourceNameExtends(Mockito.anyString(), Mockito.anyString()))
1404 .thenReturn(isToscaNameExtending);
1406 Either<Map<String, PropertyDefinition>, StorageOperationStatus> findPropertiesOfNode = Either
1407 .left(new HashMap<>());
1408 when(propertyOperation.deleteAllPropertiesAssociatedToNode(any(NodeTypeEnum.class), Mockito.anyString()))
1409 .thenReturn(findPropertiesOfNode);
1411 resource.setVersion("1.0");
1413 ArrayList<String> derivedFrom = new ArrayList<String>();
1414 derivedFrom.add("tosca.nodes.Root");
1415 updatedResource.setDerivedFrom(derivedFrom);
1416 Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(updatedResource);
1417 when(toscaOperationFacade.updateToscaElement(updatedResource)).thenReturn(dataModelResponse);
1418 Either<Resource, ResponseFormat> createResponse = bl.updateResourceMetadata(resourceId, updatedResource, null,
1420 assertTrue(createResponse.isLeft());
1424 public void testResourceTemplateCertify_UPDATE_SAD() {
1425 Resource resource = createResourceObject(true);
1426 Resource updatedResource = createResourceObject(true);
1427 String resourceId = resource.getUniqueId();
1429 // this is in order to prevent failing with 403 earlier
1430 Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
1431 when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
1433 Either<Boolean, StorageOperationStatus> isToscaNameExtending = Either.left(false);
1434 when(toscaOperationFacade.validateToscaResourceNameExtends(Mockito.anyString(), Mockito.anyString()))
1435 .thenReturn(isToscaNameExtending);
1437 resource.setVersion("1.0");
1439 ArrayList<String> derivedFrom = new ArrayList<String>();
1440 derivedFrom.add("tosca.nodes.Root");
1441 updatedResource.setDerivedFrom(derivedFrom);
1442 Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
1443 when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
1444 Either<Resource, ResponseFormat> createResponse = bl.updateResourceMetadata(resourceId, updatedResource, null,
1446 assertTrue(createResponse.isRight());
1448 assertResponse(createResponse, ActionStatus.PARENT_RESOURCE_DOES_NOT_EXTEND);
1450 // Derived from stop
1453 public void createOrUpdateResourceAlreadyCheckout() {
1454 Resource resourceExist = createResourceObject(false);
1455 validateUserRoles(Role.ADMIN, Role.DESIGNER);
1456 Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceExist,
1457 AuditingActionEnum.CREATE_RESOURCE, user, null, null);
1459 createResponse.left().value().setLastUpdaterUserId(user.getUserId());
1460 assertTrue(createResponse.isLeft());
1462 Either<Resource, StorageOperationStatus> getLatestResult = Either.left(createResponse.left().value());
1463 Either<Component, StorageOperationStatus> getCompLatestResult = Either.left(createResponse.left().value());
1464 when(toscaOperationFacade.getLatestByName(resourceExist.getName())).thenReturn(getCompLatestResult);
1465 when(toscaOperationFacade.overrideComponent(any(Resource.class), any(Resource.class)))
1466 .thenReturn(getLatestResult);
1468 Resource resourceToUpdtae = createResourceObject(false);
1470 Either<ImmutablePair<Resource, ActionStatus>, ResponseFormat> createOrUpdateResource = bl
1471 .createOrUpdateResourceByImport(resourceToUpdtae, user, false, false, false, null, null, false);
1472 assertTrue(createOrUpdateResource.isLeft());
1474 Mockito.verify(toscaOperationFacade, Mockito.times(1)).overrideComponent(any(Resource.class),
1475 any(Resource.class));
1476 Mockito.verify(lifecycleBl, Mockito.times(0)).changeState(Mockito.anyString(), eq(user),
1477 eq(LifeCycleTransitionEnum.CHECKOUT), any(LifecycleChangeInfoWithAction.class), Mockito.anyBoolean(),
1478 Mockito.anyBoolean());
1483 public void createOrUpdateResourceCertified() {
1484 Resource resourceExist = createResourceObject(false);
1485 validateUserRoles(Role.ADMIN, Role.DESIGNER);
1486 Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceExist,
1487 AuditingActionEnum.CREATE_RESOURCE, user, null, null);
1489 assertTrue(createResponse.isLeft());
1490 Resource certifiedResource = createResponse.left().value();
1491 certifiedResource.setLifecycleState(LifecycleStateEnum.CERTIFIED);
1492 certifiedResource.setVersion("1.0");
1494 Either<Resource, StorageOperationStatus> getLatestResult = Either.left(certifiedResource);
1495 Either<Component, StorageOperationStatus> getCompLatestResult = Either.left(createResponse.left().value());
1496 when(toscaOperationFacade.getLatestByName(resourceExist.getName())).thenReturn(getCompLatestResult);
1497 when(toscaOperationFacade.overrideComponent(any(Resource.class), any(Resource.class)))
1498 .thenReturn(getLatestResult);
1500 when(lifecycleBl.changeState(Mockito.anyString(), eq(user), eq(LifeCycleTransitionEnum.CHECKOUT),
1501 any(LifecycleChangeInfoWithAction.class), Mockito.anyBoolean(), Mockito.anyBoolean()))
1502 .thenReturn(createResponse);
1504 Resource resourceToUpdtae = createResourceObject(false);
1506 Either<ImmutablePair<Resource, ActionStatus>, ResponseFormat> createOrUpdateResource = bl
1507 .createOrUpdateResourceByImport(resourceToUpdtae, user, false, false, false, null, null, false);
1508 assertTrue(createOrUpdateResource.isLeft());
1510 Mockito.verify(toscaOperationFacade, Mockito.times(1)).overrideComponent(any(Resource.class),
1511 any(Resource.class));
1512 Mockito.verify(lifecycleBl, Mockito.times(1)).changeState(Mockito.anyString(), eq(user),
1513 eq(LifeCycleTransitionEnum.CHECKOUT), any(LifecycleChangeInfoWithAction.class), Mockito.anyBoolean(),
1514 Mockito.anyBoolean());
1519 public void createOrUpdateResourceNotExist() {
1520 Resource resourceToUpdtae = createResourceObject(false);
1522 Either<Component, StorageOperationStatus> getLatestResult = Either.right(StorageOperationStatus.NOT_FOUND);
1523 when(toscaOperationFacade.getLatestByName(resourceToUpdtae.getName())).thenReturn(getLatestResult);
1525 Either<Component, StorageOperationStatus> getLatestToscaNameResult = Either
1526 .right(StorageOperationStatus.NOT_FOUND);
1527 when(toscaOperationFacade.getLatestByToscaResourceName(resourceToUpdtae.getToscaResourceName()))
1528 .thenReturn(getLatestToscaNameResult);
1530 Either<ImmutablePair<Resource, ActionStatus>, ResponseFormat> createOrUpdateResource = bl
1531 .createOrUpdateResourceByImport(resourceToUpdtae, user, false, false, false, null, null, false);
1532 assertTrue(createOrUpdateResource.isLeft());
1534 Mockito.verify(toscaOperationFacade, Mockito.times(0)).overrideComponent(any(Resource.class),
1535 any(Resource.class));
1536 Mockito.verify(lifecycleBl, Mockito.times(0)).changeState(Mockito.anyString(), eq(user),
1537 eq(LifeCycleTransitionEnum.CHECKOUT), any(LifecycleChangeInfoWithAction.class), Mockito.anyBoolean(),
1538 Mockito.anyBoolean());
1543 public void testValidatePropertiesDefaultValues_SuccessfullWithoutProperties() {
1544 Resource basic = createResourceObject(true);
1546 Either<Boolean, ResponseFormat> validatePropertiesDefaultValues = bl.validatePropertiesDefaultValues(basic);
1547 assertTrue(validatePropertiesDefaultValues.isLeft());
1551 public void testValidatePropertiesDefaultValues_SuccessfullWithProperties() {
1552 Resource basic = createResourceObject(true);
1553 PropertyDefinition property = new PropertyDefinition();
1554 property.setName("myProperty");
1555 property.setType(ToscaPropertyType.INTEGER.getType());
1556 property.setDefaultValue("1");
1557 List<PropertyDefinition> properties = new ArrayList<>();
1558 properties.add(property);
1559 basic.setProperties(properties);
1560 when(propertyOperation.isPropertyTypeValid(property)).thenReturn(true);
1561 when(propertyOperation.isPropertyDefaultValueValid(property, emptyDataTypes)).thenReturn(true);
1562 Either<Boolean, ResponseFormat> validatePropertiesDefaultValues = bl.validatePropertiesDefaultValues(basic);
1563 assertTrue(validatePropertiesDefaultValues.isLeft());
1567 public void testValidatePropertiesDefaultValues_FailedWithProperties() {
1568 Resource basic = createResourceObject(true);
1569 PropertyDefinition property = new PropertyDefinition();
1570 property.setName("myProperty");
1571 property.setType(ToscaPropertyType.INTEGER.getType());
1572 property.setDefaultValue("1.5");
1573 List<PropertyDefinition> properties = new ArrayList<>();
1574 properties.add(property);
1575 basic.setProperties(properties);
1577 when(propertyOperation.isPropertyDefaultValueValid(property, emptyDataTypes)).thenReturn(false);
1578 Either<Boolean, ResponseFormat> validatePropertiesDefaultValues = bl.validatePropertiesDefaultValues(basic);
1579 assertTrue(validatePropertiesDefaultValues.isRight());
1583 @SuppressWarnings("unchecked")
1585 public void testFindVfCsarArtifactsToHandle() {
1587 Class<ResourceBusinessLogic> targetClass = ResourceBusinessLogic.class;
1588 String methodName = "findVfCsarArtifactsToHandle";
1589 Resource resource = new Resource();
1590 String deploymentArtifactToUpdateFileName = "deploymentArtifactToUpdate.yaml";
1591 String deploymentArtifactToDeleteFileName = "deploymentArtifactToDelete.yaml";
1592 String deploymentArtifactToCreateFileName = "deploymentArtifactToCreate.yaml";
1594 String artifactInfoToUpdateFileName = "infoArtifactToUpdate.yaml";
1595 String artifactInfoToDeleteFileName = "infoArtifactToDelete.yaml";
1596 String artifactInfoToNotDeleteFileName = "infoArtifactNotToDelete.yaml";
1597 String artifactInfoToCreateFileName = "infoArtifactToCreate.yaml";
1599 byte[] oldPayloadData = "oldPayloadData".getBytes();
1600 byte[] newPayloadData = "newPayloadData".getBytes();
1601 Map<String, ArtifactDefinition> deploymentArtifacts = new HashMap<>();
1603 ArtifactDefinition deploymentArtifactToUpdate = new ArtifactDefinition();
1604 deploymentArtifactToUpdate.setMandatory(false);
1605 deploymentArtifactToUpdate.setArtifactName(deploymentArtifactToUpdateFileName);
1606 deploymentArtifactToUpdate.setArtifactType("SNMP_POLL");
1607 deploymentArtifactToUpdate.setPayload(oldPayloadData);
1608 deploymentArtifactToUpdate
1609 .setArtifactChecksum(GeneralUtility.calculateMD5Base64EncodedByByteArray(oldPayloadData));
1611 ArtifactDefinition deploymentArtifactToDelete = new ArtifactDefinition();
1612 deploymentArtifactToDelete.setMandatory(false);
1613 deploymentArtifactToDelete.setArtifactName(deploymentArtifactToDeleteFileName);
1614 deploymentArtifactToDelete.setArtifactType("SNMP_TRAP");
1615 deploymentArtifactToDelete.setPayload(oldPayloadData);
1616 deploymentArtifactToDelete
1617 .setArtifactChecksum(GeneralUtility.calculateMD5Base64EncodedByByteArray(oldPayloadData));
1619 ArtifactDefinition deploymentArtifactToIgnore = new ArtifactDefinition();
1621 deploymentArtifacts.put(ValidationUtils.normalizeArtifactLabel(deploymentArtifactToUpdate.getArtifactName()),
1622 deploymentArtifactToUpdate);
1623 deploymentArtifacts.put(ValidationUtils.normalizeArtifactLabel(deploymentArtifactToDelete.getArtifactName()),
1624 deploymentArtifactToDelete);
1625 deploymentArtifacts.put("ignore", deploymentArtifactToIgnore);
1627 Map<String, ArtifactDefinition> artifacts = new HashMap<>();
1629 ArtifactDefinition artifactToUpdate = new ArtifactDefinition();
1630 artifactToUpdate.setMandatory(false);
1631 artifactToUpdate.setArtifactName(artifactInfoToUpdateFileName);
1632 artifactToUpdate.setArtifactType("SNMP_POLL");
1633 artifactToUpdate.setPayload(oldPayloadData);
1634 artifactToUpdate.setArtifactChecksum(GeneralUtility.calculateMD5Base64EncodedByByteArray(oldPayloadData));
1636 ArtifactDefinition artifactToDelete = new ArtifactDefinition();
1637 artifactToDelete.setMandatory(false);
1638 artifactToDelete.setArtifactName(artifactInfoToDeleteFileName);
1639 artifactToDelete.setArtifactType("SNMP_TRAP");
1640 artifactToDelete.setPayload(oldPayloadData);
1641 artifactToDelete.setArtifactChecksum(GeneralUtility.calculateMD5Base64EncodedByByteArray(oldPayloadData));
1642 artifactToDelete.setIsFromCsar(true);
1644 ArtifactDefinition artifactToNotDelete = new ArtifactDefinition();
1645 artifactToNotDelete.setMandatory(false);
1646 artifactToNotDelete.setArtifactName(artifactInfoToNotDeleteFileName);
1647 artifactToNotDelete.setArtifactType("SNMP_TRAP");
1648 artifactToNotDelete.setPayload(oldPayloadData);
1649 artifactToNotDelete.setArtifactChecksum(GeneralUtility.calculateMD5Base64EncodedByByteArray(oldPayloadData));
1650 artifactToNotDelete.setIsFromCsar(false);
1652 ArtifactDefinition artifactToIgnore = new ArtifactDefinition();
1654 artifacts.put(ValidationUtils.normalizeArtifactLabel(artifactToUpdate.getArtifactName()), artifactToUpdate);
1655 artifacts.put(ValidationUtils.normalizeArtifactLabel(artifactToDelete.getArtifactName()), artifactToDelete);
1656 artifacts.put(ValidationUtils.normalizeArtifactLabel(artifactToNotDelete.getArtifactName()),
1657 artifactToNotDelete);
1658 artifacts.put("ignore", artifactToIgnore);
1660 resource.setDeploymentArtifacts(deploymentArtifacts);
1661 resource.setArtifacts(artifacts);
1663 List<NonMetaArtifactInfo> artifactPathAndNameList = new ArrayList<>();
1664 NonMetaArtifactInfo deploymentArtifactInfoToUpdate = new NonMetaArtifactInfo(
1665 deploymentArtifactToUpdate.getArtifactName(), null,
1666 ArtifactTypeEnum.findType(deploymentArtifactToUpdate.getArtifactType()),
1667 ArtifactGroupTypeEnum.DEPLOYMENT, newPayloadData, deploymentArtifactToUpdate.getArtifactName(), false);
1669 NonMetaArtifactInfo informationalArtifactInfoToUpdate = new NonMetaArtifactInfo(
1670 artifactToUpdate.getArtifactName(), null, ArtifactTypeEnum.findType(artifactToUpdate.getArtifactType()),
1671 ArtifactGroupTypeEnum.DEPLOYMENT, newPayloadData, artifactToUpdate.getArtifactName(), false);
1673 NonMetaArtifactInfo informationalArtifactInfoToUpdateFromCsar = new NonMetaArtifactInfo(
1674 artifactToUpdate.getArtifactName(), null, ArtifactTypeEnum.findType(artifactToUpdate.getArtifactType()),
1675 ArtifactGroupTypeEnum.INFORMATIONAL, newPayloadData, artifactToUpdate.getArtifactName(), true);
1677 NonMetaArtifactInfo deploymentArtifactInfoToUpdateFromCsar = new NonMetaArtifactInfo(
1678 artifactToUpdate.getArtifactName(), null, ArtifactTypeEnum.findType(artifactToUpdate.getArtifactType()),
1679 ArtifactGroupTypeEnum.DEPLOYMENT, newPayloadData, artifactToUpdate.getArtifactName(), true);
1681 NonMetaArtifactInfo deploymentArtifactInfoToCreate = new NonMetaArtifactInfo(deploymentArtifactToCreateFileName,
1682 null, ArtifactTypeEnum.OTHER, ArtifactGroupTypeEnum.DEPLOYMENT, newPayloadData,
1683 deploymentArtifactToCreateFileName, false);
1685 NonMetaArtifactInfo informationalArtifactInfoToCreate = new NonMetaArtifactInfo(artifactInfoToCreateFileName,
1686 null, ArtifactTypeEnum.OTHER, ArtifactGroupTypeEnum.INFORMATIONAL, newPayloadData,
1687 artifactInfoToCreateFileName, false);
1689 artifactPathAndNameList.add(deploymentArtifactInfoToUpdate);
1690 artifactPathAndNameList.add(informationalArtifactInfoToUpdate);
1691 artifactPathAndNameList.add(deploymentArtifactInfoToCreate);
1692 artifactPathAndNameList.add(informationalArtifactInfoToCreate);
1693 artifactPathAndNameList.add(informationalArtifactInfoToUpdateFromCsar);
1694 artifactPathAndNameList.add(deploymentArtifactInfoToUpdateFromCsar);
1696 Object[] argObjects = { resource, artifactPathAndNameList, user };
1697 Class[] argClasses = { Resource.class, List.class, User.class };
1699 Method method = targetClass.getDeclaredMethod(methodName, argClasses);
1700 method.setAccessible(true);
1701 Either<EnumMap<ArtifactOperationEnum, List<NonMetaArtifactInfo>>, ResponseFormat> findVfCsarArtifactsToHandleRes = (Either<EnumMap<ArtifactOperationEnum, List<NonMetaArtifactInfo>>, ResponseFormat>) method
1702 .invoke(bl, argObjects);
1703 assertTrue(findVfCsarArtifactsToHandleRes.isLeft());
1704 EnumMap<ArtifactOperationEnum, List<NonMetaArtifactInfo>> foundVfArtifacts = findVfCsarArtifactsToHandleRes
1706 assertTrue(foundVfArtifacts.get(ArtifactOperationEnum.CREATE).size() == 4);
1707 assertTrue(foundVfArtifacts.get(ArtifactOperationEnum.UPDATE).size() == 4);
1708 assertTrue(foundVfArtifacts.get(ArtifactOperationEnum.DELETE).size() == 1);
1710 } catch (Exception e) {
1711 e.printStackTrace();
1716 public void testVFGeneratedInputs() {
1717 validateUserRoles(Role.ADMIN, Role.DESIGNER);
1718 Resource resource = createVF();
1719 List<InputDefinition> inputs = resource.getInputs();
1720 assertTrue(8 == inputs.size());
1721 for (InputDefinition input : inputs) {
1722 assertNotNull(input.getOwnerId());
1724 assertTrue(resource.getDerivedFromGenericType().equals(genericVF.getToscaResourceName()));
1725 assertTrue(resource.getDerivedFromGenericVersion().equals(genericVF.getVersion()));
1729 public void testCRGeneratedInputs() {
1730 validateUserRoles(Role.ADMIN, Role.DESIGNER);
1731 Resource resource = createCR();
1732 List<InputDefinition> inputs = resource.getInputs();
1733 assertTrue(5 == inputs.size());
1734 for (InputDefinition input : inputs) {
1735 assertNotNull(input.getOwnerId());
1737 assertTrue(resource.getDerivedFromGenericType().equals(genericCR.getToscaResourceName()));
1738 assertTrue(resource.getDerivedFromGenericVersion().equals(genericCR.getVersion()));
1742 public void testVFUpdateGenericInputsToLatestOnCheckout() {
1743 validateUserRoles(Role.ADMIN, Role.DESIGNER);
1744 // create a VF that is derived from generic version 1.0
1745 Resource resource = createVF();
1746 // create a new generic version without properties
1747 genericVF.setVersion("2.0");
1748 genericVF.setProperties(null);
1749 String currentDerivedFromVersion = resource.getDerivedFromGenericVersion();
1750 List<InputDefinition> currentInputs = resource.getInputs();
1751 // verify previous inputs ownerId fields exist - user may not delete
1753 assertTrue(8 == currentInputs.stream().filter(p -> null != p.getOwnerId()).collect(Collectors.toList()).size());
1754 Either<Boolean, ResponseFormat> upgradeToLatestGeneric = bl.shouldUpgradeToLatestGeneric(resource);
1756 assertTrue(upgradeToLatestGeneric.isLeft());
1757 // verify update required and valid
1758 assertTrue(upgradeToLatestGeneric.left().value());
1759 // verify version was upgraded
1760 assertFalse(resource.getDerivedFromGenericVersion().equals(currentDerivedFromVersion));
1761 // verify inputs were not deleted
1762 assertTrue(8 == resource.getInputs().size());
1763 // verify inputs ownerId fields were removed - user may delete/edit
1765 assertTrue(8 == resource.getInputs().stream().filter(p -> null == p.getOwnerId()).collect(Collectors.toList())
1770 public void testVFUpdateGenericInputsToLatestOnCheckoutNotPerformed() {
1772 // create a VF that is derived from generic version 1.0
1773 validateUserRoles(Role.ADMIN, Role.DESIGNER);
1774 Resource resource = createVF();
1776 // add an input to the VF
1777 PropertyDefinition newProp = new PropertyDefinition();
1778 newProp.setType("integer");
1779 newProp.setName("newProp");
1780 resource.getInputs().add(new InputDefinition(newProp));
1782 // create a new generic version with a new property which has the same
1783 // name as a user defined input on the VF with a different type
1784 genericVF.setVersion("2.0");
1785 newProp.setType("string");
1786 genericVF.setProperties(new ArrayList<PropertyDefinition>());
1787 genericVF.getProperties().add(newProp);
1788 when(genericTypeBusinessLogic.fetchDerivedFromGenericType(resource)).thenReturn(Either.left(genericVF));
1789 when(genericTypeBusinessLogic.convertGenericTypePropertiesToInputsDefintion(genericVF.getProperties(),
1790 genericVF.getUniqueId())).thenCallRealMethod();
1791 String currentDerivedFromVersion = resource.getDerivedFromGenericVersion();
1792 assertTrue(8 == resource.getInputs().stream().filter(p -> null != p.getOwnerId()).collect(Collectors.toList())
1794 Either<Boolean, ResponseFormat> upgradeToLatestGeneric = bl.shouldUpgradeToLatestGeneric(resource);
1796 assertTrue(upgradeToLatestGeneric.isLeft());
1797 // verify update is invalid an void
1798 assertFalse(upgradeToLatestGeneric.left().value());
1799 // verify version was not upgraded
1800 assertTrue(resource.getDerivedFromGenericVersion().equals(currentDerivedFromVersion));
1801 // verify inputs were not removed
1802 assertTrue(9 == resource.getInputs().size());
1803 // verify user defined input exists
1804 assertTrue(1 == resource.getInputs().stream().filter(p -> null == p.getOwnerId()).collect(Collectors.toList())
1806 assertTrue(resource.getInputs().stream().filter(p -> null == p.getOwnerId()).findAny().get().getType()
1807 .equals("integer"));
1811 public void testPNFGeneratedInputsNoGeneratedInformationalArtifacts() {
1812 validateUserRoles(Role.ADMIN, Role.DESIGNER);
1813 Resource resource = createPNF();
1814 List<InputDefinition> inputs = resource.getInputs();
1815 assertTrue(3 == inputs.size());
1816 for (InputDefinition input : inputs) {
1817 assertNotNull(input.getOwnerId());
1819 assertTrue(resource.getDerivedFromGenericType().equals(genericPNF.getToscaResourceName()));
1820 assertTrue(resource.getDerivedFromGenericVersion().equals(genericPNF.getVersion()));
1821 assertTrue(0 == resource.getArtifacts().size());
1824 private Resource createVF() {
1826 genericVF = setupGenericTypeMock(GENERIC_VF_NAME);
1827 when(toscaOperationFacade.getLatestCertifiedNodeTypeByToscaResourceName(GENERIC_VF_NAME))
1828 .thenReturn(Either.left(genericVF));
1829 Resource resource = createResourceObject(true);
1830 resource.setDerivedFrom(null);
1831 resource.setResourceType(ResourceTypeEnum.VF);
1832 when(toscaOperationFacade.createToscaComponent(resource)).thenReturn(Either.left(resource));
1833 when(genericTypeBusinessLogic.fetchDerivedFromGenericType(resource)).thenReturn(Either.left(genericVF));
1834 when(genericTypeBusinessLogic.generateInputsFromGenericTypeProperties(genericVF)).thenCallRealMethod();
1835 when(genericTypeBusinessLogic.convertGenericTypePropertiesToInputsDefintion(genericVF.getProperties(),
1836 resource.getUniqueId())).thenCallRealMethod();
1837 Either<Resource, ResponseFormat> createResponse = bl.createResource(resource,
1838 AuditingActionEnum.CREATE_RESOURCE, user, null, null);
1839 assertTrue(createResponse.isLeft());
1840 return createResponse.left().value();
1843 private Resource createCR() {
1845 genericCR = setupGenericTypeMock(GENERIC_CR_NAME);
1846 when(toscaOperationFacade.getLatestCertifiedNodeTypeByToscaResourceName(GENERIC_CR_NAME))
1847 .thenReturn(Either.left(genericCR));
1848 Resource resource = createResourceObject(true);
1849 resource.setDerivedFrom(null);
1850 resource.setResourceType(ResourceTypeEnum.CR);
1851 when(toscaOperationFacade.createToscaComponent(resource)).thenReturn(Either.left(resource));
1852 when(genericTypeBusinessLogic.fetchDerivedFromGenericType(resource)).thenReturn(Either.left(genericCR));
1853 when(genericTypeBusinessLogic.generateInputsFromGenericTypeProperties(genericCR)).thenCallRealMethod();
1854 when(genericTypeBusinessLogic.convertGenericTypePropertiesToInputsDefintion(genericCR.getProperties(),
1855 resource.getUniqueId())).thenCallRealMethod();
1856 Either<Resource, ResponseFormat> createResponse = bl.createResource(resource,
1857 AuditingActionEnum.CREATE_RESOURCE, user, null, null);
1858 assertTrue(createResponse.isLeft());
1859 return createResponse.left().value();
1862 private Resource createPNF() {
1864 genericPNF = setupGenericTypeMock(GENERIC_PNF_NAME);
1865 when(toscaOperationFacade.getLatestCertifiedNodeTypeByToscaResourceName(GENERIC_PNF_NAME))
1866 .thenReturn(Either.left(genericPNF));
1867 Resource resource = createResourceObject(true);
1868 resource.setDerivedFrom(null);
1869 resource.setResourceType(ResourceTypeEnum.PNF);
1870 when(toscaOperationFacade.createToscaComponent(resource)).thenReturn(Either.left(resource));
1871 when(genericTypeBusinessLogic.fetchDerivedFromGenericType(resource)).thenReturn(Either.left(genericPNF));
1872 when(genericTypeBusinessLogic.generateInputsFromGenericTypeProperties(genericPNF)).thenCallRealMethod();
1873 when(genericTypeBusinessLogic.convertGenericTypePropertiesToInputsDefintion(genericPNF.getProperties(),
1874 resource.getUniqueId())).thenCallRealMethod();
1875 Either<Resource, ResponseFormat> createResponse = bl.createResource(resource,
1876 AuditingActionEnum.CREATE_RESOURCE, user, null, null);
1877 assertTrue(createResponse.isLeft());
1878 return createResponse.left().value();
1881 private Map<String, String> getGenericPropertiesByToscaName(String toscaName) {
1882 HashMap<String, String> PNFProps = new HashMap<String, String>() {
1884 put("nf_function", "string");
1885 put("nf_role", "string");
1886 put("nf_type", "string");
1890 HashMap<String, String> CRProps = new HashMap<String, String>() {
1893 put("nf_naming_code", "string");
1894 put("nf_naming", "org.openecomp.datatypes.Naming");
1898 HashMap<String, String> VFProps = new HashMap<String, String>() {
1901 put("availability_zone_max_count", "integer");
1902 put("min_instances", "integer");
1903 put("max_instances", "integer");
1907 if (toscaName.contains("PNF"))
1909 if (toscaName.contains("CR"))
1911 if (toscaName.contains("VF"))
1914 return new HashMap<>();
1917 private Resource setupGenericTypeMock(String toscaName) {
1919 Resource genericType = createResourceObject(true);
1920 genericType.setVersion("1.0");
1921 genericType.setToscaResourceName(toscaName);
1922 List<PropertyDefinition> genericProps = new ArrayList<>();
1923 Map<String, String> genericPropsMap = getGenericPropertiesByToscaName(toscaName);
1924 genericPropsMap.forEach((name, type) -> {
1925 PropertyDefinition prop = new PropertyDefinition();
1928 genericProps.add(prop);
1931 genericType.setProperties(genericProps);
1935 private void validateUserRoles(Role... roles) {
1936 List<Role> listOfRoles = Stream.of(roles).collect(Collectors.toList());
1937 when(userValidations.validateUserRole(user, listOfRoles)).thenReturn(Either.left(true));
1940 private ResourceBusinessLogic createTestSubject() {
1945 public void testGetAllCertifiedResources() throws Exception {
1946 ResourceBusinessLogic testSubject;
1947 boolean getAbstract = false;
1948 HighestFilterEnum highestFilter = HighestFilterEnum.HIGHEST_ONLY;
1949 String userId = user.getUserId();
1950 Either<List<Resource>, ResponseFormat> result;
1951 Resource resource = createResourceObject(true);
1955 Either<List<Resource>, StorageOperationStatus> getLatestResult = Either.right(StorageOperationStatus.OK);
1957 when(toscaOperationFacade.getAllCertifiedResources(false, true)).thenReturn(getLatestResult);
1958 testSubject = createTestSubject();
1959 result = testSubject.getAllCertifiedResources(getAbstract, highestFilter, userId);
1963 public void testGetApplicationDataTypeCache() throws Exception {
1964 ResourceBusinessLogic testSubject;
1965 ApplicationDataTypeCache result;
1968 testSubject = createTestSubject();
1969 result = testSubject.getApplicationDataTypeCache();
1973 public void testGetArtifactsManager() throws Exception {
1974 ResourceBusinessLogic testSubject;
1975 ArtifactsBusinessLogic result;
1978 testSubject = createTestSubject();
1979 result = testSubject.getArtifactsManager();
1983 public void testGetCacheManagerOperation() throws Exception {
1984 ResourceBusinessLogic testSubject;
1985 ICacheMangerOperation result;
1988 testSubject = createTestSubject();
1989 result = testSubject.getCacheManagerOperation();
1993 public void testGetCapabilityTypeOperation() throws Exception {
1994 ResourceBusinessLogic testSubject;
1995 ICapabilityTypeOperation result;
1998 testSubject = createTestSubject();
1999 result = testSubject.getCapabilityTypeOperation();
2003 public void testGetComponentInstanceBL() throws Exception {
2004 ResourceBusinessLogic testSubject;
2005 ComponentInstanceBusinessLogic result;
2008 testSubject = createTestSubject();
2009 result = testSubject.getComponentInstanceBL();
2013 public void testGetComponentInstancesFilteredByPropertiesAndInputs() throws Exception {
2014 ResourceBusinessLogic testSubject;
2015 String componentId = "";
2016 ComponentTypeEnum componentTypeEnum = null;
2018 String searchText = "";
2019 Either<List<ComponentInstance>, ResponseFormat> result;
2022 testSubject = createTestSubject();
2023 result = testSubject.getComponentInstancesFilteredByPropertiesAndInputs(componentId, componentTypeEnum, userId,
2028 public void testGetComponentsUtils() throws Exception {
2029 ResourceBusinessLogic testSubject;
2030 ComponentsUtils result;
2033 testSubject = createTestSubject();
2034 result = testSubject.getComponentsUtils();
2038 public void testGetElementDao() throws Exception {
2039 ResourceBusinessLogic testSubject;
2040 IElementOperation result;
2043 testSubject = createTestSubject();
2044 result = testSubject.getElementDao();
2048 public void testGetCsarOperation() throws Exception {
2049 ResourceBusinessLogic testSubject;
2050 CsarOperation result;
2053 testSubject = createTestSubject();
2054 result = testSubject.getCsarOperation();
2058 public void testGetLatestResourceFromCsarUuid() throws Exception {
2059 ResourceBusinessLogic testSubject;
2060 Resource resource = createResourceObject(true);
2061 String csarUuid = "";
2062 Either<Resource, ResponseFormat> result;
2064 Either<Resource, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
2065 when(toscaOperationFacade.getLatestComponentByCsarOrName(ComponentTypeEnum.RESOURCE, csarUuid, ""))
2066 .thenReturn(eitherUpdate);
2069 testSubject = createTestSubject();
2070 result = testSubject.getLatestResourceFromCsarUuid(csarUuid, user);
2074 public void testGetLifecycleBusinessLogic() throws Exception {
2075 ResourceBusinessLogic testSubject;
2076 LifecycleBusinessLogic result;
2079 testSubject = createTestSubject();
2080 result = testSubject.getLifecycleBusinessLogic();
2084 public void testGetResource() throws Exception {
2085 ResourceBusinessLogic testSubject;
2086 Resource resource = createResourceObject(true);
2087 String resourceId = resource.getUniqueId();
2088 Either<Resource, ResponseFormat> result;
2090 Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
2091 when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
2094 testSubject = createTestSubject();
2095 result = testSubject.getResource(resourceId, user);
2099 public void testGetResourceByNameAndVersion() throws Exception {
2100 ResourceBusinessLogic testSubject;
2101 Resource resource = createResourceObject(true);
2102 String resourceName = resource.getName();
2103 String resourceVersion = resource.getVersion();
2104 String userId = user.getUserId();
2105 Either<Resource, ResponseFormat> result;
2107 when(toscaOperationFacade.getComponentByNameAndVersion(ComponentTypeEnum.RESOURCE, resourceName,
2108 resourceVersion)).thenReturn(Either.left(resource));
2111 testSubject = createTestSubject();
2112 result = testSubject.getResourceByNameAndVersion(resourceName, resourceVersion, userId);
2116 public void testGetUserAdmin() throws Exception {
2117 ResourceBusinessLogic testSubject;
2118 IUserBusinessLogic result;
2121 testSubject = createTestSubject();
2122 result = testSubject.getUserAdmin();
2126 public void testHandleNodeTypeArtifacts() throws Exception {
2127 ResourceBusinessLogic testSubject;
2128 Resource nodeTypeResource = null;
2129 Map<ArtifactOperationEnum, List<ArtifactDefinition>> nodeTypeArtifactsToHandle = null;
2130 List<ArtifactDefinition> createdArtifacts = null;
2132 boolean inTransaction = false;
2133 boolean ignoreLifecycleState = false;
2134 Either<List<ArtifactDefinition>, ResponseFormat> result;
2137 testSubject = createTestSubject();
2138 result = testSubject.handleNodeTypeArtifacts(nodeTypeResource, nodeTypeArtifactsToHandle, createdArtifacts,
2139 user, inTransaction, ignoreLifecycleState);
2144 public void testIsResourceExist() throws Exception {
2145 ResourceBusinessLogic testSubject;
2146 Resource resource = createResourceObject(true);
2147 String resourceName = resource.getName();
2151 Either<Component, StorageOperationStatus> getLatestResult = Either.right(StorageOperationStatus.NOT_FOUND);
2152 when(toscaOperationFacade.getLatestByName(resource.getName())).thenReturn(getLatestResult);
2153 testSubject = createTestSubject();
2154 result = testSubject.isResourceExist(resourceName);
2158 public void testPropagateStateToCertified() throws Exception {
2159 ResourceBusinessLogic testSubject;
2160 Resource resource = createResourceObject(true);
2162 LifecycleChangeInfoWithAction lifecycleChangeInfo = null;
2163 boolean inTransaction = false;
2164 boolean needLock = false;
2165 boolean forceCertificationAllowed = false;
2166 Either<Resource, ResponseFormat> result;
2169 testSubject = createTestSubject();
2170 result = testSubject.propagateStateToCertified(user, resource, lifecycleChangeInfo, inTransaction, needLock,
2171 forceCertificationAllowed);
2175 public void testSetApplicationDataTypeCache() throws Exception {
2176 ResourceBusinessLogic testSubject;
2177 ApplicationDataTypeCache applicationDataTypeCache = null;
2180 testSubject = createTestSubject();
2181 testSubject.setApplicationDataTypeCache(applicationDataTypeCache);
2185 public void testSetArtifactsManager() throws Exception {
2186 ResourceBusinessLogic testSubject;
2187 ArtifactsBusinessLogic artifactsManager = null;
2190 testSubject = createTestSubject();
2191 testSubject.setArtifactsManager(artifactsManager);
2195 public void testSetCacheManagerOperation() throws Exception {
2196 ResourceBusinessLogic testSubject;
2197 ICacheMangerOperation cacheManagerOperation = null;
2200 testSubject = createTestSubject();
2201 testSubject.setCacheManagerOperation(cacheManagerOperation);
2205 public void testSetCapabilityTypeOperation() throws Exception {
2206 ResourceBusinessLogic testSubject;
2207 ICapabilityTypeOperation capabilityTypeOperation = null;
2210 testSubject = createTestSubject();
2211 testSubject.setCapabilityTypeOperation(capabilityTypeOperation);
2215 public void testSetComponentsUtils() throws Exception {
2216 ResourceBusinessLogic testSubject;
2217 ComponentsUtils componentsUtils = null;
2220 testSubject = createTestSubject();
2221 testSubject.setComponentsUtils(componentsUtils);
2225 public void testSetDeploymentArtifactsPlaceHolder() throws Exception {
2226 ResourceBusinessLogic testSubject;
2227 Component component = createResourceObject(true);
2231 testSubject = createTestSubject();
2232 testSubject.setDeploymentArtifactsPlaceHolder(component, user);
2236 public void testSetCsarOperation() throws Exception {
2237 ResourceBusinessLogic testSubject;
2238 CsarOperation csarOperation = null;
2241 testSubject = createTestSubject();
2242 testSubject.setCsarOperation(csarOperation);
2246 public void testSetElementDao() throws Exception {
2247 ResourceBusinessLogic testSubject;
2248 IElementOperation elementDao = null;
2251 testSubject = createTestSubject();
2252 testSubject.setElementDao(elementDao);
2256 public void testSetInterfaceOperation() throws Exception {
2257 ResourceBusinessLogic testSubject;
2258 InterfaceOperation interfaceOperation = null;
2261 testSubject = createTestSubject();
2262 testSubject.setInterfaceOperation(interfaceOperation);
2266 public void testSetInterfaceTypeOperation() throws Exception {
2267 ResourceBusinessLogic testSubject;
2268 IInterfaceLifecycleOperation interfaceTypeOperation = null;
2271 testSubject = createTestSubject();
2272 testSubject.setInterfaceTypeOperation(interfaceTypeOperation);
2276 public void testSetLifecycleManager() throws Exception {
2277 ResourceBusinessLogic testSubject;
2278 LifecycleBusinessLogic lifecycleBusinessLogic = null;
2281 testSubject = createTestSubject();
2282 testSubject.setLifecycleManager(lifecycleBusinessLogic);
2286 public void testSetPropertyOperation() throws Exception {
2287 ResourceBusinessLogic testSubject;
2288 IPropertyOperation propertyOperation = null;
2291 testSubject = createTestSubject();
2292 testSubject.setPropertyOperation(propertyOperation);
2296 public void testSetUserAdmin() throws Exception {
2297 ResourceBusinessLogic testSubject;
2298 UserBusinessLogic userAdmin = null;
2301 testSubject = createTestSubject();
2302 testSubject.setUserAdmin(userAdmin);
2306 public void testShouldUpgradeToLatestDerived() throws Exception {
2307 ResourceBusinessLogic testSubject;
2308 Resource clonedComponent = createResourceObject(true);
2310 Either<Component, ActionStatus> result;
2312 Either<Component, StorageOperationStatus> getLatestResult = Either.right(StorageOperationStatus.OK);
2313 when(toscaOperationFacade.shouldUpgradeToLatestDerived(clonedComponent)).thenReturn(getLatestResult);
2316 testSubject = createTestSubject();
2317 result = testSubject.shouldUpgradeToLatestDerived(clonedComponent);
2321 public void testUpdateResourceMetadata() throws Exception {
2322 ResourceBusinessLogic testSubject;
2323 String resourceIdToUpdate = "";
2324 Resource newResource = createResourceObject(true);
2325 Resource currentResource = createResourceObject(true);
2326 boolean inTransaction = false;
2327 Either<Resource, ResponseFormat> result;
2330 Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(newResource));
2331 when(toscaOperationFacade.getToscaElement(newResource.getUniqueId())).thenReturn(eitherUpdate);
2332 testSubject = createTestSubject();
2333 result = testSubject.updateResourceMetadata(resourceIdToUpdate, newResource, currentResource, user,
2338 public void testValidateAndUpdateResourceFromCsar() throws Exception {
2339 ResourceBusinessLogic testSubject;
2340 Resource resource = createResourceObject(true);
2342 Map<String, byte[]> csarUIPayload = null;
2343 String payloadName = "";
2344 String resourceUniqueId = "";
2345 Either<Resource, ResponseFormat> result;
2348 testSubject = createTestSubject();
2350 result = testSubject.validateAndUpdateResourceFromCsar(resource, user, csarUIPayload, payloadName,
2354 testSubject = createTestSubject();
2356 result = testSubject.validateAndUpdateResourceFromCsar(resource, user, csarUIPayload, payloadName,
2361 public void testValidateDerivedFromNotEmpty() throws Exception {
2362 ResourceBusinessLogic testSubject;
2363 Resource resource = createResourceObject(true);
2364 AuditingActionEnum actionEnum = AuditingActionEnum.ADD_ECOMP_USER_CREDENTIALS;
2365 Either<Boolean, ResponseFormat> result;
2368 testSubject = createTestSubject();
2369 result = testSubject.validateDerivedFromNotEmpty(user, resource, actionEnum);
2373 public void testValidateResourceBeforeCreate() throws Exception {
2374 ResourceBusinessLogic testSubject;
2375 Resource resource = createResourceObject(true);
2377 AuditingActionEnum actionEnum = AuditingActionEnum.ADD_CATEGORY;
2378 boolean inTransaction = false;
2379 CsarInfo csarInfo = null;
2380 Either<Resource, ResponseFormat> result;
2383 testSubject = createTestSubject();
2384 result = testSubject.validateResourceBeforeCreate(resource, user, actionEnum, inTransaction, csarInfo);
2388 public void testValidateResourceCreationFromNodeType() throws Exception {
2389 ResourceBusinessLogic testSubject;
2390 Resource resource = createResourceObject(true);
2392 User creator = user;
2393 Either<Boolean, ResponseFormat> result;
2396 testSubject = createTestSubject();
2397 result = testSubject.validateResourceCreationFromNodeType(resource, creator);
2401 public void testValidatePropertiesDefaultValues() throws Exception {
2402 ResourceBusinessLogic testSubject;
2403 Resource resource = createResourceObject(true);
2404 Either<Boolean, ResponseFormat> result;
2407 testSubject = createTestSubject();
2408 result = testSubject.validatePropertiesDefaultValues(resource);
2412 public void testValidateResourceNameExists() throws Exception {
2413 ResourceBusinessLogic testSubject;
2414 Resource recource = createResourceObject(true);
2415 String resourceName = recource.getName();
2416 ResourceTypeEnum resourceTypeEnum = ResourceTypeEnum.VF;
2417 ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.RESOURCE;
2418 String userId = user.getUserId();
2419 Either<Map<String, Boolean>, ResponseFormat> result;
2423 Either<Boolean, StorageOperationStatus> dataModelResponse = Either.left(true);
2424 when(toscaOperationFacade.validateComponentNameUniqueness(resourceName, resourceTypeEnum, componentTypeEnum))
2425 .thenReturn(dataModelResponse);
2426 testSubject = createTestSubject();
2427 result = testSubject.validateResourceNameExists(resourceName, resourceTypeEnum, userId);
2431 public void testValidateVendorReleaseName() throws Exception {
2432 ResourceBusinessLogic testSubject;
2433 String vendorRelease = "";
2434 Either<Boolean, ResponseFormat> result;
2437 testSubject = createTestSubject();
2438 vendorRelease = null;
2439 result = testSubject.validateVendorReleaseName(vendorRelease);
2442 testSubject = createTestSubject();
2444 result = testSubject.validateVendorReleaseName(vendorRelease);
2448 public void testValidateVendorReleaseName_1() throws Exception {
2449 ResourceBusinessLogic testSubject;
2450 Resource resource = createResourceObject(true);
2451 AuditingActionEnum actionEnum = null;
2452 Either<Boolean, ResponseFormat> result;
2455 testSubject = createTestSubject();
2456 result = testSubject.validateVendorReleaseName(user, resource, actionEnum);
2460 public void testIsResourceNameEquals() throws Exception {
2461 ResourceBusinessLogic testSubject;
2462 Resource currentResource = createResourceObject(true);
2463 Resource updateInfoResource = createResourceObject(true);
2464 updateInfoResource.setName("name");
2468 testSubject = createTestSubject();
2469 result = Deencapsulation.invoke(testSubject, "isResourceNameEquals",
2470 new Object[] { currentResource, updateInfoResource });
2474 public void testAddCvfcSuffixToResourceName() throws Exception {
2475 ResourceBusinessLogic testSubject;
2476 Resource currentResource = createResourceObject(true);
2477 String resourceName = currentResource.getName();
2481 testSubject = createTestSubject();
2482 result = Deencapsulation.invoke(testSubject, "addCvfcSuffixToResourceName", new Object[] { resourceName });
2487 public void testCreateResource() throws Exception {
2488 ResourceBusinessLogic testSubject;
2489 Resource resource = createResourceObject(true);
2490 AuditingActionEnum auditingAction = null;
2491 Map<String,byte[]> csarUIPayload = null;
2492 String payloadName = "";
2493 Either<Resource,ResponseFormat> result;
2496 testSubject=createTestSubject();
2498 List<Role> listOfRoles = new ArrayList<>();
2499 listOfRoles.add(Role.ADMIN);
2500 listOfRoles.add(Role.DESIGNER);
2501 Either<Boolean, ResponseFormat> validationResult = Either.left(true);
2502 when(userValidations.validateUserRole(user, listOfRoles)).thenReturn(validationResult);
2506 result=testSubject.createResource(resource, auditingAction, user, csarUIPayload, payloadName);
2509 testSubject=createTestSubject();payloadName = "";
2510 result=testSubject.createResource(resource, auditingAction, user, csarUIPayload, payloadName);
2513 testSubject=createTestSubject();payloadName = null;
2514 result=testSubject.createResource(resource, auditingAction, user, csarUIPayload, payloadName);
2517 testSubject=createTestSubject();payloadName = "";
2518 result=testSubject.createResource(resource, auditingAction, user, csarUIPayload, payloadName);
2523 public void testGetElementDao_1() throws Exception {
2524 ResourceBusinessLogic testSubject;IElementOperation result;
2527 testSubject=createTestSubject();result=testSubject.getElementDao();
2530 @Test(expected=UnsupportedOperationException.class)
2531 public void testCreateResource_1() throws Exception {
2532 ResourceBusinessLogic testSubject;
2533 Resource resource = createResourceObject(true);;
2534 AuditingActionEnum auditingAction = AuditingActionEnum.ADD_CATEGORY;
2535 Map<String,byte[]> csarUIPayload = new HashMap<>();
2536 String payloadName = "";
2537 Either<Resource,ResponseFormat> result;
2539 List<Role> listOfRoles = new ArrayList<>();
2540 listOfRoles.add(Role.ADMIN);
2541 listOfRoles.add(Role.DESIGNER);
2542 Either<Boolean, ResponseFormat> validationResult = Either.left(true);
2543 when(userValidations.validateUserRole(user, listOfRoles)).thenReturn(validationResult);
2546 testSubject=createTestSubject();
2547 result=testSubject.createResource(resource, auditingAction, user, csarUIPayload, payloadName);
2553 public void testValidateCsarIsNotAlreadyUsed() throws Exception {
2554 ResourceBusinessLogic testSubject;
2555 Wrapper<ResponseFormat> responseWrapper = new Wrapper<ResponseFormat>();
2556 Resource oldResource = createResourceObject(true);
2557 Resource resource = createResourceObject(true);
2558 String csarUUID = "";
2560 Either<Resource, StorageOperationStatus> resourceLinkedToCsarRes = Either.right(StorageOperationStatus.BAD_REQUEST);
2561 when(toscaOperationFacade.getLatestComponentByCsarOrName(ComponentTypeEnum.RESOURCE, csarUUID, resource.getSystemName()))
2562 .thenReturn(resourceLinkedToCsarRes);
2565 testSubject=createTestSubject();Deencapsulation.invoke(testSubject, "validateCsarIsNotAlreadyUsed", new Object[]{responseWrapper, resource, oldResource, csarUUID, user});
2570 public void testValidateCsarUuidMatching() throws Exception {
2571 ResourceBusinessLogic testSubject;
2572 Wrapper<ResponseFormat> responseWrapper = new Wrapper<ResponseFormat>();
2573 Resource resource = createResourceObject(true);
2574 Resource oldResource = createResourceObject(true);
2575 String csarUUID = "";
2576 String resourceUniqueId = "";
2581 testSubject=createTestSubject();Deencapsulation.invoke(testSubject, "validateCsarUuidMatching", new Object[]{responseWrapper, resource, oldResource, csarUUID, resourceUniqueId, user});
2586 public void testGetResourceByUniqueId() throws Exception {
2587 ResourceBusinessLogic testSubject;
2588 Wrapper<ResponseFormat> responseWrapper = new Wrapper<ResponseFormat>();
2589 Resource resource = createResourceObject(true);
2590 String resourceUniqueId = resource.getUniqueId();
2594 testSubject=createTestSubject();result=Deencapsulation.invoke(testSubject, "getResourceByUniqueId", new Object[]{responseWrapper, resourceUniqueId});
2599 public void testOverrideImmutableMetadata() throws Exception {
2600 ResourceBusinessLogic testSubject;
2601 Resource oldRresource = createResourceObject(true);
2602 Resource resource = createResourceObject(true);
2606 testSubject=createTestSubject();Deencapsulation.invoke(testSubject, "overrideImmutableMetadata", new Object[]{oldRresource, resource});
2611 public void testFindNodeTypesArtifactsToHandle() throws Exception {
2612 ResourceBusinessLogic testSubject;
2613 NodeTypeInfo nodeTypeInfos = new NodeTypeInfo();
2614 Map<String,NodeTypeInfo> nodeTypesInfo = new HashMap<>();
2615 nodeTypesInfo.put("key", nodeTypeInfos);
2617 CsarInfo csarInfo = new CsarInfo("", new User(), "", null, "", false);
2618 Resource oldResource = createResourceObject(true);
2619 Either<Map<String,EnumMap<ArtifactOperationEnum,List<ArtifactDefinition>>>,ResponseFormat> result;
2622 testSubject=createTestSubject();result=Deencapsulation.invoke(testSubject, "findNodeTypesArtifactsToHandle", new Object[]{nodeTypesInfo, csarInfo, oldResource});
2626 @Test(expected=IllegalArgumentException.class)
2627 public void testFindNodeTypeArtifactsToHandle() throws Exception {
2628 ResourceBusinessLogic testSubject;
2629 Resource curNodeType = createResourceObject(true);
2630 ArtifactDefinition artifactDefinition = new ArtifactDefinition();
2631 List<ArtifactDefinition> extractedArtifacts = new ArrayList<>();
2632 extractedArtifacts.add(artifactDefinition);
2633 Either<EnumMap<ArtifactOperationEnum,List<ArtifactDefinition>>,ResponseFormat> result;
2636 testSubject=createTestSubject();result=Deencapsulation.invoke(testSubject, "findNodeTypeArtifactsToHandle", new Object[]{curNodeType, artifactDefinition});
2641 public void testCheckoutResource() throws Exception {
2642 ResourceBusinessLogic testSubject;
2643 Resource resource = createResourceObject(true);
2645 boolean inTransaction = false;
2646 Either<Resource,ResponseFormat> result;
2649 testSubject=createTestSubject();result=Deencapsulation.invoke(testSubject, "checkoutResource", new Object[]{resource, user, inTransaction});
2659 public void testExtractNodeTypes() throws Exception {
2660 ResourceBusinessLogic testSubject;
2661 Map<String,Object> nodes = new HashMap<>();
2663 Map<String,Object> mappedToscaTemplate = new HashMap<>();
2664 mappedToscaTemplate.put("node_types", new Object());
2668 testSubject=createTestSubject();Deencapsulation.invoke(testSubject, "extractNodeTypes", new Object[]{nodes, mappedToscaTemplate});
2672 public void testMarkNestedVfc() throws Exception {
2673 ResourceBusinessLogic testSubject;
2674 Map<String,Object> mappedToscaTemplate = new HashMap<>();
2675 Map<String,NodeTypeInfo> nodeTypesInfo = new HashMap<>();
2679 testSubject=createTestSubject();Deencapsulation.invoke(testSubject, "markNestedVfc", new Object[]{mappedToscaTemplate, nodeTypesInfo});
2684 public void testIsGlobalSubstitute() throws Exception {
2685 ResourceBusinessLogic testSubject;String fileName = "";
2689 testSubject=createTestSubject();result=Deencapsulation.invoke(testSubject, "isGlobalSubstitute", new Object[]{fileName});
2694 public void testValidateAndParseCsar() throws Exception {
2695 ResourceBusinessLogic testSubject;
2696 Resource resource = createResourceObject(true);
2698 String csarUUID = "";
2699 Either<Map<String,byte[]>,StorageOperationStatus> csar = Either.right(StorageOperationStatus.BAD_REQUEST);
2700 Either<ImmutablePair<String,String>,ResponseFormat> result;
2703 testSubject=createTestSubject();result=Deencapsulation.invoke(testSubject, "validateAndParseCsar", new Object[]{resource, user, csarUUID, csar});
2708 public void testValidateResourceBeforeCreate_1() throws Exception {
2709 ResourceBusinessLogic testSubject;
2710 Resource resource = createResourceObject(true);
2712 boolean inTransaction = false;
2713 Either<Resource,ResponseFormat> result;
2715 List<Role> listOfRoles = new ArrayList<>();
2716 listOfRoles.add(Role.ADMIN);
2717 listOfRoles.add(Role.DESIGNER);
2718 Either<Boolean, ResponseFormat> validationResult = Either.left(true);
2719 when(userValidations.validateUserRole(user, listOfRoles)).thenReturn(validationResult);
2722 testSubject=createTestSubject();result=Deencapsulation.invoke(testSubject, "validateResourceBeforeCreate", new Object[]{resource, user, inTransaction});
2729 public void testCreateResourcesFromYamlNodeTypesList() throws Exception {
2730 ResourceBusinessLogic testSubject;
2731 String yamlName = "";
2732 Resource resource = createResourceObject(true);
2733 Map<String,Object> mappedToscaTemplate = new HashMap<>();
2734 boolean needLock = false;
2735 Map<String,EnumMap<ArtifactOperationEnum,List<ArtifactDefinition>>> nodeTypesArtifactsToHandle = new HashMap<>();
2736 List<ArtifactDefinition> nodeTypesNewCreatedArtifacts = new ArrayList<>();
2737 Map<String,NodeTypeInfo> nodeTypesInfo = new HashMap<>();
2738 CsarInfo csarInfo = new CsarInfo("", new User(), "", null, "", false);
2739 Either<Map<String,Resource>,ResponseFormat> result;
2742 testSubject=createTestSubject();result=testSubject.createResourcesFromYamlNodeTypesList(yamlName, resource, mappedToscaTemplate, needLock, nodeTypesArtifactsToHandle, nodeTypesNewCreatedArtifacts, nodeTypesInfo, csarInfo);
2748 public void testFillResourceMetadata() throws Exception {
2749 ResourceBusinessLogic testSubject;
2750 String yamlName = "";
2751 Resource resourceVf = createResourceObject(true);;
2752 String nodeName = "";
2754 Either<UploadResourceInfo,ResponseFormat> result;
2757 testSubject=createTestSubject();result=Deencapsulation.invoke(testSubject, "fillResourceMetadata", new Object[]{yamlName, resourceVf, nodeName, user});
2764 public void testBuildCvfcName() throws Exception {
2765 ResourceBusinessLogic testSubject;
2766 Resource resource = createResourceObject(true);
2767 String resourceVfName = "ResourceResource12";
2768 String nodeName ="org.openecomp.resource.VF.ResourceResource12";
2772 testSubject=createTestSubject();result=Deencapsulation.invoke(testSubject, "buildCvfcName", new Object[]{resourceVfName, nodeName});
2776 public void testUpdateGroupMembersUsingResource() throws Exception {
2777 ResourceBusinessLogic testSubject;
2778 GroupDefinition groupDefinition = new GroupDefinition();
2779 Map<String,GroupDefinition> groups = new HashMap<>();
2780 groups.put("key", groupDefinition);
2781 Resource component = createResourceObject(true);
2782 Either<List<GroupDefinition>,ResponseFormat> result;
2785 testSubject=createTestSubject();
2786 result=Deencapsulation.invoke(testSubject, "updateGroupMembersUsingResource", new Object[]{groups, component});
2791 public void testValidateCyclicGroupsDependencies() throws Exception {
2792 ResourceBusinessLogic testSubject;
2793 GroupDefinition groupDefinition = new GroupDefinition();
2794 Map<String,GroupDefinition> groups = new HashMap<>();
2795 groups.put("key", groupDefinition);
2796 Either<Boolean,ResponseFormat> result;
2799 testSubject=createTestSubject();result=Deencapsulation.invoke(testSubject, "validateCyclicGroupsDependencies", new Object[]{groups});
2804 public void testFillAllGroupMemebersRecursivly() throws Exception {
2805 ResourceBusinessLogic testSubject;
2806 String groupName = "";
2807 GroupDefinition groupDefinition = new GroupDefinition();
2808 Map<String,GroupDefinition> groups = new HashMap<>();
2809 groups.put("key", groupDefinition);
2810 Set<String> allGroupMembers = new HashSet<String>();
2811 allGroupMembers.add("aaa");
2814 testSubject=createTestSubject();Deencapsulation.invoke(testSubject, "fillAllGroupMemebersRecursivly", new Object[]{groupName, groups, allGroupMembers});
2819 public void testIsfillGroupMemebersRecursivlyStopCondition() throws Exception {
2820 ResourceBusinessLogic testSubject;
2821 String groupName = "";
2822 GroupDefinition groupDefinition = new GroupDefinition();
2823 Map<String,GroupDefinition> groups = new HashMap<>();
2824 groups.put("key", groupDefinition);
2825 Set<String> allGroupMembers = new HashSet<String>();
2826 allGroupMembers.add("aaa");
2830 testSubject=createTestSubject();result=Deencapsulation.invoke(testSubject, "isfillGroupMemebersRecursivlyStopCondition", new Object[]{groupName, groups, allGroupMembers});
2838 public void testHandleAndAddExtractedVfcsArtifacts() throws Exception {
2839 ResourceBusinessLogic testSubject;
2840 ArtifactDefinition artifactDefinition = new ArtifactDefinition();
2842 List<ArtifactDefinition> vfcArtifacts = new ArrayList<>();
2843 vfcArtifacts.add(artifactDefinition);
2844 List<ArtifactDefinition> artifactsToAdd = new ArrayList<>();
2845 artifactsToAdd.add(artifactDefinition);
2848 testSubject=createTestSubject();Deencapsulation.invoke(testSubject, "handleAndAddExtractedVfcsArtifacts", new Object[]{vfcArtifacts, artifactsToAdd});
2855 public void testHandleVfCsarArtifacts() throws Exception {
2856 ResourceBusinessLogic testSubject;
2857 Resource resource = createResourceObject(true);
2858 CsarInfo csarInfo = new CsarInfo("", new User(), "", null, "", false);
2859 ArtifactOperationEnum download = ArtifactOperationEnum.CREATE;
2860 ArtifactsBusinessLogic artb = new ArtifactsBusinessLogic();
2862 ArtifactOperationInfo operation = artb.new ArtifactOperationInfo(false, false, download);
2863 List<ArtifactDefinition> createdArtifacts = new ArrayList<>();
2864 boolean shouldLock = false;
2865 boolean inTransaction = false;
2866 Either<Resource,ResponseFormat> result;
2869 testSubject=createTestSubject();result=Deencapsulation.invoke(testSubject, "handleVfCsarArtifacts", new Object[]{resource, csarInfo, createdArtifacts, operation, shouldLock, inTransaction});
2875 public void testIsArtifactDeletionRequired() throws Exception {
2876 ResourceBusinessLogic testSubject;
2877 String artifactId = "";
2878 byte[] artifactFileBytes = new byte[]{' '};
2879 boolean isFromCsar = false;
2883 testSubject=createTestSubject();result=Deencapsulation.invoke(testSubject, "isArtifactDeletionRequired", new Object[]{artifactId, artifactFileBytes, isFromCsar});
2890 public void testValidateArtifactNames() throws Exception {
2891 ResourceBusinessLogic testSubject;
2892 NonMetaArtifactInfo nonMetaArtifactInfo = new NonMetaArtifactInfo(operationId, operationId, null, null, null, operationId, false);
2893 List<NonMetaArtifactInfo> artifactPathAndNameList = new ArrayList<>();
2894 artifactPathAndNameList.add(nonMetaArtifactInfo);
2895 Either<Boolean,String> result;
2898 testSubject=createTestSubject();result=Deencapsulation.invoke(testSubject, "validateArtifactNames", new Object[]{artifactPathAndNameList});
2903 public void testIsNonMetaArtifact() throws Exception {
2904 ResourceBusinessLogic testSubject;
2905 ArtifactDefinition artifact = new ArtifactDefinition();
2909 testSubject=createTestSubject();result=Deencapsulation.invoke(testSubject, "isNonMetaArtifact", new Object[]{artifact});
2914 public void testIsValidArtifactType() throws Exception {
2915 ResourceBusinessLogic testSubject;
2916 ArtifactDefinition artifact = new ArtifactDefinition();
2920 testSubject=createTestSubject();result=Deencapsulation.invoke(testSubject, "isValidArtifactType", new Object[]{artifact});
2925 public void testCreateResourceInstancesRelations() throws Exception {
2926 ResourceBusinessLogic testSubject;
2927 String yamlName = "";
2928 Resource resource = createResourceObject(true);
2929 UploadComponentInstanceInfo uploadComponentInstanceInfo = new UploadComponentInstanceInfo();
2931 Map<String,UploadComponentInstanceInfo> uploadResInstancesMap = new HashMap<>();
2932 uploadResInstancesMap.put("key", uploadComponentInstanceInfo);
2933 Either<Resource,ResponseFormat> result;
2936 testSubject=createTestSubject();
2937 result=Deencapsulation.invoke(testSubject, "createResourceInstancesRelations", new Object[]{user, yamlName, resource, uploadResInstancesMap});
2942 public void testUpdatePropertyValues() throws Exception {
2943 ResourceBusinessLogic testSubject;
2944 List<ComponentInstanceProperty> properties = new ArrayList<>();
2945 Map<String,UploadPropInfo> newProperties = new HashMap<>();
2946 Map<String,DataTypeDefinition> allDataTypes = new HashMap<>();;
2947 Either<Boolean,ResponseFormat> result;
2950 testSubject=createTestSubject();result=Deencapsulation.invoke(testSubject, "updatePropertyValues", new Object[]{properties, newProperties, allDataTypes});
2955 public void testUpdatePropertyValue() throws Exception {
2956 ResourceBusinessLogic testSubject;
2957 ComponentInstanceProperty property = new ComponentInstanceProperty();
2958 UploadPropInfo propertyInfo = new UploadPropInfo();
2959 Map<String,DataTypeDefinition> allDataTypes = new HashMap<>();
2960 Either<String,StorageOperationStatus> result;
2963 testSubject=createTestSubject();
2964 result=Deencapsulation.invoke(testSubject, "updatePropertyValue", new Object[]{property, propertyInfo, allDataTypes});
2969 public void testUpdateCalculatedCapReqWithSubstitutionMappings() throws Exception {
2970 ResourceBusinessLogic testSubject;
2971 Resource resource = createResourceObject(true);
2972 UploadComponentInstanceInfo uploadComponentInstanceInfo = new UploadComponentInstanceInfo();
2973 Map<String,UploadComponentInstanceInfo> uploadResInstancesMap = new HashMap<>();
2974 uploadResInstancesMap.put("key", uploadComponentInstanceInfo);
2976 Either<Resource,StorageOperationStatus> result;
2979 testSubject=createTestSubject();result=Deencapsulation.invoke(testSubject, "updateCalculatedCapReqWithSubstitutionMappings", new Object[]{resource, uploadResInstancesMap});
2984 public void testFillUpdatedInstCapabilitiesRequirements() throws Exception {
2985 ResourceBusinessLogic testSubject;
2986 List<ComponentInstance> componentInstances = new ArrayList<>();
2987 Map<String,UploadComponentInstanceInfo> uploadResInstancesMap = new HashMap<>();
2988 Map<ComponentInstance,Map<String,List<CapabilityDefinition>>> updatedInstCapabilities = new HashMap<>();
2989 Map<ComponentInstance,Map<String,List<RequirementDefinition>>> updatedInstRequirements = new HashMap<>();
2993 testSubject=createTestSubject();Deencapsulation.invoke(testSubject, "fillUpdatedInstCapabilitiesRequirements", new Object[]{componentInstances, uploadResInstancesMap, updatedInstCapabilities, updatedInstRequirements});
2997 public void testAddInputsValuesToRi() throws Exception {
2998 ResourceBusinessLogic testSubject;
2999 UploadComponentInstanceInfo uploadComponentInstanceInfo = new UploadComponentInstanceInfo();
3000 Resource resource = createResourceObject(true);
3001 Resource originResource = createResourceObject(true);;
3002 ComponentInstance currentCompInstance = new ComponentInstance();
3003 String yamlName = "aaa";
3004 Map<String,List<ComponentInstanceInput>> instInputs = new HashMap<>();
3005 Map<String,DataTypeDefinition> allDataTypes = new HashMap<>();
3006 ResponseFormat result;
3009 testSubject=createTestSubject();result=Deencapsulation.invoke(testSubject, "addInputsValuesToRi", new Object[]{uploadComponentInstanceInfo, resource, originResource, currentCompInstance, yamlName, instInputs, allDataTypes});
3017 public void testFindAvailableCapabilityByTypeOrName() throws Exception {
3018 ResourceBusinessLogic testSubject;
3019 RequirementDefinition validReq = new RequirementDefinition();
3020 validReq.setCapability(RESOURCE_NAME);
3021 validReq.setToscaPresentationValue(JsonPresentationFields.CAPAPILITY, null);
3022 ComponentInstance currentCapCompInstance = new ComponentInstance();
3023 Map<String, List<CapabilityDefinition>> capabilities = new HashMap<>();
3024 currentCapCompInstance.setCapabilities(capabilities);
3025 UploadReqInfo uploadReqInfo = new UploadReqInfo();
3026 CapabilityDefinition result;
3029 testSubject=createTestSubject();result=Deencapsulation.invoke(testSubject, "findAvailableCapabilityByTypeOrName", new Object[]{validReq, currentCapCompInstance, uploadReqInfo});
3034 public void testFindAvailableCapability() throws Exception {
3035 ResourceBusinessLogic testSubject;
3036 RequirementDefinition validReq = new RequirementDefinition();
3037 validReq.setCapability(RESOURCE_NAME);
3038 validReq.setToscaPresentationValue(JsonPresentationFields.CAPAPILITY, null);
3039 ComponentInstance currentCapCompInstance = new ComponentInstance();
3040 Map<String, List<CapabilityDefinition>> capabilities = new HashMap<>();
3041 currentCapCompInstance.setCapabilities(capabilities);
3042 UploadReqInfo uploadReqInfo = new UploadReqInfo();
3043 CapabilityDefinition result;
3046 testSubject=createTestSubject();result=Deencapsulation.invoke(testSubject, "findAvailableCapability", new Object[]{validReq, currentCapCompInstance, uploadReqInfo});
3051 public void testFindAviableCapability() throws Exception {
3052 ResourceBusinessLogic testSubject;
3053 RequirementDefinition validReq = new RequirementDefinition();
3054 validReq.setCapability(RESOURCE_NAME);
3055 validReq.setToscaPresentationValue(JsonPresentationFields.CAPAPILITY, null);
3056 ComponentInstance currentCapCompInstance = new ComponentInstance();
3057 Map<String, List<CapabilityDefinition>> capabilities = new HashMap<>();
3058 currentCapCompInstance.setCapabilities(capabilities);
3059 CapabilityDefinition result;
3062 testSubject=createTestSubject();result=Deencapsulation.invoke(testSubject, "findAviableCapability", new Object[]{validReq, currentCapCompInstance});
3073 public void testCreateResourceInstances() throws Exception {
3074 ResourceBusinessLogic testSubject;
3075 String yamlName = "aa";
3076 Resource resource = createResourceObject(true);
3077 Map<String,UploadComponentInstanceInfo> uploadResInstancesMap = new HashMap<>();
3078 boolean inTransaction = false;
3079 boolean needLock = false;
3080 Map<String,Resource> nodeNamespaceMap = new HashMap<>();
3081 Either<Resource,ResponseFormat> result;
3084 testSubject=createTestSubject();
3085 result=Deencapsulation.invoke(testSubject, "createResourceInstances", new Object[]{user, yamlName, resource,uploadResInstancesMap, inTransaction, needLock, nodeNamespaceMap});
3090 public void testGetNamesToUpdate() throws Exception {
3091 ResourceBusinessLogic testSubject;
3092 UploadComponentInstanceInfo nodeTemplateInfo = new UploadComponentInstanceInfo();
3093 Map<String,List<String>> elements = new HashMap<>();
3094 Either<Map<String,String>,ResponseFormat> result;
3097 testSubject=createTestSubject();result=Deencapsulation.invoke(testSubject, "getNamesToUpdate", new Object[]{nodeTemplateInfo, elements});
3102 public void testCreateInputPropList() throws Exception {
3103 ResourceBusinessLogic testSubject;
3104 UploadPropInfo propertyDef = new UploadPropInfo();
3105 List<Object> propValueList = new ArrayList<>();
3109 testSubject=createTestSubject();Deencapsulation.invoke(testSubject, "createInputPropList", new Object[]{propertyDef, propValueList});
3114 public void testCreateGetInputModuleFromMap() throws Exception {
3115 ResourceBusinessLogic testSubject;
3116 String propName = "aaa";
3117 Map<String,Object> propValue = new HashMap<>();;
3118 UploadPropInfo propertyDef = new UploadPropInfo();
3122 testSubject=createTestSubject();Deencapsulation.invoke(testSubject, "createGetInputModuleFromMap", new Object[]{propName, propValue, propertyDef});
3127 public void testValueContainsPattern() throws Exception {
3128 ResourceBusinessLogic testSubject;
3129 Pattern pattern = null;
3130 Object propValue = null;
3134 testSubject=createTestSubject();propValue = null;
3135 result=Deencapsulation.invoke(testSubject, "valueContainsPattern", new Object[]{Pattern.class, Object.class});
3136 Assert.assertEquals(false, result);
3142 public void testCreateCapModuleFromYaml() throws Exception {
3143 ResourceBusinessLogic testSubject;
3144 UploadComponentInstanceInfo nodeTemplateInfo = new UploadComponentInstanceInfo();
3145 Map<String,Object> nodeTemplateJsonMap = new HashMap<>();
3146 Either<Map<String,List<UploadCapInfo>>,ResponseFormat> result;
3149 testSubject=createTestSubject();result=Deencapsulation.invoke(testSubject, "createCapModuleFromYaml", new Object[]{nodeTemplateInfo, nodeTemplateJsonMap});
3157 public void testCreateModuleNodeTemplateCap() throws Exception {
3158 ResourceBusinessLogic testSubject;Object capObject = null;
3159 Either<UploadCapInfo,ResponseFormat> result;
3162 testSubject=createTestSubject();result=Deencapsulation.invoke(testSubject, "createModuleNodeTemplateCap", new Object[]{Object.class});
3167 public void testCreateModuleNodeTemplateReg() throws Exception {
3168 ResourceBusinessLogic testSubject;Object regObject = null;
3169 Either<UploadReqInfo,ResponseFormat> result;
3172 testSubject=createTestSubject();result=Deencapsulation.invoke(testSubject, "createModuleNodeTemplateReg", new Object[]{Object.class});
3178 public void testNodeForceCertification() throws Exception {
3179 ResourceBusinessLogic testSubject;Resource resource = createResourceObject(true);
3181 LifecycleChangeInfoWithAction lifecycleChangeInfo = null;
3182 boolean inTransaction = false;
3183 boolean needLock = false;
3184 Either<Resource,ResponseFormat> result;
3187 testSubject=createTestSubject();result=Deencapsulation.invoke(testSubject, "nodeForceCertification", new Object[]{Resource.class, user, LifecycleChangeInfoWithAction.class, inTransaction, needLock});
3192 public void testCreateResourceByImport() throws Exception {
3193 ResourceBusinessLogic testSubject;
3194 Resource resource = createResourceObject(true);
3196 boolean isNormative = false;
3197 boolean isInTransaction = false;
3198 CsarInfo csarInfo = null;
3199 Either<ImmutablePair<Resource,ActionStatus>,ResponseFormat> result;
3202 testSubject=createTestSubject();result=Deencapsulation.invoke(testSubject, "createResourceByImport", new Object[]{resource, user, isNormative, isInTransaction, CsarInfo.class});
3208 public void testMergeOldResourceMetadataWithNew() throws Exception {
3209 ResourceBusinessLogic testSubject;
3210 Resource oldResource = createResourceObject(true);
3211 Resource newResource = createResourceObject(true);;
3215 testSubject=createTestSubject();Deencapsulation.invoke(testSubject, "mergeOldResourceMetadataWithNew", new Object[]{oldResource, newResource});
3220 public void testPrepareResourceForUpdate() throws Exception {
3221 ResourceBusinessLogic testSubject;
3222 Resource latestResource = createResourceObject(true);;
3224 boolean inTransaction = false;
3225 boolean needLock = false;
3226 Either<Resource,ResponseFormat> result;
3229 testSubject=createTestSubject();result=Deencapsulation.invoke(testSubject, "prepareResourceForUpdate", new Object[]{latestResource, user, inTransaction, needLock});
3234 public void testValidateResourceBeforeCreate_2() throws Exception {
3235 ResourceBusinessLogic testSubject;Resource resource = createResourceObject(true);
3237 AuditingActionEnum actionEnum = null;
3238 boolean inTransaction = false;
3239 CsarInfo csarInfo = null;
3240 Either<Resource,ResponseFormat> result;
3243 testSubject=createTestSubject();result=testSubject.validateResourceBeforeCreate(resource, user, actionEnum, inTransaction, csarInfo);
3248 public void testValidateResourceType() throws Exception {
3249 ResourceBusinessLogic testSubject;
3250 Resource resource = createResourceObject(true);
3251 AuditingActionEnum actionEnum = AuditingActionEnum.ARTIFACT_DOWNLOAD;
3252 Either<Boolean,ResponseFormat> result;
3255 testSubject=createTestSubject();result=Deencapsulation.invoke(testSubject, "validateResourceType", new Object[]{user, resource, actionEnum});
3260 public void testValidateLifecycleTypesCreate() throws Exception {
3261 ResourceBusinessLogic testSubject;
3262 Resource resource = createResourceObject(true);
3263 AuditingActionEnum actionEnum = AuditingActionEnum.ARTIFACT_METADATA_UPDATE;
3264 Either<Boolean,ResponseFormat> result;
3267 testSubject=createTestSubject();result=Deencapsulation.invoke(testSubject, "validateLifecycleTypesCreate", new Object[]{user, resource, actionEnum});
3272 public void testValidateCapabilityTypesCreate() throws Exception {
3273 ResourceBusinessLogic testSubject;
3274 ICapabilityTypeOperation capabilityTypeOperation = new ICapabilityTypeOperation() {
3277 public Either<CapabilityTypeDefinition, StorageOperationStatus> getCapabilityType(String uniqueId,
3278 boolean inTransaction) {
3279 // TODO Auto-generated method stub
3284 public Either<CapabilityTypeDefinition, StorageOperationStatus> getCapabilityType(String uniqueId) {
3285 // TODO Auto-generated method stub
3290 public Either<CapabilityTypeDefinition, StorageOperationStatus> addCapabilityType(
3291 CapabilityTypeDefinition capabilityTypeDefinition, boolean inTransaction) {
3292 // TODO Auto-generated method stub
3297 public Either<CapabilityTypeDefinition, StorageOperationStatus> addCapabilityType(
3298 CapabilityTypeDefinition capabilityTypeDefinition) {
3299 // TODO Auto-generated method stub
3303 Resource resource = createResourceObject(true);
3304 AuditingActionEnum actionEnum = AuditingActionEnum.ARTIFACT_UPLOAD;
3305 boolean inTransaction = false;
3306 Either<Boolean,ResponseFormat> result;
3309 testSubject=createTestSubject();
3310 result=Deencapsulation.invoke(testSubject, "validateCapabilityTypesCreate", new Object[]{user, capabilityTypeOperation, resource, actionEnum, inTransaction});
3314 @Test(expected=UnsupportedOperationException.class)
3315 public void testValidateCapabilityTypeExists() throws Exception {
3316 ResourceBusinessLogic testSubject;
3317 ICapabilityTypeOperation capabilityTypeOperation = new ICapabilityTypeOperation() {
3320 public Either<CapabilityTypeDefinition, StorageOperationStatus> getCapabilityType(String uniqueId,
3321 boolean inTransaction) {
3322 // TODO Auto-generated method stub
3323 return Either.right(StorageOperationStatus.ARTIFACT_NOT_FOUND);
3327 public Either<CapabilityTypeDefinition, StorageOperationStatus> getCapabilityType(String uniqueId) {
3328 // TODO Auto-generated method stub
3329 return Either.right(StorageOperationStatus.ARTIFACT_NOT_FOUND);
3333 public Either<CapabilityTypeDefinition, StorageOperationStatus> addCapabilityType(
3334 CapabilityTypeDefinition capabilityTypeDefinition, boolean inTransaction) {
3335 // TODO Auto-generated method stub
3336 return Either.right(StorageOperationStatus.ARTIFACT_NOT_FOUND);
3340 public Either<CapabilityTypeDefinition, StorageOperationStatus> addCapabilityType(
3341 CapabilityTypeDefinition capabilityTypeDefinition) {
3342 // TODO Auto-generated method stub
3346 Resource resource = createResourceObject(true);
3347 List<?> validationObjects = new ArrayList<>();
3348 AuditingActionEnum actionEnum = AuditingActionEnum.ADD_CATEGORY;
3349 Either<Boolean,ResponseFormat> eitherResult = Either.left(true);
3351 boolean inTransaction = false;
3352 Either<Boolean,ResponseFormat> result;
3355 testSubject=createTestSubject();result=Deencapsulation.invoke(testSubject, "validateCapabilityTypeExists", new Object[]{user, capabilityTypeOperation, resource, validationObjects, actionEnum,eitherResult, type, inTransaction});
3359 public void testCreateResourceTransaction() throws Exception {
3360 ResourceBusinessLogic testSubject;
3361 Resource resource = createResourceObject(true);
3363 boolean isNormative = false;
3364 boolean inTransaction = false;
3365 Either<Resource,ResponseFormat> result;
3368 testSubject=createTestSubject();result=Deencapsulation.invoke(testSubject, "createResourceTransaction", new Object[]{resource, user, isNormative, inTransaction});
3373 public void testCreateArtifactsPlaceHolderData() throws Exception {
3374 ResourceBusinessLogic testSubject;
3375 Resource resource = createResourceObject(true);
3380 testSubject=createTestSubject();Deencapsulation.invoke(testSubject, "createArtifactsPlaceHolderData", new Object[]{resource, user});
3385 public void testSetInformationalArtifactsPlaceHolder() throws Exception {
3386 ResourceBusinessLogic testSubject;
3387 Resource resource = createResourceObject(true);
3392 testSubject=createTestSubject();Deencapsulation.invoke(testSubject, "setInformationalArtifactsPlaceHolder", new Object[]{resource, user});
3397 public void testDeleteResource() throws Exception {
3398 ResourceBusinessLogic testSubject;
3399 Resource resource = createResourceObject(true);
3400 String resourceId = resource.getUniqueId();
3401 ResponseFormat result;
3404 Either<Component, StorageOperationStatus> resourceStatus = Either.right(StorageOperationStatus.BAD_REQUEST);
3405 when(toscaOperationFacade.getToscaElement(resourceId))
3406 .thenReturn(resourceStatus);
3409 testSubject=createTestSubject();result=testSubject.deleteResource(resourceId, user);
3414 public void testDeleteResourceByNameAndVersion() throws Exception {
3415 ResourceBusinessLogic testSubject;
3416 Resource resource = createResourceObject(true);
3417 String resourceName = resource.getName();
3418 String version = resource.getVersion();
3420 ResponseFormat result;
3422 Either<Component, StorageOperationStatus> resourceStatus = Either.right(StorageOperationStatus.BAD_REQUEST);
3423 when(toscaOperationFacade.getComponentByNameAndVersion(ComponentTypeEnum.RESOURCE, resourceName, version))
3424 .thenReturn(resourceStatus);
3426 testSubject=createTestSubject();result=testSubject.deleteResourceByNameAndVersion(resourceName, version, user);
3431 public void testUpdateResourceMetadata_1() throws Exception {
3432 ResourceBusinessLogic testSubject;String resourceIdToUpdate = "";
3433 Resource newResource = createResourceObject(true);;
3434 Resource currentResource = createResourceObject(true);;
3436 boolean inTransaction = false;
3437 Either<Resource,ResponseFormat> result;
3440 testSubject=createTestSubject();result=testSubject.updateResourceMetadata(resourceIdToUpdate, newResource, currentResource, user, inTransaction);
3445 public void testUpdateComponentGroupName() throws Exception {
3446 ResourceBusinessLogic testSubject;
3447 String replacePattern = "";
3449 List<GroupDefinition> oldGroup = new ArrayList<>();
3450 Either<List<GroupDefinition>,Boolean> result;
3453 testSubject=createTestSubject();
3454 result=Deencapsulation.invoke(testSubject, "updateComponentGroupName", new Object[]{replacePattern, with, oldGroup});
3460 public void testIsComponentNameChanged() throws Exception {
3461 ResourceBusinessLogic testSubject;
3462 Resource newResource = createResourceObject(true);
3463 Resource oldResource = createResourceObject(true);
3467 testSubject=createTestSubject();
3468 result=Deencapsulation.invoke(testSubject, "isComponentNameChanged", new Object[]{oldResource, newResource});
3473 public void testValidateResourceFieldsBeforeCreate() throws Exception {
3474 ResourceBusinessLogic testSubject;
3475 Resource resource = createResourceObject(true);
3476 AuditingActionEnum actionEnum = AuditingActionEnum.ACTIVATE_SERVICE_BY_API;
3477 boolean inTransaction = false;
3478 Either<Boolean,ResponseFormat> result;
3481 testSubject=createTestSubject();result=Deencapsulation.invoke(testSubject, "validateResourceFieldsBeforeCreate", new Object[]{user, resource, actionEnum, inTransaction});
3486 public void testValidateResourceFieldsBeforeUpdate() throws Exception {
3487 ResourceBusinessLogic testSubject;
3488 Resource currentResource = createResourceObject(true);
3489 Resource updateInfoResource = createResourceObject(true);
3490 boolean inTransaction = false;
3491 boolean isNested = false;
3492 Either<Boolean,ResponseFormat> result;
3495 testSubject=createTestSubject();result=Deencapsulation.invoke(testSubject, "validateResourceFieldsBeforeUpdate", new Object[]{updateInfoResource, currentResource, inTransaction, isNested});
3500 public void testValidateResourceName() throws Exception {
3501 ResourceBusinessLogic testSubject;
3502 Resource currentResource = createResourceObject(true);;
3503 Resource updateInfoResource = createResourceObject(true);;
3504 boolean hasBeenCertified = false;
3505 boolean isNested = false;
3506 Either<Boolean,ResponseFormat> result;
3509 testSubject=createTestSubject();result=Deencapsulation.invoke(testSubject, "validateResourceName", new Object[]{currentResource, updateInfoResource, hasBeenCertified, isNested});
3514 public void testValidateIcon() throws Exception {
3515 ResourceBusinessLogic testSubject;
3516 Resource currentResource = createResourceObject(true);;
3517 Resource updateInfoResource = createResourceObject(true);;
3518 boolean hasBeenCertified = false;
3519 Either<Boolean,ResponseFormat> result;
3521 Either<Component, StorageOperationStatus> resourceStatus = Either.right(StorageOperationStatus.BAD_REQUEST);
3522 when(toscaOperationFacade.getToscaElement(currentResource.getUniqueId()))
3523 .thenReturn(resourceStatus);
3527 testSubject=createTestSubject();result=Deencapsulation.invoke(testSubject, "validateIcon", new Object[]{currentResource, updateInfoResource, hasBeenCertified});
3532 public void testValidateVendorName() throws Exception {
3533 ResourceBusinessLogic testSubject;
3534 Resource currentResource = createResourceObject(true);
3535 Resource updateInfoResource = createResourceObject(true);
3536 boolean hasBeenCertified = false;
3537 Either<Boolean,ResponseFormat> result;
3540 testSubject=createTestSubject();result=Deencapsulation.invoke(testSubject, "validateVendorName", new Object[]{currentResource, updateInfoResource, hasBeenCertified});
3545 public void testValidateResourceVendorModelNumber() throws Exception {
3546 ResourceBusinessLogic testSubject;
3547 Resource currentResource = createResourceObject(true);;
3548 Resource updateInfoResource = createResourceObject(true);;
3549 Either<Boolean,ResponseFormat> result;
3552 testSubject=createTestSubject();result=Deencapsulation.invoke(testSubject, "validateResourceVendorModelNumber", new Object[]{currentResource, updateInfoResource});
3557 public void testValidateCategory() throws Exception {
3558 ResourceBusinessLogic testSubject;
3559 Resource currentResource = createResourceObject(true);;
3560 Resource updateInfoResource = createResourceObject(true);;
3561 boolean hasBeenCertified = false;
3562 boolean inTransaction = false;
3563 Either<Boolean,ResponseFormat> result;
3566 testSubject=createTestSubject();result=Deencapsulation.invoke(testSubject, "validateCategory", new Object[]{currentResource, updateInfoResource, hasBeenCertified, inTransaction});
3571 public void testValidateDerivedFromDuringUpdate() throws Exception {
3572 ResourceBusinessLogic testSubject;
3573 Resource currentResource = createResourceObject(true);
3574 Resource updateInfoResource = createResourceObject(true);
3575 boolean hasBeenCertified = false;
3576 Either<Boolean,ResponseFormat> result;
3579 testSubject=createTestSubject();result=Deencapsulation.invoke(testSubject, "validateDerivedFromDuringUpdate", new Object[]{currentResource, updateInfoResource, hasBeenCertified});
3584 public void testValidateNestedDerivedFromDuringUpdate() throws Exception {
3585 ResourceBusinessLogic testSubject;
3586 Resource currentResource = createResourceObject(true);
3587 Resource updateInfoResource = createResourceObject(true);
3588 boolean hasBeenCertified = false;
3589 Either<Boolean,ResponseFormat> result;
3592 testSubject=createTestSubject();result=Deencapsulation.invoke(testSubject, "validateNestedDerivedFromDuringUpdate", new Object[]{currentResource, updateInfoResource, hasBeenCertified});
3597 public void testValidateDerivedFromExist() throws Exception {
3598 ResourceBusinessLogic testSubject;
3599 Resource resource = createResourceObject(true);
3600 AuditingActionEnum actionEnum = AuditingActionEnum.ACTIVATE_SERVICE_BY_API;
3601 Either<Boolean,ResponseFormat> result;
3604 testSubject=createTestSubject();result=Deencapsulation.invoke(testSubject, "validateDerivedFromExist", new Object[]{user, resource, actionEnum});
3608 @Test(expected=UnsupportedOperationException.class)
3609 public void testValidateDerivedFromExtending() throws Exception {
3610 ResourceBusinessLogic testSubject;
3611 Resource currentResource = createResourceObject(true);
3612 Resource updateInfoResource = createResourceObject(true);
3613 AuditingActionEnum actionEnum = AuditingActionEnum.ADD_CATEGORY;
3614 Either<Boolean,ResponseFormat> result;
3616 Either<Boolean, StorageOperationStatus> dataModelResponse = Either.right(StorageOperationStatus.BAD_REQUEST);
3617 when(toscaOperationFacade.validateToscaResourceNameExtends(currentResource.getDerivedFrom().get(0), updateInfoResource.getDerivedFrom().get(0))).thenReturn(dataModelResponse);
3620 testSubject=createTestSubject();result=Deencapsulation.invoke(testSubject, "validateDerivedFromExtending", new Object[]{user, currentResource, updateInfoResource, actionEnum});
3625 public void testValidateResourceNameExists_2() throws Exception {
3626 ResourceBusinessLogic testSubject;
3627 Resource resource = createResourceObject(true);
3628 Either<Boolean,ResponseFormat> result;
3631 testSubject=createTestSubject();result=Deencapsulation.invoke(testSubject, "validateResourceNameExists", new Object[]{resource});
3636 public void testValidateCategory_1() throws Exception {
3637 ResourceBusinessLogic testSubject;
3638 Resource resource = createResourceObject(true);
3639 AuditingActionEnum actionEnum = AuditingActionEnum.ADD_ECOMP_USER_CREDENTIALS;
3640 boolean inTransaction = false;
3641 Either<Boolean,ResponseFormat> result;
3644 testSubject=createTestSubject();result=Deencapsulation.invoke(testSubject, "validateCategory", new Object[]{user, resource, actionEnum, inTransaction});
3649 public void testValidateCategoryListed() throws Exception {
3650 ResourceBusinessLogic testSubject;
3651 CategoryDefinition category = null;
3652 SubCategoryDefinition subcategory = null;
3653 boolean inTransaction = false;
3654 Either<Boolean,ResponseFormat> result;
3657 testSubject=createTestSubject();
3658 result=Deencapsulation.invoke(testSubject, "validateCategoryListed", new Object[]{CategoryDefinition.class, SubCategoryDefinition.class, inTransaction});
3664 public void testValidateVendorReleaseName_2() throws Exception {
3665 ResourceBusinessLogic testSubject;
3666 Resource resource = createResourceObject(true);
3667 AuditingActionEnum actionEnum = null;
3668 Either<Boolean,ResponseFormat> result;
3671 testSubject=createTestSubject();result=testSubject.validateVendorReleaseName(user, resource, actionEnum);
3676 public void testValidateVendorReleaseName_3() throws Exception {
3677 ResourceBusinessLogic testSubject;
3678 String vendorRelease = "";
3679 Either<Boolean,ResponseFormat> result;
3682 testSubject=createTestSubject();vendorRelease = null;
3683 result=testSubject.validateVendorReleaseName(vendorRelease);
3688 public void testValidateVendorName_1() throws Exception {
3689 ResourceBusinessLogic testSubject;
3690 Resource resource = createResourceObject(true);
3691 AuditingActionEnum actionEnum = AuditingActionEnum.ARTIFACT_DELETE;
3692 Either<Boolean,ResponseFormat> result;
3695 testSubject=createTestSubject();result=Deencapsulation.invoke(testSubject, "validateVendorName", new Object[]{user, resource, actionEnum});
3700 public void testValidateResourceVendorModelNumber_1() throws Exception {
3701 ResourceBusinessLogic testSubject;
3702 Resource resource = createResourceObject(true);
3703 AuditingActionEnum actionEnum = AuditingActionEnum.ARTIFACT_DELETE;
3704 Either<Boolean,ResponseFormat> result;
3707 testSubject=createTestSubject();result=Deencapsulation.invoke(testSubject, "validateResourceVendorModelNumber", new Object[]{user, resource, actionEnum});
3712 public void testValidateVendorName_2() throws Exception {
3713 ResourceBusinessLogic testSubject;
3714 String vendorName = "";
3715 Either<Boolean,ResponseFormat> result;
3718 testSubject=createTestSubject();
3719 result=Deencapsulation.invoke(testSubject, "validateVendorName", new Object[]{vendorName});
3724 public void testValidateResourceVendorModelNumber_2() throws Exception {
3725 ResourceBusinessLogic testSubject;
3726 String resourceVendorModelNumber = "";
3727 Either<Boolean,ResponseFormat> result;
3730 testSubject=createTestSubject();result=Deencapsulation.invoke(testSubject, "validateResourceVendorModelNumber", new Object[]{resourceVendorModelNumber});
3735 public void testValidateCost() throws Exception {
3736 ResourceBusinessLogic testSubject;
3737 Resource resource = createResourceObject(true);
3738 AuditingActionEnum actionEnum = AuditingActionEnum.ADD_GROUPING;
3739 Either<Boolean,ResponseFormat> result;
3742 testSubject=createTestSubject();result=Deencapsulation.invoke(testSubject, "validateCost", new Object[]{user, resource, AuditingActionEnum.class});
3747 public void testValidateLicenseType() throws Exception {
3748 ResourceBusinessLogic testSubject;
3749 Resource resource = createResourceObject(true);
3750 AuditingActionEnum actionEnum = AuditingActionEnum.ADD_KEY_TO_TOPIC_ACL;
3751 Either<Boolean,ResponseFormat> result;
3754 testSubject=createTestSubject();result=Deencapsulation.invoke(testSubject, "validateLicenseType", new Object[]{user, resource, actionEnum});
3759 public void testDeleteMarkedComponents() throws Exception {
3760 ResourceBusinessLogic testSubject;
3761 Either<List<String>,ResponseFormat> result;
3763 Either<List<String>, StorageOperationStatus> deleteMarkedElements = Either.right(StorageOperationStatus.BAD_REQUEST);
3764 when(toscaOperationFacade.deleteMarkedElements(ComponentTypeEnum.RESOURCE)).thenReturn(deleteMarkedElements);
3768 testSubject=createTestSubject();result=testSubject.deleteMarkedComponents();
3773 public void testGetComponentTypeForResponse() throws Exception {
3774 ResourceBusinessLogic testSubject;Component component = null;
3778 testSubject=createTestSubject();result=Deencapsulation.invoke(testSubject, "getComponentTypeForResponse", new Object[]{Component.class});
3783 public void testCreateGroupsFromYaml() throws Exception {
3784 ResourceBusinessLogic testSubject;
3785 String yamlFileName = "";
3786 Map<String,Object> toscaJson = new HashMap<>();;
3787 Resource resource = createResourceObject(true);
3788 Either<Map<String,GroupDefinition>,ResponseFormat> result;
3791 testSubject=createTestSubject();result=Deencapsulation.invoke(testSubject, "createGroupsFromYaml", new Object[]{yamlFileName, toscaJson, resource});
3796 public void testCreateInputsFromYaml() throws Exception {
3797 ResourceBusinessLogic testSubject;
3798 String yamlFileName = "";
3799 Map<String,Object> toscaJson = new HashMap<>();;
3800 Resource resource = createResourceObject(true);
3801 Either<Map<String,InputDefinition>,ResponseFormat> result;
3804 testSubject=createTestSubject();result=Deencapsulation.invoke(testSubject, "createInputsFromYaml", new Object[]{yamlFileName, toscaJson, resource});
3809 public void testCreateGroupInfo() throws Exception {
3810 ResourceBusinessLogic testSubject;String groupName = "";
3811 Object groupTemplateJson = null;
3812 Either<GroupDefinition,ResponseFormat> result;
3815 testSubject=createTestSubject();result=Deencapsulation.invoke(testSubject, "createGroupInfo", new Object[]{groupName, Object.class});
3819 public void testGetValidComponentInstanceCapabilities() throws Exception {
3820 ResourceBusinessLogic testSubject;
3821 Resource resource = createResourceObject(true);
3822 String resourceId = resource.getUniqueId();
3823 Map<String,List<CapabilityDefinition>> defaultCapabilities = new HashMap<>();
3824 Map<String,List<UploadCapInfo>> uploadedCapabilities = new HashMap<>();
3825 Either<Map<String,List<CapabilityDefinition>>,ResponseFormat> result;
3828 testSubject=createTestSubject();result=Deencapsulation.invoke(testSubject, "getValidComponentInstanceCapabilities", new Object[]{resourceId, defaultCapabilities, uploadedCapabilities});
3833 public void testBuildNestedToscaResourceName() throws Exception {
3834 ResourceBusinessLogic testSubject;
3835 String nodeResourceType = "VF";
3836 String vfResourceName = "Resource12";
3837 String nodeTypeFullName = "org.openecomp.resource.VF.Resource12";
3838 ImmutablePair<String,String> result;
3841 testSubject=createTestSubject();result=Deencapsulation.invoke(testSubject, "buildNestedToscaResourceName", new Object[]{nodeResourceType, vfResourceName, nodeTypeFullName});
3846 public void testValidateAndUpdateInterfaces() throws Exception {
3847 ResourceBusinessLogic testSubject;
3848 Resource resourceUpdate = createResourceObject(true);;
3849 String resourceId = resourceUpdate.getUniqueId();
3850 Either<Boolean,ResponseFormat> result;
3853 Either<Component, StorageOperationStatus> resourceStorageOperationStatusEither = Either.right(StorageOperationStatus.BAD_REQUEST);
3854 when(toscaOperationFacade.getToscaElement(resourceUpdate.getUniqueId())).thenReturn(resourceStorageOperationStatusEither);
3857 testSubject=createTestSubject();result=Deencapsulation.invoke(testSubject, "validateAndUpdateInterfaces", new Object[]{resourceId, resourceUpdate});
3862 public void testUpdateInterfaceDefinition() throws Exception {
3863 ResourceBusinessLogic testSubject;
3864 Resource resourceUpdate = createResourceObject(true);
3865 InterfaceDefinition interfaceDefinition = new InterfaceDefinition();
3866 Collection<InterfaceDefinition> interfaceDefinitionListFromToscaName = new ArrayList<>();
3867 Either<InterfaceDefinition,ResponseFormat> result;
3870 testSubject=createTestSubject();result=Deencapsulation.invoke(testSubject, "updateInterfaceDefinition", new Object[]{resourceUpdate, interfaceDefinition, interfaceDefinitionListFromToscaName});