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