2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.sdc.be.components.impl;
23 import 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.anyString;
31 import static org.mockito.ArgumentMatchers.eq;
32 import static org.mockito.Mockito.times;
33 import static org.mockito.Mockito.when;
35 import fj.data.Either;
36 import java.io.IOException;
37 import java.lang.reflect.Method;
38 import java.util.ArrayList;
39 import java.util.Arrays;
40 import java.util.EnumMap;
41 import java.util.HashMap;
42 import java.util.List;
44 import java.util.Optional;
45 import java.util.stream.Collectors;
46 import java.util.stream.Stream;
47 import javax.servlet.ServletContext;
48 import org.apache.commons.lang3.tuple.ImmutablePair;
49 import org.junit.Assert;
50 import org.junit.Before;
51 import org.junit.Test;
52 import org.mockito.InjectMocks;
53 import org.mockito.Mockito;
54 import org.mockito.MockitoAnnotations;
55 import org.openecomp.sdc.ElementOperationMock;
56 import org.openecomp.sdc.be.auditing.impl.AuditingManager;
57 import org.openecomp.sdc.be.components.ArtifactsResolver;
58 import org.openecomp.sdc.be.components.csar.CsarArtifactsAndGroupsBusinessLogic;
59 import org.openecomp.sdc.be.components.csar.CsarBusinessLogic;
60 import org.openecomp.sdc.be.components.csar.CsarInfo;
61 import org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic.ArtifactOperationEnum;
62 import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
63 import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
64 import org.openecomp.sdc.be.components.impl.generic.GenericTypeBusinessLogic;
65 import org.openecomp.sdc.be.components.lifecycle.LifecycleBusinessLogic;
66 import org.openecomp.sdc.be.components.lifecycle.LifecycleChangeInfoWithAction;
67 import org.openecomp.sdc.be.components.merge.resource.ResourceDataMergeBusinessLogic;
68 import org.openecomp.sdc.be.components.merge.utils.MergeInstanceUtils;
69 import org.openecomp.sdc.be.components.validation.UserValidations;
70 import org.openecomp.sdc.be.components.validation.component.ComponentContactIdValidator;
71 import org.openecomp.sdc.be.components.validation.component.ComponentDescriptionValidator;
72 import org.openecomp.sdc.be.components.validation.component.ComponentFieldValidator;
73 import org.openecomp.sdc.be.components.validation.component.ComponentIconValidator;
74 import org.openecomp.sdc.be.components.validation.component.ComponentNameValidator;
75 import org.openecomp.sdc.be.components.validation.component.ComponentProjectCodeValidator;
76 import org.openecomp.sdc.be.components.validation.component.ComponentTagsValidator;
77 import org.openecomp.sdc.be.components.validation.component.ComponentValidator;
78 import org.openecomp.sdc.be.config.ConfigurationManager;
79 import org.openecomp.sdc.be.dao.api.ActionStatus;
80 import org.openecomp.sdc.be.dao.cassandra.ArtifactCassandraDao;
81 import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
82 import org.openecomp.sdc.be.dao.jsongraph.JanusGraphDao;
83 import org.openecomp.sdc.be.datamodel.api.HighestFilterEnum;
84 import org.openecomp.sdc.be.datamodel.utils.UiComponentDataConverter;
85 import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
86 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
87 import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
88 import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
89 import org.openecomp.sdc.be.facade.operations.CatalogOperation;
90 import org.openecomp.sdc.be.impl.ComponentsUtils;
91 import org.openecomp.sdc.be.impl.WebAppContextWrapper;
92 import org.openecomp.sdc.be.model.ArtifactDefinition;
93 import org.openecomp.sdc.be.model.Component;
94 import org.openecomp.sdc.be.model.ComponentParametersView;
95 import org.openecomp.sdc.be.model.DataTypeDefinition;
96 import org.openecomp.sdc.be.model.GroupDefinition;
97 import org.openecomp.sdc.be.model.InputDefinition;
98 import org.openecomp.sdc.be.model.LifeCycleTransitionEnum;
99 import org.openecomp.sdc.be.model.LifecycleStateEnum;
100 import org.openecomp.sdc.be.model.NodeTypeInfo;
101 import org.openecomp.sdc.be.model.PropertyDefinition;
102 import org.openecomp.sdc.be.model.Resource;
103 import org.openecomp.sdc.be.model.User;
104 import org.openecomp.sdc.be.model.cache.ApplicationDataTypeCache;
105 import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ArtifactsOperations;
106 import org.openecomp.sdc.be.model.jsonjanusgraph.operations.InterfaceOperation;
107 import org.openecomp.sdc.be.model.jsonjanusgraph.operations.NodeTemplateOperation;
108 import org.openecomp.sdc.be.model.jsonjanusgraph.operations.NodeTypeOperation;
109 import org.openecomp.sdc.be.model.jsonjanusgraph.operations.TopologyTemplateOperation;
110 import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade;
111 import org.openecomp.sdc.be.model.operations.StorageException;
112 import org.openecomp.sdc.be.model.operations.api.ICapabilityTypeOperation;
113 import org.openecomp.sdc.be.model.operations.api.IElementOperation;
114 import org.openecomp.sdc.be.model.operations.api.IGroupInstanceOperation;
115 import org.openecomp.sdc.be.model.operations.api.IGroupOperation;
116 import org.openecomp.sdc.be.model.operations.api.IGroupTypeOperation;
117 import org.openecomp.sdc.be.model.operations.api.IInterfaceLifecycleOperation;
118 import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
119 import org.openecomp.sdc.be.model.operations.impl.CsarOperation;
120 import org.openecomp.sdc.be.model.operations.impl.GraphLockOperation;
121 import org.openecomp.sdc.be.model.operations.impl.InterfaceLifecycleOperation;
122 import org.openecomp.sdc.be.model.operations.impl.PropertyOperation;
123 import org.openecomp.sdc.be.model.tosca.ToscaPropertyType;
124 import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
125 import org.openecomp.sdc.be.tosca.CsarUtils;
126 import org.openecomp.sdc.be.tosca.CsarUtils.NonMetaArtifactInfo;
127 import org.openecomp.sdc.be.tosca.ToscaExportHandler;
128 import org.openecomp.sdc.be.user.Role;
129 import org.openecomp.sdc.be.user.UserBusinessLogic;
130 import org.openecomp.sdc.common.api.ArtifactGroupTypeEnum;
131 import org.openecomp.sdc.common.api.ArtifactTypeEnum;
132 import org.openecomp.sdc.common.api.Constants;
133 import org.openecomp.sdc.common.impl.ExternalConfiguration;
134 import org.openecomp.sdc.common.impl.FSConfigurationSource;
135 import org.openecomp.sdc.common.util.GeneralUtility;
136 import org.openecomp.sdc.common.util.ValidationUtils;
137 import org.openecomp.sdc.exception.ResponseFormat;
138 import org.springframework.web.context.WebApplicationContext;
140 public class ResourceBusinessLogicTest {
142 private final ConfigurationManager configurationManager = new ConfigurationManager(new FSConfigurationSource(ExternalConfiguration.getChangeListener(), "src/test/resources/config/catalog-be"));
143 private static final String RESOURCE_CATEGORY1 = "Network Layer 2-3";
144 private static final String RESOURCE_SUBCATEGORY = "Router";
146 private static final String UPDATED_SUBCATEGORY = "Gateway";
148 private static final String RESOURCE_NAME = "My-Resource_Name with space";
149 private static final String RESOURCE_TOSCA_NAME = "My-Resource_Tosca_Name";
150 private static final String GENERIC_ROOT_NAME = "tosca.nodes.Root";
151 private static final String GENERIC_VF_NAME = "org.openecomp.resource.abstract.nodes.VF";
152 private static final String GENERIC_CR_NAME = "org.openecomp.resource.abstract.nodes.CR";
153 private static final String GENERIC_PNF_NAME = "org.openecomp.resource.abstract.nodes.PNF";
155 private final ServletContext servletContext = Mockito.mock(ServletContext.class);
156 IElementOperation mockElementDao;
157 private final JanusGraphDao mockJanusGraphDao = Mockito.mock(JanusGraphDao.class);
158 private final UserBusinessLogic mockUserAdmin = Mockito.mock(UserBusinessLogic.class);
159 private final ToscaOperationFacade toscaOperationFacade = Mockito.mock(ToscaOperationFacade.class);
160 private final NodeTypeOperation nodeTypeOperation = Mockito.mock(NodeTypeOperation.class);
161 private final NodeTemplateOperation nodeTemplateOperation = Mockito.mock(NodeTemplateOperation.class);
162 private final TopologyTemplateOperation topologyTemplateOperation = Mockito.mock(TopologyTemplateOperation.class);
163 private final LifecycleBusinessLogic lifecycleBl = Mockito.mock(LifecycleBusinessLogic.class);
164 private final CatalogOperation catalogOperation = Mockito.mock(CatalogOperation.class);
165 private final ICapabilityTypeOperation capabilityTypeOperation = Mockito.mock(ICapabilityTypeOperation.class);
166 private final PropertyOperation propertyOperation = Mockito.mock(PropertyOperation.class);
167 private final ApplicationDataTypeCache applicationDataTypeCache = Mockito.mock(ApplicationDataTypeCache.class);
168 private final WebAppContextWrapper webAppContextWrapper = Mockito.mock(WebAppContextWrapper.class);
169 private final UserValidations userValidations = Mockito.mock(UserValidations.class);
170 private final WebApplicationContext webAppContext = Mockito.mock(WebApplicationContext.class);
171 private final IInterfaceLifecycleOperation interfaceTypeOperation = Mockito.mock(IInterfaceLifecycleOperation.class);
172 private final ArtifactCassandraDao artifactCassandraDao = Mockito.mock(ArtifactCassandraDao.class);
173 private final IElementOperation elementDao = new ElementOperationMock();
175 private final CsarUtils csarUtils = Mockito.mock(CsarUtils.class);
176 private final UserBusinessLogic userBusinessLogic = Mockito.mock(UserBusinessLogic.class);
177 private final IGroupOperation groupOperation = Mockito.mock(IGroupOperation.class);
178 private final IGroupInstanceOperation groupInstanceOperation = Mockito.mock(IGroupInstanceOperation.class);
179 private final IGroupTypeOperation groupTypeOperation = Mockito.mock(IGroupTypeOperation.class);
180 private final GroupBusinessLogic groupBusinessLogic = Mockito.mock(GroupBusinessLogic.class);
181 private final InterfaceOperation interfaceOperation = Mockito.mock(InterfaceOperation.class);
182 private final ArtifactsOperations artifactToscaOperation = Mockito.mock(ArtifactsOperations.class);
183 private final PropertyBusinessLogic propertyBusinessLogic = Mockito.mock(PropertyBusinessLogic.class);
184 private final ArtifactsResolver artifactsResolver = Mockito.mock(ArtifactsResolver.class);
185 private final InterfaceLifecycleOperation interfaceLifecycleTypeOperation = Mockito.mock(InterfaceLifecycleOperation.class);
186 private final ComponentInstanceBusinessLogic componentInstanceBusinessLogic = Mockito.mock(ComponentInstanceBusinessLogic.class);
187 private final ResourceImportManager resourceImportManager = Mockito.mock(ResourceImportManager.class);
188 private final InputsBusinessLogic inputsBusinessLogic = Mockito.mock(InputsBusinessLogic.class);
189 private final OutputsBusinessLogic outputsBusinessLogic = Mockito.mock(OutputsBusinessLogic.class);
190 private final CompositionBusinessLogic compositionBusinessLogic = Mockito.mock(CompositionBusinessLogic.class);
191 private final ResourceDataMergeBusinessLogic resourceDataMergeBusinessLogic = Mockito.mock(ResourceDataMergeBusinessLogic.class);
192 private final CsarArtifactsAndGroupsBusinessLogic csarArtifactsAndGroupsBusinessLogic = Mockito.mock(CsarArtifactsAndGroupsBusinessLogic.class);
193 private final MergeInstanceUtils mergeInstanceUtils = Mockito.mock(MergeInstanceUtils.class);
194 private final UiComponentDataConverter uiComponentDataConverter = Mockito.mock(UiComponentDataConverter.class);
195 private final ToscaExportHandler toscaExportHandler = Mockito.mock(ToscaExportHandler.class);
196 private final PolicyBusinessLogic policyBusinessLogic = Mockito.mock(PolicyBusinessLogic.class);
199 ResponseFormatManager responseManager = null;
200 private final GraphLockOperation graphLockOperation = Mockito.mock(GraphLockOperation.class);
202 Resource resourceResponse = null;
203 Resource genericVF = null;
204 Resource genericCR = null;
205 Resource genericVFC = null;
206 Resource genericPNF = null;
207 Resource rootType = null;
208 ComponentsUtils componentsUtils = new ComponentsUtils(Mockito.mock(AuditingManager.class));
209 ArtifactsBusinessLogic artifactManager = new ArtifactsBusinessLogic(artifactCassandraDao, toscaExportHandler, csarUtils, lifecycleBl,
210 userBusinessLogic, artifactsResolver, elementDao, groupOperation, groupInstanceOperation, groupTypeOperation,
211 interfaceOperation, interfaceLifecycleTypeOperation, artifactToscaOperation);
212 CsarOperation csarOperation = Mockito.mock(CsarOperation.class);
214 CsarBusinessLogic csarBusinessLogic ;
215 Map<String, DataTypeDefinition> emptyDataTypes = new HashMap<>();
216 List<Resource> reslist;
217 private GenericTypeBusinessLogic genericTypeBusinessLogic = Mockito.mock(GenericTypeBusinessLogic.class);
218 protected ComponentDescriptionValidator componentDescriptionValidator = new ComponentDescriptionValidator(componentsUtils);
219 protected ComponentProjectCodeValidator componentProjectCodeValidator = new ComponentProjectCodeValidator(componentsUtils);
220 protected ComponentIconValidator componentIconValidator = new ComponentIconValidator(componentsUtils);
221 protected ComponentContactIdValidator componentContactIdValidator = new ComponentContactIdValidator(componentsUtils);
222 protected ComponentTagsValidator componentTagsValidator = new ComponentTagsValidator(componentsUtils);
223 protected ComponentNameValidator componentNameValidator = new ComponentNameValidator(componentsUtils, toscaOperationFacade);
224 private ComponentValidator componentValidator = createComponentValidator();
225 private SoftwareInformationBusinessLogic softwareInformationBusinessLogic = Mockito.mock(SoftwareInformationBusinessLogic.class);
227 private ComponentValidator createComponentValidator() {
228 List<ComponentFieldValidator> componentFieldValidators = Arrays.asList(componentNameValidator,
229 componentDescriptionValidator, componentProjectCodeValidator,
230 componentIconValidator, componentContactIdValidator,
231 componentTagsValidator);
232 return new ComponentValidator(componentsUtils,componentFieldValidators);
235 ResourceBusinessLogic bl;
238 public void setup() {
239 MockitoAnnotations.initMocks(this);
240 Mockito.reset(propertyOperation);
243 mockElementDao = new ElementOperationMock();
246 // User data and management
248 user.setUserId("jh0003");
249 user.setFirstName("Jimmi");
250 user.setLastName("Hendrix");
251 user.setRole(Role.ADMIN.name());
253 when(mockUserAdmin.getUser("jh0003", false)).thenReturn(user);
254 when(userValidations.validateUserExists(user.getUserId())).thenReturn(user);
255 when(userValidations.validateUserNotEmpty(eq(user), anyString())).thenReturn(user);
256 // Servlet Context attributes
257 when(servletContext.getAttribute(Constants.CONFIGURATION_MANAGER_ATTR)).thenReturn(configurationManager);
258 when(servletContext.getAttribute(Constants.WEB_APPLICATION_CONTEXT_WRAPPER_ATTR))
259 .thenReturn(webAppContextWrapper);
260 when(webAppContextWrapper.getWebAppContext(servletContext)).thenReturn(webAppContext);
261 when(webAppContext.getBean(IElementOperation.class)).thenReturn(mockElementDao);
263 Either<Boolean, StorageOperationStatus> eitherFalse = Either.left(true);
264 when(toscaOperationFacade.validateComponentNameExists("tosca.nodes.Root", ResourceTypeEnum.VFC, ComponentTypeEnum.RESOURCE))
265 .thenReturn(eitherFalse);
268 Either<Boolean, StorageOperationStatus> eitherCountExist = Either.left(true);
269 when(toscaOperationFacade.validateComponentNameExists("alreadyExists", ResourceTypeEnum.VFC,
270 ComponentTypeEnum.RESOURCE)).thenReturn(eitherCountExist);
272 Either<Boolean, StorageOperationStatus> eitherCount = Either.left(false);
273 when(toscaOperationFacade.validateComponentNameExists(eq(RESOURCE_NAME), any(ResourceTypeEnum.class),
274 eq(ComponentTypeEnum.RESOURCE))).thenReturn(eitherCount);
275 Either<Boolean, StorageOperationStatus> validateDerivedExists = Either.left(true);
276 when(toscaOperationFacade.validateToscaResourceNameExists("tosca.nodes.Root")).thenReturn(validateDerivedExists);
278 Either<Boolean, StorageOperationStatus> validateDerivedNotExists = Either.left(false);
279 when(toscaOperationFacade.validateToscaResourceNameExists("kuku")).thenReturn(validateDerivedNotExists);
280 when(graphLockOperation.lockComponent(anyString(), eq(NodeTypeEnum.Resource)))
281 .thenReturn(StorageOperationStatus.OK);
282 when(graphLockOperation.lockComponentByName(anyString(), eq(NodeTypeEnum.Resource)))
283 .thenReturn(StorageOperationStatus.OK);
286 resourceResponse = createResourceObject(true);
287 Either<Resource, StorageOperationStatus> eitherCreate = Either.left(resourceResponse);
288 when(toscaOperationFacade.createToscaComponent(any(Resource.class))).thenReturn(eitherCreate);
289 when(catalogOperation.updateCatalog(Mockito.any(), Mockito.any())).thenReturn(ActionStatus.OK);
290 Map<String, DataTypeDefinition> emptyDataTypes = new HashMap<>();
291 when(applicationDataTypeCache.getAll()).thenReturn(Either.left(emptyDataTypes));
292 when(mockJanusGraphDao.commit()).thenReturn(JanusGraphOperationStatus.OK);
295 artifactManager.setNodeTemplateOperation(nodeTemplateOperation);
296 bl = new ResourceBusinessLogic(mockElementDao, groupOperation, groupInstanceOperation, groupTypeOperation, groupBusinessLogic,
297 interfaceOperation, interfaceLifecycleTypeOperation, artifactManager, componentInstanceBusinessLogic,
298 resourceImportManager, inputsBusinessLogic, outputsBusinessLogic, compositionBusinessLogic, resourceDataMergeBusinessLogic,
299 csarArtifactsAndGroupsBusinessLogic, mergeInstanceUtils, uiComponentDataConverter, csarBusinessLogic,
300 artifactToscaOperation, propertyBusinessLogic, componentContactIdValidator, componentNameValidator,
301 componentTagsValidator, componentValidator, componentIconValidator, componentProjectCodeValidator,
302 componentDescriptionValidator, policyBusinessLogic);
303 bl.setElementDao(mockElementDao);
304 bl.setUserAdmin(mockUserAdmin);
305 bl.setCapabilityTypeOperation(capabilityTypeOperation);
306 bl.setComponentsUtils(componentsUtils);
307 bl.setLifecycleManager(lifecycleBl);
308 bl.setArtifactsManager(artifactManager);
309 bl.setGraphLockOperation(graphLockOperation);
310 bl.setPropertyOperation(propertyOperation);
311 bl.setJanusGraphDao(mockJanusGraphDao);
312 bl.setApplicationDataTypeCache(applicationDataTypeCache);
313 bl.setGenericTypeBusinessLogic(genericTypeBusinessLogic);
314 bl.setCatalogOperations(catalogOperation);
315 toscaOperationFacade.setNodeTypeOperation(nodeTypeOperation);
316 csarBusinessLogic.setComponentsUtils(componentsUtils);
317 toscaOperationFacade.setTopologyTemplateOperation(topologyTemplateOperation);
318 bl.setToscaOperationFacade(toscaOperationFacade);
319 bl.setUserValidations(userValidations);
320 bl.setInterfaceTypeOperation(interfaceTypeOperation);
322 csarBusinessLogic.setCsarOperation(csarOperation);
323 Resource resourceCsar = createResourceObjectCsar(true);
324 setCanWorkOnResource(resourceCsar);
325 Either<Component, StorageOperationStatus> oldResourceRes = Either.left(resourceCsar);
326 when(toscaOperationFacade.getToscaFullElement(resourceCsar.getUniqueId())).thenReturn(oldResourceRes);
327 responseManager = ResponseFormatManager.getInstance();
328 bl.setComponentIconValidator(componentIconValidator);
329 bl.setComponentNameValidator(componentNameValidator);
330 bl.setComponentDescriptionValidator(componentDescriptionValidator);
331 bl.setComponentTagsValidator(componentTagsValidator);
332 bl.setComponentContactIdValidator(componentContactIdValidator);
333 bl.setComponentProjectCodeValidator(componentProjectCodeValidator);
334 bl.setComponentValidator(componentValidator);
335 reslist = new ArrayList<>();
336 reslist.add(resourceResponse);
337 reslist.add(genericVF);
338 reslist.add(genericCR);
339 reslist.add(genericVFC);
340 reslist.add(genericPNF);
341 Either<List<Resource>, StorageOperationStatus> returneval= Either.left(reslist);
342 when(toscaOperationFacade.getAllCertifiedResources(true, true)).thenReturn(returneval);
343 when(toscaOperationFacade.validateComponentNameUniqueness("Resource", ResourceTypeEnum.CR, ComponentTypeEnum.RESOURCE)).thenReturn(Either.left(true));
344 Either<List<Resource>, StorageOperationStatus> returnevalexception= Either.right(StorageOperationStatus.BAD_REQUEST);
345 when(toscaOperationFacade.getAllCertifiedResources(false, false)).thenReturn(returnevalexception);
348 @Test(expected = ComponentException.class)
349 public void createResourcesFromYamlNodeTypesList() throws IOException {
350 Map<String, Object> mappedToscaTemplate = new HashMap<>();
351 Map<String, EnumMap<ArtifactOperationEnum, List<ArtifactDefinition>>> nodeTypesArtifactsToHandle = new HashMap<>();
352 List<ArtifactDefinition> nodeTypesNewCreatedArtifacts = new ArrayList<>();
353 Map<String, NodeTypeInfo> nodeTypesInfo = new HashMap<>();
354 bl.createResourcesFromYamlNodeTypesList(
359 nodeTypesArtifactsToHandle,
360 nodeTypesNewCreatedArtifacts,
362 new CsarInfo(user, "abcd1234", new HashMap<>(), RESOURCE_NAME, "template name", ImportUtilsTest.loadFileNameToJsonString("normative-types-new-webServer.yml"),true));
366 public void handleNodeTypeArtifactsTest() {
367 Map<ArtifactOperationEnum, List<ArtifactDefinition>> nodeTypeArtifactsToHandle = new HashMap<>();
368 List<ArtifactDefinition> defs = new ArrayList<>();
369 defs.add(new ArtifactDefinition());
370 nodeTypeArtifactsToHandle.put(ArtifactOperationEnum.CREATE, defs);
371 nodeTypeArtifactsToHandle.put(ArtifactOperationEnum.UPDATE, defs);
372 assertTrue(bl.handleNodeTypeArtifacts(resourceResponse, nodeTypeArtifactsToHandle, new ArrayList<>(), user, true, true).isRight());
376 public void getUiComponentDataTransferByComponentIdTest() {
377 when(toscaOperationFacade.getToscaElement(eq(""), Mockito.any(ComponentParametersView.class))).thenReturn(Either.left(genericCR));
378 assertTrue(bl.getUiComponentDataTransferByComponentId("", new ArrayList<>()).isLeft());
379 when(toscaOperationFacade.getToscaElement(eq(""), Mockito.any(ComponentParametersView.class))).thenReturn(Either.right(StorageOperationStatus.OK));
380 assertTrue(bl.getUiComponentDataTransferByComponentId("", new ArrayList<>()).isRight());
384 public void shouldUpgradeToLatestDerivedTest() {
387 when(toscaOperationFacade.shouldUpgradeToLatestDerived(genericCR)).thenReturn(Either.left(genericCR));
388 when(toscaOperationFacade.shouldUpgradeToLatestDerived(genericVFC)).thenReturn(Either.right(StorageOperationStatus.OK));
389 assertTrue(bl.shouldUpgradeToLatestDerived(genericVF).isLeft());
390 assertTrue(bl.shouldUpgradeToLatestDerived(genericCR).isLeft());
393 private Resource createResourceObject(boolean afterCreate) {
394 Resource resource = new Resource();
395 resource.setName(RESOURCE_NAME);
396 resource.setToscaResourceName(RESOURCE_TOSCA_NAME);
397 resource.addCategory(RESOURCE_CATEGORY1, RESOURCE_SUBCATEGORY);
398 resource.setDescription("My short description");
399 List<String> tgs = new ArrayList<>();
401 tgs.add(resource.getName());
402 resource.setTags(tgs);
403 List<String> template = new ArrayList<>();
404 template.add("tosca.nodes.Root");
405 resource.setDerivedFrom(template);
406 resource.setVendorName("Motorola");
407 resource.setVendorRelease("1.0.0");
408 resource.setContactId("ya5467");
409 resource.setIcon("defaulticon");
412 resource.setName(resource.getName());
413 resource.setVersion("0.1");
414 resource.setUniqueId(resource.getName()
415 .toLowerCase() + ":" + resource.getVersion());
416 resource.setCreatorUserId(user.getUserId());
417 resource.setCreatorFullName(user.getFirstName() + " " + user.getLastName());
418 resource.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
423 private Resource createResourceObjectCsar(boolean afterCreate) {
424 Resource resource = new Resource();
425 resource.setName(RESOURCE_NAME);
426 resource.addCategory(RESOURCE_CATEGORY1, RESOURCE_SUBCATEGORY);
427 resource.setDescription("My short description");
428 List<String> tgs = new ArrayList<>();
430 tgs.add(resource.getName());
431 resource.setTags(tgs);
432 List<String> template = new ArrayList<>();
433 template.add("tosca.nodes.Root");
434 resource.setDerivedFrom(template);
435 resource.setVendorName("Motorola");
436 resource.setVendorRelease("1.0.0");
437 resource.setResourceVendorModelNumber("");
438 resource.setContactId("ya5467");
439 resource.setIcon("MyIcon");
440 resource.setCsarUUID("valid_vf.csar");
441 resource.setCsarVersion("1");
444 resource.setName(resource.getName());
445 resource.setVersion("0.1");
447 resource.setUniqueId(resource.getName()
448 .toLowerCase() + ":" + resource.getVersion());
449 resource.setCreatorUserId(user.getUserId());
450 resource.setCreatorFullName(user.getFirstName() + " " + user.getLastName());
451 resource.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
456 private Resource setCanWorkOnResource(Resource resource) {
457 resource.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
458 resource.setLastUpdaterUserId(user.getUserId());
463 public void testHappyScenario() {
464 validateUserRoles(Role.ADMIN, Role.DESIGNER);
465 Resource resource = createResourceObject(false);
466 Resource createdResource = null;
468 when(toscaOperationFacade
469 .validateComponentNameAndModelExists(resource.getName(), null, ResourceTypeEnum.VFC, ComponentTypeEnum.RESOURCE))
470 .thenReturn(Either.left(false));
471 createdResource = bl.createResource(resource, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
472 assertThat(createResourceObject(true)).isEqualTo(createdResource);
473 } catch (ComponentException e) {
474 assertThat(new Integer(200)).isEqualTo(e.getResponseFormat()
480 public void testUpdateHappyScenario() {
481 Resource resource = createResourceObjectCsar(true);
482 setCanWorkOnResource(resource);
483 validateUserRoles(Role.ADMIN, Role.DESIGNER);
484 Either<Resource, StorageOperationStatus> resourceLinkedToCsarRes = Either.left(resource);
485 when(toscaOperationFacade.getLatestComponentByCsarOrName(ComponentTypeEnum.RESOURCE, resource.getCsarUUID(), resource.getSystemName())).thenReturn(resourceLinkedToCsarRes);
486 Either<Boolean, StorageOperationStatus> validateDerivedExists = Either.left(true);
487 when(toscaOperationFacade.validateToscaResourceNameExists("tosca.nodes.Root")).thenReturn(validateDerivedExists);
488 Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
489 when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
490 Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
491 when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
493 assertThat(resource.getUniqueId()).isEqualTo(bl.validateAndUpdateResourceFromCsar(resource, user, null, null, resource.getUniqueId()).getUniqueId());
494 } catch (ComponentException e) {
495 assertThat(e.getResponseFormat().getStatus()).isEqualTo(200);
500 public void testUpdateUnhappyScenario() {
501 Resource resource = createResourceObjectCsar(true);
502 setCanWorkOnResource(resource);
503 validateUserRoles(Role.ADMIN, Role.DESIGNER);
505 when(toscaOperationFacade.getLatestComponentByCsarOrName(ComponentTypeEnum.RESOURCE, resource.getCsarUUID(), resource.getSystemName())).thenReturn(Either.left(resource));
506 when(toscaOperationFacade.validateToscaResourceNameExists("tosca.nodes.Root")).thenReturn(Either.left(true));
507 when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(Either.left(setCanWorkOnResource(resource)));
508 when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(Either.left(resource));
510 when(csarOperation.getCsar("valid_vf.csar", user)).thenReturn(Either.left(new HashMap<>()));
514 Resource createdResource = bl.validateAndUpdateResourceFromCsar(resource, user, null, "", resource.getUniqueId());
515 assertThat(resource.getUniqueId()).isEqualTo(createdResource.getUniqueId());
516 } catch (ComponentException e) {
517 assertThat(e.getResponseFormat().getStatus()).isEqualTo(400);
520 resource.setCsarVersion("2");
521 when(toscaOperationFacade.getLatestComponentByCsarOrName(ComponentTypeEnum.RESOURCE, resource.getCsarUUID(), resource.getSystemName())).thenReturn(Either.left(resource));
522 bl.validateAndUpdateResourceFromCsar(resource, user, null, null, resource.getUniqueId());
523 } catch (ComponentException e) {
524 assertThat(e.getResponseFormat().getStatus()).isEqualTo(400);
527 /* CREATE validations - start ***********************/
528 // Resource name - start
531 public void testFailedResourceValidations() {
532 testResourceNameExist();
533 testResourceNameEmpty();
534 // testResourceNameExceedsLimit();
535 testResourceNameWrongFormat();
536 testResourceDescExceedsLimitCreate();
537 testResourceDescNotEnglish();
538 testResourceDescriptionEmpty();
539 testResourceDescriptionMissing();
540 testResourceIconMissing();
541 testResourceIconInvalid();
542 testResourceIconExceedsLimit();
543 testResourceTagNotExist();
544 testResourceTagEmpty();
545 testTagsExceedsLimitCreate();
546 testTagsNoServiceName();
549 testContactIdTooLong();
550 testContactIdWrongFormatCreate();
551 testResourceContactIdEmpty();
552 testResourceContactIdMissing();
553 testVendorNameExceedsLimit();
554 testVendorNameWrongFormatCreate();
555 testVendorReleaseWrongFormat();
556 testVendorReleaseExceedsLimitCreate();
557 testResourceVendorModelNumberExceedsLimit();
558 testResourceVendorNameMissing();
559 testResourceVendorReleaseMissing();
560 testResourceCategoryExist();
561 testResourceBadCategoryCreate();
562 testHappyScenarioCostLicenseType();
563 testCostWrongFormatCreate();
564 testLicenseTypeWrongFormatCreate();
565 testResourceTemplateNotExist();
566 testResourceTemplateEmpty();
567 testResourceTemplateInvalid();
570 private void testResourceNameExist() {
571 String resourceName = "alreadyExists";
572 Resource resourceExist = createResourceObject(false);
573 resourceExist.setName(resourceName);
574 resourceExist.getTags()
576 validateUserRoles(Role.ADMIN, Role.DESIGNER);
577 when(toscaOperationFacade
578 .validateComponentNameAndModelExists(resourceName, null, ResourceTypeEnum.VFC, ComponentTypeEnum.RESOURCE))
579 .thenReturn(Either.left(true));
581 bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
582 } catch (ComponentException e) {
583 assertComponentException(e, ActionStatus.COMPONENT_NAME_ALREADY_EXIST,
584 ComponentTypeEnum.RESOURCE.getValue(), resourceName);
588 private void testResourceNameEmpty() {
589 Resource resourceExist = createResourceObject(false);
590 resourceExist.setName(null);
593 bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
594 } catch (ComponentException e) {
595 assertComponentException(e, ActionStatus.MISSING_COMPONENT_NAME, ComponentTypeEnum.RESOURCE.getValue());
599 private void testResourceNameExceedsLimit() {
600 Resource resourceExccedsNameLimit = createResourceObject(false);
601 // 51 chars, the limit is 50
602 String tooLongResourceName = "zCRCAWjqte0DtgcAAMmcJcXeNubeX1p1vOZNTShAHOYNAHvV3iK";
603 resourceExccedsNameLimit.setName(tooLongResourceName);
606 bl.createResource(resourceExccedsNameLimit, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
607 } catch (ComponentException e) {
608 assertComponentException(e, ActionStatus.COMPONENT_NAME_EXCEEDS_LIMIT,
609 ComponentTypeEnum.RESOURCE.getValue(), "" + ValidationUtils.COMPONENT_NAME_MAX_LENGTH);
613 private void testResourceNameWrongFormat() {
614 Resource resource = createResourceObject(false);
616 String nameWrongFormat = "ljg?fd";
617 resource.setName(nameWrongFormat);
620 bl.createResource(resource, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
621 } catch (ComponentException e) {
622 assertComponentException(e, ActionStatus.INVALID_COMPONENT_NAME, ComponentTypeEnum.RESOURCE.getValue());
626 // Resource name - end
627 // Resource description - start
628 private void testResourceDescExceedsLimitCreate() {
629 Resource resourceExccedsDescLimit = createResourceObject(false);
630 // 1025 chars, the limit is 1024
631 String tooLongResourceDesc = "1GUODojQ0sGzKR4NP7e5j82ADQ3KHTVOaezL95qcbuaqDtjZhAQGQ3iFwKAy580K4WiiXs3u3zq7RzXcSASl5fm0RsWtCMOIDP"
632 + "AOf9Tf2xtXxPCuCIMCR5wOGnNTaFxgnJEHAGxilBhZDgeMNHmCN1rMK5B5IRJOnZxcpcL1NeG3APTCIMP1lNAxngYulDm9heFSBc8TfXAADq7703AvkJT0QPpGq2z2P"
633 + "tlikcAnIjmWgfC5Tm7UH462BAlTyHg4ExnPPL4AO8c92VrD7kZSgSqiy73cN3gLT8uigkKrUgXQFGVUFrXVyyQXYtVM6bLBeuCGQf4C2j8lkNg6M0J3PC0PzMRoinOxk"
634 + "Ae2teeCtVcIj4A1KQo3210j8q2v7qQU69Mabsa6DT9FgE4rcrbiFWrg0Zto4SXWD3o1eJA9o29lTg6kxtklH3TuZTmpi5KVp1NFhS1RpnqF83tzv4mZLKsx7Zh1fEgYvRFwx1"
635 + "ar3RolyDfNoZiGBGTMsZzz7RPFBf2hTnLmNqVGQnHKhhGj0Y5s8t2cbqbO2nmHiJb9uaUVrCGypgbAcJL3KPOBfAVW8PcpmNj4yVjI3L4x5zHjmGZbp9vKshEQODcrmcgsYAoKqe"
636 + "uu5u7jk8XVxEfQ0m5qL8UOErXPlJovSmKUmP5B5T0w299zIWDYCzSoNasHpHjOMDLAiDDeHbozUOn9t3Qou00e9POq4RMM0VnIx1H38nJoJZz2XH8CI5YMQe7oTagaxgQTF2aa0qaq2"
637 + "V6nJsfRGRklGjNhFFYP2cS4Xv2IJO9DSX6LTXOmENrGVJJvMOZcvnBaZPfoAHN0LU4i1SoepLzulIxnZBfkUWFJgZ5wQ0Bco2GC1HMqzW21rwy4XHRxXpXbmW8LVyoA1KbnmVmROycU4"
638 + "scTZ62IxIcIWCVeMjBIcTviXULbPUyqlfEPXWr8IMJtpAaELWgyquPClAREMDs2b9ztKmUeXlMccFES1XWbFTrhBHhmmDyVReEgCwfokrUFR13LTUK1k8I6OEHOs";
640 resourceExccedsDescLimit.setDescription(tooLongResourceDesc);
642 bl.createResource(resourceExccedsDescLimit, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
643 } catch (ComponentException e) {
644 assertComponentException(e, ActionStatus.COMPONENT_DESCRIPTION_EXCEEDS_LIMIT,
645 ComponentTypeEnum.RESOURCE.getValue(), "" + ValidationUtils.COMPONENT_DESCRIPTION_MAX_LENGTH);
649 private void testResourceDescNotEnglish() {
650 Resource notEnglish = createResourceObject(false);
652 String notEnglishDesc = "\uC2B5";
653 notEnglish.setDescription(notEnglishDesc);
656 bl.createResource(notEnglish, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
657 } catch (ComponentException e) {
658 assertComponentException(e, ActionStatus.COMPONENT_INVALID_DESCRIPTION,
659 ComponentTypeEnum.RESOURCE.getValue());
663 private void testResourceDescriptionEmpty() {
664 Resource resourceExist = createResourceObject(false);
665 resourceExist.setDescription("");
668 bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
669 } catch (ComponentException e) {
670 assertComponentException(e, ActionStatus.COMPONENT_MISSING_DESCRIPTION,
671 ComponentTypeEnum.RESOURCE.getValue());
675 private void testResourceDescriptionMissing() {
676 Resource resourceExist = createResourceObject(false);
677 resourceExist.setDescription(null);
680 bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
681 } catch (ComponentException e) {
682 assertComponentException(e, ActionStatus.COMPONENT_MISSING_DESCRIPTION,
683 ComponentTypeEnum.RESOURCE.getValue());
686 // Resource description - end
687 // Resource icon start
689 private void testResourceIconMissing() {
690 Resource resourceExist = createResourceObject(false);
691 resourceExist.setIcon(null);
692 when(toscaOperationFacade
693 .validateComponentNameAndModelExists(resourceExist.getName(), null, ResourceTypeEnum.VFC, ComponentTypeEnum.RESOURCE))
694 .thenReturn(Either.left(false));
696 bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
697 } catch (ComponentException e) {
698 assertComponentException(e, ActionStatus.COMPONENT_MISSING_ICON, ComponentTypeEnum.RESOURCE.getValue());
702 private void testResourceIconInvalid() {
703 Resource resourceExist = createResourceObject(false);
704 resourceExist.setIcon("kjk3453^&");
707 bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
708 } catch (ComponentException e) {
709 assertComponentException(e, ActionStatus.COMPONENT_INVALID_ICON, ComponentTypeEnum.RESOURCE.getValue());
713 private void testResourceIconExceedsLimit() {
714 Resource resourceExist = createResourceObject(false);
715 resourceExist.setIcon("dsjfhskdfhskjdhfskjdhkjdhfkshdfksjsdkfhsdfsdfsdfsfsdfsf");
717 bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
718 } catch (ComponentException e) {
719 assertComponentException(e, ActionStatus.COMPONENT_ICON_EXCEEDS_LIMIT,
720 ComponentTypeEnum.RESOURCE.getValue(), "" + ValidationUtils.ICON_MAX_LENGTH);
725 // Resource tags - start
726 private void testResourceTagNotExist() {
727 Resource resourceExist = createResourceObject(false);
728 resourceExist.setTags(null);
730 bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
731 } catch (ComponentException e) {
732 assertComponentException(e, ActionStatus.COMPONENT_MISSING_TAGS);
736 private void testResourceTagEmpty() {
737 Resource resourceExist = createResourceObject(false);
738 resourceExist.setTags(new ArrayList<>());
740 bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
741 } catch (ComponentException e) {
742 assertComponentException(e, ActionStatus.COMPONENT_MISSING_TAGS);
746 private void testTagsExceedsLimitCreate() {
747 Resource resourceExccedsNameLimit = createResourceObject(false);
748 String tag1 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjQ";
749 String tag2 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjW";
750 String tag3 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjE";
751 String tag4 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjb";
752 String tag5 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjr";
753 String tag6 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjf";
754 String tag7 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjg";
755 String tag8 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjd";
756 String tag9 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjf";
757 String tag10 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjg";
758 String tag11 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjh";
759 String tag12 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjj";
760 String tag13 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjk";
761 String tag14 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjs";
762 String tag15 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjz";
763 String tag16 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjx";
764 String tag17 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBj2";
765 String tag18 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBj3";
766 String tag19 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBj4";
767 String tag20 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBj5";
768 String tag21 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBj0";
770 List<String> tagsList = new ArrayList<>();
792 tagsList.add(resourceExccedsNameLimit.getName());
794 resourceExccedsNameLimit.setTags(tagsList);
796 bl.createResource(resourceExccedsNameLimit, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
797 } catch (ComponentException e) {
798 assertComponentException(e, ActionStatus.COMPONENT_TAGS_EXCEED_LIMIT,
799 "" + ValidationUtils.TAG_LIST_MAX_LENGTH);
803 private void testTagsSingleExceedsLimit() {
804 Resource resourceExccedsNameLimit = createResourceObject(false);
805 String tag1 = "afzs2qLBb5X6tZhiunkcEwiFX1qRQY8YZl3y3Du5M5xeQY5Nq9afcFHDZ9HaURw43gH27nAUWM36bMbMylwTFSzzNV8NO4v4ripe6Q15Vc2nPOFI";
806 String tag2 = resourceExccedsNameLimit.getName();
807 List<String> tagsList = new ArrayList<>();
811 resourceExccedsNameLimit.setTags(tagsList);
813 bl.createResource(resourceExccedsNameLimit, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
814 } catch (ComponentException e) {
815 assertComponentException(e, ActionStatus.COMPONENT_SINGLE_TAG_EXCEED_LIMIT,
816 "" + ValidationUtils.TAG_MAX_LENGTH);
820 private void testTagsNoServiceName() {
821 Resource serviceExccedsNameLimit = createResourceObject(false);
822 String tag1 = "afzs2qLBb";
823 List<String> tagsList = new ArrayList<>();
825 serviceExccedsNameLimit.setTags(tagsList);
827 bl.createResource(serviceExccedsNameLimit, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
828 } catch (ComponentException e) {
829 assertComponentException(e, ActionStatus.COMPONENT_INVALID_TAGS_NO_COMP_NAME);
833 private void testInvalidTag() {
834 Resource serviceExccedsNameLimit = createResourceObject(false);
835 String tag1 = "afzs2qLBb%#%";
836 List<String> tagsList = new ArrayList<>();
838 serviceExccedsNameLimit.setTags(tagsList);
840 bl.createResource(serviceExccedsNameLimit, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
841 } catch (ComponentException e) {
842 assertComponentException(e, ActionStatus.INVALID_FIELD_FORMAT, new String[] { "Resource", "tag" });
846 // Resource tags - stop
847 // Resource contact start
849 private void testContactIdTooLong() {
850 Resource resourceContactId = createResourceObject(false);
851 // 59 chars instead of 50
852 String contactIdTooLong = "thisNameIsVeryLongAndExeccedsTheNormalLengthForContactId";
853 resourceContactId.setContactId(contactIdTooLong);
856 bl.createResource(resourceContactId, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
857 } catch (ComponentException e) {
858 assertComponentException(e, ActionStatus.COMPONENT_INVALID_CONTACT, ComponentTypeEnum.RESOURCE.getValue());
862 private void testContactIdWrongFormatCreate() {
863 Resource resourceContactId = createResourceObject(false);
864 // 3 letters and 3 digits and special characters
865 String contactIdFormatWrong = "yrt134!!!";
866 resourceContactId.setContactId(contactIdFormatWrong);
868 bl.createResource(resourceContactId, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
869 } catch (ComponentException e) {
870 assertComponentException(e, ActionStatus.COMPONENT_INVALID_CONTACT, ComponentTypeEnum.RESOURCE.getValue());
874 private void testResourceContactIdEmpty() {
875 Resource resourceExist = createResourceObject(false);
876 resourceExist.setContactId("");
878 bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
879 } catch (ComponentException e) {
880 assertComponentException(e, ActionStatus.COMPONENT_MISSING_CONTACT, ComponentTypeEnum.RESOURCE.getValue());
884 private void testResourceContactIdMissing() {
885 Resource resourceExist = createResourceObject(false);
886 resourceExist.setContactId(null);
888 bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
889 } catch (ComponentException e) {
890 assertComponentException(e, ActionStatus.COMPONENT_MISSING_CONTACT, ComponentTypeEnum.RESOURCE.getValue());
894 private void testVendorNameExceedsLimit() {
895 Resource resourceExccedsVendorNameLimit = createResourceObject(false);
896 String tooLongVendorName = "h1KSyJh9Eh1KSyJh9Eh1KSyJh9Eh1KSyJh9Eh1KSyJh9Eh1KSyJh9Eh1KSyJh9Eh1KSyJh9E";
897 resourceExccedsVendorNameLimit.setVendorName(tooLongVendorName);
899 bl.createResource(resourceExccedsVendorNameLimit, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
900 } catch (ComponentException e) {
901 assertComponentException(e, ActionStatus.VENDOR_NAME_EXCEEDS_LIMIT,
902 "" + ValidationUtils.VENDOR_NAME_MAX_LENGTH);
906 private void testResourceVendorModelNumberExceedsLimit() {
907 Resource resourceExccedsVendorModelNumberLimit = createResourceObject(false);
908 String tooLongVendorModelNumber = "h1KSyJh9Eh1KSyJh9Eh1KSyJh9Eh1KSyJh9Eh1KSyJh9Eh1KSyJh9Eh1KSyJh9Eh1KSyJh9E";
909 resourceExccedsVendorModelNumberLimit.setResourceVendorModelNumber(tooLongVendorModelNumber);
911 bl.createResource(resourceExccedsVendorModelNumberLimit, AuditingActionEnum.CREATE_RESOURCE, user, null,
913 } catch (ComponentException e) {
914 assertComponentException(e, ActionStatus.RESOURCE_VENDOR_MODEL_NUMBER_EXCEEDS_LIMIT,
915 "" + ValidationUtils.RESOURCE_VENDOR_MODEL_NUMBER_MAX_LENGTH);
919 private void testVendorNameWrongFormatCreate() {
920 Resource resource = createResourceObject(false);
922 String nameWrongFormat = "ljg*fd";
923 resource.setVendorName(nameWrongFormat);
925 bl.createResource(resource, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
926 } catch (ComponentException e) {
927 assertComponentException(e, ActionStatus.INVALID_VENDOR_NAME, nameWrongFormat);
931 private void testVendorReleaseWrongFormat() {
932 Resource resource = createResourceObject(false);
934 String vendorReleaseWrongFormat = "1>2";
935 resource.setVendorRelease(vendorReleaseWrongFormat);
937 bl.createResource(resource, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
938 } catch (ComponentException e) {
939 assertComponentException(e, ActionStatus.INVALID_VENDOR_RELEASE, vendorReleaseWrongFormat);
943 private void testVendorReleaseExceedsLimitCreate() {
944 Resource resourceExccedsNameLimit = createResourceObject(false);
945 String tooLongVendorRelease = "h1KSyJh9Eh1KSyJh9Eh1KSyJh9Eh1KSyJh9E";
946 resourceExccedsNameLimit.setVendorRelease(tooLongVendorRelease);
948 bl.createResource(resourceExccedsNameLimit, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
949 } catch (ComponentException e) {
950 assertComponentException(e, ActionStatus.VENDOR_RELEASE_EXCEEDS_LIMIT,
951 "" + ValidationUtils.VENDOR_RELEASE_MAX_LENGTH);
955 private void testResourceVendorNameMissing() {
956 Resource resourceExist = createResourceObject(false);
957 resourceExist.setVendorName(null);
959 bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
960 } catch (ComponentException e) {
961 assertComponentException(e, ActionStatus.MISSING_VENDOR_NAME);
965 private void testResourceVendorReleaseMissing() {
966 Resource resourceExist = createResourceObject(false);
967 resourceExist.setVendorRelease(null);
969 bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
970 } catch (ComponentException e) {
971 assertComponentException(e, ActionStatus.MISSING_VENDOR_RELEASE);
975 // Resource vendor name/release stop
977 private void testResourceCategoryExist() {
978 Resource resourceExist = createResourceObject(false);
979 resourceExist.setCategories(null);
981 bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
982 } catch (ComponentException e) {
983 assertComponentException(e, ActionStatus.COMPONENT_MISSING_CATEGORY, ComponentTypeEnum.RESOURCE.getValue());
987 private void testResourceBadCategoryCreate() {
989 Resource resourceExist = createResourceObject(false);
990 resourceExist.setCategories(null);
991 resourceExist.addCategory("koko", "koko");
993 bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
994 } catch (ComponentException e) {
995 assertComponentException(e, ActionStatus.COMPONENT_INVALID_CATEGORY, ComponentTypeEnum.RESOURCE.getValue());
1001 private void testHappyScenarioCostLicenseType() {
1002 Resource createResourceObject = createResourceObject(false);
1003 Resource createResourceObjectAfterCreate = createResourceObject(true);
1004 // Adding cost and licenseType to basic mock
1005 Either<Resource, StorageOperationStatus> eitherCreate = Either.left(createResourceObjectAfterCreate);
1006 when(toscaOperationFacade.createToscaComponent(any(Resource.class))).thenReturn(eitherCreate);
1008 String cost = "123.456";
1009 String licenseType = "User";
1010 createResourceObject.setCost(cost);
1011 createResourceObject.setLicenseType(licenseType);
1012 Resource createdResource;
1014 createdResource = bl.createResource(createResourceObject, AuditingActionEnum.CREATE_RESOURCE, user, null,
1016 createResourceObjectAfterCreate.setCost(cost);
1017 createResourceObjectAfterCreate.setLicenseType(licenseType);
1018 assertThat(createResourceObjectAfterCreate).isEqualTo(createdResource);
1019 } catch (ComponentException e) {
1020 assertThat(new Integer(200)).isEqualTo(e.getResponseFormat()
1025 private void testCostWrongFormatCreate() {
1026 Resource resourceCost = createResourceObject(false);
1027 // Comma instead of fullstop
1028 String cost = "12356,464";
1029 resourceCost.setCost(cost);
1031 bl.createResource(resourceCost, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
1032 } catch (ComponentException e) {
1033 assertComponentException(e, ActionStatus.INVALID_CONTENT);
1038 // License type start
1039 private void testLicenseTypeWrongFormatCreate() {
1040 Resource resourceLicenseType = createResourceObject(false);
1042 String licenseType = "cpu";
1043 resourceLicenseType.setLicenseType(licenseType);
1045 bl.createResource(resourceLicenseType, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
1046 } catch (ComponentException e) {
1047 assertComponentException(e, ActionStatus.INVALID_CONTENT);
1051 // License type stop
1052 // Derived from start
1053 private void testResourceTemplateNotExist() {
1054 Resource resourceExist = createResourceObject(false);
1055 List<String> list = null;
1056 resourceExist.setDerivedFrom(list);
1058 bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
1059 } catch (ComponentException e) {
1060 assertComponentException(e, ActionStatus.MISSING_DERIVED_FROM_TEMPLATE);
1064 private void testResourceTemplateEmpty() {
1065 Resource resourceExist = createResourceObject(false);
1066 resourceExist.setDerivedFrom(new ArrayList<>());
1068 bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
1069 } catch (ComponentException e) {
1070 assertComponentException(e, ActionStatus.MISSING_DERIVED_FROM_TEMPLATE);
1074 private void testResourceTemplateInvalid() {
1075 Resource resourceExist = createResourceObject(false);
1076 ArrayList<String> derivedFrom = new ArrayList<>();
1077 derivedFrom.add("kuku");
1078 resourceExist.setDerivedFrom(derivedFrom);
1080 bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
1081 } catch (ComponentException e) {
1082 assertComponentException(e, ActionStatus.PARENT_RESOURCE_NOT_FOUND);
1086 // Derived from stop
1087 private void assertComponentException(ComponentException e, ActionStatus expectedStatus, String... variables) {
1088 ResponseFormat actualResponse = e.getResponseFormat() != null ? e.getResponseFormat()
1089 : componentsUtils.getResponseFormat(e.getActionStatus(), e.getParams());
1090 assertResponse(actualResponse, expectedStatus, variables);
1093 private void assertResponse(ResponseFormat actualResponse, ActionStatus expectedStatus, String... variables) {
1094 ResponseFormat expectedResponse = responseManager.getResponseFormat(expectedStatus, variables);
1095 assertThat(expectedResponse.getStatus()).isEqualTo(actualResponse.getStatus());
1096 assertThat(expectedResponse.getFormattedMessage()).isEqualTo(actualResponse.getFormattedMessage());
1099 private void assertResponse(Either<Resource, ResponseFormat> createResponse, ActionStatus expectedStatus,
1100 String... variables) {
1101 assertResponse(createResponse.right()
1102 .value(), expectedStatus, variables);
1105 // UPDATE tests - start
1108 public void testResourceNameWrongFormat_UPDATE() {
1109 Resource resource = createResourceObject(true);
1110 Resource updatedResource = createResourceObject(true);
1112 // this is in order to prevent failing with 403 earlier
1113 Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
1114 when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
1116 String nameWrongFormat = "ljg*fd";
1117 updatedResource.setName(nameWrongFormat);
1119 Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
1120 when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
1122 bl.updateResourceMetadata(resource.getUniqueId(), updatedResource, null, user, false);
1123 } catch (ComponentException e) {
1124 assertComponentException(e, ActionStatus.INVALID_COMPONENT_NAME, ComponentTypeEnum.RESOURCE.getValue());
1129 public void testResourceNameAfterCertify_UPDATE() {
1130 Resource resource = createResourceObject(true);
1131 Resource updatedResource = createResourceObject(true);
1133 // this is in order to prevent failing with 403 earlier
1134 Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
1135 // when(resourceOperation.getResource_tx(resource.getUniqueId(),false)).thenReturn(eitherUpdate);
1136 when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
1138 String name = "ljg";
1139 updatedResource.setName(name);
1140 resource.setVersion("1.0");
1142 Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
1143 when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
1145 bl.updateResourceMetadata(resource.getUniqueId(), updatedResource, null, user, false);
1146 } catch (ComponentException e) {
1147 assertComponentException(e, ActionStatus.RESOURCE_NAME_CANNOT_BE_CHANGED);
1152 public void testResourceNameAlreadyExist_UPDATE() {
1153 Resource resource = createResourceObject(true);
1154 Resource updatedResource = createResourceObject(true);
1156 // this is in order to prevent failing with 403 earlier
1157 Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
1158 when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
1160 String resourceName = "alreadyExists";
1161 updatedResource.setName(resourceName);
1162 Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(updatedResource);
1163 when(toscaOperationFacade.updateToscaElement(updatedResource)).thenReturn(dataModelResponse);
1165 bl.updateResourceMetadata(resource.getUniqueId(), updatedResource, null, user, false);
1166 } catch (ComponentException e) {
1167 assertComponentException(e, ActionStatus.COMPONENT_NAME_ALREADY_EXIST,
1168 ComponentTypeEnum.RESOURCE.getValue(), resourceName);
1175 public void testResourceDescExceedsLimit_UPDATE() {
1176 Resource resource = createResourceObject(true);
1177 Resource updatedResource = createResourceObject(true);
1179 // this is in order to prevent failing with 403 earlier
1180 Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
1181 when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
1183 // 1025 chars, the limit is 1024
1184 String tooLongResourceDesc = "1GUODojQ0sGzKR4NP7e5j82ADQ3KHTVOaezL95qcbuaqDtjZhAQGQ3iFwKAy580K4WiiXs3u3zq7RzXcSASl5fm0RsWtCMOIDP"
1185 + "AOf9Tf2xtXxPCuCIMCR5wOGnNTaFxgnJEHAGxilBhZDgeMNHmCN1rMK5B5IRJOnZxcpcL1NeG3APTCIMP1lNAxngYulDm9heFSBc8TfXAADq7703AvkJT0QPpGq2z2P"
1186 + "tlikcAnIjmWgfC5Tm7UH462BAlTyHg4ExnPPL4AO8c92VrD7kZSgSqiy73cN3gLT8uigkKrUgXQFGVUFrXVyyQXYtVM6bLBeuCGQf4C2j8lkNg6M0J3PC0PzMRoinOxk"
1187 + "Ae2teeCtVcIj4A1KQo3210j8q2v7qQU69Mabsa6DT9FgE4rcrbiFWrg0Zto4SXWD3o1eJA9o29lTg6kxtklH3TuZTmpi5KVp1NFhS1RpnqF83tzv4mZLKsx7Zh1fEgYvRFwx1"
1188 + "ar3RolyDfNoZiGBGTMsZzz7RPFBf2hTnLmNqVGQnHKhhGj0Y5s8t2cbqbO2nmHiJb9uaUVrCGypgbAcJL3KPOBfAVW8PcpmNj4yVjI3L4x5zHjmGZbp9vKshEQODcrmcgsYAoKqe"
1189 + "uu5u7jk8XVxEfQ0m5qL8UOErXPlJovSmKUmP5B5T0w299zIWDYCzSoNasHpHjOMDLAiDDeHbozUOn9t3Qou00e9POq4RMM0VnIx1H38nJoJZz2XH8CI5YMQe7oTagaxgQTF2aa0qaq2"
1190 + "V6nJsfRGRklGjNhFFYP2cS4Xv2IJO9DSX6LTXOmENrGVJJvMOZcvnBaZPfoAHN0LU4i1SoepLzulIxnZBfkUWFJgZ5wQ0Bco2GC1HMqzW21rwy4XHRxXpXbmW8LVyoA1KbnmVmROycU4"
1191 + "scTZ62IxIcIWCVeMjBIcTviXULbPUyqlfEPXWr8IMJtpAaELWgyquPClAREMDs2b9ztKmUeXlMccFES1XWbFTrhBHhmmDyVReEgCwfokrUFR13LTUK1k8I6OEHOs";
1192 updatedResource.setDescription(tooLongResourceDesc);
1193 Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
1194 when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
1196 bl.updateResourceMetadata(resource.getUniqueId(), updatedResource, null, user, false);
1197 } catch (ComponentException e) {
1198 assertComponentException(e, ActionStatus.COMPONENT_DESCRIPTION_EXCEEDS_LIMIT,
1199 ComponentTypeEnum.RESOURCE.getValue(), "" + ValidationUtils.COMPONENT_DESCRIPTION_MAX_LENGTH);
1204 public void testIconWrongFormat_UPDATE() {
1205 Resource resource = createResourceObject(true);
1206 Resource updatedResource = createResourceObject(true);
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);
1213 String icon = "icon.jpg";
1214 updatedResource.setIcon(icon);
1215 Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
1216 when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
1218 bl.updateResourceMetadata(resource.getUniqueId(), updatedResource, null, user, false);
1219 } catch (ComponentException e) {
1220 assertComponentException(e, ActionStatus.COMPONENT_INVALID_ICON, ComponentTypeEnum.RESOURCE.getValue());
1225 public void testIconAfterCertify_UPDATE() {
1226 Resource resource = createResourceObject(true);
1227 Resource updatedResource = createResourceObject(true);
1229 // this is in order to prevent failing with 403 earlier
1230 Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
1231 when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
1234 String icon = "icon";
1235 updatedResource.setIcon(icon);
1237 resource.setVersion("1.0");
1239 Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
1240 when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
1242 bl.updateResourceMetadata(resource.getUniqueId(), updatedResource, null, user, false);
1243 } catch (ComponentException e) {
1244 assertComponentException(e, ActionStatus.RESOURCE_ICON_CANNOT_BE_CHANGED);
1249 public void testTagsExceedsLimit_UPDATE() {
1250 Resource resource = createResourceObject(true);
1251 Resource updatedResource = createResourceObject(true);
1253 // this is in order to prevent failing with 403 earlier
1254 Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
1255 when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
1257 String tag1 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjQ";
1258 String tag2 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjW";
1259 String tag3 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjE";
1260 String tag4 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjb";
1261 String tag5 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjr";
1262 String tag6 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjf";
1263 String tag7 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjg";
1264 String tag8 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjd";
1265 String tag9 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjf";
1266 String tag10 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjg";
1267 String tag11 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjh";
1268 String tag12 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjj";
1269 String tag13 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjk";
1270 String tag14 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjs";
1271 String tag15 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjz";
1272 String tag16 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjx";
1273 String tag17 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBj2";
1274 String tag18 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBj3";
1275 String tag19 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBj4";
1276 String tag20 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBj5";
1277 String tag21 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBj0";
1279 List<String> tagsList = new ArrayList<>();
1289 tagsList.add(tag10);
1290 tagsList.add(tag11);
1291 tagsList.add(tag12);
1292 tagsList.add(tag13);
1293 tagsList.add(tag14);
1294 tagsList.add(tag15);
1295 tagsList.add(tag16);
1296 tagsList.add(tag17);
1297 tagsList.add(tag18);
1298 tagsList.add(tag19);
1299 tagsList.add(tag20);
1300 tagsList.add(tag21);
1301 tagsList.add(resource.getName());
1303 updatedResource.setTags(tagsList);
1304 Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
1305 when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
1307 bl.updateResourceMetadata(resource.getUniqueId(), updatedResource, null, user, false);
1308 } catch (ComponentException e) {
1309 assertComponentException(e, ActionStatus.COMPONENT_TAGS_EXCEED_LIMIT,
1310 "" + ValidationUtils.TAG_LIST_MAX_LENGTH);
1315 public void testVendorNameWrongFormat_UPDATE() {
1316 Resource resource = createResourceObject(true);
1317 Resource updatedResource = createResourceObject(true);
1319 // this is in order to prevent failing with 403 earlier
1320 Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
1321 when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
1324 String nameWrongFormat = "ljg*fd";
1325 updatedResource.setVendorName(nameWrongFormat);
1326 Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
1327 when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
1329 bl.updateResourceMetadata(resource.getUniqueId(), updatedResource, null, user, false);
1330 } catch (ComponentException e) {
1331 assertComponentException(e, ActionStatus.INVALID_VENDOR_NAME, nameWrongFormat);
1336 public void testVendorNameWrongFormat() {
1337 Resource resource = createResourceObject(true);
1338 Resource updatedResource = createResourceObject(true);
1340 // this is in order to prevent failing with 403 earlier
1341 Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
1342 when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
1345 String nameWrongFormat = "ljg*fd";
1346 updatedResource.setVendorName(nameWrongFormat);
1347 resource.setVersion("1.0");
1349 Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
1350 when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
1352 bl.updateResourceMetadata(resource.getUniqueId(), updatedResource, null, user, false);
1353 } catch (ComponentException e) {
1354 assertComponentException(e, ActionStatus.INVALID_VENDOR_NAME, nameWrongFormat);
1359 public void testVendorReleaseExceedsLimit_UPDATE() {
1360 Resource resource = createResourceObject(true);
1361 Resource updatedResource = createResourceObject(true);
1363 // this is in order to prevent failing with 403 earlier
1364 Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
1365 when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
1366 // 129 chars, the limit is 128
1367 String tooLongVendorRelease = "h1KSyJh9EspI8SPwAGu4VETfqWejeanuB1PCJBxJmJncYnrW0lnsEFFVRIukRJkwlOVnZCy8p38tjhANeZq3BGMHIawWR6ICl8Wi9mikRYALWgvJug00JrlQ0iPVKPLxy";
1368 updatedResource.setVendorRelease(tooLongVendorRelease);
1369 Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
1370 when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
1372 bl.updateResourceMetadata(resource.getUniqueId(), updatedResource, null, user, false);
1373 } catch (ComponentException e) {
1374 assertComponentException(e, ActionStatus.VENDOR_RELEASE_EXCEEDS_LIMIT,
1375 "" + ValidationUtils.VENDOR_RELEASE_MAX_LENGTH);
1380 public void testResourceBadCategory_UPDATE() {
1381 Resource resource = createResourceObject(true);
1382 Resource updatedResource = createResourceObject(true);
1384 // this is in order to prevent failing with 403 earlier
1385 Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
1386 when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
1388 String resourceId = resource.getUniqueId();
1389 String badCategory = "ddfds";
1390 updatedResource.setCategories(null);
1391 updatedResource.addCategory(badCategory, "fikt");
1392 Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
1393 when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
1395 bl.updateResourceMetadata(resourceId, updatedResource, null, user, false);
1396 } catch (ComponentException e) {
1397 assertComponentException(e, ActionStatus.COMPONENT_INVALID_CATEGORY, ComponentTypeEnum.RESOURCE.getValue());
1401 @Test(expected = ComponentException.class)
1402 public void createResourceFromCsarTest() {
1403 bl.createResourceFromCsar(resourceResponse, user, new HashMap<>(), "");
1407 public void testResourceCategoryAfterCertify_UPDATE() {
1408 Resource resource = createResourceObject(true);
1409 Resource updatedResource = createResourceObject(true);
1411 // this is in order to prevent failing with 403 earlier
1412 Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
1413 when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
1415 String resourceId = resource.getUniqueId();
1416 updatedResource.setCategories(null);
1417 updatedResource.addCategory(RESOURCE_CATEGORY1, UPDATED_SUBCATEGORY);
1418 resource.setVersion("1.0");
1420 Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
1421 when(toscaOperationFacade.updateToscaElement(updatedResource)).thenReturn(dataModelResponse);
1423 bl.updateResourceMetadata(resourceId, updatedResource, null, user, false);
1424 } catch (ComponentException e) {
1425 assertComponentException(e, ActionStatus.RESOURCE_CATEGORY_CANNOT_BE_CHANGED);
1429 // Derived from start
1431 public void testResourceTemplateNotExist_UPDATE() {
1432 Resource resource = createResourceObject(true);
1433 Resource updatedResource = createResourceObject(true);
1435 // this is in order to prevent failing with 403 earlier
1436 Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
1437 when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
1438 String resourceId = resource.getUniqueId();
1440 List<String> list = null;
1441 updatedResource.setDerivedFrom(list);
1442 Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
1443 when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
1445 bl.updateResourceMetadata(resourceId, updatedResource, null, user, false);
1446 } catch (ComponentException e) {
1447 assertComponentException(e, ActionStatus.MISSING_DERIVED_FROM_TEMPLATE);
1452 public void testResourceTemplateEmpty_UPDATE() {
1453 Resource resource = createResourceObject(true);
1454 Resource updatedResource = createResourceObject(true);
1455 String resourceId = resource.getUniqueId();
1457 // this is in order to prevent failing with 403 earlier
1458 Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
1459 when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
1461 updatedResource.setDerivedFrom(new ArrayList<>());
1462 Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
1463 when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
1465 bl.updateResourceMetadata(resourceId, updatedResource, null, user, false);
1466 } catch (ComponentException e) {
1467 assertComponentException(e, ActionStatus.MISSING_DERIVED_FROM_TEMPLATE);
1472 public void testResourceTemplateInvalid_UPDATE() {
1473 Resource resource = createResourceObject(true);
1474 Resource updatedResource = createResourceObject(true);
1475 String resourceId = resource.getUniqueId();
1477 // this is in order to prevent failing with 403 earlier
1478 Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
1479 when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
1481 ArrayList<String> derivedFrom = new ArrayList<>();
1482 derivedFrom.add("kuku");
1483 updatedResource.setDerivedFrom(derivedFrom);
1484 Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
1485 when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
1487 bl.updateResourceMetadata(resourceId, updatedResource, null, user, false);
1488 } catch (ComponentException e) {
1489 assertComponentException(e, ActionStatus.PARENT_RESOURCE_NOT_FOUND);
1494 public void testResourceTemplateCertify_UPDATE_HAPPY() {
1495 Resource resource = createResourceObject(true);
1496 Resource updatedResource = createResourceObject(true);
1497 String resourceId = resource.getUniqueId();
1499 // this is in order to prevent failing with 403 earlier
1500 Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
1501 when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
1503 Either<Boolean, StorageOperationStatus> isToscaNameExtending = Either.left(true);
1504 when(toscaOperationFacade.validateToscaResourceNameExtends(anyString(), anyString()))
1505 .thenReturn(isToscaNameExtending);
1507 Either<Map<String, PropertyDefinition>, StorageOperationStatus> findPropertiesOfNode = Either
1508 .left(new HashMap<>());
1509 when(propertyOperation.deleteAllPropertiesAssociatedToNode(any(NodeTypeEnum.class), anyString()))
1510 .thenReturn(findPropertiesOfNode);
1512 resource.setVersion("1.0");
1514 ArrayList<String> derivedFrom = new ArrayList<>();
1515 derivedFrom.add("tosca.nodes.Root");
1516 updatedResource.setDerivedFrom(derivedFrom);
1517 Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(updatedResource);
1518 when(toscaOperationFacade.updateToscaElement(updatedResource)).thenReturn(dataModelResponse);
1519 Resource createdResource = bl.updateResourceMetadata(resourceId, updatedResource, null, user, false);
1520 assertThat(createdResource).isNotNull();
1524 public void testResourceTemplateCertify_UPDATE_SAD() {
1525 Resource resource = createResourceObject(true);
1526 Resource updatedResource = createResourceObject(true);
1527 String resourceId = resource.getUniqueId();
1529 // this is in order to prevent failing with 403 earlier
1530 Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
1531 when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
1533 Either<Boolean, StorageOperationStatus> isToscaNameExtending = Either.left(false);
1534 when(toscaOperationFacade.validateToscaResourceNameExtends(anyString(), anyString()))
1535 .thenReturn(isToscaNameExtending);
1537 resource.setVersion("1.0");
1539 ArrayList<String> derivedFrom = new ArrayList<>();
1540 derivedFrom.add("tosca.nodes.Root");
1541 updatedResource.setDerivedFrom(derivedFrom);
1542 Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
1543 when(toscaOperationFacade.updateToscaElement(updatedResource)).thenReturn(dataModelResponse);
1544 Either<Map<String, PropertyDefinition>, StorageOperationStatus> findPropertiesOfNode = Either
1545 .left(new HashMap<>());
1546 when(propertyOperation.deleteAllPropertiesAssociatedToNode(any(NodeTypeEnum.class), anyString()))
1547 .thenReturn(findPropertiesOfNode);
1550 bl.updateResourceMetadata(resourceId, updatedResource, null, user, false);
1551 } catch (ComponentException e) {
1552 assertComponentException(e, ActionStatus.PARENT_RESOURCE_DOES_NOT_EXTEND);
1555 // Derived from stop
1558 public void createOrUpdateResourceAlreadyCheckout() {
1560 Resource resourceExist = createResourceObject(false);
1561 validateUserRoles(Role.ADMIN, Role.DESIGNER);
1562 when(toscaOperationFacade
1563 .validateComponentNameAndModelExists(resourceExist.getName(), null, ResourceTypeEnum.VFC, ComponentTypeEnum.RESOURCE))
1564 .thenReturn(Either.left(false));
1565 Resource createdResource = bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null,
1567 createdResource.setLastUpdaterUserId(user.getUserId());
1568 assertThat(createdResource).isNotNull();
1569 Either<Resource, StorageOperationStatus> getLatestResult = Either.left(createdResource);
1570 Either<Component, StorageOperationStatus> getCompLatestResult = Either.left(createdResource);
1571 when(toscaOperationFacade.getLatestByToscaResourceName(resourceExist.getToscaResourceName()))
1572 .thenReturn(getCompLatestResult);
1573 when(toscaOperationFacade.getLatestByToscaResourceNameAndModel(resourceExist.getToscaResourceName(), null))
1574 .thenReturn(getCompLatestResult);
1575 when(toscaOperationFacade.overrideComponent(any(Resource.class), any(Resource.class)))
1576 .thenReturn(getLatestResult);
1578 Resource resourceToUpdtae = createResourceObject(false);
1580 ImmutablePair<Resource, ActionStatus> createOrUpdateResource = bl
1581 .createOrUpdateResourceByImport(resourceToUpdtae, user, false, false, false, null, null, false);
1582 assertNotNull(createOrUpdateResource);
1584 Mockito.verify(toscaOperationFacade, Mockito.times(1))
1585 .overrideComponent(any(Resource.class), any(Resource.class));
1586 Mockito.verify(lifecycleBl, Mockito.times(0))
1587 .changeState(anyString(), eq(user), eq(LifeCycleTransitionEnum.CHECKOUT),
1588 any(LifecycleChangeInfoWithAction.class), Mockito.anyBoolean(), Mockito.anyBoolean());
1593 public void createOrUpdateResourceCertified() {
1595 Resource resourceExist = createResourceObject(false);
1596 when(toscaOperationFacade
1597 .validateComponentNameAndModelExists(resourceExist.getName(), null, ResourceTypeEnum.VFC, ComponentTypeEnum.RESOURCE))
1598 .thenReturn(Either.left(false));
1599 validateUserRoles(Role.ADMIN, Role.DESIGNER);
1600 Resource createdResource = bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null,
1603 assertThat(createdResource).isNotNull();
1604 createdResource.setLifecycleState(LifecycleStateEnum.CERTIFIED);
1605 createdResource.setVersion("1.0");
1607 Either<Resource, StorageOperationStatus> getLatestResult = Either.left(createdResource);
1608 Either<Component, StorageOperationStatus> getCompLatestResult = Either.left(createdResource);
1609 when(toscaOperationFacade.getLatestByToscaResourceNameAndModel(resourceExist.getToscaResourceName(), null))
1610 .thenReturn(getCompLatestResult);
1611 when(toscaOperationFacade.overrideComponent(any(Resource.class), any(Resource.class)))
1612 .thenReturn(getLatestResult);
1614 when(lifecycleBl.changeState(anyString(), eq(user), eq(LifeCycleTransitionEnum.CHECKOUT),
1615 any(LifecycleChangeInfoWithAction.class), Mockito.anyBoolean(), Mockito.anyBoolean()))
1616 .thenReturn(Either.left(createdResource));
1618 Resource resourceToUpdtae = createResourceObject(false);
1620 ImmutablePair<Resource, ActionStatus> createOrUpdateResource = bl
1621 .createOrUpdateResourceByImport(resourceToUpdtae, user, false, false, false, null, null, false);
1622 assertNotNull(createOrUpdateResource);
1624 Mockito.verify(toscaOperationFacade, Mockito.times(1))
1625 .overrideComponent(any(Resource.class), any(Resource.class));
1626 Mockito.verify(lifecycleBl, Mockito.times(1))
1627 .changeState(anyString(), eq(user), eq(LifeCycleTransitionEnum.CHECKOUT),
1628 any(LifecycleChangeInfoWithAction.class), Mockito.anyBoolean(), Mockito.anyBoolean());
1633 public void createOrUpdateResourceNotExist() {
1634 Resource resourceToUpdtae = createResourceObject(false);
1636 Either<Component, StorageOperationStatus> getLatestResult = Either.right(StorageOperationStatus.NOT_FOUND);
1637 when(toscaOperationFacade.getLatestByName(resourceToUpdtae.getName(), null)).thenReturn(getLatestResult);
1638 when(toscaOperationFacade.getLatestByToscaResourceNameAndModel(resourceToUpdtae.getToscaResourceName(), null))
1639 .thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
1640 when(toscaOperationFacade
1641 .validateComponentNameAndModelExists(resourceToUpdtae.getName(), null, ResourceTypeEnum.VFC, ComponentTypeEnum.RESOURCE))
1642 .thenReturn(Either.left(false));
1644 ImmutablePair<Resource, ActionStatus> createOrUpdateResource = bl
1645 .createOrUpdateResourceByImport(resourceToUpdtae, user, false, false, false, null, null, false);
1646 assertThat(createOrUpdateResource).isNotNull();
1648 Mockito.verify(toscaOperationFacade, times(1))
1649 .createToscaComponent(resourceToUpdtae);
1650 Mockito.verify(toscaOperationFacade, Mockito.times(0))
1651 .overrideComponent(any(Resource.class), any(Resource.class));
1652 Mockito.verify(lifecycleBl, Mockito.times(0))
1653 .changeState(anyString(), eq(user), eq(LifeCycleTransitionEnum.CHECKOUT),
1654 any(LifecycleChangeInfoWithAction.class), Mockito.anyBoolean(), Mockito.anyBoolean());
1659 public void testIfNodeTypeNameHasValidPrefix() {
1660 final List<String> definedNodeTypeNamespaceList = ConfigurationManager.getConfigurationManager()
1661 .getConfiguration().getDefinedResourceNamespace();
1663 definedNodeTypeNamespaceList.parallelStream().forEach(validNodeTypePrefix -> {
1664 final String nodeName = validNodeTypePrefix + "." + "abc";
1665 final Optional<String> result = bl.validateNodeTypeNamePrefix(nodeName, definedNodeTypeNamespaceList);
1666 assertTrue(result.isPresent());
1671 public void updateNestedResource_typeIsNew() throws IOException {
1672 Resource resourceToUpdate = createResourceObject(false);
1673 String nodeName = Constants.USER_DEFINED_RESOURCE_NAMESPACE_PREFIX + "." + "abc";
1674 String jsonContent = ImportUtilsTest.loadFileNameToJsonString("normative-types-new-webServer.yml");
1675 CsarInfo csarInfo = new CsarInfo(user, "abcd1234", new HashMap<>(), RESOURCE_NAME, "template name", jsonContent,
1677 String nestedResourceName = bl.buildNestedToscaResourceName(resourceToUpdate.getResourceType()
1678 .name(), csarInfo.getVfResourceName(), nodeName)
1680 when(toscaOperationFacade.getLatestByName(resourceToUpdate.getName(), null))
1681 .thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
1682 when(toscaOperationFacade.getLatestByToscaResourceName(resourceToUpdate.getToscaResourceName()))
1683 .thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
1684 when(toscaOperationFacade.getLatestByToscaResourceName(nestedResourceName))
1685 .thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
1687 when(toscaOperationFacade.getLatestByToscaResourceNameAndModel(resourceToUpdate.getToscaResourceName(), null))
1688 .thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
1689 when(toscaOperationFacade
1690 .validateComponentNameAndModelExists(resourceToUpdate.getName(), null, ResourceTypeEnum.VFC, ComponentTypeEnum.RESOURCE))
1691 .thenReturn(Either.left(false));
1693 ImmutablePair<Resource, ActionStatus> createOrUpdateResource = bl
1694 .createOrUpdateResourceByImport(resourceToUpdate, user, false, false, false, csarInfo, nodeName, false);
1695 assertThat(createOrUpdateResource).isNotNull();
1697 Mockito.verify(toscaOperationFacade, times(1))
1698 .createToscaComponent(resourceToUpdate);
1699 Mockito.verify(toscaOperationFacade, times(0))
1700 .overrideComponent(any(Resource.class), any(Resource.class));
1701 Mockito.verify(lifecycleBl, times(0))
1702 .changeState(anyString(), eq(user), eq(LifeCycleTransitionEnum.CHECKOUT),
1703 any(LifecycleChangeInfoWithAction.class), Mockito.anyBoolean(), Mockito.anyBoolean());
1707 public void updateNestedResource_typeExists() throws IOException {
1709 Resource resourceToUpdate = createResourceObject(false);
1710 setCanWorkOnResource(resourceResponse);
1711 String nodeName = Constants.USER_DEFINED_RESOURCE_NAMESPACE_PREFIX + "." + "abc";
1712 String jsonContent = ImportUtilsTest.loadFileNameToJsonString("normative-types-new-webServer.yml");
1713 CsarInfo csarInfo = new CsarInfo(user, "abcd1234", new HashMap<>(), RESOURCE_NAME, "template name", jsonContent,
1715 String nestedResourceName = bl.buildNestedToscaResourceName(resourceToUpdate.getResourceType()
1716 .name(), csarInfo.getVfResourceName(), nodeName)
1718 when(toscaOperationFacade.getLatestByName(resourceToUpdate.getName(), null))
1719 .thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
1720 when(toscaOperationFacade.getLatestByToscaResourceName(resourceToUpdate.getToscaResourceName()))
1721 .thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
1722 when(toscaOperationFacade.getLatestByToscaResourceNameAndModel(resourceToUpdate.getToscaResourceName(), null))
1723 .thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
1724 when(toscaOperationFacade.getLatestByToscaResourceName(nestedResourceName))
1725 .thenReturn(Either.left(resourceResponse));
1726 when(toscaOperationFacade.overrideComponent(any(Resource.class), any(Resource.class)))
1727 .thenReturn(Either.left(resourceResponse));
1729 ImmutablePair<Resource, ActionStatus> createOrUpdateResource = bl
1730 .createOrUpdateResourceByImport(resourceToUpdate, user, false, false, false, csarInfo, nodeName, false);
1731 assertThat(createOrUpdateResource).isNotNull();
1732 Mockito.verify(toscaOperationFacade, times(1))
1733 .overrideComponent(any(Resource.class), any(Resource.class));
1734 Mockito.verify(lifecycleBl, times(0))
1735 .changeState(anyString(), eq(user), eq(LifeCycleTransitionEnum.CHECKOUT),
1736 any(LifecycleChangeInfoWithAction.class), Mockito.anyBoolean(), Mockito.anyBoolean());
1740 public void testValidatePropertiesDefaultValues_SuccessfullWithoutProperties() {
1741 Resource basic = createResourceObject(true);
1743 Boolean validatePropertiesDefaultValues = bl.validatePropertiesDefaultValues(basic);
1744 assertTrue(validatePropertiesDefaultValues);
1748 public void testValidatePropertiesDefaultValues_SuccessfullWithProperties() {
1749 Resource basic = createResourceObject(true);
1750 PropertyDefinition property = new PropertyDefinition();
1751 property.setName("myProperty");
1752 property.setType(ToscaPropertyType.INTEGER.getType());
1753 property.setDefaultValue("1");
1754 List<PropertyDefinition> properties = new ArrayList<>();
1755 properties.add(property);
1756 basic.setProperties(properties);
1757 when(propertyOperation.isPropertyTypeValid(property, null)).thenReturn(true);
1758 when(propertyOperation.isPropertyDefaultValueValid(property, emptyDataTypes)).thenReturn(true);
1759 Boolean validatePropertiesDefaultValues = bl.validatePropertiesDefaultValues(basic);
1760 assertTrue(validatePropertiesDefaultValues);
1763 @Test(expected = ComponentException.class)
1764 public void testValidatePropertiesDefaultValues_FailedWithProperties() {
1765 Resource basic = createResourceObject(true);
1766 PropertyDefinition property = new PropertyDefinition();
1767 property.setName("myProperty");
1768 property.setType(ToscaPropertyType.INTEGER.getType());
1769 property.setDefaultValue("1.5");
1770 List<PropertyDefinition> properties = new ArrayList<>();
1771 properties.add(property);
1772 basic.setProperties(properties);
1774 when(propertyOperation.isPropertyDefaultValueValid(property, emptyDataTypes)).thenReturn(false);
1775 bl.validatePropertiesDefaultValues(basic);
1779 public void testDeleteMarkedResourcesNoResources() {
1780 Either<List<String>, StorageOperationStatus> eitherNoResources = Either.left(new ArrayList<>());
1782 when(toscaOperationFacade.deleteMarkedElements(ComponentTypeEnum.RESOURCE)).thenReturn(eitherNoResources);
1784 Either<List<String>, ResponseFormat> deleteMarkedResources = bl.deleteMarkedComponents();
1785 assertTrue(deleteMarkedResources.isLeft());
1786 assertTrue(deleteMarkedResources.left().value().isEmpty());
1790 public void testDeleteMarkedResources() {
1791 List<String> ids = new ArrayList<>();
1792 String resourceInUse = "123";
1793 String resourceFree = "456";
1794 ids.add(resourceInUse);
1795 ids.add(resourceFree);
1796 Either<List<String>, StorageOperationStatus> eitherNoResources = Either.left(ids);
1797 when(toscaOperationFacade.getAllComponentsMarkedForDeletion(ComponentTypeEnum.RESOURCE)).thenReturn(eitherNoResources);
1799 Either<Boolean, StorageOperationStatus> resourceInUseResponse = Either.left(true);
1800 Either<Boolean, StorageOperationStatus> resourceFreeResponse = Either.left(false);
1802 List<ArtifactDefinition> artifacts = new ArrayList<>();
1804 when(toscaOperationFacade.isComponentInUse(resourceFree)).thenReturn(resourceFreeResponse);
1805 when(toscaOperationFacade.isComponentInUse(resourceInUse)).thenReturn(resourceInUseResponse);
1807 Either<Component, StorageOperationStatus> eitherDelete = Either.left(new
1809 when(toscaOperationFacade.deleteToscaComponent(resourceFree)).thenReturn(eitherDelete);
1811 List<String> deletedComponents = new ArrayList<>();
1812 deletedComponents.add(resourceFree);
1813 when(toscaOperationFacade.deleteMarkedElements(ComponentTypeEnum.RESOURCE)).thenReturn(Either.left(deletedComponents));
1815 Either<List<String>, ResponseFormat> deleteMarkedResources = bl.deleteMarkedComponents();
1816 assertTrue(deleteMarkedResources.isLeft());
1817 List<String> resourceIdList = deleteMarkedResources.left().value();
1818 assertFalse(resourceIdList.isEmpty());
1819 assertTrue(resourceIdList.contains(resourceFree));
1820 assertFalse(resourceIdList.contains(resourceInUse));
1823 @SuppressWarnings("unchecked")
1825 public void testFindVfCsarArtifactsToHandle() {
1827 Class<ResourceBusinessLogic> targetClass = ResourceBusinessLogic.class;
1828 String methodName = "findVfCsarArtifactsToHandle";
1829 Resource resource = new Resource();
1830 String deploymentArtifactToUpdateFileName = "deploymentArtifactToUpdate.yaml";
1831 String deploymentArtifactToDeleteFileName = "deploymentArtifactToDelete.yaml";
1832 String deploymentArtifactToCreateFileName = "deploymentArtifactToCreate.yaml";
1834 String artifactInfoToUpdateFileName = "infoArtifactToUpdate.yaml";
1835 String artifactInfoToDeleteFileName = "infoArtifactToDelete.yaml";
1836 String artifactInfoToNotDeleteFileName = "infoArtifactNotToDelete.yaml";
1837 String artifactInfoToCreateFileName = "infoArtifactToCreate.yaml";
1839 byte[] oldPayloadData = "oldPayloadData".getBytes();
1840 byte[] newPayloadData = "newPayloadData".getBytes();
1841 Map<String, ArtifactDefinition> deploymentArtifacts = new HashMap<>();
1843 ArtifactDefinition deploymentArtifactToUpdate = new ArtifactDefinition();
1844 deploymentArtifactToUpdate.setMandatory(false);
1845 deploymentArtifactToUpdate.setArtifactName(deploymentArtifactToUpdateFileName);
1846 deploymentArtifactToUpdate.setArtifactType("SNMP_POLL");
1847 deploymentArtifactToUpdate.setPayload(oldPayloadData);
1848 deploymentArtifactToUpdate
1849 .setArtifactChecksum(GeneralUtility.calculateMD5Base64EncodedByByteArray(oldPayloadData));
1851 ArtifactDefinition deploymentArtifactToDelete = new ArtifactDefinition();
1852 deploymentArtifactToDelete.setMandatory(false);
1853 deploymentArtifactToDelete.setArtifactName(deploymentArtifactToDeleteFileName);
1854 deploymentArtifactToDelete.setArtifactType("SNMP_TRAP");
1855 deploymentArtifactToDelete.setPayload(oldPayloadData);
1856 deploymentArtifactToDelete
1857 .setArtifactChecksum(GeneralUtility.calculateMD5Base64EncodedByByteArray(oldPayloadData));
1859 ArtifactDefinition deploymentArtifactToIgnore = new ArtifactDefinition();
1861 deploymentArtifacts.put(ValidationUtils.normalizeArtifactLabel(deploymentArtifactToUpdate.getArtifactName()),
1862 deploymentArtifactToUpdate);
1863 deploymentArtifacts.put(ValidationUtils.normalizeArtifactLabel(deploymentArtifactToDelete.getArtifactName()),
1864 deploymentArtifactToDelete);
1865 deploymentArtifacts.put("ignore", deploymentArtifactToIgnore);
1867 Map<String, ArtifactDefinition> artifacts = new HashMap<>();
1869 ArtifactDefinition artifactToUpdate = new ArtifactDefinition();
1870 artifactToUpdate.setMandatory(false);
1871 artifactToUpdate.setArtifactName(artifactInfoToUpdateFileName);
1872 artifactToUpdate.setArtifactType("SNMP_POLL");
1873 artifactToUpdate.setPayload(oldPayloadData);
1874 artifactToUpdate.setArtifactChecksum(GeneralUtility.calculateMD5Base64EncodedByByteArray(oldPayloadData));
1876 ArtifactDefinition artifactToDelete = new ArtifactDefinition();
1877 artifactToDelete.setMandatory(false);
1878 artifactToDelete.setArtifactName(artifactInfoToDeleteFileName);
1879 artifactToDelete.setArtifactType("SNMP_TRAP");
1880 artifactToDelete.setPayload(oldPayloadData);
1881 artifactToDelete.setArtifactChecksum(GeneralUtility.calculateMD5Base64EncodedByByteArray(oldPayloadData));
1882 artifactToDelete.setIsFromCsar(true);
1884 ArtifactDefinition artifactToNotDelete = new ArtifactDefinition();
1885 artifactToNotDelete.setMandatory(false);
1886 artifactToNotDelete.setArtifactName(artifactInfoToNotDeleteFileName);
1887 artifactToNotDelete.setArtifactType("SNMP_TRAP");
1888 artifactToNotDelete.setPayload(oldPayloadData);
1889 artifactToNotDelete.setArtifactChecksum(GeneralUtility.calculateMD5Base64EncodedByByteArray(oldPayloadData));
1890 artifactToNotDelete.setIsFromCsar(false);
1892 ArtifactDefinition artifactToIgnore = new ArtifactDefinition();
1894 artifacts.put(ValidationUtils.normalizeArtifactLabel(artifactToUpdate.getArtifactName()), artifactToUpdate);
1895 artifacts.put(ValidationUtils.normalizeArtifactLabel(artifactToDelete.getArtifactName()), artifactToDelete);
1896 artifacts.put(ValidationUtils.normalizeArtifactLabel(artifactToNotDelete.getArtifactName()),
1897 artifactToNotDelete);
1898 artifacts.put("ignore", artifactToIgnore);
1900 resource.setDeploymentArtifacts(deploymentArtifacts);
1901 resource.setArtifacts(artifacts);
1903 List<NonMetaArtifactInfo> artifactPathAndNameList = new ArrayList<>();
1904 NonMetaArtifactInfo deploymentArtifactInfoToUpdate = new NonMetaArtifactInfo(
1905 deploymentArtifactToUpdate.getArtifactName(), null,
1906 deploymentArtifactToUpdate.getArtifactType(),
1907 ArtifactGroupTypeEnum.DEPLOYMENT, newPayloadData, deploymentArtifactToUpdate.getArtifactName(), false);
1909 NonMetaArtifactInfo informationalArtifactInfoToUpdate = new NonMetaArtifactInfo(
1910 artifactToUpdate.getArtifactName(), null, artifactToUpdate.getArtifactType(),
1911 ArtifactGroupTypeEnum.DEPLOYMENT, newPayloadData, artifactToUpdate.getArtifactName(), false);
1913 NonMetaArtifactInfo informationalArtifactInfoToUpdateFromCsar = new NonMetaArtifactInfo(
1914 artifactToUpdate.getArtifactName(), null, artifactToUpdate.getArtifactType(),
1915 ArtifactGroupTypeEnum.INFORMATIONAL, newPayloadData, artifactToUpdate.getArtifactName(), true);
1917 NonMetaArtifactInfo deploymentArtifactInfoToUpdateFromCsar = new NonMetaArtifactInfo(
1918 artifactToUpdate.getArtifactName(), null, artifactToUpdate.getArtifactType(),
1919 ArtifactGroupTypeEnum.DEPLOYMENT, newPayloadData, artifactToUpdate.getArtifactName(), true);
1921 NonMetaArtifactInfo deploymentArtifactInfoToCreate = new NonMetaArtifactInfo(deploymentArtifactToCreateFileName,
1922 null, ArtifactTypeEnum.OTHER.getType(), ArtifactGroupTypeEnum.DEPLOYMENT, newPayloadData,
1923 deploymentArtifactToCreateFileName, false);
1925 NonMetaArtifactInfo informationalArtifactInfoToCreate = new NonMetaArtifactInfo(artifactInfoToCreateFileName,
1926 null, ArtifactTypeEnum.OTHER.getType(), ArtifactGroupTypeEnum.INFORMATIONAL, newPayloadData,
1927 artifactInfoToCreateFileName, false);
1929 artifactPathAndNameList.add(deploymentArtifactInfoToUpdate);
1930 artifactPathAndNameList.add(informationalArtifactInfoToUpdate);
1931 artifactPathAndNameList.add(deploymentArtifactInfoToCreate);
1932 artifactPathAndNameList.add(informationalArtifactInfoToCreate);
1933 artifactPathAndNameList.add(informationalArtifactInfoToUpdateFromCsar);
1934 artifactPathAndNameList.add(deploymentArtifactInfoToUpdateFromCsar);
1936 Object[] argObjects = { resource, artifactPathAndNameList, user };
1937 Class[] argClasses = { Resource.class, List.class, User.class };
1939 Method method = targetClass.getDeclaredMethod(methodName, argClasses);
1940 method.setAccessible(true);
1941 Either<EnumMap<ArtifactOperationEnum, List<NonMetaArtifactInfo>>, ResponseFormat> findVfCsarArtifactsToHandleRes = (Either<EnumMap<ArtifactOperationEnum, List<NonMetaArtifactInfo>>, ResponseFormat>) method
1942 .invoke(bl, argObjects);
1943 assertTrue(findVfCsarArtifactsToHandleRes.isLeft());
1944 EnumMap<ArtifactOperationEnum, List<NonMetaArtifactInfo>> foundVfArtifacts = findVfCsarArtifactsToHandleRes
1947 assertEquals(4, foundVfArtifacts.get(ArtifactOperationEnum.CREATE)
1949 assertEquals(4, foundVfArtifacts.get(ArtifactOperationEnum.UPDATE)
1951 assertEquals(1, foundVfArtifacts.get(ArtifactOperationEnum.DELETE)
1954 } catch (Exception e) {
1955 e.printStackTrace();
1960 public void testVFGeneratedInputs() {
1961 validateUserRoles(Role.ADMIN, Role.DESIGNER);
1962 Resource resource = createVF();
1963 List<InputDefinition> inputs = resource.getInputs();
1964 assertEquals(6, inputs.size());
1965 for (InputDefinition input : inputs) {
1966 assertThat(input.getOwnerId()).isNotNull();
1968 assertEquals(resource.getDerivedFromGenericType(), genericVF.getToscaResourceName());
1969 assertEquals(resource.getDerivedFromGenericVersion(), genericVF.getVersion());
1973 public void testCRGeneratedInputs() {
1974 validateUserRoles(Role.ADMIN, Role.DESIGNER);
1975 Resource resource = createCR();
1976 List<InputDefinition> inputs = resource.getInputs();
1977 assertEquals(3, inputs.size());
1978 for (InputDefinition input : inputs) {
1979 assertThat(input.getOwnerId()).isNotNull();
1981 assertEquals(resource.getDerivedFromGenericType(), genericCR.getToscaResourceName());
1982 assertEquals(resource.getDerivedFromGenericVersion(), genericCR.getVersion());
1986 public void testVFUpdateGenericInputsToLatestOnCheckout() {
1987 validateUserRoles(Role.ADMIN, Role.DESIGNER);
1988 // create a VF that is derived from generic version 1.0
1989 Resource resource = createVF();
1990 // create a new generic version without properties
1991 genericVF.setVersion("2.0");
1992 genericVF.setProperties(null);
1993 String currentDerivedFromVersion = resource.getDerivedFromGenericVersion();
1994 List<InputDefinition> currentInputs = resource.getInputs();
1995 // verify previous inputs ownerId fields exist - user may not delete
1997 assertEquals(6, currentInputs.stream()
1998 .filter(p -> null != p.getOwnerId())
1999 .collect(Collectors.toList())
2001 Either<Boolean, ResponseFormat> upgradeToLatestGeneric = bl.shouldUpgradeToLatestGeneric(resource);
2003 assertTrue(upgradeToLatestGeneric.isLeft());
2004 // verify update required and valid
2005 assertTrue(upgradeToLatestGeneric.left()
2007 // verify version was upgraded
2008 assertNotEquals(resource.getDerivedFromGenericVersion(), currentDerivedFromVersion);
2009 // verify inputs were not deleted
2010 assertEquals(6, resource.getInputs()
2012 // verify inputs ownerId fields were removed - user may delete/edit
2014 assertEquals(6, resource.getInputs()
2016 .filter(p -> null == p.getOwnerId())
2017 .collect(Collectors.toList())
2022 public void testVFUpdateGenericInputsToLatestOnCheckoutNotPerformed() {
2024 // create a VF that is derived from generic version 1.0
2025 validateUserRoles(Role.ADMIN, Role.DESIGNER);
2026 Resource resource = createVF();
2028 // add an input to the VF
2029 PropertyDefinition newProp = new PropertyDefinition();
2030 newProp.setType("integer");
2031 newProp.setName("newProp");
2032 resource.getInputs()
2033 .add(new InputDefinition(newProp));
2035 // create a new generic version with a new property which has the same
2036 // name as a user defined input on the VF with a different type
2037 genericVF.setVersion("2.0");
2038 newProp.setType("string");
2039 genericVF.setProperties(new ArrayList<>());
2040 genericVF.getProperties()
2042 when(genericTypeBusinessLogic.fetchDerivedFromGenericType(resource)).thenReturn(Either.left(genericVF));
2043 when(genericTypeBusinessLogic.convertGenericTypePropertiesToInputsDefintion(genericVF.getProperties(),
2044 genericVF.getUniqueId())).thenCallRealMethod();
2045 String currentDerivedFromVersion = resource.getDerivedFromGenericVersion();
2046 assertEquals(6, resource.getInputs()
2048 .filter(p -> null != p.getOwnerId())
2049 .collect(Collectors.toList())
2051 Either<Boolean, ResponseFormat> upgradeToLatestGeneric = bl.shouldUpgradeToLatestGeneric(resource);
2053 assertTrue(upgradeToLatestGeneric.isLeft());
2054 // verify update is invalid an void
2055 assertFalse(upgradeToLatestGeneric.left()
2057 // verify version was not upgraded
2058 assertEquals(resource.getDerivedFromGenericVersion(), currentDerivedFromVersion);
2059 // verify inputs were not removed
2060 assertEquals(7, resource.getInputs()
2062 // verify user defined input exists
2063 assertEquals(1, resource.getInputs()
2065 .filter(p -> null == p.getOwnerId())
2066 .collect(Collectors.toList())
2068 assertEquals("integer", resource.getInputs()
2070 .filter(p -> null == p.getOwnerId())
2077 public void testPNFGeneratedInputsNoGeneratedInformationalArtifacts() {
2078 validateUserRoles(Role.ADMIN, Role.DESIGNER);
2079 Resource resource = createPNF();
2080 List<InputDefinition> inputs = resource.getInputs();
2081 assertEquals(3, inputs.size());
2082 for (InputDefinition input : inputs) {
2083 assertThat(input.getOwnerId()).isNotNull();
2085 assertEquals(resource.getDerivedFromGenericType(), genericPNF.getToscaResourceName());
2086 assertEquals(resource.getDerivedFromGenericVersion(), genericPNF.getVersion());
2087 assertEquals(0, resource.getArtifacts()
2091 private Resource createVF() {
2093 genericVF = setupGenericTypeMock(GENERIC_VF_NAME);
2094 when(toscaOperationFacade.getLatestCertifiedNodeTypeByToscaResourceName(GENERIC_VF_NAME))
2095 .thenReturn(Either.left(genericVF));
2096 Resource resource = createResourceObject(true);
2097 resource.setDerivedFrom(null);
2098 resource.setResourceType(ResourceTypeEnum.VF);
2099 when(toscaOperationFacade.createToscaComponent(resource)).thenReturn(Either.left(resource));
2100 when(genericTypeBusinessLogic.fetchDerivedFromGenericType(resource)).thenReturn(Either.left(genericVF));
2101 when(genericTypeBusinessLogic.generateInputsFromGenericTypeProperties(genericVF)).thenCallRealMethod();
2102 when(genericTypeBusinessLogic.convertGenericTypePropertiesToInputsDefintion(genericVF.getProperties(),
2103 resource.getUniqueId())).thenCallRealMethod();
2104 when(toscaOperationFacade
2105 .validateComponentNameAndModelExists(resource.getName(), null, ResourceTypeEnum.VF, ComponentTypeEnum.RESOURCE))
2106 .thenReturn(Either.left(false));
2107 Resource createdResource = bl.createResource(resource, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
2108 assertThat(createdResource).isNotNull();
2109 return createdResource;
2112 private Resource createRoot() {
2113 rootType = setupGenericTypeMock(GENERIC_ROOT_NAME);
2114 when(toscaOperationFacade.getLatestByToscaResourceName(GENERIC_ROOT_NAME))
2115 .thenReturn(Either.left(rootType));
2119 private Resource createCR() {
2121 genericCR = setupGenericTypeMock(GENERIC_CR_NAME);
2122 when(toscaOperationFacade.getLatestCertifiedNodeTypeByToscaResourceName(GENERIC_CR_NAME))
2123 .thenReturn(Either.left(genericCR));
2124 Resource resource = createResourceObject(true);
2125 resource.setDerivedFrom(null);
2126 resource.setResourceType(ResourceTypeEnum.CR);
2127 when(toscaOperationFacade.createToscaComponent(resource)).thenReturn(Either.left(resource));
2128 when(genericTypeBusinessLogic.fetchDerivedFromGenericType(resource)).thenReturn(Either.left(genericCR));
2129 when(genericTypeBusinessLogic.generateInputsFromGenericTypeProperties(genericCR)).thenCallRealMethod();
2130 when(genericTypeBusinessLogic.convertGenericTypePropertiesToInputsDefintion(genericCR.getProperties(),
2131 resource.getUniqueId())).thenCallRealMethod();
2132 when(toscaOperationFacade
2133 .validateComponentNameAndModelExists(resource.getName(), null, ResourceTypeEnum.CR, ComponentTypeEnum.RESOURCE))
2134 .thenReturn(Either.left(false));
2135 Resource createdResource = bl.createResource(resource, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
2136 assertThat(createdResource).isNotNull();
2137 return createdResource;
2140 private Resource createPNF() {
2142 genericPNF = setupGenericTypeMock(GENERIC_PNF_NAME);
2143 when(toscaOperationFacade.getLatestCertifiedNodeTypeByToscaResourceName(GENERIC_PNF_NAME))
2144 .thenReturn(Either.left(genericPNF));
2145 Resource resource = createResourceObject(true);
2146 resource.setDerivedFrom(null);
2147 resource.setResourceType(ResourceTypeEnum.PNF);
2148 when(toscaOperationFacade.createToscaComponent(resource)).thenReturn(Either.left(resource));
2149 when(genericTypeBusinessLogic.fetchDerivedFromGenericType(resource)).thenReturn(Either.left(genericPNF));
2150 when(genericTypeBusinessLogic.generateInputsFromGenericTypeProperties(genericPNF)).thenCallRealMethod();
2151 when(genericTypeBusinessLogic.convertGenericTypePropertiesToInputsDefintion(genericPNF.getProperties(),
2152 resource.getUniqueId())).thenCallRealMethod();
2153 when(toscaOperationFacade
2154 .validateComponentNameAndModelExists(resource.getName(), null, ResourceTypeEnum.PNF, ComponentTypeEnum.RESOURCE))
2155 .thenReturn(Either.left(false));
2156 Resource createdResource = bl.createResource(resource, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
2157 assertThat(createdResource).isNotNull();
2158 return createdResource;
2161 private Map<String, String> getGenericPropertiesByToscaName(String toscaName) {
2162 HashMap<String, String> PNFProps = new HashMap<String, String>() {
2164 put("nf_function", "string");
2165 put("nf_role", "string");
2166 put("nf_type", "string");
2170 HashMap<String, String> CRProps = new HashMap<String, String>() {
2172 put("cr_function", "string");
2173 put("cr_role", "string");
2174 put("cr_type", "string");
2178 HashMap<String, String> VFProps = new HashMap<String, String>() {
2181 put("availability_zone_max_count", "integer");
2182 put("min_instances", "integer");
2183 put("max_instances", "integer");
2187 if (toscaName.contains("PNF"))
2189 if (toscaName.contains("CR"))
2191 if (toscaName.contains("VF"))
2194 return new HashMap<>();
2197 private Resource setupGenericTypeMock(String toscaName) {
2199 Resource genericType = createResourceObject(true);
2200 genericType.setVersion("1.0");
2201 genericType.setToscaResourceName(toscaName);
2202 genericType.setAbstract(true);
2203 List<PropertyDefinition> genericProps = new ArrayList<>();
2204 Map<String, String> genericPropsMap = getGenericPropertiesByToscaName(toscaName);
2205 genericPropsMap.forEach((name, type) -> {
2206 PropertyDefinition prop = new PropertyDefinition();
2209 genericProps.add(prop);
2212 genericType.setProperties(genericProps);
2216 private void validateUserRoles(Role... roles) {
2217 List<Role> listOfRoles = Stream.of(roles)
2218 .collect(Collectors.toList());
2222 public void testUpdateVolumeGroup() {
2223 Resource resource = getResourceWithType("HEAT_VOL", "org.openecomp.groups.VfModule");
2224 bl.updateVolumeGroup(resource);
2225 assertThat(resource.getGroups().get(0).getProperties().get(0).getValue()).isEqualTo(Boolean.toString(true));
2229 public void testUpdateVolumeGroupNull() {
2230 Resource resource = getResourceWithType("HEAT_VOL", "org.openecomp.groups.VfModule");
2231 resource.setGroups(null);
2232 bl.updateVolumeGroup(resource);
2233 assertThat(resource.getGroups()).isNull();
2237 public void testUpdateVolumeGroupFail() {
2238 Resource resource = getResourceWithType("NON_EXIST_HEAT", "org.openecomp.groups.VfModule");
2239 bl.updateVolumeGroup(resource);
2240 assertThat(resource.getGroups().get(0).getProperties().get(0).getValue()).isEqualTo(Boolean.toString(false));
2243 private Resource getResourceWithType(String artifactType, String groupDefinitionType) {
2244 ArtifactDefinition artifactToUpdate = new ArtifactDefinition();
2245 List<GroupDefinition> groups = new ArrayList<>();
2246 GroupDefinition gd = new GroupDefinition();
2247 List<PropertyDataDefinition> properties = new ArrayList<>();
2248 PropertyDataDefinition pdd = new PropertyDataDefinition();
2249 Map<String, ArtifactDefinition> artifacts = new HashMap<>();
2250 List<String> artifactsList = new ArrayList<>();
2252 artifactToUpdate.setArtifactType(artifactType);
2253 artifactToUpdate.setArtifactName(artifactType);
2254 artifactToUpdate.setUniqueId(artifactType);
2255 Resource resource = createResourceObjectCsar(true);
2256 artifactsList.add(artifactToUpdate.getArtifactName());
2259 pdd.setName("volume_group");
2260 pdd.setValue("true");
2261 pdd.setType(ToscaPropertyType.BOOLEAN.getType());
2263 artifacts.put(artifactToUpdate.getArtifactName(), artifactToUpdate);
2265 properties.add(pdd);
2266 gd.setType(groupDefinitionType);
2267 gd.setProperties(properties);
2268 gd.setArtifacts(artifactsList);
2271 resource.setGroups(groups);
2272 resource.setDeploymentArtifacts(artifacts);
2278 public void testgetAllCertifiedResources() throws Exception {
2279 List<Resource> list = bl.getAllCertifiedResources(true, HighestFilterEnum.HIGHEST_ONLY, "USER");
2280 Assert.assertEquals(reslist,list);
2283 @Test(expected = StorageException.class)
2284 public void testgetAllCertifiedResources_exception() throws Exception {
2285 List<Resource> list = bl.getAllCertifiedResources(false, HighestFilterEnum.NON_HIGHEST_ONLY, "USER");
2286 Assert.assertEquals(reslist,list);
2290 public void testvalidateResourceNameExists() throws Exception {
2291 Either<Map<String, Boolean>, ResponseFormat> res = bl.validateResourceNameExists("Resource", ResourceTypeEnum.CR, "jh0003");
2292 Assert.assertEquals(true,res.isLeft());
2296 public void rollbackWithEitherAlwaysReturnARuntimeException() {
2297 JanusGraphDao janusGraphDao = mockJanusGraphDao;
2298 ActionStatus actionStatus = ActionStatus.INPUTS_NOT_FOUND;
2299 String params = "testName";
2301 Either<Object, RuntimeException> result =
2302 ResourceBusinessLogic.rollbackWithEither(janusGraphDao, actionStatus, params);
2304 assertTrue(result.isRight());
2305 assertTrue(result.right().value() instanceof ByActionStatusComponentException);
2309 public void rollbackWithEitherWorksWithNullJanusGraphDao() {
2310 JanusGraphDao janusGraphDao = null;
2311 ActionStatus actionStatus = ActionStatus.INPUTS_NOT_FOUND;
2312 String params = "testName";
2314 Either<Object, RuntimeException> result =
2315 ResourceBusinessLogic.rollbackWithEither(janusGraphDao, actionStatus, params);
2317 assertTrue(result.isRight());
2318 assertTrue(result.right().value() instanceof ByActionStatusComponentException);