Added oparent to sdc main
[sdc.git] / catalog-be / src / test / java / org / openecomp / sdc / be / servlets / PolicyServletTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.openecomp.sdc.be.servlets;
22
23 import static org.assertj.core.api.Assertions.assertThat;
24 import static org.junit.Assert.assertEquals;
25 import static org.mockito.ArgumentMatchers.any;
26 import static org.mockito.ArgumentMatchers.anyMap;
27 import static org.mockito.ArgumentMatchers.eq;
28 import static org.mockito.Mockito.when;
29 import static org.openecomp.sdc.common.api.Constants.GET_POLICY;
30
31 import com.fasterxml.jackson.databind.DeserializationFeature;
32 import fj.data.Either;
33 import java.util.Arrays;
34 import java.util.Collections;
35 import java.util.HashMap;
36 import java.util.List;
37 import java.util.Objects;
38 import javax.ws.rs.client.ClientBuilder;
39 import javax.ws.rs.client.Entity;
40 import javax.ws.rs.client.Invocation;
41 import javax.ws.rs.core.GenericType;
42 import javax.ws.rs.core.MediaType;
43 import javax.ws.rs.core.Response;
44 import org.glassfish.grizzly.http.util.HttpStatus;
45 import org.glassfish.jersey.client.ClientConfig;
46 import org.glassfish.jersey.jackson.internal.jackson.jaxrs.json.JacksonJaxbJsonProvider;
47 import org.glassfish.jersey.jackson.internal.jackson.jaxrs.json.JacksonJsonProvider;
48 import org.glassfish.jersey.server.ResourceConfig;
49 import org.json.simple.JSONObject;
50 import org.junit.Before;
51 import org.junit.BeforeClass;
52 import org.junit.Test;
53 import org.junit.runner.RunWith;
54 import org.mockito.ArgumentCaptor;
55 import org.mockito.Captor;
56 import org.mockito.Mockito;
57 import org.mockito.Spy;
58 import org.mockito.junit.MockitoJUnitRunner;
59 import org.openecomp.sdc.be.components.impl.BaseBusinessLogic;
60 import org.openecomp.sdc.be.components.impl.PolicyBusinessLogic;
61 import org.openecomp.sdc.be.components.property.PropertyDeclarationOrchestrator;
62 import org.openecomp.sdc.be.components.utils.PropertyDataDefinitionBuilder;
63 import org.openecomp.sdc.be.dao.api.ActionStatus;
64 import org.openecomp.sdc.be.datatypes.elements.GetPolicyValueDataDefinition;
65 import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
66 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
67 import org.openecomp.sdc.be.impl.ComponentsUtils;
68 import org.openecomp.sdc.be.impl.ServletUtils;
69 import org.openecomp.sdc.be.model.ComponentInstInputsMap;
70 import org.openecomp.sdc.be.model.ComponentInstancePropInput;
71 import org.openecomp.sdc.be.model.PolicyDefinition;
72 import org.openecomp.sdc.be.model.PolicyTargetDTO;
73 import org.openecomp.sdc.be.model.PropertyDefinition;
74 import org.openecomp.sdc.be.model.Service;
75 import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade;
76 import org.openecomp.sdc.be.model.operations.impl.UniqueIdBuilder;
77 import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
78 import org.openecomp.sdc.common.api.Constants;
79 import org.openecomp.sdc.exception.ResponseFormat;
80
81 @RunWith(MockitoJUnitRunner.class)
82 public class PolicyServletTest extends JerseySpringBaseTest{
83
84     private final static String USER_ID = "jh0003";
85     private static final String COMPONENT_ID = "componentId";
86     private static PolicyBusinessLogic businessLogic;
87     private static ComponentsUtils componentsUtils;
88     private static ServletUtils servletUtils;
89     private static PropertyDeclarationOrchestrator propertyDeclarationOrchestrator;
90     private static ToscaOperationFacade toscaOperationFacade;
91     private static ResponseFormat responseFormat;
92     @Captor
93     private static ArgumentCaptor<PolicyDefinition> policyCaptor;
94     @Spy
95     private static BaseBusinessLogic baseBusinessLogic;
96
97     private static String validComponentType = "resources";
98     private static String unsupportedComponentType = "unsupported";
99     private static String componentId = "componentId";
100     private static String policyTypeName = "policyTypeName";
101
102     private static final String PROPS_URL = "/v1/catalog/{componentType}/{serviceId}/policies/{policyId}/properties";
103     private static final String DECLARE_URL = "v1/catalog/{componentType}/{serviceId}/create/policies";
104     private static final String DELETE_URL = "v1/catalog/{containerComponentType}/{componentId}/policies/{policyId}";
105     private static final String SERVICE_ID = "serviceId";
106     private static final String POLICY_ID = "policyId";
107     private static final String PROP_1 = "prop1";
108
109     private static final String UPDATE_TARGETS_URL = "/v1/catalog/{componentType}/{componentId}/policies/{policyId}/targets";
110
111     @BeforeClass
112     public static void initClass() {
113         createMocks();
114         when(servletUtils.getComponentsUtils()).thenReturn(componentsUtils);
115     }
116     
117     @Before
118     public void beforeMethod() {
119         final JacksonJsonProvider jacksonJsonProvider = new JacksonJaxbJsonProvider().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
120         setClient(ClientBuilder.newClient(new ClientConfig(jacksonJsonProvider)));
121     }
122
123     @Test
124     public void testGetPolicySuccess(){
125         String path = "/v1/catalog/" + validComponentType + "/" + componentId + "/policies/" + POLICY_ID;
126         Either<PolicyDefinition, ResponseFormat> successResponse = Either.left(new PolicyDefinition());
127         when(businessLogic.getPolicy(eq(ComponentTypeEnum.RESOURCE), eq(componentId), eq(POLICY_ID), eq(USER_ID))).thenReturn(successResponse);
128         when(responseFormat.getStatus()).thenReturn(HttpStatus.OK_200.getStatusCode());
129         Response response = target()
130                 .path(path)
131                 .request(MediaType.APPLICATION_JSON)
132                 .header("USER_ID", USER_ID)
133                 .get(Response.class);
134
135         assertEquals(response.getStatus(), HttpStatus.OK_200.getStatusCode());
136     }
137
138     @Test
139     public void testGetPolicyFailure(){
140         String path = "/v1/catalog/" + unsupportedComponentType + "/" + componentId + "/policies/" + POLICY_ID;
141         when(responseFormat.getStatus()).thenReturn(HttpStatus.BAD_REQUEST_400.getStatusCode());
142         when(componentsUtils.getResponseFormat(eq(ActionStatus.UNSUPPORTED_ERROR), eq(unsupportedComponentType))).thenReturn(responseFormat);
143         Response response = target()
144                 .path(path)
145                 .request(MediaType.APPLICATION_JSON)
146                 .header("USER_ID", USER_ID)
147                 .get(Response.class);
148
149         assertEquals(response.getStatus(), HttpStatus.BAD_REQUEST_400.getStatusCode());
150     }
151     
152     @Test
153     public void testPostPolicySuccess(){
154         String path = "/v1/catalog/" + validComponentType + "/" + componentId + "/policies/" + policyTypeName;
155         PolicyDefinition policy = new PolicyDefinition();
156         Either<PolicyDefinition, ResponseFormat> successResponse = Either.left(policy);
157         when(businessLogic.createPolicy(eq(ComponentTypeEnum.RESOURCE), eq(componentId), eq(policyTypeName), eq(USER_ID), eq(true))).thenReturn(successResponse);
158         when(responseFormat.getStatus()).thenReturn(HttpStatus.CREATED_201.getStatusCode());
159         when(componentsUtils.getResponseFormat(ActionStatus.CREATED)).thenReturn(responseFormat);
160         Response response = target()
161                 .path(path)
162                 .request(MediaType.APPLICATION_JSON)
163                 .header("USER_ID", USER_ID)
164                 .post(Entity.entity(policy, MediaType.APPLICATION_JSON),Response.class);
165
166         assertEquals(response.getStatus(), HttpStatus.CREATED_201.getStatusCode());
167     }
168     
169     @Test
170     public void testPostPolicyFailure(){
171         String path = "/v1/catalog/" + unsupportedComponentType + "/" + componentId + "/policies/" + policyTypeName;
172         PolicyDefinition policy = new PolicyDefinition();
173         when(responseFormat.getStatus()).thenReturn(HttpStatus.BAD_REQUEST_400.getStatusCode());
174         when(componentsUtils.getResponseFormat(eq(ActionStatus.UNSUPPORTED_ERROR), eq(unsupportedComponentType))).thenReturn(responseFormat);
175         Response response = target()
176                 .path(path)
177                 .request(MediaType.APPLICATION_JSON)
178                 .header("USER_ID", USER_ID)
179                 .post(Entity.entity(policy, MediaType.APPLICATION_JSON),Response.class);
180
181         assertEquals(response.getStatus(), HttpStatus.BAD_REQUEST_400.getStatusCode());
182     }
183     
184     @Test
185     public void testPutPolicySuccess(){
186         String path = "/v1/catalog/" + validComponentType + "/" + componentId + "/policies/" + POLICY_ID;
187         PolicyDefinition policy = new PolicyDefinition();
188         policy.setUniqueId(POLICY_ID);
189         Either<PolicyDefinition, ResponseFormat> successResponse = Either.left(policy);
190         when(businessLogic.updatePolicy(eq(ComponentTypeEnum.RESOURCE), eq(componentId), any(PolicyDefinition.class), eq(USER_ID), eq(true))).thenReturn(successResponse);
191         when(responseFormat.getStatus()).thenReturn(HttpStatus.OK_200.getStatusCode());
192         Response response = target()
193                 .path(path)
194                 .request(MediaType.APPLICATION_JSON)
195                 .header("USER_ID", USER_ID)
196                 .put(Entity.entity(policy, MediaType.APPLICATION_JSON),Response.class);
197
198         assertEquals(response.getStatus(), HttpStatus.OK_200.getStatusCode());
199     }
200     
201     @Test
202     public void testPutPolicyFailure(){
203         String path = "/v1/catalog/" + unsupportedComponentType + "/" + componentId + "/policies/" + POLICY_ID;
204         PolicyDefinition policy = new PolicyDefinition();
205         when(responseFormat.getStatus()).thenReturn(HttpStatus.BAD_REQUEST_400.getStatusCode());
206         when(componentsUtils.getResponseFormat(eq(ActionStatus.UNSUPPORTED_ERROR), eq(unsupportedComponentType))).thenReturn(responseFormat);
207         Response response = target()
208                 .path(path)
209                 .request(MediaType.APPLICATION_JSON)
210                 .header("USER_ID", USER_ID)
211                 .put(Entity.entity(policy, MediaType.APPLICATION_JSON),Response.class);
212
213         assertEquals(response.getStatus(), HttpStatus.BAD_REQUEST_400.getStatusCode());
214     }
215     
216     @Test
217     public void testDeletePolicySuccess(){
218         String path = "/v1/catalog/" + validComponentType + "/" + componentId + "/policies/" + POLICY_ID;
219         Either<PolicyDefinition, ResponseFormat> successResponse = Either.left(new PolicyDefinition());
220         when(businessLogic.deletePolicy(eq(ComponentTypeEnum.RESOURCE), eq(componentId), eq(POLICY_ID), eq(USER_ID), eq(true))).thenReturn(successResponse);
221         when(responseFormat.getStatus()).thenReturn(HttpStatus.OK_200.getStatusCode());
222         Response response = target()
223                 .path(path)
224                 .request(MediaType.APPLICATION_JSON)
225                 .header("USER_ID", USER_ID)
226                 .delete(Response.class);
227
228         assertEquals(response.getStatus(), HttpStatus.OK_200.getStatusCode());
229     }
230
231     @Test
232     public void testDeletePolicyFailure(){
233         String path = "/v1/catalog/" + unsupportedComponentType + "/" + componentId + "/policies/" + POLICY_ID;
234         when(responseFormat.getStatus()).thenReturn(HttpStatus.BAD_REQUEST_400.getStatusCode());
235         when(componentsUtils.getResponseFormat(eq(ActionStatus.UNSUPPORTED_ERROR), eq(unsupportedComponentType))).thenReturn(responseFormat);
236         Response response = target()
237                 .path(path)
238                 .request(MediaType.APPLICATION_JSON)
239                 .header("USER_ID", USER_ID)
240                 .delete(Response.class);
241
242         assertEquals(response.getStatus(), HttpStatus.BAD_REQUEST_400.getStatusCode());
243     }
244
245     @Test
246     public void getPolicyProperties_operationForbidden() {
247         when(businessLogic.getPolicyProperties(ComponentTypeEnum.SERVICE, SERVICE_ID, POLICY_ID, USER_ID)).thenReturn(Either.right(new ResponseFormat(Response.Status.FORBIDDEN.getStatusCode())));
248         Response response = buildGetPropertiesRequest().get();
249         assertThat(response.getStatus()).isEqualTo(Response.Status.FORBIDDEN.getStatusCode());
250     }
251
252     @Test
253     public void getPolicyProperties_unHandledError_returnGeneralError() {
254         when(businessLogic.getPolicyProperties(ComponentTypeEnum.SERVICE, SERVICE_ID, POLICY_ID, USER_ID)).thenThrow(new RuntimeException());
255         Response response = buildGetPropertiesRequest().get();
256         assertThat(response.getStatus()).isEqualTo(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
257     }
258
259     @Test
260     public void getPolicyProperties_wrongComponentType() {
261         Response response = buildGetPropertiesRequest("unknownType").get();
262         assertThat(response.getStatus()).isEqualTo(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
263         //verifyZeroInteractions(businessLogic);
264     }
265
266     @Test
267     public void getPolicyProperties() {
268         List<PropertyDataDefinition> properties = getPropertiesList();
269         when(businessLogic.getPolicyProperties(ComponentTypeEnum.SERVICE, SERVICE_ID, POLICY_ID, USER_ID)).thenReturn(Either.left(properties));
270         List<PropertyDataDefinition> policyProps = buildGetPropertiesRequest().get(new GenericType<List<PropertyDataDefinition>>() {});
271         assertThat(policyProps)
272                 .usingElementComparatorOnFields("uniqueId")
273                 .containsExactlyInAnyOrder(properties.get(0), properties.get(1));
274     }
275     
276     @Test
277     public void updatePolicyPropertiesSuccess() {
278         List<PropertyDataDefinition> properties = getPropertiesList();
279         when(businessLogic.updatePolicyProperties(eq(ComponentTypeEnum.SERVICE), eq(SERVICE_ID), eq(POLICY_ID), any(PropertyDataDefinition[].class), eq(USER_ID), eq(true))).thenReturn(Either.left(properties));
280         List<PropertyDataDefinition> policyProps = buildUpdatePropertiesRequest(ComponentTypeEnum.SERVICE_PARAM_NAME, properties).invoke(new GenericType<List<PropertyDataDefinition>>() {});
281         assertThat(policyProps)
282                 .usingElementComparatorOnFields("uniqueId")
283                 .containsExactlyInAnyOrder(properties.get(0), properties.get(1));
284     }
285
286     @Test
287     public void updatePolicyTargetsSuccess() {
288         List<PolicyTargetDTO> targets = getTargetDTOList();
289         when(businessLogic.updatePolicyTargets(eq(ComponentTypeEnum.RESOURCE), eq(COMPONENT_ID), eq(POLICY_ID), anyMap(), eq(USER_ID))).thenReturn(Either.left(new PolicyDefinition()));
290         Response policyTargets = buildUpdateTargetsRequest(ComponentTypeEnum.RESOURCE_PARAM_NAME, targets).invoke();
291         assertThat(policyTargets.getStatus()).isEqualTo(200);
292     }
293
294     @Test
295     public void updatePolicyPropertiesFailure() {
296         List<PropertyDataDefinition> properties = getPropertiesList();
297         ResponseFormat notFoundResponse = new ResponseFormat(HttpStatus.NOT_FOUND_404.getStatusCode());
298         when(businessLogic.updatePolicyProperties(eq(ComponentTypeEnum.SERVICE), eq(SERVICE_ID), eq(POLICY_ID), any(PropertyDataDefinition[].class), eq(USER_ID), eq(true))).thenReturn(Either.right(notFoundResponse));
299         Response policyProps = buildUpdatePropertiesRequest(ComponentTypeEnum.SERVICE_PARAM_NAME, properties).invoke();
300         assertEquals(HttpStatus.NOT_FOUND_404.getStatusCode(), policyProps.getStatus());
301     }
302
303     @Test
304     public void testDeclarePropertyToPolicySuccess() {
305         Service service = new Service();
306         service.setUniqueId(SERVICE_ID);
307         service.addProperty(new PropertyDataDefinitionBuilder().setUniqueId(PROP_1).build());
308
309         PolicyDefinition policyDefinition = new PolicyDefinition();
310         policyDefinition.setUniqueId(UniqueIdBuilder.buildPolicyUniqueId(SERVICE_ID, PROP_1));
311
312         setMocksForPropertyDeclaration(policyDefinition);
313
314         when(componentsUtils.getResponseFormat(eq(ActionStatus.OK))).thenReturn(new ResponseFormat(HttpStatus.OK_200.getStatusCode()));
315
316         Response declareResponse = buildDeclarePropertiesRequest(PROP_1).invoke();
317         assertEquals(HttpStatus.OK_200.getStatusCode(), declareResponse.getStatus());
318     }
319
320     @Test
321     public void testUndeclarePolicySuccess() {
322         Service service = new Service();
323         service.setUniqueId(SERVICE_ID);
324         PropertyDefinition origProperty = new PropertyDataDefinitionBuilder().setUniqueId(PROP_1).build();
325
326         service.addProperty(origProperty);
327
328         PolicyDefinition policyDefinition = new PolicyDefinition();
329         policyDefinition.setUniqueId(UniqueIdBuilder.buildPolicyUniqueId(SERVICE_ID, PROP_1));
330         service.addPolicy(policyDefinition);
331
332         addGetPolicyValueToProperty(origProperty, policyDefinition);
333
334         when(businessLogic.deletePolicy(eq(ComponentTypeEnum.SERVICE), eq(SERVICE_ID), eq(policyDefinition.getUniqueId()), eq(USER_ID), eq(true))).thenReturn(Either.left(policyDefinition));
335
336         Response deleteResponse = buildDeletePolicyRequest(policyDefinition).invoke();
337         assertEquals(HttpStatus.OK_200.getStatusCode(), deleteResponse.getStatus());
338     }
339
340     private void addGetPolicyValueToProperty(PropertyDefinition propertyDefinition,
341                                              PolicyDefinition policyDefinition) {
342         JSONObject jobject = new JSONObject();
343         String origValue = Objects.isNull(propertyDefinition.getValue()) ? propertyDefinition.getDefaultValue() : propertyDefinition.getValue();
344         jobject.put(GET_POLICY, null);
345         propertyDefinition.setValue(jobject.toJSONString());
346
347         GetPolicyValueDataDefinition getPolicyValueDataDefinition = new GetPolicyValueDataDefinition();
348         getPolicyValueDataDefinition.setPolicyId(policyDefinition.getUniqueId());
349         getPolicyValueDataDefinition.setPropertyName(propertyDefinition.getName());
350
351         getPolicyValueDataDefinition.setOrigPropertyValue(origValue);
352
353         propertyDefinition.setGetPolicyValues(Collections.singletonList(getPolicyValueDataDefinition));
354     }
355
356     private void setMocksForPropertyDeclaration(PolicyDefinition policyDefinition) {
357         when(request.getSession()).thenReturn(session);
358         when(session.getServletContext()).thenReturn(context);
359         when(context.getAttribute(eq(Constants.WEB_APPLICATION_CONTEXT_WRAPPER_ATTR))).thenReturn(contextWrapper);
360         when(contextWrapper.getWebAppContext(any())).thenReturn(applicationContext);
361         when(applicationContext.getBean(eq(PolicyBusinessLogic.class))).thenReturn(businessLogic);
362         when(businessLogic.declareProperties(eq(USER_ID), eq(SERVICE_ID), any(), any())).thenReturn(
363                 Either.left(Collections.singletonList(policyDefinition)));
364         when(componentsUtils
365                      .convertJsonToObjectUsingObjectMapper(any(), any(), eq(ComponentInstInputsMap.class), eq(
366                              AuditingActionEnum.CREATE_RESOURCE), eq(ComponentTypeEnum.SERVICE)))
367                         .thenReturn(Either.left(getDeclarationBodyForProperty(PROP_1)));
368     }
369
370     private List<PropertyDataDefinition> getPropertiesList() {
371         PropertyDefinition prop1 = new PropertyDataDefinitionBuilder()
372                 .setUniqueId("prop1")
373                 .build();
374
375         PropertyDefinition prop2 = new PropertyDataDefinitionBuilder()
376                 .setUniqueId("prop2")
377                 .build();
378         return Arrays.asList(prop1, prop2);
379     }
380
381     private List<PolicyTargetDTO> getTargetDTOList() {
382         PolicyTargetDTO target1 = new PolicyTargetDTO();
383         target1.setUniqueIds(Collections.singletonList("uniqueId"));
384         target1.setType("GROUPS");
385
386         PolicyTargetDTO target2 = new PolicyTargetDTO();
387         target2.setUniqueIds(Collections.singletonList("uniqueId"));
388         target2.setType("component_Instances");
389
390         return Arrays.asList(target1, target2);
391     }
392
393     private Invocation.Builder buildGetPropertiesRequest(String componentType) {
394         return target(PROPS_URL)
395                 .resolveTemplate("componentType", componentType)
396                 .resolveTemplate("serviceId", SERVICE_ID)
397                 .resolveTemplate("policyId", POLICY_ID)
398                 .request(MediaType.APPLICATION_JSON)
399                 .header(Constants.USER_ID_HEADER, USER_ID);
400
401     }
402     
403     private Invocation buildUpdatePropertiesRequest(String componentType, List<PropertyDataDefinition> properties) {
404         return target(PROPS_URL)
405                 .resolveTemplate("componentType", componentType)
406                 .resolveTemplate("serviceId", SERVICE_ID)
407                 .resolveTemplate("policyId", POLICY_ID)
408                 .request(MediaType.APPLICATION_JSON)
409                 .header(Constants.USER_ID_HEADER, USER_ID)
410                 .buildPut(Entity.entity(properties, MediaType.APPLICATION_JSON));
411     }
412
413     private Invocation buildUpdateTargetsRequest(String componentType, List<PolicyTargetDTO> targets) {
414         return target(UPDATE_TARGETS_URL)
415                 .resolveTemplate("componentType", componentType)
416                 .resolveTemplate("componentId", COMPONENT_ID)
417                 .resolveTemplate("policyId", POLICY_ID)
418                 .request(MediaType.APPLICATION_JSON)
419                 .header(Constants.USER_ID_HEADER, USER_ID)
420                 .buildPost(Entity.entity(targets, MediaType.APPLICATION_JSON));
421     }
422
423     private Invocation.Builder buildGetPropertiesRequest() {
424         return target(PROPS_URL)
425                 .resolveTemplate("componentType", "services")
426                 .resolveTemplate("serviceId", SERVICE_ID)
427                 .resolveTemplate("policyId", POLICY_ID)
428                 .request(MediaType.APPLICATION_JSON)
429                 .header(Constants.USER_ID_HEADER, USER_ID);
430     }
431
432     private Invocation buildDeletePolicyRequest(PolicyDefinition policyDefinition) {
433         return target(DELETE_URL)
434                        .resolveTemplate("containerComponentType", "services")
435                        .resolveTemplate("componentId", SERVICE_ID)
436                        .resolveTemplate("policyId", policyDefinition.getUniqueId())
437                        .request(MediaType.APPLICATION_JSON)
438                        .header(Constants.USER_ID_HEADER, USER_ID)
439                         .buildDelete();
440     }
441
442     private Invocation buildDeclarePropertiesRequest(String propertyId) {
443         return target(DECLARE_URL)
444                        .resolveTemplate("componentType", "services")
445                        .resolveTemplate("serviceId", SERVICE_ID)
446                        .request(MediaType.APPLICATION_JSON)
447                        .header(Constants.USER_ID_HEADER, USER_ID)
448                        .buildPost(Entity.entity(getDeclarationBodyForProperty(propertyId), MediaType.APPLICATION_JSON));
449     }
450
451     private ComponentInstInputsMap getDeclarationBodyForProperty(String propertyId) {
452         ComponentInstInputsMap componentInstInputsMap = new ComponentInstInputsMap();
453         ComponentInstancePropInput propInput = new ComponentInstancePropInput();
454         PropertyDefinition propertyDefinition = new PropertyDefinition();
455
456         propertyDefinition.setType("string");
457         propertyDefinition.setUniqueId(SERVICE_ID + "." + propertyId);
458         propInput.setInput(propertyDefinition);
459         propInput.setPropertiesName(propertyId);
460
461         componentInstInputsMap.setComponentInstancePropertiesToPolicies(new HashMap<>());
462         componentInstInputsMap.getComponentInstancePropertiesToPolicies().put("componentInstancePropertiesToPolicies", Collections.singletonList(propInput));
463
464         return componentInstInputsMap;
465     }
466     
467     @Override
468     protected ResourceConfig configure() {
469         return super.configure()
470                 .register(new PolicyServlet(businessLogic, servletUtils, null, componentsUtils));
471     }
472
473     private static void createMocks() {
474         propertyDeclarationOrchestrator = Mockito.mock(PropertyDeclarationOrchestrator.class);
475         toscaOperationFacade = Mockito.mock(ToscaOperationFacade.class);
476         businessLogic = Mockito.mock(PolicyBusinessLogic.class);
477         businessLogic.setPropertyDeclarationOrchestrator(propertyDeclarationOrchestrator);
478         businessLogic.setToscaOperationFacade(toscaOperationFacade);
479
480         baseBusinessLogic = Mockito.spy(BaseBusinessLogic.class);
481         baseBusinessLogic.setToscaOperationFacade(toscaOperationFacade);
482
483         componentsUtils = Mockito.mock(ComponentsUtils.class);
484         servletUtils = Mockito.mock(ServletUtils.class);
485         responseFormat = Mockito.mock(ResponseFormat.class);
486     }
487     
488 }