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.anyList;
31 import static org.mockito.ArgumentMatchers.anyString;
32 import static org.mockito.ArgumentMatchers.eq;
33 import static org.mockito.Mockito.doAnswer;
34 import static org.mockito.Mockito.times;
35 import static org.mockito.Mockito.when;
37 import fj.data.Either;
39 import java.io.IOException;
40 import java.lang.reflect.Method;
41 import java.net.URISyntaxException;
42 import java.util.ArrayList;
43 import java.util.Arrays;
44 import java.util.Collections;
45 import java.util.EnumMap;
46 import java.util.HashMap;
47 import java.util.List;
49 import java.util.Map.Entry;
50 import java.util.Optional;
51 import java.util.stream.Collectors;
52 import java.util.stream.Stream;
53 import javax.servlet.ServletContext;
54 import org.apache.commons.lang3.tuple.ImmutablePair;
55 import org.junit.Assert;
56 import org.junit.Before;
57 import org.junit.Test;
58 import org.mockito.InjectMocks;
59 import org.mockito.Mockito;
60 import org.mockito.MockitoAnnotations;
61 import org.openecomp.sdc.ElementOperationMock;
62 import org.openecomp.sdc.be.auditing.impl.AuditingManager;
63 import org.openecomp.sdc.be.components.ArtifactsResolver;
64 import org.openecomp.sdc.be.components.csar.CsarArtifactsAndGroupsBusinessLogic;
65 import org.openecomp.sdc.be.components.csar.CsarBusinessLogic;
66 import org.openecomp.sdc.be.components.csar.CsarInfo;
67 import org.openecomp.sdc.be.components.csar.YamlTemplateParsingHandler;
68 import org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic.ArtifactOperationEnum;
69 import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
70 import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
71 import org.openecomp.sdc.be.components.impl.generic.GenericTypeBusinessLogic;
72 import org.openecomp.sdc.be.components.lifecycle.LifecycleBusinessLogic;
73 import org.openecomp.sdc.be.components.lifecycle.LifecycleChangeInfoWithAction;
74 import org.openecomp.sdc.be.components.merge.resource.ResourceDataMergeBusinessLogic;
75 import org.openecomp.sdc.be.components.merge.utils.MergeInstanceUtils;
76 import org.openecomp.sdc.be.components.validation.UserValidations;
77 import org.openecomp.sdc.be.components.validation.component.ComponentContactIdValidator;
78 import org.openecomp.sdc.be.components.validation.component.ComponentDescriptionValidator;
79 import org.openecomp.sdc.be.components.validation.component.ComponentFieldValidator;
80 import org.openecomp.sdc.be.components.validation.component.ComponentIconValidator;
81 import org.openecomp.sdc.be.components.validation.component.ComponentNameValidator;
82 import org.openecomp.sdc.be.components.validation.component.ComponentProjectCodeValidator;
83 import org.openecomp.sdc.be.components.validation.component.ComponentTagsValidator;
84 import org.openecomp.sdc.be.components.validation.component.ComponentValidator;
85 import org.openecomp.sdc.be.config.ConfigurationManager;
86 import org.openecomp.sdc.be.dao.api.ActionStatus;
87 import org.openecomp.sdc.be.dao.cassandra.ArtifactCassandraDao;
88 import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
89 import org.openecomp.sdc.be.dao.jsongraph.JanusGraphDao;
90 import org.openecomp.sdc.be.datamodel.api.HighestFilterEnum;
91 import org.openecomp.sdc.be.datamodel.utils.UiComponentDataConverter;
92 import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
93 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
94 import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
95 import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
96 import org.openecomp.sdc.be.facade.operations.CatalogOperation;
97 import org.openecomp.sdc.be.impl.ComponentsUtils;
98 import org.openecomp.sdc.be.impl.WebAppContextWrapper;
99 import org.openecomp.sdc.be.model.ArtifactDefinition;
100 import org.openecomp.sdc.be.model.Component;
101 import org.openecomp.sdc.be.model.ComponentInstance;
102 import org.openecomp.sdc.be.model.ComponentParametersView;
103 import org.openecomp.sdc.be.model.DataTypeDefinition;
104 import org.openecomp.sdc.be.model.GroupDefinition;
105 import org.openecomp.sdc.be.model.InputDefinition;
106 import org.openecomp.sdc.be.model.LifeCycleTransitionEnum;
107 import org.openecomp.sdc.be.model.LifecycleStateEnum;
108 import org.openecomp.sdc.be.model.NodeTypeInfo;
109 import org.openecomp.sdc.be.model.ParsedToscaYamlInfo;
110 import org.openecomp.sdc.be.model.PropertyDefinition;
111 import org.openecomp.sdc.be.model.RequirementDefinition;
112 import org.openecomp.sdc.be.model.Resource;
113 import org.openecomp.sdc.be.model.UploadComponentInstanceInfo;
114 import org.openecomp.sdc.be.model.User;
115 import org.openecomp.sdc.be.model.cache.ApplicationDataTypeCache;
116 import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ArtifactsOperations;
117 import org.openecomp.sdc.be.model.jsonjanusgraph.operations.InterfaceOperation;
118 import org.openecomp.sdc.be.model.jsonjanusgraph.operations.NodeTemplateOperation;
119 import org.openecomp.sdc.be.model.jsonjanusgraph.operations.NodeTypeOperation;
120 import org.openecomp.sdc.be.model.jsonjanusgraph.operations.TopologyTemplateOperation;
121 import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade;
122 import org.openecomp.sdc.be.model.operations.StorageException;
123 import org.openecomp.sdc.be.model.operations.api.ICapabilityTypeOperation;
124 import org.openecomp.sdc.be.model.operations.api.IElementOperation;
125 import org.openecomp.sdc.be.model.operations.api.IGroupInstanceOperation;
126 import org.openecomp.sdc.be.model.operations.api.IGroupOperation;
127 import org.openecomp.sdc.be.model.operations.api.IGroupTypeOperation;
128 import org.openecomp.sdc.be.model.operations.api.IInterfaceLifecycleOperation;
129 import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
130 import org.openecomp.sdc.be.model.operations.impl.CsarOperation;
131 import org.openecomp.sdc.be.model.operations.impl.GraphLockOperation;
132 import org.openecomp.sdc.be.model.operations.impl.InterfaceLifecycleOperation;
133 import org.openecomp.sdc.be.model.operations.impl.PropertyOperation;
134 import org.openecomp.sdc.be.model.tosca.ToscaPropertyType;
135 import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
136 import org.openecomp.sdc.be.tosca.CsarUtils;
137 import org.openecomp.sdc.be.tosca.CsarUtils.NonMetaArtifactInfo;
138 import org.openecomp.sdc.be.tosca.ToscaExportHandler;
139 import org.openecomp.sdc.be.user.Role;
140 import org.openecomp.sdc.be.user.UserBusinessLogic;
141 import org.openecomp.sdc.common.api.ArtifactGroupTypeEnum;
142 import org.openecomp.sdc.common.api.ArtifactTypeEnum;
143 import org.openecomp.sdc.common.api.Constants;
144 import org.openecomp.sdc.common.impl.ExternalConfiguration;
145 import org.openecomp.sdc.common.impl.FSConfigurationSource;
146 import org.openecomp.sdc.common.util.GeneralUtility;
147 import org.openecomp.sdc.common.util.ValidationUtils;
148 import org.openecomp.sdc.common.zip.ZipUtils;
149 import org.openecomp.sdc.common.zip.exception.ZipException;
150 import org.openecomp.sdc.exception.ResponseFormat;
151 import org.springframework.web.context.WebApplicationContext;
153 public class ResourceBusinessLogicTest {
155 private final ConfigurationManager configurationManager = new ConfigurationManager(new FSConfigurationSource(ExternalConfiguration.getChangeListener(), "src/test/resources/config/catalog-be"));
156 private static final String RESOURCE_CATEGORY1 = "Network Layer 2-3";
157 private static final String RESOURCE_SUBCATEGORY = "Router";
159 private static final String UPDATED_SUBCATEGORY = "Gateway";
161 private static final String RESOURCE_NAME = "My-Resource_Name with space";
162 private static final String RESOURCE_TOSCA_NAME = "My-Resource_Tosca_Name";
163 private static final String GENERIC_ROOT_NAME = "tosca.nodes.Root";
164 private static final String GENERIC_VF_NAME = "org.openecomp.resource.abstract.nodes.VF";
165 private static final String GENERIC_CR_NAME = "org.openecomp.resource.abstract.nodes.CR";
166 private static final String GENERIC_PNF_NAME = "org.openecomp.resource.abstract.nodes.PNF";
168 private final ServletContext servletContext = Mockito.mock(ServletContext.class);
169 IElementOperation mockElementDao;
170 private final JanusGraphDao mockJanusGraphDao = Mockito.mock(JanusGraphDao.class);
171 private final UserBusinessLogic mockUserAdmin = Mockito.mock(UserBusinessLogic.class);
172 private final ToscaOperationFacade toscaOperationFacade = Mockito.mock(ToscaOperationFacade.class);
173 private final NodeTypeOperation nodeTypeOperation = Mockito.mock(NodeTypeOperation.class);
174 private final NodeTemplateOperation nodeTemplateOperation = Mockito.mock(NodeTemplateOperation.class);
175 private final TopologyTemplateOperation topologyTemplateOperation = Mockito.mock(TopologyTemplateOperation.class);
176 private final LifecycleBusinessLogic lifecycleBl = Mockito.mock(LifecycleBusinessLogic.class);
177 private final CatalogOperation catalogOperation = Mockito.mock(CatalogOperation.class);
178 private final ICapabilityTypeOperation capabilityTypeOperation = Mockito.mock(ICapabilityTypeOperation.class);
179 private final PropertyOperation propertyOperation = Mockito.mock(PropertyOperation.class);
180 private final ApplicationDataTypeCache applicationDataTypeCache = Mockito.mock(ApplicationDataTypeCache.class);
181 private final WebAppContextWrapper webAppContextWrapper = Mockito.mock(WebAppContextWrapper.class);
182 private final UserValidations userValidations = Mockito.mock(UserValidations.class);
183 private final WebApplicationContext webAppContext = Mockito.mock(WebApplicationContext.class);
184 private final IInterfaceLifecycleOperation interfaceTypeOperation = Mockito.mock(IInterfaceLifecycleOperation.class);
185 private final ArtifactCassandraDao artifactCassandraDao = Mockito.mock(ArtifactCassandraDao.class);
186 private final IElementOperation elementDao = new ElementOperationMock();
188 private final CsarUtils csarUtils = Mockito.mock(CsarUtils.class);
189 private final UserBusinessLogic userBusinessLogic = Mockito.mock(UserBusinessLogic.class);
190 private final IGroupOperation groupOperation = Mockito.mock(IGroupOperation.class);
191 private final IGroupInstanceOperation groupInstanceOperation = Mockito.mock(IGroupInstanceOperation.class);
192 private final IGroupTypeOperation groupTypeOperation = Mockito.mock(IGroupTypeOperation.class);
193 private final GroupBusinessLogic groupBusinessLogic = Mockito.mock(GroupBusinessLogic.class);
194 private final InterfaceOperation interfaceOperation = Mockito.mock(InterfaceOperation.class);
195 private final ArtifactsOperations artifactToscaOperation = Mockito.mock(ArtifactsOperations.class);
196 private final PropertyBusinessLogic propertyBusinessLogic = Mockito.mock(PropertyBusinessLogic.class);
197 private final ArtifactsResolver artifactsResolver = Mockito.mock(ArtifactsResolver.class);
198 private final InterfaceLifecycleOperation interfaceLifecycleTypeOperation = Mockito.mock(InterfaceLifecycleOperation.class);
199 private final ComponentInstanceBusinessLogic componentInstanceBusinessLogic = Mockito.mock(ComponentInstanceBusinessLogic.class);
200 private final ResourceImportManager resourceImportManager = Mockito.mock(ResourceImportManager.class);
201 private final InputsBusinessLogic inputsBusinessLogic = Mockito.mock(InputsBusinessLogic.class);
202 private final OutputsBusinessLogic outputsBusinessLogic = Mockito.mock(OutputsBusinessLogic.class);
203 private final CompositionBusinessLogic compositionBusinessLogic = Mockito.mock(CompositionBusinessLogic.class);
204 private final ResourceDataMergeBusinessLogic resourceDataMergeBusinessLogic = Mockito.mock(ResourceDataMergeBusinessLogic.class);
205 private final CsarArtifactsAndGroupsBusinessLogic csarArtifactsAndGroupsBusinessLogic = Mockito.mock(CsarArtifactsAndGroupsBusinessLogic.class);
206 private final MergeInstanceUtils mergeInstanceUtils = Mockito.mock(MergeInstanceUtils.class);
207 private final UiComponentDataConverter uiComponentDataConverter = Mockito.mock(UiComponentDataConverter.class);
208 private final ToscaExportHandler toscaExportHandler = Mockito.mock(ToscaExportHandler.class);
209 private final PolicyBusinessLogic policyBusinessLogic = Mockito.mock(PolicyBusinessLogic.class);
211 private YamlTemplateParsingHandler yamlTemplateParsingHandler = Mockito.mock(YamlTemplateParsingHandler.class);
213 ResponseFormatManager responseManager = null;
214 private final GraphLockOperation graphLockOperation = Mockito.mock(GraphLockOperation.class);
216 Resource resourceResponse = null;
217 Resource genericVF = null;
218 Resource genericCR = null;
219 Resource genericVFC = null;
220 Resource genericPNF = null;
221 Resource rootType = null;
222 ComponentsUtils componentsUtils = new ComponentsUtils(Mockito.mock(AuditingManager.class));
223 ArtifactsBusinessLogic artifactManager = new ArtifactsBusinessLogic(artifactCassandraDao, toscaExportHandler, csarUtils, lifecycleBl,
224 userBusinessLogic, artifactsResolver, elementDao, groupOperation, groupInstanceOperation, groupTypeOperation,
225 interfaceOperation, interfaceLifecycleTypeOperation, artifactToscaOperation);
226 CsarOperation csarOperation = Mockito.mock(CsarOperation.class);
228 CsarBusinessLogic csarBusinessLogic ;
229 Map<String, DataTypeDefinition> emptyDataTypes = new HashMap<>();
230 List<Resource> reslist;
231 private GenericTypeBusinessLogic genericTypeBusinessLogic = Mockito.mock(GenericTypeBusinessLogic.class);
232 protected ComponentDescriptionValidator componentDescriptionValidator = new ComponentDescriptionValidator(componentsUtils);
233 protected ComponentProjectCodeValidator componentProjectCodeValidator = new ComponentProjectCodeValidator(componentsUtils);
234 protected ComponentIconValidator componentIconValidator = new ComponentIconValidator(componentsUtils);
235 protected ComponentContactIdValidator componentContactIdValidator = new ComponentContactIdValidator(componentsUtils);
236 protected ComponentTagsValidator componentTagsValidator = new ComponentTagsValidator(componentsUtils);
237 protected ComponentNameValidator componentNameValidator = new ComponentNameValidator(componentsUtils, toscaOperationFacade);
238 private ComponentValidator componentValidator = createComponentValidator();
239 private SoftwareInformationBusinessLogic softwareInformationBusinessLogic = Mockito.mock(SoftwareInformationBusinessLogic.class);
241 private ComponentValidator createComponentValidator() {
242 List<ComponentFieldValidator> componentFieldValidators = Arrays.asList(componentNameValidator,
243 componentDescriptionValidator, componentProjectCodeValidator,
244 componentIconValidator, componentContactIdValidator,
245 componentTagsValidator);
246 return new ComponentValidator(componentsUtils,componentFieldValidators);
249 ResourceBusinessLogic bl;
252 public void setup() {
253 MockitoAnnotations.initMocks(this);
254 Mockito.reset(propertyOperation);
257 mockElementDao = new ElementOperationMock();
260 // User data and management
262 user.setUserId("jh0003");
263 user.setFirstName("Jimmi");
264 user.setLastName("Hendrix");
265 user.setRole(Role.ADMIN.name());
267 when(mockUserAdmin.getUser("jh0003", false)).thenReturn(user);
268 when(userValidations.validateUserExists(user.getUserId())).thenReturn(user);
269 when(userValidations.validateUserNotEmpty(eq(user), anyString())).thenReturn(user);
270 // Servlet Context attributes
271 when(servletContext.getAttribute(Constants.CONFIGURATION_MANAGER_ATTR)).thenReturn(configurationManager);
272 when(servletContext.getAttribute(Constants.WEB_APPLICATION_CONTEXT_WRAPPER_ATTR))
273 .thenReturn(webAppContextWrapper);
274 when(webAppContextWrapper.getWebAppContext(servletContext)).thenReturn(webAppContext);
275 when(webAppContext.getBean(IElementOperation.class)).thenReturn(mockElementDao);
277 Either<Boolean, StorageOperationStatus> eitherFalse = Either.left(true);
278 when(toscaOperationFacade.validateComponentNameExists("tosca.nodes.Root", ResourceTypeEnum.VFC, ComponentTypeEnum.RESOURCE))
279 .thenReturn(eitherFalse);
282 Either<Boolean, StorageOperationStatus> eitherCountExist = Either.left(true);
283 when(toscaOperationFacade.validateComponentNameExists("alreadyExists", ResourceTypeEnum.VFC,
284 ComponentTypeEnum.RESOURCE)).thenReturn(eitherCountExist);
286 Either<Boolean, StorageOperationStatus> eitherCount = Either.left(false);
287 when(toscaOperationFacade.validateComponentNameExists(eq(RESOURCE_NAME), any(ResourceTypeEnum.class),
288 eq(ComponentTypeEnum.RESOURCE))).thenReturn(eitherCount);
289 Either<Boolean, StorageOperationStatus> validateDerivedExists = Either.left(true);
290 when(toscaOperationFacade.validateToscaResourceNameExists("tosca.nodes.Root")).thenReturn(validateDerivedExists);
292 Either<Boolean, StorageOperationStatus> validateDerivedNotExists = Either.left(false);
293 when(toscaOperationFacade.validateToscaResourceNameExists("kuku")).thenReturn(validateDerivedNotExists);
294 when(graphLockOperation.lockComponent(anyString(), eq(NodeTypeEnum.Resource)))
295 .thenReturn(StorageOperationStatus.OK);
296 when(graphLockOperation.lockComponentByName(anyString(), eq(NodeTypeEnum.Resource)))
297 .thenReturn(StorageOperationStatus.OK);
300 resourceResponse = createResourceObject(true);
301 Either<Resource, StorageOperationStatus> eitherCreate = Either.left(resourceResponse);
302 when(toscaOperationFacade.createToscaComponent(any(Resource.class))).thenReturn(eitherCreate);
303 when(catalogOperation.updateCatalog(Mockito.any(), Mockito.any())).thenReturn(ActionStatus.OK);
304 Map<String, DataTypeDefinition> emptyDataTypes = new HashMap<>();
305 when(applicationDataTypeCache.getAll(null)).thenReturn(Either.left(emptyDataTypes));
306 when(mockJanusGraphDao.commit()).thenReturn(JanusGraphOperationStatus.OK);
309 artifactManager.setNodeTemplateOperation(nodeTemplateOperation);
310 bl = new ResourceBusinessLogic(mockElementDao, groupOperation, groupInstanceOperation, groupTypeOperation, groupBusinessLogic,
311 interfaceOperation, interfaceLifecycleTypeOperation, artifactManager, componentInstanceBusinessLogic,
312 resourceImportManager, inputsBusinessLogic, outputsBusinessLogic, compositionBusinessLogic, resourceDataMergeBusinessLogic,
313 csarArtifactsAndGroupsBusinessLogic, mergeInstanceUtils, uiComponentDataConverter, csarBusinessLogic,
314 artifactToscaOperation, propertyBusinessLogic, componentContactIdValidator, componentNameValidator,
315 componentTagsValidator, componentValidator, componentIconValidator, componentProjectCodeValidator,
316 componentDescriptionValidator, policyBusinessLogic);
317 bl.setElementDao(mockElementDao);
318 bl.setUserAdmin(mockUserAdmin);
319 bl.setCapabilityTypeOperation(capabilityTypeOperation);
320 bl.setComponentsUtils(componentsUtils);
321 bl.setLifecycleManager(lifecycleBl);
322 bl.setArtifactsManager(artifactManager);
323 bl.setGraphLockOperation(graphLockOperation);
324 bl.setPropertyOperation(propertyOperation);
325 bl.setJanusGraphDao(mockJanusGraphDao);
326 bl.setApplicationDataTypeCache(applicationDataTypeCache);
327 bl.setGenericTypeBusinessLogic(genericTypeBusinessLogic);
328 bl.setCatalogOperations(catalogOperation);
329 toscaOperationFacade.setNodeTypeOperation(nodeTypeOperation);
330 csarBusinessLogic.setComponentsUtils(componentsUtils);
331 toscaOperationFacade.setTopologyTemplateOperation(topologyTemplateOperation);
332 bl.setToscaOperationFacade(toscaOperationFacade);
333 bl.setUserValidations(userValidations);
334 bl.setInterfaceTypeOperation(interfaceTypeOperation);
336 csarBusinessLogic.setCsarOperation(csarOperation);
337 Resource resourceCsar = createResourceObjectCsar(true);
338 setCanWorkOnResource(resourceCsar);
339 Either<Component, StorageOperationStatus> oldResourceRes = Either.left(resourceCsar);
340 when(toscaOperationFacade.getToscaFullElement(resourceCsar.getUniqueId())).thenReturn(oldResourceRes);
341 responseManager = ResponseFormatManager.getInstance();
342 bl.setComponentIconValidator(componentIconValidator);
343 bl.setComponentNameValidator(componentNameValidator);
344 bl.setComponentDescriptionValidator(componentDescriptionValidator);
345 bl.setComponentTagsValidator(componentTagsValidator);
346 bl.setComponentContactIdValidator(componentContactIdValidator);
347 bl.setComponentProjectCodeValidator(componentProjectCodeValidator);
348 bl.setComponentValidator(componentValidator);
349 reslist = new ArrayList<>();
350 reslist.add(resourceResponse);
351 reslist.add(genericVF);
352 reslist.add(genericCR);
353 reslist.add(genericVFC);
354 reslist.add(genericPNF);
355 Either<List<Resource>, StorageOperationStatus> returneval= Either.left(reslist);
356 when(toscaOperationFacade.getAllCertifiedResources(true, true)).thenReturn(returneval);
357 when(toscaOperationFacade.validateComponentNameUniqueness("Resource", ResourceTypeEnum.CR, ComponentTypeEnum.RESOURCE)).thenReturn(Either.left(true));
358 Either<List<Resource>, StorageOperationStatus> returnevalexception= Either.right(StorageOperationStatus.BAD_REQUEST);
359 when(toscaOperationFacade.getAllCertifiedResources(false, false)).thenReturn(returnevalexception);
362 @Test(expected = ComponentException.class)
363 public void createResourcesFromYamlNodeTypesList() throws IOException {
364 Map<String, Object> mappedToscaTemplate = new HashMap<>();
365 Map<String, EnumMap<ArtifactOperationEnum, List<ArtifactDefinition>>> nodeTypesArtifactsToHandle = new HashMap<>();
366 List<ArtifactDefinition> nodeTypesNewCreatedArtifacts = new ArrayList<>();
367 Map<String, NodeTypeInfo> nodeTypesInfo = new HashMap<>();
368 bl.createResourcesFromYamlNodeTypesList(
373 nodeTypesArtifactsToHandle,
374 nodeTypesNewCreatedArtifacts,
376 new CsarInfo(user, "abcd1234", new HashMap<>(), RESOURCE_NAME, "template name", ImportUtilsTest.loadFileNameToJsonString("normative-types-new-webServer.yml"),true), "");
380 public void handleNodeTypeArtifactsTest() {
381 Map<ArtifactOperationEnum, List<ArtifactDefinition>> nodeTypeArtifactsToHandle = new HashMap<>();
382 List<ArtifactDefinition> defs = new ArrayList<>();
383 defs.add(new ArtifactDefinition());
384 nodeTypeArtifactsToHandle.put(ArtifactOperationEnum.CREATE, defs);
385 nodeTypeArtifactsToHandle.put(ArtifactOperationEnum.UPDATE, defs);
386 assertTrue(bl.handleNodeTypeArtifacts(resourceResponse, nodeTypeArtifactsToHandle, new ArrayList<>(), user, true, true).isRight());
390 public void getUiComponentDataTransferByComponentIdTest() {
391 when(toscaOperationFacade.getToscaElement(eq(""), Mockito.any(ComponentParametersView.class))).thenReturn(Either.left(genericCR));
392 assertTrue(bl.getUiComponentDataTransferByComponentId("", new ArrayList<>()).isLeft());
393 when(toscaOperationFacade.getToscaElement(eq(""), Mockito.any(ComponentParametersView.class))).thenReturn(Either.right(StorageOperationStatus.OK));
394 assertTrue(bl.getUiComponentDataTransferByComponentId("", new ArrayList<>()).isRight());
398 public void shouldUpgradeToLatestDerivedTest() {
401 when(toscaOperationFacade.shouldUpgradeToLatestDerived(genericCR)).thenReturn(Either.left(genericCR));
402 when(toscaOperationFacade.shouldUpgradeToLatestDerived(genericVFC)).thenReturn(Either.right(StorageOperationStatus.OK));
403 assertTrue(bl.shouldUpgradeToLatestDerived(genericVF).isLeft());
404 assertTrue(bl.shouldUpgradeToLatestDerived(genericCR).isLeft());
407 private Resource createResourceObject(boolean afterCreate) {
408 Resource resource = new Resource();
409 resource.setName(RESOURCE_NAME);
410 resource.setToscaResourceName(RESOURCE_TOSCA_NAME);
411 resource.addCategory(RESOURCE_CATEGORY1, RESOURCE_SUBCATEGORY);
412 resource.setDescription("My short description");
413 List<String> tgs = new ArrayList<>();
415 tgs.add(resource.getName());
416 resource.setTags(tgs);
417 List<String> template = new ArrayList<>();
418 template.add("tosca.nodes.Root");
419 resource.setDerivedFrom(template);
420 resource.setVendorName("Motorola");
421 resource.setVendorRelease("1.0.0");
422 resource.setContactId("ya5467");
423 resource.setIcon("defaulticon");
426 resource.setName(resource.getName());
427 resource.setVersion("0.1");
428 resource.setUniqueId(resource.getName()
429 .toLowerCase() + ":" + resource.getVersion());
430 resource.setCreatorUserId(user.getUserId());
431 resource.setCreatorFullName(user.getFirstName() + " " + user.getLastName());
432 resource.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
437 private Resource createResourceObjectWithModel(boolean afterCreate) {
438 Resource resource = new Resource();
439 resource.setName(RESOURCE_NAME);
440 resource.setToscaResourceName(RESOURCE_TOSCA_NAME);
441 resource.addCategory(RESOURCE_CATEGORY1, RESOURCE_SUBCATEGORY);
442 resource.setDescription("My short description");
443 List<String> tgs = new ArrayList<>();
445 tgs.add(resource.getName());
446 resource.setTags(tgs);
447 List<String> template = new ArrayList<>();
448 template.add("tosca.nodes.Root");
449 resource.setDerivedFrom(template);
450 resource.setVendorName("Motorola");
451 resource.setVendorRelease("1.0.0");
452 resource.setContactId("ya5467");
453 resource.setIcon("defaulticon");
454 resource.setModel("Test Model");
457 resource.setName(resource.getName());
458 resource.setVersion("0.1");
459 resource.setUniqueId(resource.getName()
460 .toLowerCase() + ":" + resource.getVersion());
461 resource.setCreatorUserId(user.getUserId());
462 resource.setCreatorFullName(user.getFirstName() + " " + user.getLastName());
463 resource.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
468 private Resource createResourceObjectCsar(boolean afterCreate) {
469 Resource resource = new Resource();
470 resource.setName(RESOURCE_NAME);
471 resource.addCategory(RESOURCE_CATEGORY1, RESOURCE_SUBCATEGORY);
472 resource.setDescription("My short description");
473 List<String> tgs = new ArrayList<>();
475 tgs.add(resource.getName());
476 resource.setTags(tgs);
477 List<String> template = new ArrayList<>();
478 template.add("tosca.nodes.Root");
479 resource.setDerivedFrom(template);
480 resource.setVendorName("Motorola");
481 resource.setVendorRelease("1.0.0");
482 resource.setResourceVendorModelNumber("");
483 resource.setContactId("ya5467");
484 resource.setIcon("MyIcon");
485 resource.setCsarUUID("valid_vf.csar");
486 resource.setCsarVersion("1");
489 resource.setName(resource.getName());
490 resource.setVersion("0.1");
492 resource.setUniqueId(resource.getName()
493 .toLowerCase() + ":" + resource.getVersion());
494 resource.setCreatorUserId(user.getUserId());
495 resource.setCreatorFullName(user.getFirstName() + " " + user.getLastName());
496 resource.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
501 private Resource setCanWorkOnResource(Resource resource) {
502 resource.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
503 resource.setLastUpdaterUserId(user.getUserId());
508 public void testHappyScenario() {
509 validateUserRoles(Role.ADMIN, Role.DESIGNER);
510 Resource resource = createResourceObject(false);
511 Resource createdResource = null;
513 when(toscaOperationFacade
514 .validateComponentNameAndModelExists(resource.getName(), null, ResourceTypeEnum.VFC, ComponentTypeEnum.RESOURCE))
515 .thenReturn(Either.left(false));
516 createdResource = bl.createResource(resource, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
517 assertThat(createResourceObject(true)).isEqualTo(createdResource);
518 } catch (ComponentException e) {
519 assertThat(new Integer(200)).isEqualTo(e.getResponseFormat()
525 public void testUpdateHappyScenario() {
526 Resource resource = createResourceObjectCsar(true);
527 setCanWorkOnResource(resource);
528 validateUserRoles(Role.ADMIN, Role.DESIGNER);
529 Either<Resource, StorageOperationStatus> resourceLinkedToCsarRes = Either.left(resource);
530 when(toscaOperationFacade.getLatestComponentByCsarOrName(ComponentTypeEnum.RESOURCE, resource.getCsarUUID(), resource.getSystemName())).thenReturn(resourceLinkedToCsarRes);
531 Either<Boolean, StorageOperationStatus> validateDerivedExists = Either.left(true);
532 when(toscaOperationFacade.validateToscaResourceNameExists("tosca.nodes.Root")).thenReturn(validateDerivedExists);
533 Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
534 when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
535 Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
536 when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
538 assertThat(resource.getUniqueId()).isEqualTo(bl.validateAndUpdateResourceFromCsar(resource, user, null, null, resource.getUniqueId()).getUniqueId());
539 } catch (ComponentException e) {
540 assertThat(e.getResponseFormat().getStatus()).isEqualTo(200);
545 public void testUpdateUnhappyScenario() {
546 Resource resource = createResourceObjectCsar(true);
547 setCanWorkOnResource(resource);
548 validateUserRoles(Role.ADMIN, Role.DESIGNER);
550 when(toscaOperationFacade.getLatestComponentByCsarOrName(ComponentTypeEnum.RESOURCE, resource.getCsarUUID(), resource.getSystemName())).thenReturn(Either.left(resource));
551 when(toscaOperationFacade.validateToscaResourceNameExists("tosca.nodes.Root")).thenReturn(Either.left(true));
552 when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(Either.left(setCanWorkOnResource(resource)));
553 when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(Either.left(resource));
555 when(csarOperation.getCsar("valid_vf.csar", user)).thenReturn(Either.left(new HashMap<>()));
559 Resource createdResource = bl.validateAndUpdateResourceFromCsar(resource, user, null, "", resource.getUniqueId());
560 assertThat(resource.getUniqueId()).isEqualTo(createdResource.getUniqueId());
561 } catch (ComponentException e) {
562 assertThat(e.getResponseFormat().getStatus()).isEqualTo(400);
565 resource.setCsarVersion("2");
566 when(toscaOperationFacade.getLatestComponentByCsarOrName(ComponentTypeEnum.RESOURCE, resource.getCsarUUID(), resource.getSystemName())).thenReturn(Either.left(resource));
567 bl.validateAndUpdateResourceFromCsar(resource, user, null, null, resource.getUniqueId());
568 } catch (ComponentException e) {
569 assertThat(e.getResponseFormat().getStatus()).isEqualTo(400);
572 /* CREATE validations - start ***********************/
573 // Resource name - start
576 public void testFailedResourceValidations() {
577 testResourceNameExist();
578 testResourceNameEmpty();
579 // testResourceNameExceedsLimit();
580 testResourceNameWrongFormat();
581 testResourceDescExceedsLimitCreate();
582 testResourceDescNotEnglish();
583 testResourceDescriptionEmpty();
584 testResourceDescriptionMissing();
585 testResourceIconMissing();
586 testResourceIconInvalid();
587 testResourceIconExceedsLimit();
588 testResourceTagNotExist();
589 testResourceTagEmpty();
590 testTagsExceedsLimitCreate();
591 testTagsNoServiceName();
594 testContactIdTooLong();
595 testContactIdWrongFormatCreate();
596 testResourceContactIdEmpty();
597 testResourceContactIdMissing();
598 testVendorNameExceedsLimit();
599 testVendorNameWrongFormatCreate();
600 testVendorReleaseWrongFormat();
601 testVendorReleaseExceedsLimitCreate();
602 testResourceVendorModelNumberExceedsLimit();
603 testResourceVendorNameMissing();
604 testResourceVendorReleaseMissing();
605 testResourceCategoryExist();
606 testResourceBadCategoryCreate();
607 testHappyScenarioCostLicenseType();
608 testCostWrongFormatCreate();
609 testLicenseTypeWrongFormatCreate();
610 testResourceTemplateNotExist();
611 testResourceTemplateEmpty();
612 testResourceTemplateInvalid();
615 private void testResourceNameExist() {
616 String resourceName = "alreadyExists";
617 Resource resourceExist = createResourceObject(false);
618 resourceExist.setName(resourceName);
619 resourceExist.getTags()
621 validateUserRoles(Role.ADMIN, Role.DESIGNER);
622 when(toscaOperationFacade
623 .validateComponentNameAndModelExists(resourceName, null, ResourceTypeEnum.VFC, ComponentTypeEnum.RESOURCE))
624 .thenReturn(Either.left(true));
626 bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
627 } catch (ComponentException e) {
628 assertComponentException(e, ActionStatus.COMPONENT_NAME_ALREADY_EXIST,
629 ComponentTypeEnum.RESOURCE.getValue(), resourceName);
633 private void testResourceNameEmpty() {
634 Resource resourceExist = createResourceObject(false);
635 resourceExist.setName(null);
638 bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
639 } catch (ComponentException e) {
640 assertComponentException(e, ActionStatus.MISSING_COMPONENT_NAME, ComponentTypeEnum.RESOURCE.getValue());
644 private void testResourceNameExceedsLimit() {
645 Resource resourceExccedsNameLimit = createResourceObject(false);
646 // 51 chars, the limit is 50
647 String tooLongResourceName = "zCRCAWjqte0DtgcAAMmcJcXeNubeX1p1vOZNTShAHOYNAHvV3iK";
648 resourceExccedsNameLimit.setName(tooLongResourceName);
651 bl.createResource(resourceExccedsNameLimit, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
652 } catch (ComponentException e) {
653 assertComponentException(e, ActionStatus.COMPONENT_NAME_EXCEEDS_LIMIT,
654 ComponentTypeEnum.RESOURCE.getValue(), "" + ValidationUtils.COMPONENT_NAME_MAX_LENGTH);
658 private void testResourceNameWrongFormat() {
659 Resource resource = createResourceObject(false);
661 String nameWrongFormat = "ljg?fd";
662 resource.setName(nameWrongFormat);
665 bl.createResource(resource, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
666 } catch (ComponentException e) {
667 assertComponentException(e, ActionStatus.INVALID_COMPONENT_NAME, ComponentTypeEnum.RESOURCE.getValue());
671 // Resource name - end
672 // Resource description - start
673 private void testResourceDescExceedsLimitCreate() {
674 Resource resourceExccedsDescLimit = createResourceObject(false);
675 // 1025 chars, the limit is 1024
676 String tooLongResourceDesc = "1GUODojQ0sGzKR4NP7e5j82ADQ3KHTVOaezL95qcbuaqDtjZhAQGQ3iFwKAy580K4WiiXs3u3zq7RzXcSASl5fm0RsWtCMOIDP"
677 + "AOf9Tf2xtXxPCuCIMCR5wOGnNTaFxgnJEHAGxilBhZDgeMNHmCN1rMK5B5IRJOnZxcpcL1NeG3APTCIMP1lNAxngYulDm9heFSBc8TfXAADq7703AvkJT0QPpGq2z2P"
678 + "tlikcAnIjmWgfC5Tm7UH462BAlTyHg4ExnPPL4AO8c92VrD7kZSgSqiy73cN3gLT8uigkKrUgXQFGVUFrXVyyQXYtVM6bLBeuCGQf4C2j8lkNg6M0J3PC0PzMRoinOxk"
679 + "Ae2teeCtVcIj4A1KQo3210j8q2v7qQU69Mabsa6DT9FgE4rcrbiFWrg0Zto4SXWD3o1eJA9o29lTg6kxtklH3TuZTmpi5KVp1NFhS1RpnqF83tzv4mZLKsx7Zh1fEgYvRFwx1"
680 + "ar3RolyDfNoZiGBGTMsZzz7RPFBf2hTnLmNqVGQnHKhhGj0Y5s8t2cbqbO2nmHiJb9uaUVrCGypgbAcJL3KPOBfAVW8PcpmNj4yVjI3L4x5zHjmGZbp9vKshEQODcrmcgsYAoKqe"
681 + "uu5u7jk8XVxEfQ0m5qL8UOErXPlJovSmKUmP5B5T0w299zIWDYCzSoNasHpHjOMDLAiDDeHbozUOn9t3Qou00e9POq4RMM0VnIx1H38nJoJZz2XH8CI5YMQe7oTagaxgQTF2aa0qaq2"
682 + "V6nJsfRGRklGjNhFFYP2cS4Xv2IJO9DSX6LTXOmENrGVJJvMOZcvnBaZPfoAHN0LU4i1SoepLzulIxnZBfkUWFJgZ5wQ0Bco2GC1HMqzW21rwy4XHRxXpXbmW8LVyoA1KbnmVmROycU4"
683 + "scTZ62IxIcIWCVeMjBIcTviXULbPUyqlfEPXWr8IMJtpAaELWgyquPClAREMDs2b9ztKmUeXlMccFES1XWbFTrhBHhmmDyVReEgCwfokrUFR13LTUK1k8I6OEHOs";
685 resourceExccedsDescLimit.setDescription(tooLongResourceDesc);
687 bl.createResource(resourceExccedsDescLimit, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
688 } catch (ComponentException e) {
689 assertComponentException(e, ActionStatus.COMPONENT_DESCRIPTION_EXCEEDS_LIMIT,
690 ComponentTypeEnum.RESOURCE.getValue(), "" + ValidationUtils.COMPONENT_DESCRIPTION_MAX_LENGTH);
694 private void testResourceDescNotEnglish() {
695 Resource notEnglish = createResourceObject(false);
697 String notEnglishDesc = "\uC2B5";
698 notEnglish.setDescription(notEnglishDesc);
701 bl.createResource(notEnglish, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
702 } catch (ComponentException e) {
703 assertComponentException(e, ActionStatus.COMPONENT_INVALID_DESCRIPTION,
704 ComponentTypeEnum.RESOURCE.getValue());
708 private void testResourceDescriptionEmpty() {
709 Resource resourceExist = createResourceObject(false);
710 resourceExist.setDescription("");
713 bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
714 } catch (ComponentException e) {
715 assertComponentException(e, ActionStatus.COMPONENT_MISSING_DESCRIPTION,
716 ComponentTypeEnum.RESOURCE.getValue());
720 private void testResourceDescriptionMissing() {
721 Resource resourceExist = createResourceObject(false);
722 resourceExist.setDescription(null);
725 bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
726 } catch (ComponentException e) {
727 assertComponentException(e, ActionStatus.COMPONENT_MISSING_DESCRIPTION,
728 ComponentTypeEnum.RESOURCE.getValue());
731 // Resource description - end
732 // Resource icon start
734 private void testResourceIconMissing() {
735 Resource resourceExist = createResourceObject(false);
736 resourceExist.setIcon(null);
737 when(toscaOperationFacade
738 .validateComponentNameAndModelExists(resourceExist.getName(), null, ResourceTypeEnum.VFC, ComponentTypeEnum.RESOURCE))
739 .thenReturn(Either.left(false));
741 bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
742 } catch (ComponentException e) {
743 assertComponentException(e, ActionStatus.COMPONENT_MISSING_ICON, ComponentTypeEnum.RESOURCE.getValue());
747 private void testResourceIconInvalid() {
748 Resource resourceExist = createResourceObject(false);
749 resourceExist.setIcon("kjk3453^&");
752 bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
753 } catch (ComponentException e) {
754 assertComponentException(e, ActionStatus.COMPONENT_INVALID_ICON, ComponentTypeEnum.RESOURCE.getValue());
758 private void testResourceIconExceedsLimit() {
759 Resource resourceExist = createResourceObject(false);
760 resourceExist.setIcon("dsjfhskdfhskjdhfskjdhkjdhfkshdfksjsdkfhsdfsdfsdfsfsdfsf");
762 bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
763 } catch (ComponentException e) {
764 assertComponentException(e, ActionStatus.COMPONENT_ICON_EXCEEDS_LIMIT,
765 ComponentTypeEnum.RESOURCE.getValue(), "" + ValidationUtils.ICON_MAX_LENGTH);
770 // Resource tags - start
771 private void testResourceTagNotExist() {
772 Resource resourceExist = createResourceObject(false);
773 resourceExist.setTags(null);
775 bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
776 } catch (ComponentException e) {
777 assertComponentException(e, ActionStatus.COMPONENT_MISSING_TAGS);
781 private void testResourceTagEmpty() {
782 Resource resourceExist = createResourceObject(false);
783 resourceExist.setTags(new ArrayList<>());
785 bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
786 } catch (ComponentException e) {
787 assertComponentException(e, ActionStatus.COMPONENT_MISSING_TAGS);
791 private void testTagsExceedsLimitCreate() {
792 Resource resourceExccedsNameLimit = createResourceObject(false);
793 String tag1 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjQ";
794 String tag2 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjW";
795 String tag3 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjE";
796 String tag4 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjb";
797 String tag5 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjr";
798 String tag6 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjf";
799 String tag7 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjg";
800 String tag8 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjd";
801 String tag9 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjf";
802 String tag10 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjg";
803 String tag11 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjh";
804 String tag12 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjj";
805 String tag13 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjk";
806 String tag14 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjs";
807 String tag15 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjz";
808 String tag16 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjx";
809 String tag17 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBj2";
810 String tag18 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBj3";
811 String tag19 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBj4";
812 String tag20 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBj5";
813 String tag21 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBj0";
815 List<String> tagsList = new ArrayList<>();
837 tagsList.add(resourceExccedsNameLimit.getName());
839 resourceExccedsNameLimit.setTags(tagsList);
841 bl.createResource(resourceExccedsNameLimit, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
842 } catch (ComponentException e) {
843 assertComponentException(e, ActionStatus.COMPONENT_TAGS_EXCEED_LIMIT,
844 "" + ValidationUtils.TAG_LIST_MAX_LENGTH);
848 private void testTagsSingleExceedsLimit() {
849 Resource resourceExccedsNameLimit = createResourceObject(false);
850 String tag1 = "afzs2qLBb5X6tZhiunkcEwiFX1qRQY8YZl3y3Du5M5xeQY5Nq9afcFHDZ9HaURw43gH27nAUWM36bMbMylwTFSzzNV8NO4v4ripe6Q15Vc2nPOFI";
851 String tag2 = resourceExccedsNameLimit.getName();
852 List<String> tagsList = new ArrayList<>();
856 resourceExccedsNameLimit.setTags(tagsList);
858 bl.createResource(resourceExccedsNameLimit, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
859 } catch (ComponentException e) {
860 assertComponentException(e, ActionStatus.COMPONENT_SINGLE_TAG_EXCEED_LIMIT,
861 "" + ValidationUtils.TAG_MAX_LENGTH);
865 private void testTagsNoServiceName() {
866 Resource serviceExccedsNameLimit = createResourceObject(false);
867 String tag1 = "afzs2qLBb";
868 List<String> tagsList = new ArrayList<>();
870 serviceExccedsNameLimit.setTags(tagsList);
872 bl.createResource(serviceExccedsNameLimit, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
873 } catch (ComponentException e) {
874 assertComponentException(e, ActionStatus.COMPONENT_INVALID_TAGS_NO_COMP_NAME);
878 private void testInvalidTag() {
879 Resource serviceExccedsNameLimit = createResourceObject(false);
880 String tag1 = "afzs2qLBb%#%";
881 List<String> tagsList = new ArrayList<>();
883 serviceExccedsNameLimit.setTags(tagsList);
885 bl.createResource(serviceExccedsNameLimit, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
886 } catch (ComponentException e) {
887 assertComponentException(e, ActionStatus.INVALID_FIELD_FORMAT, new String[] { "Resource", "tag" });
891 // Resource tags - stop
892 // Resource contact start
894 private void testContactIdTooLong() {
895 Resource resourceContactId = createResourceObject(false);
896 // 59 chars instead of 50
897 String contactIdTooLong = "thisNameIsVeryLongAndExeccedsTheNormalLengthForContactId";
898 resourceContactId.setContactId(contactIdTooLong);
901 bl.createResource(resourceContactId, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
902 } catch (ComponentException e) {
903 assertComponentException(e, ActionStatus.COMPONENT_INVALID_CONTACT, ComponentTypeEnum.RESOURCE.getValue());
907 private void testContactIdWrongFormatCreate() {
908 Resource resourceContactId = createResourceObject(false);
909 // 3 letters and 3 digits and special characters
910 String contactIdFormatWrong = "yrt134!!!";
911 resourceContactId.setContactId(contactIdFormatWrong);
913 bl.createResource(resourceContactId, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
914 } catch (ComponentException e) {
915 assertComponentException(e, ActionStatus.COMPONENT_INVALID_CONTACT, ComponentTypeEnum.RESOURCE.getValue());
919 private void testResourceContactIdEmpty() {
920 Resource resourceExist = createResourceObject(false);
921 resourceExist.setContactId("");
923 bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
924 } catch (ComponentException e) {
925 assertComponentException(e, ActionStatus.COMPONENT_MISSING_CONTACT, ComponentTypeEnum.RESOURCE.getValue());
929 private void testResourceContactIdMissing() {
930 Resource resourceExist = createResourceObject(false);
931 resourceExist.setContactId(null);
933 bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
934 } catch (ComponentException e) {
935 assertComponentException(e, ActionStatus.COMPONENT_MISSING_CONTACT, ComponentTypeEnum.RESOURCE.getValue());
939 private void testVendorNameExceedsLimit() {
940 Resource resourceExccedsVendorNameLimit = createResourceObject(false);
941 String tooLongVendorName = "h1KSyJh9Eh1KSyJh9Eh1KSyJh9Eh1KSyJh9Eh1KSyJh9Eh1KSyJh9Eh1KSyJh9Eh1KSyJh9E";
942 resourceExccedsVendorNameLimit.setVendorName(tooLongVendorName);
944 bl.createResource(resourceExccedsVendorNameLimit, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
945 } catch (ComponentException e) {
946 assertComponentException(e, ActionStatus.VENDOR_NAME_EXCEEDS_LIMIT,
947 "" + ValidationUtils.VENDOR_NAME_MAX_LENGTH);
951 private void testResourceVendorModelNumberExceedsLimit() {
952 Resource resourceExccedsVendorModelNumberLimit = createResourceObject(false);
953 String tooLongVendorModelNumber = "h1KSyJh9Eh1KSyJh9Eh1KSyJh9Eh1KSyJh9Eh1KSyJh9Eh1KSyJh9Eh1KSyJh9Eh1KSyJh9E";
954 resourceExccedsVendorModelNumberLimit.setResourceVendorModelNumber(tooLongVendorModelNumber);
956 bl.createResource(resourceExccedsVendorModelNumberLimit, AuditingActionEnum.CREATE_RESOURCE, user, null,
958 } catch (ComponentException e) {
959 assertComponentException(e, ActionStatus.RESOURCE_VENDOR_MODEL_NUMBER_EXCEEDS_LIMIT,
960 "" + ValidationUtils.RESOURCE_VENDOR_MODEL_NUMBER_MAX_LENGTH);
964 private void testVendorNameWrongFormatCreate() {
965 Resource resource = createResourceObject(false);
967 String nameWrongFormat = "ljg*fd";
968 resource.setVendorName(nameWrongFormat);
970 bl.createResource(resource, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
971 } catch (ComponentException e) {
972 assertComponentException(e, ActionStatus.INVALID_VENDOR_NAME, nameWrongFormat);
976 private void testVendorReleaseWrongFormat() {
977 Resource resource = createResourceObject(false);
979 String vendorReleaseWrongFormat = "1>2";
980 resource.setVendorRelease(vendorReleaseWrongFormat);
982 bl.createResource(resource, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
983 } catch (ComponentException e) {
984 assertComponentException(e, ActionStatus.INVALID_VENDOR_RELEASE, vendorReleaseWrongFormat);
988 private void testVendorReleaseExceedsLimitCreate() {
989 Resource resourceExccedsNameLimit = createResourceObject(false);
990 String tooLongVendorRelease = "h1KSyJh9Eh1KSyJh9Eh1KSyJh9Eh1KSyJh9E";
991 resourceExccedsNameLimit.setVendorRelease(tooLongVendorRelease);
993 bl.createResource(resourceExccedsNameLimit, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
994 } catch (ComponentException e) {
995 assertComponentException(e, ActionStatus.VENDOR_RELEASE_EXCEEDS_LIMIT,
996 "" + ValidationUtils.VENDOR_RELEASE_MAX_LENGTH);
1000 private void testResourceVendorNameMissing() {
1001 Resource resourceExist = createResourceObject(false);
1002 resourceExist.setVendorName(null);
1004 bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
1005 } catch (ComponentException e) {
1006 assertComponentException(e, ActionStatus.MISSING_VENDOR_NAME);
1010 private void testResourceVendorReleaseMissing() {
1011 Resource resourceExist = createResourceObject(false);
1012 resourceExist.setVendorRelease(null);
1014 bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
1015 } catch (ComponentException e) {
1016 assertComponentException(e, ActionStatus.MISSING_VENDOR_RELEASE);
1020 // Resource vendor name/release stop
1022 private void testResourceCategoryExist() {
1023 Resource resourceExist = createResourceObject(false);
1024 resourceExist.setCategories(null);
1026 bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
1027 } catch (ComponentException e) {
1028 assertComponentException(e, ActionStatus.COMPONENT_MISSING_CATEGORY, ComponentTypeEnum.RESOURCE.getValue());
1032 private void testResourceBadCategoryCreate() {
1034 Resource resourceExist = createResourceObject(false);
1035 resourceExist.setCategories(null);
1036 resourceExist.addCategory("koko", "koko");
1038 bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
1039 } catch (ComponentException e) {
1040 assertComponentException(e, ActionStatus.COMPONENT_INVALID_CATEGORY, ComponentTypeEnum.RESOURCE.getValue());
1046 private void testHappyScenarioCostLicenseType() {
1047 Resource createResourceObject = createResourceObject(false);
1048 Resource createResourceObjectAfterCreate = createResourceObject(true);
1049 // Adding cost and licenseType to basic mock
1050 Either<Resource, StorageOperationStatus> eitherCreate = Either.left(createResourceObjectAfterCreate);
1051 when(toscaOperationFacade.createToscaComponent(any(Resource.class))).thenReturn(eitherCreate);
1053 String cost = "123.456";
1054 String licenseType = "User";
1055 createResourceObject.setCost(cost);
1056 createResourceObject.setLicenseType(licenseType);
1057 Resource createdResource;
1059 createdResource = bl.createResource(createResourceObject, AuditingActionEnum.CREATE_RESOURCE, user, null,
1061 createResourceObjectAfterCreate.setCost(cost);
1062 createResourceObjectAfterCreate.setLicenseType(licenseType);
1063 assertThat(createResourceObjectAfterCreate).isEqualTo(createdResource);
1064 } catch (ComponentException e) {
1065 assertThat(new Integer(200)).isEqualTo(e.getResponseFormat()
1070 private void testCostWrongFormatCreate() {
1071 Resource resourceCost = createResourceObject(false);
1072 // Comma instead of fullstop
1073 String cost = "12356,464";
1074 resourceCost.setCost(cost);
1076 bl.createResource(resourceCost, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
1077 } catch (ComponentException e) {
1078 assertComponentException(e, ActionStatus.INVALID_CONTENT);
1083 // License type start
1084 private void testLicenseTypeWrongFormatCreate() {
1085 Resource resourceLicenseType = createResourceObject(false);
1087 String licenseType = "cpu";
1088 resourceLicenseType.setLicenseType(licenseType);
1090 bl.createResource(resourceLicenseType, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
1091 } catch (ComponentException e) {
1092 assertComponentException(e, ActionStatus.INVALID_CONTENT);
1096 // License type stop
1097 // Derived from start
1098 private void testResourceTemplateNotExist() {
1099 Resource resourceExist = createResourceObject(false);
1100 List<String> list = null;
1101 resourceExist.setDerivedFrom(list);
1103 bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
1104 } catch (ComponentException e) {
1105 assertComponentException(e, ActionStatus.MISSING_DERIVED_FROM_TEMPLATE);
1109 private void testResourceTemplateEmpty() {
1110 Resource resourceExist = createResourceObject(false);
1111 resourceExist.setDerivedFrom(new ArrayList<>());
1113 bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
1114 } catch (ComponentException e) {
1115 assertComponentException(e, ActionStatus.MISSING_DERIVED_FROM_TEMPLATE);
1119 private void testResourceTemplateInvalid() {
1120 Resource resourceExist = createResourceObject(false);
1121 ArrayList<String> derivedFrom = new ArrayList<>();
1122 derivedFrom.add("kuku");
1123 resourceExist.setDerivedFrom(derivedFrom);
1125 bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
1126 } catch (ComponentException e) {
1127 assertComponentException(e, ActionStatus.PARENT_RESOURCE_NOT_FOUND);
1131 // Derived from stop
1132 private void assertComponentException(ComponentException e, ActionStatus expectedStatus, String... variables) {
1133 ResponseFormat actualResponse = e.getResponseFormat() != null ? e.getResponseFormat()
1134 : componentsUtils.getResponseFormat(e.getActionStatus(), e.getParams());
1135 assertResponse(actualResponse, expectedStatus, variables);
1138 private void assertResponse(ResponseFormat actualResponse, ActionStatus expectedStatus, String... variables) {
1139 ResponseFormat expectedResponse = responseManager.getResponseFormat(expectedStatus, variables);
1140 assertThat(expectedResponse.getStatus()).isEqualTo(actualResponse.getStatus());
1141 assertThat(expectedResponse.getFormattedMessage()).isEqualTo(actualResponse.getFormattedMessage());
1144 private void assertResponse(Either<Resource, ResponseFormat> createResponse, ActionStatus expectedStatus,
1145 String... variables) {
1146 assertResponse(createResponse.right()
1147 .value(), expectedStatus, variables);
1150 // UPDATE tests - start
1153 public void testResourceNameWrongFormat_UPDATE() {
1154 Resource resource = createResourceObject(true);
1155 Resource updatedResource = createResourceObject(true);
1157 // this is in order to prevent failing with 403 earlier
1158 Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
1159 when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
1161 String nameWrongFormat = "ljg*fd";
1162 updatedResource.setName(nameWrongFormat);
1164 Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
1165 when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
1167 bl.updateResourceMetadata(resource.getUniqueId(), updatedResource, null, user, false);
1168 } catch (ComponentException e) {
1169 assertComponentException(e, ActionStatus.INVALID_COMPONENT_NAME, ComponentTypeEnum.RESOURCE.getValue());
1174 public void testResourceNameAfterCertify_UPDATE() {
1175 Resource resource = createResourceObject(true);
1176 Resource updatedResource = createResourceObject(true);
1178 // this is in order to prevent failing with 403 earlier
1179 Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
1180 // when(resourceOperation.getResource_tx(resource.getUniqueId(),false)).thenReturn(eitherUpdate);
1181 when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
1183 String name = "ljg";
1184 updatedResource.setName(name);
1185 resource.setVersion("1.0");
1187 Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
1188 when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
1190 bl.updateResourceMetadata(resource.getUniqueId(), updatedResource, null, user, false);
1191 } catch (ComponentException e) {
1192 assertComponentException(e, ActionStatus.RESOURCE_NAME_CANNOT_BE_CHANGED);
1197 public void testResourceNameAlreadyExist_UPDATE() {
1198 Resource resource = createResourceObject(true);
1199 Resource updatedResource = createResourceObject(true);
1201 // this is in order to prevent failing with 403 earlier
1202 Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
1203 when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
1205 String resourceName = "alreadyExists";
1206 updatedResource.setName(resourceName);
1207 Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(updatedResource);
1208 when(toscaOperationFacade.updateToscaElement(updatedResource)).thenReturn(dataModelResponse);
1210 bl.updateResourceMetadata(resource.getUniqueId(), updatedResource, null, user, false);
1211 } catch (ComponentException e) {
1212 assertComponentException(e, ActionStatus.COMPONENT_NAME_ALREADY_EXIST,
1213 ComponentTypeEnum.RESOURCE.getValue(), resourceName);
1220 public void testResourceDescExceedsLimit_UPDATE() {
1221 Resource resource = createResourceObject(true);
1222 Resource updatedResource = createResourceObject(true);
1224 // this is in order to prevent failing with 403 earlier
1225 Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
1226 when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
1228 // 1025 chars, the limit is 1024
1229 String tooLongResourceDesc = "1GUODojQ0sGzKR4NP7e5j82ADQ3KHTVOaezL95qcbuaqDtjZhAQGQ3iFwKAy580K4WiiXs3u3zq7RzXcSASl5fm0RsWtCMOIDP"
1230 + "AOf9Tf2xtXxPCuCIMCR5wOGnNTaFxgnJEHAGxilBhZDgeMNHmCN1rMK5B5IRJOnZxcpcL1NeG3APTCIMP1lNAxngYulDm9heFSBc8TfXAADq7703AvkJT0QPpGq2z2P"
1231 + "tlikcAnIjmWgfC5Tm7UH462BAlTyHg4ExnPPL4AO8c92VrD7kZSgSqiy73cN3gLT8uigkKrUgXQFGVUFrXVyyQXYtVM6bLBeuCGQf4C2j8lkNg6M0J3PC0PzMRoinOxk"
1232 + "Ae2teeCtVcIj4A1KQo3210j8q2v7qQU69Mabsa6DT9FgE4rcrbiFWrg0Zto4SXWD3o1eJA9o29lTg6kxtklH3TuZTmpi5KVp1NFhS1RpnqF83tzv4mZLKsx7Zh1fEgYvRFwx1"
1233 + "ar3RolyDfNoZiGBGTMsZzz7RPFBf2hTnLmNqVGQnHKhhGj0Y5s8t2cbqbO2nmHiJb9uaUVrCGypgbAcJL3KPOBfAVW8PcpmNj4yVjI3L4x5zHjmGZbp9vKshEQODcrmcgsYAoKqe"
1234 + "uu5u7jk8XVxEfQ0m5qL8UOErXPlJovSmKUmP5B5T0w299zIWDYCzSoNasHpHjOMDLAiDDeHbozUOn9t3Qou00e9POq4RMM0VnIx1H38nJoJZz2XH8CI5YMQe7oTagaxgQTF2aa0qaq2"
1235 + "V6nJsfRGRklGjNhFFYP2cS4Xv2IJO9DSX6LTXOmENrGVJJvMOZcvnBaZPfoAHN0LU4i1SoepLzulIxnZBfkUWFJgZ5wQ0Bco2GC1HMqzW21rwy4XHRxXpXbmW8LVyoA1KbnmVmROycU4"
1236 + "scTZ62IxIcIWCVeMjBIcTviXULbPUyqlfEPXWr8IMJtpAaELWgyquPClAREMDs2b9ztKmUeXlMccFES1XWbFTrhBHhmmDyVReEgCwfokrUFR13LTUK1k8I6OEHOs";
1237 updatedResource.setDescription(tooLongResourceDesc);
1238 Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
1239 when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
1241 bl.updateResourceMetadata(resource.getUniqueId(), updatedResource, null, user, false);
1242 } catch (ComponentException e) {
1243 assertComponentException(e, ActionStatus.COMPONENT_DESCRIPTION_EXCEEDS_LIMIT,
1244 ComponentTypeEnum.RESOURCE.getValue(), "" + ValidationUtils.COMPONENT_DESCRIPTION_MAX_LENGTH);
1249 public void testIconWrongFormat_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);
1258 String icon = "icon.jpg";
1259 updatedResource.setIcon(icon);
1260 Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
1261 when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
1263 bl.updateResourceMetadata(resource.getUniqueId(), updatedResource, null, user, false);
1264 } catch (ComponentException e) {
1265 assertComponentException(e, ActionStatus.COMPONENT_INVALID_ICON, ComponentTypeEnum.RESOURCE.getValue());
1270 public void testIconAfterCertify_UPDATE() {
1271 Resource resource = createResourceObject(true);
1272 Resource updatedResource = createResourceObject(true);
1274 // this is in order to prevent failing with 403 earlier
1275 Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
1276 when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
1279 String icon = "icon";
1280 updatedResource.setIcon(icon);
1282 resource.setVersion("1.0");
1284 Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
1285 when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
1287 bl.updateResourceMetadata(resource.getUniqueId(), updatedResource, null, user, false);
1288 } catch (ComponentException e) {
1289 assertComponentException(e, ActionStatus.RESOURCE_ICON_CANNOT_BE_CHANGED);
1294 public void testTagsExceedsLimit_UPDATE() {
1295 Resource resource = createResourceObject(true);
1296 Resource updatedResource = createResourceObject(true);
1298 // this is in order to prevent failing with 403 earlier
1299 Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
1300 when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
1302 String tag1 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjQ";
1303 String tag2 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjW";
1304 String tag3 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjE";
1305 String tag4 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjb";
1306 String tag5 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjr";
1307 String tag6 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjf";
1308 String tag7 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjg";
1309 String tag8 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjd";
1310 String tag9 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjf";
1311 String tag10 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjg";
1312 String tag11 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjh";
1313 String tag12 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjj";
1314 String tag13 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjk";
1315 String tag14 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjs";
1316 String tag15 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjz";
1317 String tag16 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBjx";
1318 String tag17 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBj2";
1319 String tag18 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBj3";
1320 String tag19 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBj4";
1321 String tag20 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBj5";
1322 String tag21 = "I63llMSEF12FntTwpMt64JhopkjQZzv5KS7mBoRku42PYLrBj0";
1324 List<String> tagsList = new ArrayList<>();
1334 tagsList.add(tag10);
1335 tagsList.add(tag11);
1336 tagsList.add(tag12);
1337 tagsList.add(tag13);
1338 tagsList.add(tag14);
1339 tagsList.add(tag15);
1340 tagsList.add(tag16);
1341 tagsList.add(tag17);
1342 tagsList.add(tag18);
1343 tagsList.add(tag19);
1344 tagsList.add(tag20);
1345 tagsList.add(tag21);
1346 tagsList.add(resource.getName());
1348 updatedResource.setTags(tagsList);
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.COMPONENT_TAGS_EXCEED_LIMIT,
1355 "" + ValidationUtils.TAG_LIST_MAX_LENGTH);
1360 public void testVendorNameWrongFormat_UPDATE() {
1361 Resource resource = createResourceObject(true);
1362 Resource updatedResource = createResourceObject(true);
1364 // this is in order to prevent failing with 403 earlier
1365 Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
1366 when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
1369 String nameWrongFormat = "ljg*fd";
1370 updatedResource.setVendorName(nameWrongFormat);
1371 Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
1372 when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
1374 bl.updateResourceMetadata(resource.getUniqueId(), updatedResource, null, user, false);
1375 } catch (ComponentException e) {
1376 assertComponentException(e, ActionStatus.INVALID_VENDOR_NAME, nameWrongFormat);
1381 public void testVendorNameWrongFormat() {
1382 Resource resource = createResourceObject(true);
1383 Resource updatedResource = createResourceObject(true);
1385 // this is in order to prevent failing with 403 earlier
1386 Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
1387 when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
1390 String nameWrongFormat = "ljg*fd";
1391 updatedResource.setVendorName(nameWrongFormat);
1392 resource.setVersion("1.0");
1394 Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
1395 when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
1397 bl.updateResourceMetadata(resource.getUniqueId(), updatedResource, null, user, false);
1398 } catch (ComponentException e) {
1399 assertComponentException(e, ActionStatus.INVALID_VENDOR_NAME, nameWrongFormat);
1404 public void testVendorReleaseExceedsLimit_UPDATE() {
1405 Resource resource = createResourceObject(true);
1406 Resource updatedResource = createResourceObject(true);
1408 // this is in order to prevent failing with 403 earlier
1409 Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
1410 when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
1411 // 129 chars, the limit is 128
1412 String tooLongVendorRelease = "h1KSyJh9EspI8SPwAGu4VETfqWejeanuB1PCJBxJmJncYnrW0lnsEFFVRIukRJkwlOVnZCy8p38tjhANeZq3BGMHIawWR6ICl8Wi9mikRYALWgvJug00JrlQ0iPVKPLxy";
1413 updatedResource.setVendorRelease(tooLongVendorRelease);
1414 Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
1415 when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
1417 bl.updateResourceMetadata(resource.getUniqueId(), updatedResource, null, user, false);
1418 } catch (ComponentException e) {
1419 assertComponentException(e, ActionStatus.VENDOR_RELEASE_EXCEEDS_LIMIT,
1420 "" + ValidationUtils.VENDOR_RELEASE_MAX_LENGTH);
1425 public void testResourceBadCategory_UPDATE() {
1426 Resource resource = createResourceObject(true);
1427 Resource updatedResource = createResourceObject(true);
1429 // this is in order to prevent failing with 403 earlier
1430 Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
1431 when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
1433 String resourceId = resource.getUniqueId();
1434 String badCategory = "ddfds";
1435 updatedResource.setCategories(null);
1436 updatedResource.addCategory(badCategory, "fikt");
1437 Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
1438 when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
1440 bl.updateResourceMetadata(resourceId, updatedResource, null, user, false);
1441 } catch (ComponentException e) {
1442 assertComponentException(e, ActionStatus.COMPONENT_INVALID_CATEGORY, ComponentTypeEnum.RESOURCE.getValue());
1446 @Test(expected = ComponentException.class)
1447 public void createResourceFromCsarTest() {
1448 bl.createResourceFromCsar(resourceResponse, user, new HashMap<>(), "");
1452 public void testCreateResourceFromCsarWithModel() throws URISyntaxException, ZipException {
1454 final File csarFile = new File(
1455 ResourceBusinessLogicTest.class.getClassLoader().getResource("csars/nonOnapCsar.csar").toURI());
1456 final Map<String, byte[]> csar = ZipUtils.readZip(csarFile, false);
1458 String resourceYml = new String(csar.get("Definitions/my_vnf.yaml"));
1460 YamlTemplateParsingHandler yamlTemplateParser = new YamlTemplateParsingHandler(mockJanusGraphDao, null, Mockito.mock(AnnotationBusinessLogic.class), null);
1461 final ParsedToscaYamlInfo parsedToscaYamlInfo = yamlTemplateParser.parseResourceInfoFromYAML("Definitions/my_vnf.yml", resourceYml, Collections.EMPTY_MAP, Collections.EMPTY_MAP, "myVnf", resourceResponse);
1463 when(toscaOperationFacade.getLatestByToscaResourceName(anyString(), any())).thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
1464 Resource vduCp = new Resource();
1465 vduCp.setToscaResourceName("tosca.nodes.nfv.VduCp");
1466 vduCp.setState(LifecycleStateEnum.CERTIFIED);
1467 vduCp.setUniqueId("tosca.nodes.nfv.VduCp");
1468 vduCp.setProperties(new ArrayList<>());
1469 Map<String, List<RequirementDefinition>> requirements = new HashMap<>();
1470 RequirementDefinition req = new RequirementDefinition();
1471 req.setName("virtual_link");
1472 List<RequirementDefinition> listReqs = new ArrayList<>();
1474 requirements.put("tosca.nodes.nfv.VduCp", listReqs);
1475 vduCp.setRequirements(requirements);
1476 PropertyDefinition bitrateProp = new PropertyDefinition();
1477 bitrateProp.setName("bitrate_requirement");
1478 bitrateProp.setType("integer");
1479 vduCp.getProperties().add(bitrateProp);
1480 PropertyDefinition virtNiProp = new PropertyDefinition();
1481 virtNiProp.setName("virtual_network_interface_requirements");
1482 virtNiProp.setType("list");
1483 vduCp.getProperties().add(virtNiProp);
1484 PropertyDefinition descriptionProp = new PropertyDefinition();
1485 descriptionProp.setName("description");
1486 descriptionProp.setType("string");
1487 vduCp.getProperties().add(descriptionProp);
1488 PropertyDefinition roleProp = new PropertyDefinition();
1489 roleProp.setName("role");
1490 roleProp.setType("string");
1491 vduCp.getProperties().add(roleProp);
1492 when(toscaOperationFacade.getByToscaResourceNameMatchingVendorRelease("tosca.nodes.nfv.VduCp", "1.0.0")).thenReturn(Either.left(vduCp));
1495 when(yamlTemplateParsingHandler.parseResourceInfoFromYAML(any(), any(), any(), any(), any(), any())).thenReturn(parsedToscaYamlInfo);
1497 UploadComponentInstanceInfo uploadComponentInstanceInfo = new UploadComponentInstanceInfo();
1498 uploadComponentInstanceInfo.setType("myType");
1499 resourceResponse.setUniqueId("myVnf");
1500 resourceResponse.setName("myVnf");
1501 resourceResponse.setSystemName("myVnf");
1502 resourceResponse.setModel("testModel");
1503 resourceResponse.setResourceType(ResourceTypeEnum.VF);
1504 resourceResponse.setProperties(new ArrayList<>());
1506 Resource derivedFrom = new Resource();
1507 List<PropertyDefinition> properties = new ArrayList<>();
1508 PropertyDefinition baseTypeProp = new PropertyDefinition();
1509 baseTypeProp.setName("propInBase");
1510 baseTypeProp.setType("string");
1511 properties.add(baseTypeProp);
1512 derivedFrom.setProperties(properties );
1513 when(genericTypeBusinessLogic.fetchDerivedFromGenericType(any(), eq("tosca.nodes.nfv.VNF"))).thenReturn(Either.left(derivedFrom));
1515 when(toscaOperationFacade
1516 .validateComponentNameAndModelExists("myVnf", "testModel", ResourceTypeEnum.VF, ComponentTypeEnum.RESOURCE)).thenReturn(Either.left(false));
1518 when(toscaOperationFacade.addPropertyToComponent(any(), any(), any())).thenReturn(Either.left(new PropertyDefinition()));
1519 when(toscaOperationFacade.associateComponentInstancePropertiesToComponent(any(), any())).thenReturn(Either.left(Collections.emptyMap()));
1520 when(toscaOperationFacade.associateArtifactsToInstances(any(), any())).thenReturn(StorageOperationStatus.OK);
1521 when(toscaOperationFacade.associateDeploymentArtifactsToInstances(any(), any(), any())).thenReturn(StorageOperationStatus.OK);
1522 when(toscaOperationFacade.associateInstAttributeToComponentToInstances(any(), any())).thenReturn(StorageOperationStatus.OK);
1523 when(toscaOperationFacade.associateResourceInstances(any(Component.class), anyString(), anyList())).thenReturn(Either.left(Collections.EMPTY_LIST));
1524 when(applicationDataTypeCache.getAll(resourceResponse.getModel())).thenReturn(Either.left(emptyDataTypes));
1526 doAnswer(invocation -> {
1527 Map<ComponentInstance, Map<String, List<RequirementDefinition>>> instReqs = invocation.getArgument(1);
1528 for (final Entry<ComponentInstance, Map<String, List<RequirementDefinition>>> m: instReqs.entrySet()) {
1529 m.getKey().setRequirements(m.getValue());
1531 return StorageOperationStatus.OK;
1533 when(toscaOperationFacade).associateOrAddCalculatedCapReq(any(), any(), any());
1536 when(toscaOperationFacade.updateCalculatedCapabilitiesRequirements(any(), any(), any())).thenReturn(StorageOperationStatus.OK);
1537 when(groupBusinessLogic.validateUpdateVfGroupNames(any(), any())).thenReturn(Either.left(Collections.EMPTY_MAP));
1539 ComponentInstance ci = new ComponentInstance();
1540 List<ComponentInstance> cis = new ArrayList<>();
1542 doAnswer(invocation -> {
1543 List<ComponentInstance> componentInstances = new ArrayList<ComponentInstance>(((Map<ComponentInstance, Resource>)invocation.getArgument(1)).keySet());
1544 ((Resource)invocation.getArgument(0)).setComponentInstances(componentInstances);
1546 }).when(toscaOperationFacade).associateComponentInstancesToComponent(any(), any(), eq(false), eq(false));
1548 doAnswer(invocation -> {
1549 return Either.left(invocation.getArgument(0));
1550 }).when(csarArtifactsAndGroupsBusinessLogic).deleteVFModules(any(Resource.class), any(CsarInfo.class), eq(true), eq(false));
1552 doAnswer(invocation -> {
1553 return Either.left(resourceResponse);
1554 }).when(toscaOperationFacade).getToscaFullElement("myVnf");
1557 Resource result = bl.createResourceFromCsar(resourceResponse, user, csar, "1234");
1559 assertEquals("myDomain.myVnf", result.getToscaResourceName());
1560 List<String> propIds = result.getProperties().stream().map(prop -> prop.getUniqueId()).collect(Collectors.toList());
1561 assertTrue(propIds.contains("myVnf.propInBase"));
1562 assertTrue(propIds.contains("myVnf.descriptor_id"));
1563 assertTrue(propIds.contains("myVnf.descriptor_version"));
1564 assertTrue(propIds.contains("myVnf.flavour_description"));
1565 assertTrue(propIds.contains("myVnf.flavour_id"));
1566 assertTrue(propIds.contains("myVnf.product_name"));
1567 assertTrue(propIds.contains("myVnf.provider"));
1568 assertTrue(propIds.contains("myVnf.software_version"));
1569 assertTrue(propIds.contains("myVnf.vnfm_info"));
1571 final List<String> reqsName = new ArrayList<>();
1573 final List<ComponentInstance> cisWithExtReq = result.getComponentInstances().stream().filter(instance -> instance.getRequirements().get("tosca.nodes.nfv.VduCp").get(0).isExternal()).collect(Collectors.toList());
1574 cisWithExtReq.forEach(instance -> reqsName.add(instance.getRequirements().get("tosca.nodes.nfv.VduCp").get(0).getExternalName()));
1575 assertEquals(3, cisWithExtReq.size());
1579 public void testResourceCategoryAfterCertify_UPDATE() {
1580 Resource resource = createResourceObject(true);
1581 Resource updatedResource = createResourceObject(true);
1583 // this is in order to prevent failing with 403 earlier
1584 Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
1585 when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
1587 String resourceId = resource.getUniqueId();
1588 updatedResource.setCategories(null);
1589 updatedResource.addCategory(RESOURCE_CATEGORY1, UPDATED_SUBCATEGORY);
1590 resource.setVersion("1.0");
1592 Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
1593 when(toscaOperationFacade.updateToscaElement(updatedResource)).thenReturn(dataModelResponse);
1595 bl.updateResourceMetadata(resourceId, updatedResource, null, user, false);
1596 } catch (ComponentException e) {
1597 assertComponentException(e, ActionStatus.RESOURCE_CATEGORY_CANNOT_BE_CHANGED);
1601 // Derived from start
1603 public void testResourceTemplateNotExist_UPDATE() {
1604 Resource resource = createResourceObject(true);
1605 Resource updatedResource = createResourceObject(true);
1607 // this is in order to prevent failing with 403 earlier
1608 Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
1609 when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
1610 String resourceId = resource.getUniqueId();
1612 List<String> list = null;
1613 updatedResource.setDerivedFrom(list);
1614 Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
1615 when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
1617 bl.updateResourceMetadata(resourceId, updatedResource, null, user, false);
1618 } catch (ComponentException e) {
1619 assertComponentException(e, ActionStatus.MISSING_DERIVED_FROM_TEMPLATE);
1624 public void testResourceTemplateEmpty_UPDATE() {
1625 Resource resource = createResourceObject(true);
1626 Resource updatedResource = createResourceObject(true);
1627 String resourceId = resource.getUniqueId();
1629 // this is in order to prevent failing with 403 earlier
1630 Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
1631 when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
1633 updatedResource.setDerivedFrom(new ArrayList<>());
1634 Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
1635 when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
1637 bl.updateResourceMetadata(resourceId, updatedResource, null, user, false);
1638 } catch (ComponentException e) {
1639 assertComponentException(e, ActionStatus.MISSING_DERIVED_FROM_TEMPLATE);
1644 public void testResourceTemplateInvalid_UPDATE() {
1645 Resource resource = createResourceObject(true);
1646 Resource updatedResource = createResourceObject(true);
1647 String resourceId = resource.getUniqueId();
1649 // this is in order to prevent failing with 403 earlier
1650 Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
1651 when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
1653 ArrayList<String> derivedFrom = new ArrayList<>();
1654 derivedFrom.add("kuku");
1655 updatedResource.setDerivedFrom(derivedFrom);
1656 Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
1657 when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
1659 bl.updateResourceMetadata(resourceId, updatedResource, null, user, false);
1660 } catch (ComponentException e) {
1661 assertComponentException(e, ActionStatus.PARENT_RESOURCE_NOT_FOUND);
1666 public void testResourceTemplateCertify_UPDATE_HAPPY() {
1667 Resource resource = createResourceObject(true);
1668 Resource updatedResource = createResourceObject(true);
1669 String resourceId = resource.getUniqueId();
1671 // this is in order to prevent failing with 403 earlier
1672 Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
1673 when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
1675 Either<Boolean, StorageOperationStatus> isToscaNameExtending = Either.left(true);
1676 when(toscaOperationFacade.validateToscaResourceNameExtends(anyString(), anyString(), anyString()))
1677 .thenReturn(isToscaNameExtending);
1679 Either<Map<String, PropertyDefinition>, StorageOperationStatus> findPropertiesOfNode = Either
1680 .left(new HashMap<>());
1681 when(propertyOperation.deleteAllPropertiesAssociatedToNode(any(NodeTypeEnum.class), anyString()))
1682 .thenReturn(findPropertiesOfNode);
1684 resource.setVersion("1.0");
1686 ArrayList<String> derivedFrom = new ArrayList<>();
1687 derivedFrom.add("tosca.nodes.Root");
1688 updatedResource.setDerivedFrom(derivedFrom);
1689 Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(updatedResource);
1690 when(toscaOperationFacade.updateToscaElement(updatedResource)).thenReturn(dataModelResponse);
1691 Resource createdResource = bl.updateResourceMetadata(resourceId, updatedResource, null, user, false);
1692 assertThat(createdResource).isNotNull();
1696 public void testResourceTemplateCertify_UPDATE_SAD() {
1697 Resource resource = createResourceObject(true);
1698 Resource updatedResource = createResourceObject(true);
1699 String resourceId = resource.getUniqueId();
1701 // this is in order to prevent failing with 403 earlier
1702 Either<Component, StorageOperationStatus> eitherUpdate = Either.left(setCanWorkOnResource(resource));
1703 when(toscaOperationFacade.getToscaElement(resource.getUniqueId())).thenReturn(eitherUpdate);
1705 Either<Boolean, StorageOperationStatus> isToscaNameExtending = Either.left(false);
1706 when(toscaOperationFacade.validateToscaResourceNameExtends(anyString(), anyString(), anyString()))
1707 .thenReturn(isToscaNameExtending);
1709 resource.setVersion("1.0");
1711 ArrayList<String> derivedFrom = new ArrayList<>();
1712 derivedFrom.add("tosca.nodes.Root");
1713 updatedResource.setDerivedFrom(derivedFrom);
1714 Either<Resource, StorageOperationStatus> dataModelResponse = Either.left(resource);
1715 when(toscaOperationFacade.updateToscaElement(updatedResource)).thenReturn(dataModelResponse);
1716 Either<Map<String, PropertyDefinition>, StorageOperationStatus> findPropertiesOfNode = Either
1717 .left(new HashMap<>());
1718 when(propertyOperation.deleteAllPropertiesAssociatedToNode(any(NodeTypeEnum.class), anyString()))
1719 .thenReturn(findPropertiesOfNode);
1722 bl.updateResourceMetadata(resourceId, updatedResource, null, user, false);
1723 } catch (ComponentException e) {
1724 assertComponentException(e, ActionStatus.PARENT_RESOURCE_DOES_NOT_EXTEND);
1727 // Derived from stop
1730 public void createOrUpdateResourceAlreadyCheckout() {
1732 Resource resourceExist = createResourceObject(false);
1733 validateUserRoles(Role.ADMIN, Role.DESIGNER);
1734 when(toscaOperationFacade
1735 .validateComponentNameAndModelExists(resourceExist.getName(), null, ResourceTypeEnum.VFC, ComponentTypeEnum.RESOURCE))
1736 .thenReturn(Either.left(false));
1737 Resource createdResource = bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null,
1739 createdResource.setLastUpdaterUserId(user.getUserId());
1740 assertThat(createdResource).isNotNull();
1741 Either<Resource, StorageOperationStatus> getLatestResult = Either.left(createdResource);
1742 Either<Component, StorageOperationStatus> getCompLatestResult = Either.left(createdResource);
1743 when(toscaOperationFacade.getLatestByToscaResourceName(resourceExist.getToscaResourceName(), null))
1744 .thenReturn(getCompLatestResult);
1745 when(toscaOperationFacade.getLatestByToscaResourceNameAndModel(resourceExist.getToscaResourceName(), null))
1746 .thenReturn(getCompLatestResult);
1747 when(toscaOperationFacade.overrideComponent(any(Resource.class), any(Resource.class)))
1748 .thenReturn(getLatestResult);
1750 Resource resourceToUpdtae = createResourceObject(false);
1752 ImmutablePair<Resource, ActionStatus> createOrUpdateResource = bl
1753 .createOrUpdateResourceByImport(resourceToUpdtae, user, false, false, false, null, null, false);
1754 assertNotNull(createOrUpdateResource);
1756 Mockito.verify(toscaOperationFacade, Mockito.times(1))
1757 .overrideComponent(any(Resource.class), any(Resource.class));
1758 Mockito.verify(lifecycleBl, Mockito.times(0))
1759 .changeState(anyString(), eq(user), eq(LifeCycleTransitionEnum.CHECKOUT),
1760 any(LifecycleChangeInfoWithAction.class), Mockito.anyBoolean(), Mockito.anyBoolean());
1765 public void createOrUpdateResourceCertified() {
1767 Resource resourceExist = createResourceObject(false);
1768 when(toscaOperationFacade
1769 .validateComponentNameAndModelExists(resourceExist.getName(), null, ResourceTypeEnum.VFC, ComponentTypeEnum.RESOURCE))
1770 .thenReturn(Either.left(false));
1771 validateUserRoles(Role.ADMIN, Role.DESIGNER);
1772 Resource createdResource = bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null,
1775 assertThat(createdResource).isNotNull();
1776 createdResource.setLifecycleState(LifecycleStateEnum.CERTIFIED);
1777 createdResource.setVersion("1.0");
1779 Either<Resource, StorageOperationStatus> getLatestResult = Either.left(createdResource);
1780 Either<Component, StorageOperationStatus> getCompLatestResult = Either.left(createdResource);
1781 when(toscaOperationFacade.getLatestByToscaResourceNameAndModel(resourceExist.getToscaResourceName(), null))
1782 .thenReturn(getCompLatestResult);
1783 when(toscaOperationFacade.overrideComponent(any(Resource.class), any(Resource.class)))
1784 .thenReturn(getLatestResult);
1786 when(lifecycleBl.changeState(anyString(), eq(user), eq(LifeCycleTransitionEnum.CHECKOUT),
1787 any(LifecycleChangeInfoWithAction.class), Mockito.anyBoolean(), Mockito.anyBoolean()))
1788 .thenReturn(Either.left(createdResource));
1790 Resource resourceToUpdtae = createResourceObject(false);
1792 ImmutablePair<Resource, ActionStatus> createOrUpdateResource = bl
1793 .createOrUpdateResourceByImport(resourceToUpdtae, user, false, false, false, null, null, false);
1794 assertNotNull(createOrUpdateResource);
1796 Mockito.verify(toscaOperationFacade, Mockito.times(1))
1797 .overrideComponent(any(Resource.class), any(Resource.class));
1798 Mockito.verify(lifecycleBl, Mockito.times(1))
1799 .changeState(anyString(), eq(user), eq(LifeCycleTransitionEnum.CHECKOUT),
1800 any(LifecycleChangeInfoWithAction.class), Mockito.anyBoolean(), Mockito.anyBoolean());
1805 public void createOrUpdateResourceNotExist() {
1806 Resource resourceToUpdtae = createResourceObject(false);
1808 Either<Component, StorageOperationStatus> getLatestResult = Either.right(StorageOperationStatus.NOT_FOUND);
1809 when(toscaOperationFacade.getLatestByName(resourceToUpdtae.getName(), null)).thenReturn(getLatestResult);
1810 when(toscaOperationFacade.getLatestByToscaResourceNameAndModel(resourceToUpdtae.getToscaResourceName(), null))
1811 .thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
1812 when(toscaOperationFacade
1813 .validateComponentNameAndModelExists(resourceToUpdtae.getName(), null, ResourceTypeEnum.VFC, ComponentTypeEnum.RESOURCE))
1814 .thenReturn(Either.left(false));
1816 ImmutablePair<Resource, ActionStatus> createOrUpdateResource = bl
1817 .createOrUpdateResourceByImport(resourceToUpdtae, user, false, false, false, null, null, false);
1818 assertThat(createOrUpdateResource).isNotNull();
1820 Mockito.verify(toscaOperationFacade, times(1))
1821 .createToscaComponent(resourceToUpdtae);
1822 Mockito.verify(toscaOperationFacade, Mockito.times(0))
1823 .overrideComponent(any(Resource.class), any(Resource.class));
1824 Mockito.verify(lifecycleBl, Mockito.times(0))
1825 .changeState(anyString(), eq(user), eq(LifeCycleTransitionEnum.CHECKOUT),
1826 any(LifecycleChangeInfoWithAction.class), Mockito.anyBoolean(), Mockito.anyBoolean());
1831 public void testIfNodeTypeNameHasValidPrefix() {
1832 final List<String> definedNodeTypeNamespaceList = ConfigurationManager.getConfigurationManager()
1833 .getConfiguration().getDefinedResourceNamespace();
1835 definedNodeTypeNamespaceList.parallelStream().forEach(validNodeTypePrefix -> {
1836 final String nodeName = validNodeTypePrefix + "." + "abc";
1837 final Optional<String> result = bl.validateNodeTypeNamePrefix(nodeName, definedNodeTypeNamespaceList);
1838 assertTrue(result.isPresent());
1843 public void updateNestedResource_typeIsNew() throws IOException {
1844 Resource resourceToUpdate = createResourceObject(false);
1845 String nodeName = Constants.USER_DEFINED_RESOURCE_NAMESPACE_PREFIX + "." + "abc";
1846 String jsonContent = ImportUtilsTest.loadFileNameToJsonString("normative-types-new-webServer.yml");
1847 CsarInfo csarInfo = new CsarInfo(user, "abcd1234", new HashMap<>(), RESOURCE_NAME, "template name", jsonContent,
1849 String nestedResourceName = bl.buildNestedToscaResourceName(resourceToUpdate.getResourceType()
1850 .name(), csarInfo.getVfResourceName(), nodeName)
1852 when(toscaOperationFacade.getLatestByName(resourceToUpdate.getName(), null))
1853 .thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
1854 when(toscaOperationFacade.getLatestByToscaResourceName(resourceToUpdate.getToscaResourceName(), null))
1855 .thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
1856 when(toscaOperationFacade.getLatestByToscaResourceName(nestedResourceName, null))
1857 .thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
1859 when(toscaOperationFacade.getLatestByToscaResourceNameAndModel(resourceToUpdate.getToscaResourceName(), null))
1860 .thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
1861 when(toscaOperationFacade
1862 .validateComponentNameAndModelExists(resourceToUpdate.getName(), null, ResourceTypeEnum.VFC, ComponentTypeEnum.RESOURCE))
1863 .thenReturn(Either.left(false));
1865 ImmutablePair<Resource, ActionStatus> createOrUpdateResource = bl
1866 .createOrUpdateResourceByImport(resourceToUpdate, user, false, false, false, csarInfo, nodeName, false);
1867 assertThat(createOrUpdateResource).isNotNull();
1869 Mockito.verify(toscaOperationFacade, times(1))
1870 .createToscaComponent(resourceToUpdate);
1871 Mockito.verify(toscaOperationFacade, times(0))
1872 .overrideComponent(any(Resource.class), any(Resource.class));
1873 Mockito.verify(lifecycleBl, times(0))
1874 .changeState(anyString(), eq(user), eq(LifeCycleTransitionEnum.CHECKOUT),
1875 any(LifecycleChangeInfoWithAction.class), Mockito.anyBoolean(), Mockito.anyBoolean());
1879 public void updateNestedResource_typeExists() throws IOException {
1881 Resource resourceToUpdate = createResourceObject(false);
1882 setCanWorkOnResource(resourceResponse);
1883 String nodeName = Constants.USER_DEFINED_RESOURCE_NAMESPACE_PREFIX + "." + "abc";
1884 String jsonContent = ImportUtilsTest.loadFileNameToJsonString("normative-types-new-webServer.yml");
1885 CsarInfo csarInfo = new CsarInfo(user, "abcd1234", new HashMap<>(), RESOURCE_NAME, "template name", jsonContent,
1887 String nestedResourceName = bl.buildNestedToscaResourceName(resourceToUpdate.getResourceType()
1888 .name(), csarInfo.getVfResourceName(), nodeName)
1890 when(toscaOperationFacade.getLatestByName(resourceToUpdate.getName(), null))
1891 .thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
1892 when(toscaOperationFacade.getLatestByToscaResourceName(resourceToUpdate.getToscaResourceName(), null))
1893 .thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
1894 when(toscaOperationFacade.getLatestByToscaResourceNameAndModel(resourceToUpdate.getToscaResourceName(), null))
1895 .thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
1896 when(toscaOperationFacade.getLatestByToscaResourceName(nestedResourceName, null))
1897 .thenReturn(Either.left(resourceResponse));
1898 when(toscaOperationFacade.overrideComponent(any(Resource.class), any(Resource.class)))
1899 .thenReturn(Either.left(resourceResponse));
1901 ImmutablePair<Resource, ActionStatus> createOrUpdateResource = bl
1902 .createOrUpdateResourceByImport(resourceToUpdate, user, false, false, false, csarInfo, nodeName, false);
1903 assertThat(createOrUpdateResource).isNotNull();
1904 Mockito.verify(toscaOperationFacade, times(1))
1905 .overrideComponent(any(Resource.class), any(Resource.class));
1906 Mockito.verify(lifecycleBl, times(0))
1907 .changeState(anyString(), eq(user), eq(LifeCycleTransitionEnum.CHECKOUT),
1908 any(LifecycleChangeInfoWithAction.class), Mockito.anyBoolean(), Mockito.anyBoolean());
1912 public void testValidatePropertiesDefaultValues_SuccessfullWithoutProperties() {
1913 Resource basic = createResourceObject(true);
1915 Boolean validatePropertiesDefaultValues = bl.validatePropertiesDefaultValues(basic);
1916 assertTrue(validatePropertiesDefaultValues);
1920 public void testValidatePropertiesDefaultValues_SuccessfullWithProperties() {
1921 Resource basic = createResourceObject(true);
1922 PropertyDefinition property = new PropertyDefinition();
1923 property.setName("myProperty");
1924 property.setType(ToscaPropertyType.INTEGER.getType());
1925 property.setDefaultValue("1");
1926 List<PropertyDefinition> properties = new ArrayList<>();
1927 properties.add(property);
1928 basic.setProperties(properties);
1929 when(propertyOperation.isPropertyTypeValid(property, null)).thenReturn(true);
1930 when(propertyOperation.isPropertyDefaultValueValid(property, emptyDataTypes)).thenReturn(true);
1931 Boolean validatePropertiesDefaultValues = bl.validatePropertiesDefaultValues(basic);
1932 assertTrue(validatePropertiesDefaultValues);
1935 @Test(expected = ComponentException.class)
1936 public void testValidatePropertiesDefaultValues_FailedWithProperties() {
1937 Resource basic = createResourceObject(true);
1938 PropertyDefinition property = new PropertyDefinition();
1939 property.setName("myProperty");
1940 property.setType(ToscaPropertyType.INTEGER.getType());
1941 property.setDefaultValue("1.5");
1942 List<PropertyDefinition> properties = new ArrayList<>();
1943 properties.add(property);
1944 basic.setProperties(properties);
1946 when(propertyOperation.isPropertyDefaultValueValid(property, emptyDataTypes)).thenReturn(false);
1947 bl.validatePropertiesDefaultValues(basic);
1951 public void testDeleteMarkedResourcesNoResources() {
1952 Either<List<String>, StorageOperationStatus> eitherNoResources = Either.left(new ArrayList<>());
1954 when(toscaOperationFacade.deleteMarkedElements(ComponentTypeEnum.RESOURCE)).thenReturn(eitherNoResources);
1956 Either<List<String>, ResponseFormat> deleteMarkedResources = bl.deleteMarkedComponents();
1957 assertTrue(deleteMarkedResources.isLeft());
1958 assertTrue(deleteMarkedResources.left().value().isEmpty());
1962 public void testDeleteMarkedResources() {
1963 List<String> ids = new ArrayList<>();
1964 String resourceInUse = "123";
1965 String resourceFree = "456";
1966 ids.add(resourceInUse);
1967 ids.add(resourceFree);
1968 Either<List<String>, StorageOperationStatus> eitherNoResources = Either.left(ids);
1969 when(toscaOperationFacade.getAllComponentsMarkedForDeletion(ComponentTypeEnum.RESOURCE)).thenReturn(eitherNoResources);
1971 Either<Boolean, StorageOperationStatus> resourceInUseResponse = Either.left(true);
1972 Either<Boolean, StorageOperationStatus> resourceFreeResponse = Either.left(false);
1974 List<ArtifactDefinition> artifacts = new ArrayList<>();
1976 when(toscaOperationFacade.isComponentInUse(resourceFree)).thenReturn(resourceFreeResponse);
1977 when(toscaOperationFacade.isComponentInUse(resourceInUse)).thenReturn(resourceInUseResponse);
1979 Either<Component, StorageOperationStatus> eitherDelete = Either.left(new
1981 when(toscaOperationFacade.deleteToscaComponent(resourceFree)).thenReturn(eitherDelete);
1983 List<String> deletedComponents = new ArrayList<>();
1984 deletedComponents.add(resourceFree);
1985 when(toscaOperationFacade.deleteMarkedElements(ComponentTypeEnum.RESOURCE)).thenReturn(Either.left(deletedComponents));
1987 Either<List<String>, ResponseFormat> deleteMarkedResources = bl.deleteMarkedComponents();
1988 assertTrue(deleteMarkedResources.isLeft());
1989 List<String> resourceIdList = deleteMarkedResources.left().value();
1990 assertFalse(resourceIdList.isEmpty());
1991 assertTrue(resourceIdList.contains(resourceFree));
1992 assertFalse(resourceIdList.contains(resourceInUse));
1995 @SuppressWarnings("unchecked")
1997 public void testFindVfCsarArtifactsToHandle() {
1999 Class<ResourceBusinessLogic> targetClass = ResourceBusinessLogic.class;
2000 String methodName = "findVfCsarArtifactsToHandle";
2001 Resource resource = new Resource();
2002 String deploymentArtifactToUpdateFileName = "deploymentArtifactToUpdate.yaml";
2003 String deploymentArtifactToDeleteFileName = "deploymentArtifactToDelete.yaml";
2004 String deploymentArtifactToCreateFileName = "deploymentArtifactToCreate.yaml";
2006 String artifactInfoToUpdateFileName = "infoArtifactToUpdate.yaml";
2007 String artifactInfoToDeleteFileName = "infoArtifactToDelete.yaml";
2008 String artifactInfoToNotDeleteFileName = "infoArtifactNotToDelete.yaml";
2009 String artifactInfoToCreateFileName = "infoArtifactToCreate.yaml";
2011 byte[] oldPayloadData = "oldPayloadData".getBytes();
2012 byte[] newPayloadData = "newPayloadData".getBytes();
2013 Map<String, ArtifactDefinition> deploymentArtifacts = new HashMap<>();
2015 ArtifactDefinition deploymentArtifactToUpdate = new ArtifactDefinition();
2016 deploymentArtifactToUpdate.setMandatory(false);
2017 deploymentArtifactToUpdate.setArtifactName(deploymentArtifactToUpdateFileName);
2018 deploymentArtifactToUpdate.setArtifactType("SNMP_POLL");
2019 deploymentArtifactToUpdate.setPayload(oldPayloadData);
2020 deploymentArtifactToUpdate
2021 .setArtifactChecksum(GeneralUtility.calculateMD5Base64EncodedByByteArray(oldPayloadData));
2023 ArtifactDefinition deploymentArtifactToDelete = new ArtifactDefinition();
2024 deploymentArtifactToDelete.setMandatory(false);
2025 deploymentArtifactToDelete.setArtifactName(deploymentArtifactToDeleteFileName);
2026 deploymentArtifactToDelete.setArtifactType("SNMP_TRAP");
2027 deploymentArtifactToDelete.setPayload(oldPayloadData);
2028 deploymentArtifactToDelete
2029 .setArtifactChecksum(GeneralUtility.calculateMD5Base64EncodedByByteArray(oldPayloadData));
2031 ArtifactDefinition deploymentArtifactToIgnore = new ArtifactDefinition();
2033 deploymentArtifacts.put(ValidationUtils.normalizeArtifactLabel(deploymentArtifactToUpdate.getArtifactName()),
2034 deploymentArtifactToUpdate);
2035 deploymentArtifacts.put(ValidationUtils.normalizeArtifactLabel(deploymentArtifactToDelete.getArtifactName()),
2036 deploymentArtifactToDelete);
2037 deploymentArtifacts.put("ignore", deploymentArtifactToIgnore);
2039 Map<String, ArtifactDefinition> artifacts = new HashMap<>();
2041 ArtifactDefinition artifactToUpdate = new ArtifactDefinition();
2042 artifactToUpdate.setMandatory(false);
2043 artifactToUpdate.setArtifactName(artifactInfoToUpdateFileName);
2044 artifactToUpdate.setArtifactType("SNMP_POLL");
2045 artifactToUpdate.setPayload(oldPayloadData);
2046 artifactToUpdate.setArtifactChecksum(GeneralUtility.calculateMD5Base64EncodedByByteArray(oldPayloadData));
2048 ArtifactDefinition artifactToDelete = new ArtifactDefinition();
2049 artifactToDelete.setMandatory(false);
2050 artifactToDelete.setArtifactName(artifactInfoToDeleteFileName);
2051 artifactToDelete.setArtifactType("SNMP_TRAP");
2052 artifactToDelete.setPayload(oldPayloadData);
2053 artifactToDelete.setArtifactChecksum(GeneralUtility.calculateMD5Base64EncodedByByteArray(oldPayloadData));
2054 artifactToDelete.setIsFromCsar(true);
2056 ArtifactDefinition artifactToNotDelete = new ArtifactDefinition();
2057 artifactToNotDelete.setMandatory(false);
2058 artifactToNotDelete.setArtifactName(artifactInfoToNotDeleteFileName);
2059 artifactToNotDelete.setArtifactType("SNMP_TRAP");
2060 artifactToNotDelete.setPayload(oldPayloadData);
2061 artifactToNotDelete.setArtifactChecksum(GeneralUtility.calculateMD5Base64EncodedByByteArray(oldPayloadData));
2062 artifactToNotDelete.setIsFromCsar(false);
2064 ArtifactDefinition artifactToIgnore = new ArtifactDefinition();
2066 artifacts.put(ValidationUtils.normalizeArtifactLabel(artifactToUpdate.getArtifactName()), artifactToUpdate);
2067 artifacts.put(ValidationUtils.normalizeArtifactLabel(artifactToDelete.getArtifactName()), artifactToDelete);
2068 artifacts.put(ValidationUtils.normalizeArtifactLabel(artifactToNotDelete.getArtifactName()),
2069 artifactToNotDelete);
2070 artifacts.put("ignore", artifactToIgnore);
2072 resource.setDeploymentArtifacts(deploymentArtifacts);
2073 resource.setArtifacts(artifacts);
2075 List<NonMetaArtifactInfo> artifactPathAndNameList = new ArrayList<>();
2076 NonMetaArtifactInfo deploymentArtifactInfoToUpdate = new NonMetaArtifactInfo(
2077 deploymentArtifactToUpdate.getArtifactName(), null,
2078 deploymentArtifactToUpdate.getArtifactType(),
2079 ArtifactGroupTypeEnum.DEPLOYMENT, newPayloadData, deploymentArtifactToUpdate.getArtifactName(), false);
2081 NonMetaArtifactInfo informationalArtifactInfoToUpdate = new NonMetaArtifactInfo(
2082 artifactToUpdate.getArtifactName(), null, artifactToUpdate.getArtifactType(),
2083 ArtifactGroupTypeEnum.DEPLOYMENT, newPayloadData, artifactToUpdate.getArtifactName(), false);
2085 NonMetaArtifactInfo informationalArtifactInfoToUpdateFromCsar = new NonMetaArtifactInfo(
2086 artifactToUpdate.getArtifactName(), null, artifactToUpdate.getArtifactType(),
2087 ArtifactGroupTypeEnum.INFORMATIONAL, newPayloadData, artifactToUpdate.getArtifactName(), true);
2089 NonMetaArtifactInfo deploymentArtifactInfoToUpdateFromCsar = new NonMetaArtifactInfo(
2090 artifactToUpdate.getArtifactName(), null, artifactToUpdate.getArtifactType(),
2091 ArtifactGroupTypeEnum.DEPLOYMENT, newPayloadData, artifactToUpdate.getArtifactName(), true);
2093 NonMetaArtifactInfo deploymentArtifactInfoToCreate = new NonMetaArtifactInfo(deploymentArtifactToCreateFileName,
2094 null, ArtifactTypeEnum.OTHER.getType(), ArtifactGroupTypeEnum.DEPLOYMENT, newPayloadData,
2095 deploymentArtifactToCreateFileName, false);
2097 NonMetaArtifactInfo informationalArtifactInfoToCreate = new NonMetaArtifactInfo(artifactInfoToCreateFileName,
2098 null, ArtifactTypeEnum.OTHER.getType(), ArtifactGroupTypeEnum.INFORMATIONAL, newPayloadData,
2099 artifactInfoToCreateFileName, false);
2101 artifactPathAndNameList.add(deploymentArtifactInfoToUpdate);
2102 artifactPathAndNameList.add(informationalArtifactInfoToUpdate);
2103 artifactPathAndNameList.add(deploymentArtifactInfoToCreate);
2104 artifactPathAndNameList.add(informationalArtifactInfoToCreate);
2105 artifactPathAndNameList.add(informationalArtifactInfoToUpdateFromCsar);
2106 artifactPathAndNameList.add(deploymentArtifactInfoToUpdateFromCsar);
2108 Object[] argObjects = { resource, artifactPathAndNameList, user };
2109 Class[] argClasses = { Resource.class, List.class, User.class };
2111 Method method = targetClass.getDeclaredMethod(methodName, argClasses);
2112 method.setAccessible(true);
2113 Either<EnumMap<ArtifactOperationEnum, List<NonMetaArtifactInfo>>, ResponseFormat> findVfCsarArtifactsToHandleRes = (Either<EnumMap<ArtifactOperationEnum, List<NonMetaArtifactInfo>>, ResponseFormat>) method
2114 .invoke(bl, argObjects);
2115 assertTrue(findVfCsarArtifactsToHandleRes.isLeft());
2116 EnumMap<ArtifactOperationEnum, List<NonMetaArtifactInfo>> foundVfArtifacts = findVfCsarArtifactsToHandleRes
2119 assertEquals(4, foundVfArtifacts.get(ArtifactOperationEnum.CREATE)
2121 assertEquals(4, foundVfArtifacts.get(ArtifactOperationEnum.UPDATE)
2123 assertEquals(1, foundVfArtifacts.get(ArtifactOperationEnum.DELETE)
2126 } catch (Exception e) {
2127 e.printStackTrace();
2132 public void testVFGeneratedInputs() {
2133 validateUserRoles(Role.ADMIN, Role.DESIGNER);
2134 Resource resource = createVF();
2135 List<InputDefinition> inputs = resource.getInputs();
2136 assertEquals(6, inputs.size());
2137 for (InputDefinition input : inputs) {
2138 assertThat(input.getOwnerId()).isNotNull();
2140 assertEquals(resource.getDerivedFromGenericType(), genericVF.getToscaResourceName());
2141 assertEquals(resource.getDerivedFromGenericVersion(), genericVF.getVersion());
2145 public void testCRGeneratedInputs() {
2146 validateUserRoles(Role.ADMIN, Role.DESIGNER);
2147 Resource resource = createCR();
2148 List<InputDefinition> inputs = resource.getInputs();
2149 assertEquals(3, inputs.size());
2150 for (InputDefinition input : inputs) {
2151 assertThat(input.getOwnerId()).isNotNull();
2153 assertEquals(resource.getDerivedFromGenericType(), genericCR.getToscaResourceName());
2154 assertEquals(resource.getDerivedFromGenericVersion(), genericCR.getVersion());
2158 public void testVFUpdateGenericInputsToLatestOnCheckout() {
2159 validateUserRoles(Role.ADMIN, Role.DESIGNER);
2160 // create a VF that is derived from generic version 1.0
2161 Resource resource = createVF();
2162 // create a new generic version without properties
2163 genericVF.setVersion("2.0");
2164 genericVF.setProperties(null);
2165 String currentDerivedFromVersion = resource.getDerivedFromGenericVersion();
2166 List<InputDefinition> currentInputs = resource.getInputs();
2167 // verify previous inputs ownerId fields exist - user may not delete
2169 assertEquals(6, currentInputs.stream()
2170 .filter(p -> null != p.getOwnerId())
2171 .collect(Collectors.toList())
2173 Either<Boolean, ResponseFormat> upgradeToLatestGeneric = bl.shouldUpgradeToLatestGeneric(resource);
2175 assertTrue(upgradeToLatestGeneric.isLeft());
2176 // verify update required and valid
2177 assertTrue(upgradeToLatestGeneric.left()
2179 // verify version was upgraded
2180 assertNotEquals(resource.getDerivedFromGenericVersion(), currentDerivedFromVersion);
2181 // verify inputs were not deleted
2182 assertEquals(6, resource.getInputs()
2184 // verify inputs ownerId fields were removed - user may delete/edit
2186 assertEquals(6, resource.getInputs()
2188 .filter(p -> null == p.getOwnerId())
2189 .collect(Collectors.toList())
2194 public void testVFUpdateGenericInputsToLatestOnCheckoutNotPerformed() {
2196 // create a VF that is derived from generic version 1.0
2197 validateUserRoles(Role.ADMIN, Role.DESIGNER);
2198 Resource resource = createVF();
2200 // add an input to the VF
2201 PropertyDefinition newProp = new PropertyDefinition();
2202 newProp.setType("integer");
2203 newProp.setName("newProp");
2204 resource.getInputs()
2205 .add(new InputDefinition(newProp));
2207 // create a new generic version with a new property which has the same
2208 // name as a user defined input on the VF with a different type
2209 genericVF.setVersion("2.0");
2210 newProp.setType("string");
2211 genericVF.setProperties(new ArrayList<>());
2212 genericVF.getProperties()
2214 when(genericTypeBusinessLogic.fetchDerivedFromGenericType(resource)).thenReturn(Either.left(genericVF));
2215 when(genericTypeBusinessLogic.convertGenericTypePropertiesToInputsDefintion(genericVF.getProperties(),
2216 genericVF.getUniqueId())).thenCallRealMethod();
2217 String currentDerivedFromVersion = resource.getDerivedFromGenericVersion();
2218 assertEquals(6, resource.getInputs()
2220 .filter(p -> null != p.getOwnerId())
2221 .collect(Collectors.toList())
2223 Either<Boolean, ResponseFormat> upgradeToLatestGeneric = bl.shouldUpgradeToLatestGeneric(resource);
2225 assertTrue(upgradeToLatestGeneric.isLeft());
2226 // verify update is invalid an void
2227 assertFalse(upgradeToLatestGeneric.left()
2229 // verify version was not upgraded
2230 assertEquals(resource.getDerivedFromGenericVersion(), currentDerivedFromVersion);
2231 // verify inputs were not removed
2232 assertEquals(7, resource.getInputs()
2234 // verify user defined input exists
2235 assertEquals(1, resource.getInputs()
2237 .filter(p -> null == p.getOwnerId())
2238 .collect(Collectors.toList())
2240 assertEquals("integer", resource.getInputs()
2242 .filter(p -> null == p.getOwnerId())
2249 public void testPNFGeneratedInputsNoGeneratedInformationalArtifacts() {
2250 validateUserRoles(Role.ADMIN, Role.DESIGNER);
2251 Resource resource = createPNF();
2252 List<InputDefinition> inputs = resource.getInputs();
2253 assertEquals(3, inputs.size());
2254 for (InputDefinition input : inputs) {
2255 assertThat(input.getOwnerId()).isNotNull();
2257 assertEquals(resource.getDerivedFromGenericType(), genericPNF.getToscaResourceName());
2258 assertEquals(resource.getDerivedFromGenericVersion(), genericPNF.getVersion());
2259 assertEquals(0, resource.getArtifacts()
2263 private Resource createVF() {
2265 genericVF = setupGenericTypeMock(GENERIC_VF_NAME);
2266 when(toscaOperationFacade.getLatestCertifiedNodeTypeByToscaResourceName(GENERIC_VF_NAME))
2267 .thenReturn(Either.left(genericVF));
2268 Resource resource = createResourceObject(true);
2269 resource.setDerivedFrom(null);
2270 resource.setResourceType(ResourceTypeEnum.VF);
2271 when(toscaOperationFacade.createToscaComponent(resource)).thenReturn(Either.left(resource));
2272 when(genericTypeBusinessLogic.fetchDerivedFromGenericType(resource, null)).thenReturn(Either.left(genericVF));
2273 when(genericTypeBusinessLogic.generateInputsFromGenericTypeProperties(genericVF)).thenCallRealMethod();
2274 when(genericTypeBusinessLogic.convertGenericTypePropertiesToInputsDefintion(genericVF.getProperties(),
2275 resource.getUniqueId())).thenCallRealMethod();
2276 when(toscaOperationFacade
2277 .validateComponentNameAndModelExists(resource.getName(), null, ResourceTypeEnum.VF, ComponentTypeEnum.RESOURCE))
2278 .thenReturn(Either.left(false));
2279 Resource createdResource = bl.createResource(resource, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
2280 assertThat(createdResource).isNotNull();
2281 return createdResource;
2284 private Resource createRoot() {
2285 rootType = setupGenericTypeMock(GENERIC_ROOT_NAME);
2286 when(toscaOperationFacade.getLatestByToscaResourceName(GENERIC_ROOT_NAME, null))
2287 .thenReturn(Either.left(rootType));
2291 private Resource createCR() {
2293 genericCR = setupGenericTypeMock(GENERIC_CR_NAME);
2294 when(toscaOperationFacade.getLatestCertifiedNodeTypeByToscaResourceName(GENERIC_CR_NAME))
2295 .thenReturn(Either.left(genericCR));
2296 Resource resource = createResourceObject(true);
2297 resource.setDerivedFrom(null);
2298 resource.setResourceType(ResourceTypeEnum.CR);
2299 when(toscaOperationFacade.createToscaComponent(resource)).thenReturn(Either.left(resource));
2300 when(genericTypeBusinessLogic.fetchDerivedFromGenericType(resource, null)).thenReturn(Either.left(genericCR));
2301 when(genericTypeBusinessLogic.generateInputsFromGenericTypeProperties(genericCR)).thenCallRealMethod();
2302 when(genericTypeBusinessLogic.convertGenericTypePropertiesToInputsDefintion(genericCR.getProperties(),
2303 resource.getUniqueId())).thenCallRealMethod();
2304 when(toscaOperationFacade
2305 .validateComponentNameAndModelExists(resource.getName(), null, ResourceTypeEnum.CR, ComponentTypeEnum.RESOURCE))
2306 .thenReturn(Either.left(false));
2307 Resource createdResource = bl.createResource(resource, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
2308 assertThat(createdResource).isNotNull();
2309 return createdResource;
2312 private Resource createPNF() {
2314 genericPNF = setupGenericTypeMock(GENERIC_PNF_NAME);
2315 when(toscaOperationFacade.getLatestCertifiedNodeTypeByToscaResourceName(GENERIC_PNF_NAME))
2316 .thenReturn(Either.left(genericPNF));
2317 Resource resource = createResourceObject(true);
2318 resource.setDerivedFrom(null);
2319 resource.setResourceType(ResourceTypeEnum.PNF);
2320 when(toscaOperationFacade.createToscaComponent(resource)).thenReturn(Either.left(resource));
2321 when(genericTypeBusinessLogic.fetchDerivedFromGenericType(resource, null)).thenReturn(Either.left(genericPNF));
2322 when(genericTypeBusinessLogic.generateInputsFromGenericTypeProperties(genericPNF)).thenCallRealMethod();
2323 when(genericTypeBusinessLogic.convertGenericTypePropertiesToInputsDefintion(genericPNF.getProperties(),
2324 resource.getUniqueId())).thenCallRealMethod();
2325 when(toscaOperationFacade
2326 .validateComponentNameAndModelExists(resource.getName(), null, ResourceTypeEnum.PNF, ComponentTypeEnum.RESOURCE))
2327 .thenReturn(Either.left(false));
2328 Resource createdResource = bl.createResource(resource, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
2329 assertThat(createdResource).isNotNull();
2330 return createdResource;
2333 private Map<String, String> getGenericPropertiesByToscaName(String toscaName) {
2334 HashMap<String, String> PNFProps = new HashMap<String, String>() {
2336 put("nf_function", "string");
2337 put("nf_role", "string");
2338 put("nf_type", "string");
2342 HashMap<String, String> CRProps = new HashMap<String, String>() {
2344 put("cr_function", "string");
2345 put("cr_role", "string");
2346 put("cr_type", "string");
2350 HashMap<String, String> VFProps = new HashMap<String, String>() {
2353 put("availability_zone_max_count", "integer");
2354 put("min_instances", "integer");
2355 put("max_instances", "integer");
2359 if (toscaName.contains("PNF"))
2361 if (toscaName.contains("CR"))
2363 if (toscaName.contains("VF"))
2366 return new HashMap<>();
2369 private Resource setupGenericTypeMock(String toscaName) {
2371 Resource genericType = createResourceObject(true);
2372 genericType.setVersion("1.0");
2373 genericType.setToscaResourceName(toscaName);
2374 genericType.setAbstract(true);
2375 List<PropertyDefinition> genericProps = new ArrayList<>();
2376 Map<String, String> genericPropsMap = getGenericPropertiesByToscaName(toscaName);
2377 genericPropsMap.forEach((name, type) -> {
2378 PropertyDefinition prop = new PropertyDefinition();
2381 genericProps.add(prop);
2384 genericType.setProperties(genericProps);
2388 private void validateUserRoles(Role... roles) {
2389 List<Role> listOfRoles = Stream.of(roles)
2390 .collect(Collectors.toList());
2394 public void testUpdateVolumeGroup() {
2395 Resource resource = getResourceWithType("HEAT_VOL", "org.openecomp.groups.VfModule");
2396 bl.updateVolumeGroup(resource);
2397 assertThat(resource.getGroups().get(0).getProperties().get(0).getValue()).isEqualTo(Boolean.toString(true));
2401 public void testUpdateVolumeGroupNull() {
2402 Resource resource = getResourceWithType("HEAT_VOL", "org.openecomp.groups.VfModule");
2403 resource.setGroups(null);
2404 bl.updateVolumeGroup(resource);
2405 assertThat(resource.getGroups()).isNull();
2409 public void testUpdateVolumeGroupFail() {
2410 Resource resource = getResourceWithType("NON_EXIST_HEAT", "org.openecomp.groups.VfModule");
2411 bl.updateVolumeGroup(resource);
2412 assertThat(resource.getGroups().get(0).getProperties().get(0).getValue()).isEqualTo(Boolean.toString(false));
2415 private Resource getResourceWithType(String artifactType, String groupDefinitionType) {
2416 ArtifactDefinition artifactToUpdate = new ArtifactDefinition();
2417 List<GroupDefinition> groups = new ArrayList<>();
2418 GroupDefinition gd = new GroupDefinition();
2419 List<PropertyDataDefinition> properties = new ArrayList<>();
2420 PropertyDataDefinition pdd = new PropertyDataDefinition();
2421 Map<String, ArtifactDefinition> artifacts = new HashMap<>();
2422 List<String> artifactsList = new ArrayList<>();
2424 artifactToUpdate.setArtifactType(artifactType);
2425 artifactToUpdate.setArtifactName(artifactType);
2426 artifactToUpdate.setUniqueId(artifactType);
2427 Resource resource = createResourceObjectCsar(true);
2428 artifactsList.add(artifactToUpdate.getArtifactName());
2431 pdd.setName("volume_group");
2432 pdd.setValue("true");
2433 pdd.setType(ToscaPropertyType.BOOLEAN.getType());
2435 artifacts.put(artifactToUpdate.getArtifactName(), artifactToUpdate);
2437 properties.add(pdd);
2438 gd.setType(groupDefinitionType);
2439 gd.setProperties(properties);
2440 gd.setArtifacts(artifactsList);
2443 resource.setGroups(groups);
2444 resource.setDeploymentArtifacts(artifacts);
2450 public void testgetAllCertifiedResources() throws Exception {
2451 List<Resource> list = bl.getAllCertifiedResources(true, HighestFilterEnum.HIGHEST_ONLY, "USER");
2452 Assert.assertEquals(reslist,list);
2455 @Test(expected = StorageException.class)
2456 public void testgetAllCertifiedResources_exception() throws Exception {
2457 List<Resource> list = bl.getAllCertifiedResources(false, HighestFilterEnum.NON_HIGHEST_ONLY, "USER");
2458 Assert.assertEquals(reslist,list);
2462 public void testvalidateResourceNameExists() throws Exception {
2463 Either<Map<String, Boolean>, ResponseFormat> res = bl.validateResourceNameExists("Resource", ResourceTypeEnum.CR, "jh0003");
2464 Assert.assertEquals(true,res.isLeft());
2468 public void rollbackWithEitherAlwaysReturnARuntimeException() {
2469 JanusGraphDao janusGraphDao = mockJanusGraphDao;
2470 ActionStatus actionStatus = ActionStatus.INPUTS_NOT_FOUND;
2471 String params = "testName";
2473 Either<Object, RuntimeException> result =
2474 ResourceBusinessLogic.rollbackWithEither(janusGraphDao, actionStatus, params);
2476 assertTrue(result.isRight());
2477 assertTrue(result.right().value() instanceof ByActionStatusComponentException);
2481 public void rollbackWithEitherWorksWithNullJanusGraphDao() {
2482 JanusGraphDao janusGraphDao = null;
2483 ActionStatus actionStatus = ActionStatus.INPUTS_NOT_FOUND;
2484 String params = "testName";
2486 Either<Object, RuntimeException> result =
2487 ResourceBusinessLogic.rollbackWithEither(janusGraphDao, actionStatus, params);
2489 assertTrue(result.isRight());
2490 assertTrue(result.right().value() instanceof ByActionStatusComponentException);