Fix locally failing TCs in catalog-be
[sdc.git] / catalog-be / src / test / java / org / openecomp / sdc / be / servlets / ComponentInstanceServletTest.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.anyString;
27 import static org.mockito.ArgumentMatchers.eq;
28 import static org.mockito.ArgumentMatchers.nullable;
29 import static org.mockito.Mockito.when;
30 import static org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum.SERVICE_PARAM_NAME;
31
32 import com.fasterxml.jackson.core.JsonProcessingException;
33 import com.fasterxml.jackson.databind.ObjectMapper;
34 import fj.data.Either;
35 import java.util.ArrayList;
36 import java.util.Arrays;
37 import java.util.List;
38 import java.util.Map;
39 import javax.servlet.ServletContext;
40 import javax.servlet.http.HttpServletRequest;
41 import javax.servlet.http.HttpSession;
42 import javax.ws.rs.client.Entity;
43 import javax.ws.rs.core.MediaType;
44 import javax.ws.rs.core.Response;
45 import org.eclipse.jetty.http.HttpStatus;
46 import org.glassfish.hk2.utilities.binding.AbstractBinder;
47 import org.glassfish.jersey.server.ResourceConfig;
48 import org.glassfish.jersey.test.JerseyTest;
49 import org.glassfish.jersey.test.TestProperties;
50 import org.junit.jupiter.api.AfterEach;
51 import org.junit.jupiter.api.BeforeAll;
52 import org.junit.jupiter.api.BeforeEach;
53 import org.junit.jupiter.api.Test;
54 import org.mockito.ArgumentMatchers;
55 import org.mockito.Mockito;
56 import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic;
57 import org.openecomp.sdc.be.components.impl.ComponentNodeFilterBusinessLogic;
58 import org.openecomp.sdc.be.components.impl.GroupBusinessLogic;
59 import org.openecomp.sdc.be.components.impl.ResourceImportManager;
60 import org.openecomp.sdc.be.components.impl.ServiceBusinessLogic;
61 import org.openecomp.sdc.be.config.Configuration;
62 import org.openecomp.sdc.be.config.ConfigurationManager;
63 import org.openecomp.sdc.be.config.SpringConfig;
64 import org.openecomp.sdc.be.dao.api.ActionStatus;
65 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
66 import org.openecomp.sdc.be.impl.ComponentsUtils;
67 import org.openecomp.sdc.be.impl.ServletUtils;
68 import org.openecomp.sdc.be.impl.WebAppContextWrapper;
69 import org.openecomp.sdc.be.model.ComponentInstance;
70 import org.openecomp.sdc.be.model.ComponentInstanceInput;
71 import org.openecomp.sdc.be.model.ComponentInstanceProperty;
72 import org.openecomp.sdc.be.model.RequirementCapabilityRelDef;
73 import org.openecomp.sdc.be.model.RequirementDefinition;
74 import org.openecomp.sdc.be.model.User;
75 import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
76 import org.openecomp.sdc.be.user.UserBusinessLogic;
77 import org.openecomp.sdc.common.api.Constants;
78 import org.openecomp.sdc.common.api.ConfigurationSource;
79 import org.openecomp.sdc.common.impl.ExternalConfiguration;
80 import org.openecomp.sdc.common.impl.FSConfigurationSource;
81 import org.openecomp.sdc.exception.ResponseFormat;
82 import org.springframework.context.ApplicationContext;
83 import org.springframework.context.annotation.AnnotationConfigApplicationContext;
84 import org.springframework.web.context.WebApplicationContext;
85
86
87 /**
88  * The test suite designed for test functionality of ComponentInstanceServlet class
89  */
90 class ComponentInstanceServletTest extends JerseyTest {
91
92     private final static String USER_ID = "jh0003";
93     private static HttpServletRequest request;
94     private static HttpSession session;
95     private static ServletContext servletContext;
96     private static WebAppContextWrapper webAppContextWrapper;
97     private static WebApplicationContext webApplicationContext;
98     private static ComponentInstanceBusinessLogic componentInstanceBusinessLogic;
99     private static ComponentsUtils componentsUtils;
100     private static ServletUtils servletUtils;
101     private static ResponseFormat responseFormat;
102     private static UserBusinessLogic userBusinessLogic;
103     private static GroupBusinessLogic groupBusinessLogic;
104     private static ResourceImportManager resourceImportManager;
105     private static ServiceBusinessLogic serviceBusinessLogic;
106     private static ComponentNodeFilterBusinessLogic componentNodeFilterBusinessLogic;
107     private static ConfigurationManager configurationManager;
108
109     @BeforeAll
110     public static void setup() {
111         createMocks();
112         stubMethods();
113         String appConfigDir = "src/test/resources/config/catalog-be";
114         ConfigurationSource configurationSource = new FSConfigurationSource(ExternalConfiguration.getChangeListener(), appConfigDir);
115         configurationManager = new ConfigurationManager(configurationSource);
116         org.openecomp.sdc.be.config.Configuration configuration = new org.openecomp.sdc.be.config.Configuration();
117         configuration.setJanusGraphInMemoryGraph(true);
118         configurationManager.setConfiguration(configuration);
119         ExternalConfiguration.setAppName("catalog-be");
120     }
121
122     @BeforeEach
123     public void before() throws Exception {
124         super.setUp();
125     }
126
127     @AfterEach
128     public void tearDown() throws Exception {
129         super.tearDown();
130     }
131
132     @Test
133     void testGetRelationByIdSuccess() {
134
135         String containerComponentType = "resources";
136         String componentId = "componentId";
137         String relationId = "relationId";
138         String path = "/v1/catalog/" + containerComponentType + "/" + componentId + "/" + relationId + "/relationId";
139         Either<RequirementCapabilityRelDef, ResponseFormat> successResponse = Either
140             .left(new RequirementCapabilityRelDef());
141         when(componentInstanceBusinessLogic
142             .getRelationById(eq(componentId), eq(relationId), eq(USER_ID), eq(ComponentTypeEnum.RESOURCE)))
143             .thenReturn(successResponse);
144         when(responseFormat.getStatus()).thenReturn(HttpStatus.OK_200);
145         when(componentsUtils.getResponseFormat(ActionStatus.OK)).thenReturn(responseFormat);
146         Response response = target()
147             .path(path)
148             .request(MediaType.APPLICATION_JSON)
149             .accept(MediaType.APPLICATION_JSON)
150             .header("USER_ID", USER_ID)
151             .get(Response.class);
152
153         assertThat(response.getStatus()).isEqualTo(HttpStatus.OK_200);
154     }
155
156     @Test
157     void testGetRelationByIdFailure() {
158
159         String containerComponentType = "unknown_type";
160         String componentId = "componentId";
161         String relationId = "relationId";
162         String path = "/v1/catalog/" + containerComponentType + "/" + componentId + "/" + relationId + "/relationId";
163         when(responseFormat.getStatus()).thenReturn(HttpStatus.BAD_REQUEST_400);
164         when(componentsUtils.getResponseFormat(eq(ActionStatus.UNSUPPORTED_ERROR), eq(containerComponentType)))
165             .thenReturn(responseFormat);
166         Response response = target()
167             .path(path)
168             .request(MediaType.APPLICATION_JSON)
169             .header("USER_ID", USER_ID)
170             .get(Response.class);
171
172         assertEquals(HttpStatus.BAD_REQUEST_400, response.getStatus());
173     }
174
175     @Test
176     void testBatchDeleteResourceInstancesSuccess() {
177
178         String componentId = "componentId";
179         String containerComponentType = ComponentTypeEnum.SERVICE_PARAM_NAME;
180         String compId1 = "compId1";
181         String[] delCompIds = new String[1];
182         delCompIds[0] = compId1;
183         List<ComponentInstance> compInsts = new ArrayList<ComponentInstance>();
184         String path = "/v1/catalog/" + containerComponentType + "/" + componentId + "/batchDeleteResourceInstances";
185
186         ComponentInstance compInst = new ComponentInstance();
187         compInst.setName(compId1);
188         compInst.setUniqueId(compId1);
189         compInst.setComponentUid(compId1);
190         compInst.setInvariantName(compId1);
191         compInsts.add(compInst);
192
193         when(responseFormat.getStatus()).thenReturn(HttpStatus.OK_200);
194         when(componentsUtils.getResponseFormat(ActionStatus.OK)).thenReturn(responseFormat);
195         Either<String[], ResponseFormat> convertStatusEither = Either.left(delCompIds);
196         when(componentsUtils
197             .convertJsonToObjectUsingObjectMapper(anyString(), any(User.class), ArgumentMatchers.<Class<String[]>>any(),
198                 nullable(AuditingActionEnum.class), nullable(ComponentTypeEnum.class))).thenReturn(convertStatusEither);
199         when(componentInstanceBusinessLogic
200             .batchDeleteComponentInstance(eq(containerComponentType), eq(componentId), any(List.class),
201                 eq(USER_ID))).thenReturn(Mockito.mock(Map.class));
202
203         Response response = target()
204             .path(path)
205             .request(MediaType.APPLICATION_JSON)
206             .header("USER_ID", USER_ID)
207             .post(Entity.json(compInsts));
208
209         assertEquals(HttpStatus.OK_200, response.getStatus());
210     }
211
212     @Test
213     void testBatchDeleteResourceInstancesFailure() {
214
215         String componentId = "componentId";
216         String containerComponentType = ComponentTypeEnum.SERVICE_PARAM_NAME;
217         String path = "/v1/catalog/" + containerComponentType + "/" + componentId + "/batchDeleteResourceInstances";
218
219         when(responseFormat.getStatus()).thenReturn(HttpStatus.INTERNAL_SERVER_ERROR_500);
220         when(componentsUtils.getResponseFormat(ActionStatus.INVALID_CONTENT)).thenReturn(responseFormat);
221
222         Response response = target()
223             .path(path)
224             .request(MediaType.APPLICATION_JSON)
225             .header("USER_ID", USER_ID)
226             .post(Entity.json(""));
227
228         assertEquals(HttpStatus.INTERNAL_SERVER_ERROR_500, response.getStatus());
229     }
230
231     @Test
232     void testBatchDissociateRIFromRISuccess() {
233
234         String componentId = "componentId";
235         String containerComponentType = ComponentTypeEnum.SERVICE_PARAM_NAME;
236         String path = "/v1/catalog/" + containerComponentType + "/" + componentId + "/resourceInstance/batchDissociate";
237         RequirementCapabilityRelDef[] refs = new RequirementCapabilityRelDef[1];
238         RequirementCapabilityRelDef ref = new RequirementCapabilityRelDef();
239         refs[0] = ref;
240
241         when(responseFormat.getStatus()).thenReturn(HttpStatus.OK_200);
242         when(componentsUtils.getResponseFormat(ActionStatus.OK)).thenReturn(responseFormat);
243         Either<RequirementCapabilityRelDef[], ResponseFormat> convertReqEither = Either.left(refs);
244         when(componentsUtils.convertJsonToObjectUsingObjectMapper(anyString(), any(User.class),
245             ArgumentMatchers.<Class<RequirementCapabilityRelDef[]>>any(),
246             nullable(AuditingActionEnum.class), nullable(ComponentTypeEnum.class))).thenReturn(convertReqEither);
247         RequirementCapabilityRelDef actionResponseEither = ref;
248         when(componentInstanceBusinessLogic
249             .dissociateRIFromRI(componentId, USER_ID, ref, ComponentTypeEnum.findByParamName(containerComponentType)))
250             .thenReturn(actionResponseEither);
251
252         Response response = target()
253             .path(path)
254             .request(MediaType.APPLICATION_JSON)
255             .header("USER_ID", USER_ID)
256             .put(Entity.json(refs));
257
258         assertEquals(HttpStatus.OK_200, response.getStatus());
259     }
260
261     @Test
262     void testBatchDissociateRIFromRIFailure() {
263
264         String componentId = "componentId";
265         String containerComponentType = ComponentTypeEnum.SERVICE_PARAM_NAME;
266         String path = "/v1/catalog/" + containerComponentType + "/" + componentId + "/resourceInstance/batchDissociate";
267
268         when(responseFormat.getStatus()).thenReturn(HttpStatus.INTERNAL_SERVER_ERROR_500);
269         when(componentsUtils.getResponseFormat(ActionStatus.INVALID_CONTENT)).thenReturn(responseFormat);
270
271         Response response = target()
272             .path(path)
273             .request(MediaType.APPLICATION_JSON)
274             .header("USER_ID", USER_ID)
275             .put(Entity.json(""));
276
277         assertEquals(HttpStatus.INTERNAL_SERVER_ERROR_500, response.getStatus());
278     }
279
280     @Override
281     protected ResourceConfig configure() {
282         forceSet(TestProperties.CONTAINER_PORT, "0");
283         ApplicationContext context = new AnnotationConfigApplicationContext(SpringConfig.class);
284         return new ResourceConfig(ComponentInstanceServlet.class)
285             .register(new AbstractBinder() {
286                 @Override
287                 protected void configure() {
288                     bind(request).to(HttpServletRequest.class);
289                     bind(userBusinessLogic).to(UserBusinessLogic.class);
290                     bind(groupBusinessLogic).to(GroupBusinessLogic.class);
291                     bind(componentInstanceBusinessLogic).to(ComponentInstanceBusinessLogic.class);
292                     bind(componentsUtils).to(ComponentsUtils.class);
293                     bind(servletUtils).to(ServletUtils.class);
294                     bind(resourceImportManager).to(ResourceImportManager.class);
295                     bind(serviceBusinessLogic).to(ServiceBusinessLogic.class);
296                     bind(componentNodeFilterBusinessLogic).to(ComponentNodeFilterBusinessLogic.class);
297                 }
298             })
299             .property("contextConfig", context);
300     }
301
302     private static void createMocks() {
303         request = Mockito.mock(HttpServletRequest.class);
304         session = Mockito.mock(HttpSession.class);
305         servletContext = Mockito.mock(ServletContext.class);
306         webAppContextWrapper = Mockito.mock(WebAppContextWrapper.class);
307         webApplicationContext = Mockito.mock(WebApplicationContext.class);
308         userBusinessLogic = Mockito.mock(UserBusinessLogic.class);
309         groupBusinessLogic = Mockito.mock(GroupBusinessLogic.class);
310         resourceImportManager = Mockito.mock(ResourceImportManager.class);
311         componentInstanceBusinessLogic = Mockito.mock(ComponentInstanceBusinessLogic.class);
312         componentsUtils = Mockito.mock(ComponentsUtils.class);
313         servletUtils = Mockito.mock(ServletUtils.class);
314         responseFormat = Mockito.mock(ResponseFormat.class);
315         serviceBusinessLogic = Mockito.mock(ServiceBusinessLogic.class);
316         componentNodeFilterBusinessLogic = Mockito.mock(ComponentNodeFilterBusinessLogic.class);
317     }
318
319     private static void stubMethods() {
320         when(request.getSession()).thenReturn(session);
321         when(session.getServletContext()).thenReturn(servletContext);
322         when(servletContext.getAttribute(Constants.WEB_APPLICATION_CONTEXT_WRAPPER_ATTR))
323             .thenReturn(webAppContextWrapper);
324         when(webAppContextWrapper.getWebAppContext(servletContext)).thenReturn(webApplicationContext);
325         when(webApplicationContext.getBean(ComponentInstanceBusinessLogic.class))
326             .thenReturn(componentInstanceBusinessLogic);
327         when(request.getHeader("USER_ID")).thenReturn(USER_ID);
328         when(webApplicationContext.getBean(ServletUtils.class)).thenReturn(servletUtils);
329         when(servletUtils.getComponentsUtils()).thenReturn(componentsUtils);
330     }
331
332     @Test
333     void testUpdateResourceInstancePropertiesSuccess() {
334
335         String containerComponentType = "services";
336         String componentId = "componentId";
337         String resourceInstanceId = "resourceInstanceId";
338         ComponentInstanceProperty[] properties = new ComponentInstanceProperty[1];
339         ComponentInstanceProperty property = new ComponentInstanceProperty();
340         property.setName("property");
341         property.setValue("value");
342         property.setType("String");
343         properties[0] = (property);
344         ObjectMapper mapper = new ObjectMapper();
345         String propertyJson = null;
346         try {
347             propertyJson = mapper.writeValueAsString(properties);
348         } catch (JsonProcessingException e) {
349             e.printStackTrace();
350         }
351         String path = "/v1/catalog/" + containerComponentType + "/" + componentId + "/resourceInstance" + "/" +
352             resourceInstanceId + "/properties";
353         when(componentsUtils
354             .convertJsonToObjectUsingObjectMapper(propertyJson, new User(), ComponentInstanceProperty[].class,
355                 null, ComponentTypeEnum.RESOURCE_INSTANCE)).thenReturn(Either.left(properties));
356         when(componentInstanceBusinessLogic
357             .createOrUpdatePropertiesValues(eq(ComponentTypeEnum.findByParamName(SERVICE_PARAM_NAME)),
358                 eq(componentId), eq(resourceInstanceId), eq(Arrays.asList(properties)), eq(USER_ID)))
359             .thenReturn(Either.left(Arrays.asList(properties)));
360         when(responseFormat.getStatus()).thenReturn(HttpStatus.OK_200);
361         when(componentsUtils.getResponseFormat(ActionStatus.OK)).thenReturn(responseFormat);
362         Response response = target()
363             .path(path)
364             .request(MediaType.APPLICATION_JSON)
365             .header("USER_ID", USER_ID).post(Entity.entity(properties, MediaType.APPLICATION_JSON));
366         assertThat(response.getStatus()).isEqualTo(HttpStatus.OK_200);
367     }
368
369     @Test
370     void testUpdateResourceInstanceInputsSuccess() {
371
372         String containerComponentType = "services";
373         String componentId = "componentId";
374         String resourceInstanceId = "resourceInstanceId";
375         ComponentInstanceInput[] inputs = new ComponentInstanceInput[1];
376         ComponentInstanceInput input = new ComponentInstanceInput();
377         input.setName("input");
378         input.setValue("value");
379         input.setType("String");
380         inputs[0] = (input);
381         ObjectMapper mapper = new ObjectMapper();
382         String inputJson = null;
383         try {
384             inputJson = mapper.writeValueAsString(inputs);
385         } catch (JsonProcessingException e) {
386             e.printStackTrace();
387         }
388         String path = "/v1/catalog/" + containerComponentType + "/" + componentId + "/resourceInstance" + "/" +
389             resourceInstanceId + "/inputs";
390         when(componentsUtils.convertJsonToObjectUsingObjectMapper(inputJson, new User(), ComponentInstanceInput[].class,
391             null, ComponentTypeEnum.RESOURCE_INSTANCE)).thenReturn(Either.left(inputs));
392         when(componentInstanceBusinessLogic
393             .createOrUpdateInstanceInputValues(eq(ComponentTypeEnum.findByParamName(SERVICE_PARAM_NAME)),
394                 eq(componentId), eq(resourceInstanceId), eq(Arrays.asList(inputs)), eq(USER_ID)))
395             .thenReturn(Either.left(Arrays.asList(inputs)));
396         when(responseFormat.getStatus()).thenReturn(HttpStatus.OK_200);
397         when(componentsUtils.getResponseFormat(ActionStatus.OK)).thenReturn(responseFormat);
398         Response response = target()
399             .path(path)
400             .request(MediaType.APPLICATION_JSON)
401             .header("USER_ID", USER_ID).post(Entity.entity(inputs, MediaType.APPLICATION_JSON));
402         assertThat(response.getStatus()).isEqualTo(HttpStatus.OK_200);
403     }
404
405     @Test
406     void testUpdateResourceInstancePropertiesFailure() {
407
408         String containerComponentType = "services";
409         String componentId = "componentId";
410         String resourceInstanceId = "resourceInstanceId";
411         ComponentInstanceProperty[] properties = new ComponentInstanceProperty[1];
412         ComponentInstanceProperty property = new ComponentInstanceProperty();
413         property.setName("property");
414         property.setValue("value");
415         property.setType("String");
416         properties[0] = (property);
417         ObjectMapper mapper = new ObjectMapper();
418         String propertyJson = null;
419         try {
420             propertyJson = mapper.writeValueAsString(properties);
421         } catch (JsonProcessingException e) {
422             e.printStackTrace();
423         }
424         String path = "/v1/catalog/" + containerComponentType + "/" + componentId + "/resourceInstance" + "/" +
425             resourceInstanceId + "/properties";
426         when(componentsUtils
427             .convertJsonToObjectUsingObjectMapper(propertyJson, new User(), ComponentInstanceProperty[].class,
428                 null, ComponentTypeEnum.RESOURCE_INSTANCE)).thenReturn(Either.left(properties));
429         when(componentInstanceBusinessLogic
430             .createOrUpdatePropertiesValues(eq(ComponentTypeEnum.findByParamName(SERVICE_PARAM_NAME)),
431                 eq(componentId), eq(resourceInstanceId), eq(Arrays.asList(properties)), eq(USER_ID)))
432             .thenReturn(Either.right(new ResponseFormat(404)));
433         when(responseFormat.getStatus()).thenReturn(HttpStatus.NOT_FOUND_404);
434         when(componentsUtils.getResponseFormat(ActionStatus.RESOURCE_NOT_FOUND)).thenReturn(responseFormat);
435         Response response = target()
436             .path(path)
437             .request(MediaType.APPLICATION_JSON)
438             .header("USER_ID", USER_ID).post(Entity.entity(properties, MediaType.APPLICATION_JSON));
439         assertThat(response.getStatus()).isEqualTo(HttpStatus.NOT_FOUND_404);
440     }
441
442     @Test
443     void testUpdateResourceInstanceInputsFailure() {
444
445         String containerComponentType = "services";
446         String componentId = "componentId";
447         String resourceInstanceId = "resourceInstanceId";
448         ComponentInstanceInput[] inputs = new ComponentInstanceInput[1];
449         ComponentInstanceInput input = new ComponentInstanceInput();
450         input.setName("input");
451         input.setValue("value");
452         input.setType("String");
453         inputs[0] = (input);
454         ObjectMapper mapper = new ObjectMapper();
455         String inputJson = null;
456         try {
457             inputJson = mapper.writeValueAsString(inputs);
458         } catch (JsonProcessingException e) {
459             e.printStackTrace();
460         }
461         String path = "/v1/catalog/" + containerComponentType + "/" + componentId + "/resourceInstance" + "/" +
462             resourceInstanceId + "/inputs";
463         when(componentsUtils.convertJsonToObjectUsingObjectMapper(inputJson, new User(), ComponentInstanceInput[].class,
464             null, ComponentTypeEnum.RESOURCE_INSTANCE)).thenReturn(Either.left(inputs));
465         when(componentInstanceBusinessLogic
466             .createOrUpdateInstanceInputValues(eq(ComponentTypeEnum.findByParamName(SERVICE_PARAM_NAME)),
467                 eq(componentId), eq(resourceInstanceId), eq(Arrays.asList(inputs)), eq(USER_ID)))
468             .thenReturn(Either.right(new ResponseFormat(404)));
469         when(responseFormat.getStatus()).thenReturn(HttpStatus.NOT_FOUND_404);
470         when(componentsUtils.getResponseFormat(ActionStatus.RESOURCE_NOT_FOUND)).thenReturn(responseFormat);
471         Response response = target()
472             .path(path)
473             .request(MediaType.APPLICATION_JSON)
474             .header("USER_ID", USER_ID).post(Entity.entity(inputs, MediaType.APPLICATION_JSON));
475         assertThat(response.getStatus()).isEqualTo(HttpStatus.NOT_FOUND_404);
476     }
477
478     @Test
479     void testUpdateInstanceRequirement() {
480
481         String containerComponentType = "services";
482         String componentId = "componentId";
483         String componentInstanceId = "componentInstanceIdInstanceId";
484         String capabilityType = "capabilityType";
485         String requirementName = "requirementName";
486         RequirementDefinition requirementDefinition = new RequirementDefinition();
487         ObjectMapper mapper = new ObjectMapper();
488         String requirementJson = null;
489         try {
490             requirementJson = mapper.writeValueAsString(requirementDefinition);
491         } catch (JsonProcessingException e) {
492             e.printStackTrace();
493         }
494         String path = "/v1/catalog/" + containerComponentType + "/" + componentId + "/componentInstances/" +
495             componentInstanceId + "/requirement/" + capabilityType + "/requirementName/" + requirementName;
496         when(componentsUtils
497             .convertJsonToObjectUsingObjectMapper(eq(requirementJson), any(User.class), eq(RequirementDefinition.class),
498                 eq(AuditingActionEnum.GET_TOSCA_MODEL), eq(ComponentTypeEnum.SERVICE)))
499             .thenReturn(Either.left(requirementDefinition));
500         when(componentInstanceBusinessLogic.updateInstanceRequirement(ComponentTypeEnum.SERVICE,
501             componentId, componentInstanceId, capabilityType, requirementName, requirementDefinition, USER_ID))
502             .thenReturn(Either.left(requirementDefinition));
503         when(componentsUtils.getResponseFormat(ActionStatus.OK)).thenReturn(responseFormat);
504         when(responseFormat.getStatus()).thenReturn(HttpStatus.OK_200);
505
506         Response response = target()
507             .path(path)
508             .request(MediaType.APPLICATION_JSON)
509             .header("USER_ID", USER_ID).put(Entity.entity(requirementDefinition, MediaType.APPLICATION_JSON));
510         assertThat(response.getStatus()).isEqualTo(HttpStatus.OK_200);
511     }
512 }