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