Sync Integ to Master
[sdc.git] / catalog-be / src / test / java / org / openecomp / sdc / be / components / impl / PolicyBusinessLogicTest.java
1 package org.openecomp.sdc.be.components.impl;
2
3
4 import fj.data.Either;
5 import org.junit.Assert;
6 import org.junit.BeforeClass;
7 import org.junit.Test;
8 import org.junit.runner.RunWith;
9 import org.mockito.InjectMocks;
10 import org.mockito.Mock;
11 import org.mockito.junit.MockitoJUnitRunner;
12 import org.openecomp.sdc.be.components.utils.ComponentInstanceBuilder;
13 import org.openecomp.sdc.be.components.utils.GroupDefinitionBuilder;
14 import org.openecomp.sdc.be.components.utils.ResourceBuilder;
15 import org.openecomp.sdc.be.components.validation.UserValidations;
16 import org.openecomp.sdc.be.config.ConfigurationManager;
17 import org.openecomp.sdc.be.dao.api.ActionStatus;
18 import org.openecomp.sdc.be.dao.jsongraph.TitanDao;
19 import org.openecomp.sdc.be.dao.titan.TitanOperationStatus;
20 import org.openecomp.sdc.be.datatypes.elements.PolicyTargetType;
21 import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
22 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
23 import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
24 import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
25 import org.openecomp.sdc.be.impl.ComponentsUtils;
26 import org.openecomp.sdc.be.model.Component;
27 import org.openecomp.sdc.be.model.ComponentInstance;
28 import org.openecomp.sdc.be.model.ComponentParametersView;
29 import org.openecomp.sdc.be.model.GroupDefinition;
30 import org.openecomp.sdc.be.model.LifecycleStateEnum;
31 import org.openecomp.sdc.be.model.PolicyDefinition;
32 import org.openecomp.sdc.be.model.PolicyTargetDTO;
33 import org.openecomp.sdc.be.model.PolicyTypeDefinition;
34 import org.openecomp.sdc.be.model.Resource;
35 import org.openecomp.sdc.be.model.User;
36 import org.openecomp.sdc.be.model.cache.ApplicationDataTypeCache;
37 import org.openecomp.sdc.be.model.jsontitan.datamodel.ToscaElementTypeEnum;
38 import org.openecomp.sdc.be.model.jsontitan.operations.ToscaOperationFacade;
39 import org.openecomp.sdc.be.model.operations.api.IGraphLockOperation;
40 import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
41 import org.openecomp.sdc.be.model.operations.impl.PolicyTypeOperation;
42 import org.openecomp.sdc.be.model.operations.impl.PropertyOperation;
43 import org.openecomp.sdc.common.impl.ExternalConfiguration;
44 import org.openecomp.sdc.common.impl.FSConfigurationSource;
45 import org.openecomp.sdc.exception.ResponseFormat;
46
47 import java.util.Arrays;
48 import java.util.Collections;
49 import java.util.HashMap;
50 import java.util.List;
51 import java.util.Map;
52
53 import static org.assertj.core.api.Java6Assertions.assertThat;
54 import static org.junit.Assert.assertTrue;
55 import static org.mockito.ArgumentMatchers.any;
56 import static org.mockito.ArgumentMatchers.anyBoolean;
57 import static org.mockito.ArgumentMatchers.anyMap;
58 import static org.mockito.ArgumentMatchers.anyString;
59 import static org.mockito.ArgumentMatchers.eq;
60 import static org.mockito.Mockito.when;
61
62 @RunWith(MockitoJUnitRunner.class)
63 public class PolicyBusinessLogicTest {
64
65     @InjectMocks
66     private PolicyBusinessLogic businessLogic;
67     @Mock
68     private ComponentsUtils componentsUtils;
69     @Mock
70     private ToscaOperationFacade toscaOperationFacade;
71     @Mock
72     private IGraphLockOperation graphLockOperation;
73     @Mock
74     private PolicyTypeOperation policyTypeOperation;
75     @Mock
76     private UserValidations userValidations;
77     @Mock
78     private TitanDao titanDao;
79     @Mock
80     private ApplicationDataTypeCache dataTypeCache;
81     @Mock
82     private PropertyOperation propertyOperation;
83
84     private final static String COMPONENT_ID = "componentId";
85     private final static String COMPONENT_NAME = "componentName";
86     private final static String POLICY_TYPE_NAME = "policyTypeName";
87     private final static String POLICY_ID = "policyId";
88     private final static String INVALID_POLICY_ID = "invalidPolicyId";
89     private final static String POLICY_NAME = "policyName";
90     private final static String OTHER_POLICY_NAME = "otherPolicyName";
91     private final static String USER_ID = "jh0003";
92     private final static String UNIQUE_ID_EXSISTS = "uniqueIdExists";
93     private final static String UNIQUE_ID_DOESNT_EXSISTS = "uniqueIdDoesntExists";
94     private final static String FAKE_TYPE = "fakeType";
95     private final static String COMPONENT_INSTANCE_TYPE = "component_Instances";
96     private final static String GROUP_TYPE = "GROUPS";
97
98
99
100
101     private final String CREATE_POLICY = "create Policy";
102
103     private final static User user = buildUser();
104     private final static PolicyDefinition policy = buildPolicy(POLICY_NAME);
105     private final static PolicyDefinition otherPolicy = buildPolicy(OTHER_POLICY_NAME);
106     private final static Resource resource = buildResource();
107     private final static PolicyTypeDefinition policyType = buildPolicyType();
108
109     private static Either<User, ResponseFormat> userSuccessEither;
110     private static Either<Component, StorageOperationStatus> componentSuccessEither;
111     private static Either<PolicyTypeDefinition, StorageOperationStatus> getPolicyTypeSuccessEither;
112     private static Either<PolicyDefinition, StorageOperationStatus> policySuccessEither;
113     private static ResponseFormat notFoundResponse;
114     private static ResponseFormat invalidContentResponse;
115     private static ResponseFormat nameExistsResponse;
116
117     @BeforeClass
118     public static void setup() {
119         String appConfigDir = "src/test/resources/config/catalog-be";
120         new ConfigurationManager(new FSConfigurationSource(ExternalConfiguration.getChangeListener(), appConfigDir));
121         createResponses();
122         new ConfigurationManager(new FSConfigurationSource(ExternalConfiguration.getChangeListener(), appConfigDir));
123     }
124
125     private static void createResponses() {
126         userSuccessEither = Either.left(user);
127         componentSuccessEither = Either.left(resource);
128         getPolicyTypeSuccessEither = Either.left(policyType);
129         policySuccessEither = Either.left(policy);
130         notFoundResponse = new ResponseFormat();
131         notFoundResponse.setStatus(404);
132         invalidContentResponse = new ResponseFormat();
133         invalidContentResponse.setStatus(400);
134         nameExistsResponse = new ResponseFormat();
135         nameExistsResponse.setStatus(409);
136     }
137
138     @Test
139     public void createPolicySuccessTest(){
140         stubValidateAndLockSuccess(CREATE_POLICY);
141         when(policyTypeOperation.getLatestPolicyTypeByType(eq(POLICY_TYPE_NAME))).thenReturn(getPolicyTypeSuccessEither);
142         when(toscaOperationFacade.associatePolicyToComponent(eq(COMPONENT_ID), any(PolicyDefinition.class), eq(0))).thenReturn(policySuccessEither);
143         stubUnlockAndCommit();
144         Either<PolicyDefinition, ResponseFormat>  response = businessLogic.createPolicy(ComponentTypeEnum.RESOURCE, COMPONENT_ID, POLICY_TYPE_NAME, USER_ID, true);
145         assertTrue(response.isLeft());
146     }
147     
148     @Test
149     public void createPolicyUserFailureTest(){
150         Either<User, ResponseFormat> userNotFoundResponse = Either.right(new ResponseFormat(404));
151         when(userValidations.validateUserExists(eq(USER_ID), eq(CREATE_POLICY), eq(false))).thenReturn(userNotFoundResponse);
152         stubRollback();
153         Either<PolicyDefinition, ResponseFormat>  response = businessLogic.createPolicy(ComponentTypeEnum.RESOURCE, COMPONENT_ID, POLICY_TYPE_NAME, USER_ID, true);
154         assertNotFound(response);
155     }
156
157     private void assertNotFound(Either<PolicyDefinition, ResponseFormat> response) {
158         assertTrue(response.isRight() && response.right().value().getStatus().equals(404));
159     }
160     
161     @Test
162     public void createPolicyComponentFailureTest(){
163         when(userValidations.validateUserExists(eq(USER_ID), eq(CREATE_POLICY), eq(false))).thenReturn(userSuccessEither);
164         Either<Component, StorageOperationStatus> componentNotFoundResponse = Either.right(StorageOperationStatus.NOT_FOUND);
165         when(componentsUtils.convertFromStorageResponse(eq(StorageOperationStatus.NOT_FOUND), eq(ComponentTypeEnum.RESOURCE))).thenReturn(ActionStatus.RESOURCE_NOT_FOUND);
166         when(componentsUtils.getResponseFormat(eq(ActionStatus.RESOURCE_NOT_FOUND), anyString())).thenReturn(notFoundResponse);
167         when(toscaOperationFacade.getToscaElement(eq(COMPONENT_ID), any(ComponentParametersView.class))).thenReturn(componentNotFoundResponse);
168         Either<PolicyDefinition, ResponseFormat>  response = businessLogic.createPolicy(ComponentTypeEnum.RESOURCE, COMPONENT_ID, POLICY_TYPE_NAME, USER_ID, true);
169         assertNotFound(response);
170     }
171     
172     @Test
173     public void createPolicyPolicyTypeFailureTest(){
174         stubValidateAndLockSuccess(CREATE_POLICY);
175         Either<PolicyTypeDefinition, StorageOperationStatus> getPolicyTypeFailed = Either.right(StorageOperationStatus.NOT_FOUND);
176         when(policyTypeOperation.getLatestPolicyTypeByType(eq(POLICY_TYPE_NAME))).thenReturn(getPolicyTypeFailed);
177         when(componentsUtils.convertFromStorageResponse(eq(getPolicyTypeFailed.right().value()))).thenReturn(ActionStatus.RESOURCE_NOT_FOUND);
178         when(componentsUtils.getResponseFormat(eq(ActionStatus.RESOURCE_NOT_FOUND))).thenReturn(notFoundResponse);
179         stubUnlockAndRollback();
180         Either<PolicyDefinition, ResponseFormat>  response = businessLogic.createPolicy(ComponentTypeEnum.RESOURCE, COMPONENT_ID, POLICY_TYPE_NAME, USER_ID, true);
181         assertNotFound(response);
182     }
183     
184     @Test
185     public void createPolicyComponentTypeFailureTest(){
186         stubValidateAndLockSuccess(CREATE_POLICY);
187         when(policyTypeOperation.getLatestPolicyTypeByType(eq(POLICY_TYPE_NAME))).thenReturn(getPolicyTypeSuccessEither);
188         Either<PolicyDefinition, StorageOperationStatus> addPolicyRes = Either.right(StorageOperationStatus.BAD_REQUEST);
189         when(toscaOperationFacade.associatePolicyToComponent(eq(COMPONENT_ID), any(PolicyDefinition.class), eq(0))).thenReturn(addPolicyRes);
190         when(componentsUtils.convertFromStorageResponse(eq(addPolicyRes.right().value()))).thenReturn(ActionStatus.INVALID_CONTENT);
191         when(componentsUtils.getResponseFormat(eq(ActionStatus.INVALID_CONTENT))).thenReturn(invalidContentResponse);
192         stubUnlockAndRollback();
193         Either<PolicyDefinition, ResponseFormat>  response = businessLogic.createPolicy(ComponentTypeEnum.RESOURCE, COMPONENT_ID, POLICY_TYPE_NAME, USER_ID, true);
194         assertTrue(response.isRight() && response.right().value().getStatus().equals(400));
195     }
196
197     @Test
198     public void updatePolicySuccessTest(){
199         stubValidateAndLockSuccess(CREATE_POLICY);
200         when(toscaOperationFacade.updatePolicyOfComponent(eq(COMPONENT_ID), any(PolicyDefinition.class))).thenReturn(policySuccessEither);
201         stubUnlockAndCommit();
202         Either<PolicyDefinition, ResponseFormat>  response = businessLogic.updatePolicy(ComponentTypeEnum.RESOURCE, COMPONENT_ID, otherPolicy, USER_ID, true);
203         assertTrue(response.isLeft());
204     }
205     
206     @Test
207     public void updatePolicyNameFailureTest(){
208         stubValidateAndLockSuccess(CREATE_POLICY);
209         when(componentsUtils.getResponseFormat(eq(ActionStatus.POLICY_NAME_ALREADY_EXIST), eq(POLICY_NAME))).thenReturn(nameExistsResponse);
210         stubUnlockAndRollback();
211         Either<PolicyDefinition, ResponseFormat>  response = businessLogic.updatePolicy(ComponentTypeEnum.RESOURCE, COMPONENT_ID, policy, USER_ID, true);
212         assertTrue(response.isRight() && response.right().value().getStatus().equals(409));
213     }
214     
215     @Test
216     public void getPolicySuccessTest(){
217         stubValidationSuccess(CREATE_POLICY);
218         stubCommit();
219         Either<PolicyDefinition, ResponseFormat>  response = businessLogic.getPolicy(ComponentTypeEnum.RESOURCE, COMPONENT_ID, POLICY_ID, USER_ID);
220         assertTrue(response.isLeft());
221     }
222     
223     @Test
224     public void getPolicyFailureTest(){
225         stubValidationSuccess(CREATE_POLICY);
226         stubRollback();
227         when(componentsUtils.getResponseFormat(eq(ActionStatus.POLICY_NOT_FOUND_ON_CONTAINER), eq(INVALID_POLICY_ID), eq(COMPONENT_ID))).thenReturn(notFoundResponse);
228         Either<PolicyDefinition, ResponseFormat>  response = businessLogic.getPolicy(ComponentTypeEnum.RESOURCE, COMPONENT_ID, INVALID_POLICY_ID, USER_ID);
229         assertTrue(response.isRight() && response.right().value().getStatus().equals(404));
230     }
231     
232     @Test
233     public void deletePolicySuccessTest(){
234         stubValidateAndLockSuccess(CREATE_POLICY);
235         stubCommit();
236         when(toscaOperationFacade.removePolicyFromComponent(eq(COMPONENT_ID),eq(POLICY_ID))).thenReturn(StorageOperationStatus.OK);
237         Either<PolicyDefinition, ResponseFormat>  response = businessLogic.deletePolicy(ComponentTypeEnum.RESOURCE, COMPONENT_ID, POLICY_ID, USER_ID, true);
238         assertTrue(response.isLeft());
239     }
240     
241     @Test
242     public void deletePolicyFailureTest(){
243         stubValidateAndLockSuccess(CREATE_POLICY);
244         stubCommit();
245         stubComponentUtilsGetResponsePOLICY_NOT_FOUND_ON_CONTAINER();
246         Either<PolicyDefinition, ResponseFormat>  response = businessLogic.deletePolicy(ComponentTypeEnum.RESOURCE, COMPONENT_ID, INVALID_POLICY_ID, USER_ID, true);
247         assertNotFound(response);
248     }
249
250     private void stubComponentUtilsGetResponsePOLICY_NOT_FOUND_ON_CONTAINER() {
251         when(componentsUtils.getResponseFormat(eq(ActionStatus.POLICY_NOT_FOUND_ON_CONTAINER), anyString(), anyString())).thenReturn(new ResponseFormat(404));
252     }
253
254     @Test
255     public void updatePolicyPropertiesSuccessTest(){
256         stubValidateAndLockSuccess(CREATE_POLICY);
257         when(dataTypeCache.getAll()).thenReturn(Either.left(new HashMap<>()));
258         String prop1 = "Name";
259         String prop2 = "Type";
260         when(propertyOperation.validateAndUpdatePropertyValue(eq(null), eq(prop1), anyBoolean(), eq(null), anyMap())).thenReturn(Either.left(prop1));
261         when(propertyOperation.validateAndUpdatePropertyValue(eq(null), eq(prop2), anyBoolean(), eq(null), anyMap())).thenReturn(Either.left(prop2));
262         when(toscaOperationFacade.updatePolicyOfComponent(eq(COMPONENT_ID), any(PolicyDefinition.class))).thenReturn(policySuccessEither);
263         stubUnlockAndCommit();
264         PropertyDataDefinition[] properties = getProperties(prop1, prop2);
265         policy.setProperties(Arrays.asList(properties));
266         Either<List<PropertyDataDefinition>, ResponseFormat>  response = businessLogic.updatePolicyProperties(ComponentTypeEnum.RESOURCE, COMPONENT_ID, POLICY_ID, properties , USER_ID, true);
267         assertTrue(response.isLeft());
268     }
269
270     @Test
271     public void updatePolicyTargetsSuccessTest(){
272         stubValidateAndLockSuccess(CREATE_POLICY);
273         stubGetToscaFullElementSuccess();
274         stubUpdatePolicyOfComponentSuccess();
275         stubGetToscaElementSuccess();
276         stubGetTargetType();
277
278         Either<PolicyDefinition, ResponseFormat> result = businessLogic.updatePolicyTargets(ComponentTypeEnum.RESOURCE, COMPONENT_ID, POLICY_ID, getTargets(), USER_ID);
279
280         Assert.assertTrue(result.isLeft());
281         PolicyDefinition policyResult = result.left().value();
282         Map<PolicyTargetType, List<String>> targets = getTargets();
283         assertThat(policyResult.getTargets().values()).usingFieldByFieldElementComparator().containsExactlyInAnyOrder(targets.get(PolicyTargetType.GROUPS), targets.get(PolicyTargetType.COMPONENT_INSTANCES));
284
285     }
286
287     private void stubGetTargetType() {
288     }
289
290     @Test
291     public void updatePolicyTargetsTargetIDFailureTest(){
292         stubValidateAndLockSuccess(CREATE_POLICY);
293         stubGetToscaFullElementSuccess();
294         stubGetToscaElementSuccess();
295         stubUpdatePolicyOfComponentSuccess();
296         stubComponentUtilsGetResponseTargetNotFound();
297         stubRollback();
298
299         Either<PolicyDefinition, ResponseFormat> result = businessLogic.updatePolicyTargets(ComponentTypeEnum.RESOURCE, COMPONENT_ID, POLICY_ID, getTargetListFakeId(), USER_ID);
300
301         Assert.assertTrue(result.isRight());
302         ResponseFormat responseResult = result.right().value();
303         Assert.assertEquals(responseResult.getStatus().longValue(), 400L);
304
305     }
306
307     private void stubComponentUtilsGetResponseTargetNotFound() {
308         when(componentsUtils.getResponseFormat(eq(ActionStatus.POLICY_TARGET_DOES_NOT_EXIST), (anyString()))).thenReturn(new ResponseFormat(400));
309     }
310
311     @Test
312     public void updatePolicyTargetsTypeFailureTest(){
313         stubValidateAndLockSuccess(CREATE_POLICY);
314         stubGetToscaFullElementSuccess();
315         stubGetToscaElementSuccess();
316         stubUpdatePolicyOfComponentSuccess();
317         stubComponentUtilsGetResponseTargetNotFound();
318         stubRollback();
319
320         Either<PolicyDefinition, ResponseFormat> result = businessLogic.updatePolicyTargets(ComponentTypeEnum.RESOURCE, COMPONENT_ID, POLICY_ID, getTargetListFakeType(), USER_ID);
321
322         Assert.assertTrue(result.isRight());
323         ResponseFormat responseResult = result.right().value();
324         Assert.assertTrue(responseResult.getStatus().equals(400));
325
326     }
327
328     private void stubUpdatePolicyOfComponentSuccess() {
329         when(toscaOperationFacade.updatePolicyOfComponent(eq(COMPONENT_ID), eq(policy))).thenReturn(policySuccessEither);
330     }
331
332
333     @Test
334     public void updatePolicyPropertiesFailureTest(){
335         stubValidateAndLockSuccess(CREATE_POLICY);
336         when(componentsUtils.getResponseFormat(eq(ActionStatus.PROPERTY_NOT_FOUND))).thenReturn(notFoundResponse);
337         stubUnlockAndRollback();
338         policy.setProperties(null);
339         Either<List<PropertyDataDefinition>, ResponseFormat>  response = businessLogic.updatePolicyProperties(ComponentTypeEnum.RESOURCE, COMPONENT_ID, POLICY_ID, getProperties("Name", "Type") , USER_ID, true);
340         assertTrue(response.isRight() && response.right().value().getStatus().equals(404));
341     }
342     
343     private PropertyDataDefinition[] getProperties(String prop1, String prop2) {
344         PropertyDataDefinition property1 = new PropertyDataDefinition();
345         property1.setName(prop1);
346         property1.setValue(prop1);
347         PropertyDataDefinition property2 = new PropertyDataDefinition();
348         property2.setName(prop2);
349         property2.setValue(prop2);
350         PropertyDataDefinition[] properties = {property1, property2};
351         return properties;
352     }
353     
354     
355     private void stubUnlockAndRollback() {
356         when(graphLockOperation.unlockComponent(eq(COMPONENT_ID), any(NodeTypeEnum.class))).thenReturn(StorageOperationStatus.OK);
357         stubRollback();
358     }
359
360     private void stubCommit() {
361         when(titanDao.commit()).thenReturn(TitanOperationStatus.OK);
362     }
363
364     private void stubRollback() {
365         when(titanDao.rollback()).thenReturn(TitanOperationStatus.OK);
366     }
367
368     private void stubUnlockAndCommit() {
369         when(graphLockOperation.unlockComponent(eq(COMPONENT_ID), any(NodeTypeEnum.class))).thenReturn(StorageOperationStatus.OK);
370         stubCommit();
371     }
372     
373     private void stubValidateAndLockSuccess(String methodName) {
374         stubValidationSuccess(methodName);
375         when(graphLockOperation.lockComponent(eq(COMPONENT_ID), any(NodeTypeEnum.class))).thenReturn(StorageOperationStatus.OK);
376     }
377
378     private void stubValidationSuccess(String methodName) {
379         when(userValidations.validateUserExists(eq(USER_ID), eq(methodName), eq(false))).thenReturn(userSuccessEither);
380         when(toscaOperationFacade.getToscaElement(eq(COMPONENT_ID), any(ComponentParametersView.class))).thenReturn(componentSuccessEither);
381     }
382
383     private void stubGetToscaFullElementSuccess() {
384         when(toscaOperationFacade.getToscaFullElement(eq(COMPONENT_ID))).thenReturn(buildElementEither());
385     }
386
387     private void stubGetToscaElementSuccess() {
388         when(toscaOperationFacade.getToscaElement(eq(COMPONENT_ID))).thenReturn(componentSuccessEither);
389     }
390
391     private Either<Component, StorageOperationStatus> buildElementEither() {
392         ResourceBuilder builder = new ResourceBuilder();
393         GroupDefinition groupDefinition = GroupDefinitionBuilder.create().setUniqueId(UNIQUE_ID_EXSISTS).build();
394         ComponentInstanceBuilder componentInstanceBuilder = new ComponentInstanceBuilder();
395         ComponentInstance componentInstance = componentInstanceBuilder.setUniqueId(UNIQUE_ID_EXSISTS).build();
396         return Either.left(builder.addGroups(groupDefinition).addComponentInstance(componentInstance).build());
397     }
398
399     private Map<PolicyTargetType, List<String>> getTargets() {
400         Map<PolicyTargetType, List<String>> targets = new HashMap<>();
401         targets.put(PolicyTargetType.COMPONENT_INSTANCES, Collections.singletonList(UNIQUE_ID_EXSISTS));
402         targets.put(PolicyTargetType.GROUPS, Collections.singletonList(UNIQUE_ID_EXSISTS));
403         return targets;
404     }
405
406
407
408     private static PolicyTypeDefinition buildPolicyType() {
409         PolicyTypeDefinition policyType = new PolicyTypeDefinition();
410         policyType.setType(POLICY_TYPE_NAME);
411         return policyType;
412     }
413
414     private static PolicyDefinition buildPolicy(String policyName) {
415         PolicyDefinition policy = new PolicyDefinition();
416         policy.setUniqueId(POLICY_ID);
417         policy.setPolicyTypeName(POLICY_TYPE_NAME);
418         policy.setComponentName(COMPONENT_NAME);
419         policy.setName(policyName);
420         return policy;
421     }
422
423     private static Resource buildResource() {
424         Resource resource = new Resource();
425         resource.setUniqueId(COMPONENT_ID);
426         resource.setName(COMPONENT_NAME);
427         resource.setCreatorUserId(USER_ID);
428         resource.setLastUpdaterUserId(USER_ID);
429         resource.setState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
430         resource.setIsDeleted(false);
431         resource.setResourceType(ResourceTypeEnum.VF);
432         resource.setToscaType(ToscaElementTypeEnum.TopologyTemplate.getValue());
433         Map<String, PolicyDefinition> policies = new HashMap<>();
434         policies.put(POLICY_ID, policy);
435         resource.setPolicies(policies);
436         return resource;
437     }
438
439     private static User buildUser() {
440         User user = new User();
441         user.setUserId(USER_ID);
442         return user;
443     }
444     private List<PolicyTargetDTO> getTargetDTOList() {
445         PolicyTargetDTO target1 = new PolicyTargetDTO();
446         target1.setUniqueIds(Collections.singletonList(UNIQUE_ID_EXSISTS));
447         target1.setType("GROUPS");
448
449         PolicyTargetDTO target2 = new PolicyTargetDTO();
450         target2.setUniqueIds(Collections.singletonList(UNIQUE_ID_EXSISTS));
451         target2.setType("componentInstances");
452
453         return Arrays.asList(target1, target2);
454     }
455
456     private List<PolicyTargetDTO> getFakeIDTargetDTOList() {
457         PolicyTargetDTO target1 = new PolicyTargetDTO();
458         target1.setUniqueIds(Collections.singletonList(UNIQUE_ID_DOESNT_EXSISTS));
459         target1.setType(GROUP_TYPE);
460
461         PolicyTargetDTO target2 = new PolicyTargetDTO();
462         target2.setUniqueIds(Collections.singletonList(UNIQUE_ID_DOESNT_EXSISTS));
463         target2.setType(COMPONENT_INSTANCE_TYPE);
464
465         return Arrays.asList(target1, target2);
466     }
467     private List<PolicyTargetDTO> getFakeTypeTargetDTOList() {
468         PolicyTargetDTO target1 = new PolicyTargetDTO();
469         target1.setUniqueIds(Collections.singletonList(UNIQUE_ID_EXSISTS));
470         target1.setType(FAKE_TYPE);
471
472         PolicyTargetDTO target2 = new PolicyTargetDTO();
473         target2.setUniqueIds(Collections.singletonList(UNIQUE_ID_EXSISTS));
474         target2.setType(FAKE_TYPE);
475
476         return Arrays.asList(target1, target2);
477     }
478
479     private Map<PolicyTargetType, List<String>> getTargetListFakeType() {
480         Map<PolicyTargetType, List<String>> targets = new HashMap<>();
481         targets.put(PolicyTargetType.TYPE_DOES_NOT_EXIST, Collections.singletonList(UNIQUE_ID_EXSISTS));
482         targets.put(PolicyTargetType.TYPE_DOES_NOT_EXIST, Collections.singletonList(UNIQUE_ID_EXSISTS));
483         return targets;
484     }
485
486     private Map<PolicyTargetType, List<String>> getTargetListFakeId() {
487         Map<PolicyTargetType, List<String>> targets = new HashMap<>();
488         targets.put(PolicyTargetType.COMPONENT_INSTANCES, Collections.singletonList(UNIQUE_ID_DOESNT_EXSISTS));
489         targets.put(PolicyTargetType.GROUPS, Collections.singletonList(UNIQUE_ID_DOESNT_EXSISTS));
490         return targets;
491     }
492
493 }