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 org.apache.commons.collections.CollectionUtils;
22 import org.junit.Before;
23 import org.junit.BeforeClass;
24 import org.junit.Test;
25 import org.junit.runner.RunWith;
26 import org.mockito.InjectMocks;
27 import org.mockito.Mock;
28 import org.mockito.Mockito;
29 import org.mockito.junit.MockitoJUnitRunner;
30 import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
31 import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
32 import org.openecomp.sdc.be.components.property.PropertyDeclarationOrchestrator;
33 import org.openecomp.sdc.be.components.utils.ComponentInstanceBuilder;
34 import org.openecomp.sdc.be.components.utils.GroupDefinitionBuilder;
35 import org.openecomp.sdc.be.components.utils.ResourceBuilder;
36 import org.openecomp.sdc.be.components.validation.UserValidations;
37 import org.openecomp.sdc.be.config.ConfigurationManager;
38 import org.openecomp.sdc.be.dao.api.ActionStatus;
39 import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
40 import org.openecomp.sdc.be.dao.jsongraph.JanusGraphDao;
41 import org.openecomp.sdc.be.datatypes.elements.PolicyTargetType;
42 import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
43 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
44 import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
45 import org.openecomp.sdc.be.datatypes.enums.PromoteVersionEnum;
46 import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
47 import org.openecomp.sdc.be.impl.ComponentsUtils;
48 import org.openecomp.sdc.be.model.Component;
49 import org.openecomp.sdc.be.model.ComponentInstInputsMap;
50 import org.openecomp.sdc.be.model.ComponentInstance;
51 import org.openecomp.sdc.be.model.ComponentInstancePropInput;
52 import org.openecomp.sdc.be.model.ComponentParametersView;
53 import org.openecomp.sdc.be.model.GroupDefinition;
54 import org.openecomp.sdc.be.model.LifecycleStateEnum;
55 import org.openecomp.sdc.be.model.PolicyDefinition;
56 import org.openecomp.sdc.be.model.PolicyTypeDefinition;
57 import org.openecomp.sdc.be.model.PropertyDefinition;
58 import org.openecomp.sdc.be.model.Resource;
59 import org.openecomp.sdc.be.model.User;
60 import org.openecomp.sdc.be.model.cache.ApplicationDataTypeCache;
61 import org.openecomp.sdc.be.model.jsonjanusgraph.datamodel.ToscaElementTypeEnum;
62 import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade;
63 import org.openecomp.sdc.be.model.operations.api.IGraphLockOperation;
64 import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
65 import org.openecomp.sdc.be.model.operations.impl.PolicyTypeOperation;
66 import org.openecomp.sdc.be.model.operations.impl.PropertyOperation;
67 import org.openecomp.sdc.common.impl.ExternalConfiguration;
68 import org.openecomp.sdc.common.impl.FSConfigurationSource;
69 import org.openecomp.sdc.exception.ResponseFormat;
71 import java.util.Arrays;
72 import java.util.Collections;
73 import java.util.HashMap;
74 import java.util.List;
77 import static org.assertj.core.api.Java6Assertions.assertThat;
78 import static org.junit.Assert.assertEquals;
79 import static org.junit.Assert.assertTrue;
80 import static org.junit.Assert.fail;
81 import static org.mockito.ArgumentMatchers.any;
82 import static org.mockito.ArgumentMatchers.anyBoolean;
83 import static org.mockito.ArgumentMatchers.anyMap;
84 import static org.mockito.ArgumentMatchers.eq;
85 import static org.mockito.Mockito.when;
87 @RunWith(MockitoJUnitRunner.class)
88 public class PolicyBusinessLogicTest {
91 private PolicyBusinessLogic businessLogic;
93 private ComponentsUtils componentsUtils;
95 private ToscaOperationFacade toscaOperationFacade;
97 private IGraphLockOperation graphLockOperation;
99 private PolicyTypeOperation policyTypeOperation;
101 private UserValidations userValidations;
103 private JanusGraphDao janusGraphDao;
105 private ApplicationDataTypeCache dataTypeCache;
107 private PropertyOperation propertyOperation;
109 PropertyDeclarationOrchestrator propertyDeclarationOrchestrator;
111 private final static String COMPONENT_ID = "componentId";
112 private final static String NON_EXIST_COMPONENT_ID = "nonExistComponentId";
113 private final static String COMPONENT_NAME = "componentName";
114 private final static String POLICY_TYPE_NAME = "policyTypeName";
115 private final static String POLICY_ID = "policyId";
116 private final static String INVALID_POLICY_ID = "invalidPolicyId";
117 private final static String POLICY_NAME = "policyName";
118 private final static String OTHER_POLICY_NAME = "otherPolicyName";
119 private final static String USER_ID = "jh0003";
120 private final static String UNIQUE_ID_EXSISTS = "uniqueIdExists";
121 private final static String UNIQUE_ID_DOESNT_EXSISTS = "uniqueIdDoesntExists";
122 private final static String CREATE_POLICY = "create Policy";
123 private final static String PROPERTY_NAME = "propDefinition";
124 private final static User user = buildUser();
125 private final static PolicyDefinition policy = buildPolicy(POLICY_NAME);
126 private final static PolicyDefinition otherPolicy = buildPolicy(OTHER_POLICY_NAME);
127 private final static Resource resource = buildResource();
128 private final static PolicyTypeDefinition policyType = buildPolicyType();
130 private static Either<Component, StorageOperationStatus> componentSuccessEither;
131 private static Either<PolicyTypeDefinition, StorageOperationStatus> getPolicyTypeSuccessEither;
132 private static Either<PolicyDefinition, StorageOperationStatus> policySuccessEither;
133 private static ResponseFormat notFoundResponse;
134 private static ResponseFormat invalidContentResponse;
135 private static ResponseFormat nameExistsResponse;
138 public static void setup() {
139 String appConfigDir = "src/test/resources/config/catalog-be";
140 new ConfigurationManager(new FSConfigurationSource(ExternalConfiguration.getChangeListener(), appConfigDir));
142 new ConfigurationManager(new FSConfigurationSource(ExternalConfiguration.getChangeListener(), appConfigDir));
146 public void initBl() {
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.setDataTypeCache(dataTypeCache);
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))).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 assertTrue(!response.isEmpty());
182 public void createPolicyUserFailureTest(){
183 ByActionStatusComponentException userNotFoundException = new ByActionStatusComponentException(ActionStatus.USER_NOT_FOUND);
184 when(userValidations.validateUserExists(eq(USER_ID))).thenThrow(userNotFoundException);
187 businessLogic.createPolicy(ComponentTypeEnum.RESOURCE, COMPONENT_ID, POLICY_TYPE_NAME, USER_ID, true);
188 } catch(ByActionStatusComponentException e){
189 assertEquals(e.getActionStatus(), userNotFoundException.getActionStatus());
193 private void assertNotFound(Either<PolicyDefinition, ResponseFormat> response) {
194 assertTrue(response.isRight() && response.right().value().getStatus().equals(404));
197 @Test(expected = ComponentException.class)
198 public void createPolicyComponentFailureTest(){
199 when(userValidations.validateUserExists(eq(USER_ID))).thenReturn(user);
200 Either<Component, StorageOperationStatus> componentNotFoundResponse = Either.right(StorageOperationStatus.NOT_FOUND);
201 when(componentsUtils.convertFromStorageResponse(eq(StorageOperationStatus.NOT_FOUND), eq(ComponentTypeEnum.RESOURCE))).thenReturn(ActionStatus.RESOURCE_NOT_FOUND);
202 when(toscaOperationFacade.getToscaElement(eq(COMPONENT_ID), any(ComponentParametersView.class))).thenReturn(componentNotFoundResponse);
203 businessLogic.createPolicy(ComponentTypeEnum.RESOURCE, COMPONENT_ID, POLICY_TYPE_NAME, USER_ID, true);
206 @Test(expected = ComponentException.class)
207 public void createPolicyPolicyTypeFailureTest(){
208 stubValidateAndLockSuccess(CREATE_POLICY);
209 Either<PolicyTypeDefinition, StorageOperationStatus> getPolicyTypeFailed = Either.right(StorageOperationStatus.NOT_FOUND);
210 when(policyTypeOperation.getLatestPolicyTypeByType(eq(POLICY_TYPE_NAME))).thenReturn(getPolicyTypeFailed);
211 when(componentsUtils.convertFromStorageResponse(eq(getPolicyTypeFailed.right().value()))).thenReturn(ActionStatus.RESOURCE_NOT_FOUND);
212 stubUnlockAndRollback();
213 businessLogic.createPolicy(ComponentTypeEnum.RESOURCE, COMPONENT_ID, POLICY_TYPE_NAME, USER_ID, true);
216 @Test(expected = ComponentException.class)
217 public void createPolicyComponentTypeFailureTest(){
218 stubValidateAndLockSuccess(CREATE_POLICY);
219 when(policyTypeOperation.getLatestPolicyTypeByType(eq(POLICY_TYPE_NAME))).thenReturn(getPolicyTypeSuccessEither);
220 Either<PolicyDefinition, StorageOperationStatus> addPolicyRes = Either.right(StorageOperationStatus.BAD_REQUEST);
221 when(toscaOperationFacade.associatePolicyToComponent(eq(COMPONENT_ID), any(PolicyDefinition.class), eq(0))).thenReturn(addPolicyRes);
222 when(componentsUtils.convertFromStorageResponse(eq(addPolicyRes.right().value()))).thenReturn(ActionStatus.INVALID_CONTENT);
224 stubUnlockAndRollback();
225 businessLogic.createPolicy(ComponentTypeEnum.RESOURCE, COMPONENT_ID, POLICY_TYPE_NAME, USER_ID, true);
229 public void updatePolicySuccessTest(){
230 stubValidateAndLockSuccess(CREATE_POLICY);
231 when(toscaOperationFacade.updatePolicyOfComponent(eq(COMPONENT_ID), any(PolicyDefinition.class), any(PromoteVersionEnum.class))).thenReturn(policySuccessEither);
232 stubUnlockAndCommit();
233 PolicyDefinition response = businessLogic.updatePolicy(ComponentTypeEnum.RESOURCE, COMPONENT_ID, otherPolicy, USER_ID, true);
234 assertTrue(!response.isEmpty());
237 @Test(expected = ComponentException.class)
238 public void updatePolicyNameFailureTest(){
239 stubValidateAndLockSuccess(CREATE_POLICY);
240 stubUnlockAndRollback();
241 businessLogic.updatePolicy(ComponentTypeEnum.RESOURCE, COMPONENT_ID, policy, USER_ID, true);
245 public void getPolicySuccessTest(){
246 stubValidationSuccess(CREATE_POLICY);
248 PolicyDefinition response = businessLogic.getPolicy(ComponentTypeEnum.RESOURCE, COMPONENT_ID, POLICY_ID, USER_ID);
249 assertTrue(!response.isEmpty());
252 @Test(expected = ComponentException.class)
253 public void getPolicyFailureTest(){
254 stubValidationSuccess(CREATE_POLICY);
256 businessLogic.getPolicy(ComponentTypeEnum.RESOURCE, COMPONENT_ID, INVALID_POLICY_ID, USER_ID);
260 public void deletePolicySuccessTest(){
261 stubValidateAndLockSuccess(CREATE_POLICY);
263 when(toscaOperationFacade.removePolicyFromComponent(eq(COMPONENT_ID),eq(POLICY_ID))).thenReturn(StorageOperationStatus.OK);
264 PolicyDefinition response = businessLogic.deletePolicy(ComponentTypeEnum.RESOURCE, COMPONENT_ID, POLICY_ID, USER_ID, true);
265 assertTrue(!response.isEmpty());
268 @Test(expected = ComponentException.class)
269 public void deletePolicyFailureTest(){
270 stubValidateAndLockSuccess(CREATE_POLICY);
272 businessLogic.deletePolicy(ComponentTypeEnum.RESOURCE, COMPONENT_ID, INVALID_POLICY_ID, USER_ID, true);
277 public void updatePolicyPropertiesSuccessTest(){
278 stubValidateAndLockSuccess(CREATE_POLICY);
279 when(dataTypeCache.getAll()).thenReturn(Either.left(new HashMap<>()));
280 String prop1 = "Name";
281 String prop2 = "Type";
282 when(propertyOperation.validateAndUpdatePropertyValue(eq(null), eq(prop1), anyBoolean(), eq(null), anyMap())).thenReturn(Either.left(prop1));
283 when(propertyOperation.validateAndUpdatePropertyValue(eq(null), eq(prop2), anyBoolean(), eq(null), anyMap())).thenReturn(Either.left(prop2));
284 when(toscaOperationFacade.updatePolicyOfComponent(eq(COMPONENT_ID), any(PolicyDefinition.class), any(PromoteVersionEnum.class))).thenReturn(policySuccessEither);
285 stubUnlockAndCommit();
286 PropertyDataDefinition[] properties = getProperties(prop1, prop2);
287 policy.setProperties(Arrays.asList(properties));
288 List<PropertyDataDefinition> response = businessLogic.updatePolicyProperties(ComponentTypeEnum.RESOURCE, COMPONENT_ID, POLICY_ID, properties , USER_ID, true);
289 List<PropertyDataDefinition> updatedProperties = response;
290 assertThat(updatedProperties.size()).isEqualTo(2);
294 public void updatePolicyTargetsSuccessTest(){
295 stubValidateAndLockSuccess(CREATE_POLICY);
296 stubGetToscaFullElementSuccess();
297 stubUpdatePolicyOfComponentSuccess();
298 stubGetToscaElementSuccess();
299 PolicyDefinition policyResult = businessLogic.updatePolicyTargets(ComponentTypeEnum.RESOURCE, COMPONENT_ID, POLICY_ID, getTargets(), USER_ID);
300 Map<PolicyTargetType, List<String>> targets = getTargets();
301 assertThat(policyResult.getTargets().values()).usingFieldByFieldElementComparator().containsExactlyInAnyOrder(targets.get(PolicyTargetType.GROUPS), targets.get(PolicyTargetType.COMPONENT_INSTANCES));
305 @Test(expected = ComponentException.class)
306 public void updatePolicyTargetsTargetIDFailureTest(){
307 stubValidateAndLockSuccess(CREATE_POLICY);
308 stubGetToscaFullElementSuccess();
309 stubGetToscaElementSuccess();
310 stubUpdatePolicyOfComponentSuccess();
312 businessLogic.updatePolicyTargets(ComponentTypeEnum.RESOURCE, COMPONENT_ID, POLICY_ID, getTargetListFakeId(), USER_ID);
317 @Test(expected = ComponentException.class)
318 public void updatePolicyTargetsTypeFailureTest(){
319 stubValidateAndLockSuccess(CREATE_POLICY);
320 stubGetToscaFullElementSuccess();
321 stubGetToscaElementSuccess();
322 stubUpdatePolicyOfComponentSuccess();
324 businessLogic.updatePolicyTargets(ComponentTypeEnum.RESOURCE, COMPONENT_ID, POLICY_ID, getTargetListFakeType(), USER_ID);
328 private void stubUpdatePolicyOfComponentSuccess() {
329 when(toscaOperationFacade.updatePolicyOfComponent(eq(COMPONENT_ID), eq(policy), any(PromoteVersionEnum.class))).thenReturn(policySuccessEither);
333 @Test(expected = ComponentException.class)
334 public void updatePolicyPropertiesFailureTest(){
335 stubValidateAndLockSuccess(CREATE_POLICY);
336 stubUnlockAndRollback();
337 policy.setProperties(null);
338 businessLogic.updatePolicyProperties(ComponentTypeEnum.RESOURCE, COMPONENT_ID, POLICY_ID, getProperties("Name", "Type") , USER_ID, true);
342 public void testDeclarePropertiesAsPoliciesSuccess() {
343 when(toscaOperationFacade.getToscaElement(eq(COMPONENT_ID), Mockito.any(ComponentParametersView.class))).thenReturn(Either.left(resource));
344 when(graphLockOperation.lockComponent(any(), any())).thenReturn(StorageOperationStatus.OK);
345 when(graphLockOperation.unlockComponent(any(), any())).thenReturn(StorageOperationStatus.OK);
347 when(propertyDeclarationOrchestrator.declarePropertiesToPolicies(any(), any())).thenReturn(Either.left(getDeclaredPolicies()));
349 Either<List<PolicyDefinition>, ResponseFormat> declaredPoliciesEither = businessLogic
350 .declareProperties(USER_ID,
351 resource.getUniqueId(),
352 ComponentTypeEnum.RESOURCE,
353 getInputForPropertyToPolicyDeclaration());
355 assertTrue(declaredPoliciesEither.isLeft());
357 List<PolicyDefinition> declaredPolicies = declaredPoliciesEither.left().value();
358 assertTrue(CollectionUtils.isNotEmpty(declaredPolicies));
359 assertEquals(1, declaredPolicies.size());
363 public void testDeclarePropertiesAsPoliciesFailure() {
364 when(toscaOperationFacade.getToscaElement(eq(NON_EXIST_COMPONENT_ID), Mockito.any(ComponentParametersView.class))).thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
365 when(componentsUtils.convertFromStorageResponse(eq(StorageOperationStatus.NOT_FOUND), eq(ComponentTypeEnum.RESOURCE))).thenReturn(ActionStatus.RESOURCE_NOT_FOUND);
368 .declareProperties(USER_ID,
369 NON_EXIST_COMPONENT_ID,
370 ComponentTypeEnum.RESOURCE,
371 getInputForPropertyToPolicyDeclaration());
372 } catch (ComponentException e) {
373 assertEquals(ActionStatus.RESOURCE_NOT_FOUND, e.getActionStatus());
379 private ComponentInstInputsMap getInputForPropertyToPolicyDeclaration() {
380 PropertyDefinition propertyDefinition = getPropertyDefinitionForDeclaration();
382 ComponentInstancePropInput componentInstancePropInput = new ComponentInstancePropInput();
383 componentInstancePropInput.setInput(propertyDefinition);
384 componentInstancePropInput.setPropertiesName(PROPERTY_NAME);
386 Map<String, List<ComponentInstancePropInput>> componentPropertiesToPolicies = new HashMap<>();
387 componentPropertiesToPolicies.put(resource.getUniqueId(), Collections.singletonList(componentInstancePropInput));
389 ComponentInstInputsMap componentInstInputsMap = new ComponentInstInputsMap();
390 componentInstInputsMap.setComponentInstancePropertiesToPolicies(componentPropertiesToPolicies);
391 return componentInstInputsMap;
394 private List<PolicyDefinition> getDeclaredPolicies() {
395 return Collections.singletonList(new PolicyDefinition(getPropertyDefinitionForDeclaration()));
398 private PropertyDefinition getPropertyDefinitionForDeclaration() {
399 PropertyDefinition propertyDefinition = new PropertyDefinition();
400 propertyDefinition.setUniqueId(PROPERTY_NAME);
401 propertyDefinition.setName(PROPERTY_NAME);
402 return propertyDefinition;
405 private PropertyDataDefinition[] getProperties(String prop1, String prop2) {
406 PropertyDataDefinition property1 = new PropertyDataDefinition();
407 property1.setName(prop1);
408 property1.setValue(prop1);
409 PropertyDataDefinition property2 = new PropertyDataDefinition();
410 property2.setName(prop2);
411 property2.setValue(prop2);
412 return new PropertyDataDefinition[]{property1, property2};
416 private void stubUnlockAndRollback() {
417 when(graphLockOperation.unlockComponent(eq(COMPONENT_ID), any(NodeTypeEnum.class))).thenReturn(StorageOperationStatus.OK);
421 private void stubCommit() {
422 when(janusGraphDao.commit()).thenReturn(JanusGraphOperationStatus.OK);
425 private void stubRollback() {
426 when(janusGraphDao.rollback()).thenReturn(JanusGraphOperationStatus.OK);
429 private void stubUnlockAndCommit() {
430 when(graphLockOperation.unlockComponent(eq(COMPONENT_ID), any(NodeTypeEnum.class))).thenReturn(StorageOperationStatus.OK);
434 private void stubValidateAndLockSuccess(String methodName) {
435 stubValidationSuccess(methodName);
436 when(graphLockOperation.lockComponent(eq(COMPONENT_ID), any(NodeTypeEnum.class))).thenReturn(StorageOperationStatus.OK);
439 private void stubValidationSuccess(String methodName) {
440 when(userValidations.validateUserExists(eq(USER_ID))).thenReturn(user);
441 when(toscaOperationFacade.getToscaElement(eq(COMPONENT_ID), any(ComponentParametersView.class))).thenReturn(componentSuccessEither);
444 private void stubGetToscaFullElementSuccess() {
445 when(toscaOperationFacade.getToscaFullElement(eq(COMPONENT_ID))).thenReturn(buildElementEither());
448 private void stubGetToscaElementSuccess() {
449 when(toscaOperationFacade.getToscaElement(eq(COMPONENT_ID))).thenReturn(componentSuccessEither);
452 private Either<Component, StorageOperationStatus> buildElementEither() {
453 ResourceBuilder builder = new ResourceBuilder();
454 GroupDefinition groupDefinition = GroupDefinitionBuilder.create().setUniqueId(UNIQUE_ID_EXSISTS).build();
455 ComponentInstanceBuilder componentInstanceBuilder = new ComponentInstanceBuilder();
456 ComponentInstance componentInstance = componentInstanceBuilder.setUniqueId(UNIQUE_ID_EXSISTS).build();
457 return Either.left(builder.addGroup(groupDefinition).addComponentInstance(componentInstance).build());
460 private Map<PolicyTargetType, List<String>> getTargets() {
461 Map<PolicyTargetType, List<String>> targets = new HashMap<>();
462 targets.put(PolicyTargetType.COMPONENT_INSTANCES, Collections.singletonList(UNIQUE_ID_EXSISTS));
463 targets.put(PolicyTargetType.GROUPS, Collections.singletonList(UNIQUE_ID_EXSISTS));
469 private static PolicyTypeDefinition buildPolicyType() {
470 PolicyTypeDefinition policyType = new PolicyTypeDefinition();
471 policyType.setType(POLICY_TYPE_NAME);
475 private static PolicyDefinition buildPolicy(String policyName) {
476 PolicyDefinition policy = new PolicyDefinition();
477 policy.setUniqueId(POLICY_ID);
478 policy.setPolicyTypeName(POLICY_TYPE_NAME);
479 policy.setComponentName(COMPONENT_NAME);
480 policy.setName(policyName);
484 private static Resource buildResource() {
485 Resource resource = new Resource();
486 resource.setUniqueId(COMPONENT_ID);
487 resource.setName(COMPONENT_NAME);
488 resource.setCreatorUserId(USER_ID);
489 resource.setLastUpdaterUserId(USER_ID);
490 resource.setState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
491 resource.setIsDeleted(false);
492 resource.setResourceType(ResourceTypeEnum.VF);
493 resource.setToscaType(ToscaElementTypeEnum.TOPOLOGY_TEMPLATE.getValue());
494 resource.setComponentType(ComponentTypeEnum.RESOURCE);
495 Map<String, PolicyDefinition> policies = new HashMap<>();
496 policies.put(POLICY_ID, policy);
497 resource.setPolicies(policies);
501 private static User buildUser() {
502 User user = new User();
503 user.setUserId(USER_ID);
507 private Map<PolicyTargetType, List<String>> getTargetListFakeType() {
508 Map<PolicyTargetType, List<String>> targets = new HashMap<>();
509 targets.put(PolicyTargetType.TYPE_DOES_NOT_EXIST, Collections.singletonList(UNIQUE_ID_EXSISTS));
513 private Map<PolicyTargetType, List<String>> getTargetListFakeId() {
514 Map<PolicyTargetType, List<String>> targets = new HashMap<>();
515 targets.put(PolicyTargetType.COMPONENT_INSTANCES, Collections.singletonList(UNIQUE_ID_DOESNT_EXSISTS));
516 targets.put(PolicyTargetType.GROUPS, Collections.singletonList(UNIQUE_ID_DOESNT_EXSISTS));