Merge "add few more tests to BE components"
[sdc.git] / catalog-be / src / test / java / org / openecomp / sdc / be / components / impl / ResourceBusinessLogicTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.openecomp.sdc.be.components.impl;
22
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertFalse;
25 import static org.junit.Assert.assertNotNull;
26 import static org.junit.Assert.assertTrue;
27 import static org.mockito.Mockito.when;
28
29 import java.lang.reflect.Method;
30 import java.util.ArrayList;
31 import java.util.EnumMap;
32 import java.util.HashMap;
33 import java.util.List;
34 import java.util.Map;
35 import java.util.Set;
36 import java.util.regex.Pattern;
37 import java.util.stream.Collectors;
38
39 import javax.servlet.ServletContext;
40
41 import org.apache.commons.lang3.tuple.ImmutablePair;
42 import org.junit.Assert;
43 import org.junit.Before;
44 import org.junit.Ignore;
45 import org.junit.Test;
46 import org.mockito.InjectMocks;
47 import org.mockito.Mockito;
48 import org.mockito.MockitoAnnotations;
49 import org.openecomp.sdc.ElementOperationMock;
50 import org.openecomp.sdc.be.auditing.api.IAuditingManager;
51 import org.openecomp.sdc.be.auditing.impl.AuditingLogFormatUtil;
52 import org.openecomp.sdc.be.auditing.impl.AuditingManager;
53 import org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic.ArtifactOperationEnum;
54 import org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic.ArtifactOperationInfo;
55 import org.openecomp.sdc.be.components.lifecycle.LifecycleBusinessLogic;
56 import org.openecomp.sdc.be.components.lifecycle.LifecycleChangeInfoWithAction;
57 import org.openecomp.sdc.be.config.ConfigurationManager;
58 import org.openecomp.sdc.be.dao.api.ActionStatus;
59 import org.openecomp.sdc.be.dao.jsongraph.TitanDao;
60 import org.openecomp.sdc.be.datamodel.api.HighestFilterEnum;
61 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
62 import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
63 import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
64 import org.openecomp.sdc.be.impl.ComponentsUtils;
65 import org.openecomp.sdc.be.impl.WebAppContextWrapper;
66 import org.openecomp.sdc.be.info.ArtifactTemplateInfo;
67 import org.openecomp.sdc.be.info.MergedArtifactInfo;
68 import org.openecomp.sdc.be.model.ArtifactDefinition;
69 import org.openecomp.sdc.be.model.CapabilityDefinition;
70 import org.openecomp.sdc.be.model.Component;
71 import org.openecomp.sdc.be.model.ComponentInstance;
72 import org.openecomp.sdc.be.model.ComponentInstanceInput;
73 import org.openecomp.sdc.be.model.ComponentInstanceProperty;
74 import org.openecomp.sdc.be.model.CsarInfo;
75 import org.openecomp.sdc.be.model.DataTypeDefinition;
76 import org.openecomp.sdc.be.model.GroupDefinition;
77 import org.openecomp.sdc.be.model.GroupProperty;
78 import org.openecomp.sdc.be.model.GroupTypeDefinition;
79 import org.openecomp.sdc.be.model.HeatParameterDefinition;
80 import org.openecomp.sdc.be.model.InputDefinition;
81 import org.openecomp.sdc.be.model.LifeCycleTransitionEnum;
82 import org.openecomp.sdc.be.model.LifecycleStateEnum;
83 import org.openecomp.sdc.be.model.NodeTypeInfo;
84 import org.openecomp.sdc.be.model.ParsedToscaYamlInfo;
85 import org.openecomp.sdc.be.model.PropertyDefinition;
86 import org.openecomp.sdc.be.model.RequirementCapabilityRelDef;
87 import org.openecomp.sdc.be.model.RequirementDefinition;
88 import org.openecomp.sdc.be.model.Resource;
89 import org.openecomp.sdc.be.model.UploadCapInfo;
90 import org.openecomp.sdc.be.model.UploadComponentInstanceInfo;
91 import org.openecomp.sdc.be.model.UploadPropInfo;
92 import org.openecomp.sdc.be.model.UploadReqInfo;
93 import org.openecomp.sdc.be.model.UploadResourceInfo;
94 import org.openecomp.sdc.be.model.User;
95 import org.openecomp.sdc.be.model.cache.ApplicationDataTypeCache;
96 import org.openecomp.sdc.be.model.category.CategoryDefinition;
97 import org.openecomp.sdc.be.model.category.SubCategoryDefinition;
98 import org.openecomp.sdc.be.model.jsontitan.operations.NodeTemplateOperation;
99 import org.openecomp.sdc.be.model.jsontitan.operations.NodeTypeOperation;
100 import org.openecomp.sdc.be.model.jsontitan.operations.TopologyTemplateOperation;
101 import org.openecomp.sdc.be.model.jsontitan.operations.ToscaOperationFacade;
102 import org.openecomp.sdc.be.model.operations.api.ICacheMangerOperation;
103 import org.openecomp.sdc.be.model.operations.api.ICapabilityTypeOperation;
104 import org.openecomp.sdc.be.model.operations.api.IElementOperation;
105 import org.openecomp.sdc.be.model.operations.api.IPropertyOperation;
106 import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
107 import org.openecomp.sdc.be.model.operations.impl.CacheMangerOperation;
108 import org.openecomp.sdc.be.model.operations.impl.CsarOperation;
109 import org.openecomp.sdc.be.model.operations.impl.GraphLockOperation;
110 import org.openecomp.sdc.be.model.tosca.ToscaPropertyType;
111 import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
112 import org.openecomp.sdc.be.tosca.CsarUtils.NonMetaArtifactInfo;
113 import org.openecomp.sdc.be.ui.model.UiComponentDataTransfer;
114 import org.openecomp.sdc.be.user.IUserBusinessLogic;
115 import org.openecomp.sdc.be.user.Role;
116 import org.openecomp.sdc.be.user.UserBusinessLogic;
117 import org.openecomp.sdc.common.api.ArtifactGroupTypeEnum;
118 import org.openecomp.sdc.common.api.ArtifactTypeEnum;
119 import org.openecomp.sdc.common.api.ConfigurationSource;
120 import org.openecomp.sdc.common.api.Constants;
121 import org.openecomp.sdc.common.datastructure.AuditingFieldsKeysEnum;
122 import org.openecomp.sdc.common.impl.ExternalConfiguration;
123 import org.openecomp.sdc.common.impl.FSConfigurationSource;
124 import org.openecomp.sdc.common.util.GeneralUtility;
125 import org.openecomp.sdc.common.util.ValidationUtils;
126 import org.openecomp.sdc.exception.ResponseFormat;
127 import org.slf4j.Logger;
128 import org.slf4j.LoggerFactory;
129 import org.springframework.web.context.WebApplicationContext;
130
131 import com.att.nsa.cambria.test.support.CambriaBatchingPublisherMock.Entry;
132 import com.google.common.base.Equivalence.Wrapper;
133 import com.netflix.astyanax.connectionpool.Operation;
134
135 import fj.data.Either;
136
137 public class ResourceBusinessLogicTest {
138
139         private static Logger log = LoggerFactory.getLogger(ResourceBusinessLogicTest.class.getName());
140         public static final String RESOURCE_CATEGORY = "Network Layer 2-3/Router";
141         public static final String RESOURCE_CATEGORY1 = "Network Layer 2-3";
142         public static final String RESOURCE_SUBCATEGORY = "Router";
143
144         public static final String UPDATED_CATEGORY = "Network Layer 2-3/Gateway";
145         public static final String UPDATED_SUBCATEGORY = "Gateway";
146
147         public static final String RESOURCE_NAME = "My-Resource_Name with   space";
148         private static final String GENERIC_VF_NAME = "org.openecomp.resource.abstract.nodes.VF";
149         private static final String GENERIC_VFC_NAME = "org.openecomp.resource.abstract.nodes.VFC";
150         private static final String GENERIC_PNF_NAME = "org.openecomp.resource.abstract.nodes.PNF";
151
152         final ServletContext servletContext = Mockito.mock(ServletContext.class);
153         IAuditingManager iAuditingManager = null;
154         IElementOperation mockElementDao;
155         TitanDao mockTitanDao = Mockito.mock(TitanDao.class);
156         UserBusinessLogic mockUserAdmin = Mockito.mock(UserBusinessLogic.class);
157         ToscaOperationFacade toscaOperationFacade = Mockito.mock(ToscaOperationFacade.class);
158         NodeTypeOperation nodeTypeOperation = Mockito.mock(NodeTypeOperation.class);
159         NodeTemplateOperation nodeTemplateOperation = Mockito.mock(NodeTemplateOperation.class);
160         TopologyTemplateOperation topologyTemplateOperation = Mockito.mock(TopologyTemplateOperation.class);
161         final LifecycleBusinessLogic lifecycleBl = Mockito.mock(LifecycleBusinessLogic.class);
162         final ICapabilityTypeOperation capabilityTypeOperation = Mockito.mock(ICapabilityTypeOperation.class);
163         final IPropertyOperation propertyOperation = Mockito.mock(IPropertyOperation.class);
164         final ApplicationDataTypeCache applicationDataTypeCache = Mockito.mock(ApplicationDataTypeCache.class);
165         WebAppContextWrapper webAppContextWrapper = Mockito.mock(WebAppContextWrapper.class);
166         WebApplicationContext webAppContext = Mockito.mock(WebApplicationContext.class);
167         AuditingLogFormatUtil auditingLogFormatter = Mockito.mock(AuditingLogFormatUtil.class);
168         @InjectMocks
169         ResourceBusinessLogic bl = new ResourceBusinessLogic();
170         ResponseFormatManager responseManager = null;
171         AuditingManager auditingManager = Mockito.mock(AuditingManager.class);
172         GraphLockOperation graphLockOperation = Mockito.mock(GraphLockOperation.class);
173         User user = null;
174         Resource resourceResponse = null;
175         Resource genericVF = null;
176         Resource genericVFC = null;
177         Resource genericPNF = null;
178         ComponentsUtils componentsUtils = new ComponentsUtils();
179         ArtifactsBusinessLogic artifactManager = new ArtifactsBusinessLogic();
180         CsarOperation csarOperation = Mockito.mock(CsarOperation.class);
181         Map<String, DataTypeDefinition> emptyDataTypes = new HashMap<String, DataTypeDefinition>();
182
183         CacheMangerOperation cacheManager = Mockito.mock(CacheMangerOperation.class);
184
185         public ResourceBusinessLogicTest() {
186
187         }
188
189         @Before
190         public void setup() {
191                 MockitoAnnotations.initMocks(this);
192                 Mockito.reset(propertyOperation);
193
194                 ExternalConfiguration.setAppName("catalog-be");
195
196                 // Init Configuration
197                 String appConfigDir = "src/test/resources/config/catalog-be";
198                 ConfigurationSource configurationSource = new FSConfigurationSource(ExternalConfiguration.getChangeListener(),
199                                 appConfigDir);
200                 ConfigurationManager configurationManager = new ConfigurationManager(configurationSource);
201
202                 // Elements
203                 mockElementDao = new ElementOperationMock();
204
205                 // User data and management
206                 user = new User();
207                 user.setUserId("jh0003");
208                 user.setFirstName("Jimmi");
209                 user.setLastName("Hendrix");
210                 user.setRole(Role.ADMIN.name());
211
212                 Either<User, ActionStatus> eitherGetUser = Either.left(user);
213                 when(mockUserAdmin.getUser("jh0003", false)).thenReturn(eitherGetUser);
214
215                 // Servlet Context attributes
216                 when(servletContext.getAttribute(Constants.CONFIGURATION_MANAGER_ATTR)).thenReturn(configurationManager);
217                 when(servletContext.getAttribute(Constants.WEB_APPLICATION_CONTEXT_WRAPPER_ATTR))
218                                 .thenReturn(webAppContextWrapper);
219                 when(webAppContextWrapper.getWebAppContext(servletContext)).thenReturn(webAppContext);
220                 when(webAppContext.getBean(IElementOperation.class)).thenReturn(mockElementDao);
221
222                 Either<Integer, StorageOperationStatus> eitherCountRoot = Either.left(1);
223                 Either<Boolean, StorageOperationStatus> eitherFalse = Either.left(true);
224                 when(toscaOperationFacade.validateComponentNameExists("Root", ResourceTypeEnum.VFC, ComponentTypeEnum.RESOURCE))
225                                 .thenReturn(eitherFalse);
226
227                 Either<Boolean, StorageOperationStatus> eitherCountExist = Either.left(true);
228                 when(toscaOperationFacade.validateComponentNameExists("alreadyExists", ResourceTypeEnum.VFC,
229                                 ComponentTypeEnum.RESOURCE)).thenReturn(eitherCountExist);
230
231                 Either<Boolean, StorageOperationStatus> eitherCount = Either.left(false);
232                 when(toscaOperationFacade.validateComponentNameExists(RESOURCE_NAME, ResourceTypeEnum.VFC,
233                                 ComponentTypeEnum.RESOURCE)).thenReturn(eitherCount);
234                 when(toscaOperationFacade.validateComponentNameExists(RESOURCE_NAME, ResourceTypeEnum.VF,
235                                 ComponentTypeEnum.RESOURCE)).thenReturn(eitherCount);
236                 when(toscaOperationFacade.validateComponentNameExists(RESOURCE_NAME, ResourceTypeEnum.PNF,
237                                 ComponentTypeEnum.RESOURCE)).thenReturn(eitherCount);
238
239                 Either<Boolean, StorageOperationStatus> validateDerivedExists = Either.left(true);
240                 when(toscaOperationFacade.validateToscaResourceNameExists("Root")).thenReturn(validateDerivedExists);
241
242                 Either<Boolean, StorageOperationStatus> validateDerivedNotExists = Either.left(false);
243                 when(toscaOperationFacade.validateToscaResourceNameExists("kuku")).thenReturn(validateDerivedNotExists);
244                 when(graphLockOperation.lockComponent(Mockito.anyString(), Mockito.eq(NodeTypeEnum.Resource)))
245                                 .thenReturn(StorageOperationStatus.OK);
246                 when(graphLockOperation.lockComponentByName(Mockito.anyString(), Mockito.eq(NodeTypeEnum.Resource)))
247                                 .thenReturn(StorageOperationStatus.OK);
248
249                 // createResource
250                 resourceResponse = createResourceObject(true);
251                 Either<Resource, StorageOperationStatus> eitherCreate = Either.left(resourceResponse);
252                 Either<Integer, StorageOperationStatus> eitherValidate = Either.left(null);
253                 when(toscaOperationFacade.createToscaComponent(Mockito.any(Resource.class))).thenReturn(eitherCreate);
254                 when(toscaOperationFacade.validateCsarUuidUniqueness(Mockito.anyString())).thenReturn(eitherValidate);
255                 Map<String, DataTypeDefinition> emptyDataTypes = new HashMap<String, DataTypeDefinition>();
256                 when(applicationDataTypeCache.getAll()).thenReturn(Either.left(emptyDataTypes));
257
258                 // BL object
259                 artifactManager.nodeTemplateOperation = nodeTemplateOperation;
260                 bl = new ResourceBusinessLogic();
261                 bl.setElementDao(mockElementDao);
262                 bl.setUserAdmin(mockUserAdmin);
263                 bl.setCapabilityTypeOperation(capabilityTypeOperation);
264                 componentsUtils.Init();
265                 componentsUtils.setAuditingManager(auditingManager);
266                 bl.setComponentsUtils(componentsUtils);
267                 bl.setLifecycleManager(lifecycleBl);
268                 bl.setGraphLockOperation(graphLockOperation);
269                 bl.setArtifactsManager(artifactManager);
270                 bl.setPropertyOperation(propertyOperation);
271                 bl.setTitanGenericDao(mockTitanDao);
272                 bl.setApplicationDataTypeCache(applicationDataTypeCache);
273                 bl.setCsarOperation(csarOperation);
274                 bl.setCacheManagerOperation(cacheManager);
275                 toscaOperationFacade.setNodeTypeOperation(nodeTypeOperation);
276                 toscaOperationFacade.setTopologyTemplateOperation(topologyTemplateOperation);
277                 bl.setToscaOperationFacade(toscaOperationFacade);
278                 Resource resourceCsar = createResourceObjectCsar(true);
279                 setCanWorkOnResource(resourceCsar);
280                 Either<Component, StorageOperationStatus> oldResourceRes = Either.left(resourceCsar);
281                 when(toscaOperationFacade.getToscaElement(resourceCsar.getUniqueId())).thenReturn(oldResourceRes);
282                 responseManager = ResponseFormatManager.getInstance();
283
284         }
285
286         private Resource createResourceObject(boolean afterCreate) {
287                 Resource resource = new Resource();
288                 resource.setName(RESOURCE_NAME);
289                 resource.addCategory(RESOURCE_CATEGORY1, RESOURCE_SUBCATEGORY);
290                 resource.setDescription("My short description");
291                 List<String> tgs = new ArrayList<String>();
292                 tgs.add("test");
293                 tgs.add(resource.getName());
294                 resource.setTags(tgs);
295                 List<String> template = new ArrayList<String>();
296                 template.add("Root");
297                 resource.setDerivedFrom(template);
298                 resource.setVendorName("Motorola");
299                 resource.setVendorRelease("1.0.0");
300                 resource.setContactId("ya5467");
301                 resource.setIcon("MyIcon");
302
303                 if (afterCreate) {
304                         resource.setName(resource.getName());
305                         resource.setVersion("0.1");
306                         resource.setUniqueId(resource.getName().toLowerCase() + ":" + resource.getVersion());
307                         resource.setCreatorUserId(user.getUserId());
308                         resource.setCreatorFullName(user.getFirstName() + " " + user.getLastName());
309                         resource.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
310                 }
311                 return resource;
312         }
313
314         private Resource createResourceObjectCsar(boolean afterCreate) {
315                 Resource resource = new Resource();
316                 resource.setName(RESOURCE_NAME);
317                 resource.addCategory(RESOURCE_CATEGORY1, RESOURCE_SUBCATEGORY);
318                 resource.setDescription("My short description");
319                 List<String> tgs = new ArrayList<String>();
320                 tgs.add("test");
321                 tgs.add(resource.getName());
322                 resource.setTags(tgs);
323                 List<String> template = new ArrayList<String>();
324                 template.add("Root");
325                 resource.setDerivedFrom(template);
326                 resource.setVendorName("Motorola");
327                 resource.setVendorRelease("1.0.0");
328                 resource.setResourceVendorModelNumber("");
329                 resource.setContactId("ya5467");
330                 resource.setIcon("MyIcon");
331                 resource.setCsarUUID("valid_vf.csar");
332                 resource.setCsarVersion("1");
333
334                 if (afterCreate) {
335                         resource.setName(resource.getName());
336                         resource.setVersion("0.1");
337
338                         resource.setUniqueId(resource.getName().toLowerCase() + ":" + resource.getVersion());
339                         resource.setCreatorUserId(user.getUserId());
340                         resource.setCreatorFullName(user.getFirstName() + " " + user.getLastName());
341                         resource.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
342                 }
343                 return resource;
344         }
345
346         private Resource setCanWorkOnResource(Resource resource) {
347                 resource.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
348                 resource.setLastUpdaterUserId(user.getUserId());
349                 return resource;
350         }
351
352         @Test
353         public void testHappyScenario() {
354                 Resource resource = createResourceObject(false);
355                 Either<Resource, ResponseFormat> createResponse = bl.createResource(resource,
356                                 AuditingActionEnum.CREATE_RESOURCE, user, null, null);
357
358                 if (createResponse.isRight()) {
359                         assertEquals(new Integer(200), createResponse.right().value().getStatus());
360                 }
361                 assertEquals(createResourceObject(true), createResponse.left().value());
362         }
363
364         @Test
365         public void testUpdateHappyScenario() {
366                 Resource resource = createResourceObjectCsar(true);
367                 setCanWorkOnResource(resource);
368
369                 Either<Resource, StorageOperationStatus> resourceLinkedToCsarRes = Either.left(resource);
370                 when(toscaOperationFacade.getLatestComponentByCsarOrName(ComponentTypeEnum.RESOURCE, resource.getCsarUUID(),
371                                 resource.getSystemName())).thenReturn(resourceLinkedToCsarRes);
372                 Either<Boolean, StorageOperationStatus> validateDerivedExists = Either.left(true);
373                 when(toscaOperationFacade.validateToscaResourceNameExists("Root")).thenReturn(validateDerivedExists);
374
375                 Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
376                 when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
377                 Either<Resource, ResponseFormat> updateResponse = bl.validateAndUpdateResourceFromCsar(resource, user, null,
378                                 null, resource.getUniqueId());
379                 if (updateResponse.isRight()) {
380                         assertEquals(new Integer(200), updateResponse.right().value().getStatus());
381                 }
382                 assertEquals(resource.getUniqueId(), updateResponse.left().value().getUniqueId());
383         }
384
385         /* CREATE validations - start ***********************/
386         // Resource name - start
387
388         @Test
389         public void testFailedResourceValidations() {
390                 testResourceNameExist();
391                 testResourceNameEmpty();
392                 // testResourceNameExceedsLimit();
393                 testResourceNameWrongFormat();
394                 testResourceDescExceedsLimitCreate();
395                 testResourceDescNotEnglish();
396                 testResourceDescriptionEmpty();
397                 testResourceDescriptionMissing();
398                 testResourceIconMissing();
399                 testResourceIconInvalid();
400                 testResourceIconExceedsLimit();
401                 testResourceTagNotExist();
402                 testResourceTagEmpty();
403                 testTagsExceedsLimitCreate();
404                 testTagsNoServiceName();
405                 testInvalidTag();
406
407                 testContactIdTooLong();
408                 testContactIdWrongFormatCreate();
409                 testResourceContactIdEmpty();
410                 testResourceContactIdMissing();
411                 testVendorNameExceedsLimit();
412                 testVendorNameWrongFormatCreate();
413                 testVendorReleaseWrongFormat();
414                 testVendorReleaseExceedsLimitCreate();
415                 testResourceVendorModelNumberExceedsLimit();
416                 testResourceVendorNameMissing();
417                 testResourceVendorReleaseMissing();
418                 testResourceCategoryExist();
419                 testResourceBadCategoryCreate();
420                 testHappyScenarioCostLicenseType();
421                 testCostWrongFormatCreate();
422                 testLicenseTypeWrongFormatCreate();
423                 testResourceTemplateNotExist();
424                 testResourceTemplateEmpty();
425                 testResourceTemplateInvalid();
426         }
427
428         private void testResourceNameExist() {
429                 String resourceName = "alreadyExists";
430                 Resource resourceExist = createResourceObject(false);
431                 resourceExist.setName(resourceName);
432                 resourceExist.getTags().add(resourceName);
433
434                 Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceExist,
435                                 AuditingActionEnum.CREATE_RESOURCE, user, null, null);
436                 assertResponse(createResponse, ActionStatus.COMPONENT_NAME_ALREADY_EXIST, ComponentTypeEnum.RESOURCE.getValue(),
437                                 resourceName);
438         }
439
440         private void testResourceNameEmpty() {
441                 Resource resourceExist = createResourceObject(false);
442                 resourceExist.setName(null);
443
444                 Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceExist,
445                                 AuditingActionEnum.CREATE_RESOURCE, user, null, null);
446                 assertResponse(createResponse, ActionStatus.MISSING_COMPONENT_NAME, ComponentTypeEnum.RESOURCE.getValue());
447         }
448
449         private void testResourceNameExceedsLimit() {
450                 Resource resourceExccedsNameLimit = createResourceObject(false);
451                 // 51 chars, the limit is 50
452                 String tooLongResourceName = "zCRCAWjqte0DtgcAAMmcJcXeNubeX1p1vOZNTShAHOYNAHvV3iK";
453                 resourceExccedsNameLimit.setName(tooLongResourceName);
454
455                 Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceExccedsNameLimit,
456                                 AuditingActionEnum.CREATE_RESOURCE, user, null, null);
457                 assertTrue(createResponse.isRight());
458                 assertResponse(createResponse, ActionStatus.COMPONENT_NAME_EXCEEDS_LIMIT, ComponentTypeEnum.RESOURCE.getValue(),
459                                 "" + ValidationUtils.COMPONENT_NAME_MAX_LENGTH);
460         }
461
462         private void testResourceNameWrongFormat() {
463                 Resource resource = createResourceObject(false);
464                 // contains :
465                 String nameWrongFormat = "ljg?fd";
466                 resource.setName(nameWrongFormat);
467
468                 Either<Resource, ResponseFormat> createResponse = bl.createResource(resource,
469                                 AuditingActionEnum.CREATE_RESOURCE, user, null, null);
470                 assertTrue(createResponse.isRight());
471                 assertResponse(createResponse, ActionStatus.INVALID_COMPONENT_NAME, ComponentTypeEnum.RESOURCE.getValue());
472         }
473
474         // Resource name - end
475         // Resource description - start
476         private void testResourceDescExceedsLimitCreate() {
477                 Resource resourceExccedsDescLimit = createResourceObject(false);
478                 // 1025 chars, the limit is 1024
479                 String tooLongResourceDesc = "1GUODojQ0sGzKR4NP7e5j82ADQ3KHTVOaezL95qcbuaqDtjZhAQGQ3iFwKAy580K4WiiXs3u3zq7RzXcSASl5fm0RsWtCMOIDP"
480                                 + "AOf9Tf2xtXxPCuCIMCR5wOGnNTaFxgnJEHAGxilBhZDgeMNHmCN1rMK5B5IRJOnZxcpcL1NeG3APTCIMP1lNAxngYulDm9heFSBc8TfXAADq7703AvkJT0QPpGq2z2P"
481                                 + "tlikcAnIjmWgfC5Tm7UH462BAlTyHg4ExnPPL4AO8c92VrD7kZSgSqiy73cN3gLT8uigkKrUgXQFGVUFrXVyyQXYtVM6bLBeuCGQf4C2j8lkNg6M0J3PC0PzMRoinOxk"
482                                 + "Ae2teeCtVcIj4A1KQo3210j8q2v7qQU69Mabsa6DT9FgE4rcrbiFWrg0Zto4SXWD3o1eJA9o29lTg6kxtklH3TuZTmpi5KVp1NFhS1RpnqF83tzv4mZLKsx7Zh1fEgYvRFwx1"
483                                 + "ar3RolyDfNoZiGBGTMsZzz7RPFBf2hTnLmNqVGQnHKhhGj0Y5s8t2cbqbO2nmHiJb9uaUVrCGypgbAcJL3KPOBfAVW8PcpmNj4yVjI3L4x5zHjmGZbp9vKshEQODcrmcgsYAoKqe"
484                                 + "uu5u7jk8XVxEfQ0m5qL8UOErXPlJovSmKUmP5B5T0w299zIWDYCzSoNasHpHjOMDLAiDDeHbozUOn9t3Qou00e9POq4RMM0VnIx1H38nJoJZz2XH8CI5YMQe7oTagaxgQTF2aa0qaq2"
485                                 + "V6nJsfRGRklGjNhFFYP2cS4Xv2IJO9DSX6LTXOmENrGVJJvMOZcvnBaZPfoAHN0LU4i1SoepLzulIxnZBfkUWFJgZ5wQ0Bco2GC1HMqzW21rwy4XHRxXpXbmW8LVyoA1KbnmVmROycU4"
486                                 + "scTZ62IxIcIWCVeMjBIcTviXULbPUyqlfEPXWr8IMJtpAaELWgyquPClAREMDs2b9ztKmUeXlMccFES1XWbFTrhBHhmmDyVReEgCwfokrUFR13LTUK1k8I6OEHOs";
487
488                 resourceExccedsDescLimit.setDescription(tooLongResourceDesc);
489
490                 Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceExccedsDescLimit,
491                                 AuditingActionEnum.CREATE_RESOURCE, user, null, null);
492                 assertTrue(createResponse.isRight());
493                 assertResponse(createResponse, ActionStatus.COMPONENT_DESCRIPTION_EXCEEDS_LIMIT,
494                                 ComponentTypeEnum.RESOURCE.getValue(), "" + ValidationUtils.COMPONENT_DESCRIPTION_MAX_LENGTH);
495         }
496
497         private void testResourceDescNotEnglish() {
498                 Resource notEnglish = createResourceObject(false);
499                 // Not english
500                 String notEnglishDesc = "\uC2B5";
501                 notEnglish.setDescription(notEnglishDesc);
502
503                 Either<Resource, ResponseFormat> createResponse = bl.createResource(notEnglish,
504                                 AuditingActionEnum.CREATE_RESOURCE, user, null, null);
505                 assertTrue(createResponse.isRight());
506                 assertResponse(createResponse, ActionStatus.COMPONENT_INVALID_DESCRIPTION,
507                                 ComponentTypeEnum.RESOURCE.getValue());
508         }
509
510         private void testResourceDescriptionEmpty() {
511                 Resource resourceExist = createResourceObject(false);
512                 resourceExist.setDescription("");
513
514                 Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceExist,
515                                 AuditingActionEnum.CREATE_RESOURCE, user, null, null);
516                 assertTrue(createResponse.isRight());
517
518                 assertResponse(createResponse, ActionStatus.COMPONENT_MISSING_DESCRIPTION,
519                                 ComponentTypeEnum.RESOURCE.getValue());
520         }
521
522         private void testResourceDescriptionMissing() {
523                 Resource resourceExist = createResourceObject(false);
524                 resourceExist.setDescription(null);
525
526                 Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceExist,
527                                 AuditingActionEnum.CREATE_RESOURCE, user, null, null);
528                 assertTrue(createResponse.isRight());
529
530                 assertResponse(createResponse, ActionStatus.COMPONENT_MISSING_DESCRIPTION,
531                                 ComponentTypeEnum.RESOURCE.getValue());
532         }
533         // Resource description - end
534         // Resource icon start
535
536         private void testResourceIconMissing() {
537                 Resource resourceExist = createResourceObject(false);
538                 resourceExist.setIcon(null);
539
540                 Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceExist,
541                                 AuditingActionEnum.CREATE_RESOURCE, user, null, null);
542                 assertTrue(createResponse.isRight());
543
544                 assertResponse(createResponse, ActionStatus.COMPONENT_MISSING_ICON, ComponentTypeEnum.RESOURCE.getValue());
545         }
546
547         private void testResourceIconInvalid() {
548                 Resource resourceExist = createResourceObject(false);
549                 resourceExist.setIcon("kjk3453^&");
550
551                 Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceExist,
552                                 AuditingActionEnum.CREATE_RESOURCE, user, null, null);
553                 assertTrue(createResponse.isRight());
554
555                 assertResponse(createResponse, ActionStatus.COMPONENT_INVALID_ICON, ComponentTypeEnum.RESOURCE.getValue());
556         }
557
558         private void testResourceIconExceedsLimit() {
559                 Resource resourceExist = createResourceObject(false);
560                 resourceExist.setIcon("dsjfhskdfhskjdhfskjdhkjdhfkshdfksjsdkfhsdfsdfsdfsfsdfsf");
561
562                 Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceExist,
563                                 AuditingActionEnum.CREATE_RESOURCE, user, null, null);
564                 assertTrue(createResponse.isRight());
565
566                 assertResponse(createResponse, ActionStatus.COMPONENT_ICON_EXCEEDS_LIMIT, ComponentTypeEnum.RESOURCE.getValue(),
567                                 "" + ValidationUtils.ICON_MAX_LENGTH);
568         }
569
570         // Resource icon end
571         // Resource tags - start
572         private void testResourceTagNotExist() {
573                 Resource resourceExist = createResourceObject(false);
574                 resourceExist.setTags(null);
575
576                 Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceExist,
577                                 AuditingActionEnum.CREATE_RESOURCE, user, null, null);
578                 assertTrue(createResponse.isRight());
579
580                 assertResponse(createResponse, ActionStatus.COMPONENT_MISSING_TAGS);
581         }
582
583         private void testResourceTagEmpty() {
584                 Resource resourceExist = createResourceObject(false);
585                 resourceExist.setTags(new ArrayList<String>());
586
587                 Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceExist,
588                                 AuditingActionEnum.CREATE_RESOURCE, user, null, null);
589                 assertTrue(createResponse.isRight());
590
591                 assertResponse(createResponse, ActionStatus.COMPONENT_MISSING_TAGS);
592         }
593
594         private void testTagsExceedsLimitCreate() {
595                 Resource resourceExccedsNameLimit = createResourceObject(false);
596                 String tag1 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjQ";
597                 String tag2 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjW";
598                 String tag3 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjE";
599                 String tag4 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjb";
600                 String tag5 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjr";
601                 String tag6 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjf";
602                 String tag7 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjg";
603                 String tag8 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjd";
604                 String tag9 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjf";
605                 String tag10 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjg";
606                 String tag11 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjh";
607                 String tag12 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjj";
608                 String tag13 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjk";
609                 String tag14 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjs";
610                 String tag15 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjz";
611                 String tag16 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjx";
612                 String tag17 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBj2";
613                 String tag18 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBj3";
614                 String tag19 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBj4";
615                 String tag20 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBj5";
616                 String tag21 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBj0";
617
618                 List<String> tagsList = new ArrayList<String>();
619                 tagsList.add(tag1);
620                 tagsList.add(tag2);
621                 tagsList.add(tag3);
622                 tagsList.add(tag4);
623                 tagsList.add(tag5);
624                 tagsList.add(tag6);
625                 tagsList.add(tag7);
626                 tagsList.add(tag8);
627                 tagsList.add(tag9);
628                 tagsList.add(tag10);
629                 tagsList.add(tag11);
630                 tagsList.add(tag12);
631                 tagsList.add(tag13);
632                 tagsList.add(tag14);
633                 tagsList.add(tag15);
634                 tagsList.add(tag16);
635                 tagsList.add(tag17);
636                 tagsList.add(tag18);
637                 tagsList.add(tag19);
638                 tagsList.add(tag20);
639                 tagsList.add(tag21);
640                 tagsList.add(resourceExccedsNameLimit.getName());
641
642                 resourceExccedsNameLimit.setTags(tagsList);
643
644                 Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceExccedsNameLimit,
645                                 AuditingActionEnum.CREATE_RESOURCE, user, null, null);
646                 assertTrue(createResponse.isRight());
647                 assertResponse(createResponse, ActionStatus.COMPONENT_TAGS_EXCEED_LIMIT,
648                                 "" + ValidationUtils.TAG_LIST_MAX_LENGTH);
649
650         }
651
652         private void testTagsSingleExceedsLimit() {
653                 Resource resourceExccedsNameLimit = createResourceObject(false);
654                 String tag1 = "afzs2qLBb5X6tZhiunkcEwiFX1qRQY8YZl3y3Du5M5xeQY5Nq9afcFHDZ9HaURw43gH27nAUWM36bMbMylwTFSzzNV8NO4v4ripe6Q15Vc2nPOFI";
655                 String tag2 = resourceExccedsNameLimit.getName();
656                 List<String> tagsList = new ArrayList<String>();
657                 tagsList.add(tag1);
658                 tagsList.add(tag2);
659
660                 resourceExccedsNameLimit.setTags(tagsList);
661
662                 Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceExccedsNameLimit,
663                                 AuditingActionEnum.CREATE_RESOURCE, user, null, null);
664                 assertTrue(createResponse.isRight());
665                 assertResponse(createResponse, ActionStatus.COMPONENT_SINGLE_TAG_EXCEED_LIMIT,
666                                 "" + ValidationUtils.TAG_MAX_LENGTH);
667
668         }
669
670         private void testTagsNoServiceName() {
671                 Resource serviceExccedsNameLimit = createResourceObject(false);
672                 String tag1 = "afzs2qLBb";
673                 List<String> tagsList = new ArrayList<String>();
674                 tagsList.add(tag1);
675                 serviceExccedsNameLimit.setTags(tagsList);
676
677                 Either<Resource, ResponseFormat> createResponse = bl.createResource(serviceExccedsNameLimit,
678                                 AuditingActionEnum.CREATE_RESOURCE, user, null, null);
679                 assertTrue(createResponse.isRight());
680                 assertResponse(createResponse, ActionStatus.COMPONENT_INVALID_TAGS_NO_COMP_NAME);
681
682         }
683
684         private void testInvalidTag() {
685                 Resource serviceExccedsNameLimit = createResourceObject(false);
686                 String tag1 = "afzs2qLBb%#%";
687                 List<String> tagsList = new ArrayList<String>();
688                 tagsList.add(tag1);
689                 serviceExccedsNameLimit.setTags(tagsList);
690
691                 Either<Resource, ResponseFormat> createResponse = bl.createResource(serviceExccedsNameLimit,
692                                 AuditingActionEnum.CREATE_RESOURCE, user, null, null);
693                 assertTrue(createResponse.isRight());
694                 assertResponse(createResponse, ActionStatus.INVALID_FIELD_FORMAT, new String[] { "Resource", "tag" });
695
696         }
697
698         // Resource tags - stop
699         // Resource contact start
700
701         private void testContactIdTooLong() {
702                 Resource resourceContactId = createResourceObject(false);
703                 // 59 chars instead of 50
704                 String contactIdTooLong = "thisNameIsVeryLongAndExeccedsTheNormalLengthForContactId";
705                 resourceContactId.setContactId(contactIdTooLong);
706
707                 Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceContactId,
708                                 AuditingActionEnum.CREATE_RESOURCE, user, null, null);
709                 assertTrue(createResponse.isRight());
710                 assertResponse(createResponse, ActionStatus.COMPONENT_INVALID_CONTACT, ComponentTypeEnum.RESOURCE.getValue());
711         }
712
713         private void testContactIdWrongFormatCreate() {
714                 Resource resourceContactId = createResourceObject(false);
715                 // 3 letters and 3 digits and special characters
716                 String contactIdFormatWrong = "yrt134!!!";
717                 resourceContactId.setContactId(contactIdFormatWrong);
718
719                 Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceContactId,
720                                 AuditingActionEnum.CREATE_RESOURCE, user, null, null);
721                 assertTrue(createResponse.isRight());
722                 assertResponse(createResponse, ActionStatus.COMPONENT_INVALID_CONTACT, ComponentTypeEnum.RESOURCE.getValue());
723         }
724
725         private void testResourceContactIdEmpty() {
726                 Resource resourceExist = createResourceObject(false);
727                 resourceExist.setContactId("");
728
729                 Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceExist,
730                                 AuditingActionEnum.CREATE_RESOURCE, user, null, null);
731                 assertTrue(createResponse.isRight());
732
733                 assertResponse(createResponse, ActionStatus.COMPONENT_MISSING_CONTACT, ComponentTypeEnum.RESOURCE.getValue());
734         }
735
736         private void testResourceContactIdMissing() {
737                 Resource resourceExist = createResourceObject(false);
738                 resourceExist.setContactId(null);
739
740                 Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceExist,
741                                 AuditingActionEnum.CREATE_RESOURCE, user, null, null);
742                 assertTrue(createResponse.isRight());
743
744                 assertResponse(createResponse, ActionStatus.COMPONENT_MISSING_CONTACT, ComponentTypeEnum.RESOURCE.getValue());
745         }
746
747         private void testVendorNameExceedsLimit() {
748                 Resource resourceExccedsVendorNameLimit = createResourceObject(false);
749                 String tooLongVendorName = "h1KSyJh9Eh1KSyJh9Eh1KSyJh9Eh1KSyJh9Eh1KSyJh9Eh1KSyJh9Eh1KSyJh9Eh1KSyJh9E";
750                 resourceExccedsVendorNameLimit.setVendorName(tooLongVendorName);
751
752                 Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceExccedsVendorNameLimit,
753                                 AuditingActionEnum.CREATE_RESOURCE, user, null, null);
754                 assertTrue(createResponse.isRight());
755                 assertResponse(createResponse, ActionStatus.VENDOR_NAME_EXCEEDS_LIMIT,
756                                 "" + ValidationUtils.VENDOR_NAME_MAX_LENGTH);
757         }
758
759         private void testResourceVendorModelNumberExceedsLimit() {
760                 Resource resourceExccedsVendorModelNumberLimit = createResourceObject(false);
761                 String tooLongVendorModelNumber = "h1KSyJh9Eh1KSyJh9Eh1KSyJh9Eh1KSyJh9Eh1KSyJh9Eh1KSyJh9Eh1KSyJh9Eh1KSyJh9E";
762                 resourceExccedsVendorModelNumberLimit.setResourceVendorModelNumber(tooLongVendorModelNumber);
763
764                 Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceExccedsVendorModelNumberLimit,
765                                 AuditingActionEnum.CREATE_RESOURCE, user, null, null);
766                 assertTrue(createResponse.isRight());
767                 assertResponse(createResponse, ActionStatus.RESOURCE_VENDOR_MODEL_NUMBER_EXCEEDS_LIMIT,
768                                 "" + ValidationUtils.RESOURCE_VENDOR_MODEL_NUMBER_MAX_LENGTH);
769         }
770
771         private void testVendorNameWrongFormatCreate() {
772                 Resource resource = createResourceObject(false);
773                 // contains *
774                 String nameWrongFormat = "ljg*fd";
775                 resource.setVendorName(nameWrongFormat);
776
777                 Either<Resource, ResponseFormat> createResponse = bl.createResource(resource,
778                                 AuditingActionEnum.CREATE_RESOURCE, user, null, null);
779                 assertTrue(createResponse.isRight());
780                 assertResponse(createResponse, ActionStatus.INVALID_VENDOR_NAME);
781         }
782
783         private void testVendorReleaseWrongFormat() {
784                 Resource resource = createResourceObject(false);
785                 // contains >
786                 String nameWrongFormat = "1>2";
787                 resource.setVendorRelease(nameWrongFormat);
788
789                 Either<Resource, ResponseFormat> createResponse = bl.createResource(resource,
790                                 AuditingActionEnum.CREATE_RESOURCE, user, null, null);
791                 assertTrue(createResponse.isRight());
792                 assertResponse(createResponse, ActionStatus.INVALID_VENDOR_RELEASE);
793
794         }
795
796         private void testVendorReleaseExceedsLimitCreate() {
797                 Resource resourceExccedsNameLimit = createResourceObject(false);
798                 String tooLongVendorRelease = "h1KSyJh9Eh1KSyJh9Eh1KSyJh9Eh1KSyJh9E";
799                 resourceExccedsNameLimit.setVendorRelease(tooLongVendorRelease);
800
801                 Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceExccedsNameLimit,
802                                 AuditingActionEnum.CREATE_RESOURCE, user, null, null);
803                 assertTrue(createResponse.isRight());
804                 assertResponse(createResponse, ActionStatus.VENDOR_RELEASE_EXCEEDS_LIMIT,
805                                 "" + ValidationUtils.VENDOR_RELEASE_MAX_LENGTH);
806         }
807
808         private void testResourceVendorNameMissing() {
809                 Resource resourceExist = createResourceObject(false);
810                 resourceExist.setVendorName(null);
811
812                 Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceExist,
813                                 AuditingActionEnum.CREATE_RESOURCE, user, null, null);
814                 assertTrue(createResponse.isRight());
815
816                 assertResponse(createResponse, ActionStatus.MISSING_VENDOR_NAME);
817         }
818
819         private void testResourceVendorReleaseMissing() {
820                 Resource resourceExist = createResourceObject(false);
821                 resourceExist.setVendorRelease(null);
822
823                 Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceExist,
824                                 AuditingActionEnum.CREATE_RESOURCE, user, null, null);
825                 assertTrue(createResponse.isRight());
826
827                 assertResponse(createResponse, ActionStatus.MISSING_VENDOR_RELEASE);
828         }
829
830         // Resource vendor name/release stop
831         // Category start
832         private void testResourceCategoryExist() {
833                 Resource resourceExist = createResourceObject(false);
834                 resourceExist.setCategories(null);
835
836                 Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceExist,
837                                 AuditingActionEnum.CREATE_RESOURCE, user, null, null);
838                 assertTrue(createResponse.isRight());
839
840                 assertResponse(createResponse, ActionStatus.COMPONENT_MISSING_CATEGORY, ComponentTypeEnum.RESOURCE.getValue());
841         }
842
843         private void testResourceBadCategoryCreate() {
844
845                 Resource resourceExist = createResourceObject(false);
846                 resourceExist.setCategories(null);
847                 resourceExist.addCategory("koko", "koko");
848
849                 Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceExist,
850                                 AuditingActionEnum.CREATE_RESOURCE, user, null, null);
851                 assertTrue(createResponse.isRight());
852
853                 assertResponse(createResponse, ActionStatus.COMPONENT_INVALID_CATEGORY, ComponentTypeEnum.RESOURCE.getValue());
854         }
855
856         // Category stop
857         // Cost start
858         private void testHappyScenarioCostLicenseType() {
859                 Resource createResourceObject = createResourceObject(false);
860                 Resource createResourceObjectAfterCreate = createResourceObject(true);
861                 // Adding cost and licenseType to basic mock
862                 Either<Resource, StorageOperationStatus> eitherCreate = Either.left(createResourceObjectAfterCreate);
863                 when(toscaOperationFacade.createToscaComponent(Mockito.any(Resource.class))).thenReturn(eitherCreate);
864
865                 String cost = "123.456";
866                 String licenseType = "User";
867                 createResourceObject.setCost(cost);
868                 createResourceObject.setLicenseType(licenseType);
869                 Either<Resource, ResponseFormat> createResponse = bl.createResource(createResourceObject,
870                                 AuditingActionEnum.CREATE_RESOURCE, user, null, null);
871
872                 if (createResponse.isRight()) {
873                         assertEquals(new Integer(200), createResponse.right().value().getStatus());
874                 }
875                 createResourceObjectAfterCreate.setCost(cost);
876                 createResourceObjectAfterCreate.setLicenseType(licenseType);
877                 assertEquals(createResourceObjectAfterCreate, createResponse.left().value());
878         }
879
880         private void testCostWrongFormatCreate() {
881                 Resource resourceCost = createResourceObject(false);
882                 // Comma instead of fullstop
883                 String cost = "12356,464";
884                 resourceCost.setCost(cost);
885
886                 Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceCost,
887                                 AuditingActionEnum.CREATE_RESOURCE, user, null, null);
888                 assertTrue(createResponse.isRight());
889                 assertResponse(createResponse, ActionStatus.INVALID_CONTENT);
890         }
891
892         // Cost stop
893         // License type start
894         private void testLicenseTypeWrongFormatCreate() {
895                 Resource resourceLicenseType = createResourceObject(false);
896                 // lowcase
897                 String licenseType = "cpu";
898                 resourceLicenseType.setLicenseType(licenseType);
899
900                 Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceLicenseType,
901                                 AuditingActionEnum.CREATE_RESOURCE, user, null, null);
902                 assertTrue(createResponse.isRight());
903                 assertResponse(createResponse, ActionStatus.INVALID_CONTENT);
904         }
905
906         // License type stop
907         // Derived from start
908         private void testResourceTemplateNotExist() {
909                 Resource resourceExist = createResourceObject(false);
910                 List<String> list = null;
911                 resourceExist.setDerivedFrom(list);
912
913                 Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceExist,
914                                 AuditingActionEnum.CREATE_RESOURCE, user, null, null);
915                 assertTrue(createResponse.isRight());
916
917                 assertResponse(createResponse, ActionStatus.MISSING_DERIVED_FROM_TEMPLATE);
918         }
919
920         private void testResourceTemplateEmpty() {
921                 Resource resourceExist = createResourceObject(false);
922                 resourceExist.setDerivedFrom(new ArrayList<String>());
923
924                 Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceExist,
925                                 AuditingActionEnum.CREATE_RESOURCE, user, null, null);
926                 assertTrue(createResponse.isRight());
927
928                 assertResponse(createResponse, ActionStatus.MISSING_DERIVED_FROM_TEMPLATE);
929         }
930
931         private void testResourceTemplateInvalid() {
932                 Resource resourceExist = createResourceObject(false);
933                 ArrayList<String> derivedFrom = new ArrayList<String>();
934                 derivedFrom.add("kuku");
935                 resourceExist.setDerivedFrom(derivedFrom);
936
937                 Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceExist,
938                                 AuditingActionEnum.CREATE_RESOURCE, user, null, null);
939                 assertTrue(createResponse.isRight());
940
941                 assertResponse(createResponse, ActionStatus.PARENT_RESOURCE_NOT_FOUND);
942         }
943         // Derived from stop
944
945         private void assertResponse(Either<Resource, ResponseFormat> createResponse, ActionStatus expectedStatus,
946                         String... variables) {
947                 ResponseFormat expectedResponse = responseManager.getResponseFormat(expectedStatus, variables);
948                 ResponseFormat actualResponse = createResponse.right().value();
949                 assertEquals(expectedResponse.getStatus(), actualResponse.getStatus());
950                 assertEquals("assert error description", expectedResponse.getFormattedMessage(),
951                                 actualResponse.getFormattedMessage());
952         }
953
954         // UPDATE tests - start
955         // Resource name
956         @Test
957         public void testResourceNameWrongFormat_UPDATE() {
958                 Resource resource = createResourceObject(true);
959                 Resource updatedResource = createResourceObject(true);
960
961                 // this is in order to prevent failing with 403 earlier
962                 Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
963                 when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
964                 // contains *
965                 String nameWrongFormat = "ljg*fd";
966                 updatedResource.setName(nameWrongFormat);
967
968                 Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
969                 when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
970
971                 Either<Resource, ResponseFormat> createResponse = bl.updateResourceMetadata(resource.getUniqueId(),
972                                 updatedResource, null, user, false);
973                 assertTrue(createResponse.isRight());
974                 assertResponse(createResponse, ActionStatus.INVALID_COMPONENT_NAME, ComponentTypeEnum.RESOURCE.getValue());
975
976         }
977
978         @Test
979         public void testResourceNameAfterCertify_UPDATE() {
980                 Resource resource = createResourceObject(true);
981                 Resource updatedResource = createResourceObject(true);
982
983                 // this is in order to prevent failing with 403 earlier
984                 Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
985                 // when(resourceOperation.getResource_tx(resource.getUniqueId(),false)).thenReturn(eitherUpdate);
986                 when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
987
988                 String name = "ljg";
989                 updatedResource.setName(name);
990                 resource.setVersion("1.0");
991
992                 Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
993                 when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
994
995                 Either<Resource, ResponseFormat> createResponse = bl.updateResourceMetadata(resource.getUniqueId(),
996                                 updatedResource, null, user, false);
997                 assertTrue(createResponse.isRight());
998                 assertResponse(createResponse, ActionStatus.RESOURCE_NAME_CANNOT_BE_CHANGED);
999
1000         }
1001
1002         @Ignore
1003         public void testResourceNameExceedsLimit_UPDATE() {
1004                 Resource resource = createResourceObject(true);
1005                 Resource updatedResource = createResourceObject(true);
1006
1007                 // this is in order to prevent failing with 403 earlier
1008                 Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
1009                 when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
1010
1011                 // 51 chars, the limit is 50
1012                 String tooLongResourceName = "zCRCAWjqte0DtgcAAMmcJcXeNubeX1p1vOZNTShAHOYNAHvV3iK";
1013                 updatedResource.setName(tooLongResourceName);
1014                 Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
1015                 when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
1016
1017                 Either<Resource, ResponseFormat> createResponse = bl.updateResourceMetadata(resource.getUniqueId(),
1018                                 updatedResource, null, user, false);
1019                 assertTrue(createResponse.isRight());
1020                 assertResponse(createResponse, ActionStatus.COMPONENT_NAME_EXCEEDS_LIMIT, ComponentTypeEnum.RESOURCE.getValue(),
1021                                 "" + ValidationUtils.COMPONENT_NAME_MAX_LENGTH);
1022         }
1023
1024         @Test
1025         public void testResourceNameAlreadyExist_UPDATE() {
1026                 Resource resource = createResourceObject(true);
1027                 Resource updatedResource = createResourceObject(true);
1028
1029                 // this is in order to prevent failing with 403 earlier
1030                 Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
1031                 when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
1032
1033                 String resourceName = "alreadyExists";
1034                 updatedResource.setName(resourceName);
1035                 Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(updatedResource);
1036                 when(toscaOperationFacade.updateToscaElement(updatedResource)).thenReturn(dataModelResponse);
1037                 Either<Resource, ResponseFormat> createResponse = bl.updateResourceMetadata(resource.getUniqueId(),
1038                                 updatedResource, null, user, false);
1039                 assertTrue(createResponse.isRight());
1040                 assertResponse(createResponse, ActionStatus.COMPONENT_NAME_ALREADY_EXIST, ComponentTypeEnum.RESOURCE.getValue(),
1041                                 resourceName);
1042         }
1043
1044         //
1045
1046         @Test
1047         public void testResourceDescExceedsLimit_UPDATE() {
1048                 Resource resource = createResourceObject(true);
1049                 Resource updatedResource = createResourceObject(true);
1050
1051                 // this is in order to prevent failing with 403 earlier
1052                 Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
1053                 when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
1054
1055                 // 1025 chars, the limit is 1024
1056                 String tooLongResourceDesc = "1GUODojQ0sGzKR4NP7e5j82ADQ3KHTVOaezL95qcbuaqDtjZhAQGQ3iFwKAy580K4WiiXs3u3zq7RzXcSASl5fm0RsWtCMOIDP"
1057                                 + "AOf9Tf2xtXxPCuCIMCR5wOGnNTaFxgnJEHAGxilBhZDgeMNHmCN1rMK5B5IRJOnZxcpcL1NeG3APTCIMP1lNAxngYulDm9heFSBc8TfXAADq7703AvkJT0QPpGq2z2P"
1058                                 + "tlikcAnIjmWgfC5Tm7UH462BAlTyHg4ExnPPL4AO8c92VrD7kZSgSqiy73cN3gLT8uigkKrUgXQFGVUFrXVyyQXYtVM6bLBeuCGQf4C2j8lkNg6M0J3PC0PzMRoinOxk"
1059                                 + "Ae2teeCtVcIj4A1KQo3210j8q2v7qQU69Mabsa6DT9FgE4rcrbiFWrg0Zto4SXWD3o1eJA9o29lTg6kxtklH3TuZTmpi5KVp1NFhS1RpnqF83tzv4mZLKsx7Zh1fEgYvRFwx1"
1060                                 + "ar3RolyDfNoZiGBGTMsZzz7RPFBf2hTnLmNqVGQnHKhhGj0Y5s8t2cbqbO2nmHiJb9uaUVrCGypgbAcJL3KPOBfAVW8PcpmNj4yVjI3L4x5zHjmGZbp9vKshEQODcrmcgsYAoKqe"
1061                                 + "uu5u7jk8XVxEfQ0m5qL8UOErXPlJovSmKUmP5B5T0w299zIWDYCzSoNasHpHjOMDLAiDDeHbozUOn9t3Qou00e9POq4RMM0VnIx1H38nJoJZz2XH8CI5YMQe7oTagaxgQTF2aa0qaq2"
1062                                 + "V6nJsfRGRklGjNhFFYP2cS4Xv2IJO9DSX6LTXOmENrGVJJvMOZcvnBaZPfoAHN0LU4i1SoepLzulIxnZBfkUWFJgZ5wQ0Bco2GC1HMqzW21rwy4XHRxXpXbmW8LVyoA1KbnmVmROycU4"
1063                                 + "scTZ62IxIcIWCVeMjBIcTviXULbPUyqlfEPXWr8IMJtpAaELWgyquPClAREMDs2b9ztKmUeXlMccFES1XWbFTrhBHhmmDyVReEgCwfokrUFR13LTUK1k8I6OEHOs";
1064                 updatedResource.setDescription(tooLongResourceDesc);
1065                 Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
1066                 when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
1067                 Either<Resource, ResponseFormat> createResponse = bl.updateResourceMetadata(resource.getUniqueId(),
1068                                 updatedResource, null, user, false);
1069                 assertTrue(createResponse.isRight());
1070                 assertResponse(createResponse, ActionStatus.COMPONENT_DESCRIPTION_EXCEEDS_LIMIT,
1071                                 ComponentTypeEnum.RESOURCE.getValue(), "" + ValidationUtils.COMPONENT_DESCRIPTION_MAX_LENGTH);
1072
1073         }
1074
1075         @Test
1076         public void testIconWrongFormat_UPDATE() {
1077                 Resource resource = createResourceObject(true);
1078                 Resource updatedResource = createResourceObject(true);
1079
1080                 // this is in order to prevent failing with 403 earlier
1081                 Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
1082                 when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
1083
1084                 // contains .
1085                 String icon = "icon.jpg";
1086                 updatedResource.setIcon(icon);
1087                 Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
1088                 when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
1089
1090                 Either<Resource, ResponseFormat> createResponse = bl.updateResourceMetadata(resource.getUniqueId(),
1091                                 updatedResource, null, user, false);
1092                 assertTrue(createResponse.isRight());
1093                 assertResponse(createResponse, ActionStatus.COMPONENT_INVALID_ICON, ComponentTypeEnum.RESOURCE.getValue());
1094
1095         }
1096
1097         @Test
1098         public void testIconAfterCertify_UPDATE() {
1099                 Resource resource = createResourceObject(true);
1100                 Resource updatedResource = createResourceObject(true);
1101
1102                 // this is in order to prevent failing with 403 earlier
1103                 Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
1104                 when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
1105
1106                 // contains
1107                 String icon = "icon";
1108                 updatedResource.setIcon(icon);
1109
1110                 resource.setVersion("1.0");
1111                 ;
1112                 Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
1113                 when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
1114                 Either<Resource, ResponseFormat> createResponse = bl.updateResourceMetadata(resource.getUniqueId(),
1115                                 updatedResource, null, user, false);
1116                 assertTrue(createResponse.isRight());
1117                 assertResponse(createResponse, ActionStatus.RESOURCE_ICON_CANNOT_BE_CHANGED);
1118
1119         }
1120
1121         @Test
1122         public void testTagsExceedsLimit_UPDATE() {
1123                 Resource resource = createResourceObject(true);
1124                 Resource updatedResource = createResourceObject(true);
1125
1126                 // this is in order to prevent failing with 403 earlier
1127                 Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
1128                 when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
1129
1130                 String tag1 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjQ";
1131                 String tag2 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjW";
1132                 String tag3 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjE";
1133                 String tag4 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjb";
1134                 String tag5 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjr";
1135                 String tag6 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjf";
1136                 String tag7 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjg";
1137                 String tag8 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjd";
1138                 String tag9 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjf";
1139                 String tag10 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjg";
1140                 String tag11 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjh";
1141                 String tag12 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjj";
1142                 String tag13 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjk";
1143                 String tag14 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjs";
1144                 String tag15 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjz";
1145                 String tag16 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjx";
1146                 String tag17 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBj2";
1147                 String tag18 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBj3";
1148                 String tag19 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBj4";
1149                 String tag20 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBj5";
1150                 String tag21 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBj0";
1151
1152                 List<String> tagsList = new ArrayList<String>();
1153                 tagsList.add(tag1);
1154                 tagsList.add(tag2);
1155                 tagsList.add(tag3);
1156                 tagsList.add(tag4);
1157                 tagsList.add(tag5);
1158                 tagsList.add(tag6);
1159                 tagsList.add(tag7);
1160                 tagsList.add(tag8);
1161                 tagsList.add(tag9);
1162                 tagsList.add(tag10);
1163                 tagsList.add(tag11);
1164                 tagsList.add(tag12);
1165                 tagsList.add(tag13);
1166                 tagsList.add(tag14);
1167                 tagsList.add(tag15);
1168                 tagsList.add(tag16);
1169                 tagsList.add(tag17);
1170                 tagsList.add(tag18);
1171                 tagsList.add(tag19);
1172                 tagsList.add(tag20);
1173                 tagsList.add(tag21);
1174                 tagsList.add(resource.getName());
1175
1176                 updatedResource.setTags(tagsList);
1177                 Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
1178                 when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
1179                 Either<Resource, ResponseFormat> createResponse = bl.updateResourceMetadata(resource.getUniqueId(),
1180                                 updatedResource, null, user, false);
1181                 assertTrue(createResponse.isRight());
1182
1183                 assertResponse(createResponse, ActionStatus.COMPONENT_TAGS_EXCEED_LIMIT,
1184                                 "" + ValidationUtils.TAG_LIST_MAX_LENGTH);
1185         }
1186
1187         @Test
1188         public void testVendorNameWrongFormat_UPDATE() {
1189                 Resource resource = createResourceObject(true);
1190                 Resource updatedResource = createResourceObject(true);
1191
1192                 // this is in order to prevent failing with 403 earlier
1193                 Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
1194                 when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
1195
1196                 // contains *
1197                 String nameWrongFormat = "ljg*fd";
1198                 updatedResource.setVendorName(nameWrongFormat);
1199                 Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
1200                 when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
1201                 Either<Resource, ResponseFormat> createResponse = bl.updateResourceMetadata(resource.getUniqueId(),
1202                                 updatedResource, null, user, false);
1203                 assertTrue(createResponse.isRight());
1204                 assertResponse(createResponse, ActionStatus.INVALID_VENDOR_NAME);
1205
1206         }
1207
1208         @Test
1209         public void testVendorNameAfterCertify_UPDATE() {
1210                 Resource resource = createResourceObject(true);
1211                 Resource updatedResource = createResourceObject(true);
1212
1213                 // this is in order to prevent failing with 403 earlier
1214                 Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
1215                 when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
1216
1217                 // contains *
1218                 String nameWrongFormat = "ljg*fd";
1219                 updatedResource.setVendorName(nameWrongFormat);
1220                 resource.setVersion("1.0");
1221                 ;
1222                 Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
1223                 when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
1224                 Either<Resource, ResponseFormat> createResponse = bl.updateResourceMetadata(resource.getUniqueId(),
1225                                 updatedResource, null, user, false);
1226                 assertTrue(createResponse.isRight());
1227                 assertResponse(createResponse, ActionStatus.RESOURCE_VENDOR_NAME_CANNOT_BE_CHANGED);
1228
1229         }
1230
1231         @Test
1232         public void testVendorReleaseExceedsLimit_UPDATE() {
1233                 Resource resource = createResourceObject(true);
1234                 Resource updatedResource = createResourceObject(true);
1235
1236                 // this is in order to prevent failing with 403 earlier
1237                 Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
1238                 when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
1239                 // 129 chars, the limit is 128
1240                 String tooLongVendorRelease = "h1KSyJh9EspI8SPwAGu4VETfqWejeanuB1PCJBxJmJncYnrW0lnsEFFVRIukRJkwlOVnZCy8p38tjhANeZq3BGMHIawWR6ICl8Wi9mikRYALWgvJug00JrlQ0iPVKPLxy";
1241                 updatedResource.setVendorRelease(tooLongVendorRelease);
1242                 Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
1243                 when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
1244                 Either<Resource, ResponseFormat> createResponse = bl.updateResourceMetadata(resource.getUniqueId(),
1245                                 updatedResource, null, user, false);
1246                 assertTrue(createResponse.isRight());
1247                 assertResponse(createResponse, ActionStatus.VENDOR_RELEASE_EXCEEDS_LIMIT,
1248                                 "" + ValidationUtils.VENDOR_RELEASE_MAX_LENGTH);
1249         }
1250
1251         @Ignore
1252         public void testContactIdWrongFormat_UPDATE() {
1253                 Resource resource = createResourceObject(true);
1254                 Resource updatedResource = createResourceObject(true);
1255
1256                 // this is in order to prevent failing with 403 earlier
1257                 Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
1258                 when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
1259
1260                 String resourceId = resource.getUniqueId();
1261                 // 3 letters and 3 digits
1262                 String contactIdTooLong = "yrt134";
1263                 updatedResource.setContactId(contactIdTooLong);
1264                 Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
1265                 when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
1266                 Either<Resource, ResponseFormat> createResponse = bl.updateResourceMetadata(resourceId, updatedResource, null,
1267                                 user, false);
1268                 assertTrue(createResponse.isRight());
1269
1270                 assertResponse(createResponse, ActionStatus.COMPONENT_INVALID_CONTACT, ComponentTypeEnum.RESOURCE.getValue());
1271         }
1272
1273         @Test
1274         public void testResourceBadCategory_UPDATE() {
1275                 Resource resource = createResourceObject(true);
1276                 Resource updatedResource = createResourceObject(true);
1277
1278                 // this is in order to prevent failing with 403 earlier
1279                 Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
1280                 when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
1281
1282                 String resourceId = resource.getUniqueId();
1283                 String badCategory = "ddfds";
1284                 updatedResource.setCategories(null);
1285                 updatedResource.addCategory(badCategory, "fikt");
1286                 Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
1287                 when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
1288                 Either<Resource, ResponseFormat> createResponse = bl.updateResourceMetadata(resourceId, updatedResource, null,
1289                                 user, false);
1290                 assertTrue(createResponse.isRight());
1291
1292                 assertResponse(createResponse, ActionStatus.COMPONENT_INVALID_CATEGORY, ComponentTypeEnum.RESOURCE.getValue());
1293         }
1294
1295         @Test
1296         public void testResourceCategoryAfterCertify_UPDATE() {
1297                 Resource resource = createResourceObject(true);
1298                 Resource updatedResource = createResourceObject(true);
1299
1300                 // this is in order to prevent failing with 403 earlier
1301                 Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
1302                 when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
1303
1304                 String resourceId = resource.getUniqueId();
1305                 updatedResource.setCategories(null);
1306                 updatedResource.addCategory(RESOURCE_CATEGORY1, UPDATED_SUBCATEGORY);
1307                 resource.setVersion("1.0");
1308                 ;
1309                 Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
1310                 when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
1311                 Either<Resource, ResponseFormat> createResponse = bl.updateResourceMetadata(resourceId, updatedResource, null,
1312                                 user, false);
1313                 assertTrue(createResponse.isRight());
1314
1315                 assertResponse(createResponse, ActionStatus.RESOURCE_CATEGORY_CANNOT_BE_CHANGED);
1316         }
1317
1318         // Derived from start
1319         @Test
1320         public void testResourceTemplateNotExist_UPDATE() {
1321                 Resource resource = createResourceObject(true);
1322                 Resource updatedResource = createResourceObject(true);
1323
1324                 // this is in order to prevent failing with 403 earlier
1325                 Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
1326                 when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
1327                 String resourceId = resource.getUniqueId();
1328
1329                 List<String> list = null;
1330                 updatedResource.setDerivedFrom(list);
1331                 Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
1332                 when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
1333                 Either<Resource, ResponseFormat> createResponse = bl.updateResourceMetadata(resourceId, updatedResource, null,
1334                                 user, false);
1335                 assertTrue(createResponse.isRight());
1336
1337                 assertResponse(createResponse, ActionStatus.MISSING_DERIVED_FROM_TEMPLATE);
1338         }
1339
1340         @Test
1341         public void testResourceTemplateEmpty_UPDATE() {
1342                 Resource resource = createResourceObject(true);
1343                 Resource updatedResource = createResourceObject(true);
1344                 String resourceId = resource.getUniqueId();
1345
1346                 // this is in order to prevent failing with 403 earlier
1347                 Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
1348                 when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
1349
1350                 updatedResource.setDerivedFrom(new ArrayList<String>());
1351                 Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
1352                 when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
1353                 Either<Resource, ResponseFormat> createResponse = bl.updateResourceMetadata(resourceId, updatedResource, null,
1354                                 user, false);
1355                 assertTrue(createResponse.isRight());
1356
1357                 assertResponse(createResponse, ActionStatus.MISSING_DERIVED_FROM_TEMPLATE);
1358         }
1359
1360         @Test
1361         public void testResourceTemplateInvalid_UPDATE() {
1362                 Resource resource = createResourceObject(true);
1363                 Resource updatedResource = createResourceObject(true);
1364                 String resourceId = resource.getUniqueId();
1365
1366                 // this is in order to prevent failing with 403 earlier
1367                 Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
1368                 when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
1369
1370                 ArrayList<String> derivedFrom = new ArrayList<String>();
1371                 derivedFrom.add("kuku");
1372                 updatedResource.setDerivedFrom(derivedFrom);
1373                 Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
1374                 when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
1375                 Either<Resource, ResponseFormat> createResponse = bl.updateResourceMetadata(resourceId, updatedResource, null,
1376                                 user, false);
1377                 assertTrue(createResponse.isRight());
1378
1379                 assertResponse(createResponse, ActionStatus.PARENT_RESOURCE_NOT_FOUND);
1380         }
1381
1382         @Test
1383         public void testResourceTemplateCertify_UPDATE_HAPPY() {
1384                 Resource resource = createResourceObject(true);
1385                 Resource updatedResource = createResourceObject(true);
1386                 String resourceId = resource.getUniqueId();
1387
1388                 // this is in order to prevent failing with 403 earlier
1389                 Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
1390                 when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
1391
1392                 Either<Boolean, StorageOperationStatus> isToscaNameExtending = Either.left(true);
1393                 when(toscaOperationFacade.validateToscaResourceNameExtends(Mockito.anyString(), Mockito.anyString()))
1394                                 .thenReturn(isToscaNameExtending);
1395
1396                 Either<Map<String, PropertyDefinition>, StorageOperationStatus> findPropertiesOfNode = Either
1397                                 .left(new HashMap<>());
1398                 when(propertyOperation.deleteAllPropertiesAssociatedToNode(Mockito.any(NodeTypeEnum.class),
1399                                 Mockito.anyString())).thenReturn(findPropertiesOfNode);
1400
1401                 resource.setVersion("1.0");
1402
1403                 ArrayList<String> derivedFrom = new ArrayList<String>();
1404                 derivedFrom.add("tosca.nodes.Root");
1405                 updatedResource.setDerivedFrom(derivedFrom);
1406                 Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(updatedResource);
1407                 when(toscaOperationFacade.updateToscaElement(updatedResource)).thenReturn(dataModelResponse);
1408                 Either<Resource, ResponseFormat> createResponse = bl.updateResourceMetadata(resourceId, updatedResource, null,
1409                                 user, false);
1410                 assertTrue(createResponse.isLeft());
1411         }
1412
1413         @Test
1414         public void testResourceTemplateCertify_UPDATE_SAD() {
1415                 Resource resource = createResourceObject(true);
1416                 Resource updatedResource = createResourceObject(true);
1417                 String resourceId = resource.getUniqueId();
1418
1419                 // this is in order to prevent failing with 403 earlier
1420                 Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
1421                 when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
1422
1423                 Either<Boolean, StorageOperationStatus> isToscaNameExtending = Either.left(false);
1424                 when(toscaOperationFacade.validateToscaResourceNameExtends(Mockito.anyString(), Mockito.anyString()))
1425                                 .thenReturn(isToscaNameExtending);
1426
1427                 resource.setVersion("1.0");
1428
1429                 ArrayList<String> derivedFrom = new ArrayList<String>();
1430                 derivedFrom.add("tosca.nodes.Root");
1431                 updatedResource.setDerivedFrom(derivedFrom);
1432                 Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
1433                 when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
1434                 Either<Resource, ResponseFormat> createResponse = bl.updateResourceMetadata(resourceId, updatedResource, null,
1435                                 user, false);
1436                 assertTrue(createResponse.isRight());
1437
1438                 assertResponse(createResponse, ActionStatus.PARENT_RESOURCE_DOES_NOT_EXTEND);
1439         }
1440         // Derived from stop
1441
1442         @Test
1443         public void createOrUpdateResourceAlreadyCheckout() {
1444                 Resource resourceExist = createResourceObject(false);
1445
1446                 Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceExist,
1447                                 AuditingActionEnum.CREATE_RESOURCE, user, null, null);
1448
1449                 createResponse.left().value().setLastUpdaterUserId(user.getUserId());
1450                 assertTrue(createResponse.isLeft());
1451
1452                 Either<Component, StorageOperationStatus> getLatestResult = Either.left(createResponse.left().value());
1453                 when(toscaOperationFacade.getLatestByName(resourceExist.getName())).thenReturn(getLatestResult);
1454                 when(toscaOperationFacade.overrideComponent(Mockito.any(Component.class), Mockito.any(Component.class)))
1455                                 .thenReturn(getLatestResult);
1456
1457                 Resource resourceToUpdtae = createResourceObject(false);
1458
1459                 Either<ImmutablePair<Resource, ActionStatus>, ResponseFormat> createOrUpdateResource = bl
1460                                 .createOrUpdateResourceByImport(resourceToUpdtae, user, false, false, false, null);
1461                 assertTrue(createOrUpdateResource.isLeft());
1462
1463                 Mockito.verify(toscaOperationFacade, Mockito.times(1)).overrideComponent(Mockito.any(Resource.class),
1464                                 Mockito.any(Resource.class));
1465                 Mockito.verify(lifecycleBl, Mockito.times(0)).changeState(Mockito.anyString(), Mockito.eq(user),
1466                                 Mockito.eq(LifeCycleTransitionEnum.CHECKOUT), Mockito.any(LifecycleChangeInfoWithAction.class),
1467                                 Mockito.anyBoolean(), Mockito.anyBoolean());
1468
1469         }
1470
1471         @Test
1472         public void createOrUpdateResourceCertified() {
1473                 Resource resourceExist = createResourceObject(false);
1474
1475                 Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceExist,
1476                                 AuditingActionEnum.CREATE_RESOURCE, user, null, null);
1477
1478                 assertTrue(createResponse.isLeft());
1479                 Resource certifiedResource = createResponse.left().value();
1480                 certifiedResource.setLifecycleState(LifecycleStateEnum.CERTIFIED);
1481                 certifiedResource.setVersion("1.0");
1482
1483                 Either<Component, StorageOperationStatus> getLatestResult = Either.left(certifiedResource);
1484                 when(toscaOperationFacade.getLatestByName(resourceExist.getName())).thenReturn(getLatestResult);
1485                 when(toscaOperationFacade.overrideComponent(Mockito.any(Component.class), Mockito.any(Component.class)))
1486                                 .thenReturn(getLatestResult);
1487
1488                 when(lifecycleBl.changeState(Mockito.anyString(), Mockito.eq(user),
1489                                 Mockito.eq(LifeCycleTransitionEnum.CHECKOUT), Mockito.any(LifecycleChangeInfoWithAction.class),
1490                                 Mockito.anyBoolean(), Mockito.anyBoolean())).thenReturn(createResponse);
1491
1492                 Resource resourceToUpdtae = createResourceObject(false);
1493
1494                 Either<ImmutablePair<Resource, ActionStatus>, ResponseFormat> createOrUpdateResource = bl
1495                                 .createOrUpdateResourceByImport(resourceToUpdtae, user, false, false, false, null);
1496                 assertTrue(createOrUpdateResource.isLeft());
1497
1498                 Mockito.verify(toscaOperationFacade, Mockito.times(1)).overrideComponent(Mockito.any(Component.class),
1499                                 Mockito.any(Component.class));
1500                 Mockito.verify(lifecycleBl, Mockito.times(1)).changeState(Mockito.anyString(), Mockito.eq(user),
1501                                 Mockito.eq(LifeCycleTransitionEnum.CHECKOUT), Mockito.any(LifecycleChangeInfoWithAction.class),
1502                                 Mockito.anyBoolean(), Mockito.anyBoolean());
1503
1504         }
1505
1506         @Test
1507         public void createOrUpdateResourceNotExist() {
1508                 Resource resourceToUpdtae = createResourceObject(false);
1509
1510                 Either<Component, StorageOperationStatus> getLatestResult = Either.right(StorageOperationStatus.NOT_FOUND);
1511                 when(toscaOperationFacade.getLatestByName(resourceToUpdtae.getName())).thenReturn(getLatestResult);
1512
1513                 Either<Component, StorageOperationStatus> getLatestToscaNameResult = Either
1514                                 .right(StorageOperationStatus.NOT_FOUND);
1515                 when(toscaOperationFacade.getLatestByToscaResourceName(resourceToUpdtae.getToscaResourceName()))
1516                                 .thenReturn(getLatestToscaNameResult);
1517
1518                 Either<ImmutablePair<Resource, ActionStatus>, ResponseFormat> createOrUpdateResource = bl
1519                                 .createOrUpdateResourceByImport(resourceToUpdtae, user, false, false, false, null);
1520                 assertTrue(createOrUpdateResource.isLeft());
1521
1522                 Mockito.verify(toscaOperationFacade, Mockito.times(0)).overrideComponent(Mockito.any(Component.class),
1523                                 Mockito.any(Component.class));
1524                 Mockito.verify(lifecycleBl, Mockito.times(0)).changeState(Mockito.anyString(), Mockito.eq(user),
1525                                 Mockito.eq(LifeCycleTransitionEnum.CHECKOUT), Mockito.any(LifecycleChangeInfoWithAction.class),
1526                                 Mockito.anyBoolean(), Mockito.anyBoolean());
1527
1528         }
1529
1530         @Test
1531         public void testValidatePropertiesDefaultValues_SuccessfullWithoutProperties() {
1532                 Resource basic = createResourceObject(true);
1533
1534                 Either<Boolean, ResponseFormat> validatePropertiesDefaultValues = bl.validatePropertiesDefaultValues(basic);
1535                 assertTrue(validatePropertiesDefaultValues.isLeft());
1536         }
1537
1538         @Test
1539         public void testValidatePropertiesDefaultValues_SuccessfullWithProperties() {
1540                 Resource basic = createResourceObject(true);
1541                 PropertyDefinition property = new PropertyDefinition();
1542                 property.setName("myProperty");
1543                 property.setType(ToscaPropertyType.INTEGER.getType());
1544                 property.setDefaultValue("1");
1545                 List<PropertyDefinition> properties = new ArrayList<>();
1546                 properties.add(property);
1547                 basic.setProperties(properties);
1548                 when(propertyOperation.isPropertyTypeValid(property)).thenReturn(true);
1549                 when(propertyOperation.isPropertyDefaultValueValid(property, emptyDataTypes)).thenReturn(true);
1550                 Either<Boolean, ResponseFormat> validatePropertiesDefaultValues = bl.validatePropertiesDefaultValues(basic);
1551                 assertTrue(validatePropertiesDefaultValues.isLeft());
1552         }
1553
1554         @Test
1555         public void testValidatePropertiesDefaultValues_FailedWithProperties() {
1556                 Resource basic = createResourceObject(true);
1557                 PropertyDefinition property = new PropertyDefinition();
1558                 property.setName("myProperty");
1559                 property.setType(ToscaPropertyType.INTEGER.getType());
1560                 property.setDefaultValue("1.5");
1561                 List<PropertyDefinition> properties = new ArrayList<>();
1562                 properties.add(property);
1563                 basic.setProperties(properties);
1564
1565                 when(propertyOperation.isPropertyDefaultValueValid(property, emptyDataTypes)).thenReturn(false);
1566                 Either<Boolean, ResponseFormat> validatePropertiesDefaultValues = bl.validatePropertiesDefaultValues(basic);
1567                 assertTrue(validatePropertiesDefaultValues.isRight());
1568         }
1569
1570         // @Test
1571         // public void testDeleteMarkedResourcesNoResources() {
1572         // List<GraphVertex> ids = new ArrayList<>();
1573         // Either<List<GraphVertex>, StorageOperationStatus> eitherNoResources =
1574         // Either.left(ids);
1575         // when(topologyTemplateOperation.getAllComponentsMarkedForDeletion(ComponentTypeEnum.RESOURCE)).thenReturn(eitherNoResources);
1576         //
1577         // Either<List<String>, ResponseFormat> deleteMarkedResources =
1578         // bl.deleteMarkedComponents();
1579         // assertTrue(deleteMarkedResources.isLeft());
1580         // assertTrue(deleteMarkedResources.left().value().isEmpty());
1581         //
1582         // Mockito.verify(artifactManager,
1583         // Mockito.times(0)).deleteAllComponentArtifactsIfNotOnGraph(Mockito.anyList());
1584         //
1585         // }
1586         //
1587         // @Test
1588         // public void testDeleteMarkedResources() {
1589         // List<String> ids = new ArrayList<String>();
1590         // String resourceInUse = "123";
1591         // ids.add(resourceInUse);
1592         // String resourceFree = "456";
1593         // ids.add(resourceFree);
1594         // Either<List<String>, StorageOperationStatus> eitherNoResources =
1595         // Either.left(ids);
1596         // when(toscaOperationFacade.getAllComponentsMarkedForDeletion()).thenReturn(eitherNoResources);
1597         //
1598         // Either<Boolean, StorageOperationStatus> resourceInUseResponse =
1599         // Either.left(true);
1600         // Either<Boolean, StorageOperationStatus> resourceFreeResponse =
1601         // Either.left(false);
1602         //
1603         // List<ArtifactDefinition> artifacts = new ArrayList<ArtifactDefinition>();
1604         // Either<List<ArtifactDefinition>, StorageOperationStatus>
1605         // getArtifactsResponse = Either.left(artifacts);
1606         // when(toscaOperationFacade.getComponentArtifactsForDelete(resourceFree,
1607         // NodeTypeEnum.Resource, true)).thenReturn(getArtifactsResponse);
1608         //
1609         // when(toscaOperationFacade.isComponentInUse(resourceFree)).thenReturn(resourceFreeResponse);
1610         // when(toscaOperationFacade.isComponentInUse(resourceInUse)).thenReturn(resourceInUseResponse);
1611         //
1612         // Either<Component, StorageOperationStatus> eitherDelete = Either.left(new
1613         // Resource());
1614         // when(toscaOperationFacade.deleteToscaComponent(resourceFree)).thenReturn(eitherDelete);
1615         //
1616         // when(artifactManager.deleteAllComponentArtifactsIfNotOnGraph(artifacts)).thenReturn(StorageOperationStatus.OK);
1617         // List<String> deletedComponents = new ArrayList<>();
1618         // deletedComponents.add(resourceFree);
1619         // when(toscaOperationFacade.deleteMarkedElements(ComponentTypeEnum.RESOURCE)).thenReturn(Either.left(deletedComponents));
1620         //
1621         // Either<List<String>, ResponseFormat> deleteMarkedResources =
1622         // bl.deleteMarkedComponents();
1623         // assertTrue(deleteMarkedResources.isLeft());
1624         // List<String> resourceIdList = deleteMarkedResources.left().value();
1625         // assertFalse(resourceIdList.isEmpty());
1626         // assertTrue(resourceIdList.contains(resourceFree));
1627         // assertFalse(resourceIdList.contains(resourceInUse));
1628         //
1629         // Mockito.verify(artifactManager,
1630         // Mockito.times(1)).deleteAllComponentArtifactsIfNotOnGraph(artifacts);
1631         // }
1632
1633         
1634         @SuppressWarnings("unchecked")
1635         @Test
1636         public void testFindVfCsarArtifactsToHandle() {
1637
1638                 Class<ResourceBusinessLogic> targetClass = ResourceBusinessLogic.class;
1639                 String methodName = "findVfCsarArtifactsToHandle";
1640                 Resource resource = new Resource();
1641                 String deploymentArtifactToUpdateFileName = "deploymentArtifactToUpdate.yaml";
1642                 String deploymentArtifactToDeleteFileName = "deploymentArtifactToDelete.yaml";
1643                 String deploymentArtifactToCreateFileName = "deploymentArtifactToCreate.yaml";
1644
1645                 String artifactInfoToUpdateFileName = "infoArtifactToUpdate.yaml";
1646                 String artifactInfoToDeleteFileName = "infoArtifactToDelete.yaml";
1647                 String artifactInfoToCreateFileName = "infoArtifactToCreate.yaml";
1648
1649                 byte[] oldPayloadData = "oldPayloadData".getBytes();
1650                 byte[] newPayloadData = "newPayloadData".getBytes();
1651                 Map<String, ArtifactDefinition> deploymentArtifacts = new HashMap<>();
1652
1653                 ArtifactDefinition deploymentArtifactToUpdate = new ArtifactDefinition();
1654                 deploymentArtifactToUpdate.setMandatory(false);
1655                 deploymentArtifactToUpdate.setArtifactName(deploymentArtifactToUpdateFileName);
1656                 deploymentArtifactToUpdate.setArtifactType("SNMP_POLL");
1657                 deploymentArtifactToUpdate.setPayload(oldPayloadData);
1658                 deploymentArtifactToUpdate
1659                                 .setArtifactChecksum(GeneralUtility.calculateMD5Base64EncodedByByteArray(oldPayloadData));
1660
1661                 ArtifactDefinition deploymentArtifactToDelete = new ArtifactDefinition();
1662                 deploymentArtifactToDelete.setMandatory(false);
1663                 deploymentArtifactToDelete.setArtifactName(deploymentArtifactToDeleteFileName);
1664                 deploymentArtifactToDelete.setArtifactType("SNMP_TRAP");
1665                 deploymentArtifactToDelete.setPayload(oldPayloadData);
1666                 deploymentArtifactToDelete
1667                                 .setArtifactChecksum(GeneralUtility.calculateMD5Base64EncodedByByteArray(oldPayloadData));
1668
1669                 ArtifactDefinition deploymentArtifactToIgnore = new ArtifactDefinition();
1670
1671                 deploymentArtifacts.put(ValidationUtils.normalizeArtifactLabel(deploymentArtifactToUpdate.getArtifactName()),
1672                                 deploymentArtifactToUpdate);
1673                 deploymentArtifacts.put(ValidationUtils.normalizeArtifactLabel(deploymentArtifactToDelete.getArtifactName()),
1674                                 deploymentArtifactToDelete);
1675                 deploymentArtifacts.put("ignore", deploymentArtifactToIgnore);
1676
1677                 Map<String, ArtifactDefinition> artifacts = new HashMap<>();
1678
1679                 ArtifactDefinition artifactToUpdate = new ArtifactDefinition();
1680                 artifactToUpdate.setMandatory(false);
1681                 artifactToUpdate.setArtifactName(artifactInfoToUpdateFileName);
1682                 artifactToUpdate.setArtifactType("SNMP_POLL");
1683                 artifactToUpdate.setPayload(oldPayloadData);
1684                 artifactToUpdate.setArtifactChecksum(GeneralUtility.calculateMD5Base64EncodedByByteArray(oldPayloadData));
1685
1686                 ArtifactDefinition artifactToDelete = new ArtifactDefinition();
1687                 artifactToDelete.setMandatory(false);
1688                 artifactToDelete.setArtifactName(artifactInfoToDeleteFileName);
1689                 artifactToDelete.setArtifactType("SNMP_TRAP");
1690                 artifactToDelete.setPayload(oldPayloadData);
1691                 artifactToDelete.setArtifactChecksum(GeneralUtility.calculateMD5Base64EncodedByByteArray(oldPayloadData));
1692
1693                 ArtifactDefinition artifactToIgnore = new ArtifactDefinition();
1694
1695                 artifacts.put(ValidationUtils.normalizeArtifactLabel(artifactToUpdate.getArtifactName()), artifactToUpdate);
1696                 artifacts.put(ValidationUtils.normalizeArtifactLabel(artifactToDelete.getArtifactName()), artifactToDelete);
1697                 artifacts.put("ignore", artifactToIgnore);
1698
1699                 resource.setDeploymentArtifacts(deploymentArtifacts);
1700                 resource.setArtifacts(artifacts);
1701
1702                 List<NonMetaArtifactInfo> artifactPathAndNameList = new ArrayList<>();
1703                 NonMetaArtifactInfo deploymentArtifactInfoToUpdate = new NonMetaArtifactInfo(
1704                                 deploymentArtifactToUpdate.getArtifactName(), null,
1705                                 ArtifactTypeEnum.findType(deploymentArtifactToUpdate.getArtifactType()),
1706                                 ArtifactGroupTypeEnum.DEPLOYMENT, newPayloadData, deploymentArtifactToUpdate.getArtifactName());
1707
1708                 NonMetaArtifactInfo informationalArtifactInfoToUpdate = new NonMetaArtifactInfo(
1709                                 artifactToUpdate.getArtifactName(), null, ArtifactTypeEnum.findType(artifactToUpdate.getArtifactType()),
1710                                 ArtifactGroupTypeEnum.DEPLOYMENT, newPayloadData, artifactToUpdate.getArtifactName());
1711
1712                 NonMetaArtifactInfo deploymentArtifactInfoToCreate = new NonMetaArtifactInfo(deploymentArtifactToCreateFileName,
1713                                 null, ArtifactTypeEnum.OTHER, ArtifactGroupTypeEnum.DEPLOYMENT, newPayloadData,
1714                                 deploymentArtifactToCreateFileName);
1715
1716                 NonMetaArtifactInfo informationalArtifactInfoToCreate = new NonMetaArtifactInfo(artifactInfoToCreateFileName,
1717                                 null, ArtifactTypeEnum.OTHER, ArtifactGroupTypeEnum.DEPLOYMENT, newPayloadData,
1718                                 artifactInfoToCreateFileName);
1719
1720                 artifactPathAndNameList.add(deploymentArtifactInfoToUpdate);
1721                 artifactPathAndNameList.add(informationalArtifactInfoToUpdate);
1722                 artifactPathAndNameList.add(deploymentArtifactInfoToCreate);
1723                 artifactPathAndNameList.add(informationalArtifactInfoToCreate);
1724
1725                 Object[] argObjects = { resource, artifactPathAndNameList, user };
1726                 Class[] argClasses = { Resource.class, List.class, User.class };
1727                 try {
1728                         Method method = targetClass.getDeclaredMethod(methodName, argClasses);
1729                         method.setAccessible(true);
1730                         Either<EnumMap<ArtifactOperationEnum, List<NonMetaArtifactInfo>>, ResponseFormat> findVfCsarArtifactsToHandleRes = (Either<EnumMap<ArtifactOperationEnum, List<NonMetaArtifactInfo>>, ResponseFormat>) method
1731                                         .invoke(bl, argObjects);
1732                         assertTrue(findVfCsarArtifactsToHandleRes.isLeft());
1733                         EnumMap<ArtifactOperationEnum, List<NonMetaArtifactInfo>> foundVfArtifacts = findVfCsarArtifactsToHandleRes
1734                                         .left().value();
1735                         assertTrue(foundVfArtifacts.get(ArtifactOperationEnum.Create).size() == 2);
1736                         assertTrue(foundVfArtifacts.get(ArtifactOperationEnum.Update).size() == 2);
1737                         assertTrue(foundVfArtifacts.get(ArtifactOperationEnum.Create).size() == 2);
1738
1739                 } catch (Exception e) {
1740                         e.printStackTrace();
1741                 }
1742         }
1743
1744         @SuppressWarnings("rawtypes")
1745         @Test
1746         public void testBuildNestedVfcToscaNamespace() {
1747
1748                 Class<ResourceBusinessLogic> targetClass = ResourceBusinessLogic.class;
1749                 String methodName = "buildNestedVfcToscaNamespace";
1750                 String nodeTypeFullName = "org.openecomp.resource.abstract.nodes.heat.FEAdd_On_Module_vLBAgentTemplate";
1751                 String expectedNestedVfcToscaNamespace = "org.openecomp.resource.vfc.nodes.heat.FEAdd_On_Module_vLBAgentTemplate";
1752                 Object[] argObjects = { nodeTypeFullName };
1753                 Class[] argClasses = { String.class };
1754                 try {
1755                         Method method = targetClass.getDeclaredMethod(methodName, argClasses);
1756                         method.setAccessible(true);
1757                         String actualNestedVfcToscaNamespace = (String) method.invoke(bl, argObjects);
1758                         assertTrue(!actualNestedVfcToscaNamespace.isEmpty());
1759                         assertTrue(actualNestedVfcToscaNamespace.equals(expectedNestedVfcToscaNamespace));
1760
1761                 } catch (Exception e) {
1762                         e.printStackTrace();
1763                 }
1764         }
1765
1766         @SuppressWarnings("rawtypes")
1767         @Test
1768         public void testBuildNestedVfcToscaResourceName() {
1769
1770                 Class<ResourceBusinessLogic> targetClass = ResourceBusinessLogic.class;
1771                 String methodName = "buildNestedVfcToscaResourceName";
1772                 String vfResourceName = "vfname";
1773                 String nodeTypeFullName = "org.openecomp.resource.abstract.nodes.heat.FEAdd_On_Module_vLBAgentTemplate";
1774                 String expectedNestedVfcToscaResourceName = "org.openecomp.resource.vfc.vfname.abstract.nodes.heat.FEAdd_On_Module_vLBAgentTemplate";
1775                 Object[] argObjects = { vfResourceName, nodeTypeFullName };
1776                 Class[] argClasses = { String.class, String.class };
1777                 try {
1778                         Method method = targetClass.getDeclaredMethod(methodName, argClasses);
1779                         method.setAccessible(true);
1780                         String actualNestedVfcToscaResourceName = (String) method.invoke(bl, argObjects);
1781                         assertTrue(!actualNestedVfcToscaResourceName.isEmpty());
1782                         assertTrue(actualNestedVfcToscaResourceName.equals(expectedNestedVfcToscaResourceName));
1783
1784                 } catch (Exception e) {
1785                         e.printStackTrace();
1786                 }
1787         }
1788
1789         @SuppressWarnings("rawtypes")
1790         @Test
1791         public void testBuildNestedSubstituteYamlName() {
1792
1793                 Class<ResourceBusinessLogic> targetClass = ResourceBusinessLogic.class;
1794                 String methodName = "buildNestedSubstituteYamlName";
1795                 String nodeTypeFullName = "org.openecomp.resource.abstract.nodes.heat.FEAdd_On_Module_vLBAgentTemplate";
1796                 String expectedNestedSubstituteYamlName = "Definitions/FEAdd_On_Module_vLBAgentTemplateServiceTemplate.yaml";
1797                 Object[] argObjects = { nodeTypeFullName };
1798                 Class[] argClasses = { String.class };
1799                 try {
1800                         Method method = targetClass.getDeclaredMethod(methodName, argClasses);
1801                         method.setAccessible(true);
1802                         String actualNestedSubstituteYamlName = (String) method.invoke(bl, argObjects);
1803                         assertTrue(!actualNestedSubstituteYamlName.isEmpty());
1804                         assertTrue(actualNestedSubstituteYamlName.equals(expectedNestedSubstituteYamlName));
1805
1806                 } catch (Exception e) {
1807                         e.printStackTrace();
1808                 }
1809         }
1810
1811         @Test
1812         public void testVFGeneratedInputs() {
1813
1814                 Resource resource = createVF();
1815                 List<InputDefinition> inputs = resource.getInputs();
1816                 assertTrue(8 == inputs.size());
1817                 for (InputDefinition input : inputs) {
1818                         assertNotNull(input.getOwnerId());
1819                 }
1820                 assertTrue(resource.getDerivedFromGenericType().equals(genericVF.getToscaResourceName()));
1821                 assertTrue(resource.getDerivedFromGenericVersion().equals(genericVF.getVersion()));
1822         }
1823
1824         @Test
1825         public void testVFUpdateGenericInputsToLatestOnCheckout() {
1826
1827                 // create a VF that is derived from generic version 1.0
1828                 Resource resource = createVF();
1829                 // create a new generic version without properties
1830                 genericVF.setVersion("2.0");
1831                 genericVF.setProperties(null);
1832                 String currentDerivedFromVersion = resource.getDerivedFromGenericVersion();
1833                 List<InputDefinition> currentInputs = resource.getInputs();
1834                 // verify previous inputs ownerId fields exist - user may not delete
1835                 // generated inputs
1836                 assertTrue(8 == currentInputs.stream().filter(p -> null != p.getOwnerId()).collect(Collectors.toList()).size());
1837                 Either<Boolean, ResponseFormat> upgradeToLatestGeneric = bl.shouldUpgradeToLatestGeneric(resource);
1838                 // verify success
1839                 assertTrue(upgradeToLatestGeneric.isLeft());
1840                 // verify update required and valid
1841                 assertTrue(upgradeToLatestGeneric.left().value());
1842                 // verify version was upgraded
1843                 assertFalse(resource.getDerivedFromGenericVersion().equals(currentDerivedFromVersion));
1844                 // verify inputs were not deleted
1845                 assertTrue(8 == resource.getInputs().size());
1846                 // verify inputs ownerId fields were removed - user may delete/edit
1847                 // inputs
1848                 assertTrue(8 == resource.getInputs().stream().filter(p -> null == p.getOwnerId()).collect(Collectors.toList())
1849                                 .size());
1850         }
1851
1852         @Test
1853         public void testVFUpdateGenericInputsToLatestOnCheckoutNotPerformed() {
1854
1855                 // create a VF that is derived from generic version 1.0
1856                 Resource resource = createVF();
1857
1858                 // add an input to the VF
1859                 PropertyDefinition newProp = new PropertyDefinition();
1860                 newProp.setType("integer");
1861                 newProp.setName("newProp");
1862                 resource.getInputs().add(new InputDefinition(newProp));
1863
1864                 // create a new generic version with a new property which has the same
1865                 // name as a user defined input on the VF with a different type
1866                 genericVF.setVersion("2.0");
1867                 newProp.setType("string");
1868                 genericVF.setProperties(new ArrayList<PropertyDefinition>());
1869                 genericVF.getProperties().add(newProp);
1870
1871                 String currentDerivedFromVersion = resource.getDerivedFromGenericVersion();
1872                 assertTrue(8 == resource.getInputs().stream().filter(p -> null != p.getOwnerId()).collect(Collectors.toList())
1873                                 .size());
1874                 Either<Boolean, ResponseFormat> upgradeToLatestGeneric = bl.shouldUpgradeToLatestGeneric(resource);
1875                 // verify success
1876                 assertTrue(upgradeToLatestGeneric.isLeft());
1877                 // verify update is invalid an void
1878                 assertFalse(upgradeToLatestGeneric.left().value());
1879                 // verify version was not upgraded
1880                 assertTrue(resource.getDerivedFromGenericVersion().equals(currentDerivedFromVersion));
1881                 // verify inputs were not removed
1882                 assertTrue(9 == resource.getInputs().size());
1883                 // verify user defined input exists
1884                 assertTrue(1 == resource.getInputs().stream().filter(p -> null == p.getOwnerId()).collect(Collectors.toList())
1885                                 .size());
1886                 assertTrue(resource.getInputs().stream().filter(p -> null == p.getOwnerId()).findAny().get().getType()
1887                                 .equals("integer"));
1888         }
1889
1890         @Test
1891         public void testPNFGeneratedInputsNoGeneratedInformationalArtifacts() {
1892
1893                 Resource resource = createPNF();
1894                 List<InputDefinition> inputs = resource.getInputs();
1895                 assertTrue(8 == inputs.size());
1896                 for (InputDefinition input : inputs) {
1897                         assertNotNull(input.getOwnerId());
1898                 }
1899                 assertTrue(resource.getDerivedFromGenericType().equals(genericPNF.getToscaResourceName()));
1900                 assertTrue(resource.getDerivedFromGenericVersion().equals(genericPNF.getVersion()));
1901                 assertTrue(0 == resource.getArtifacts().size());
1902         }
1903
1904         private Resource createVF() {
1905
1906                 genericVF = setupGenericTypeMock(GENERIC_VF_NAME);
1907                 when(toscaOperationFacade.getLatestCertifiedNodeTypeByToscaResourceName(GENERIC_VF_NAME))
1908                                 .thenReturn(Either.left(genericVF));
1909                 Resource resource = createResourceObject(true);
1910                 resource.setDerivedFrom(null);
1911                 resource.setResourceType(ResourceTypeEnum.VF);
1912                 when(toscaOperationFacade.createToscaComponent(resource)).thenReturn(Either.left(resource));
1913                 Either<Resource, ResponseFormat> createResponse = bl.createResource(resource,
1914                                 AuditingActionEnum.CREATE_RESOURCE, user, null, null);
1915                 assertTrue(createResponse.isLeft());
1916                 return createResponse.left().value();
1917         }
1918
1919         private Resource createPNF() {
1920
1921                 genericPNF = setupGenericTypeMock(GENERIC_PNF_NAME);
1922                 when(toscaOperationFacade.getLatestCertifiedNodeTypeByToscaResourceName(GENERIC_PNF_NAME))
1923                                 .thenReturn(Either.left(genericPNF));
1924                 Resource resource = createResourceObject(true);
1925                 resource.setDerivedFrom(null);
1926                 resource.setResourceType(ResourceTypeEnum.PNF);
1927                 when(toscaOperationFacade.createToscaComponent(resource)).thenReturn(Either.left(resource));
1928                 Either<Resource, ResponseFormat> createResponse = bl.createResource(resource,
1929                                 AuditingActionEnum.CREATE_RESOURCE, user, null, null);
1930                 assertTrue(createResponse.isLeft());
1931                 return createResponse.left().value();
1932         }
1933
1934         private Resource setupGenericTypeMock(String toscaName) {
1935
1936                 Resource genericType = createResourceObject(true);
1937                 genericType.setVersion("1.0");
1938                 genericType.setToscaResourceName(toscaName);
1939                 String[] propNames = { "nf_function", "nf_role", "nf_naming_code", "nf_type", "nf_naming",
1940                                 "availability_zone_max_count", "min_instances", "max_instances" };
1941                 String[] propTypes = { "string", "string", "string", "string", "org.openecomp.datatypes.Naming", "integer",
1942                                 "integer", "integer" };
1943                 List<PropertyDefinition> genericProps = new ArrayList<>();
1944                 for (int i = 0; i < 8; ++i) {
1945                         PropertyDefinition prop = new PropertyDefinition();
1946                         prop.setName(propNames[i]);
1947                         prop.setType(propTypes[i]);
1948                         genericProps.add(prop);
1949                 }
1950                 genericType.setProperties(genericProps);
1951                 return genericType;
1952         }
1953
1954         private ResourceBusinessLogic createTestSubject() {
1955                 return new ResourceBusinessLogic();
1956         }
1957
1958         @Test
1959         public void testGetCsarOperation() throws Exception {
1960                 ResourceBusinessLogic testSubject;
1961                 CsarOperation result;
1962
1963                 // default test
1964                 testSubject = createTestSubject();
1965                 result = testSubject.getCsarOperation();
1966         }
1967
1968         @Test
1969         public void testSetCsarOperation() throws Exception {
1970                 ResourceBusinessLogic testSubject;
1971                 CsarOperation csarOperation = null;
1972
1973                 // default test
1974                 testSubject = createTestSubject();
1975                 testSubject.setCsarOperation(csarOperation);
1976         }
1977
1978         
1979         @Test
1980         public void testGetLifecycleBusinessLogic() throws Exception {
1981                 ResourceBusinessLogic testSubject;
1982                 LifecycleBusinessLogic result;
1983
1984                 // default test
1985                 testSubject = createTestSubject();
1986                 result = testSubject.getLifecycleBusinessLogic();
1987         }
1988
1989         
1990         @Test
1991         public void testSetLifecycleManager() throws Exception {
1992                 ResourceBusinessLogic testSubject;
1993                 LifecycleBusinessLogic lifecycleBusinessLogic = null;
1994
1995                 // default test
1996                 testSubject = createTestSubject();
1997                 testSubject.setLifecycleManager(lifecycleBusinessLogic);
1998         }
1999
2000         
2001         @Test
2002         public void testGetElementDao() throws Exception {
2003                 ResourceBusinessLogic testSubject;
2004                 IElementOperation result;
2005
2006                 // default test
2007                 testSubject = createTestSubject();
2008                 result = testSubject.getElementDao();
2009         }
2010
2011         
2012         @Test
2013         public void testSetElementDao() throws Exception {
2014                 ResourceBusinessLogic testSubject;
2015                 IElementOperation elementDao = null;
2016
2017                 // default test
2018                 testSubject = createTestSubject();
2019                 testSubject.setElementDao(elementDao);
2020         }
2021
2022         
2023         @Test
2024         public void testGetUserAdmin() throws Exception {
2025                 ResourceBusinessLogic testSubject;
2026                 IUserBusinessLogic result;
2027
2028                 // default test
2029                 testSubject = createTestSubject();
2030                 result = testSubject.getUserAdmin();
2031         }
2032
2033         
2034         @Test
2035         public void testSetUserAdmin() throws Exception {
2036                 ResourceBusinessLogic testSubject;
2037                 UserBusinessLogic userAdmin = null;
2038
2039                 // default test
2040                 testSubject = createTestSubject();
2041                 testSubject.setUserAdmin(userAdmin);
2042         }
2043
2044         
2045         @Test
2046         public void testGetComponentsUtils() throws Exception {
2047                 ResourceBusinessLogic testSubject;
2048                 ComponentsUtils result;
2049
2050                 // default test
2051                 testSubject = createTestSubject();
2052                 result = testSubject.getComponentsUtils();
2053         }
2054
2055         
2056         @Test
2057         public void testSetComponentsUtils() throws Exception {
2058                 ResourceBusinessLogic testSubject;
2059                 ComponentsUtils componentsUtils = null;
2060
2061                 // default test
2062                 testSubject = createTestSubject();
2063                 testSubject.setComponentsUtils(componentsUtils);
2064         }
2065
2066         
2067         @Test
2068         public void testGetArtifactsManager() throws Exception {
2069                 ResourceBusinessLogic testSubject;
2070                 ArtifactsBusinessLogic result;
2071
2072                 // default test
2073                 testSubject = createTestSubject();
2074                 result = testSubject.getArtifactsManager();
2075         }
2076
2077         
2078         @Test
2079         public void testSetArtifactsManager() throws Exception {
2080                 ResourceBusinessLogic testSubject;
2081                 ArtifactsBusinessLogic artifactsManager = null;
2082
2083                 // default test
2084                 testSubject = createTestSubject();
2085                 testSubject.setArtifactsManager(artifactsManager);
2086         }
2087
2088         
2089         @Test
2090         public void testSetPropertyOperation() throws Exception {
2091                 ResourceBusinessLogic testSubject;
2092                 IPropertyOperation propertyOperation = null;
2093
2094                 // default test
2095                 testSubject = createTestSubject();
2096                 testSubject.setPropertyOperation(propertyOperation);
2097         }
2098
2099         
2100         @Test
2101         public void testGetApplicationDataTypeCache() throws Exception {
2102                 ResourceBusinessLogic testSubject;
2103                 ApplicationDataTypeCache result;
2104
2105                 // default test
2106                 testSubject = createTestSubject();
2107                 result = testSubject.getApplicationDataTypeCache();
2108         }
2109
2110         
2111         @Test
2112         public void testSetApplicationDataTypeCache() throws Exception {
2113                 ResourceBusinessLogic testSubject;
2114                 ApplicationDataTypeCache applicationDataTypeCache = null;
2115
2116                 // default test
2117                 testSubject = createTestSubject();
2118                 testSubject.setApplicationDataTypeCache(applicationDataTypeCache);
2119         }
2120         
2121         @Test
2122         public void testSetDeploymentArtifactsPlaceHolder() throws Exception {
2123                 ResourceBusinessLogic testSubject;
2124                 Component component = new Resource() {
2125                 };
2126                 User user = null;
2127
2128                 // default test
2129                 testSubject = createTestSubject();
2130                 testSubject.setDeploymentArtifactsPlaceHolder(component, user);
2131         }
2132
2133
2134         
2135         @Test
2136         public void testValidateVendorReleaseName_1() throws Exception {
2137                 ResourceBusinessLogic testSubject;
2138                 String vendorRelease = "";
2139                 Either<Boolean, ResponseFormat> result;
2140
2141                 // test 1
2142                 testSubject = createTestSubject();
2143                 vendorRelease = null;
2144                 result = testSubject.validateVendorReleaseName(vendorRelease);
2145                 Assert.assertEquals(false, result.left().value());
2146
2147         }
2148
2149         
2150
2151
2152
2153         
2154         @Test
2155         public void testGetCapabilityTypeOperation() throws Exception {
2156                 ResourceBusinessLogic testSubject;
2157                 ICapabilityTypeOperation result;
2158
2159                 // default test
2160                 testSubject = createTestSubject();
2161                 result = testSubject.getCapabilityTypeOperation();
2162         }
2163
2164         
2165         @Test
2166         public void testSetCapabilityTypeOperation() throws Exception {
2167                 ResourceBusinessLogic testSubject;
2168                 ICapabilityTypeOperation capabilityTypeOperation = null;
2169
2170                 // default test
2171                 testSubject = createTestSubject();
2172                 testSubject.setCapabilityTypeOperation(capabilityTypeOperation);
2173         }
2174
2175         
2176         @Test
2177         public void testValidatePropertiesDefaultValues() throws Exception {
2178                 ResourceBusinessLogic testSubject;
2179                 Resource resource = new Resource();
2180                 Either<Boolean, ResponseFormat> result;
2181
2182                 // default test
2183                 testSubject = createTestSubject();
2184                 result = testSubject.validatePropertiesDefaultValues(resource);
2185         }
2186
2187         
2188         @Test
2189         public void testGetComponentInstanceBL() throws Exception {
2190                 ResourceBusinessLogic testSubject;
2191                 ComponentInstanceBusinessLogic result;
2192
2193                 // default test
2194                 testSubject = createTestSubject();
2195                 result = testSubject.getComponentInstanceBL();
2196         }
2197
2198
2199         
2200         @Test
2201         public void testGetComponentInstancesFilteredByPropertiesAndInputs() throws Exception {
2202                 ResourceBusinessLogic testSubject;
2203                 String componentId = "";
2204                 ComponentTypeEnum componentTypeEnum = null;
2205                 String userId = "";
2206                 String searchText = "";
2207                 Either<List<ComponentInstance>, ResponseFormat> result;
2208
2209                 // default test
2210                 testSubject = createTestSubject();
2211                 result = testSubject.getComponentInstancesFilteredByPropertiesAndInputs(componentId, componentTypeEnum, userId,
2212                                 searchText);
2213         }
2214
2215
2216         
2217         @Test
2218         public void testGetCacheManagerOperation() throws Exception {
2219                 ResourceBusinessLogic testSubject;
2220                 ICacheMangerOperation result;
2221
2222                 // default test
2223                 testSubject = createTestSubject();
2224                 result = testSubject.getCacheManagerOperation();
2225         }
2226
2227         
2228         @Test
2229         public void testSetCacheManagerOperation() throws Exception {
2230                 ResourceBusinessLogic testSubject;
2231                 ICacheMangerOperation cacheManagerOperation = null;
2232
2233                 // default test
2234                 testSubject = createTestSubject();
2235                 testSubject.setCacheManagerOperation(cacheManagerOperation);
2236         }
2237
2238         
2239         @Test
2240         public void testGetElementDao_1() throws Exception {
2241         ResourceBusinessLogic testSubject;IElementOperation result;
2242         
2243         // default test
2244         testSubject=createTestSubject();result=testSubject.getElementDao();
2245         }
2246
2247         
2248         @Test
2249         public void testGetAllCertifiedResources() throws Exception {
2250         ResourceBusinessLogic testSubject;boolean getAbstract = false;
2251         HighestFilterEnum highestFilter = null;
2252         String userId = "";
2253         Either<List<Resource>,ResponseFormat> result;
2254         
2255         // default test
2256         }
2257
2258         
2259         @Test
2260         public void testValidateResourceNameExists() throws Exception {
2261         ResourceBusinessLogic testSubject;String resourceName = "";
2262         ResourceTypeEnum resourceTypeEnum = null;
2263         String userId = "";
2264         Either<Map<String,Boolean>,ResponseFormat> result;
2265         
2266         // default test
2267         }
2268
2269         
2270         @Test
2271         public void testCreateResource() throws Exception {
2272         ResourceBusinessLogic testSubject;Resource resource = null;
2273         AuditingActionEnum auditingAction = null;
2274         User user = null;
2275         Map<String,byte[]> csarUIPayload = null;
2276         String payloadName = "";
2277         Either<Resource,ResponseFormat> result;
2278         
2279         // test 1
2280         testSubject=createTestSubject();payloadName = null;
2281         
2282         // test 2
2283         testSubject=createTestSubject();payloadName = "";
2284         }
2285
2286         
2287         @Test
2288         public void testValidateAndUpdateResourceFromCsar() throws Exception {
2289         ResourceBusinessLogic testSubject;Resource resource = null;
2290         User user = null;
2291         Map<String,byte[]> csarUIPayload = null;
2292         String payloadName = "";
2293         String resourceUniqueId = "";
2294         Either<Resource,ResponseFormat> result;
2295         
2296         // test 1
2297         testSubject=createTestSubject();payloadName = null;
2298         
2299         // test 2
2300         testSubject=createTestSubject();payloadName = "";
2301         }
2302
2303         
2304
2305
2306         
2307
2308
2309
2310
2311         
2312         
2313         @Test
2314         public void testCreateResourceFromCsar() throws Exception {
2315         ResourceBusinessLogic testSubject;Resource resource = null;
2316         User user = null;
2317         Either<Map<String,byte[]>,StorageOperationStatus> csarUIPayload = null;
2318         String csarUUID = "";
2319         Either<Resource,ResponseFormat> result;
2320         
2321         // test 1
2322         testSubject=createTestSubject();csarUIPayload = null;
2323         }
2324
2325         
2326
2327
2328         
2329         
2330         
2331         @Test
2332         public void testCreateResourcesFromYamlNodeTypesList() throws Exception {
2333         ResourceBusinessLogic testSubject;String yamlName = "";
2334         Resource resource = null;
2335         Map<String,Object> mappedToscaTemplate = null;
2336         boolean needLock = false;
2337         Map<String,EnumMap<ArtifactOperationEnum,List<ArtifactDefinition>>> nodeTypesArtifactsToHandle = null;
2338         List<ArtifactDefinition> nodeTypesNewCreatedArtifacts = null;
2339         Map<String,NodeTypeInfo> nodeTypesInfo = null;
2340         CsarInfo csarInfo = null;
2341         Either<Map<String,Resource>,ResponseFormat> result;
2342         
2343         // default test
2344         }
2345
2346         
2347
2348
2349
2350         
2351         @Test
2352         public void testValidateResourceCreationFromNodeType() throws Exception {
2353         ResourceBusinessLogic testSubject;Resource resource = null;
2354         User creator = null;
2355         Either<Boolean,ResponseFormat> result;
2356         
2357         // default test
2358         }
2359
2360         
2361         @Test
2362         public void testCreateResourceFromNodeType() throws Exception {
2363         ResourceBusinessLogic testSubject;String nodeTypeYaml = "";
2364         UploadResourceInfo resourceMetaData = null;
2365         User creator = null;
2366         boolean isInTransaction = false;
2367         boolean needLock = false;
2368         Map<ArtifactOperationEnum,List<ArtifactDefinition>> nodeTypeArtifactsToHandle = null;
2369         List<ArtifactDefinition> nodeTypesNewCreatedArtifacts = null;
2370         boolean forceCertificationAllowed = false;
2371         CsarInfo csarInfo = null;
2372         Either<ImmutablePair<Resource,ActionStatus>,ResponseFormat> result;
2373         
2374         // default test
2375         }
2376
2377 }