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