2 * Copyright © 2016-2019 European Support Limited
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.openecomp.sdc.be.components.impl;
20 import fj.data.Either;
21 import java.util.ArrayList;
22 import org.apache.commons.collections.CollectionUtils;
23 import org.junit.Before;
24 import org.junit.BeforeClass;
25 import org.junit.Test;
26 import org.junit.runner.RunWith;
27 import org.mockito.InjectMocks;
28 import org.mockito.Mock;
29 import org.mockito.Mockito;
30 import org.mockito.MockitoAnnotations;
31 import org.mockito.junit.MockitoJUnitRunner;
32 import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
33 import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
34 import org.openecomp.sdc.be.components.property.PropertyDeclarationOrchestrator;
35 import org.openecomp.sdc.be.components.utils.ComponentInstanceBuilder;
36 import org.openecomp.sdc.be.components.utils.GroupDefinitionBuilder;
37 import org.openecomp.sdc.be.components.utils.ResourceBuilder;
38 import org.openecomp.sdc.be.components.validation.UserValidations;
39 import org.openecomp.sdc.be.config.ConfigurationManager;
40 import org.openecomp.sdc.be.dao.api.ActionStatus;
41 import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
42 import org.openecomp.sdc.be.dao.jsongraph.JanusGraphDao;
43 import org.openecomp.sdc.be.datatypes.elements.PolicyTargetType;
44 import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
45 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
46 import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
47 import org.openecomp.sdc.be.datatypes.enums.PromoteVersionEnum;
48 import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
49 import org.openecomp.sdc.be.impl.ComponentsUtils;
50 import org.openecomp.sdc.be.model.Component;
51 import org.openecomp.sdc.be.model.ComponentInstInputsMap;
52 import org.openecomp.sdc.be.model.ComponentInstance;
53 import org.openecomp.sdc.be.model.ComponentInstancePropInput;
54 import org.openecomp.sdc.be.model.ComponentParametersView;
55 import org.openecomp.sdc.be.model.GroupDefinition;
56 import org.openecomp.sdc.be.model.LifecycleStateEnum;
57 import org.openecomp.sdc.be.model.PolicyDefinition;
58 import org.openecomp.sdc.be.model.PolicyTypeDefinition;
59 import org.openecomp.sdc.be.model.PropertyDefinition;
60 import org.openecomp.sdc.be.model.Resource;
61 import org.openecomp.sdc.be.model.User;
62 import org.openecomp.sdc.be.model.cache.ApplicationDataTypeCache;
63 import org.openecomp.sdc.be.model.jsonjanusgraph.datamodel.ToscaElementTypeEnum;
64 import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade;
65 import org.openecomp.sdc.be.model.operations.api.IGraphLockOperation;
66 import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
67 import org.openecomp.sdc.be.model.operations.impl.PolicyTypeOperation;
68 import org.openecomp.sdc.be.model.operations.impl.PropertyOperation;
69 import org.openecomp.sdc.common.impl.ExternalConfiguration;
70 import org.openecomp.sdc.common.impl.FSConfigurationSource;
71 import org.openecomp.sdc.exception.ResponseFormat;
73 import java.util.Arrays;
74 import java.util.Collections;
75 import java.util.HashMap;
76 import java.util.List;
79 import static org.assertj.core.api.Java6Assertions.assertThat;
80 import static org.junit.Assert.assertEquals;
81 import static org.junit.Assert.assertNotNull;
82 import static org.junit.Assert.fail;
83 import static org.mockito.ArgumentMatchers.any;
84 import static org.mockito.ArgumentMatchers.anyBoolean;
85 import static org.mockito.ArgumentMatchers.anyMap;
86 import static org.mockito.ArgumentMatchers.eq;
87 import static org.mockito.Mockito.when;
89 @RunWith(MockitoJUnitRunner.class)
90 public class PolicyBusinessLogicTest {
93 private PolicyBusinessLogic businessLogic;
95 private ComponentsUtils componentsUtils;
97 private ToscaOperationFacade toscaOperationFacade;
99 private IGraphLockOperation graphLockOperation;
101 private PolicyTypeOperation policyTypeOperation;
103 private UserValidations userValidations;
105 private JanusGraphDao janusGraphDao;
107 private ApplicationDataTypeCache dataTypeCache;
109 private PropertyOperation propertyOperation;
111 PropertyDeclarationOrchestrator propertyDeclarationOrchestrator;
113 private final static String COMPONENT_ID = "componentId";
114 private final static String NON_EXIST_COMPONENT_ID = "nonExistComponentId";
115 private final static String COMPONENT_NAME = "componentName";
116 private final static String POLICY_TYPE_NAME = "policyTypeName";
117 private final static String POLICY_ID = "policyId";
118 private final static String INVALID_POLICY_ID = "invalidPolicyId";
119 private final static String POLICY_NAME = "policyName";
120 private final static String OTHER_POLICY_NAME = "otherPolicyName";
121 private final static String USER_ID = "jh0003";
122 private final static String UNIQUE_ID_EXSISTS = "uniqueIdExists";
123 private final static String UNIQUE_ID_DOESNT_EXSISTS = "uniqueIdDoesntExists";
124 private final static String CREATE_POLICY = "create Policy";
125 private final static String PROPERTY_NAME = "propDefinition";
126 private final static User user = buildUser();
127 private final static PolicyDefinition policy = buildPolicy(POLICY_NAME);
128 private final static PolicyDefinition otherPolicy = buildPolicy(OTHER_POLICY_NAME);
129 private final static Resource resource = buildResource();
130 private final static PolicyTypeDefinition policyType = buildPolicyType();
132 private static Either<Component, StorageOperationStatus> componentSuccessEither;
133 private static Either<PolicyTypeDefinition, StorageOperationStatus> getPolicyTypeSuccessEither;
134 private static Either<PolicyDefinition, StorageOperationStatus> policySuccessEither;
135 private static ResponseFormat notFoundResponse;
136 private static ResponseFormat invalidContentResponse;
137 private static ResponseFormat nameExistsResponse;
138 private final ConfigurationManager configurationManager = new ConfigurationManager(new FSConfigurationSource(ExternalConfiguration.getChangeListener(), "src/test/resources/config/catalog-be"));
141 public static void setup() {
146 public void initBl() {
147 MockitoAnnotations.initMocks(this);
148 businessLogic.setComponentsUtils(componentsUtils);
149 businessLogic.setToscaOperationFacade(toscaOperationFacade);
150 businessLogic.setJanusGraphDao(janusGraphDao);
151 businessLogic.setUserValidations(userValidations);
152 businessLogic.setGraphLockOperation(graphLockOperation);
153 businessLogic.setPolicyTypeOperation(policyTypeOperation);
154 businessLogic.setDataTypeCache(dataTypeCache);
155 businessLogic.setPropertyOperation(propertyOperation);
156 businessLogic.setPropertyDeclarationOrchestrator(propertyDeclarationOrchestrator);
160 private static void createResponses() {
161 componentSuccessEither = Either.left(resource);
162 getPolicyTypeSuccessEither = Either.left(policyType);
163 policySuccessEither = Either.left(policy);
164 notFoundResponse = new ResponseFormat();
165 notFoundResponse.setStatus(404);
166 invalidContentResponse = new ResponseFormat();
167 invalidContentResponse.setStatus(400);
168 nameExistsResponse = new ResponseFormat();
169 nameExistsResponse.setStatus(409);
173 public void createPolicySuccessTest(){
174 stubValidateAndLockSuccess(CREATE_POLICY);
175 when(policyTypeOperation.getLatestPolicyTypeByType(eq(POLICY_TYPE_NAME))).thenReturn(getPolicyTypeSuccessEither);
176 when(toscaOperationFacade.associatePolicyToComponent(eq(COMPONENT_ID), any(PolicyDefinition.class), eq(0))).thenReturn(policySuccessEither);
177 stubUnlockAndCommit();
178 PolicyDefinition response = businessLogic.createPolicy(ComponentTypeEnum.RESOURCE, COMPONENT_ID, POLICY_TYPE_NAME, USER_ID, true);
179 assertThat(response.isEmpty()).isFalse();
183 public void createPolicyFromCsarDefinitionTest() {
184 String prop1 = "Prop_1";
185 String prop2 = "Prop_2";
186 Map<String, PolicyDefinition> policies = new HashMap<>();
187 PolicyDefinition policy = buildPolicy(POLICY_NAME);
188 Map<PolicyTargetType, List<String>> targets = getTargets();
189 PropertyDataDefinition[] properties = getProperties(prop1, prop2);
190 policy.setTargets(targets);
191 policy.setProperties(Arrays.asList(properties));
192 policies.put(POLICY_NAME, policy);
194 List<ComponentInstance> instanceList = new ArrayList<>();
195 ComponentInstance componentInstance = new ComponentInstance();
196 componentInstance.setUniqueId(UNIQUE_ID_EXSISTS);
197 componentInstance.setName(UNIQUE_ID_EXSISTS);
198 instanceList.add(componentInstance);
200 Resource newResource = buildResource();
201 newResource.setPolicies(policies);
202 newResource.setComponentInstances(instanceList);
204 when(policyTypeOperation.getLatestPolicyTypeByType(eq(POLICY_TYPE_NAME))).thenReturn(getPolicyTypeSuccessEither);
205 when(toscaOperationFacade.associatePolicyToComponent(eq(COMPONENT_ID), any(PolicyDefinition.class), eq(0))).thenReturn(Either.left(policy));
206 when(toscaOperationFacade.getToscaFullElement(eq(COMPONENT_ID))).thenReturn(Either.left(newResource));
207 when(toscaOperationFacade.updatePolicyOfComponent(eq(COMPONENT_ID), any(PolicyDefinition.class), any(PromoteVersionEnum.class))).thenReturn(Either.left(policy));
208 when(dataTypeCache.getAll()).thenReturn(Either.left(new HashMap<>()));
209 when(propertyOperation.validateAndUpdatePropertyValue(eq(null), eq(prop1), anyBoolean(), eq(null), anyMap())).thenReturn(Either.left(prop1));
210 when(propertyOperation.validateAndUpdatePropertyValue(eq(null), eq(prop2), anyBoolean(), eq(null), anyMap())).thenReturn(Either.left(prop2));
212 Map<String, PolicyDefinition> createdPolicy = businessLogic.createPoliciesFromParsedCsar(newResource, policies);
214 assertThat(createdPolicy.isEmpty()).isFalse();
215 PolicyDefinition newPolicy = createdPolicy.get(POLICY_NAME);
216 assertNotNull(newPolicy);
217 assertNotNull(newPolicy.getTargets());
218 assertNotNull(newPolicy.getProperties());
219 assertEquals(2, newPolicy.getProperties().size());
220 assertEquals(1, newPolicy.getTargets().size());
224 public void createPolicyUserFailureTest(){
225 ByActionStatusComponentException userNotFoundException = new ByActionStatusComponentException(ActionStatus.USER_NOT_FOUND);
226 when(userValidations.validateUserExists(eq(USER_ID))).thenThrow(userNotFoundException);
229 businessLogic.createPolicy(ComponentTypeEnum.RESOURCE, COMPONENT_ID, POLICY_TYPE_NAME, USER_ID, true);
230 } catch(ByActionStatusComponentException e){
231 assertEquals(e.getActionStatus(), userNotFoundException.getActionStatus());
235 private void assertNotFound(Either<PolicyDefinition, ResponseFormat> response) {
236 assertThat(response.isRight() && response.right().value().getStatus().equals(404)).isTrue();
239 @Test(expected = ComponentException.class)
240 public void createPolicyComponentFailureTest(){
241 when(userValidations.validateUserExists(eq(USER_ID))).thenReturn(user);
242 Either<Component, StorageOperationStatus> componentNotFoundResponse = Either.right(StorageOperationStatus.NOT_FOUND);
243 when(componentsUtils.convertFromStorageResponse(eq(StorageOperationStatus.NOT_FOUND), eq(ComponentTypeEnum.RESOURCE))).thenReturn(ActionStatus.RESOURCE_NOT_FOUND);
244 when(toscaOperationFacade.getToscaElement(eq(COMPONENT_ID), any(ComponentParametersView.class))).thenReturn(componentNotFoundResponse);
245 businessLogic.createPolicy(ComponentTypeEnum.RESOURCE, COMPONENT_ID, POLICY_TYPE_NAME, USER_ID, true);
248 @Test(expected = ComponentException.class)
249 public void createPolicyPolicyTypeFailureTest(){
250 stubValidateAndLockSuccess(CREATE_POLICY);
251 Either<PolicyTypeDefinition, StorageOperationStatus> getPolicyTypeFailed = Either.right(StorageOperationStatus.NOT_FOUND);
252 when(policyTypeOperation.getLatestPolicyTypeByType(eq(POLICY_TYPE_NAME))).thenReturn(getPolicyTypeFailed);
253 when(componentsUtils.convertFromStorageResponse(eq(getPolicyTypeFailed.right().value()))).thenReturn(ActionStatus.RESOURCE_NOT_FOUND);
254 stubUnlockAndRollback();
255 businessLogic.createPolicy(ComponentTypeEnum.RESOURCE, COMPONENT_ID, POLICY_TYPE_NAME, USER_ID, true);
258 @Test(expected = ComponentException.class)
259 public void createPolicyComponentTypeFailureTest(){
260 stubValidateAndLockSuccess(CREATE_POLICY);
261 when(policyTypeOperation.getLatestPolicyTypeByType(eq(POLICY_TYPE_NAME))).thenReturn(getPolicyTypeSuccessEither);
262 Either<PolicyDefinition, StorageOperationStatus> addPolicyRes = Either.right(StorageOperationStatus.BAD_REQUEST);
263 when(toscaOperationFacade.associatePolicyToComponent(eq(COMPONENT_ID), any(PolicyDefinition.class), eq(0))).thenReturn(addPolicyRes);
264 when(componentsUtils.convertFromStorageResponse(eq(addPolicyRes.right().value()))).thenReturn(ActionStatus.INVALID_CONTENT);
266 stubUnlockAndRollback();
267 businessLogic.createPolicy(ComponentTypeEnum.RESOURCE, COMPONENT_ID, POLICY_TYPE_NAME, USER_ID, true);
271 public void updatePolicySuccessTest(){
272 stubValidateAndLockSuccess(CREATE_POLICY);
273 when(toscaOperationFacade.updatePolicyOfComponent(eq(COMPONENT_ID), any(PolicyDefinition.class), any(PromoteVersionEnum.class))).thenReturn(policySuccessEither);
274 stubUnlockAndCommit();
275 PolicyDefinition response = businessLogic.updatePolicy(ComponentTypeEnum.RESOURCE, COMPONENT_ID, otherPolicy, USER_ID, true);
276 assertThat(response.isEmpty()).isFalse();
279 @Test(expected = ComponentException.class)
280 public void updatePolicyNameFailureTest(){
281 stubValidateAndLockSuccess(CREATE_POLICY);
282 stubUnlockAndRollback();
283 businessLogic.updatePolicy(ComponentTypeEnum.RESOURCE, COMPONENT_ID, policy, USER_ID, true);
287 public void getPolicySuccessTest(){
288 stubValidationSuccess(CREATE_POLICY);
290 PolicyDefinition response = businessLogic.getPolicy(ComponentTypeEnum.RESOURCE, COMPONENT_ID, POLICY_ID, USER_ID);
291 assertThat(response.isEmpty()).isFalse();
294 @Test(expected = ComponentException.class)
295 public void getPolicyFailureTest(){
296 stubValidationSuccess(CREATE_POLICY);
298 businessLogic.getPolicy(ComponentTypeEnum.RESOURCE, COMPONENT_ID, INVALID_POLICY_ID, USER_ID);
302 public void deletePolicySuccessTest(){
303 stubValidateAndLockSuccess(CREATE_POLICY);
305 when(toscaOperationFacade.removePolicyFromComponent(eq(COMPONENT_ID),eq(POLICY_ID))).thenReturn(StorageOperationStatus.OK);
306 PolicyDefinition response = businessLogic.deletePolicy(ComponentTypeEnum.RESOURCE, COMPONENT_ID, POLICY_ID, USER_ID, true);
307 assertThat(response.isEmpty()).isFalse();
310 @Test(expected = ComponentException.class)
311 public void deletePolicyFailureTest(){
312 stubValidateAndLockSuccess(CREATE_POLICY);
314 businessLogic.deletePolicy(ComponentTypeEnum.RESOURCE, COMPONENT_ID, INVALID_POLICY_ID, USER_ID, true);
319 public void updatePolicyPropertiesSuccessTest(){
320 stubValidateAndLockSuccess(CREATE_POLICY);
321 when(dataTypeCache.getAll()).thenReturn(Either.left(new HashMap<>()));
322 String prop1 = "Name";
323 String prop2 = "Type";
324 when(propertyOperation.validateAndUpdatePropertyValue(eq(null), eq(prop1), anyBoolean(), eq(null), anyMap())).thenReturn(Either.left(prop1));
325 when(propertyOperation.validateAndUpdatePropertyValue(eq(null), eq(prop2), anyBoolean(), eq(null), anyMap())).thenReturn(Either.left(prop2));
326 when(toscaOperationFacade.updatePolicyOfComponent(eq(COMPONENT_ID), any(PolicyDefinition.class), any(PromoteVersionEnum.class))).thenReturn(policySuccessEither);
327 stubUnlockAndCommit();
328 PropertyDataDefinition[] properties = getProperties(prop1, prop2);
329 policy.setProperties(Arrays.asList(properties));
330 List<PropertyDataDefinition> response = businessLogic.updatePolicyProperties(ComponentTypeEnum.RESOURCE, COMPONENT_ID, POLICY_ID, properties , USER_ID, true);
331 List<PropertyDataDefinition> updatedProperties = response;
332 assertThat(updatedProperties.size()).isEqualTo(2);
336 public void updatePolicyTargetsSuccessTest(){
337 stubValidateAndLockSuccess(CREATE_POLICY);
338 stubGetToscaFullElementSuccess();
339 stubUpdatePolicyOfComponentSuccess();
340 stubGetToscaElementSuccess();
341 PolicyDefinition policyResult = businessLogic.updatePolicyTargets(ComponentTypeEnum.RESOURCE, COMPONENT_ID, POLICY_ID, getTargets(), USER_ID);
342 Map<PolicyTargetType, List<String>> targets = getTargets();
343 assertThat(policyResult.getTargets().values()).usingFieldByFieldElementComparator().containsExactlyInAnyOrder(targets.get(PolicyTargetType.GROUPS), targets.get(PolicyTargetType.COMPONENT_INSTANCES));
347 @Test(expected = ComponentException.class)
348 public void updatePolicyTargetsTargetIDFailureTest(){
349 stubValidateAndLockSuccess(CREATE_POLICY);
350 stubGetToscaFullElementSuccess();
351 stubGetToscaElementSuccess();
352 stubUpdatePolicyOfComponentSuccess();
354 businessLogic.updatePolicyTargets(ComponentTypeEnum.RESOURCE, COMPONENT_ID, POLICY_ID, getTargetListFakeId(), USER_ID);
359 @Test(expected = ComponentException.class)
360 public void updatePolicyTargetsTypeFailureTest(){
361 stubValidateAndLockSuccess(CREATE_POLICY);
362 stubGetToscaFullElementSuccess();
363 stubGetToscaElementSuccess();
364 stubUpdatePolicyOfComponentSuccess();
366 businessLogic.updatePolicyTargets(ComponentTypeEnum.RESOURCE, COMPONENT_ID, POLICY_ID, getTargetListFakeType(), USER_ID);
370 private void stubUpdatePolicyOfComponentSuccess() {
371 when(toscaOperationFacade.updatePolicyOfComponent(eq(COMPONENT_ID), eq(policy), any(PromoteVersionEnum.class))).thenReturn(policySuccessEither);
375 @Test(expected = ComponentException.class)
376 public void updatePolicyPropertiesFailureTest(){
377 stubValidateAndLockSuccess(CREATE_POLICY);
378 stubUnlockAndRollback();
379 policy.setProperties(null);
380 businessLogic.updatePolicyProperties(ComponentTypeEnum.RESOURCE, COMPONENT_ID, POLICY_ID, getProperties("Name", "Type") , USER_ID, true);
384 public void testDeclarePropertiesAsPoliciesSuccess() {
385 when(toscaOperationFacade.getToscaElement(eq(COMPONENT_ID), Mockito.any(ComponentParametersView.class))).thenReturn(Either.left(resource));
386 when(graphLockOperation.lockComponent(any(), any())).thenReturn(StorageOperationStatus.OK);
387 when(graphLockOperation.unlockComponent(any(), any())).thenReturn(StorageOperationStatus.OK);
389 when(propertyDeclarationOrchestrator.declarePropertiesToPolicies(any(), any())).thenReturn(Either.left(getDeclaredPolicies()));
391 Either<List<PolicyDefinition>, ResponseFormat> declaredPoliciesEither = businessLogic
392 .declareProperties(USER_ID,
393 resource.getUniqueId(),
394 ComponentTypeEnum.RESOURCE,
395 getInputForPropertyToPolicyDeclaration());
397 assertThat(declaredPoliciesEither.isLeft()).isTrue();
399 List<PolicyDefinition> declaredPolicies = declaredPoliciesEither.left().value();
400 assertThat(CollectionUtils.isNotEmpty(declaredPolicies)).isTrue();
401 assertEquals(1, declaredPolicies.size());
405 public void testDeclarePropertiesAsPoliciesFailure() {
406 when(toscaOperationFacade.getToscaElement(eq(NON_EXIST_COMPONENT_ID), Mockito.any(ComponentParametersView.class))).thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
407 when(componentsUtils.convertFromStorageResponse(eq(StorageOperationStatus.NOT_FOUND), eq(ComponentTypeEnum.RESOURCE))).thenReturn(ActionStatus.RESOURCE_NOT_FOUND);
410 .declareProperties(USER_ID,
411 NON_EXIST_COMPONENT_ID,
412 ComponentTypeEnum.RESOURCE,
413 getInputForPropertyToPolicyDeclaration());
414 } catch (ComponentException e) {
415 assertEquals(ActionStatus.RESOURCE_NOT_FOUND, e.getActionStatus());
421 private ComponentInstInputsMap getInputForPropertyToPolicyDeclaration() {
422 PropertyDefinition propertyDefinition = getPropertyDefinitionForDeclaration();
424 ComponentInstancePropInput componentInstancePropInput = new ComponentInstancePropInput();
425 componentInstancePropInput.setInput(propertyDefinition);
426 componentInstancePropInput.setPropertiesName(PROPERTY_NAME);
428 Map<String, List<ComponentInstancePropInput>> componentPropertiesToPolicies = new HashMap<>();
429 componentPropertiesToPolicies.put(resource.getUniqueId(), Collections.singletonList(componentInstancePropInput));
431 ComponentInstInputsMap componentInstInputsMap = new ComponentInstInputsMap();
432 componentInstInputsMap.setComponentInstancePropertiesToPolicies(componentPropertiesToPolicies);
433 return componentInstInputsMap;
436 private List<PolicyDefinition> getDeclaredPolicies() {
437 return Collections.singletonList(new PolicyDefinition(getPropertyDefinitionForDeclaration()));
440 private PropertyDefinition getPropertyDefinitionForDeclaration() {
441 PropertyDefinition propertyDefinition = new PropertyDefinition();
442 propertyDefinition.setUniqueId(PROPERTY_NAME);
443 propertyDefinition.setName(PROPERTY_NAME);
444 return propertyDefinition;
447 private PropertyDataDefinition[] getProperties(String prop1, String prop2) {
448 PropertyDataDefinition property1 = new PropertyDataDefinition();
449 property1.setName(prop1);
450 property1.setValue(prop1);
451 PropertyDataDefinition property2 = new PropertyDataDefinition();
452 property2.setName(prop2);
453 property2.setValue(prop2);
454 return new PropertyDataDefinition[]{property1, property2};
458 private void stubUnlockAndRollback() {
459 when(graphLockOperation.unlockComponent(eq(COMPONENT_ID), any(NodeTypeEnum.class))).thenReturn(StorageOperationStatus.OK);
463 private void stubCommit() {
464 when(janusGraphDao.commit()).thenReturn(JanusGraphOperationStatus.OK);
467 private void stubRollback() {
468 when(janusGraphDao.rollback()).thenReturn(JanusGraphOperationStatus.OK);
471 private void stubUnlockAndCommit() {
472 when(graphLockOperation.unlockComponent(eq(COMPONENT_ID), any(NodeTypeEnum.class))).thenReturn(StorageOperationStatus.OK);
476 private void stubValidateAndLockSuccess(String methodName) {
477 stubValidationSuccess(methodName);
478 when(graphLockOperation.lockComponent(eq(COMPONENT_ID), any(NodeTypeEnum.class))).thenReturn(StorageOperationStatus.OK);
481 private void stubValidationSuccess(String methodName) {
482 when(userValidations.validateUserExists(eq(USER_ID))).thenReturn(user);
483 when(toscaOperationFacade.getToscaElement(eq(COMPONENT_ID), any(ComponentParametersView.class))).thenReturn(componentSuccessEither);
486 private void stubGetToscaFullElementSuccess() {
487 when(toscaOperationFacade.getToscaFullElement(eq(COMPONENT_ID))).thenReturn(buildElementEither());
490 private void stubGetToscaElementSuccess() {
491 when(toscaOperationFacade.getToscaElement(eq(COMPONENT_ID))).thenReturn(componentSuccessEither);
494 private Either<Component, StorageOperationStatus> buildElementEither() {
495 ResourceBuilder builder = new ResourceBuilder();
496 GroupDefinition groupDefinition = GroupDefinitionBuilder.create().setUniqueId(UNIQUE_ID_EXSISTS).build();
497 ComponentInstanceBuilder componentInstanceBuilder = new ComponentInstanceBuilder();
498 ComponentInstance componentInstance = componentInstanceBuilder.setUniqueId(UNIQUE_ID_EXSISTS).build();
499 return Either.left(builder.addGroup(groupDefinition).addComponentInstance(componentInstance).build());
502 private Map<PolicyTargetType, List<String>> getTargets() {
503 Map<PolicyTargetType, List<String>> targets = new HashMap<>();
504 targets.put(PolicyTargetType.COMPONENT_INSTANCES, Collections.singletonList(UNIQUE_ID_EXSISTS));
505 targets.put(PolicyTargetType.GROUPS, Collections.singletonList(UNIQUE_ID_EXSISTS));
511 private static PolicyTypeDefinition buildPolicyType() {
512 PolicyTypeDefinition policyType = new PolicyTypeDefinition();
513 policyType.setType(POLICY_TYPE_NAME);
517 private static PolicyDefinition buildPolicy(String policyName) {
518 PolicyDefinition policy = new PolicyDefinition();
519 policy.setUniqueId(POLICY_ID);
520 policy.setPolicyTypeName(POLICY_TYPE_NAME);
521 policy.setComponentName(COMPONENT_NAME);
522 policy.setName(policyName);
526 private static Resource buildResource() {
527 Resource resource = new Resource();
528 resource.setUniqueId(COMPONENT_ID);
529 resource.setName(COMPONENT_NAME);
530 resource.setCreatorUserId(USER_ID);
531 resource.setLastUpdaterUserId(USER_ID);
532 resource.setState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
533 resource.setIsDeleted(false);
534 resource.setResourceType(ResourceTypeEnum.VF);
535 resource.setToscaType(ToscaElementTypeEnum.TOPOLOGY_TEMPLATE.getValue());
536 resource.setComponentType(ComponentTypeEnum.RESOURCE);
537 Map<String, PolicyDefinition> policies = new HashMap<>();
538 policies.put(POLICY_ID, policy);
539 resource.setPolicies(policies);
543 private static User buildUser() {
544 User user = new User();
545 user.setUserId(USER_ID);
549 private Map<PolicyTargetType, List<String>> getTargetListFakeType() {
550 Map<PolicyTargetType, List<String>> targets = new HashMap<>();
551 targets.put(PolicyTargetType.TYPE_DOES_NOT_EXIST, Collections.singletonList(UNIQUE_ID_EXSISTS));
555 private Map<PolicyTargetType, List<String>> getTargetListFakeId() {
556 Map<PolicyTargetType, List<String>> targets = new HashMap<>();
557 targets.put(PolicyTargetType.COMPONENT_INSTANCES, Collections.singletonList(UNIQUE_ID_DOESNT_EXSISTS));
558 targets.put(PolicyTargetType.GROUPS, Collections.singletonList(UNIQUE_ID_DOESNT_EXSISTS));