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