4d2c3621d9ecb991a407d363f3b346d21557fa51
[sdc.git] / catalog-be / src / test / java / org / openecomp / sdc / be / servlets / ElementServletTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2017 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  * Modifications copyright (c) 2019 Nokia
20  * ================================================================================
21  */
22
23 package org.openecomp.sdc.be.servlets;
24
25 import static org.assertj.core.api.Assertions.assertThat;
26 import static org.mockito.ArgumentMatchers.any;
27 import static org.mockito.ArgumentMatchers.eq;
28 import static org.mockito.Mockito.reset;
29 import static org.mockito.Mockito.when;
30
31 import fj.data.Either;
32 import java.util.ArrayList;
33 import java.util.HashMap;
34 import java.util.List;
35 import java.util.Map;
36 import javax.servlet.ServletContext;
37 import javax.servlet.http.HttpServletRequest;
38 import javax.servlet.http.HttpSession;
39 import javax.ws.rs.client.Entity;
40 import javax.ws.rs.core.Application;
41 import javax.ws.rs.core.MediaType;
42 import javax.ws.rs.core.Response;
43 import org.apache.commons.text.StrSubstitutor;
44 import org.apache.http.HttpStatus;
45 import org.glassfish.hk2.utilities.binding.AbstractBinder;
46 import org.glassfish.jersey.server.ResourceConfig;
47 import org.glassfish.jersey.test.JerseyTest;
48 import org.glassfish.jersey.test.TestProperties;
49 import org.junit.jupiter.api.AfterEach;
50 import org.junit.jupiter.api.BeforeAll;
51 import org.junit.jupiter.api.BeforeEach;
52 import org.junit.jupiter.api.Test;
53 import org.mockito.Mockito;
54 import org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic;
55 import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic;
56 import org.openecomp.sdc.be.components.impl.ElementBusinessLogic;
57 import org.openecomp.sdc.be.components.impl.ResourceBusinessLogic;
58 import org.openecomp.sdc.be.components.impl.ResourceImportManager;
59 import org.openecomp.sdc.be.components.impl.exceptions.ByResponseFormatComponentException;
60 import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
61 import org.openecomp.sdc.be.components.scheduledtasks.ComponentsCleanBusinessLogic;
62 import org.openecomp.sdc.be.config.Configuration;
63 import org.openecomp.sdc.be.config.ConfigurationManager;
64 import org.openecomp.sdc.be.config.SpringConfig;
65 import org.openecomp.sdc.be.dao.api.ActionStatus;
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.impl.WebAppContextWrapper;
70 import org.openecomp.sdc.be.model.ArtifactType;
71 import org.openecomp.sdc.be.model.BaseType;
72 import org.openecomp.sdc.be.model.PropertyScope;
73 import org.openecomp.sdc.be.model.Resource;
74 import org.openecomp.sdc.be.model.Tag;
75 import org.openecomp.sdc.be.model.User;
76 import org.openecomp.sdc.be.model.catalog.CatalogComponent;
77 import org.openecomp.sdc.be.model.category.CategoryDefinition;
78 import org.openecomp.sdc.be.model.category.GroupingDefinition;
79 import org.openecomp.sdc.be.model.category.SubCategoryDefinition;
80 import org.openecomp.sdc.be.ui.model.UiCategories;
81 import org.openecomp.sdc.be.user.Role;
82 import org.openecomp.sdc.be.user.UserBusinessLogic;
83 import org.openecomp.sdc.common.api.ConfigurationSource;
84 import org.openecomp.sdc.common.api.Constants;
85 import org.openecomp.sdc.common.impl.ExternalConfiguration;
86 import org.openecomp.sdc.common.impl.FSConfigurationSource;
87 import org.openecomp.sdc.exception.ResponseFormat;
88 import org.springframework.context.ApplicationContext;
89 import org.springframework.context.annotation.AnnotationConfigApplicationContext;
90 import org.springframework.web.context.WebApplicationContext;
91
92 class ElementServletTest extends JerseyTest {
93
94     public static final HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
95     public static final HttpSession session = Mockito.mock(HttpSession.class);
96     public static final ResourceImportManager resourceImportManager = Mockito.mock(ResourceImportManager.class);
97     public static final ResourceBusinessLogic resourceBusinessLogic = Mockito.mock(ResourceBusinessLogic.class);
98     public static final BeGenericServlet beGenericServlet = Mockito.mock(BeGenericServlet.class);
99     public static final Resource resource = Mockito.mock(Resource.class);
100     public static final UserBusinessLogic userBusinessLogic = Mockito.mock(UserBusinessLogic.class);
101     public static final ComponentInstanceBusinessLogic componentInstanceBusinessLogic = Mockito
102         .mock(ComponentInstanceBusinessLogic.class);
103     public static final ArtifactsBusinessLogic artifactsBusinessLogic = Mockito.mock(ArtifactsBusinessLogic.class);
104
105     private static final ServletContext servletContext = Mockito.mock(ServletContext.class);
106     public static final WebAppContextWrapper webAppContextWrapper = Mockito.mock(WebAppContextWrapper.class);
107     private static final WebApplicationContext webApplicationContext = Mockito.mock(WebApplicationContext.class);
108     private static final ServletUtils servletUtils = Mockito.mock(ServletUtils.class);
109     private static final UserBusinessLogic userAdmin = Mockito.mock(UserBusinessLogic.class);
110     private static final ComponentsUtils componentUtils = Mockito.mock(ComponentsUtils.class);
111     private static final ComponentsCleanBusinessLogic componentsCleanBusinessLogic = Mockito
112         .mock(ComponentsCleanBusinessLogic.class);
113     private static final ElementBusinessLogic elementBusinessLogic = Mockito.mock(ElementBusinessLogic.class);
114
115     private static final ResponseFormat okResponseFormat = new ResponseFormat(HttpStatus.SC_OK);
116     private static final ResponseFormat conflictResponseFormat = new ResponseFormat(HttpStatus.SC_CONFLICT);
117     private static final ResponseFormat generalErrorResponseFormat = new ResponseFormat(
118         HttpStatus.SC_INTERNAL_SERVER_ERROR);
119     private static final ResponseFormat createdResponseFormat = new ResponseFormat(HttpStatus.SC_CREATED);
120     private static final ResponseFormat noContentResponseFormat = new ResponseFormat(HttpStatus.SC_NO_CONTENT);
121     private static final ResponseFormat unauthorizedResponseFormat = Mockito.mock(ResponseFormat.class);
122     private static final ResponseFormat notFoundResponseFormat = Mockito.mock(ResponseFormat.class);
123     private static final ResponseFormat badRequestResponseFormat = Mockito.mock(ResponseFormat.class);
124     private static final String EMPTY_JSON = "{}";
125     private static final String COMPONENT_TYPE = "componentType";
126     private static final String CATEGORY_UNIQUE_ID = "categoryUniqueId";
127     private static final String CATEGORY_ID = "categoryId";
128     private static final String SUB_CATEGORY_UNIQUE_ID = "subCategoryUniqueId";
129     private static final String SUB_CATEGORY_ID = "subCategoryId";
130     private static final String GROUPING_UNIQUE_ID = "groupingUniqueId";
131
132     /* Users */
133     private static User designerUser = new User("designer", "designer", "designer", "designer@email.com",
134         Role.DESIGNER.name(), System
135         .currentTimeMillis());
136
137     private static ConfigurationManager configurationManager;
138
139     @BeforeAll
140     public static void setup() {
141
142         //Needed for User Authorization
143         when(servletContext.getAttribute(Constants.WEB_APPLICATION_CONTEXT_WRAPPER_ATTR))
144             .thenReturn(webAppContextWrapper);
145         when(webAppContextWrapper.getWebAppContext(servletContext)).thenReturn(webApplicationContext);
146         when(webApplicationContext.getBean(ServletUtils.class)).thenReturn(servletUtils);
147         when(servletUtils.getUserAdmin()).thenReturn(userAdmin);
148         when(servletUtils.getComponentsUtils()).thenReturn(componentUtils);
149         when(componentUtils.getResponseFormat(ActionStatus.RESTRICTED_OPERATION))
150             .thenReturn(unauthorizedResponseFormat);
151         when(unauthorizedResponseFormat.getStatus()).thenReturn(HttpStatus.SC_UNAUTHORIZED);
152
153         when(componentUtils.getResponseFormat(ActionStatus.OK)).thenReturn(okResponseFormat);
154         when(componentUtils.getResponseFormat(ActionStatus.CREATED)).thenReturn(createdResponseFormat);
155         when(componentUtils.getResponseFormat(ActionStatus.NO_CONTENT)).thenReturn(noContentResponseFormat);
156         when(componentUtils.getResponseFormat(ActionStatus.INVALID_CONTENT)).thenReturn(badRequestResponseFormat);
157         when(componentUtils.getResponseFormat(ActionStatus.GENERAL_ERROR)).thenReturn(generalErrorResponseFormat);
158         when(componentUtils.getResponseFormat(any(ComponentException.class)))
159             .thenReturn(generalErrorResponseFormat);
160
161         ByResponseFormatComponentException ce = Mockito.mock(ByResponseFormatComponentException.class);
162         when(ce.getResponseFormat()).thenReturn(unauthorizedResponseFormat);
163
164         //Needed for error configuration
165         when(notFoundResponseFormat.getStatus()).thenReturn(HttpStatus.SC_NOT_FOUND);
166         when(badRequestResponseFormat.getStatus()).thenReturn(HttpStatus.SC_BAD_REQUEST);
167         when(componentUtils.getResponseFormat(eq(ActionStatus.RESOURCE_NOT_FOUND), any()))
168             .thenReturn(notFoundResponseFormat);
169         when(componentUtils.getResponseFormat(eq(ActionStatus.COMPONENT_VERSION_NOT_FOUND), any()))
170             .thenReturn(notFoundResponseFormat);
171         when(componentUtils.getResponseFormat(eq(ActionStatus.COMPONENT_INSTANCE_NOT_FOUND), any()))
172             .thenReturn(notFoundResponseFormat);
173         when(componentUtils.getResponseFormat(eq(ActionStatus.EXT_REF_NOT_FOUND), any()))
174             .thenReturn(notFoundResponseFormat);
175         when(componentUtils.getResponseFormat(eq(ActionStatus.MISSING_X_ECOMP_INSTANCE_ID), any()))
176             .thenReturn(badRequestResponseFormat);
177         when(request.getSession()).thenReturn(session);
178         when(session.getServletContext()).thenReturn(servletContext);
179         when(beGenericServlet.getElementBL(any())).thenReturn(elementBusinessLogic);
180         when(webApplicationContext.getBean(ElementBusinessLogic.class)).thenReturn(elementBusinessLogic);
181         when(webApplicationContext.getBean(ComponentsUtils.class)).thenReturn(componentUtils);
182         when(beGenericServlet.getComponentsUtils()).thenReturn(componentUtils);
183
184         Either<User, ActionStatus> designerEither = Either.left(designerUser);
185
186         when(userAdmin.getUser(designerUser.getUserId(), false)).thenReturn(designerUser);
187
188         String appConfigDir = "src/test/resources/config/catalog-be";
189         ConfigurationSource configurationSource = new FSConfigurationSource(ExternalConfiguration.getChangeListener(),
190             appConfigDir);
191         configurationManager = new ConfigurationManager(configurationSource);
192
193         org.openecomp.sdc.be.config.Configuration configuration = new org.openecomp.sdc.be.config.Configuration();
194         configuration.setJanusGraphInMemoryGraph(true);
195         Configuration.HeatDeploymentArtifactTimeout testHeatDeploymentArtifactTimeout = new Configuration.HeatDeploymentArtifactTimeout();
196         testHeatDeploymentArtifactTimeout.setDefaultMinutes(1);
197         configuration.setHeatArtifactDeploymentTimeout(testHeatDeploymentArtifactTimeout);
198
199         configurationManager.setConfiguration(configuration);
200         ExternalConfiguration.setAppName("catalog-be");
201
202
203     }
204
205     @BeforeEach
206     public void before() throws Exception {
207         super.setUp();
208         reset(elementBusinessLogic);
209     }
210
211     @AfterEach
212     public void tearDown() throws Exception {
213         super.tearDown();
214     }
215
216     @Test
217     void getComponentCategoriesNoCategoryFoundTest() {
218         String componentType = ComponentTypeEnum.SERVICE_PARAM_NAME;
219         Map<String, String> parametersMap = new HashMap<>();
220         parametersMap.put(COMPONENT_TYPE, componentType);
221
222         String formatEndpoint = "/v1/categories/{componentType}";
223         String path = StrSubstitutor.replace(formatEndpoint, parametersMap, "{", "}");
224
225         ResponseFormat notFoundResponseFormat = new ResponseFormat(HttpStatus.SC_NOT_FOUND);
226         Either<List<CategoryDefinition>, ResponseFormat> getAllCategoriesEither = Either.right(notFoundResponseFormat);
227
228         when(elementBusinessLogic.getAllCategories(componentType, designerUser.getUserId()))
229             .thenReturn(getAllCategoriesEither);
230
231         Response response = target()
232             .path(path)
233             .request()
234             .accept(MediaType.APPLICATION_JSON)
235             .header(Constants.USER_ID_HEADER, designerUser.getUserId())
236             .get();
237
238         assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_NOT_FOUND);
239     }
240
241     @Test
242     void getComponentCategoriesExceptionDuringProcessingTest() {
243         String componentType = ComponentTypeEnum.SERVICE_PARAM_NAME;
244         Map<String, String> parametersMap = new HashMap<>();
245         parametersMap.put(COMPONENT_TYPE, componentType);
246
247         String formatEndpoint = "/v1/categories/{componentType}";
248         String path = StrSubstitutor.replace(formatEndpoint, parametersMap, "{", "}");
249
250         when(elementBusinessLogic.getAllCategories(componentType, designerUser.getUserId()))
251             .thenThrow(new RuntimeException("Test exception: getComponentCategories"));
252
253         Response response = target()
254             .path(path)
255             .request()
256             .accept(MediaType.APPLICATION_JSON)
257             .header(Constants.USER_ID_HEADER, designerUser.getUserId())
258             .get();
259
260         assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_INTERNAL_SERVER_ERROR);
261     }
262
263     @Test
264     void getComponentCategoriesTest() {
265         String componentType = ComponentTypeEnum.SERVICE_PARAM_NAME;
266         Map<String, String> parametersMap = new HashMap<>();
267         parametersMap.put(COMPONENT_TYPE, componentType);
268
269         String formatEndpoint = "/v1/categories/{componentType}";
270         String path = StrSubstitutor.replace(formatEndpoint, parametersMap, "{", "}");
271
272         Either<List<CategoryDefinition>, ResponseFormat> getAllCategoriesEither = Either.left(new ArrayList<>());
273
274         when(elementBusinessLogic.getAllCategories(componentType, designerUser.getUserId()))
275             .thenReturn(getAllCategoriesEither);
276
277         Response response = target()
278             .path(path)
279             .request()
280             .accept(MediaType.APPLICATION_JSON)
281             .header(Constants.USER_ID_HEADER, designerUser.getUserId())
282             .get();
283
284         assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_OK);
285     }
286
287     @Test
288     void getAllCategoriesNoCategoryFoundTest() {
289         String path = "/v1/categories";
290
291         ResponseFormat notFoundResponseFormat = new ResponseFormat(HttpStatus.SC_NOT_FOUND);
292         Either<UiCategories, ResponseFormat> getAllCategoriesEither = Either.right(notFoundResponseFormat);
293
294         when(elementBusinessLogic.getAllCategories(designerUser.getUserId()))
295             .thenReturn(getAllCategoriesEither);
296
297         Response response = target()
298             .path(path)
299             .request()
300             .accept(MediaType.APPLICATION_JSON)
301             .header(Constants.USER_ID_HEADER, designerUser.getUserId())
302             .get();
303
304         assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_NOT_FOUND);
305     }
306
307     @Test
308     void getAllCategoriesExceptionDuringProcessingTest() {
309         String path = "/v1/setup/ui";
310         when(elementBusinessLogic.getAllCategories(designerUser.getUserId()))
311             .thenThrow(new RuntimeException("Test exception: getAllCategories"));
312
313         Response response = target()
314             .path(path)
315             .request()
316             .accept(MediaType.APPLICATION_JSON)
317             .header(Constants.USER_ID_HEADER, designerUser.getUserId())
318             .get();
319
320         assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_INTERNAL_SERVER_ERROR);
321     }
322
323     @Test
324     void getAllCategoriesTest() {
325         String path = "/v1/setup/ui";
326         Either<UiCategories, ResponseFormat> getAllCategoriesEither = Either.left(new UiCategories());
327         Either<List<ArtifactType>, ActionStatus> otherEither = Either.left(new ArrayList<>());
328         when(elementBusinessLogic.getDefaultHeatTimeout())
329             .thenReturn(Either.left(configurationManager.getConfiguration().getHeatArtifactDeploymentTimeout()));
330         when(elementBusinessLogic.getResourceTypesMap()).thenReturn(Either.left(new HashMap<String, String>()));
331         when(elementBusinessLogic.getAllArtifactTypes(designerUser.getUserId()))
332             .thenReturn(otherEither);
333
334         when(elementBusinessLogic.getAllCategories(designerUser.getUserId()))
335             .thenReturn(getAllCategoriesEither);
336
337         Response response = target()
338             .path(path)
339             .request()
340             .accept(MediaType.APPLICATION_JSON)
341             .header(Constants.USER_ID_HEADER, designerUser.getUserId())
342             .get();
343
344         assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_OK);
345     }
346
347     @Test
348     void createComponentCategoryCreationFailedTest() {
349         String componentType = ComponentTypeEnum.SERVICE_PARAM_NAME;
350         Map<String, String> parametersMap = new HashMap<>();
351         parametersMap.put(COMPONENT_TYPE, componentType);
352
353         String formatEndpoint = "/v1/category/{componentType}";
354         String path = StrSubstitutor.replace(formatEndpoint, parametersMap, "{", "}");
355
356         Either<CategoryDefinition, ResponseFormat> createComponentCategoryEither = Either.right(conflictResponseFormat);
357
358         when(elementBusinessLogic.createCategory(any(), eq(componentType), eq(designerUser.getUserId())))
359             .thenReturn(createComponentCategoryEither);
360
361         Response response = target()
362             .path(path)
363             .request()
364             .accept(MediaType.APPLICATION_JSON)
365             .header(Constants.USER_ID_HEADER, designerUser.getUserId())
366             .post(Entity.json(EMPTY_JSON));
367
368         assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_CONFLICT);
369     }
370
371     @Test
372     void createComponentCategoryExceptionDuringCreationTest() {
373         String componentType = ComponentTypeEnum.SERVICE_PARAM_NAME;
374         Map<String, String> parametersMap = new HashMap<>();
375         parametersMap.put(COMPONENT_TYPE, componentType);
376
377         String formatEndpoint = "/v1/category/{componentType}";
378         String path = StrSubstitutor.replace(formatEndpoint, parametersMap, "{", "}");
379
380         when(elementBusinessLogic.createCategory(any(), eq(componentType), eq(designerUser.getUserId())))
381             .thenThrow(new RuntimeException("Test exception: createComponentCategory"));
382
383         Response response = target()
384             .path(path)
385             .request()
386             .accept(MediaType.APPLICATION_JSON)
387             .header(Constants.USER_ID_HEADER, designerUser.getUserId())
388             .post(Entity.json(EMPTY_JSON));
389
390         assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_INTERNAL_SERVER_ERROR);
391     }
392
393     @Test
394     void createComponentCategoryTest() {
395         String componentType = ComponentTypeEnum.SERVICE_PARAM_NAME;
396         Map<String, String> parametersMap = new HashMap<>();
397         parametersMap.put(COMPONENT_TYPE, componentType);
398
399         String formatEndpoint = "/v1/category/{componentType}";
400         String path = StrSubstitutor.replace(formatEndpoint, parametersMap, "{", "}");
401
402         Either<CategoryDefinition, ResponseFormat> createComponentCategoryEither = Either
403             .left(new CategoryDefinition());
404
405         when(elementBusinessLogic.createCategory(any(), eq(componentType), eq(designerUser.getUserId())))
406             .thenReturn(createComponentCategoryEither);
407
408         Response response = target()
409             .path(path)
410             .request()
411             .accept(MediaType.APPLICATION_JSON)
412             .header(Constants.USER_ID_HEADER, designerUser.getUserId())
413             .post(Entity.json(EMPTY_JSON));
414
415         assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_CREATED);
416     }
417
418     @Test
419     void deleteComponentCategoryNoCategoryFoundTest() {
420         String componentType = ComponentTypeEnum.SERVICE_PARAM_NAME;
421         String categoryUniqueId = "categoryUniqueId";
422         Map<String, String> parametersMap = new HashMap<>();
423         parametersMap.put(COMPONENT_TYPE, componentType);
424         parametersMap.put(CATEGORY_UNIQUE_ID, categoryUniqueId);
425
426         String formatEndpoint = "/v1/category/{componentType}/{categoryUniqueId}";
427         String path = StrSubstitutor.replace(formatEndpoint, parametersMap, "{", "}");
428
429         ResponseFormat notFoundResponseFormat = new ResponseFormat(HttpStatus.SC_NOT_FOUND);
430         Either<CategoryDefinition, ResponseFormat> deleteComponentCategoryEither = Either.right(notFoundResponseFormat);
431
432         when(elementBusinessLogic.deleteCategory(categoryUniqueId, componentType, designerUser.getUserId()))
433             .thenReturn(deleteComponentCategoryEither);
434
435         Response response = target()
436             .path(path)
437             .request()
438             .accept(MediaType.APPLICATION_JSON)
439             .header(Constants.USER_ID_HEADER, designerUser.getUserId())
440             .delete();
441
442         assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_NOT_FOUND);
443     }
444
445     @Test
446     void deleteComponentCategoryExceptionDuringProcessingTest() {
447         String componentType = ComponentTypeEnum.SERVICE_PARAM_NAME;
448         String categoryUniqueId = "categoryUniqueId";
449         Map<String, String> parametersMap = new HashMap<>();
450         parametersMap.put(COMPONENT_TYPE, componentType);
451         parametersMap.put(CATEGORY_UNIQUE_ID, categoryUniqueId);
452
453         String formatEndpoint = "/v1/category/{componentType}/{categoryUniqueId}";
454         String path = StrSubstitutor.replace(formatEndpoint, parametersMap, "{", "}");
455
456         when(elementBusinessLogic.deleteCategory(categoryUniqueId, componentType, designerUser.getUserId()))
457             .thenThrow(new RuntimeException("Test exception: deleteComponentCategory"));
458
459         Response response = target()
460             .path(path)
461             .request()
462             .accept(MediaType.APPLICATION_JSON)
463             .header(Constants.USER_ID_HEADER, designerUser.getUserId())
464             .delete();
465
466         assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_INTERNAL_SERVER_ERROR);
467     }
468
469     @Test
470     void deleteComponentCategoryTest() {
471         String componentType = ComponentTypeEnum.SERVICE_PARAM_NAME;
472         String categoryUniqueId = "categoryUniqueId";
473         Map<String, String> parametersMap = new HashMap<>();
474         parametersMap.put(COMPONENT_TYPE, componentType);
475         parametersMap.put(CATEGORY_UNIQUE_ID, categoryUniqueId);
476
477         String formatEndpoint = "/v1/category/{componentType}/{categoryUniqueId}";
478         String path = StrSubstitutor.replace(formatEndpoint, parametersMap, "{", "}");
479
480         Either<CategoryDefinition, ResponseFormat> deleteComponentCategoryEither = Either
481             .left(new CategoryDefinition());
482         when(elementBusinessLogic.deleteCategory(categoryUniqueId, componentType, designerUser.getUserId()))
483             .thenReturn(deleteComponentCategoryEither);
484
485         Response response = target()
486             .path(path)
487             .request()
488             .accept(MediaType.APPLICATION_JSON)
489             .header(Constants.USER_ID_HEADER, designerUser.getUserId())
490             .delete();
491
492         assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_NO_CONTENT);
493     }
494
495     @Test
496     void createComponentSubCategoryCreationFailedTest() {
497         String componentType = ComponentTypeEnum.SERVICE_PARAM_NAME;
498         String categoryId = "categoryId";
499         Map<String, String> parametersMap = new HashMap<>();
500         parametersMap.put(COMPONENT_TYPE, componentType);
501         parametersMap.put(CATEGORY_ID, categoryId);
502
503         String formatEndpoint = "/v1/category/{componentType}/{categoryId}/subCategory";
504         String path = StrSubstitutor.replace(formatEndpoint, parametersMap, "{", "}");
505
506         Either<SubCategoryDefinition, ResponseFormat> createComponentSubCategoryEither = Either
507             .right(conflictResponseFormat);
508
509         when(elementBusinessLogic
510             .createSubCategory(any(), eq(componentType), eq(categoryId), eq(designerUser.getUserId())))
511             .thenReturn(createComponentSubCategoryEither);
512
513         Response response = target()
514             .path(path)
515             .request()
516             .accept(MediaType.APPLICATION_JSON)
517             .header(Constants.USER_ID_HEADER, designerUser.getUserId())
518             .post(Entity.json(EMPTY_JSON));
519
520         assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_CONFLICT);
521     }
522
523     @Test
524     void createComponentSubCategoryExceptionDuringCreationTest() {
525         String componentType = ComponentTypeEnum.SERVICE_PARAM_NAME;
526         String categoryId = "categoryId";
527         Map<String, String> parametersMap = new HashMap<>();
528         parametersMap.put(COMPONENT_TYPE, componentType);
529         parametersMap.put(CATEGORY_ID, categoryId);
530
531         String formatEndpoint = "/v1/category/{componentType}/{categoryId}/subCategory";
532         String path = StrSubstitutor.replace(formatEndpoint, parametersMap, "{", "}");
533
534         when(elementBusinessLogic
535             .createSubCategory(any(), eq(componentType), eq(categoryId), eq(designerUser.getUserId())))
536             .thenThrow(new RuntimeException("Test exception: createComponentSubCategory"));
537
538         Response response = target()
539             .path(path)
540             .request()
541             .accept(MediaType.APPLICATION_JSON)
542             .header(Constants.USER_ID_HEADER, designerUser.getUserId())
543             .post(Entity.json(EMPTY_JSON));
544
545         assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_INTERNAL_SERVER_ERROR);
546     }
547
548     @Test
549     void createComponentSubCategoryTest() {
550         String componentType = ComponentTypeEnum.SERVICE_PARAM_NAME;
551         String categoryId = "categoryId";
552         Map<String, String> parametersMap = new HashMap<>();
553         parametersMap.put(COMPONENT_TYPE, componentType);
554         parametersMap.put(CATEGORY_ID, categoryId);
555
556         String formatEndpoint = "/v1/category/{componentType}/{categoryId}/subCategory";
557         String path = StrSubstitutor.replace(formatEndpoint, parametersMap, "{", "}");
558
559         Either<SubCategoryDefinition, ResponseFormat> createComponentSubCategoryEither = Either
560             .left(new SubCategoryDefinition());
561
562         when(elementBusinessLogic
563             .createSubCategory(any(), eq(componentType), eq(categoryId), eq(designerUser.getUserId())))
564             .thenReturn(createComponentSubCategoryEither);
565
566         Response response = target()
567             .path(path)
568             .request()
569             .accept(MediaType.APPLICATION_JSON)
570             .header(Constants.USER_ID_HEADER, designerUser.getUserId())
571             .post(Entity.json(EMPTY_JSON));
572
573         assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_CREATED);
574     }
575
576     @Test
577     void deleteComponentSubCategoryCreationFailedTest() {
578         String componentType = ComponentTypeEnum.SERVICE_PARAM_NAME;
579         String categoryUniqueId = "categoryUniqueId";
580         String subCategoryUniqueId = "subCategoryUniqueId";
581         Map<String, String> parametersMap = new HashMap<>();
582         parametersMap.put(COMPONENT_TYPE, componentType);
583         parametersMap.put(CATEGORY_UNIQUE_ID, categoryUniqueId);
584         parametersMap.put(SUB_CATEGORY_UNIQUE_ID, subCategoryUniqueId);
585
586         String formatEndpoint = "/v1/category/{componentType}/{categoryUniqueId}/subCategory/{subCategoryUniqueId}";
587         String path = StrSubstitutor.replace(formatEndpoint, parametersMap, "{", "}");
588
589         Either<SubCategoryDefinition, ResponseFormat> deleteComponentSubCategoryEither = Either
590             .right(conflictResponseFormat);
591
592         when(elementBusinessLogic
593             .deleteSubCategory(eq(subCategoryUniqueId), eq(componentType), eq(designerUser.getUserId())))
594             .thenReturn(deleteComponentSubCategoryEither);
595
596         Response response = target()
597             .path(path)
598             .request()
599             .accept(MediaType.APPLICATION_JSON)
600             .header(Constants.USER_ID_HEADER, designerUser.getUserId())
601             .delete();
602
603         assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_CONFLICT);
604     }
605
606     @Test
607     void deleteComponentSubCategoryExceptionDuringCreationTest() {
608         String componentType = ComponentTypeEnum.SERVICE_PARAM_NAME;
609         String categoryUniqueId = "categoryUniqueId";
610         String subCategoryUniqueId = "subCategoryUniqueId";
611         Map<String, String> parametersMap = new HashMap<>();
612         parametersMap.put(COMPONENT_TYPE, componentType);
613         parametersMap.put(CATEGORY_UNIQUE_ID, categoryUniqueId);
614         parametersMap.put(SUB_CATEGORY_UNIQUE_ID, subCategoryUniqueId);
615
616         String formatEndpoint = "/v1/category/{componentType}/{categoryUniqueId}/subCategory/{subCategoryUniqueId}";
617         String path = StrSubstitutor.replace(formatEndpoint, parametersMap, "{", "}");
618
619         when(elementBusinessLogic
620             .deleteSubCategory(eq(subCategoryUniqueId), eq(componentType), eq(designerUser.getUserId())))
621             .thenThrow(new RuntimeException("Test exception: deleteComponentSubCategory"));
622
623         Response response = target()
624             .path(path)
625             .request()
626             .accept(MediaType.APPLICATION_JSON)
627             .header(Constants.USER_ID_HEADER, designerUser.getUserId())
628             .delete();
629
630         assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_INTERNAL_SERVER_ERROR);
631     }
632
633     @Test
634     void deleteComponentSubCategoryTest() {
635         String componentType = ComponentTypeEnum.SERVICE_PARAM_NAME;
636         String categoryUniqueId = "categoryUniqueId";
637         String subCategoryUniqueId = "subCategoryUniqueId";
638         Map<String, String> parametersMap = new HashMap<>();
639         parametersMap.put(COMPONENT_TYPE, componentType);
640         parametersMap.put(CATEGORY_UNIQUE_ID, categoryUniqueId);
641         parametersMap.put(SUB_CATEGORY_UNIQUE_ID, subCategoryUniqueId);
642
643         String formatEndpoint = "/v1/category/{componentType}/{categoryUniqueId}/subCategory/{subCategoryUniqueId}";
644         String path = StrSubstitutor.replace(formatEndpoint, parametersMap, "{", "}");
645
646         Either<SubCategoryDefinition, ResponseFormat> deleteComponentSubCategoryEither = Either
647             .left(new SubCategoryDefinition());
648
649         when(elementBusinessLogic
650             .deleteSubCategory(eq(subCategoryUniqueId), eq(componentType), eq(designerUser.getUserId())))
651             .thenReturn(deleteComponentSubCategoryEither);
652
653         Response response = target()
654             .path(path)
655             .request()
656             .accept(MediaType.APPLICATION_JSON)
657             .header(Constants.USER_ID_HEADER, designerUser.getUserId())
658             .delete();
659
660         assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_NO_CONTENT);
661     }
662
663     @Test
664     void createComponentGroupingCreationFailedTest() {
665         String componentType = ComponentTypeEnum.SERVICE_PARAM_NAME;
666         String categoryId = "categoryUniqueId";
667         String subCategoryId = "subCategoryId";
668         Map<String, String> parametersMap = new HashMap<>();
669         parametersMap.put(COMPONENT_TYPE, componentType);
670         parametersMap.put(CATEGORY_ID, categoryId);
671         parametersMap.put(SUB_CATEGORY_ID, subCategoryId);
672
673         String formatEndpoint = "/v1/category/{componentType}/{categoryId}/subCategory/{subCategoryId}/grouping";
674         String path = StrSubstitutor.replace(formatEndpoint, parametersMap, "{", "}");
675
676         Either<GroupingDefinition, ResponseFormat> createComponentGroupingEither = Either.right(conflictResponseFormat);
677
678         when(elementBusinessLogic
679             .createGrouping(any(), eq(componentType), eq(categoryId), eq(subCategoryId), eq(designerUser.getUserId())))
680             .thenReturn(createComponentGroupingEither);
681
682         Response response = target()
683             .path(path)
684             .request()
685             .accept(MediaType.APPLICATION_JSON)
686             .header(Constants.USER_ID_HEADER, designerUser.getUserId())
687             .post(Entity.json(EMPTY_JSON));
688
689         assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_CONFLICT);
690     }
691
692     @Test
693     void createComponentGroupingExceptionDuringCreationTest() {
694         String componentType = ComponentTypeEnum.SERVICE_PARAM_NAME;
695         String categoryId = "categoryUniqueId";
696         String subCategoryId = "subCategoryId";
697         Map<String, String> parametersMap = new HashMap<>();
698         parametersMap.put(COMPONENT_TYPE, componentType);
699         parametersMap.put(CATEGORY_ID, categoryId);
700         parametersMap.put(SUB_CATEGORY_ID, subCategoryId);
701
702         String formatEndpoint = "/v1/category/{componentType}/{categoryId}/subCategory/{subCategoryId}/grouping";
703         String path = StrSubstitutor.replace(formatEndpoint, parametersMap, "{", "}");
704
705         when(elementBusinessLogic
706             .createGrouping(any(), eq(componentType), eq(categoryId), eq(subCategoryId), eq(designerUser.getUserId())))
707             .thenThrow(new RuntimeException("Test exception: createComponentGrouping"));
708
709         Response response = target()
710             .path(path)
711             .request()
712             .accept(MediaType.APPLICATION_JSON)
713             .header(Constants.USER_ID_HEADER, designerUser.getUserId())
714             .post(Entity.json(EMPTY_JSON));
715
716         assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_INTERNAL_SERVER_ERROR);
717     }
718
719     @Test
720     void createComponentGroupingTest() {
721         String componentType = ComponentTypeEnum.SERVICE_PARAM_NAME;
722         String categoryId = "categoryUniqueId";
723         String subCategoryId = "subCategoryId";
724         Map<String, String> parametersMap = new HashMap<>();
725         parametersMap.put(COMPONENT_TYPE, componentType);
726         parametersMap.put(CATEGORY_ID, categoryId);
727         parametersMap.put(SUB_CATEGORY_ID, subCategoryId);
728
729         String formatEndpoint = "/v1/category/{componentType}/{categoryId}/subCategory/{subCategoryId}/grouping";
730         String path = StrSubstitutor.replace(formatEndpoint, parametersMap, "{", "}");
731
732         Either<GroupingDefinition, ResponseFormat> createComponentGroupingEither = Either
733             .left(new GroupingDefinition());
734
735         when(elementBusinessLogic
736             .createGrouping(any(), eq(componentType), eq(categoryId), eq(subCategoryId), eq(designerUser.getUserId())))
737             .thenReturn(createComponentGroupingEither);
738
739         Response response = target()
740             .path(path)
741             .request()
742             .accept(MediaType.APPLICATION_JSON)
743             .header(Constants.USER_ID_HEADER, designerUser.getUserId())
744             .post(Entity.json(EMPTY_JSON));
745
746         assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_CREATED);
747     }
748
749     @Test
750     void deleteComponentGroupingCreationFailedTest() {
751         String componentType = ComponentTypeEnum.SERVICE_PARAM_NAME;
752         String categoryUniqueId = "categoryUniqueId";
753         String subCategoryUniqueId = "subCategoryUniqueId";
754         String groupingUniqueId = "groupingUniqueId";
755         Map<String, String> parametersMap = new HashMap<>();
756         parametersMap.put(COMPONENT_TYPE, componentType);
757         parametersMap.put(CATEGORY_UNIQUE_ID, categoryUniqueId);
758         parametersMap.put(SUB_CATEGORY_UNIQUE_ID, subCategoryUniqueId);
759         parametersMap.put(GROUPING_UNIQUE_ID, groupingUniqueId);
760
761         String formatEndpoint = "/v1/category/{componentType}/{categoryUniqueId}/subCategory/{subCategoryUniqueId}/grouping/{groupingUniqueId}";
762         String path = StrSubstitutor.replace(formatEndpoint, parametersMap, "{", "}");
763
764         Either<GroupingDefinition, ResponseFormat> deleteComponentGroupingEither = Either.right(conflictResponseFormat);
765
766         when(elementBusinessLogic.deleteGrouping(eq(groupingUniqueId), eq(componentType), eq(designerUser.getUserId())))
767             .thenReturn(deleteComponentGroupingEither);
768
769         Response response = target()
770             .path(path)
771             .request()
772             .accept(MediaType.APPLICATION_JSON)
773             .header(Constants.USER_ID_HEADER, designerUser.getUserId())
774             .delete();
775
776         assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_CONFLICT);
777     }
778
779     @Test
780     void deleteComponentGroupingExceptionDuringCreationTest() {
781         String componentType = ComponentTypeEnum.SERVICE_PARAM_NAME;
782         String categoryUniqueId = "categoryUniqueId";
783         String subCategoryUniqueId = "subCategoryUniqueId";
784         String groupingUniqueId = "groupingUniqueId";
785         Map<String, String> parametersMap = new HashMap<>();
786         parametersMap.put(COMPONENT_TYPE, componentType);
787         parametersMap.put(CATEGORY_UNIQUE_ID, categoryUniqueId);
788         parametersMap.put(SUB_CATEGORY_UNIQUE_ID, subCategoryUniqueId);
789         parametersMap.put(GROUPING_UNIQUE_ID, groupingUniqueId);
790
791         String formatEndpoint = "/v1/category/{componentType}/{categoryUniqueId}/subCategory/{subCategoryUniqueId}/grouping/{groupingUniqueId}";
792         String path = StrSubstitutor.replace(formatEndpoint, parametersMap, "{", "}");
793
794         when(elementBusinessLogic.deleteGrouping(eq(groupingUniqueId), eq(componentType), eq(designerUser.getUserId())))
795             .thenThrow(new RuntimeException("Test exception: deleteComponentGrouping"));
796
797         Response response = target()
798             .path(path)
799             .request()
800             .accept(MediaType.APPLICATION_JSON)
801             .header(Constants.USER_ID_HEADER, designerUser.getUserId())
802             .delete();
803
804         assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_INTERNAL_SERVER_ERROR);
805     }
806
807     @Test
808     void deleteComponentGroupingTest() {
809         String componentType = ComponentTypeEnum.SERVICE_PARAM_NAME;
810         String categoryUniqueId = "categoryUniqueId";
811         String subCategoryUniqueId = "subCategoryUniqueId";
812         String groupingUniqueId = "groupingUniqueId";
813         Map<String, String> parametersMap = new HashMap<>();
814         parametersMap.put(COMPONENT_TYPE, componentType);
815         parametersMap.put(CATEGORY_UNIQUE_ID, categoryUniqueId);
816         parametersMap.put(SUB_CATEGORY_UNIQUE_ID, subCategoryUniqueId);
817         parametersMap.put(GROUPING_UNIQUE_ID, groupingUniqueId);
818
819         String formatEndpoint = "/v1/category/{componentType}/{categoryUniqueId}/subCategory/{subCategoryUniqueId}/grouping/{groupingUniqueId}";
820         String path = StrSubstitutor.replace(formatEndpoint, parametersMap, "{", "}");
821
822         Either<GroupingDefinition, ResponseFormat> deleteComponentGroupingEither = Either
823             .left(new GroupingDefinition());
824
825         when(elementBusinessLogic.deleteGrouping(eq(groupingUniqueId), eq(componentType), eq(designerUser.getUserId())))
826             .thenReturn(deleteComponentGroupingEither);
827
828         Response response = target()
829             .path(path)
830             .request()
831             .accept(MediaType.APPLICATION_JSON)
832             .header(Constants.USER_ID_HEADER, designerUser.getUserId())
833             .delete();
834
835         assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_NO_CONTENT);
836     }
837
838     @Test
839     void tagsNoTagsFoundTest() {
840         String path = "/v1/tags";
841         Either<List<Tag>, ActionStatus> tagsEither = Either.right(ActionStatus.NO_CONTENT);
842
843         when(elementBusinessLogic.getAllTags(designerUser.getUserId()))
844             .thenReturn(tagsEither);
845
846         Response response = target()
847             .path(path)
848             .request()
849             .accept(MediaType.APPLICATION_JSON)
850             .header(Constants.USER_ID_HEADER, designerUser.getUserId())
851             .get();
852
853         assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_NO_CONTENT);
854     }
855
856     @Test
857     void tagsExceptionDuringProcessingTest() {
858         String path = "/v1/tags";
859         when(elementBusinessLogic.getAllTags(designerUser.getUserId()))
860             .thenThrow(new RuntimeException("Test exception: tags"));
861
862         Response response = target()
863             .path(path)
864             .request()
865             .accept(MediaType.APPLICATION_JSON)
866             .header(Constants.USER_ID_HEADER, designerUser.getUserId())
867             .get();
868
869         assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_INTERNAL_SERVER_ERROR);
870     }
871
872     @Test
873     void tagsTest() {
874         String path = "/v1/tags";
875         Either<List<Tag>, ActionStatus> tagsEither = Either.left(new ArrayList<>());
876         when(elementBusinessLogic.getAllTags(designerUser.getUserId()))
877             .thenReturn(tagsEither);
878
879         Response response = target()
880             .path(path)
881             .request()
882             .accept(MediaType.APPLICATION_JSON)
883             .header(Constants.USER_ID_HEADER, designerUser.getUserId())
884             .get();
885
886         assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_OK);
887     }
888
889     @Test
890     void propertyScopesNoPropertyScopesFoundTest() {
891         String path = "/v1/propertyScopes";
892         Either<List<PropertyScope>, ActionStatus> propertyScopesEither = Either.right(ActionStatus.NO_CONTENT);
893
894         when(elementBusinessLogic.getAllPropertyScopes(designerUser.getUserId()))
895             .thenReturn(propertyScopesEither);
896
897         Response response = target()
898             .path(path)
899             .request()
900             .accept(MediaType.APPLICATION_JSON)
901             .header(Constants.USER_ID_HEADER, designerUser.getUserId())
902             .get();
903
904         assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_NO_CONTENT);
905     }
906
907     @Test
908     void propertyScopesExceptionDuringProcessingTest() {
909         String path = "/v1/propertyScopes";
910         when(elementBusinessLogic.getAllPropertyScopes(designerUser.getUserId()))
911             .thenThrow(new RuntimeException("Test exception: propertyScopes"));
912
913         Response response = target()
914             .path(path)
915             .request()
916             .accept(MediaType.APPLICATION_JSON)
917             .header(Constants.USER_ID_HEADER, designerUser.getUserId())
918             .get();
919
920         assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_INTERNAL_SERVER_ERROR);
921     }
922
923     @Test
924     void propertyScopesTest() {
925         String path = "/v1/propertyScopes";
926         Either<List<PropertyScope>, ActionStatus> propertyScopesEither = Either.left(new ArrayList<>());
927         when(elementBusinessLogic.getAllPropertyScopes(designerUser.getUserId()))
928             .thenReturn(propertyScopesEither);
929
930         Response response = target()
931             .path(path)
932             .request()
933             .accept(MediaType.APPLICATION_JSON)
934             .header(Constants.USER_ID_HEADER, designerUser.getUserId())
935             .get();
936
937         assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_OK);
938     }
939
940     @Test
941     void artifactTypesNoartifactTypesFoundTest() {
942         String path = "/v1/artifactTypes";
943         Either<List<ArtifactType>, ActionStatus> artifactTypesEither = Either.right(ActionStatus.NO_CONTENT);
944
945         when(elementBusinessLogic.getAllArtifactTypes(designerUser.getUserId()))
946             .thenReturn(artifactTypesEither);
947
948         Response response = target()
949             .path(path)
950             .request()
951             .accept(MediaType.APPLICATION_JSON)
952             .header(Constants.USER_ID_HEADER, designerUser.getUserId())
953             .get();
954
955         assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_NO_CONTENT);
956     }
957
958     @Test
959     void artifactTypesExceptionDuringProcessingTest() {
960         String path = "/v1/artifactTypes";
961         when(elementBusinessLogic.getAllArtifactTypes(designerUser.getUserId()))
962             .thenThrow(new RuntimeException("Test exception: artifactTypes"));
963
964         Response response = target()
965             .path(path)
966             .request()
967             .accept(MediaType.APPLICATION_JSON)
968             .header(Constants.USER_ID_HEADER, designerUser.getUserId())
969             .get();
970
971         assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_INTERNAL_SERVER_ERROR);
972     }
973
974     @Test
975     void artifactTypesTest() {
976         String path = "/v1/artifactTypes";
977         Either<List<ArtifactType>, ActionStatus> artifactTypesEither = Either.left(new ArrayList<>());
978         when(elementBusinessLogic.getAllArtifactTypes(designerUser.getUserId()))
979             .thenReturn(artifactTypesEither);
980
981         Response response = target()
982             .path(path)
983             .request()
984             .accept(MediaType.APPLICATION_JSON)
985             .header(Constants.USER_ID_HEADER, designerUser.getUserId())
986             .get();
987
988         assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_OK);
989     }
990
991     @Test
992     void configurationNoConfigurationFoundTest() {
993         String path = "/v1/setup/ui";
994
995         Either<List<ArtifactType>, ActionStatus> otherEither = Either.left(new ArrayList<>());
996         Configuration.HeatDeploymentArtifactTimeout heatDeploymentArtifactTimeout = new Configuration.HeatDeploymentArtifactTimeout();
997         heatDeploymentArtifactTimeout.setDefaultMinutes(1);
998         Either<Configuration.HeatDeploymentArtifactTimeout, ActionStatus> defaultHeatTimeoutEither = Either
999             .left(heatDeploymentArtifactTimeout);
1000         Either<Map<String, String>, ActionStatus> resourceTypesMapEither = Either.left(new HashMap<>());
1001
1002         when(elementBusinessLogic.getAllArtifactTypes(designerUser.getUserId()))
1003             .thenReturn(otherEither);
1004         when(elementBusinessLogic.getDefaultHeatTimeout())
1005             .thenReturn(defaultHeatTimeoutEither);
1006         when(elementBusinessLogic.getResourceTypesMap())
1007             .thenReturn(resourceTypesMapEither);
1008
1009         Response response = target()
1010             .path(path)
1011             .request()
1012             .accept(MediaType.APPLICATION_JSON)
1013             .header(Constants.USER_ID_HEADER, designerUser.getUserId())
1014             .get();
1015
1016         assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_INTERNAL_SERVER_ERROR);
1017     }
1018
1019     @Test
1020     void configurationExceptionDuringProcessingTest() {
1021         String path = "/v1/setup/ui";
1022         when(elementBusinessLogic.getAllArtifactTypes(designerUser.getUserId()))
1023             .thenThrow(new RuntimeException("Test exception: artifactTypes"));
1024
1025         Response response = target()
1026             .path(path)
1027             .request()
1028             .accept(MediaType.APPLICATION_JSON)
1029             .header(Constants.USER_ID_HEADER, designerUser.getUserId())
1030             .get();
1031
1032         assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_INTERNAL_SERVER_ERROR);
1033     }
1034
1035     @Test
1036     void screenNoCatalogComponentsFoundTest() {
1037         String path = "/v1/screen";
1038
1039         Either<Map<String, List<CatalogComponent>>, ResponseFormat> screenEither = Either
1040             .right(badRequestResponseFormat);
1041         when(elementBusinessLogic.getCatalogComponents(eq(designerUser.getUserId()), any()))
1042             .thenReturn(screenEither);
1043
1044         Response response = target()
1045             .path(path)
1046             .request()
1047             .accept(MediaType.APPLICATION_JSON)
1048             .header(Constants.USER_ID_HEADER, designerUser.getUserId())
1049             .get();
1050
1051         assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_BAD_REQUEST);
1052     }
1053
1054     @Test
1055     void screenExceptionDuringProcessingTest() {
1056         String path = "/v1/screen";
1057
1058         when(elementBusinessLogic.getCatalogComponents(eq(designerUser.getUserId()), any()))
1059             .thenThrow(new RuntimeException("Test exception: screen"));
1060
1061         Response response = target()
1062             .path(path)
1063             .request()
1064             .accept(MediaType.APPLICATION_JSON)
1065             .header(Constants.USER_ID_HEADER, designerUser.getUserId())
1066             .get();
1067
1068         assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_INTERNAL_SERVER_ERROR);
1069     }
1070
1071     @Test
1072     void screenTest() {
1073         String path = "/v1/screen";
1074
1075         Either<Map<String, List<CatalogComponent>>, ResponseFormat> screenEither = Either.left(new HashMap<>());
1076         when(elementBusinessLogic.getCatalogComponents(eq(designerUser.getUserId()), any()))
1077             .thenReturn(screenEither);
1078
1079         Response response = target()
1080             .path(path)
1081             .request()
1082             .accept(MediaType.APPLICATION_JSON)
1083             .header(Constants.USER_ID_HEADER, designerUser.getUserId())
1084             .get();
1085
1086         assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_OK);
1087     }
1088
1089     @Override
1090     protected Application configure() {
1091         ApplicationContext context = new AnnotationConfigApplicationContext(SpringConfig.class);
1092                 forceSet(TestProperties.CONTAINER_PORT, "0");
1093         return new ResourceConfig(ElementServlet.class)
1094             .register(new AbstractBinder() {
1095
1096                 @Override
1097                 protected void configure() {
1098                     bind(request).to(HttpServletRequest.class);
1099                     bind(userBusinessLogic).to(UserBusinessLogic.class);
1100                     bind(componentUtils).to(ComponentsUtils.class);
1101                     bind(componentsCleanBusinessLogic).to(ComponentsCleanBusinessLogic.class);
1102                     bind(elementBusinessLogic).to(ElementBusinessLogic.class);
1103                     bind(artifactsBusinessLogic).to(ArtifactsBusinessLogic.class);
1104                 }
1105             })
1106             .property("contextConfig", context);
1107     }
1108     
1109     @Test
1110     void getBaseTypesTest() {
1111         String path = "/v1/category/services/CAT1/baseTypes";
1112         Either<List<BaseType>, ActionStatus> baseTypesEither = Either.left(new ArrayList<>());
1113         when(elementBusinessLogic.getBaseTypes("CAT1", designerUser.getUserId()))
1114             .thenReturn(baseTypesEither);
1115
1116         Response response = target()
1117             .path(path)
1118             .request()
1119             .accept(MediaType.APPLICATION_JSON)
1120             .header(Constants.USER_ID_HEADER, designerUser.getUserId())
1121             .get();
1122
1123         assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_OK);
1124     }
1125     
1126     @Test
1127     void getBaseTypesNoBaseTypesFoundTest() {
1128         String path = "/v1/category/services/CAT1/baseTypes";
1129         Either<List<BaseType>, ActionStatus> baseTypesEither = Either.right(ActionStatus.NO_CONTENT);
1130
1131         when(elementBusinessLogic.getBaseTypes("CAT1", designerUser.getUserId()))
1132             .thenReturn(baseTypesEither);
1133
1134         Response response = target()
1135             .path(path)
1136             .request()
1137             .accept(MediaType.APPLICATION_JSON)
1138             .header(Constants.USER_ID_HEADER, designerUser.getUserId())
1139             .get();
1140
1141         assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_NO_CONTENT);
1142     }
1143     
1144 }