2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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 * ================================================================================
23 package org.openecomp.sdc.be.servlets;
25 import static org.assertj.core.api.Assertions.assertThat;
26 import static org.mockito.ArgumentMatchers.any;
27 import static org.mockito.ArgumentMatchers.eq;
28 import static org.mockito.Mockito.reset;
29 import static org.mockito.Mockito.when;
31 import fj.data.Either;
32 import java.util.ArrayList;
33 import java.util.HashMap;
34 import java.util.List;
36 import javax.servlet.ServletContext;
37 import javax.servlet.http.HttpServletRequest;
38 import javax.servlet.http.HttpSession;
39 import javax.ws.rs.client.Entity;
40 import javax.ws.rs.core.Application;
41 import javax.ws.rs.core.MediaType;
42 import javax.ws.rs.core.Response;
43 import org.apache.commons.text.StrSubstitutor;
44 import org.apache.http.HttpStatus;
45 import org.glassfish.hk2.utilities.binding.AbstractBinder;
46 import org.glassfish.jersey.server.ResourceConfig;
47 import org.glassfish.jersey.test.JerseyTest;
48 import org.glassfish.jersey.test.TestProperties;
49 import org.junit.jupiter.api.AfterEach;
50 import org.junit.jupiter.api.BeforeAll;
51 import org.junit.jupiter.api.BeforeEach;
52 import org.junit.jupiter.api.Test;
53 import org.mockito.Mockito;
54 import org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic;
55 import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic;
56 import org.openecomp.sdc.be.components.impl.ElementBusinessLogic;
57 import org.openecomp.sdc.be.components.impl.ResourceBusinessLogic;
58 import org.openecomp.sdc.be.components.impl.ResourceImportManager;
59 import org.openecomp.sdc.be.components.impl.exceptions.ByResponseFormatComponentException;
60 import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
61 import org.openecomp.sdc.be.components.scheduledtasks.ComponentsCleanBusinessLogic;
62 import org.openecomp.sdc.be.config.Configuration;
63 import org.openecomp.sdc.be.config.ConfigurationManager;
64 import org.openecomp.sdc.be.config.SpringConfig;
65 import org.openecomp.sdc.be.dao.api.ActionStatus;
66 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
67 import org.openecomp.sdc.be.impl.ComponentsUtils;
68 import org.openecomp.sdc.be.impl.ServletUtils;
69 import org.openecomp.sdc.be.impl.WebAppContextWrapper;
70 import org.openecomp.sdc.be.model.ArtifactType;
71 import org.openecomp.sdc.be.model.BaseType;
72 import org.openecomp.sdc.be.model.PropertyScope;
73 import org.openecomp.sdc.be.model.Resource;
74 import org.openecomp.sdc.be.model.Tag;
75 import org.openecomp.sdc.be.model.User;
76 import org.openecomp.sdc.be.model.catalog.CatalogComponent;
77 import org.openecomp.sdc.be.model.category.CategoryDefinition;
78 import org.openecomp.sdc.be.model.category.GroupingDefinition;
79 import org.openecomp.sdc.be.model.category.SubCategoryDefinition;
80 import org.openecomp.sdc.be.ui.model.UiCategories;
81 import org.openecomp.sdc.be.user.Role;
82 import org.openecomp.sdc.be.user.UserBusinessLogic;
83 import org.openecomp.sdc.common.api.ConfigurationSource;
84 import org.openecomp.sdc.common.api.Constants;
85 import org.openecomp.sdc.common.impl.ExternalConfiguration;
86 import org.openecomp.sdc.common.impl.FSConfigurationSource;
87 import org.openecomp.sdc.exception.ResponseFormat;
88 import org.springframework.context.ApplicationContext;
89 import org.springframework.context.annotation.AnnotationConfigApplicationContext;
90 import org.springframework.web.context.WebApplicationContext;
92 class ElementServletTest extends JerseyTest {
94 public static final HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
95 public static final HttpSession session = Mockito.mock(HttpSession.class);
96 public static final ResourceImportManager resourceImportManager = Mockito.mock(ResourceImportManager.class);
97 public static final ResourceBusinessLogic resourceBusinessLogic = Mockito.mock(ResourceBusinessLogic.class);
98 public static final BeGenericServlet beGenericServlet = Mockito.mock(BeGenericServlet.class);
99 public static final Resource resource = Mockito.mock(Resource.class);
100 public static final UserBusinessLogic userBusinessLogic = Mockito.mock(UserBusinessLogic.class);
101 public static final ComponentInstanceBusinessLogic componentInstanceBusinessLogic = Mockito
102 .mock(ComponentInstanceBusinessLogic.class);
103 public static final ArtifactsBusinessLogic artifactsBusinessLogic = Mockito.mock(ArtifactsBusinessLogic.class);
105 private static final ServletContext servletContext = Mockito.mock(ServletContext.class);
106 public static final WebAppContextWrapper webAppContextWrapper = Mockito.mock(WebAppContextWrapper.class);
107 private static final WebApplicationContext webApplicationContext = Mockito.mock(WebApplicationContext.class);
108 private static final ServletUtils servletUtils = Mockito.mock(ServletUtils.class);
109 private static final UserBusinessLogic userAdmin = Mockito.mock(UserBusinessLogic.class);
110 private static final ComponentsUtils componentUtils = Mockito.mock(ComponentsUtils.class);
111 private static final ComponentsCleanBusinessLogic componentsCleanBusinessLogic = Mockito
112 .mock(ComponentsCleanBusinessLogic.class);
113 private static final ElementBusinessLogic elementBusinessLogic = Mockito.mock(ElementBusinessLogic.class);
115 private static final ResponseFormat okResponseFormat = new ResponseFormat(HttpStatus.SC_OK);
116 private static final ResponseFormat conflictResponseFormat = new ResponseFormat(HttpStatus.SC_CONFLICT);
117 private static final ResponseFormat generalErrorResponseFormat = new ResponseFormat(
118 HttpStatus.SC_INTERNAL_SERVER_ERROR);
119 private static final ResponseFormat createdResponseFormat = new ResponseFormat(HttpStatus.SC_CREATED);
120 private static final ResponseFormat noContentResponseFormat = new ResponseFormat(HttpStatus.SC_NO_CONTENT);
121 private static final ResponseFormat unauthorizedResponseFormat = Mockito.mock(ResponseFormat.class);
122 private static final ResponseFormat notFoundResponseFormat = Mockito.mock(ResponseFormat.class);
123 private static final ResponseFormat badRequestResponseFormat = Mockito.mock(ResponseFormat.class);
124 private static final String EMPTY_JSON = "{}";
125 private static final String COMPONENT_TYPE = "componentType";
126 private static final String CATEGORY_UNIQUE_ID = "categoryUniqueId";
127 private static final String CATEGORY_ID = "categoryId";
128 private static final String SUB_CATEGORY_UNIQUE_ID = "subCategoryUniqueId";
129 private static final String SUB_CATEGORY_ID = "subCategoryId";
130 private static final String GROUPING_UNIQUE_ID = "groupingUniqueId";
133 private static User designerUser = new User("designer", "designer", "designer", "designer@email.com",
134 Role.DESIGNER.name(), System
135 .currentTimeMillis());
137 private static ConfigurationManager configurationManager;
140 public static void setup() {
142 //Needed for User Authorization
143 when(servletContext.getAttribute(Constants.WEB_APPLICATION_CONTEXT_WRAPPER_ATTR))
144 .thenReturn(webAppContextWrapper);
145 when(webAppContextWrapper.getWebAppContext(servletContext)).thenReturn(webApplicationContext);
146 when(webApplicationContext.getBean(ServletUtils.class)).thenReturn(servletUtils);
147 when(servletUtils.getUserAdmin()).thenReturn(userAdmin);
148 when(servletUtils.getComponentsUtils()).thenReturn(componentUtils);
149 when(componentUtils.getResponseFormat(ActionStatus.RESTRICTED_OPERATION))
150 .thenReturn(unauthorizedResponseFormat);
151 when(unauthorizedResponseFormat.getStatus()).thenReturn(HttpStatus.SC_UNAUTHORIZED);
153 when(componentUtils.getResponseFormat(ActionStatus.OK)).thenReturn(okResponseFormat);
154 when(componentUtils.getResponseFormat(ActionStatus.CREATED)).thenReturn(createdResponseFormat);
155 when(componentUtils.getResponseFormat(ActionStatus.NO_CONTENT)).thenReturn(noContentResponseFormat);
156 when(componentUtils.getResponseFormat(ActionStatus.INVALID_CONTENT)).thenReturn(badRequestResponseFormat);
157 when(componentUtils.getResponseFormat(ActionStatus.GENERAL_ERROR)).thenReturn(generalErrorResponseFormat);
158 when(componentUtils.getResponseFormat(any(ComponentException.class)))
159 .thenReturn(generalErrorResponseFormat);
161 ByResponseFormatComponentException ce = Mockito.mock(ByResponseFormatComponentException.class);
162 when(ce.getResponseFormat()).thenReturn(unauthorizedResponseFormat);
164 //Needed for error configuration
165 when(notFoundResponseFormat.getStatus()).thenReturn(HttpStatus.SC_NOT_FOUND);
166 when(badRequestResponseFormat.getStatus()).thenReturn(HttpStatus.SC_BAD_REQUEST);
167 when(componentUtils.getResponseFormat(eq(ActionStatus.RESOURCE_NOT_FOUND), any()))
168 .thenReturn(notFoundResponseFormat);
169 when(componentUtils.getResponseFormat(eq(ActionStatus.COMPONENT_VERSION_NOT_FOUND), any()))
170 .thenReturn(notFoundResponseFormat);
171 when(componentUtils.getResponseFormat(eq(ActionStatus.COMPONENT_INSTANCE_NOT_FOUND), any()))
172 .thenReturn(notFoundResponseFormat);
173 when(componentUtils.getResponseFormat(eq(ActionStatus.EXT_REF_NOT_FOUND), any()))
174 .thenReturn(notFoundResponseFormat);
175 when(componentUtils.getResponseFormat(eq(ActionStatus.MISSING_X_ECOMP_INSTANCE_ID), any()))
176 .thenReturn(badRequestResponseFormat);
177 when(request.getSession()).thenReturn(session);
178 when(session.getServletContext()).thenReturn(servletContext);
179 when(beGenericServlet.getElementBL(any())).thenReturn(elementBusinessLogic);
180 when(webApplicationContext.getBean(ElementBusinessLogic.class)).thenReturn(elementBusinessLogic);
181 when(webApplicationContext.getBean(ComponentsUtils.class)).thenReturn(componentUtils);
182 when(beGenericServlet.getComponentsUtils()).thenReturn(componentUtils);
184 Either<User, ActionStatus> designerEither = Either.left(designerUser);
186 when(userAdmin.getUser(designerUser.getUserId(), false)).thenReturn(designerUser);
188 String appConfigDir = "src/test/resources/config/catalog-be";
189 ConfigurationSource configurationSource = new FSConfigurationSource(ExternalConfiguration.getChangeListener(),
191 configurationManager = new ConfigurationManager(configurationSource);
193 org.openecomp.sdc.be.config.Configuration configuration = new org.openecomp.sdc.be.config.Configuration();
194 configuration.setJanusGraphInMemoryGraph(true);
195 Configuration.HeatDeploymentArtifactTimeout testHeatDeploymentArtifactTimeout = new Configuration.HeatDeploymentArtifactTimeout();
196 testHeatDeploymentArtifactTimeout.setDefaultMinutes(1);
197 configuration.setHeatArtifactDeploymentTimeout(testHeatDeploymentArtifactTimeout);
199 configurationManager.setConfiguration(configuration);
200 ExternalConfiguration.setAppName("catalog-be");
206 public void before() throws Exception {
208 reset(elementBusinessLogic);
212 public void tearDown() throws Exception {
217 void getComponentCategoriesNoCategoryFoundTest() {
218 String componentType = ComponentTypeEnum.SERVICE_PARAM_NAME;
219 Map<String, String> parametersMap = new HashMap<>();
220 parametersMap.put(COMPONENT_TYPE, componentType);
222 String formatEndpoint = "/v1/categories/{componentType}";
223 String path = StrSubstitutor.replace(formatEndpoint, parametersMap, "{", "}");
225 ResponseFormat notFoundResponseFormat = new ResponseFormat(HttpStatus.SC_NOT_FOUND);
226 Either<List<CategoryDefinition>, ResponseFormat> getAllCategoriesEither = Either.right(notFoundResponseFormat);
228 when(elementBusinessLogic.getAllCategories(componentType, designerUser.getUserId()))
229 .thenReturn(getAllCategoriesEither);
231 Response response = target()
234 .accept(MediaType.APPLICATION_JSON)
235 .header(Constants.USER_ID_HEADER, designerUser.getUserId())
238 assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_NOT_FOUND);
242 void getComponentCategoriesExceptionDuringProcessingTest() {
243 String componentType = ComponentTypeEnum.SERVICE_PARAM_NAME;
244 Map<String, String> parametersMap = new HashMap<>();
245 parametersMap.put(COMPONENT_TYPE, componentType);
247 String formatEndpoint = "/v1/categories/{componentType}";
248 String path = StrSubstitutor.replace(formatEndpoint, parametersMap, "{", "}");
250 when(elementBusinessLogic.getAllCategories(componentType, designerUser.getUserId()))
251 .thenThrow(new RuntimeException("Test exception: getComponentCategories"));
253 Response response = target()
256 .accept(MediaType.APPLICATION_JSON)
257 .header(Constants.USER_ID_HEADER, designerUser.getUserId())
260 assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_INTERNAL_SERVER_ERROR);
264 void getComponentCategoriesTest() {
265 String componentType = ComponentTypeEnum.SERVICE_PARAM_NAME;
266 Map<String, String> parametersMap = new HashMap<>();
267 parametersMap.put(COMPONENT_TYPE, componentType);
269 String formatEndpoint = "/v1/categories/{componentType}";
270 String path = StrSubstitutor.replace(formatEndpoint, parametersMap, "{", "}");
272 Either<List<CategoryDefinition>, ResponseFormat> getAllCategoriesEither = Either.left(new ArrayList<>());
274 when(elementBusinessLogic.getAllCategories(componentType, designerUser.getUserId()))
275 .thenReturn(getAllCategoriesEither);
277 Response response = target()
280 .accept(MediaType.APPLICATION_JSON)
281 .header(Constants.USER_ID_HEADER, designerUser.getUserId())
284 assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_OK);
288 void getAllCategoriesNoCategoryFoundTest() {
289 String path = "/v1/categories";
291 ResponseFormat notFoundResponseFormat = new ResponseFormat(HttpStatus.SC_NOT_FOUND);
292 Either<UiCategories, ResponseFormat> getAllCategoriesEither = Either.right(notFoundResponseFormat);
294 when(elementBusinessLogic.getAllCategories(designerUser.getUserId()))
295 .thenReturn(getAllCategoriesEither);
297 Response response = target()
300 .accept(MediaType.APPLICATION_JSON)
301 .header(Constants.USER_ID_HEADER, designerUser.getUserId())
304 assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_NOT_FOUND);
308 void getAllCategoriesExceptionDuringProcessingTest() {
309 String path = "/v1/setup/ui";
310 when(elementBusinessLogic.getAllCategories(designerUser.getUserId()))
311 .thenThrow(new RuntimeException("Test exception: getAllCategories"));
313 Response response = target()
316 .accept(MediaType.APPLICATION_JSON)
317 .header(Constants.USER_ID_HEADER, designerUser.getUserId())
320 assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_INTERNAL_SERVER_ERROR);
324 void getAllCategoriesTest() {
325 String path = "/v1/setup/ui";
326 Either<UiCategories, ResponseFormat> getAllCategoriesEither = Either.left(new UiCategories());
327 Either<List<ArtifactType>, ActionStatus> otherEither = Either.left(new ArrayList<>());
328 when(elementBusinessLogic.getDefaultHeatTimeout())
329 .thenReturn(Either.left(configurationManager.getConfiguration().getHeatArtifactDeploymentTimeout()));
330 when(elementBusinessLogic.getResourceTypesMap()).thenReturn(Either.left(new HashMap<String, String>()));
331 when(elementBusinessLogic.getAllArtifactTypes(designerUser.getUserId()))
332 .thenReturn(otherEither);
334 when(elementBusinessLogic.getAllCategories(designerUser.getUserId()))
335 .thenReturn(getAllCategoriesEither);
337 Response response = target()
340 .accept(MediaType.APPLICATION_JSON)
341 .header(Constants.USER_ID_HEADER, designerUser.getUserId())
344 assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_OK);
348 void createComponentCategoryCreationFailedTest() {
349 String componentType = ComponentTypeEnum.SERVICE_PARAM_NAME;
350 Map<String, String> parametersMap = new HashMap<>();
351 parametersMap.put(COMPONENT_TYPE, componentType);
353 String formatEndpoint = "/v1/category/{componentType}";
354 String path = StrSubstitutor.replace(formatEndpoint, parametersMap, "{", "}");
356 Either<CategoryDefinition, ResponseFormat> createComponentCategoryEither = Either.right(conflictResponseFormat);
358 when(elementBusinessLogic.createCategory(any(), eq(componentType), eq(designerUser.getUserId())))
359 .thenReturn(createComponentCategoryEither);
361 Response response = target()
364 .accept(MediaType.APPLICATION_JSON)
365 .header(Constants.USER_ID_HEADER, designerUser.getUserId())
366 .post(Entity.json(EMPTY_JSON));
368 assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_CONFLICT);
372 void createComponentCategoryExceptionDuringCreationTest() {
373 String componentType = ComponentTypeEnum.SERVICE_PARAM_NAME;
374 Map<String, String> parametersMap = new HashMap<>();
375 parametersMap.put(COMPONENT_TYPE, componentType);
377 String formatEndpoint = "/v1/category/{componentType}";
378 String path = StrSubstitutor.replace(formatEndpoint, parametersMap, "{", "}");
380 when(elementBusinessLogic.createCategory(any(), eq(componentType), eq(designerUser.getUserId())))
381 .thenThrow(new RuntimeException("Test exception: createComponentCategory"));
383 Response response = target()
386 .accept(MediaType.APPLICATION_JSON)
387 .header(Constants.USER_ID_HEADER, designerUser.getUserId())
388 .post(Entity.json(EMPTY_JSON));
390 assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_INTERNAL_SERVER_ERROR);
394 void createComponentCategoryTest() {
395 String componentType = ComponentTypeEnum.SERVICE_PARAM_NAME;
396 Map<String, String> parametersMap = new HashMap<>();
397 parametersMap.put(COMPONENT_TYPE, componentType);
399 String formatEndpoint = "/v1/category/{componentType}";
400 String path = StrSubstitutor.replace(formatEndpoint, parametersMap, "{", "}");
402 Either<CategoryDefinition, ResponseFormat> createComponentCategoryEither = Either
403 .left(new CategoryDefinition());
405 when(elementBusinessLogic.createCategory(any(), eq(componentType), eq(designerUser.getUserId())))
406 .thenReturn(createComponentCategoryEither);
408 Response response = target()
411 .accept(MediaType.APPLICATION_JSON)
412 .header(Constants.USER_ID_HEADER, designerUser.getUserId())
413 .post(Entity.json(EMPTY_JSON));
415 assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_CREATED);
419 void deleteComponentCategoryNoCategoryFoundTest() {
420 String componentType = ComponentTypeEnum.SERVICE_PARAM_NAME;
421 String categoryUniqueId = "categoryUniqueId";
422 Map<String, String> parametersMap = new HashMap<>();
423 parametersMap.put(COMPONENT_TYPE, componentType);
424 parametersMap.put(CATEGORY_UNIQUE_ID, categoryUniqueId);
426 String formatEndpoint = "/v1/category/{componentType}/{categoryUniqueId}";
427 String path = StrSubstitutor.replace(formatEndpoint, parametersMap, "{", "}");
429 ResponseFormat notFoundResponseFormat = new ResponseFormat(HttpStatus.SC_NOT_FOUND);
430 Either<CategoryDefinition, ResponseFormat> deleteComponentCategoryEither = Either.right(notFoundResponseFormat);
432 when(elementBusinessLogic.deleteCategory(categoryUniqueId, componentType, designerUser.getUserId()))
433 .thenReturn(deleteComponentCategoryEither);
435 Response response = target()
438 .accept(MediaType.APPLICATION_JSON)
439 .header(Constants.USER_ID_HEADER, designerUser.getUserId())
442 assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_NOT_FOUND);
446 void deleteComponentCategoryExceptionDuringProcessingTest() {
447 String componentType = ComponentTypeEnum.SERVICE_PARAM_NAME;
448 String categoryUniqueId = "categoryUniqueId";
449 Map<String, String> parametersMap = new HashMap<>();
450 parametersMap.put(COMPONENT_TYPE, componentType);
451 parametersMap.put(CATEGORY_UNIQUE_ID, categoryUniqueId);
453 String formatEndpoint = "/v1/category/{componentType}/{categoryUniqueId}";
454 String path = StrSubstitutor.replace(formatEndpoint, parametersMap, "{", "}");
456 when(elementBusinessLogic.deleteCategory(categoryUniqueId, componentType, designerUser.getUserId()))
457 .thenThrow(new RuntimeException("Test exception: deleteComponentCategory"));
459 Response response = target()
462 .accept(MediaType.APPLICATION_JSON)
463 .header(Constants.USER_ID_HEADER, designerUser.getUserId())
466 assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_INTERNAL_SERVER_ERROR);
470 void deleteComponentCategoryTest() {
471 String componentType = ComponentTypeEnum.SERVICE_PARAM_NAME;
472 String categoryUniqueId = "categoryUniqueId";
473 Map<String, String> parametersMap = new HashMap<>();
474 parametersMap.put(COMPONENT_TYPE, componentType);
475 parametersMap.put(CATEGORY_UNIQUE_ID, categoryUniqueId);
477 String formatEndpoint = "/v1/category/{componentType}/{categoryUniqueId}";
478 String path = StrSubstitutor.replace(formatEndpoint, parametersMap, "{", "}");
480 Either<CategoryDefinition, ResponseFormat> deleteComponentCategoryEither = Either
481 .left(new CategoryDefinition());
482 when(elementBusinessLogic.deleteCategory(categoryUniqueId, componentType, designerUser.getUserId()))
483 .thenReturn(deleteComponentCategoryEither);
485 Response response = target()
488 .accept(MediaType.APPLICATION_JSON)
489 .header(Constants.USER_ID_HEADER, designerUser.getUserId())
492 assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_NO_CONTENT);
496 void createComponentSubCategoryCreationFailedTest() {
497 String componentType = ComponentTypeEnum.SERVICE_PARAM_NAME;
498 String categoryId = "categoryId";
499 Map<String, String> parametersMap = new HashMap<>();
500 parametersMap.put(COMPONENT_TYPE, componentType);
501 parametersMap.put(CATEGORY_ID, categoryId);
503 String formatEndpoint = "/v1/category/{componentType}/{categoryId}/subCategory";
504 String path = StrSubstitutor.replace(formatEndpoint, parametersMap, "{", "}");
506 Either<SubCategoryDefinition, ResponseFormat> createComponentSubCategoryEither = Either
507 .right(conflictResponseFormat);
509 when(elementBusinessLogic
510 .createSubCategory(any(), eq(componentType), eq(categoryId), eq(designerUser.getUserId())))
511 .thenReturn(createComponentSubCategoryEither);
513 Response response = target()
516 .accept(MediaType.APPLICATION_JSON)
517 .header(Constants.USER_ID_HEADER, designerUser.getUserId())
518 .post(Entity.json(EMPTY_JSON));
520 assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_CONFLICT);
524 void createComponentSubCategoryExceptionDuringCreationTest() {
525 String componentType = ComponentTypeEnum.SERVICE_PARAM_NAME;
526 String categoryId = "categoryId";
527 Map<String, String> parametersMap = new HashMap<>();
528 parametersMap.put(COMPONENT_TYPE, componentType);
529 parametersMap.put(CATEGORY_ID, categoryId);
531 String formatEndpoint = "/v1/category/{componentType}/{categoryId}/subCategory";
532 String path = StrSubstitutor.replace(formatEndpoint, parametersMap, "{", "}");
534 when(elementBusinessLogic
535 .createSubCategory(any(), eq(componentType), eq(categoryId), eq(designerUser.getUserId())))
536 .thenThrow(new RuntimeException("Test exception: createComponentSubCategory"));
538 Response response = target()
541 .accept(MediaType.APPLICATION_JSON)
542 .header(Constants.USER_ID_HEADER, designerUser.getUserId())
543 .post(Entity.json(EMPTY_JSON));
545 assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_INTERNAL_SERVER_ERROR);
549 void createComponentSubCategoryTest() {
550 String componentType = ComponentTypeEnum.SERVICE_PARAM_NAME;
551 String categoryId = "categoryId";
552 Map<String, String> parametersMap = new HashMap<>();
553 parametersMap.put(COMPONENT_TYPE, componentType);
554 parametersMap.put(CATEGORY_ID, categoryId);
556 String formatEndpoint = "/v1/category/{componentType}/{categoryId}/subCategory";
557 String path = StrSubstitutor.replace(formatEndpoint, parametersMap, "{", "}");
559 Either<SubCategoryDefinition, ResponseFormat> createComponentSubCategoryEither = Either
560 .left(new SubCategoryDefinition());
562 when(elementBusinessLogic
563 .createSubCategory(any(), eq(componentType), eq(categoryId), eq(designerUser.getUserId())))
564 .thenReturn(createComponentSubCategoryEither);
566 Response response = target()
569 .accept(MediaType.APPLICATION_JSON)
570 .header(Constants.USER_ID_HEADER, designerUser.getUserId())
571 .post(Entity.json(EMPTY_JSON));
573 assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_CREATED);
577 void deleteComponentSubCategoryCreationFailedTest() {
578 String componentType = ComponentTypeEnum.SERVICE_PARAM_NAME;
579 String categoryUniqueId = "categoryUniqueId";
580 String subCategoryUniqueId = "subCategoryUniqueId";
581 Map<String, String> parametersMap = new HashMap<>();
582 parametersMap.put(COMPONENT_TYPE, componentType);
583 parametersMap.put(CATEGORY_UNIQUE_ID, categoryUniqueId);
584 parametersMap.put(SUB_CATEGORY_UNIQUE_ID, subCategoryUniqueId);
586 String formatEndpoint = "/v1/category/{componentType}/{categoryUniqueId}/subCategory/{subCategoryUniqueId}";
587 String path = StrSubstitutor.replace(formatEndpoint, parametersMap, "{", "}");
589 Either<SubCategoryDefinition, ResponseFormat> deleteComponentSubCategoryEither = Either
590 .right(conflictResponseFormat);
592 when(elementBusinessLogic
593 .deleteSubCategory(eq(subCategoryUniqueId), eq(componentType), eq(designerUser.getUserId())))
594 .thenReturn(deleteComponentSubCategoryEither);
596 Response response = target()
599 .accept(MediaType.APPLICATION_JSON)
600 .header(Constants.USER_ID_HEADER, designerUser.getUserId())
603 assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_CONFLICT);
607 void deleteComponentSubCategoryExceptionDuringCreationTest() {
608 String componentType = ComponentTypeEnum.SERVICE_PARAM_NAME;
609 String categoryUniqueId = "categoryUniqueId";
610 String subCategoryUniqueId = "subCategoryUniqueId";
611 Map<String, String> parametersMap = new HashMap<>();
612 parametersMap.put(COMPONENT_TYPE, componentType);
613 parametersMap.put(CATEGORY_UNIQUE_ID, categoryUniqueId);
614 parametersMap.put(SUB_CATEGORY_UNIQUE_ID, subCategoryUniqueId);
616 String formatEndpoint = "/v1/category/{componentType}/{categoryUniqueId}/subCategory/{subCategoryUniqueId}";
617 String path = StrSubstitutor.replace(formatEndpoint, parametersMap, "{", "}");
619 when(elementBusinessLogic
620 .deleteSubCategory(eq(subCategoryUniqueId), eq(componentType), eq(designerUser.getUserId())))
621 .thenThrow(new RuntimeException("Test exception: deleteComponentSubCategory"));
623 Response response = target()
626 .accept(MediaType.APPLICATION_JSON)
627 .header(Constants.USER_ID_HEADER, designerUser.getUserId())
630 assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_INTERNAL_SERVER_ERROR);
634 void deleteComponentSubCategoryTest() {
635 String componentType = ComponentTypeEnum.SERVICE_PARAM_NAME;
636 String categoryUniqueId = "categoryUniqueId";
637 String subCategoryUniqueId = "subCategoryUniqueId";
638 Map<String, String> parametersMap = new HashMap<>();
639 parametersMap.put(COMPONENT_TYPE, componentType);
640 parametersMap.put(CATEGORY_UNIQUE_ID, categoryUniqueId);
641 parametersMap.put(SUB_CATEGORY_UNIQUE_ID, subCategoryUniqueId);
643 String formatEndpoint = "/v1/category/{componentType}/{categoryUniqueId}/subCategory/{subCategoryUniqueId}";
644 String path = StrSubstitutor.replace(formatEndpoint, parametersMap, "{", "}");
646 Either<SubCategoryDefinition, ResponseFormat> deleteComponentSubCategoryEither = Either
647 .left(new SubCategoryDefinition());
649 when(elementBusinessLogic
650 .deleteSubCategory(eq(subCategoryUniqueId), eq(componentType), eq(designerUser.getUserId())))
651 .thenReturn(deleteComponentSubCategoryEither);
653 Response response = target()
656 .accept(MediaType.APPLICATION_JSON)
657 .header(Constants.USER_ID_HEADER, designerUser.getUserId())
660 assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_NO_CONTENT);
664 void createComponentGroupingCreationFailedTest() {
665 String componentType = ComponentTypeEnum.SERVICE_PARAM_NAME;
666 String categoryId = "categoryUniqueId";
667 String subCategoryId = "subCategoryId";
668 Map<String, String> parametersMap = new HashMap<>();
669 parametersMap.put(COMPONENT_TYPE, componentType);
670 parametersMap.put(CATEGORY_ID, categoryId);
671 parametersMap.put(SUB_CATEGORY_ID, subCategoryId);
673 String formatEndpoint = "/v1/category/{componentType}/{categoryId}/subCategory/{subCategoryId}/grouping";
674 String path = StrSubstitutor.replace(formatEndpoint, parametersMap, "{", "}");
676 Either<GroupingDefinition, ResponseFormat> createComponentGroupingEither = Either.right(conflictResponseFormat);
678 when(elementBusinessLogic
679 .createGrouping(any(), eq(componentType), eq(categoryId), eq(subCategoryId), eq(designerUser.getUserId())))
680 .thenReturn(createComponentGroupingEither);
682 Response response = target()
685 .accept(MediaType.APPLICATION_JSON)
686 .header(Constants.USER_ID_HEADER, designerUser.getUserId())
687 .post(Entity.json(EMPTY_JSON));
689 assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_CONFLICT);
693 void createComponentGroupingExceptionDuringCreationTest() {
694 String componentType = ComponentTypeEnum.SERVICE_PARAM_NAME;
695 String categoryId = "categoryUniqueId";
696 String subCategoryId = "subCategoryId";
697 Map<String, String> parametersMap = new HashMap<>();
698 parametersMap.put(COMPONENT_TYPE, componentType);
699 parametersMap.put(CATEGORY_ID, categoryId);
700 parametersMap.put(SUB_CATEGORY_ID, subCategoryId);
702 String formatEndpoint = "/v1/category/{componentType}/{categoryId}/subCategory/{subCategoryId}/grouping";
703 String path = StrSubstitutor.replace(formatEndpoint, parametersMap, "{", "}");
705 when(elementBusinessLogic
706 .createGrouping(any(), eq(componentType), eq(categoryId), eq(subCategoryId), eq(designerUser.getUserId())))
707 .thenThrow(new RuntimeException("Test exception: createComponentGrouping"));
709 Response response = target()
712 .accept(MediaType.APPLICATION_JSON)
713 .header(Constants.USER_ID_HEADER, designerUser.getUserId())
714 .post(Entity.json(EMPTY_JSON));
716 assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_INTERNAL_SERVER_ERROR);
720 void createComponentGroupingTest() {
721 String componentType = ComponentTypeEnum.SERVICE_PARAM_NAME;
722 String categoryId = "categoryUniqueId";
723 String subCategoryId = "subCategoryId";
724 Map<String, String> parametersMap = new HashMap<>();
725 parametersMap.put(COMPONENT_TYPE, componentType);
726 parametersMap.put(CATEGORY_ID, categoryId);
727 parametersMap.put(SUB_CATEGORY_ID, subCategoryId);
729 String formatEndpoint = "/v1/category/{componentType}/{categoryId}/subCategory/{subCategoryId}/grouping";
730 String path = StrSubstitutor.replace(formatEndpoint, parametersMap, "{", "}");
732 Either<GroupingDefinition, ResponseFormat> createComponentGroupingEither = Either
733 .left(new GroupingDefinition());
735 when(elementBusinessLogic
736 .createGrouping(any(), eq(componentType), eq(categoryId), eq(subCategoryId), eq(designerUser.getUserId())))
737 .thenReturn(createComponentGroupingEither);
739 Response response = target()
742 .accept(MediaType.APPLICATION_JSON)
743 .header(Constants.USER_ID_HEADER, designerUser.getUserId())
744 .post(Entity.json(EMPTY_JSON));
746 assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_CREATED);
750 void deleteComponentGroupingCreationFailedTest() {
751 String componentType = ComponentTypeEnum.SERVICE_PARAM_NAME;
752 String categoryUniqueId = "categoryUniqueId";
753 String subCategoryUniqueId = "subCategoryUniqueId";
754 String groupingUniqueId = "groupingUniqueId";
755 Map<String, String> parametersMap = new HashMap<>();
756 parametersMap.put(COMPONENT_TYPE, componentType);
757 parametersMap.put(CATEGORY_UNIQUE_ID, categoryUniqueId);
758 parametersMap.put(SUB_CATEGORY_UNIQUE_ID, subCategoryUniqueId);
759 parametersMap.put(GROUPING_UNIQUE_ID, groupingUniqueId);
761 String formatEndpoint = "/v1/category/{componentType}/{categoryUniqueId}/subCategory/{subCategoryUniqueId}/grouping/{groupingUniqueId}";
762 String path = StrSubstitutor.replace(formatEndpoint, parametersMap, "{", "}");
764 Either<GroupingDefinition, ResponseFormat> deleteComponentGroupingEither = Either.right(conflictResponseFormat);
766 when(elementBusinessLogic.deleteGrouping(eq(groupingUniqueId), eq(componentType), eq(designerUser.getUserId())))
767 .thenReturn(deleteComponentGroupingEither);
769 Response response = target()
772 .accept(MediaType.APPLICATION_JSON)
773 .header(Constants.USER_ID_HEADER, designerUser.getUserId())
776 assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_CONFLICT);
780 void deleteComponentGroupingExceptionDuringCreationTest() {
781 String componentType = ComponentTypeEnum.SERVICE_PARAM_NAME;
782 String categoryUniqueId = "categoryUniqueId";
783 String subCategoryUniqueId = "subCategoryUniqueId";
784 String groupingUniqueId = "groupingUniqueId";
785 Map<String, String> parametersMap = new HashMap<>();
786 parametersMap.put(COMPONENT_TYPE, componentType);
787 parametersMap.put(CATEGORY_UNIQUE_ID, categoryUniqueId);
788 parametersMap.put(SUB_CATEGORY_UNIQUE_ID, subCategoryUniqueId);
789 parametersMap.put(GROUPING_UNIQUE_ID, groupingUniqueId);
791 String formatEndpoint = "/v1/category/{componentType}/{categoryUniqueId}/subCategory/{subCategoryUniqueId}/grouping/{groupingUniqueId}";
792 String path = StrSubstitutor.replace(formatEndpoint, parametersMap, "{", "}");
794 when(elementBusinessLogic.deleteGrouping(eq(groupingUniqueId), eq(componentType), eq(designerUser.getUserId())))
795 .thenThrow(new RuntimeException("Test exception: deleteComponentGrouping"));
797 Response response = target()
800 .accept(MediaType.APPLICATION_JSON)
801 .header(Constants.USER_ID_HEADER, designerUser.getUserId())
804 assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_INTERNAL_SERVER_ERROR);
808 void deleteComponentGroupingTest() {
809 String componentType = ComponentTypeEnum.SERVICE_PARAM_NAME;
810 String categoryUniqueId = "categoryUniqueId";
811 String subCategoryUniqueId = "subCategoryUniqueId";
812 String groupingUniqueId = "groupingUniqueId";
813 Map<String, String> parametersMap = new HashMap<>();
814 parametersMap.put(COMPONENT_TYPE, componentType);
815 parametersMap.put(CATEGORY_UNIQUE_ID, categoryUniqueId);
816 parametersMap.put(SUB_CATEGORY_UNIQUE_ID, subCategoryUniqueId);
817 parametersMap.put(GROUPING_UNIQUE_ID, groupingUniqueId);
819 String formatEndpoint = "/v1/category/{componentType}/{categoryUniqueId}/subCategory/{subCategoryUniqueId}/grouping/{groupingUniqueId}";
820 String path = StrSubstitutor.replace(formatEndpoint, parametersMap, "{", "}");
822 Either<GroupingDefinition, ResponseFormat> deleteComponentGroupingEither = Either
823 .left(new GroupingDefinition());
825 when(elementBusinessLogic.deleteGrouping(eq(groupingUniqueId), eq(componentType), eq(designerUser.getUserId())))
826 .thenReturn(deleteComponentGroupingEither);
828 Response response = target()
831 .accept(MediaType.APPLICATION_JSON)
832 .header(Constants.USER_ID_HEADER, designerUser.getUserId())
835 assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_NO_CONTENT);
839 void tagsNoTagsFoundTest() {
840 String path = "/v1/tags";
841 Either<List<Tag>, ActionStatus> tagsEither = Either.right(ActionStatus.NO_CONTENT);
843 when(elementBusinessLogic.getAllTags(designerUser.getUserId()))
844 .thenReturn(tagsEither);
846 Response response = target()
849 .accept(MediaType.APPLICATION_JSON)
850 .header(Constants.USER_ID_HEADER, designerUser.getUserId())
853 assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_NO_CONTENT);
857 void tagsExceptionDuringProcessingTest() {
858 String path = "/v1/tags";
859 when(elementBusinessLogic.getAllTags(designerUser.getUserId()))
860 .thenThrow(new RuntimeException("Test exception: tags"));
862 Response response = target()
865 .accept(MediaType.APPLICATION_JSON)
866 .header(Constants.USER_ID_HEADER, designerUser.getUserId())
869 assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_INTERNAL_SERVER_ERROR);
874 String path = "/v1/tags";
875 Either<List<Tag>, ActionStatus> tagsEither = Either.left(new ArrayList<>());
876 when(elementBusinessLogic.getAllTags(designerUser.getUserId()))
877 .thenReturn(tagsEither);
879 Response response = target()
882 .accept(MediaType.APPLICATION_JSON)
883 .header(Constants.USER_ID_HEADER, designerUser.getUserId())
886 assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_OK);
890 void propertyScopesNoPropertyScopesFoundTest() {
891 String path = "/v1/propertyScopes";
892 Either<List<PropertyScope>, ActionStatus> propertyScopesEither = Either.right(ActionStatus.NO_CONTENT);
894 when(elementBusinessLogic.getAllPropertyScopes(designerUser.getUserId()))
895 .thenReturn(propertyScopesEither);
897 Response response = target()
900 .accept(MediaType.APPLICATION_JSON)
901 .header(Constants.USER_ID_HEADER, designerUser.getUserId())
904 assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_NO_CONTENT);
908 void propertyScopesExceptionDuringProcessingTest() {
909 String path = "/v1/propertyScopes";
910 when(elementBusinessLogic.getAllPropertyScopes(designerUser.getUserId()))
911 .thenThrow(new RuntimeException("Test exception: propertyScopes"));
913 Response response = target()
916 .accept(MediaType.APPLICATION_JSON)
917 .header(Constants.USER_ID_HEADER, designerUser.getUserId())
920 assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_INTERNAL_SERVER_ERROR);
924 void propertyScopesTest() {
925 String path = "/v1/propertyScopes";
926 Either<List<PropertyScope>, ActionStatus> propertyScopesEither = Either.left(new ArrayList<>());
927 when(elementBusinessLogic.getAllPropertyScopes(designerUser.getUserId()))
928 .thenReturn(propertyScopesEither);
930 Response response = target()
933 .accept(MediaType.APPLICATION_JSON)
934 .header(Constants.USER_ID_HEADER, designerUser.getUserId())
937 assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_OK);
941 void artifactTypesNoartifactTypesFoundTest() {
942 String path = "/v1/artifactTypes";
943 Either<List<ArtifactType>, ActionStatus> artifactTypesEither = Either.right(ActionStatus.NO_CONTENT);
945 when(elementBusinessLogic.getAllArtifactTypes(designerUser.getUserId()))
946 .thenReturn(artifactTypesEither);
948 Response response = target()
951 .accept(MediaType.APPLICATION_JSON)
952 .header(Constants.USER_ID_HEADER, designerUser.getUserId())
955 assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_NO_CONTENT);
959 void artifactTypesExceptionDuringProcessingTest() {
960 String path = "/v1/artifactTypes";
961 when(elementBusinessLogic.getAllArtifactTypes(designerUser.getUserId()))
962 .thenThrow(new RuntimeException("Test exception: artifactTypes"));
964 Response response = target()
967 .accept(MediaType.APPLICATION_JSON)
968 .header(Constants.USER_ID_HEADER, designerUser.getUserId())
971 assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_INTERNAL_SERVER_ERROR);
975 void artifactTypesTest() {
976 String path = "/v1/artifactTypes";
977 Either<List<ArtifactType>, ActionStatus> artifactTypesEither = Either.left(new ArrayList<>());
978 when(elementBusinessLogic.getAllArtifactTypes(designerUser.getUserId()))
979 .thenReturn(artifactTypesEither);
981 Response response = target()
984 .accept(MediaType.APPLICATION_JSON)
985 .header(Constants.USER_ID_HEADER, designerUser.getUserId())
988 assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_OK);
992 void configurationNoConfigurationFoundTest() {
993 String path = "/v1/setup/ui";
995 Either<List<ArtifactType>, ActionStatus> otherEither = Either.left(new ArrayList<>());
996 Configuration.HeatDeploymentArtifactTimeout heatDeploymentArtifactTimeout = new Configuration.HeatDeploymentArtifactTimeout();
997 heatDeploymentArtifactTimeout.setDefaultMinutes(1);
998 Either<Configuration.HeatDeploymentArtifactTimeout, ActionStatus> defaultHeatTimeoutEither = Either
999 .left(heatDeploymentArtifactTimeout);
1000 Either<Map<String, String>, ActionStatus> resourceTypesMapEither = Either.left(new HashMap<>());
1002 when(elementBusinessLogic.getAllArtifactTypes(designerUser.getUserId()))
1003 .thenReturn(otherEither);
1004 when(elementBusinessLogic.getDefaultHeatTimeout())
1005 .thenReturn(defaultHeatTimeoutEither);
1006 when(elementBusinessLogic.getResourceTypesMap())
1007 .thenReturn(resourceTypesMapEither);
1009 Response response = target()
1012 .accept(MediaType.APPLICATION_JSON)
1013 .header(Constants.USER_ID_HEADER, designerUser.getUserId())
1016 assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_INTERNAL_SERVER_ERROR);
1020 void configurationExceptionDuringProcessingTest() {
1021 String path = "/v1/setup/ui";
1022 when(elementBusinessLogic.getAllArtifactTypes(designerUser.getUserId()))
1023 .thenThrow(new RuntimeException("Test exception: artifactTypes"));
1025 Response response = target()
1028 .accept(MediaType.APPLICATION_JSON)
1029 .header(Constants.USER_ID_HEADER, designerUser.getUserId())
1032 assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_INTERNAL_SERVER_ERROR);
1036 void screenNoCatalogComponentsFoundTest() {
1037 String path = "/v1/screen";
1039 Either<Map<String, List<CatalogComponent>>, ResponseFormat> screenEither = Either
1040 .right(badRequestResponseFormat);
1041 when(elementBusinessLogic.getCatalogComponents(eq(designerUser.getUserId()), any()))
1042 .thenReturn(screenEither);
1044 Response response = target()
1047 .accept(MediaType.APPLICATION_JSON)
1048 .header(Constants.USER_ID_HEADER, designerUser.getUserId())
1051 assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_BAD_REQUEST);
1055 void screenExceptionDuringProcessingTest() {
1056 String path = "/v1/screen";
1058 when(elementBusinessLogic.getCatalogComponents(eq(designerUser.getUserId()), any()))
1059 .thenThrow(new RuntimeException("Test exception: screen"));
1061 Response response = target()
1064 .accept(MediaType.APPLICATION_JSON)
1065 .header(Constants.USER_ID_HEADER, designerUser.getUserId())
1068 assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_INTERNAL_SERVER_ERROR);
1073 String path = "/v1/screen";
1075 Either<Map<String, List<CatalogComponent>>, ResponseFormat> screenEither = Either.left(new HashMap<>());
1076 when(elementBusinessLogic.getCatalogComponents(eq(designerUser.getUserId()), any()))
1077 .thenReturn(screenEither);
1079 Response response = target()
1082 .accept(MediaType.APPLICATION_JSON)
1083 .header(Constants.USER_ID_HEADER, designerUser.getUserId())
1086 assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_OK);
1090 protected Application configure() {
1091 ApplicationContext context = new AnnotationConfigApplicationContext(SpringConfig.class);
1092 forceSet(TestProperties.CONTAINER_PORT, "0");
1093 return new ResourceConfig(ElementServlet.class)
1094 .register(new AbstractBinder() {
1097 protected void configure() {
1098 bind(request).to(HttpServletRequest.class);
1099 bind(userBusinessLogic).to(UserBusinessLogic.class);
1100 bind(componentUtils).to(ComponentsUtils.class);
1101 bind(componentsCleanBusinessLogic).to(ComponentsCleanBusinessLogic.class);
1102 bind(elementBusinessLogic).to(ElementBusinessLogic.class);
1103 bind(artifactsBusinessLogic).to(ArtifactsBusinessLogic.class);
1106 .property("contextConfig", context);
1110 void getBaseTypesTest() {
1111 String path = "/v1/category/services/CAT1/baseTypes";
1112 Either<List<BaseType>, ActionStatus> baseTypesEither = Either.left(new ArrayList<>());
1113 when(elementBusinessLogic.getBaseTypes("CAT1", designerUser.getUserId()))
1114 .thenReturn(baseTypesEither);
1116 Response response = target()
1119 .accept(MediaType.APPLICATION_JSON)
1120 .header(Constants.USER_ID_HEADER, designerUser.getUserId())
1123 assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_OK);
1127 void getBaseTypesNoBaseTypesFoundTest() {
1128 String path = "/v1/category/services/CAT1/baseTypes";
1129 Either<List<BaseType>, ActionStatus> baseTypesEither = Either.right(ActionStatus.NO_CONTENT);
1131 when(elementBusinessLogic.getBaseTypes("CAT1", designerUser.getUserId()))
1132 .thenReturn(baseTypesEither);
1134 Response response = target()
1137 .accept(MediaType.APPLICATION_JSON)
1138 .header(Constants.USER_ID_HEADER, designerUser.getUserId())
1141 assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_NO_CONTENT);