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