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 static org.assertj.core.api.Java6Assertions.assertThat;
21 import static org.junit.Assert.assertEquals;
22 import static org.junit.Assert.assertNotNull;
23 import static org.junit.Assert.fail;
24 import static org.mockito.ArgumentMatchers.any;
25 import static org.mockito.ArgumentMatchers.anyBoolean;
26 import static org.mockito.ArgumentMatchers.anyMap;
27 import static org.mockito.ArgumentMatchers.eq;
28 import static org.mockito.Mockito.when;
30 import fj.data.Either;
31 import java.util.ArrayList;
32 import java.util.Arrays;
33 import java.util.Collections;
34 import java.util.HashMap;
35 import java.util.List;
37 import org.apache.commons.collections.CollectionUtils;
38 import org.junit.Before;
39 import org.junit.BeforeClass;
40 import org.junit.Test;
41 import org.junit.runner.RunWith;
42 import org.mockito.InjectMocks;
43 import org.mockito.Mock;
44 import org.mockito.Mockito;
45 import org.mockito.MockitoAnnotations;
46 import org.mockito.junit.MockitoJUnitRunner;
47 import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
48 import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
49 import org.openecomp.sdc.be.components.property.PropertyDeclarationOrchestrator;
50 import org.openecomp.sdc.be.components.utils.ComponentInstanceBuilder;
51 import org.openecomp.sdc.be.components.utils.GroupDefinitionBuilder;
52 import org.openecomp.sdc.be.components.utils.ResourceBuilder;
53 import org.openecomp.sdc.be.components.validation.UserValidations;
54 import org.openecomp.sdc.be.config.ConfigurationManager;
55 import org.openecomp.sdc.be.dao.api.ActionStatus;
56 import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
57 import org.openecomp.sdc.be.dao.janusgraph.JanusGraphDao;
58 import org.openecomp.sdc.be.datatypes.elements.PolicyTargetType;
59 import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
60 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
61 import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
62 import org.openecomp.sdc.be.datatypes.enums.PromoteVersionEnum;
63 import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
64 import org.openecomp.sdc.be.impl.ComponentsUtils;
65 import org.openecomp.sdc.be.model.Component;
66 import org.openecomp.sdc.be.model.ComponentInstInputsMap;
67 import org.openecomp.sdc.be.model.ComponentInstance;
68 import org.openecomp.sdc.be.model.ComponentInstancePropInput;
69 import org.openecomp.sdc.be.model.ComponentParametersView;
70 import org.openecomp.sdc.be.model.GroupDefinition;
71 import org.openecomp.sdc.be.model.LifecycleStateEnum;
72 import org.openecomp.sdc.be.model.PolicyDefinition;
73 import org.openecomp.sdc.be.model.PolicyTypeDefinition;
74 import org.openecomp.sdc.be.model.PropertyDefinition;
75 import org.openecomp.sdc.be.model.Resource;
76 import org.openecomp.sdc.be.model.User;
77 import org.openecomp.sdc.be.model.cache.ApplicationDataTypeCache;
78 import org.openecomp.sdc.be.model.jsonjanusgraph.datamodel.ToscaElementTypeEnum;
79 import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade;
80 import org.openecomp.sdc.be.model.operations.api.IGraphLockOperation;
81 import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
82 import org.openecomp.sdc.be.model.operations.impl.PolicyTypeOperation;
83 import org.openecomp.sdc.be.model.operations.impl.PropertyOperation;
84 import org.openecomp.sdc.common.impl.ExternalConfiguration;
85 import org.openecomp.sdc.common.impl.FSConfigurationSource;
86 import org.openecomp.sdc.exception.ResponseFormat;
88 @RunWith(MockitoJUnitRunner.class)
89 public class PolicyBusinessLogicTest {
92 private PolicyBusinessLogic businessLogic;
94 private ComponentsUtils componentsUtils;
96 private ToscaOperationFacade toscaOperationFacade;
98 private IGraphLockOperation graphLockOperation;
100 private PolicyTypeOperation policyTypeOperation;
102 private UserValidations userValidations;
104 private JanusGraphDao janusGraphDao;
106 private ApplicationDataTypeCache applicationDataTypeCache;
108 private PropertyOperation propertyOperation;
110 PropertyDeclarationOrchestrator propertyDeclarationOrchestrator;
112 private final static String COMPONENT_ID = "componentId";
113 private final static String NON_EXIST_COMPONENT_ID = "nonExistComponentId";
114 private final static String COMPONENT_NAME = "componentName";
115 private final static String POLICY_TYPE_NAME = "policyTypeName";
116 private final static String POLICY_ID = "policyId";
117 private final static String INVALID_POLICY_ID = "invalidPolicyId";
118 private final static String POLICY_NAME = "policyName";
119 private final static String OTHER_POLICY_NAME = "otherPolicyName";
120 private final static String USER_ID = "jh0003";
121 private final static String UNIQUE_ID_EXSISTS = "uniqueIdExists";
122 private final static String UNIQUE_ID_DOESNT_EXSISTS = "uniqueIdDoesntExists";
123 private final static String CREATE_POLICY = "create Policy";
124 private final static String PROPERTY_NAME = "propDefinition";
125 private final static User user = buildUser();
126 private final static PolicyDefinition policy = buildPolicy(POLICY_NAME);
127 private final static PolicyDefinition otherPolicy = buildPolicy(OTHER_POLICY_NAME);
128 private final static Resource resource = buildResource();
129 private final static PolicyTypeDefinition policyType = buildPolicyType();
131 private static Either<Component, StorageOperationStatus> componentSuccessEither;
132 private static Either<PolicyTypeDefinition, StorageOperationStatus> getPolicyTypeSuccessEither;
133 private static Either<PolicyDefinition, StorageOperationStatus> policySuccessEither;
134 private static ResponseFormat notFoundResponse;
135 private static ResponseFormat invalidContentResponse;
136 private static ResponseFormat nameExistsResponse;
137 private final ConfigurationManager configurationManager = new ConfigurationManager(new FSConfigurationSource(ExternalConfiguration.getChangeListener(), "src/test/resources/config/catalog-be"));
140 public static void setup() {
145 public void initBl() {
146 MockitoAnnotations.openMocks(this);
147 businessLogic.setComponentsUtils(componentsUtils);
148 businessLogic.setToscaOperationFacade(toscaOperationFacade);
149 businessLogic.setJanusGraphDao(janusGraphDao);
150 businessLogic.setUserValidations(userValidations);
151 businessLogic.setGraphLockOperation(graphLockOperation);
152 businessLogic.setPolicyTypeOperation(policyTypeOperation);
153 businessLogic.setApplicationDataTypeCache(applicationDataTypeCache);
154 businessLogic.setPropertyOperation(propertyOperation);
155 businessLogic.setPropertyDeclarationOrchestrator(propertyDeclarationOrchestrator);
159 private static void createResponses() {
160 componentSuccessEither = Either.left(resource);
161 getPolicyTypeSuccessEither = Either.left(policyType);
162 policySuccessEither = Either.left(policy);
163 notFoundResponse = new ResponseFormat();
164 notFoundResponse.setStatus(404);
165 invalidContentResponse = new ResponseFormat();
166 invalidContentResponse.setStatus(400);
167 nameExistsResponse = new ResponseFormat();
168 nameExistsResponse.setStatus(409);
172 public void createPolicySuccessTest(){
173 stubValidateAndLockSuccess(CREATE_POLICY);
174 when(policyTypeOperation.getLatestPolicyTypeByType(eq(POLICY_TYPE_NAME), any())).thenReturn(getPolicyTypeSuccessEither);
175 when(toscaOperationFacade.associatePolicyToComponent(eq(COMPONENT_ID), any(PolicyDefinition.class), eq(0))).thenReturn(policySuccessEither);
176 stubUnlockAndCommit();
177 PolicyDefinition response = businessLogic.createPolicy(ComponentTypeEnum.RESOURCE, COMPONENT_ID, POLICY_TYPE_NAME, USER_ID, true);
178 assertThat(response.isEmpty()).isFalse();
182 public void createPolicyFromCsarDefinitionTest() {
183 String prop1 = "Prop_1";
184 String prop2 = "Prop_2";
185 Map<String, PolicyDefinition> policies = new HashMap<>();
186 PolicyDefinition policy = buildPolicy(POLICY_NAME);
187 Map<PolicyTargetType, List<String>> targets = getTargets();
188 PropertyDataDefinition[] properties = getProperties(prop1, prop2);
189 policy.setTargets(targets);
190 policy.setProperties(Arrays.asList(properties));
191 policies.put(POLICY_NAME, policy);
193 List<ComponentInstance> instanceList = new ArrayList<>();
194 ComponentInstance componentInstance = new ComponentInstance();
195 componentInstance.setUniqueId(UNIQUE_ID_EXSISTS);
196 componentInstance.setName(UNIQUE_ID_EXSISTS);
197 instanceList.add(componentInstance);
199 Resource newResource = buildResource();
200 newResource.setPolicies(policies);
201 newResource.setComponentInstances(instanceList);
203 when(policyTypeOperation.getLatestPolicyTypeByType(eq(POLICY_TYPE_NAME), any())).thenReturn(getPolicyTypeSuccessEither);
204 when(toscaOperationFacade.associatePolicyToComponent(eq(COMPONENT_ID), any(PolicyDefinition.class), eq(0))).thenReturn(Either.left(policy));
205 when(toscaOperationFacade.getToscaFullElement(eq(COMPONENT_ID))).thenReturn(Either.left(newResource));
206 when(toscaOperationFacade.updatePolicyOfComponent(eq(COMPONENT_ID), any(PolicyDefinition.class), any(PromoteVersionEnum.class))).thenReturn(Either.left(policy));
207 when(propertyOperation.validateAndUpdatePropertyValue(eq(null), eq(prop1), anyBoolean(), eq(null), anyMap())).thenReturn(Either.left(prop1));
208 when(propertyOperation.validateAndUpdatePropertyValue(eq(null), eq(prop2), anyBoolean(), eq(null), anyMap())).thenReturn(Either.left(prop2));
210 Map<String, PolicyDefinition> createdPolicy = businessLogic.createPoliciesFromParsedCsar(newResource, policies);
212 assertThat(createdPolicy.isEmpty()).isFalse();
213 PolicyDefinition newPolicy = createdPolicy.get(POLICY_NAME);
214 assertNotNull(newPolicy);
215 assertNotNull(newPolicy.getTargets());
216 assertNotNull(newPolicy.getProperties());
217 assertEquals(2, newPolicy.getProperties().size());
218 assertEquals(1, newPolicy.getTargets().size());
222 public void createPolicyUserFailureTest(){
223 ByActionStatusComponentException userNotFoundException = new ByActionStatusComponentException(ActionStatus.USER_NOT_FOUND);
224 when(userValidations.validateUserExists(eq(USER_ID))).thenThrow(userNotFoundException);
227 businessLogic.createPolicy(ComponentTypeEnum.RESOURCE, COMPONENT_ID, POLICY_TYPE_NAME, USER_ID, true);
228 } catch(ByActionStatusComponentException e){
229 assertEquals(e.getActionStatus(), userNotFoundException.getActionStatus());
233 private void assertNotFound(Either<PolicyDefinition, ResponseFormat> response) {
234 assertThat(response.isRight() && response.right().value().getStatus().equals(404)).isTrue();
237 @Test(expected = ComponentException.class)
238 public void createPolicyComponentFailureTest(){
239 when(userValidations.validateUserExists(eq(USER_ID))).thenReturn(user);
240 Either<Component, StorageOperationStatus> componentNotFoundResponse = Either.right(StorageOperationStatus.NOT_FOUND);
241 when(componentsUtils.convertFromStorageResponse(eq(StorageOperationStatus.NOT_FOUND), eq(ComponentTypeEnum.RESOURCE))).thenReturn(ActionStatus.RESOURCE_NOT_FOUND);
242 when(toscaOperationFacade.getToscaElement(eq(COMPONENT_ID), any(ComponentParametersView.class))).thenReturn(componentNotFoundResponse);
243 businessLogic.createPolicy(ComponentTypeEnum.RESOURCE, COMPONENT_ID, POLICY_TYPE_NAME, USER_ID, true);
246 @Test(expected = ComponentException.class)
247 public void createPolicyPolicyTypeFailureTest(){
248 stubValidateAndLockSuccess(CREATE_POLICY);
249 Either<PolicyTypeDefinition, StorageOperationStatus> getPolicyTypeFailed = Either.right(StorageOperationStatus.NOT_FOUND);
250 when(policyTypeOperation.getLatestPolicyTypeByType(eq(POLICY_TYPE_NAME), any())).thenReturn(getPolicyTypeFailed);
251 when(componentsUtils.convertFromStorageResponse(eq(getPolicyTypeFailed.right().value()))).thenReturn(ActionStatus.RESOURCE_NOT_FOUND);
252 stubUnlockAndRollback();
253 businessLogic.createPolicy(ComponentTypeEnum.RESOURCE, COMPONENT_ID, POLICY_TYPE_NAME, USER_ID, true);
256 @Test(expected = ComponentException.class)
257 public void createPolicyComponentTypeFailureTest(){
258 stubValidateAndLockSuccess(CREATE_POLICY);
259 when(policyTypeOperation.getLatestPolicyTypeByType(eq(POLICY_TYPE_NAME), any())).thenReturn(getPolicyTypeSuccessEither);
260 Either<PolicyDefinition, StorageOperationStatus> addPolicyRes = Either.right(StorageOperationStatus.BAD_REQUEST);
261 when(toscaOperationFacade.associatePolicyToComponent(eq(COMPONENT_ID), any(PolicyDefinition.class), eq(0))).thenReturn(addPolicyRes);
262 when(componentsUtils.convertFromStorageResponse(eq(addPolicyRes.right().value()))).thenReturn(ActionStatus.INVALID_CONTENT);
264 stubUnlockAndRollback();
265 businessLogic.createPolicy(ComponentTypeEnum.RESOURCE, COMPONENT_ID, POLICY_TYPE_NAME, USER_ID, true);
269 public void updatePolicySuccessTest(){
270 stubValidateAndLockSuccess(CREATE_POLICY);
271 when(toscaOperationFacade.updatePolicyOfComponent(eq(COMPONENT_ID), any(PolicyDefinition.class), any(PromoteVersionEnum.class))).thenReturn(policySuccessEither);
272 stubUnlockAndCommit();
273 PolicyDefinition response = businessLogic.updatePolicy(ComponentTypeEnum.RESOURCE, COMPONENT_ID, otherPolicy, USER_ID, true);
274 assertThat(response.isEmpty()).isFalse();
277 @Test(expected = ComponentException.class)
278 public void updatePolicyNameFailureTest(){
279 stubValidateAndLockSuccess(CREATE_POLICY);
280 stubUnlockAndRollback();
281 businessLogic.updatePolicy(ComponentTypeEnum.RESOURCE, COMPONENT_ID, policy, USER_ID, true);
285 public void getPolicySuccessTest(){
286 stubValidationSuccess(CREATE_POLICY);
288 PolicyDefinition response = businessLogic.getPolicy(ComponentTypeEnum.RESOURCE, COMPONENT_ID, POLICY_ID, USER_ID);
289 assertThat(response.isEmpty()).isFalse();
292 @Test(expected = ComponentException.class)
293 public void getPolicyFailureTest(){
294 stubValidationSuccess(CREATE_POLICY);
296 businessLogic.getPolicy(ComponentTypeEnum.RESOURCE, COMPONENT_ID, INVALID_POLICY_ID, USER_ID);
300 public void deletePolicySuccessTest(){
301 stubValidateAndLockSuccess(CREATE_POLICY);
303 when(toscaOperationFacade.removePolicyFromComponent(eq(COMPONENT_ID),eq(POLICY_ID))).thenReturn(StorageOperationStatus.OK);
304 PolicyDefinition response = businessLogic.deletePolicy(ComponentTypeEnum.RESOURCE, COMPONENT_ID, POLICY_ID, USER_ID, true);
305 assertThat(response.isEmpty()).isFalse();
308 @Test(expected = ComponentException.class)
309 public void deletePolicyFailureTest(){
310 stubValidateAndLockSuccess(CREATE_POLICY);
312 businessLogic.deletePolicy(ComponentTypeEnum.RESOURCE, COMPONENT_ID, INVALID_POLICY_ID, USER_ID, true);
317 public void updatePolicyPropertiesSuccessTest(){
318 stubValidateAndLockSuccess(CREATE_POLICY);
319 String prop1 = "Name";
320 String prop2 = "Type";
321 when(propertyOperation.validateAndUpdatePropertyValue(eq(null), eq(prop1), anyBoolean(), eq(null), anyMap())).thenReturn(Either.left(prop1));
322 when(propertyOperation.validateAndUpdatePropertyValue(eq(null), eq(prop2), anyBoolean(), eq(null), anyMap())).thenReturn(Either.left(prop2));
323 when(toscaOperationFacade.updatePolicyOfComponent(eq(COMPONENT_ID), any(PolicyDefinition.class), any(PromoteVersionEnum.class))).thenReturn(policySuccessEither);
324 stubUnlockAndCommit();
325 PropertyDataDefinition[] properties = getProperties(prop1, prop2);
326 policy.setProperties(Arrays.asList(properties));
327 List<PropertyDataDefinition> response = businessLogic.updatePolicyProperties(ComponentTypeEnum.RESOURCE, COMPONENT_ID, POLICY_ID, properties , USER_ID, true);
328 List<PropertyDataDefinition> updatedProperties = response;
329 assertThat(updatedProperties.size()).isEqualTo(2);
333 public void updatePolicyTargetsSuccessTest(){
334 stubValidateAndLockSuccess(CREATE_POLICY);
335 stubGetToscaFullElementSuccess();
336 stubUpdatePolicyOfComponentSuccess();
337 stubGetToscaElementSuccess();
338 PolicyDefinition policyResult = businessLogic.updatePolicyTargets(ComponentTypeEnum.RESOURCE, COMPONENT_ID, POLICY_ID, getTargets(), USER_ID);
339 Map<PolicyTargetType, List<String>> targets = getTargets();
340 assertThat(policyResult.getTargets().values()).usingFieldByFieldElementComparator().containsExactlyInAnyOrder(targets.get(PolicyTargetType.GROUPS), targets.get(PolicyTargetType.COMPONENT_INSTANCES));
344 @Test(expected = ComponentException.class)
345 public void updatePolicyTargetsTargetIDFailureTest(){
346 stubValidateAndLockSuccess(CREATE_POLICY);
347 stubGetToscaFullElementSuccess();
348 stubGetToscaElementSuccess();
349 stubUpdatePolicyOfComponentSuccess();
351 businessLogic.updatePolicyTargets(ComponentTypeEnum.RESOURCE, COMPONENT_ID, POLICY_ID, getTargetListFakeId(), USER_ID);
356 @Test(expected = ComponentException.class)
357 public void updatePolicyTargetsTypeFailureTest(){
358 stubValidateAndLockSuccess(CREATE_POLICY);
359 stubGetToscaFullElementSuccess();
360 stubGetToscaElementSuccess();
361 stubUpdatePolicyOfComponentSuccess();
363 businessLogic.updatePolicyTargets(ComponentTypeEnum.RESOURCE, COMPONENT_ID, POLICY_ID, getTargetListFakeType(), USER_ID);
367 private void stubUpdatePolicyOfComponentSuccess() {
368 when(toscaOperationFacade.updatePolicyOfComponent(eq(COMPONENT_ID), eq(policy), any(PromoteVersionEnum.class))).thenReturn(policySuccessEither);
372 @Test(expected = ComponentException.class)
373 public void updatePolicyPropertiesFailureTest(){
374 stubValidateAndLockSuccess(CREATE_POLICY);
375 stubUnlockAndRollback();
376 policy.setProperties(null);
377 businessLogic.updatePolicyProperties(ComponentTypeEnum.RESOURCE, COMPONENT_ID, POLICY_ID, getProperties("Name", "Type") , USER_ID, true);
381 public void testDeclarePropertiesAsPoliciesSuccess() {
382 when(toscaOperationFacade.getToscaElement(eq(COMPONENT_ID), Mockito.any(ComponentParametersView.class))).thenReturn(Either.left(resource));
383 when(graphLockOperation.lockComponent(any(), any())).thenReturn(StorageOperationStatus.OK);
384 when(graphLockOperation.unlockComponent(any(), any())).thenReturn(StorageOperationStatus.OK);
386 when(propertyDeclarationOrchestrator.declarePropertiesToPolicies(any(), any())).thenReturn(Either.left(getDeclaredPolicies()));
388 Either<List<PolicyDefinition>, ResponseFormat> declaredPoliciesEither = businessLogic
389 .declareProperties(USER_ID,
390 resource.getUniqueId(),
391 ComponentTypeEnum.RESOURCE,
392 getInputForPropertyToPolicyDeclaration());
394 assertThat(declaredPoliciesEither.isLeft()).isTrue();
396 List<PolicyDefinition> declaredPolicies = declaredPoliciesEither.left().value();
397 assertThat(CollectionUtils.isNotEmpty(declaredPolicies)).isTrue();
398 assertEquals(1, declaredPolicies.size());
402 public void testDeclarePropertiesAsPoliciesFailure() {
403 when(toscaOperationFacade.getToscaElement(eq(NON_EXIST_COMPONENT_ID), Mockito.any(ComponentParametersView.class))).thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
404 when(componentsUtils.convertFromStorageResponse(eq(StorageOperationStatus.NOT_FOUND), eq(ComponentTypeEnum.RESOURCE))).thenReturn(ActionStatus.RESOURCE_NOT_FOUND);
407 .declareProperties(USER_ID,
408 NON_EXIST_COMPONENT_ID,
409 ComponentTypeEnum.RESOURCE,
410 getInputForPropertyToPolicyDeclaration());
411 } catch (ComponentException e) {
412 assertEquals(ActionStatus.RESOURCE_NOT_FOUND, e.getActionStatus());
418 private ComponentInstInputsMap getInputForPropertyToPolicyDeclaration() {
419 PropertyDefinition propertyDefinition = getPropertyDefinitionForDeclaration();
421 ComponentInstancePropInput componentInstancePropInput = new ComponentInstancePropInput();
422 componentInstancePropInput.setInput(propertyDefinition);
423 componentInstancePropInput.setPropertiesName(PROPERTY_NAME);
425 Map<String, List<ComponentInstancePropInput>> componentPropertiesToPolicies = new HashMap<>();
426 componentPropertiesToPolicies.put(resource.getUniqueId(), Collections.singletonList(componentInstancePropInput));
428 ComponentInstInputsMap componentInstInputsMap = new ComponentInstInputsMap();
429 componentInstInputsMap.setComponentInstancePropertiesToPolicies(componentPropertiesToPolicies);
430 return componentInstInputsMap;
433 private List<PolicyDefinition> getDeclaredPolicies() {
434 return Collections.singletonList(new PolicyDefinition(getPropertyDefinitionForDeclaration()));
437 private PropertyDefinition getPropertyDefinitionForDeclaration() {
438 PropertyDefinition propertyDefinition = new PropertyDefinition();
439 propertyDefinition.setUniqueId(PROPERTY_NAME);
440 propertyDefinition.setName(PROPERTY_NAME);
441 return propertyDefinition;
444 private PropertyDataDefinition[] getProperties(String prop1, String prop2) {
445 PropertyDataDefinition property1 = new PropertyDataDefinition();
446 property1.setName(prop1);
447 property1.setValue(prop1);
448 PropertyDataDefinition property2 = new PropertyDataDefinition();
449 property2.setName(prop2);
450 property2.setValue(prop2);
451 return new PropertyDataDefinition[]{property1, property2};
455 private void stubUnlockAndRollback() {
456 when(graphLockOperation.unlockComponent(eq(COMPONENT_ID), any(NodeTypeEnum.class))).thenReturn(StorageOperationStatus.OK);
460 private void stubCommit() {
461 when(janusGraphDao.commit()).thenReturn(JanusGraphOperationStatus.OK);
464 private void stubRollback() {
465 when(janusGraphDao.rollback()).thenReturn(JanusGraphOperationStatus.OK);
468 private void stubUnlockAndCommit() {
469 when(graphLockOperation.unlockComponent(eq(COMPONENT_ID), any(NodeTypeEnum.class))).thenReturn(StorageOperationStatus.OK);
473 private void stubValidateAndLockSuccess(String methodName) {
474 stubValidationSuccess(methodName);
475 when(graphLockOperation.lockComponent(eq(COMPONENT_ID), any(NodeTypeEnum.class))).thenReturn(StorageOperationStatus.OK);
478 private void stubValidationSuccess(String methodName) {
479 when(userValidations.validateUserExists(eq(USER_ID))).thenReturn(user);
480 when(toscaOperationFacade.getToscaElement(eq(COMPONENT_ID), any(ComponentParametersView.class))).thenReturn(componentSuccessEither);
483 private void stubGetToscaFullElementSuccess() {
484 when(toscaOperationFacade.getToscaFullElement(eq(COMPONENT_ID))).thenReturn(buildElementEither());
487 private void stubGetToscaElementSuccess() {
488 when(toscaOperationFacade.getToscaElement(eq(COMPONENT_ID))).thenReturn(componentSuccessEither);
491 private Either<Component, StorageOperationStatus> buildElementEither() {
492 ResourceBuilder builder = new ResourceBuilder();
493 GroupDefinition groupDefinition = GroupDefinitionBuilder.create().setUniqueId(UNIQUE_ID_EXSISTS).build();
494 ComponentInstanceBuilder componentInstanceBuilder = new ComponentInstanceBuilder();
495 ComponentInstance componentInstance = componentInstanceBuilder.setUniqueId(UNIQUE_ID_EXSISTS).build();
496 return Either.left(builder.addGroup(groupDefinition).addComponentInstance(componentInstance).build());
499 private Map<PolicyTargetType, List<String>> getTargets() {
500 Map<PolicyTargetType, List<String>> targets = new HashMap<>();
501 targets.put(PolicyTargetType.COMPONENT_INSTANCES, Collections.singletonList(UNIQUE_ID_EXSISTS));
502 targets.put(PolicyTargetType.GROUPS, Collections.singletonList(UNIQUE_ID_EXSISTS));
508 private static PolicyTypeDefinition buildPolicyType() {
509 PolicyTypeDefinition policyType = new PolicyTypeDefinition();
510 policyType.setType(POLICY_TYPE_NAME);
514 private static PolicyDefinition buildPolicy(String policyName) {
515 PolicyDefinition policy = new PolicyDefinition();
516 policy.setUniqueId(POLICY_ID);
517 policy.setPolicyTypeName(POLICY_TYPE_NAME);
518 policy.setComponentName(COMPONENT_NAME);
519 policy.setName(policyName);
523 private static Resource buildResource() {
524 Resource resource = new Resource();
525 resource.setUniqueId(COMPONENT_ID);
526 resource.setName(COMPONENT_NAME);
527 resource.setCreatorUserId(USER_ID);
528 resource.setLastUpdaterUserId(USER_ID);
529 resource.setState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
530 resource.setIsDeleted(false);
531 resource.setResourceType(ResourceTypeEnum.VF);
532 resource.setToscaType(ToscaElementTypeEnum.TOPOLOGY_TEMPLATE.getValue());
533 resource.setComponentType(ComponentTypeEnum.RESOURCE);
534 Map<String, PolicyDefinition> policies = new HashMap<>();
535 policies.put(POLICY_ID, policy);
536 resource.setPolicies(policies);
540 private static User buildUser() {
541 User user = new User();
542 user.setUserId(USER_ID);
546 private Map<PolicyTargetType, List<String>> getTargetListFakeType() {
547 Map<PolicyTargetType, List<String>> targets = new HashMap<>();
548 targets.put(PolicyTargetType.TYPE_DOES_NOT_EXIST, Collections.singletonList(UNIQUE_ID_EXSISTS));
552 private Map<PolicyTargetType, List<String>> getTargetListFakeId() {
553 Map<PolicyTargetType, List<String>> targets = new HashMap<>();
554 targets.put(PolicyTargetType.COMPONENT_INSTANCES, Collections.singletonList(UNIQUE_ID_DOESNT_EXSISTS));
555 targets.put(PolicyTargetType.GROUPS, Collections.singletonList(UNIQUE_ID_DOESNT_EXSISTS));