Merge "Revert "[sdc] - ecomp portal version fix""
[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.*;
24 import static org.mockito.Mockito.when;
25
26 import java.lang.reflect.Method;
27 import java.util.ArrayList;
28 import java.util.EnumMap;
29 import java.util.HashMap;
30 import java.util.List;
31 import java.util.Map;
32 import java.util.stream.Collectors;
33
34 import javax.servlet.ServletContext;
35
36 import org.apache.commons.lang3.tuple.ImmutablePair;
37 import org.junit.Before;
38 import org.junit.Ignore;
39 import org.junit.Test;
40 import org.mockito.InjectMocks;
41 import org.mockito.Mockito;
42 import org.mockito.MockitoAnnotations;
43 import org.openecomp.sdc.ElementOperationMock;
44 import org.openecomp.sdc.be.auditing.api.IAuditingManager;
45 import org.openecomp.sdc.be.auditing.impl.AuditingLogFormatUtil;
46 import org.openecomp.sdc.be.auditing.impl.AuditingManager;
47 import org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic.ArtifactOperationEnum;
48 import org.openecomp.sdc.be.components.lifecycle.LifecycleBusinessLogic;
49 import org.openecomp.sdc.be.components.lifecycle.LifecycleChangeInfoWithAction;
50 import org.openecomp.sdc.be.config.ConfigurationManager;
51 import org.openecomp.sdc.be.dao.api.ActionStatus;
52 import org.openecomp.sdc.be.dao.jsongraph.TitanDao;
53 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
54 import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
55 import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
56 import org.openecomp.sdc.be.impl.ComponentsUtils;
57 import org.openecomp.sdc.be.impl.WebAppContextWrapper;
58 import org.openecomp.sdc.be.model.ArtifactDefinition;
59 import org.openecomp.sdc.be.model.Component;
60 import org.openecomp.sdc.be.model.DataTypeDefinition;
61 import org.openecomp.sdc.be.model.InputDefinition;
62 import org.openecomp.sdc.be.model.LifeCycleTransitionEnum;
63 import org.openecomp.sdc.be.model.LifecycleStateEnum;
64 import org.openecomp.sdc.be.model.PropertyDefinition;
65 import org.openecomp.sdc.be.model.Resource;
66 import org.openecomp.sdc.be.model.User;
67 import org.openecomp.sdc.be.model.cache.ApplicationDataTypeCache;
68 import org.openecomp.sdc.be.model.jsontitan.operations.NodeTemplateOperation;
69 import org.openecomp.sdc.be.model.jsontitan.operations.NodeTypeOperation;
70 import org.openecomp.sdc.be.model.jsontitan.operations.TopologyTemplateOperation;
71 import org.openecomp.sdc.be.model.jsontitan.operations.ToscaOperationFacade;
72 import org.openecomp.sdc.be.model.operations.api.ICapabilityTypeOperation;
73 import org.openecomp.sdc.be.model.operations.api.IElementOperation;
74 import org.openecomp.sdc.be.model.operations.api.IPropertyOperation;
75 import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
76 import org.openecomp.sdc.be.model.operations.impl.CacheMangerOperation;
77 import org.openecomp.sdc.be.model.operations.impl.CsarOperation;
78 import org.openecomp.sdc.be.model.operations.impl.GraphLockOperation;
79 import org.openecomp.sdc.be.model.tosca.ToscaPropertyType;
80 import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
81 import org.openecomp.sdc.be.tosca.CsarUtils.NonMetaArtifactInfo;
82 import org.openecomp.sdc.be.user.Role;
83 import org.openecomp.sdc.be.user.UserBusinessLogic;
84 import org.openecomp.sdc.common.api.ArtifactGroupTypeEnum;
85 import org.openecomp.sdc.common.api.ArtifactTypeEnum;
86 import org.openecomp.sdc.common.api.ConfigurationSource;
87 import org.openecomp.sdc.common.api.Constants;
88 import org.openecomp.sdc.common.impl.ExternalConfiguration;
89 import org.openecomp.sdc.common.impl.FSConfigurationSource;
90 import org.openecomp.sdc.common.util.GeneralUtility;
91 import org.openecomp.sdc.common.util.ValidationUtils;
92 import org.openecomp.sdc.exception.ResponseFormat;
93 import org.slf4j.Logger;
94 import org.slf4j.LoggerFactory;
95 import org.springframework.web.context.WebApplicationContext;
96
97 import fj.data.Either;
98
99 public class ResourceBusinessLogicTest {
100
101         private static Logger log = LoggerFactory.getLogger(ResourceBusinessLogicTest.class.getName());
102         public static final String RESOURCE_CATEGORY = "Network Layer 2-3/Router";
103         public static final String RESOURCE_CATEGORY1 = "Network Layer 2-3";
104         public static final String RESOURCE_SUBCATEGORY = "Router";
105
106         public static final String UPDATED_CATEGORY = "Network Layer 2-3/Gateway";
107         public static final String UPDATED_SUBCATEGORY = "Gateway";
108
109         public static final String RESOURCE_NAME = "My-Resource_Name with   space";
110     private static final String GENERIC_VF_NAME = "org.openecomp.resource.abstract.nodes.VF";
111     private static final String GENERIC_VFC_NAME = "org.openecomp.resource.abstract.nodes.VFC";
112     private static final String GENERIC_PNF_NAME = "org.openecomp.resource.abstract.nodes.PNF";
113     
114         final ServletContext servletContext = Mockito.mock(ServletContext.class);
115         IAuditingManager iAuditingManager = null;
116         IElementOperation mockElementDao;
117         TitanDao mockTitanDao = Mockito.mock(TitanDao.class);
118         UserBusinessLogic mockUserAdmin = Mockito.mock(UserBusinessLogic.class);
119         ToscaOperationFacade toscaOperationFacade = Mockito.mock(ToscaOperationFacade.class);
120         NodeTypeOperation nodeTypeOperation = Mockito.mock(NodeTypeOperation.class);
121         NodeTemplateOperation nodeTemplateOperation = Mockito.mock(NodeTemplateOperation.class);
122         TopologyTemplateOperation topologyTemplateOperation = Mockito.mock(TopologyTemplateOperation.class);
123         final LifecycleBusinessLogic lifecycleBl = Mockito.mock(LifecycleBusinessLogic.class);
124         final ICapabilityTypeOperation capabilityTypeOperation = Mockito.mock(ICapabilityTypeOperation.class);
125         final IPropertyOperation propertyOperation = Mockito.mock(IPropertyOperation.class);
126         final ApplicationDataTypeCache applicationDataTypeCache = Mockito.mock(ApplicationDataTypeCache.class);
127         WebAppContextWrapper webAppContextWrapper = Mockito.mock(WebAppContextWrapper.class);
128         WebApplicationContext webAppContext = Mockito.mock(WebApplicationContext.class);
129         AuditingLogFormatUtil auditingLogFormatter = Mockito.mock(AuditingLogFormatUtil.class);
130         @InjectMocks
131         ResourceBusinessLogic bl = new ResourceBusinessLogic();
132         ResponseFormatManager responseManager = null;
133         AuditingManager auditingManager = Mockito.mock(AuditingManager.class);
134         GraphLockOperation graphLockOperation = Mockito.mock(GraphLockOperation.class);
135         User user = null;
136         Resource resourceResponse = null;
137         Resource genericVF = null;
138         Resource genericVFC = null;
139         Resource genericPNF = null;
140         ComponentsUtils componentsUtils = new ComponentsUtils();
141         ArtifactsBusinessLogic artifactManager = new ArtifactsBusinessLogic();
142         CsarOperation csarOperation = Mockito.mock(CsarOperation.class);
143         Map<String, DataTypeDefinition> emptyDataTypes = new HashMap<String, DataTypeDefinition>();
144
145         CacheMangerOperation cacheManager = Mockito.mock(CacheMangerOperation.class);
146
147         public ResourceBusinessLogicTest() {
148
149         }
150
151         @Before
152         public void setup() {
153                 MockitoAnnotations.initMocks(this);
154                 Mockito.reset(propertyOperation);
155
156                 ExternalConfiguration.setAppName("catalog-be");
157
158                 // Init Configuration
159                 String appConfigDir = "src/test/resources/config/catalog-be";
160                 ConfigurationSource configurationSource = new FSConfigurationSource(ExternalConfiguration.getChangeListener(), appConfigDir);
161                 ConfigurationManager configurationManager = new ConfigurationManager(configurationSource);
162
163                 // Elements
164                 mockElementDao = new ElementOperationMock();
165
166                 // User data and management
167                 user = new User();
168                 user.setUserId("jh0003");
169                 user.setFirstName("Jimmi");
170                 user.setLastName("Hendrix");
171                 user.setRole(Role.ADMIN.name());
172
173                 Either<User, ActionStatus> eitherGetUser = Either.left(user);
174                 when(mockUserAdmin.getUser("jh0003", false)).thenReturn(eitherGetUser);
175
176                 // Servlet Context attributes
177                 when(servletContext.getAttribute(Constants.CONFIGURATION_MANAGER_ATTR)).thenReturn(configurationManager);
178                 when(servletContext.getAttribute(Constants.WEB_APPLICATION_CONTEXT_WRAPPER_ATTR)).thenReturn(webAppContextWrapper);
179                 when(webAppContextWrapper.getWebAppContext(servletContext)).thenReturn(webAppContext);
180                 when(webAppContext.getBean(IElementOperation.class)).thenReturn(mockElementDao);
181
182                 Either<Integer, StorageOperationStatus> eitherCountRoot = Either.left(1);
183                 Either<Boolean, StorageOperationStatus> eitherFalse = Either.left(true);
184                 when(toscaOperationFacade.validateComponentNameExists("Root", ResourceTypeEnum.VFC, ComponentTypeEnum.RESOURCE)).thenReturn(eitherFalse);
185
186                 Either<Boolean, StorageOperationStatus> eitherCountExist = Either.left(true);
187                 when(toscaOperationFacade.validateComponentNameExists("alreadyExists", ResourceTypeEnum.VFC, ComponentTypeEnum.RESOURCE)).thenReturn(eitherCountExist);
188                 
189                 Either<Boolean, StorageOperationStatus> eitherCount = Either.left(false);
190                 when(toscaOperationFacade.validateComponentNameExists(RESOURCE_NAME, ResourceTypeEnum.VFC, ComponentTypeEnum.RESOURCE)).thenReturn(eitherCount);
191                 when(toscaOperationFacade.validateComponentNameExists(RESOURCE_NAME, ResourceTypeEnum.VF, ComponentTypeEnum.RESOURCE)).thenReturn(eitherCount);
192                 when(toscaOperationFacade.validateComponentNameExists(RESOURCE_NAME, ResourceTypeEnum.PNF, ComponentTypeEnum.RESOURCE)).thenReturn(eitherCount);
193                 
194                 Either<Boolean, StorageOperationStatus> validateDerivedExists = Either.left(true);
195                 when(toscaOperationFacade.validateToscaResourceNameExists("Root")).thenReturn(validateDerivedExists);
196                 
197                 Either<Boolean, StorageOperationStatus> validateDerivedNotExists = Either.left(false);
198                 when(toscaOperationFacade.validateToscaResourceNameExists("kuku")).thenReturn(validateDerivedNotExists);
199                 when(graphLockOperation.lockComponent(Mockito.anyString(), Mockito.eq(NodeTypeEnum.Resource))).thenReturn(StorageOperationStatus.OK);
200                 when(graphLockOperation.lockComponentByName(Mockito.anyString(), Mockito.eq(NodeTypeEnum.Resource))).thenReturn(StorageOperationStatus.OK);
201                 
202                 // createResource
203                 resourceResponse = createResourceObject(true);
204                 Either<Resource, StorageOperationStatus> eitherCreate = Either.left(resourceResponse);
205                 Either<Integer, StorageOperationStatus> eitherValidate = Either.left(null);
206                 when(toscaOperationFacade.createToscaComponent(Mockito.any(Resource.class))).thenReturn(eitherCreate);
207                 when(toscaOperationFacade.validateCsarUuidUniqueness(Mockito.anyString())).thenReturn(eitherValidate);
208                 Map<String, DataTypeDefinition> emptyDataTypes = new HashMap<String, DataTypeDefinition>();
209                 when(applicationDataTypeCache.getAll()).thenReturn(Either.left(emptyDataTypes));
210
211                 // BL object
212                 artifactManager.nodeTemplateOperation = nodeTemplateOperation;
213                 bl = new ResourceBusinessLogic();
214                 bl.setElementDao(mockElementDao);
215                 bl.setUserAdmin(mockUserAdmin);
216                 bl.setCapabilityTypeOperation(capabilityTypeOperation);
217                 componentsUtils.Init();
218                 componentsUtils.setAuditingManager(auditingManager);
219                 bl.setComponentsUtils(componentsUtils);
220                 bl.setLifecycleManager(lifecycleBl);
221                 bl.setGraphLockOperation(graphLockOperation);
222                 bl.setArtifactsManager(artifactManager);
223                 bl.setPropertyOperation(propertyOperation);
224                 bl.setTitanGenericDao(mockTitanDao);
225                 bl.setApplicationDataTypeCache(applicationDataTypeCache);
226                 bl.setCsarOperation(csarOperation);
227                 bl.setCacheManagerOperation(cacheManager);
228                 toscaOperationFacade.setNodeTypeOperation(nodeTypeOperation);
229                 toscaOperationFacade.setTopologyTemplateOperation(topologyTemplateOperation);
230                 bl.setToscaOperationFacade(toscaOperationFacade);
231                 Resource resourceCsar = createResourceObjectCsar(true);
232                 setCanWorkOnResource(resourceCsar);
233                 Either<Component, StorageOperationStatus> oldResourceRes = Either.left(resourceCsar);
234                 when(toscaOperationFacade.getToscaElement(resourceCsar.getUniqueId())).thenReturn(oldResourceRes);
235                 responseManager = ResponseFormatManager.getInstance();
236
237         }
238
239         private Resource createResourceObject(boolean afterCreate) {
240                 Resource resource = new Resource();
241                 resource.setName(RESOURCE_NAME);
242                 resource.addCategory(RESOURCE_CATEGORY1, RESOURCE_SUBCATEGORY);
243                 resource.setDescription("My short description");
244                 List<String> tgs = new ArrayList<String>();
245                 tgs.add("test");
246                 tgs.add(resource.getName());
247                 resource.setTags(tgs);
248                 List<String> template = new ArrayList<String>();
249                 template.add("Root");
250                 resource.setDerivedFrom(template);
251                 resource.setVendorName("Motorola");
252                 resource.setVendorRelease("1.0.0");
253                 resource.setContactId("ya5467");
254                 resource.setIcon("MyIcon");
255
256                 if (afterCreate) {
257                         resource.setName(resource.getName());
258                         resource.setVersion("0.1");
259                         resource.setUniqueId(resource.getName().toLowerCase() + ":" + resource.getVersion());
260                         resource.setCreatorUserId(user.getUserId());
261                         resource.setCreatorFullName(user.getFirstName() + " " + user.getLastName());
262                         resource.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
263                 }
264                 return resource;
265         }
266
267         private Resource createResourceObjectCsar(boolean afterCreate) {
268                 Resource resource = new Resource();
269                 resource.setName(RESOURCE_NAME);
270                 resource.addCategory(RESOURCE_CATEGORY1, RESOURCE_SUBCATEGORY);
271                 resource.setDescription("My short description");
272                 List<String> tgs = new ArrayList<String>();
273                 tgs.add("test");
274                 tgs.add(resource.getName());
275                 resource.setTags(tgs);
276                 List<String> template = new ArrayList<String>();
277                 template.add("Root");
278                 resource.setDerivedFrom(template);
279                 resource.setVendorName("Motorola");
280                 resource.setVendorRelease("1.0.0");
281                 resource.setResourceVendorModelNumber("");
282                 resource.setContactId("ya5467");
283                 resource.setIcon("MyIcon");
284                 resource.setCsarUUID("valid_vf.csar");
285                 resource.setCsarVersion("1");
286
287                 if (afterCreate) {
288                         resource.setName(resource.getName());
289                         resource.setVersion("0.1");
290                         
291                         resource.setUniqueId(resource.getName().toLowerCase() + ":" + resource.getVersion());
292                         resource.setCreatorUserId(user.getUserId());
293                         resource.setCreatorFullName(user.getFirstName() + " " + user.getLastName());
294                         resource.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
295                 }
296                 return resource;
297         }
298
299         private Resource setCanWorkOnResource(Resource resource) {
300                 resource.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
301                 resource.setLastUpdaterUserId(user.getUserId());
302                 return resource;
303         }
304
305         @Test
306         public void testHappyScenario() {
307                 Resource resource = createResourceObject(false);
308                 Either<Resource, ResponseFormat> createResponse = bl.createResource(resource, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
309
310                 if (createResponse.isRight()) {
311                         assertEquals(new Integer(200), createResponse.right().value().getStatus());
312                 }
313                 assertEquals(createResourceObject(true), createResponse.left().value());
314         }
315
316         @Test
317         public void testUpdateHappyScenario() {
318                 Resource resource = createResourceObjectCsar(true);
319                 setCanWorkOnResource(resource);
320                 
321                 Either<Resource, StorageOperationStatus> resourceLinkedToCsarRes = Either.left(resource);
322                 when(toscaOperationFacade.getLatestComponentByCsarOrName(ComponentTypeEnum.RESOURCE, resource.getCsarUUID(), resource.getSystemName())).thenReturn(resourceLinkedToCsarRes);
323                 Either<Boolean, StorageOperationStatus> validateDerivedExists = Either.left(true);
324                 when(toscaOperationFacade.validateToscaResourceNameExists("Root")).thenReturn(validateDerivedExists);
325                 
326                 Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
327                 when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
328                 Either<Resource, ResponseFormat> updateResponse = bl.validateAndUpdateResourceFromCsar(resource, user, null, null, resource.getUniqueId());
329                 if (updateResponse.isRight()) {
330                         assertEquals(new Integer(200), updateResponse.right().value().getStatus());
331                 }
332                 assertEquals(resource.getUniqueId(), updateResponse.left().value().getUniqueId());
333         }
334
335         /* CREATE validations - start ***********************/
336         // Resource name - start
337
338         @Test
339         public void testFailedResourceValidations() {
340                 testResourceNameExist();
341                 testResourceNameEmpty();
342                 // testResourceNameExceedsLimit();
343                 testResourceNameWrongFormat();
344                 testResourceDescExceedsLimitCreate();
345                 testResourceDescNotEnglish();
346                 testResourceDescriptionEmpty();
347                 testResourceDescriptionMissing();
348                 testResourceIconMissing();
349                 testResourceIconInvalid();
350                 testResourceIconExceedsLimit();
351                 testResourceTagNotExist();
352                 testResourceTagEmpty();
353                 testTagsExceedsLimitCreate();
354                 testTagsNoServiceName();
355                 testInvalidTag();
356                 
357                 testContactIdTooLong();
358                 testContactIdWrongFormatCreate();
359                 testResourceContactIdEmpty();
360                 testResourceContactIdMissing();
361                 testVendorNameExceedsLimit();
362                 testVendorNameWrongFormatCreate();
363                 testVendorReleaseWrongFormat();
364                 testVendorReleaseExceedsLimitCreate();
365                 testResourceVendorModelNumberExceedsLimit();
366                 testResourceVendorNameMissing();
367                 testResourceVendorReleaseMissing();
368                 testResourceCategoryExist();
369                 testResourceBadCategoryCreate();
370                 testHappyScenarioCostLicenseType();
371                 testCostWrongFormatCreate();
372                 testLicenseTypeWrongFormatCreate();
373                 testResourceTemplateNotExist();
374                 testResourceTemplateEmpty();
375                 testResourceTemplateInvalid();
376         }
377
378         private void testResourceNameExist() {
379                 String resourceName = "alreadyExists";
380                 Resource resourceExist = createResourceObject(false);
381                 resourceExist.setName(resourceName);
382                 resourceExist.getTags().add(resourceName);
383
384                 Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
385                 assertResponse(createResponse, ActionStatus.COMPONENT_NAME_ALREADY_EXIST, ComponentTypeEnum.RESOURCE.getValue(), resourceName);
386         }
387
388         private void testResourceNameEmpty() {
389                 Resource resourceExist = createResourceObject(false);
390                 resourceExist.setName(null);
391
392                 Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
393                 assertResponse(createResponse, ActionStatus.MISSING_COMPONENT_NAME, ComponentTypeEnum.RESOURCE.getValue());
394         }
395
396         private void testResourceNameExceedsLimit() {
397                 Resource resourceExccedsNameLimit = createResourceObject(false);
398                 // 51 chars, the limit is 50
399                 String tooLongResourceName = "zCRCAWjqte0DtgcAAMmcJcXeNubeX1p1vOZNTShAHOYNAHvV3iK";
400                 resourceExccedsNameLimit.setName(tooLongResourceName);
401
402                 Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceExccedsNameLimit, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
403                 assertTrue(createResponse.isRight());
404                 assertResponse(createResponse, ActionStatus.COMPONENT_NAME_EXCEEDS_LIMIT, ComponentTypeEnum.RESOURCE.getValue(), "" + ValidationUtils.COMPONENT_NAME_MAX_LENGTH);
405         }
406
407         private void testResourceNameWrongFormat() {
408                 Resource resource = createResourceObject(false);
409                 // contains :
410                 String nameWrongFormat = "ljg?fd";
411                 resource.setName(nameWrongFormat);
412
413                 Either<Resource, ResponseFormat> createResponse = bl.createResource(resource, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
414                 assertTrue(createResponse.isRight());
415                 assertResponse(createResponse, ActionStatus.INVALID_COMPONENT_NAME, ComponentTypeEnum.RESOURCE.getValue());
416         }
417
418         // Resource name - end
419         // Resource description - start
420         private void testResourceDescExceedsLimitCreate() {
421                 Resource resourceExccedsDescLimit = createResourceObject(false);
422                 // 1025 chars, the limit is 1024
423                 String tooLongResourceDesc = "1GUODojQ0sGzKR4NP7e5j82ADQ3KHTVOaezL95qcbuaqDtjZhAQGQ3iFwKAy580K4WiiXs3u3zq7RzXcSASl5fm0RsWtCMOIDP"
424                                 + "AOf9Tf2xtXxPCuCIMCR5wOGnNTaFxgnJEHAGxilBhZDgeMNHmCN1rMK5B5IRJOnZxcpcL1NeG3APTCIMP1lNAxngYulDm9heFSBc8TfXAADq7703AvkJT0QPpGq2z2P"
425                                 + "tlikcAnIjmWgfC5Tm7UH462BAlTyHg4ExnPPL4AO8c92VrD7kZSgSqiy73cN3gLT8uigkKrUgXQFGVUFrXVyyQXYtVM6bLBeuCGQf4C2j8lkNg6M0J3PC0PzMRoinOxk"
426                                 + "Ae2teeCtVcIj4A1KQo3210j8q2v7qQU69Mabsa6DT9FgE4rcrbiFWrg0Zto4SXWD3o1eJA9o29lTg6kxtklH3TuZTmpi5KVp1NFhS1RpnqF83tzv4mZLKsx7Zh1fEgYvRFwx1"
427                                 + "ar3RolyDfNoZiGBGTMsZzz7RPFBf2hTnLmNqVGQnHKhhGj0Y5s8t2cbqbO2nmHiJb9uaUVrCGypgbAcJL3KPOBfAVW8PcpmNj4yVjI3L4x5zHjmGZbp9vKshEQODcrmcgsYAoKqe"
428                                 + "uu5u7jk8XVxEfQ0m5qL8UOErXPlJovSmKUmP5B5T0w299zIWDYCzSoNasHpHjOMDLAiDDeHbozUOn9t3Qou00e9POq4RMM0VnIx1H38nJoJZz2XH8CI5YMQe7oTagaxgQTF2aa0qaq2"
429                                 + "V6nJsfRGRklGjNhFFYP2cS4Xv2IJO9DSX6LTXOmENrGVJJvMOZcvnBaZPfoAHN0LU4i1SoepLzulIxnZBfkUWFJgZ5wQ0Bco2GC1HMqzW21rwy4XHRxXpXbmW8LVyoA1KbnmVmROycU4"
430                                 + "scTZ62IxIcIWCVeMjBIcTviXULbPUyqlfEPXWr8IMJtpAaELWgyquPClAREMDs2b9ztKmUeXlMccFES1XWbFTrhBHhmmDyVReEgCwfokrUFR13LTUK1k8I6OEHOs";
431
432                 resourceExccedsDescLimit.setDescription(tooLongResourceDesc);
433
434                 Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceExccedsDescLimit, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
435                 assertTrue(createResponse.isRight());
436                 assertResponse(createResponse, ActionStatus.COMPONENT_DESCRIPTION_EXCEEDS_LIMIT, ComponentTypeEnum.RESOURCE.getValue(), "" + ValidationUtils.COMPONENT_DESCRIPTION_MAX_LENGTH);
437         }
438
439         private void testResourceDescNotEnglish() {
440                 Resource notEnglish = createResourceObject(false);
441                 // Not english
442                 String notEnglishDesc = "\uC2B5";
443                 notEnglish.setDescription(notEnglishDesc);
444
445                 Either<Resource, ResponseFormat> createResponse = bl.createResource(notEnglish, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
446                 assertTrue(createResponse.isRight());
447                 assertResponse(createResponse, ActionStatus.COMPONENT_INVALID_DESCRIPTION, ComponentTypeEnum.RESOURCE.getValue());
448         }
449
450         private void testResourceDescriptionEmpty() {
451                 Resource resourceExist = createResourceObject(false);
452                 resourceExist.setDescription("");
453
454                 Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
455                 assertTrue(createResponse.isRight());
456
457                 assertResponse(createResponse, ActionStatus.COMPONENT_MISSING_DESCRIPTION, ComponentTypeEnum.RESOURCE.getValue());
458         }
459
460         private void testResourceDescriptionMissing() {
461                 Resource resourceExist = createResourceObject(false);
462                 resourceExist.setDescription(null);
463
464                 Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
465                 assertTrue(createResponse.isRight());
466
467                 assertResponse(createResponse, ActionStatus.COMPONENT_MISSING_DESCRIPTION, ComponentTypeEnum.RESOURCE.getValue());
468         }
469         // Resource description - end
470         // Resource icon start
471
472         private void testResourceIconMissing() {
473                 Resource resourceExist = createResourceObject(false);
474                 resourceExist.setIcon(null);
475
476                 Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
477                 assertTrue(createResponse.isRight());
478
479                 assertResponse(createResponse, ActionStatus.COMPONENT_MISSING_ICON, ComponentTypeEnum.RESOURCE.getValue());
480         }
481
482         private void testResourceIconInvalid() {
483                 Resource resourceExist = createResourceObject(false);
484                 resourceExist.setIcon("kjk3453^&");
485
486                 Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
487                 assertTrue(createResponse.isRight());
488
489                 assertResponse(createResponse, ActionStatus.COMPONENT_INVALID_ICON, ComponentTypeEnum.RESOURCE.getValue());
490         }
491
492         private void testResourceIconExceedsLimit() {
493                 Resource resourceExist = createResourceObject(false);
494                 resourceExist.setIcon("dsjfhskdfhskjdhfskjdhkjdhfkshdfksjsdkfhsdfsdfsdfsfsdfsf");
495
496                 Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
497                 assertTrue(createResponse.isRight());
498
499                 assertResponse(createResponse, ActionStatus.COMPONENT_ICON_EXCEEDS_LIMIT, ComponentTypeEnum.RESOURCE.getValue(), "" + ValidationUtils.ICON_MAX_LENGTH);
500         }
501
502         // Resource icon end
503         // Resource tags - start
504         private void testResourceTagNotExist() {
505                 Resource resourceExist = createResourceObject(false);
506                 resourceExist.setTags(null);
507
508                 Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
509                 assertTrue(createResponse.isRight());
510
511                 assertResponse(createResponse, ActionStatus.COMPONENT_MISSING_TAGS);
512         }
513
514         private void testResourceTagEmpty() {
515                 Resource resourceExist = createResourceObject(false);
516                 resourceExist.setTags(new ArrayList<String>());
517
518                 Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
519                 assertTrue(createResponse.isRight());
520
521                 assertResponse(createResponse, ActionStatus.COMPONENT_MISSING_TAGS);
522         }
523
524         private void testTagsExceedsLimitCreate() {
525                 Resource resourceExccedsNameLimit = createResourceObject(false);
526                 String tag1 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjQ";
527                 String tag2 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjW";
528                 String tag3 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjE";
529                 String tag4 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjb";
530                 String tag5 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjr";
531                 String tag6 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjf";
532                 String tag7 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjg";
533                 String tag8 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjd";
534                 String tag9 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjf";
535                 String tag10 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjg";
536                 String tag11 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjh";
537                 String tag12 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjj";
538                 String tag13 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjk";
539                 String tag14 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjs";
540                 String tag15 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjz";
541                 String tag16 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjx";
542                 String tag17 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBj2";
543                 String tag18 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBj3";
544                 String tag19 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBj4";
545                 String tag20 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBj5";
546                 String tag21 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBj0";
547
548                 List<String> tagsList = new ArrayList<String>();
549                 tagsList.add(tag1);
550                 tagsList.add(tag2);
551                 tagsList.add(tag3);
552                 tagsList.add(tag4);
553                 tagsList.add(tag5);
554                 tagsList.add(tag6);
555                 tagsList.add(tag7);
556                 tagsList.add(tag8);
557                 tagsList.add(tag9);
558                 tagsList.add(tag10);
559                 tagsList.add(tag11);
560                 tagsList.add(tag12);
561                 tagsList.add(tag13);
562                 tagsList.add(tag14);
563                 tagsList.add(tag15);
564                 tagsList.add(tag16);
565                 tagsList.add(tag17);
566                 tagsList.add(tag18);
567                 tagsList.add(tag19);
568                 tagsList.add(tag20);
569                 tagsList.add(tag21);
570                 tagsList.add(resourceExccedsNameLimit.getName());
571
572                 resourceExccedsNameLimit.setTags(tagsList);
573
574                 Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceExccedsNameLimit, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
575                 assertTrue(createResponse.isRight());
576                 assertResponse(createResponse, ActionStatus.COMPONENT_TAGS_EXCEED_LIMIT, "" + ValidationUtils.TAG_LIST_MAX_LENGTH);
577
578         }
579
580         private void testTagsSingleExceedsLimit() {
581                 Resource resourceExccedsNameLimit = createResourceObject(false);
582                 String tag1 = "afzs2qLBb5X6tZhiunkcEwiFX1qRQY8YZl3y3Du5M5xeQY5Nq9afcFHDZ9HaURw43gH27nAUWM36bMbMylwTFSzzNV8NO4v4ripe6Q15Vc2nPOFI";
583                 String tag2 = resourceExccedsNameLimit.getName();
584                 List<String> tagsList = new ArrayList<String>();
585                 tagsList.add(tag1);
586                 tagsList.add(tag2);
587
588                 resourceExccedsNameLimit.setTags(tagsList);
589
590                 Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceExccedsNameLimit, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
591                 assertTrue(createResponse.isRight());
592                 assertResponse(createResponse, ActionStatus.COMPONENT_SINGLE_TAG_EXCEED_LIMIT, "" + ValidationUtils.TAG_MAX_LENGTH);
593
594         }
595
596         private void testTagsNoServiceName() {
597                 Resource serviceExccedsNameLimit = createResourceObject(false);
598                 String tag1 = "afzs2qLBb";
599                 List<String> tagsList = new ArrayList<String>();
600                 tagsList.add(tag1);
601                 serviceExccedsNameLimit.setTags(tagsList);
602
603                 Either<Resource, ResponseFormat> createResponse = bl.createResource(serviceExccedsNameLimit, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
604                 assertTrue(createResponse.isRight());
605                 assertResponse(createResponse, ActionStatus.COMPONENT_INVALID_TAGS_NO_COMP_NAME);
606
607         }
608
609         private void testInvalidTag() {
610                 Resource serviceExccedsNameLimit = createResourceObject(false);
611                 String tag1 = "afzs2qLBb%#%";
612                 List<String> tagsList = new ArrayList<String>();
613                 tagsList.add(tag1);
614                 serviceExccedsNameLimit.setTags(tagsList);
615
616                 Either<Resource, ResponseFormat> createResponse = bl.createResource(serviceExccedsNameLimit, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
617                 assertTrue(createResponse.isRight());
618                 assertResponse(createResponse, ActionStatus.INVALID_FIELD_FORMAT, new String[] { "Resource", "tag" });
619
620         }
621
622         // Resource tags - stop
623         // Resource contact start
624         
625         private void testContactIdTooLong() {
626                 Resource resourceContactId = createResourceObject(false);
627                 // 59 chars instead of 50
628                 String contactIdTooLong = "thisNameIsVeryLongAndExeccedsTheNormalLengthForContactId";
629                 resourceContactId.setContactId(contactIdTooLong);
630
631                 Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceContactId, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
632                 assertTrue(createResponse.isRight());
633                 assertResponse(createResponse, ActionStatus.COMPONENT_INVALID_CONTACT, ComponentTypeEnum.RESOURCE.getValue());
634         }
635
636         private void testContactIdWrongFormatCreate() {
637                 Resource resourceContactId = createResourceObject(false);
638                 // 3 letters and 3 digits and special characters
639                 String contactIdFormatWrong = "yrt134!!!";
640                 resourceContactId.setContactId(contactIdFormatWrong);
641
642                 Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceContactId, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
643                 assertTrue(createResponse.isRight());
644                 assertResponse(createResponse, ActionStatus.COMPONENT_INVALID_CONTACT, ComponentTypeEnum.RESOURCE.getValue());
645         }
646
647         private void testResourceContactIdEmpty() {
648                 Resource resourceExist = createResourceObject(false);
649                 resourceExist.setContactId("");
650
651                 Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
652                 assertTrue(createResponse.isRight());
653
654                 assertResponse(createResponse, ActionStatus.COMPONENT_MISSING_CONTACT, ComponentTypeEnum.RESOURCE.getValue());
655         }
656
657         private void testResourceContactIdMissing() {
658                 Resource resourceExist = createResourceObject(false);
659                 resourceExist.setContactId(null);
660
661                 Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
662                 assertTrue(createResponse.isRight());
663
664                 assertResponse(createResponse, ActionStatus.COMPONENT_MISSING_CONTACT, ComponentTypeEnum.RESOURCE.getValue());
665         }
666
667         private void testVendorNameExceedsLimit() {
668                 Resource resourceExccedsVendorNameLimit = createResourceObject(false);
669                 String tooLongVendorName = "h1KSyJh9Eh1KSyJh9Eh1KSyJh9Eh1KSyJh9Eh1KSyJh9Eh1KSyJh9Eh1KSyJh9Eh1KSyJh9E";
670                 resourceExccedsVendorNameLimit.setVendorName(tooLongVendorName);
671
672                 Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceExccedsVendorNameLimit, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
673                 assertTrue(createResponse.isRight());
674                 assertResponse(createResponse, ActionStatus.VENDOR_NAME_EXCEEDS_LIMIT, "" + ValidationUtils.VENDOR_NAME_MAX_LENGTH);
675         }
676         
677         private void testResourceVendorModelNumberExceedsLimit() {
678                 Resource resourceExccedsVendorModelNumberLimit = createResourceObject(false);
679                 String tooLongVendorModelNumber = "h1KSyJh9Eh1KSyJh9Eh1KSyJh9Eh1KSyJh9Eh1KSyJh9Eh1KSyJh9Eh1KSyJh9Eh1KSyJh9E";
680                 resourceExccedsVendorModelNumberLimit.setResourceVendorModelNumber(tooLongVendorModelNumber);
681
682                 Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceExccedsVendorModelNumberLimit, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
683                 assertTrue(createResponse.isRight());
684                 assertResponse(createResponse, ActionStatus.RESOURCE_VENDOR_MODEL_NUMBER_EXCEEDS_LIMIT, "" + ValidationUtils.RESOURCE_VENDOR_MODEL_NUMBER_MAX_LENGTH);
685         }
686
687         private void testVendorNameWrongFormatCreate() {
688                 Resource resource = createResourceObject(false);
689                 // contains *
690                 String nameWrongFormat = "ljg*fd";
691                 resource.setVendorName(nameWrongFormat);
692
693                 Either<Resource, ResponseFormat> createResponse = bl.createResource(resource, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
694                 assertTrue(createResponse.isRight());
695                 assertResponse(createResponse, ActionStatus.INVALID_VENDOR_NAME);
696         }
697
698         private void testVendorReleaseWrongFormat() {
699                 Resource resource = createResourceObject(false);
700                 // contains >
701                 String nameWrongFormat = "1>2";
702                 resource.setVendorRelease(nameWrongFormat);
703
704                 Either<Resource, ResponseFormat> createResponse = bl.createResource(resource, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
705                 assertTrue(createResponse.isRight());
706                 assertResponse(createResponse, ActionStatus.INVALID_VENDOR_RELEASE);
707
708         }
709
710         private void testVendorReleaseExceedsLimitCreate() {
711                 Resource resourceExccedsNameLimit = createResourceObject(false);
712                 String tooLongVendorRelease = "h1KSyJh9Eh1KSyJh9Eh1KSyJh9Eh1KSyJh9E";
713                 resourceExccedsNameLimit.setVendorRelease(tooLongVendorRelease);
714
715                 Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceExccedsNameLimit, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
716                 assertTrue(createResponse.isRight());
717                 assertResponse(createResponse, ActionStatus.VENDOR_RELEASE_EXCEEDS_LIMIT, "" + ValidationUtils.VENDOR_RELEASE_MAX_LENGTH);
718         }
719
720         private void testResourceVendorNameMissing() {
721                 Resource resourceExist = createResourceObject(false);
722                 resourceExist.setVendorName(null);
723
724                 Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
725                 assertTrue(createResponse.isRight());
726
727                 assertResponse(createResponse, ActionStatus.MISSING_VENDOR_NAME);
728         }
729
730         private void testResourceVendorReleaseMissing() {
731                 Resource resourceExist = createResourceObject(false);
732                 resourceExist.setVendorRelease(null);
733
734                 Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
735                 assertTrue(createResponse.isRight());
736
737                 assertResponse(createResponse, ActionStatus.MISSING_VENDOR_RELEASE);
738         }
739
740         // Resource vendor name/release stop
741         // Category start
742         private void testResourceCategoryExist() {
743                 Resource resourceExist = createResourceObject(false);
744                 resourceExist.setCategories(null);
745
746                 Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
747                 assertTrue(createResponse.isRight());
748
749                 assertResponse(createResponse, ActionStatus.COMPONENT_MISSING_CATEGORY, ComponentTypeEnum.RESOURCE.getValue());
750         }
751
752         private void testResourceBadCategoryCreate() {
753
754                 Resource resourceExist = createResourceObject(false);
755                 resourceExist.setCategories(null);
756                 resourceExist.addCategory("koko", "koko");
757
758                 Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
759                 assertTrue(createResponse.isRight());
760
761                 assertResponse(createResponse, ActionStatus.COMPONENT_INVALID_CATEGORY, ComponentTypeEnum.RESOURCE.getValue());
762         }
763
764         // Category stop
765         // Cost start
766         private void testHappyScenarioCostLicenseType() {
767                 Resource createResourceObject = createResourceObject(false);
768                 Resource createResourceObjectAfterCreate = createResourceObject(true);
769                 // Adding cost and licenseType to basic mock
770                 Either<Resource, StorageOperationStatus> eitherCreate = Either.left(createResourceObjectAfterCreate);
771                 when(toscaOperationFacade.createToscaComponent(Mockito.any(Resource.class))).thenReturn(eitherCreate);
772
773                 String cost = "123.456";
774                 String licenseType = "User";
775                 createResourceObject.setCost(cost);
776                 createResourceObject.setLicenseType(licenseType);
777                 Either<Resource, ResponseFormat> createResponse = bl.createResource(createResourceObject, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
778
779                 if (createResponse.isRight()) {
780                         assertEquals(new Integer(200), createResponse.right().value().getStatus());
781                 }
782                 createResourceObjectAfterCreate.setCost(cost);
783                 createResourceObjectAfterCreate.setLicenseType(licenseType);
784                 assertEquals(createResourceObjectAfterCreate, createResponse.left().value());
785         }
786
787         private void testCostWrongFormatCreate() {
788                 Resource resourceCost = createResourceObject(false);
789                 // Comma instead of fullstop
790                 String cost = "12356,464";
791                 resourceCost.setCost(cost);
792
793                 Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceCost, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
794                 assertTrue(createResponse.isRight());
795                 assertResponse(createResponse, ActionStatus.INVALID_CONTENT);
796         }
797
798         // Cost stop
799         // License type start
800         private void testLicenseTypeWrongFormatCreate() {
801                 Resource resourceLicenseType = createResourceObject(false);
802                 // lowcase
803                 String licenseType = "cpu";
804                 resourceLicenseType.setLicenseType(licenseType);
805
806                 Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceLicenseType, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
807                 assertTrue(createResponse.isRight());
808                 assertResponse(createResponse, ActionStatus.INVALID_CONTENT);
809         }
810
811         // License type stop
812         // Derived from start
813         private void testResourceTemplateNotExist() {
814                 Resource resourceExist = createResourceObject(false);
815                 List<String> list = null;
816                 resourceExist.setDerivedFrom(list);
817
818                 Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
819                 assertTrue(createResponse.isRight());
820
821                 assertResponse(createResponse, ActionStatus.MISSING_DERIVED_FROM_TEMPLATE);
822         }
823
824         private void testResourceTemplateEmpty() {
825                 Resource resourceExist = createResourceObject(false);
826                 resourceExist.setDerivedFrom(new ArrayList<String>());
827
828                 Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
829                 assertTrue(createResponse.isRight());
830
831                 assertResponse(createResponse, ActionStatus.MISSING_DERIVED_FROM_TEMPLATE);
832         }
833
834         private void testResourceTemplateInvalid() {
835                 Resource resourceExist = createResourceObject(false);
836                 ArrayList<String> derivedFrom = new ArrayList<String>();
837                 derivedFrom.add("kuku");
838                 resourceExist.setDerivedFrom(derivedFrom);
839
840                 Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
841                 assertTrue(createResponse.isRight());
842
843                 assertResponse(createResponse, ActionStatus.PARENT_RESOURCE_NOT_FOUND);
844         }
845         // Derived from stop
846
847         private void assertResponse(Either<Resource, ResponseFormat> createResponse, ActionStatus expectedStatus, String... variables) {
848                 ResponseFormat expectedResponse = responseManager.getResponseFormat(expectedStatus, variables);
849                 ResponseFormat actualResponse = createResponse.right().value();
850                 assertEquals(expectedResponse.getStatus(), actualResponse.getStatus());
851                 assertEquals("assert error description", expectedResponse.getFormattedMessage(), actualResponse.getFormattedMessage());
852         }
853
854         // UPDATE tests - start
855         // Resource name
856         @Test
857         public void testResourceNameWrongFormat_UPDATE() {
858                 Resource resource = createResourceObject(true);
859                 Resource updatedResource = createResourceObject(true);
860
861                 // this is in order to prevent failing with 403 earlier
862                 Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
863                 when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
864                 // contains *
865                 String nameWrongFormat = "ljg*fd";
866                 updatedResource.setName(nameWrongFormat);
867
868                 Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
869                 when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
870                 
871                 Either<Resource, ResponseFormat> createResponse = bl.updateResourceMetadata(resource.getUniqueId(), updatedResource, null, user, false);
872                 assertTrue(createResponse.isRight());
873                 assertResponse(createResponse, ActionStatus.INVALID_COMPONENT_NAME, ComponentTypeEnum.RESOURCE.getValue());
874
875         }
876
877         @Test
878         public void testResourceNameAfterCertify_UPDATE() {
879                 Resource resource = createResourceObject(true);
880                 Resource updatedResource = createResourceObject(true);
881
882                 // this is in order to prevent failing with 403 earlier
883                 Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
884                 // when(resourceOperation.getResource_tx(resource.getUniqueId(),false)).thenReturn(eitherUpdate);
885                 when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
886
887                 String name = "ljg";
888                 updatedResource.setName(name);
889                 resource.setVersion("1.0");
890         
891                 Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
892                 when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
893
894                 Either<Resource, ResponseFormat> createResponse = bl.updateResourceMetadata(resource.getUniqueId(), updatedResource, null, user, false);
895                 assertTrue(createResponse.isRight());
896                 assertResponse(createResponse, ActionStatus.RESOURCE_NAME_CANNOT_BE_CHANGED);
897
898         }
899
900         @Ignore
901         public void testResourceNameExceedsLimit_UPDATE() {
902                 Resource resource = createResourceObject(true);
903                 Resource updatedResource = createResourceObject(true);
904
905                 // this is in order to prevent failing with 403 earlier
906                 Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
907                 when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
908
909                 // 51 chars, the limit is 50
910                 String tooLongResourceName = "zCRCAWjqte0DtgcAAMmcJcXeNubeX1p1vOZNTShAHOYNAHvV3iK";
911                 updatedResource.setName(tooLongResourceName);
912                 Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
913                 when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
914
915                 Either<Resource, ResponseFormat> createResponse = bl.updateResourceMetadata(resource.getUniqueId(), updatedResource, null, user, false);
916                 assertTrue(createResponse.isRight());
917                 assertResponse(createResponse, ActionStatus.COMPONENT_NAME_EXCEEDS_LIMIT, ComponentTypeEnum.RESOURCE.getValue(), "" + ValidationUtils.COMPONENT_NAME_MAX_LENGTH);
918         }
919
920         @Test
921         public void testResourceNameAlreadyExist_UPDATE() {
922                 Resource resource = createResourceObject(true);
923                 Resource updatedResource = createResourceObject(true);
924
925                 // this is in order to prevent failing with 403 earlier
926                 Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
927                 when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
928
929                 String resourceName = "alreadyExists";
930                 updatedResource.setName(resourceName);
931                 Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(updatedResource);
932                 when(toscaOperationFacade.updateToscaElement(updatedResource)).thenReturn(dataModelResponse);
933                 Either<Resource, ResponseFormat> createResponse = bl.updateResourceMetadata(resource.getUniqueId(), updatedResource, null, user, false);
934                 assertTrue(createResponse.isRight());
935                 assertResponse(createResponse, ActionStatus.COMPONENT_NAME_ALREADY_EXIST, ComponentTypeEnum.RESOURCE.getValue(), resourceName);
936         }
937
938         //
939
940         @Test
941         public void testResourceDescExceedsLimit_UPDATE() {
942                 Resource resource = createResourceObject(true);
943                 Resource updatedResource = createResourceObject(true);
944
945                 // this is in order to prevent failing with 403 earlier
946                 Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
947                 when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
948
949                 // 1025 chars, the limit is 1024
950                 String tooLongResourceDesc = "1GUODojQ0sGzKR4NP7e5j82ADQ3KHTVOaezL95qcbuaqDtjZhAQGQ3iFwKAy580K4WiiXs3u3zq7RzXcSASl5fm0RsWtCMOIDP"
951                                 + "AOf9Tf2xtXxPCuCIMCR5wOGnNTaFxgnJEHAGxilBhZDgeMNHmCN1rMK5B5IRJOnZxcpcL1NeG3APTCIMP1lNAxngYulDm9heFSBc8TfXAADq7703AvkJT0QPpGq2z2P"
952                                 + "tlikcAnIjmWgfC5Tm7UH462BAlTyHg4ExnPPL4AO8c92VrD7kZSgSqiy73cN3gLT8uigkKrUgXQFGVUFrXVyyQXYtVM6bLBeuCGQf4C2j8lkNg6M0J3PC0PzMRoinOxk"
953                                 + "Ae2teeCtVcIj4A1KQo3210j8q2v7qQU69Mabsa6DT9FgE4rcrbiFWrg0Zto4SXWD3o1eJA9o29lTg6kxtklH3TuZTmpi5KVp1NFhS1RpnqF83tzv4mZLKsx7Zh1fEgYvRFwx1"
954                                 + "ar3RolyDfNoZiGBGTMsZzz7RPFBf2hTnLmNqVGQnHKhhGj0Y5s8t2cbqbO2nmHiJb9uaUVrCGypgbAcJL3KPOBfAVW8PcpmNj4yVjI3L4x5zHjmGZbp9vKshEQODcrmcgsYAoKqe"
955                                 + "uu5u7jk8XVxEfQ0m5qL8UOErXPlJovSmKUmP5B5T0w299zIWDYCzSoNasHpHjOMDLAiDDeHbozUOn9t3Qou00e9POq4RMM0VnIx1H38nJoJZz2XH8CI5YMQe7oTagaxgQTF2aa0qaq2"
956                                 + "V6nJsfRGRklGjNhFFYP2cS4Xv2IJO9DSX6LTXOmENrGVJJvMOZcvnBaZPfoAHN0LU4i1SoepLzulIxnZBfkUWFJgZ5wQ0Bco2GC1HMqzW21rwy4XHRxXpXbmW8LVyoA1KbnmVmROycU4"
957                                 + "scTZ62IxIcIWCVeMjBIcTviXULbPUyqlfEPXWr8IMJtpAaELWgyquPClAREMDs2b9ztKmUeXlMccFES1XWbFTrhBHhmmDyVReEgCwfokrUFR13LTUK1k8I6OEHOs";
958                 updatedResource.setDescription(tooLongResourceDesc);
959                 Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
960                 when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
961                 Either<Resource, ResponseFormat> createResponse = bl.updateResourceMetadata(resource.getUniqueId(), updatedResource, null, user, false);
962                 assertTrue(createResponse.isRight());
963                 assertResponse(createResponse, ActionStatus.COMPONENT_DESCRIPTION_EXCEEDS_LIMIT, ComponentTypeEnum.RESOURCE.getValue(), "" + ValidationUtils.COMPONENT_DESCRIPTION_MAX_LENGTH);
964
965         }
966
967         @Test
968         public void testIconWrongFormat_UPDATE() {
969                 Resource resource = createResourceObject(true);
970                 Resource updatedResource = createResourceObject(true);
971
972                 // this is in order to prevent failing with 403 earlier
973                 Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
974                 when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
975
976                 // contains .
977                 String icon = "icon.jpg";
978                 updatedResource.setIcon(icon);
979                 Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
980                 when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
981
982                 Either<Resource, ResponseFormat> createResponse = bl.updateResourceMetadata(resource.getUniqueId(), updatedResource, null, user, false);
983                 assertTrue(createResponse.isRight());
984                 assertResponse(createResponse, ActionStatus.COMPONENT_INVALID_ICON, ComponentTypeEnum.RESOURCE.getValue());
985
986         }
987
988         @Test
989         public void testIconAfterCertify_UPDATE() {
990                 Resource resource = createResourceObject(true);
991                 Resource updatedResource = createResourceObject(true);
992
993                 // this is in order to prevent failing with 403 earlier
994                 Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
995                 when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
996
997                 // contains
998                 String icon = "icon";
999                 updatedResource.setIcon(icon);
1000
1001                 resource.setVersion("1.0");
1002                 ;
1003                 Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
1004                 when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
1005                 Either<Resource, ResponseFormat> createResponse = bl.updateResourceMetadata(resource.getUniqueId(), updatedResource, null, user, false);
1006                 assertTrue(createResponse.isRight());
1007                 assertResponse(createResponse, ActionStatus.RESOURCE_ICON_CANNOT_BE_CHANGED);
1008
1009         }
1010
1011         @Test
1012         public void testTagsExceedsLimit_UPDATE() {
1013                 Resource resource = createResourceObject(true);
1014                 Resource updatedResource = createResourceObject(true);
1015
1016                 // this is in order to prevent failing with 403 earlier
1017                 Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
1018                 when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
1019
1020                 String tag1 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjQ";
1021                 String tag2 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjW";
1022                 String tag3 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjE";
1023                 String tag4 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjb";
1024                 String tag5 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjr";
1025                 String tag6 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjf";
1026                 String tag7 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjg";
1027                 String tag8 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjd";
1028                 String tag9 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjf";
1029                 String tag10 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjg";
1030                 String tag11 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjh";
1031                 String tag12 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjj";
1032                 String tag13 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjk";
1033                 String tag14 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjs";
1034                 String tag15 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjz";
1035                 String tag16 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjx";
1036                 String tag17 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBj2";
1037                 String tag18 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBj3";
1038                 String tag19 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBj4";
1039                 String tag20 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBj5";
1040                 String tag21 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBj0";
1041
1042                 List<String> tagsList = new ArrayList<String>();
1043                 tagsList.add(tag1);
1044                 tagsList.add(tag2);
1045                 tagsList.add(tag3);
1046                 tagsList.add(tag4);
1047                 tagsList.add(tag5);
1048                 tagsList.add(tag6);
1049                 tagsList.add(tag7);
1050                 tagsList.add(tag8);
1051                 tagsList.add(tag9);
1052                 tagsList.add(tag10);
1053                 tagsList.add(tag11);
1054                 tagsList.add(tag12);
1055                 tagsList.add(tag13);
1056                 tagsList.add(tag14);
1057                 tagsList.add(tag15);
1058                 tagsList.add(tag16);
1059                 tagsList.add(tag17);
1060                 tagsList.add(tag18);
1061                 tagsList.add(tag19);
1062                 tagsList.add(tag20);
1063                 tagsList.add(tag21);
1064                 tagsList.add(resource.getName());
1065
1066                 updatedResource.setTags(tagsList);
1067                 Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
1068                 when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
1069                 Either<Resource, ResponseFormat> createResponse = bl.updateResourceMetadata(resource.getUniqueId(), updatedResource, null, user, false);
1070                 assertTrue(createResponse.isRight());
1071
1072                 assertResponse(createResponse, ActionStatus.COMPONENT_TAGS_EXCEED_LIMIT, "" + ValidationUtils.TAG_LIST_MAX_LENGTH);
1073         }
1074
1075         @Test
1076         public void testVendorNameWrongFormat_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 nameWrongFormat = "ljg*fd";
1086                 updatedResource.setVendorName(nameWrongFormat);
1087                 Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
1088                 when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
1089                 Either<Resource, ResponseFormat> createResponse = bl.updateResourceMetadata(resource.getUniqueId(), updatedResource, null, user, false);
1090                 assertTrue(createResponse.isRight());
1091                 assertResponse(createResponse, ActionStatus.INVALID_VENDOR_NAME);
1092
1093         }
1094
1095         @Test
1096         public void testVendorNameAfterCertify_UPDATE() {
1097                 Resource resource = createResourceObject(true);
1098                 Resource updatedResource = createResourceObject(true);
1099
1100                 // this is in order to prevent failing with 403 earlier
1101                 Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
1102                 when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
1103
1104                 // contains *
1105                 String nameWrongFormat = "ljg*fd";
1106                 updatedResource.setVendorName(nameWrongFormat);
1107                 resource.setVersion("1.0");
1108                 ;
1109                 Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
1110                 when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
1111                 Either<Resource, ResponseFormat> createResponse = bl.updateResourceMetadata(resource.getUniqueId(), updatedResource, null, user, false);
1112                 assertTrue(createResponse.isRight());
1113                 assertResponse(createResponse, ActionStatus.RESOURCE_VENDOR_NAME_CANNOT_BE_CHANGED);
1114
1115         }
1116
1117         @Test
1118         public void testVendorReleaseExceedsLimit_UPDATE() {
1119                 Resource resource = createResourceObject(true);
1120                 Resource updatedResource = createResourceObject(true);
1121
1122                 // this is in order to prevent failing with 403 earlier
1123                 Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
1124                 when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
1125                 // 129 chars, the limit is 128
1126                 String tooLongVendorRelease = "h1KSyJh9EspI8SPwAGu4VETfqWejeanuB1PCJBxJmJncYnrW0lnsEFFVRIukRJkwlOVnZCy8p38tjhANeZq3BGMHIawWR6ICl8Wi9mikRYALWgvJug00JrlQ0iPVKPLxy";
1127                 updatedResource.setVendorRelease(tooLongVendorRelease);
1128                 Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
1129                 when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
1130                 Either<Resource, ResponseFormat> createResponse = bl.updateResourceMetadata(resource.getUniqueId(), updatedResource, null, user, false);
1131                 assertTrue(createResponse.isRight());
1132                 assertResponse(createResponse, ActionStatus.VENDOR_RELEASE_EXCEEDS_LIMIT, "" + ValidationUtils.VENDOR_RELEASE_MAX_LENGTH);
1133         }
1134
1135         @Ignore
1136         public void testContactIdWrongFormat_UPDATE() {
1137                 Resource resource = createResourceObject(true);
1138                 Resource updatedResource = createResourceObject(true);
1139
1140                 // this is in order to prevent failing with 403 earlier
1141                 Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
1142                 when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
1143
1144                 String resourceId = resource.getUniqueId();
1145                 // 3 letters and 3 digits
1146                 String contactIdTooLong = "yrt134";
1147                 updatedResource.setContactId(contactIdTooLong);
1148                 Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
1149                 when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
1150                 Either<Resource, ResponseFormat> createResponse = bl.updateResourceMetadata(resourceId, updatedResource, null, user, false);
1151                 assertTrue(createResponse.isRight());
1152
1153                 assertResponse(createResponse, ActionStatus.COMPONENT_INVALID_CONTACT, ComponentTypeEnum.RESOURCE.getValue());
1154         }
1155
1156         @Test
1157         public void testResourceBadCategory_UPDATE() {
1158                 Resource resource = createResourceObject(true);
1159                 Resource updatedResource = createResourceObject(true);
1160
1161                 // this is in order to prevent failing with 403 earlier
1162                 Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
1163                 when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
1164
1165                 String resourceId = resource.getUniqueId();
1166                 String badCategory = "ddfds";
1167                 updatedResource.setCategories(null);
1168                 updatedResource.addCategory(badCategory, "fikt");
1169                 Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
1170                 when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
1171                 Either<Resource, ResponseFormat> createResponse = bl.updateResourceMetadata(resourceId, updatedResource, null, user, false);
1172                 assertTrue(createResponse.isRight());
1173
1174                 assertResponse(createResponse, ActionStatus.COMPONENT_INVALID_CATEGORY, ComponentTypeEnum.RESOURCE.getValue());
1175         }
1176
1177         @Test
1178         public void testResourceCategoryAfterCertify_UPDATE() {
1179                 Resource resource = createResourceObject(true);
1180                 Resource updatedResource = createResourceObject(true);
1181
1182                 // this is in order to prevent failing with 403 earlier
1183                 Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
1184                 when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
1185
1186                 String resourceId = resource.getUniqueId();
1187                 updatedResource.setCategories(null);
1188                 updatedResource.addCategory(RESOURCE_CATEGORY1, UPDATED_SUBCATEGORY);
1189                 resource.setVersion("1.0");
1190                 ;
1191                 Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
1192                 when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
1193                 Either<Resource, ResponseFormat> createResponse = bl.updateResourceMetadata(resourceId, updatedResource, null, user, false);
1194                 assertTrue(createResponse.isRight());
1195
1196                 assertResponse(createResponse, ActionStatus.RESOURCE_CATEGORY_CANNOT_BE_CHANGED);
1197         }
1198
1199         // Derived from start
1200         @Test
1201         public void testResourceTemplateNotExist_UPDATE() {
1202                 Resource resource = createResourceObject(true);
1203                 Resource updatedResource = createResourceObject(true);
1204
1205                 // this is in order to prevent failing with 403 earlier
1206                 Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
1207                 when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
1208                 String resourceId = resource.getUniqueId();
1209
1210                 List<String> list = null;
1211                 updatedResource.setDerivedFrom(list);
1212                 Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
1213                 when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
1214                 Either<Resource, ResponseFormat> createResponse = bl.updateResourceMetadata(resourceId, updatedResource, null, user, false);
1215                 assertTrue(createResponse.isRight());
1216
1217                 assertResponse(createResponse, ActionStatus.MISSING_DERIVED_FROM_TEMPLATE);
1218         }
1219
1220         @Test
1221         public void testResourceTemplateEmpty_UPDATE() {
1222                 Resource resource = createResourceObject(true);
1223                 Resource updatedResource = createResourceObject(true);
1224                 String resourceId = resource.getUniqueId();
1225
1226                 // this is in order to prevent failing with 403 earlier
1227                 Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
1228                 when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
1229
1230                 updatedResource.setDerivedFrom(new ArrayList<String>());
1231                 Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
1232                 when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
1233                 Either<Resource, ResponseFormat> createResponse = bl.updateResourceMetadata(resourceId, updatedResource, null, user, false);
1234                 assertTrue(createResponse.isRight());
1235
1236                 assertResponse(createResponse, ActionStatus.MISSING_DERIVED_FROM_TEMPLATE);
1237         }
1238
1239         @Test
1240         public void testResourceTemplateInvalid_UPDATE() {
1241                 Resource resource = createResourceObject(true);
1242                 Resource updatedResource = createResourceObject(true);
1243                 String resourceId = resource.getUniqueId();
1244
1245                 // this is in order to prevent failing with 403 earlier
1246                 Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
1247                 when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
1248
1249                 ArrayList<String> derivedFrom = new ArrayList<String>();
1250                 derivedFrom.add("kuku");
1251                 updatedResource.setDerivedFrom(derivedFrom);
1252                 Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
1253                 when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
1254                 Either<Resource, ResponseFormat> createResponse = bl.updateResourceMetadata(resourceId, updatedResource, null, user, false);
1255                 assertTrue(createResponse.isRight());
1256
1257                 assertResponse(createResponse, ActionStatus.PARENT_RESOURCE_NOT_FOUND);
1258         }
1259
1260         @Test
1261         public void testResourceTemplateCertify_UPDATE_HAPPY() {
1262                 Resource resource = createResourceObject(true);
1263                 Resource updatedResource = createResourceObject(true);
1264                 String resourceId = resource.getUniqueId();
1265
1266                 // this is in order to prevent failing with 403 earlier
1267                 Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
1268                 when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
1269                 
1270                 Either<Boolean, StorageOperationStatus> isToscaNameExtending = Either.left(true);
1271                 when(toscaOperationFacade.validateToscaResourceNameExtends(Mockito.anyString(), Mockito.anyString())).thenReturn(isToscaNameExtending);
1272                 
1273                 Either<Map<String, PropertyDefinition>, StorageOperationStatus> findPropertiesOfNode = Either.left(new HashMap<>());
1274                 when(propertyOperation.deleteAllPropertiesAssociatedToNode(Mockito.any(NodeTypeEnum.class), Mockito.anyString())).thenReturn(findPropertiesOfNode);
1275                 
1276                 resource.setVersion("1.0");
1277
1278                 ArrayList<String> derivedFrom = new ArrayList<String>();
1279                 derivedFrom.add("tosca.nodes.Root");
1280                 updatedResource.setDerivedFrom(derivedFrom);
1281                 Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(updatedResource);
1282                 when(toscaOperationFacade.updateToscaElement(updatedResource)).thenReturn(dataModelResponse);
1283                 Either<Resource, ResponseFormat> createResponse = bl.updateResourceMetadata(resourceId, updatedResource, null, user, false);
1284                 assertTrue(createResponse.isLeft());
1285         }
1286         
1287         @Test
1288         public void testResourceTemplateCertify_UPDATE_SAD() {
1289                 Resource resource = createResourceObject(true);
1290                 Resource updatedResource = createResourceObject(true);
1291                 String resourceId = resource.getUniqueId();
1292
1293                 // this is in order to prevent failing with 403 earlier
1294                 Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
1295                 when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
1296                 
1297                 Either<Boolean, StorageOperationStatus> isToscaNameExtending = Either.left(false);
1298                 when(toscaOperationFacade.validateToscaResourceNameExtends(Mockito.anyString(), Mockito.anyString()))
1299                                 .thenReturn(isToscaNameExtending);
1300
1301                 resource.setVersion("1.0");
1302
1303                 ArrayList<String> derivedFrom = new ArrayList<String>();
1304                 derivedFrom.add("tosca.nodes.Root");
1305                 updatedResource.setDerivedFrom(derivedFrom);
1306                 Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
1307                 when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
1308                 Either<Resource, ResponseFormat> createResponse = bl.updateResourceMetadata(resourceId, updatedResource, null, user,
1309                                 false);
1310                 assertTrue(createResponse.isRight());
1311
1312                 assertResponse(createResponse, ActionStatus.PARENT_RESOURCE_DOES_NOT_EXTEND);
1313         }
1314         // Derived from stop
1315
1316         @Test
1317         public void createOrUpdateResourceAlreadyCheckout() {
1318                 Resource resourceExist = createResourceObject(false);
1319
1320                 Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
1321
1322                 createResponse.left().value().setLastUpdaterUserId(user.getUserId());
1323                 assertTrue(createResponse.isLeft());
1324
1325                 Either<Component, StorageOperationStatus> getLatestResult = Either.left(createResponse.left().value());
1326                 when(toscaOperationFacade.getLatestByName(resourceExist.getName())).thenReturn(getLatestResult);
1327                 when(toscaOperationFacade.overrideComponent(Mockito.any(Component.class), Mockito.any(Component.class))).thenReturn(getLatestResult);
1328
1329                 Resource resourceToUpdtae = createResourceObject(false);
1330
1331                 Either<ImmutablePair<Resource, ActionStatus>, ResponseFormat> createOrUpdateResource = bl.createOrUpdateResourceByImport(resourceToUpdtae, user, false, false, false, null);
1332                 assertTrue(createOrUpdateResource.isLeft());
1333
1334                 Mockito.verify(toscaOperationFacade, Mockito.times(1)).overrideComponent(Mockito.any(Resource.class), Mockito.any(Resource.class));
1335                 Mockito.verify(lifecycleBl, Mockito.times(0)).changeState(Mockito.anyString(), Mockito.eq(user), Mockito.eq(LifeCycleTransitionEnum.CHECKOUT), Mockito.any(LifecycleChangeInfoWithAction.class), Mockito.anyBoolean(), Mockito.anyBoolean());
1336
1337         }
1338
1339         @Test
1340         public void createOrUpdateResourceCertified() {
1341                 Resource resourceExist = createResourceObject(false);
1342
1343                 Either<Resource, ResponseFormat> createResponse = bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
1344
1345                 assertTrue(createResponse.isLeft());
1346                 Resource certifiedResource = createResponse.left().value();
1347                 certifiedResource.setLifecycleState(LifecycleStateEnum.CERTIFIED);
1348                 certifiedResource.setVersion("1.0");
1349                 
1350
1351                 Either<Component, StorageOperationStatus> getLatestResult = Either.left(certifiedResource);
1352                 when(toscaOperationFacade.getLatestByName(resourceExist.getName())).thenReturn(getLatestResult);
1353                 when(toscaOperationFacade.overrideComponent(Mockito.any(Component.class), Mockito.any(Component.class))).thenReturn(getLatestResult);
1354
1355                 when(lifecycleBl.changeState(Mockito.anyString(), Mockito.eq(user), Mockito.eq(LifeCycleTransitionEnum.CHECKOUT), Mockito.any(LifecycleChangeInfoWithAction.class), Mockito.anyBoolean(), Mockito.anyBoolean())).thenReturn(createResponse);
1356
1357                 Resource resourceToUpdtae = createResourceObject(false);
1358
1359                 Either<ImmutablePair<Resource, ActionStatus>, ResponseFormat> createOrUpdateResource = bl.createOrUpdateResourceByImport(resourceToUpdtae, user, false, false, false, null);
1360                 assertTrue(createOrUpdateResource.isLeft());
1361
1362                 Mockito.verify(toscaOperationFacade, Mockito.times(1)).overrideComponent(Mockito.any(Component.class), Mockito.any(Component.class));
1363                 Mockito.verify(lifecycleBl, Mockito.times(1)).changeState(Mockito.anyString(), Mockito.eq(user), Mockito.eq(LifeCycleTransitionEnum.CHECKOUT), Mockito.any(LifecycleChangeInfoWithAction.class), Mockito.anyBoolean(), Mockito.anyBoolean());
1364
1365         }
1366
1367         @Test
1368         public void createOrUpdateResourceNotExist() {
1369                 Resource resourceToUpdtae = createResourceObject(false);
1370
1371                 Either<Component, StorageOperationStatus> getLatestResult = Either.right(StorageOperationStatus.NOT_FOUND);
1372                 when(toscaOperationFacade.getLatestByName(resourceToUpdtae.getName())).thenReturn(getLatestResult);
1373
1374                 Either<Component, StorageOperationStatus> getLatestToscaNameResult = Either.right(StorageOperationStatus.NOT_FOUND);
1375                 when(toscaOperationFacade.getLatestByToscaResourceName(resourceToUpdtae.getToscaResourceName())).thenReturn(getLatestToscaNameResult);
1376
1377                 Either<ImmutablePair<Resource, ActionStatus>, ResponseFormat> createOrUpdateResource = bl.createOrUpdateResourceByImport(resourceToUpdtae, user, false, false, false, null);
1378                 assertTrue(createOrUpdateResource.isLeft());
1379
1380                 Mockito.verify(toscaOperationFacade, Mockito.times(0)).overrideComponent(Mockito.any(Component.class), Mockito.any(Component.class));
1381                 Mockito.verify(lifecycleBl, Mockito.times(0)).changeState(Mockito.anyString(), Mockito.eq(user), Mockito.eq(LifeCycleTransitionEnum.CHECKOUT), Mockito.any(LifecycleChangeInfoWithAction.class), Mockito.anyBoolean(), Mockito.anyBoolean());
1382
1383         }
1384
1385         @Test
1386         public void testValidatePropertiesDefaultValues_SuccessfullWithoutProperties() {
1387                 Resource basic = createResourceObject(true);
1388
1389                 Either<Boolean, ResponseFormat> validatePropertiesDefaultValues = bl.validatePropertiesDefaultValues(basic);
1390                 assertTrue(validatePropertiesDefaultValues.isLeft());
1391         }
1392
1393         @Test
1394         public void testValidatePropertiesDefaultValues_SuccessfullWithProperties() {
1395                 Resource basic = createResourceObject(true);
1396                 PropertyDefinition property = new PropertyDefinition();
1397                 property.setName("myProperty");
1398                 property.setType(ToscaPropertyType.INTEGER.getType());
1399                 property.setDefaultValue("1");
1400                 List<PropertyDefinition> properties = new ArrayList<>();
1401                 properties.add(property);
1402                 basic.setProperties(properties);
1403                 when(propertyOperation.isPropertyTypeValid(property)).thenReturn(true);
1404                 when(propertyOperation.isPropertyDefaultValueValid(property, emptyDataTypes)).thenReturn(true);
1405                 Either<Boolean, ResponseFormat> validatePropertiesDefaultValues = bl.validatePropertiesDefaultValues(basic);
1406                 assertTrue(validatePropertiesDefaultValues.isLeft());
1407         }
1408
1409         @Test
1410         public void testValidatePropertiesDefaultValues_FailedWithProperties() {
1411                 Resource basic = createResourceObject(true);
1412                 PropertyDefinition property = new PropertyDefinition();
1413                 property.setName("myProperty");
1414                 property.setType(ToscaPropertyType.INTEGER.getType());
1415                 property.setDefaultValue("1.5");
1416                 List<PropertyDefinition> properties = new ArrayList<>();
1417                 properties.add(property);
1418                 basic.setProperties(properties);
1419
1420                 when(propertyOperation.isPropertyDefaultValueValid(property, emptyDataTypes)).thenReturn(false);
1421                 Either<Boolean, ResponseFormat> validatePropertiesDefaultValues = bl.validatePropertiesDefaultValues(basic);
1422                 assertTrue(validatePropertiesDefaultValues.isRight());
1423         }
1424
1425 //      @Test
1426 //      public void testDeleteMarkedResourcesNoResources() {
1427 //              List<GraphVertex> ids = new ArrayList<>();
1428 //              Either<List<GraphVertex>, StorageOperationStatus> eitherNoResources = Either.left(ids);
1429 //              when(topologyTemplateOperation.getAllComponentsMarkedForDeletion(ComponentTypeEnum.RESOURCE)).thenReturn(eitherNoResources);
1430 //
1431 //              Either<List<String>, ResponseFormat> deleteMarkedResources = bl.deleteMarkedComponents();
1432 //              assertTrue(deleteMarkedResources.isLeft());
1433 //              assertTrue(deleteMarkedResources.left().value().isEmpty());
1434 //
1435 //              Mockito.verify(artifactManager, Mockito.times(0)).deleteAllComponentArtifactsIfNotOnGraph(Mockito.anyList());
1436 //
1437 //      }
1438 //
1439 //      @Test
1440 //      public void testDeleteMarkedResources() {
1441 //              List<String> ids = new ArrayList<String>();
1442 //              String resourceInUse = "123";
1443 //              ids.add(resourceInUse);
1444 //              String resourceFree = "456";
1445 //              ids.add(resourceFree);
1446 //              Either<List<String>, StorageOperationStatus> eitherNoResources = Either.left(ids);
1447 //              when(toscaOperationFacade.getAllComponentsMarkedForDeletion()).thenReturn(eitherNoResources);
1448 //
1449 //              Either<Boolean, StorageOperationStatus> resourceInUseResponse = Either.left(true);
1450 //              Either<Boolean, StorageOperationStatus> resourceFreeResponse = Either.left(false);
1451 //
1452 //              List<ArtifactDefinition> artifacts = new ArrayList<ArtifactDefinition>();
1453 //              Either<List<ArtifactDefinition>, StorageOperationStatus> getArtifactsResponse = Either.left(artifacts);
1454 //              when(toscaOperationFacade.getComponentArtifactsForDelete(resourceFree, NodeTypeEnum.Resource, true)).thenReturn(getArtifactsResponse);
1455 //
1456 //              when(toscaOperationFacade.isComponentInUse(resourceFree)).thenReturn(resourceFreeResponse);
1457 //              when(toscaOperationFacade.isComponentInUse(resourceInUse)).thenReturn(resourceInUseResponse);
1458 //
1459 //              Either<Component, StorageOperationStatus> eitherDelete = Either.left(new Resource());
1460 //              when(toscaOperationFacade.deleteToscaComponent(resourceFree)).thenReturn(eitherDelete);
1461 //
1462 //              when(artifactManager.deleteAllComponentArtifactsIfNotOnGraph(artifacts)).thenReturn(StorageOperationStatus.OK);
1463 //              List<String> deletedComponents = new ArrayList<>();
1464 //              deletedComponents.add(resourceFree);
1465 //              when(toscaOperationFacade.deleteMarkedElements(ComponentTypeEnum.RESOURCE)).thenReturn(Either.left(deletedComponents));
1466 //              
1467 //              Either<List<String>, ResponseFormat> deleteMarkedResources = bl.deleteMarkedComponents();
1468 //              assertTrue(deleteMarkedResources.isLeft());
1469 //              List<String> resourceIdList = deleteMarkedResources.left().value();
1470 //              assertFalse(resourceIdList.isEmpty());
1471 //              assertTrue(resourceIdList.contains(resourceFree));
1472 //              assertFalse(resourceIdList.contains(resourceInUse));
1473 //
1474 //              Mockito.verify(artifactManager, Mockito.times(1)).deleteAllComponentArtifactsIfNotOnGraph(artifacts);
1475 //      }
1476         
1477         @SuppressWarnings("unchecked")
1478         @Test
1479         public void testFindVfCsarArtifactsToHandle() {
1480                 
1481                 Class<ResourceBusinessLogic> targetClass = ResourceBusinessLogic.class;
1482                 String methodName = "findVfCsarArtifactsToHandle";
1483                 Resource resource = new Resource();
1484                 String deploymentArtifactToUpdateFileName = "deploymentArtifactToUpdate.yaml";
1485                 String deploymentArtifactToDeleteFileName = "deploymentArtifactToDelete.yaml";
1486                 String deploymentArtifactToCreateFileName = "deploymentArtifactToCreate.yaml";
1487                 
1488                 String artifactInfoToUpdateFileName = "infoArtifactToUpdate.yaml";
1489                 String artifactInfoToDeleteFileName = "infoArtifactToDelete.yaml";
1490                 String artifactInfoToCreateFileName = "infoArtifactToCreate.yaml";
1491                 
1492                 byte[] oldPayloadData = "oldPayloadData".getBytes();
1493                 byte[] newPayloadData = "newPayloadData".getBytes();
1494                 Map<String, ArtifactDefinition> deploymentArtifacts =new HashMap<>();
1495                 
1496                 ArtifactDefinition deploymentArtifactToUpdate = new ArtifactDefinition();
1497                 deploymentArtifactToUpdate.setMandatory(false);
1498                 deploymentArtifactToUpdate.setArtifactName(deploymentArtifactToUpdateFileName);
1499                 deploymentArtifactToUpdate.setArtifactType("SNMP_POLL");
1500                 deploymentArtifactToUpdate.setPayload(oldPayloadData);
1501                 deploymentArtifactToUpdate.setArtifactChecksum(GeneralUtility.calculateMD5ByByteArray(oldPayloadData));
1502                 
1503                 ArtifactDefinition deploymentArtifactToDelete = new ArtifactDefinition();
1504                 deploymentArtifactToDelete.setMandatory(false);
1505                 deploymentArtifactToDelete.setArtifactName(deploymentArtifactToDeleteFileName);
1506                 deploymentArtifactToDelete.setArtifactType("SNMP_TRAP");
1507                 deploymentArtifactToDelete.setPayload(oldPayloadData);
1508                 deploymentArtifactToDelete.setArtifactChecksum(GeneralUtility.calculateMD5ByByteArray(oldPayloadData));
1509                 
1510                 ArtifactDefinition deploymentArtifactToIgnore = new ArtifactDefinition();
1511                 
1512                 deploymentArtifacts.put(ValidationUtils.normalizeArtifactLabel(deploymentArtifactToUpdate.getArtifactName()), deploymentArtifactToUpdate);
1513                 deploymentArtifacts.put(ValidationUtils.normalizeArtifactLabel(deploymentArtifactToDelete.getArtifactName()), deploymentArtifactToDelete);
1514                 deploymentArtifacts.put("ignore", deploymentArtifactToIgnore);
1515                 
1516                 Map<String, ArtifactDefinition> artifacts = new HashMap<>();
1517                 
1518                 ArtifactDefinition artifactToUpdate = new ArtifactDefinition();
1519                 artifactToUpdate.setMandatory(false);
1520                 artifactToUpdate.setArtifactName(artifactInfoToUpdateFileName);
1521                 artifactToUpdate.setArtifactType("SNMP_POLL");
1522                 artifactToUpdate.setPayload(oldPayloadData);
1523                 artifactToUpdate.setArtifactChecksum(GeneralUtility.calculateMD5ByByteArray(oldPayloadData));
1524                 
1525                 ArtifactDefinition artifactToDelete = new ArtifactDefinition();
1526                 artifactToDelete.setMandatory(false);
1527                 artifactToDelete.setArtifactName(artifactInfoToDeleteFileName);
1528                 artifactToDelete.setArtifactType("SNMP_TRAP");
1529                 artifactToDelete.setPayload(oldPayloadData);
1530                 artifactToDelete.setArtifactChecksum(GeneralUtility.calculateMD5ByByteArray(oldPayloadData));
1531                 
1532                 ArtifactDefinition artifactToIgnore = new ArtifactDefinition();
1533                 
1534                 artifacts.put(ValidationUtils.normalizeArtifactLabel(artifactToUpdate.getArtifactName()),artifactToUpdate);
1535                 artifacts.put(ValidationUtils.normalizeArtifactLabel(artifactToDelete.getArtifactName()),artifactToDelete);
1536                 artifacts.put("ignore",artifactToIgnore);
1537                 
1538                 resource.setDeploymentArtifacts(deploymentArtifacts);
1539                 resource.setArtifacts(artifacts);
1540                 
1541                 List<NonMetaArtifactInfo> artifactPathAndNameList = new ArrayList<>();
1542                 NonMetaArtifactInfo deploymentArtifactInfoToUpdate = new NonMetaArtifactInfo(deploymentArtifactToUpdate.getArtifactName(), null, 
1543                         ArtifactTypeEnum.findType(deploymentArtifactToUpdate.getArtifactType()), ArtifactGroupTypeEnum.DEPLOYMENT,
1544                         newPayloadData, deploymentArtifactToUpdate.getArtifactName());
1545                 
1546                 NonMetaArtifactInfo informationalArtifactInfoToUpdate = new NonMetaArtifactInfo(artifactToUpdate.getArtifactName(), null, 
1547                                 ArtifactTypeEnum.findType(artifactToUpdate.getArtifactType()), ArtifactGroupTypeEnum.DEPLOYMENT,
1548                                 newPayloadData, artifactToUpdate.getArtifactName());
1549                 
1550                 NonMetaArtifactInfo deploymentArtifactInfoToCreate = new NonMetaArtifactInfo(deploymentArtifactToCreateFileName, null, 
1551                                 ArtifactTypeEnum.OTHER, ArtifactGroupTypeEnum.DEPLOYMENT, newPayloadData, deploymentArtifactToCreateFileName);
1552                         
1553                         NonMetaArtifactInfo informationalArtifactInfoToCreate = new NonMetaArtifactInfo(artifactInfoToCreateFileName, null, 
1554                                         ArtifactTypeEnum.OTHER, ArtifactGroupTypeEnum.DEPLOYMENT,
1555                                         newPayloadData, artifactInfoToCreateFileName);
1556                 
1557                 artifactPathAndNameList.add(deploymentArtifactInfoToUpdate);
1558                 artifactPathAndNameList.add(informationalArtifactInfoToUpdate);
1559                 artifactPathAndNameList.add(deploymentArtifactInfoToCreate);
1560                 artifactPathAndNameList.add(informationalArtifactInfoToCreate);
1561                 
1562                 Object[] argObjects = {resource, artifactPathAndNameList, user};
1563                 Class[] argClasses = {Resource.class, List.class, User.class};
1564             try {
1565                 Method method = targetClass.getDeclaredMethod(methodName, argClasses);
1566                 method.setAccessible(true);
1567                 Either<EnumMap<ArtifactOperationEnum, List<NonMetaArtifactInfo>>, ResponseFormat> findVfCsarArtifactsToHandleRes = 
1568                                 (Either<EnumMap<ArtifactOperationEnum, List<NonMetaArtifactInfo>>, ResponseFormat>) method.invoke(bl, argObjects);
1569                  assertTrue(findVfCsarArtifactsToHandleRes.isLeft());
1570                  EnumMap<ArtifactOperationEnum, List<NonMetaArtifactInfo>> foundVfArtifacts = findVfCsarArtifactsToHandleRes.left().value();
1571                  assertTrue(foundVfArtifacts.get(ArtifactOperationEnum.Create).size()==2);
1572                  assertTrue(foundVfArtifacts.get(ArtifactOperationEnum.Update).size()==2);
1573                  assertTrue(foundVfArtifacts.get(ArtifactOperationEnum.Create).size()==2);
1574                  
1575             }
1576             catch (Exception e) {
1577                 e.printStackTrace();
1578             }
1579         }
1580         
1581         @SuppressWarnings("rawtypes")
1582         @Test
1583         public void testBuildNestedVfcToscaNamespace() {
1584                 
1585                 Class<ResourceBusinessLogic> targetClass = ResourceBusinessLogic.class;
1586                 String methodName = "buildNestedVfcToscaNamespace";
1587                 String nodeTypeFullName = "org.openecomp.resource.abstract.nodes.heat.FEAdd_On_Module_vLBAgentTemplate";
1588                 String expectedNestedVfcToscaNamespace = "org.openecomp.resource.vfc.nodes.heat.FEAdd_On_Module_vLBAgentTemplate";
1589                 Object[] argObjects = {nodeTypeFullName};
1590                 Class[] argClasses = {String.class};
1591             try {
1592                 Method method = targetClass.getDeclaredMethod(methodName, argClasses);
1593                 method.setAccessible(true);
1594                 String actualNestedVfcToscaNamespace = (String) method.invoke(bl, argObjects);
1595                 assertTrue(!actualNestedVfcToscaNamespace.isEmpty());
1596                 assertTrue(actualNestedVfcToscaNamespace.equals(expectedNestedVfcToscaNamespace));
1597                  
1598             }
1599             catch (Exception e) {
1600                 e.printStackTrace();
1601             }
1602         }
1603         
1604         @SuppressWarnings("rawtypes")
1605         @Test
1606         public void testBuildNestedVfcToscaResourceName() {
1607                 
1608                 Class<ResourceBusinessLogic> targetClass = ResourceBusinessLogic.class;
1609                 String methodName = "buildNestedVfcToscaResourceName";
1610                 String vfResourceName = "vfname";
1611                 String nodeTypeFullName = "org.openecomp.resource.abstract.nodes.heat.FEAdd_On_Module_vLBAgentTemplate";
1612                 String expectedNestedVfcToscaResourceName = "org.openecomp.resource.vfc.vfname.abstract.nodes.heat.FEAdd_On_Module_vLBAgentTemplate";
1613                 Object[] argObjects = {vfResourceName, nodeTypeFullName};
1614                 Class[] argClasses = {String.class, String.class};
1615             try {
1616                 Method method = targetClass.getDeclaredMethod(methodName, argClasses);
1617                 method.setAccessible(true);
1618                 String actualNestedVfcToscaResourceName = (String) method.invoke(bl, argObjects);
1619                 assertTrue(!actualNestedVfcToscaResourceName.isEmpty());
1620                 assertTrue(actualNestedVfcToscaResourceName.equals(expectedNestedVfcToscaResourceName));
1621                  
1622             }
1623             catch (Exception e) {
1624                 e.printStackTrace();
1625             }
1626         }
1627         
1628         @SuppressWarnings("rawtypes")
1629         @Test
1630         public void testBuildNestedSubstituteYamlName() {
1631                 
1632                 Class<ResourceBusinessLogic> targetClass = ResourceBusinessLogic.class;
1633                 String methodName = "buildNestedSubstituteYamlName";
1634                 String nodeTypeFullName = "org.openecomp.resource.abstract.nodes.heat.FEAdd_On_Module_vLBAgentTemplate";
1635                 String expectedNestedSubstituteYamlName = "Definitions/FEAdd_On_Module_vLBAgentTemplateServiceTemplate.yaml";
1636                 Object[] argObjects = {nodeTypeFullName};
1637                 Class[] argClasses = {String.class};
1638             try {
1639                 Method method = targetClass.getDeclaredMethod(methodName, argClasses);
1640                 method.setAccessible(true);
1641                 String actualNestedSubstituteYamlName = (String) method.invoke(bl, argObjects);
1642                 assertTrue(!actualNestedSubstituteYamlName.isEmpty());
1643                 assertTrue(actualNestedSubstituteYamlName.equals(expectedNestedSubstituteYamlName));
1644                  
1645             }
1646             catch (Exception e) {
1647                 e.printStackTrace();
1648             }
1649         }
1650         
1651         
1652         @Test
1653         public void testVFGeneratedInputs() {
1654                 
1655                 Resource resource = createVF();
1656                 List<InputDefinition> inputs = resource.getInputs();
1657                 assertTrue(8 == inputs.size());
1658                 for(InputDefinition input : inputs){
1659                         assertNotNull(input.getOwnerId());
1660                 }
1661                 assertTrue(resource.getDerivedFromGenericType().equals(genericVF.getToscaResourceName()));
1662                 assertTrue(resource.getDerivedFromGenericVersion().equals(genericVF.getVersion()));
1663         }
1664         
1665         @Test
1666         public void testVFUpdateGenericInputsToLatestOnCheckout() {
1667                 
1668                 //create a VF that is derived from generic version 1.0
1669                 Resource resource = createVF(); 
1670                 // create a new generic version without properties
1671                 genericVF.setVersion("2.0");
1672                 genericVF.setProperties(null);
1673                 String currentDerivedFromVersion = resource.getDerivedFromGenericVersion();
1674                 List<InputDefinition> currentInputs = resource.getInputs();
1675                 //verify previous inputs ownerId fields exist - user may not delete generated inputs
1676                 assertTrue(8 == currentInputs.stream().filter(p -> null != p.getOwnerId()).collect(Collectors.toList()).size());
1677                 Either<Boolean, ResponseFormat> upgradeToLatestGeneric = bl.shouldUpgradeToLatestGeneric(resource);
1678                 //verify success
1679                 assertTrue(upgradeToLatestGeneric.isLeft());
1680                 //verify update required and valid
1681                 assertTrue(upgradeToLatestGeneric.left().value());
1682                 //verify version was upgraded   
1683                 assertFalse(resource.getDerivedFromGenericVersion().equals(currentDerivedFromVersion));
1684                 //verify inputs were not deleted
1685                 assertTrue(8 == resource.getInputs().size());
1686                 //verify inputs ownerId fields were removed - user may delete/edit inputs
1687                 assertTrue(8 == resource.getInputs().stream().filter(p -> null == p.getOwnerId()).collect(Collectors.toList()).size());         
1688         }
1689         
1690         
1691         @Test
1692         public void testVFUpdateGenericInputsToLatestOnCheckoutNotPerformed() {
1693                 
1694                 //create a VF that is derived from generic version 1.0
1695                 Resource resource = createVF();
1696                 
1697                 //add an input to the VF
1698                 PropertyDefinition newProp = new PropertyDefinition();
1699                 newProp.setType("integer");
1700                 newProp.setName("newProp");
1701                 resource.getInputs().add(new InputDefinition(newProp));
1702                 
1703                 //create a new generic version with a new property which has the same name as a user defined input on the VF with a different type      
1704                 genericVF.setVersion("2.0");
1705                 newProp.setType("string");
1706                 genericVF.setProperties(new ArrayList<PropertyDefinition>());
1707                 genericVF.getProperties().add(newProp);
1708                 
1709                 String currentDerivedFromVersion = resource.getDerivedFromGenericVersion();
1710                 assertTrue(8 == resource.getInputs().stream().filter(p -> null != p.getOwnerId()).collect(Collectors.toList()).size());
1711                 Either<Boolean, ResponseFormat> upgradeToLatestGeneric = bl.shouldUpgradeToLatestGeneric(resource);
1712                 //verify success
1713                 assertTrue(upgradeToLatestGeneric.isLeft());
1714                 //verify update is invalid an void
1715                 assertFalse(upgradeToLatestGeneric.left().value());
1716                 //verify version was not upgraded       
1717                 assertTrue(resource.getDerivedFromGenericVersion().equals(currentDerivedFromVersion));
1718                 //verify inputs were not removed
1719                 assertTrue(9 == resource.getInputs().size());
1720                 //verify user defined input exists
1721                 assertTrue(1 == resource.getInputs().stream().filter(p -> null == p.getOwnerId()).collect(Collectors.toList()).size());
1722                 assertTrue(resource.getInputs().stream().filter(p -> null == p.getOwnerId()).findAny().get().getType().equals("integer"));              
1723         }
1724         
1725         @Test
1726         public void testPNFGeneratedInputsNoGeneratedInformationalArtifacts() {
1727                 
1728                 Resource resource = createPNF();
1729                 List<InputDefinition> inputs = resource.getInputs();
1730                 assertTrue(8 == inputs.size());
1731                 for(InputDefinition input : inputs){
1732                         assertNotNull(input.getOwnerId());
1733                 }
1734                 assertTrue(resource.getDerivedFromGenericType().equals(genericPNF.getToscaResourceName()));
1735                 assertTrue(resource.getDerivedFromGenericVersion().equals(genericPNF.getVersion()));
1736                 assertTrue(0 == resource.getArtifacts().size());
1737         }
1738         
1739         
1740         private Resource createVF() {
1741                 
1742                 genericVF = setupGenericTypeMock(GENERIC_VF_NAME);
1743                 when(toscaOperationFacade.getLatestCertifiedNodeTypeByToscaResourceName(GENERIC_VF_NAME)).thenReturn(Either.left(genericVF));
1744                 Resource resource = createResourceObject(true);
1745                 resource.setDerivedFrom(null);
1746                 resource.setResourceType(ResourceTypeEnum.VF);
1747                 when(toscaOperationFacade.createToscaComponent(resource)).thenReturn(Either.left(resource));
1748                 Either<Resource, ResponseFormat> createResponse = bl.createResource(resource, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
1749                 assertTrue(createResponse.isLeft());
1750                 return createResponse.left().value();
1751         }
1752         
1753      private Resource createPNF() {
1754                 
1755                 genericPNF = setupGenericTypeMock(GENERIC_PNF_NAME);
1756                 when(toscaOperationFacade.getLatestCertifiedNodeTypeByToscaResourceName(GENERIC_PNF_NAME)).thenReturn(Either.left(genericPNF));
1757                 Resource resource = createResourceObject(true);
1758                 resource.setDerivedFrom(null);
1759                 resource.setResourceType(ResourceTypeEnum.PNF);
1760                 when(toscaOperationFacade.createToscaComponent(resource)).thenReturn(Either.left(resource));
1761                 Either<Resource, ResponseFormat> createResponse = bl.createResource(resource, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
1762                 assertTrue(createResponse.isLeft());
1763                 return createResponse.left().value();
1764         }
1765         
1766
1767         
1768     private Resource setupGenericTypeMock(String toscaName) {
1769                 
1770                 Resource genericType = createResourceObject(true);
1771                 genericType.setVersion("1.0");
1772                 genericType.setToscaResourceName(toscaName);
1773                 String[] propNames = {"nf_function", "nf_role", "nf_naming_code", "nf_type", "nf_naming", "availability_zone_max_count", "min_instances", "max_instances"};
1774                 String[] propTypes = {"string", "string", "string", "string", "org.openecomp.datatypes.Naming", "integer", "integer", "integer"};
1775                 List<PropertyDefinition> genericProps = new ArrayList<>();
1776                 for(int i = 0; i < 8; ++i){
1777                         PropertyDefinition prop = new PropertyDefinition();
1778                         prop.setName(propNames[i]);
1779                         prop.setType(propTypes[i]);
1780                         genericProps.add(prop);
1781                 }
1782                 genericType.setProperties(genericProps);
1783                 return genericType;
1784         }
1785
1786          
1787     
1788 }