+ public void deleteComponentSubCategoryCreationFailedTest() {
+ String componentType = ComponentTypeEnum.SERVICE_PARAM_NAME;
+ String categoryUniqueId = "categoryUniqueId";
+ String subCategoryUniqueId = "subCategoryUniqueId";
+ Map<String,String> parametersMap = new HashMap<>();
+ parametersMap.put(COMPONENT_TYPE, componentType);
+ parametersMap.put(CATEGORY_UNIQUE_ID, categoryUniqueId);
+ parametersMap.put(SUB_CATEGORY_UNIQUE_ID, subCategoryUniqueId);
+
+ String formatEndpoint = "/v1/category/{componentType}/{categoryUniqueId}/subCategory/{subCategoryUniqueId}";
+ String path = StrSubstitutor.replace(formatEndpoint, parametersMap, "{","}");
+
+ Either<SubCategoryDefinition, ResponseFormat> deleteComponentSubCategoryEither = Either.right(conflictResponseFormat);
+
+ when(elementBusinessLogic.deleteSubCategory(eq(subCategoryUniqueId), eq(componentType), eq(designerUser.getUserId())))
+ .thenReturn(deleteComponentSubCategoryEither);
+
+ Response response = target()
+ .path(path)
+ .request()
+ .accept(MediaType.APPLICATION_JSON)
+ .header(Constants.USER_ID_HEADER, designerUser.getUserId())
+ .delete();
+
+ assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_CONFLICT);
+ }
+
+ @Test
+ public void deleteComponentSubCategoryExceptionDuringCreationTest() {
+ String componentType = ComponentTypeEnum.SERVICE_PARAM_NAME;
+ String categoryUniqueId = "categoryUniqueId";
+ String subCategoryUniqueId = "subCategoryUniqueId";
+ Map<String,String> parametersMap = new HashMap<>();
+ parametersMap.put(COMPONENT_TYPE, componentType);
+ parametersMap.put(CATEGORY_UNIQUE_ID, categoryUniqueId);
+ parametersMap.put(SUB_CATEGORY_UNIQUE_ID, subCategoryUniqueId);
+
+ String formatEndpoint = "/v1/category/{componentType}/{categoryUniqueId}/subCategory/{subCategoryUniqueId}";
+ String path = StrSubstitutor.replace(formatEndpoint, parametersMap, "{","}");
+
+ when(elementBusinessLogic.deleteSubCategory(eq(subCategoryUniqueId), eq(componentType), eq(designerUser.getUserId())))
+ .thenThrow(new RuntimeException("Test exception: deleteComponentSubCategory"));
+
+ Response response = target()
+ .path(path)
+ .request()
+ .accept(MediaType.APPLICATION_JSON)
+ .header(Constants.USER_ID_HEADER, designerUser.getUserId())
+ .delete();
+
+ assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_INTERNAL_SERVER_ERROR);
+ }
+
+ @Test
+ public void deleteComponentSubCategoryTest() {
+ String componentType = ComponentTypeEnum.SERVICE_PARAM_NAME;
+ String categoryUniqueId = "categoryUniqueId";
+ String subCategoryUniqueId = "subCategoryUniqueId";
+ Map<String,String> parametersMap = new HashMap<>();
+ parametersMap.put(COMPONENT_TYPE, componentType);
+ parametersMap.put(CATEGORY_UNIQUE_ID, categoryUniqueId);
+ parametersMap.put(SUB_CATEGORY_UNIQUE_ID, subCategoryUniqueId);
+
+ String formatEndpoint = "/v1/category/{componentType}/{categoryUniqueId}/subCategory/{subCategoryUniqueId}";
+ String path = StrSubstitutor.replace(formatEndpoint, parametersMap, "{","}");
+
+ Either<SubCategoryDefinition, ResponseFormat> deleteComponentSubCategoryEither = Either.left(new SubCategoryDefinition());
+
+ when(elementBusinessLogic.deleteSubCategory(eq(subCategoryUniqueId), eq(componentType), eq(designerUser.getUserId())))
+ .thenReturn(deleteComponentSubCategoryEither);
+
+ Response response = target()
+ .path(path)
+ .request()
+ .accept(MediaType.APPLICATION_JSON)
+ .header(Constants.USER_ID_HEADER, designerUser.getUserId())
+ .delete();
+
+ assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_NO_CONTENT);
+ }
+
+ @Test
+ public void createComponentGroupingCreationFailedTest() {
+ String componentType = ComponentTypeEnum.SERVICE_PARAM_NAME;
+ String categoryId = "categoryUniqueId";
+ String subCategoryId = "subCategoryId";
+ Map<String,String> parametersMap = new HashMap<>();
+ parametersMap.put(COMPONENT_TYPE, componentType);
+ parametersMap.put(CATEGORY_ID, categoryId);
+ parametersMap.put(SUB_CATEGORY_ID, subCategoryId);
+
+ String formatEndpoint = "/v1/category/{componentType}/{categoryId}/subCategory/{subCategoryId}/grouping";
+ String path = StrSubstitutor.replace(formatEndpoint, parametersMap, "{","}");
+
+ Either<GroupingDefinition, ResponseFormat> createComponentGroupingEither = Either.right(conflictResponseFormat);
+
+ when(elementBusinessLogic.createGrouping(any(), eq(componentType), eq(categoryId), eq(subCategoryId), eq(designerUser.getUserId())))
+ .thenReturn(createComponentGroupingEither);
+
+ Response response = target()
+ .path(path)
+ .request()
+ .accept(MediaType.APPLICATION_JSON)
+ .header(Constants.USER_ID_HEADER, designerUser.getUserId())
+ .post(Entity.json(EMPTY_JSON));
+
+ assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_CONFLICT);
+ }
+
+ @Test
+ public void createComponentGroupingExceptionDuringCreationTest() {
+ String componentType = ComponentTypeEnum.SERVICE_PARAM_NAME;
+ String categoryId = "categoryUniqueId";
+ String subCategoryId = "subCategoryId";
+ Map<String,String> parametersMap = new HashMap<>();
+ parametersMap.put(COMPONENT_TYPE, componentType);
+ parametersMap.put(CATEGORY_ID, categoryId);
+ parametersMap.put(SUB_CATEGORY_ID, subCategoryId);
+
+ String formatEndpoint = "/v1/category/{componentType}/{categoryId}/subCategory/{subCategoryId}/grouping";
+ String path = StrSubstitutor.replace(formatEndpoint, parametersMap, "{","}");
+
+
+ when(elementBusinessLogic.createGrouping(any(), eq(componentType), eq(categoryId), eq(subCategoryId), eq(designerUser.getUserId())))
+ .thenThrow(new RuntimeException("Test exception: createComponentGrouping"));
+
+ Response response = target()
+ .path(path)
+ .request()
+ .accept(MediaType.APPLICATION_JSON)
+ .header(Constants.USER_ID_HEADER, designerUser.getUserId())
+ .post(Entity.json(EMPTY_JSON));
+
+ assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_INTERNAL_SERVER_ERROR);
+ }
+
+ @Test
+ public void createComponentGroupingTest() {
+ String componentType = ComponentTypeEnum.SERVICE_PARAM_NAME;
+ String categoryId = "categoryUniqueId";
+ String subCategoryId = "subCategoryId";
+ Map<String,String> parametersMap = new HashMap<>();
+ parametersMap.put(COMPONENT_TYPE, componentType);
+ parametersMap.put(CATEGORY_ID, categoryId);
+ parametersMap.put(SUB_CATEGORY_ID, subCategoryId);
+
+ String formatEndpoint = "/v1/category/{componentType}/{categoryId}/subCategory/{subCategoryId}/grouping";
+ String path = StrSubstitutor.replace(formatEndpoint, parametersMap, "{","}");
+
+ Either<GroupingDefinition, ResponseFormat> createComponentGroupingEither = Either.left(new GroupingDefinition());
+
+ when(elementBusinessLogic.createGrouping(any(), eq(componentType), eq(categoryId), eq(subCategoryId), eq(designerUser.getUserId())))
+ .thenReturn(createComponentGroupingEither);
+
+ Response response = target()
+ .path(path)
+ .request()
+ .accept(MediaType.APPLICATION_JSON)
+ .header(Constants.USER_ID_HEADER, designerUser.getUserId())
+ .post(Entity.json(EMPTY_JSON));
+
+ assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_CREATED);
+ }
+
+ @Test
+ public void deleteComponentGroupingCreationFailedTest() {
+ String componentType = ComponentTypeEnum.SERVICE_PARAM_NAME;
+ String categoryUniqueId = "categoryUniqueId";
+ String subCategoryUniqueId = "subCategoryUniqueId";
+ String groupingUniqueId = "groupingUniqueId";
+ Map<String,String> parametersMap = new HashMap<>();
+ parametersMap.put(COMPONENT_TYPE, componentType);
+ parametersMap.put(CATEGORY_UNIQUE_ID, categoryUniqueId);
+ parametersMap.put(SUB_CATEGORY_UNIQUE_ID, subCategoryUniqueId);
+ parametersMap.put(GROUPING_UNIQUE_ID, groupingUniqueId);
+
+ String formatEndpoint = "/v1/category/{componentType}/{categoryUniqueId}/subCategory/{subCategoryUniqueId}/grouping/{groupingUniqueId}";
+ String path = StrSubstitutor.replace(formatEndpoint, parametersMap, "{","}");
+
+ Either<GroupingDefinition, ResponseFormat> deleteComponentGroupingEither = Either.right(conflictResponseFormat);
+
+ when(elementBusinessLogic.deleteGrouping(eq(groupingUniqueId), eq(componentType), eq(designerUser.getUserId())))
+ .thenReturn(deleteComponentGroupingEither);
+
+ Response response = target()
+ .path(path)
+ .request()
+ .accept(MediaType.APPLICATION_JSON)
+ .header(Constants.USER_ID_HEADER, designerUser.getUserId())
+ .delete();
+
+ assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_CONFLICT);
+ }
+
+ @Test
+ public void deleteComponentGroupingExceptionDuringCreationTest() {
+ String componentType = ComponentTypeEnum.SERVICE_PARAM_NAME;
+ String categoryUniqueId = "categoryUniqueId";
+ String subCategoryUniqueId = "subCategoryUniqueId";
+ String groupingUniqueId = "groupingUniqueId";
+ Map<String,String> parametersMap = new HashMap<>();
+ parametersMap.put(COMPONENT_TYPE, componentType);
+ parametersMap.put(CATEGORY_UNIQUE_ID, categoryUniqueId);
+ parametersMap.put(SUB_CATEGORY_UNIQUE_ID, subCategoryUniqueId);
+ parametersMap.put(GROUPING_UNIQUE_ID, groupingUniqueId);
+
+ String formatEndpoint = "/v1/category/{componentType}/{categoryUniqueId}/subCategory/{subCategoryUniqueId}/grouping/{groupingUniqueId}";
+ String path = StrSubstitutor.replace(formatEndpoint, parametersMap, "{","}");
+
+ when(elementBusinessLogic.deleteGrouping(eq(groupingUniqueId), eq(componentType), eq(designerUser.getUserId())))
+ .thenThrow(new RuntimeException("Test exception: deleteComponentGrouping"));
+
+ Response response = target()
+ .path(path)
+ .request()
+ .accept(MediaType.APPLICATION_JSON)
+ .header(Constants.USER_ID_HEADER, designerUser.getUserId())
+ .delete();
+
+ assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_INTERNAL_SERVER_ERROR);
+ }
+
+ @Test
+ public void deleteComponentGroupingTest() {
+ String componentType = ComponentTypeEnum.SERVICE_PARAM_NAME;
+ String categoryUniqueId = "categoryUniqueId";
+ String subCategoryUniqueId = "subCategoryUniqueId";
+ String groupingUniqueId = "groupingUniqueId";
+ Map<String,String> parametersMap = new HashMap<>();
+ parametersMap.put(COMPONENT_TYPE, componentType);
+ parametersMap.put(CATEGORY_UNIQUE_ID, categoryUniqueId);
+ parametersMap.put(SUB_CATEGORY_UNIQUE_ID, subCategoryUniqueId);
+ parametersMap.put(GROUPING_UNIQUE_ID, groupingUniqueId);
+
+ String formatEndpoint = "/v1/category/{componentType}/{categoryUniqueId}/subCategory/{subCategoryUniqueId}/grouping/{groupingUniqueId}";
+ String path = StrSubstitutor.replace(formatEndpoint, parametersMap, "{","}");
+
+ Either<GroupingDefinition, ResponseFormat> deleteComponentGroupingEither = Either.left(new GroupingDefinition());
+
+ when(elementBusinessLogic.deleteGrouping(eq(groupingUniqueId), eq(componentType), eq(designerUser.getUserId())))
+ .thenReturn(deleteComponentGroupingEither);
+
+ Response response = target()
+ .path(path)
+ .request()
+ .accept(MediaType.APPLICATION_JSON)
+ .header(Constants.USER_ID_HEADER, designerUser.getUserId())
+ .delete();
+
+ assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_NO_CONTENT);
+ }
+
+ @Test
+ public void tagsNoTagsFoundTest() {
+ String path = "/v1/tags";
+ Either<List<Tag>, ActionStatus> tagsEither = Either.right(ActionStatus.NO_CONTENT);
+
+ when(elementBusinessLogic.getAllTags(designerUser.getUserId()))
+ .thenReturn(tagsEither);
+
+ Response response = target()
+ .path(path)
+ .request()
+ .accept(MediaType.APPLICATION_JSON)
+ .header(Constants.USER_ID_HEADER, designerUser.getUserId())
+ .get();
+
+ assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_NO_CONTENT);
+ }
+
+ @Test
+ public void tagsExceptionDuringProcessingTest() {
+ String path = "/v1/tags";
+ when(elementBusinessLogic.getAllTags(designerUser.getUserId()))
+ .thenThrow(new RuntimeException("Test exception: tags"));
+
+ Response response = target()
+ .path(path)
+ .request()
+ .accept(MediaType.APPLICATION_JSON)
+ .header(Constants.USER_ID_HEADER, designerUser.getUserId())
+ .get();
+
+ assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_INTERNAL_SERVER_ERROR);
+ }
+
+ @Test
+ public void tagsTest() {
+ String path = "/v1/tags";
+ Either<List<Tag>, ActionStatus> tagsEither = Either.left(new ArrayList<>());
+ when(elementBusinessLogic.getAllTags(designerUser.getUserId()))
+ .thenReturn(tagsEither);
+
+ Response response = target()
+ .path(path)
+ .request()
+ .accept(MediaType.APPLICATION_JSON)
+ .header(Constants.USER_ID_HEADER, designerUser.getUserId())
+ .get();
+
+ assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_OK);
+ }
+
+ @Test
+ public void propertyScopesNoPropertyScopesFoundTest() {
+ String path = "/v1/propertyScopes";
+ Either<List<PropertyScope>, ActionStatus> propertyScopesEither = Either.right(ActionStatus.NO_CONTENT);
+
+ when(elementBusinessLogic.getAllPropertyScopes(designerUser.getUserId()))
+ .thenReturn(propertyScopesEither);
+
+ Response response = target()
+ .path(path)
+ .request()
+ .accept(MediaType.APPLICATION_JSON)
+ .header(Constants.USER_ID_HEADER, designerUser.getUserId())
+ .get();
+
+ assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_NO_CONTENT);
+ }
+
+ @Test
+ public void propertyScopesExceptionDuringProcessingTest() {
+ String path = "/v1/propertyScopes";
+ when(elementBusinessLogic.getAllPropertyScopes(designerUser.getUserId()))
+ .thenThrow(new RuntimeException("Test exception: propertyScopes"));
+
+ Response response = target()
+ .path(path)
+ .request()
+ .accept(MediaType.APPLICATION_JSON)
+ .header(Constants.USER_ID_HEADER, designerUser.getUserId())
+ .get();
+
+ assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_INTERNAL_SERVER_ERROR);
+ }
+
+ @Test
+ public void propertyScopesTest() {
+ String path = "/v1/propertyScopes";
+ Either<List<PropertyScope>, ActionStatus> propertyScopesEither = Either.left(new ArrayList<>());
+ when(elementBusinessLogic.getAllPropertyScopes(designerUser.getUserId()))
+ .thenReturn(propertyScopesEither);
+
+ Response response = target()
+ .path(path)
+ .request()
+ .accept(MediaType.APPLICATION_JSON)
+ .header(Constants.USER_ID_HEADER, designerUser.getUserId())
+ .get();
+
+ assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_OK);
+ }
+
+ @Test
+ public void artifactTypesNoartifactTypesFoundTest() {
+ String path = "/v1/artifactTypes";
+ Either<List<ArtifactType>, ActionStatus> artifactTypesEither = Either.right(ActionStatus.NO_CONTENT);
+
+ when(elementBusinessLogic.getAllArtifactTypes(designerUser.getUserId()))
+ .thenReturn(artifactTypesEither);
+
+ Response response = target()
+ .path(path)
+ .request()
+ .accept(MediaType.APPLICATION_JSON)
+ .header(Constants.USER_ID_HEADER, designerUser.getUserId())
+ .get();
+
+ assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_NO_CONTENT);
+ }
+
+ @Test
+ public void artifactTypesExceptionDuringProcessingTest() {
+ String path = "/v1/artifactTypes";
+ when(elementBusinessLogic.getAllArtifactTypes(designerUser.getUserId()))
+ .thenThrow(new RuntimeException("Test exception: artifactTypes"));
+
+ Response response = target()
+ .path(path)
+ .request()
+ .accept(MediaType.APPLICATION_JSON)
+ .header(Constants.USER_ID_HEADER, designerUser.getUserId())
+ .get();
+
+ assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_INTERNAL_SERVER_ERROR);
+ }
+
+ @Test
+ public void artifactTypesTest() {
+ String path = "/v1/artifactTypes";
+ Either<List<ArtifactType>, ActionStatus> artifactTypesEither = Either.left(new ArrayList<>());
+ when(elementBusinessLogic.getAllArtifactTypes(designerUser.getUserId()))
+ .thenReturn(artifactTypesEither);
+
+ Response response = target()
+ .path(path)
+ .request()
+ .accept(MediaType.APPLICATION_JSON)
+ .header(Constants.USER_ID_HEADER, designerUser.getUserId())
+ .get();
+
+ assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_OK);
+ }
+
+ @Test
+ public void configurationNoConfigurationFoundTest() {
+ String path = "/v1/configuration/ui";
+
+ Either<List<ArtifactType>, ActionStatus> otherEither = Either.left(new ArrayList<>());
+ Either<Integer, ActionStatus> defaultHeatTimeoutEither = Either.left(1);
+ Either<Map<String, Object>, ActionStatus> deploymentEither = Either.left(new HashMap<>());
+ Either<Map<String, String>, ActionStatus> resourceTypesMapEither = Either.left(new HashMap<>());
+
+ when(elementBusinessLogic.getAllArtifactTypes(designerUser.getUserId()))
+ .thenReturn(otherEither);
+ when(elementBusinessLogic.getDefaultHeatTimeout())
+ .thenReturn(defaultHeatTimeoutEither);
+ when(elementBusinessLogic.getAllDeploymentArtifactTypes())
+ .thenReturn(deploymentEither);
+ when(elementBusinessLogic.getResourceTypesMap())
+ .thenReturn(resourceTypesMapEither);
+
+ Response response = target()
+ .path(path)
+ .request()
+ .accept(MediaType.APPLICATION_JSON)
+ .header(Constants.USER_ID_HEADER, designerUser.getUserId())
+ .get();
+
+ assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_OK);
+ }
+
+ @Test
+ public void configurationExceptionDuringProcessingTest() {
+ String path = "/v1/configuration/ui";
+ when(elementBusinessLogic.getAllArtifactTypes(designerUser.getUserId()))
+ .thenThrow(new RuntimeException("Test exception: artifactTypes"));
+
+ Response response = target()
+ .path(path)
+ .request()
+ .accept(MediaType.APPLICATION_JSON)
+ .header(Constants.USER_ID_HEADER, designerUser.getUserId())
+ .get();
+
+ assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_INTERNAL_SERVER_ERROR);
+ }
+
+ @Test
+ public void screenNoCatalogComponentsFoundTest() {
+ String path = "/v1/screen";
+
+ Either<Map<String, List<CatalogComponent>>, ResponseFormat> screenEither = Either.right(badRequestResponseFormat);
+ when(elementBusinessLogic.getCatalogComponents(eq(designerUser.getUserId()), any()))
+ .thenReturn(screenEither);
+
+ Response response = target()
+ .path(path)
+ .request()
+ .accept(MediaType.APPLICATION_JSON)
+ .header(Constants.USER_ID_HEADER, designerUser.getUserId())
+ .get();
+
+ assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_BAD_REQUEST);
+ }
+
+ @Test
+ public void screenExceptionDuringProcessingTest() {
+ String path = "/v1/screen";
+
+ when(elementBusinessLogic.getCatalogComponents(eq(designerUser.getUserId()), any()))
+ .thenThrow(new RuntimeException("Test exception: screen"));
+
+ Response response = target()
+ .path(path)
+ .request()
+ .accept(MediaType.APPLICATION_JSON)
+ .header(Constants.USER_ID_HEADER, designerUser.getUserId())
+ .get();
+
+ assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_INTERNAL_SERVER_ERROR);
+ }
+
+ @Test
+ public void screenTest() {
+ String path = "/v1/screen";
+
+ Either<Map<String, List<CatalogComponent>>, ResponseFormat> screenEither = Either.left(new HashMap<>());
+ when(elementBusinessLogic.getCatalogComponents(eq(designerUser.getUserId()), any()))
+ .thenReturn(screenEither);
+
+ Response response = target()
+ .path(path)
+ .request()
+ .accept(MediaType.APPLICATION_JSON)
+ .header(Constants.USER_ID_HEADER, designerUser.getUserId())
+ .get();
+
+ assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_OK);
+ }
+
+ @Override
+ protected Application configure() {
+ ApplicationContext context = new AnnotationConfigApplicationContext(SpringConfig.class);
+ return new ResourceConfig(ElementServlet.class)
+ .register(new AbstractBinder() {