diff options
author | vasraz <vasyl.razinkov@est.tech> | 2021-09-14 16:40:39 +0100 |
---|---|---|
committer | Michael Morris <michael.morris@est.tech> | 2021-10-05 08:23:33 +0000 |
commit | aae70f4bfb7126a6fc562604bf48fcd01d6d7af8 (patch) | |
tree | ec5e6dcbff4978c61f391586d7ff424db2a25e73 /catalog-be/src/test | |
parent | 71ecc57f5ccef81ee64762783d47bf47781c87f8 (diff) |
Allow multiple base types for a service
Change-Id: I2e37818a432295a6e9f795f38d730d60f66eef78
Signed-off-by: Vasyl Razinkov <vasyl.razinkov@est.tech>
Issue-ID: SDC-3727
Diffstat (limited to 'catalog-be/src/test')
-rw-r--r-- | catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ElementBusinessLogicTest.java | 321 | ||||
-rw-r--r-- | catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ElementServletTest.java | 48 |
2 files changed, 178 insertions, 191 deletions
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ElementBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ElementBusinessLogicTest.java index 3fdc42fc21..8eb840a664 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ElementBusinessLogicTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ElementBusinessLogicTest.java @@ -21,7 +21,20 @@ */ package org.openecomp.sdc.be.components.impl; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyBoolean; +import static org.mockito.ArgumentMatchers.anySet; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.doThrow; +import static org.mockito.Mockito.when; + import fj.data.Either; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -53,214 +66,201 @@ import org.openecomp.sdc.be.user.Role; import org.openecomp.sdc.be.user.UserBusinessLogic; import org.openecomp.sdc.exception.ResponseFormat; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyBoolean; -import static org.mockito.ArgumentMatchers.anySet; -import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.doThrow; -import static org.mockito.Mockito.when; - @RunWith(MockitoJUnitRunner.class) public class ElementBusinessLogicTest extends BaseBusinessLogicMock { - private User user; + private User user; - @Mock - private ComponentsUtils componentsUtils; + @Mock + private ComponentsUtils componentsUtils; - @Mock - private UserBusinessLogic userAdminManager; + @Mock + private UserBusinessLogic userAdminManager; - @Mock - private JanusGraphDao janusGraphDao; + @Mock + private JanusGraphDao janusGraphDao; - @Mock - private UserValidations userValidations; + @Mock + private UserValidations userValidations; - @Mock - private ToscaOperationFacade toscaOperationFacade; + @Mock + private ToscaOperationFacade toscaOperationFacade; - @InjectMocks - ElementBusinessLogic elementBusinessLogic; + @InjectMocks + private ElementBusinessLogic elementBusinessLogic; @Before - public void setUp() { - MockitoAnnotations.initMocks(this); - elementBusinessLogic = new ElementBusinessLogic(elementDao, groupOperation, groupInstanceOperation, groupTypeOperation, - groupBusinessLogic, interfaceOperation, interfaceLifecycleTypeOperation, artifactToscaOperation, elementDao, userAdminManager); - elementBusinessLogic.setComponentsUtils(componentsUtils); - elementBusinessLogic.setJanusGraphDao(janusGraphDao); - elementBusinessLogic.setToscaOperationFacade(toscaOperationFacade); - elementBusinessLogic.setUserValidations(userValidations); - user = new User(); - user.setUserId("admin"); - } + public void setUp() { + MockitoAnnotations.initMocks(this); + elementBusinessLogic = new ElementBusinessLogic(elementDao, groupOperation, groupInstanceOperation, groupTypeOperation, + groupBusinessLogic, interfaceOperation, interfaceLifecycleTypeOperation, artifactToscaOperation, elementDao, userAdminManager); + elementBusinessLogic.setComponentsUtils(componentsUtils); + elementBusinessLogic.setJanusGraphDao(janusGraphDao); + elementBusinessLogic.setToscaOperationFacade(toscaOperationFacade); + elementBusinessLogic.setUserValidations(userValidations); + user = new User(); + user.setUserId("admin"); + } @Test - public void testGetFollowed_givenUserWithDesignerRole_thenReturnsSuccessful() { - user.setUserId("designer1"); - user.setRole(Role.DESIGNER.name()); + public void testGetFollowed_givenUserWithDesignerRole_thenReturnsSuccessful() { + user.setUserId("designer1"); + user.setRole(Role.DESIGNER.name()); - Set<Component> resources = new HashSet<>(); - Set<Component> services = new HashSet<>(); + Set<Component> resources = new HashSet<>(); + Set<Component> services = new HashSet<>(); - Resource resource = new Resource(); - Service service = new Service(); + Resource resource = new Resource(); + Service service = new Service(); - resources.add(resource); - services.add(service); + resources.add(resource); + services.add(service); - Mockito.when(toscaOperationFacade.getFollowed(eq(user.getUserId()), Mockito.anySet(), Mockito.anySet(), Mockito.eq(ComponentTypeEnum.RESOURCE))) - .thenReturn(Either.left(resources)); - Mockito.when(toscaOperationFacade.getFollowed(eq(user.getUserId()), anySet(), anySet(), eq(ComponentTypeEnum.SERVICE))) - .thenReturn(Either.left(services)); + Mockito.when( + toscaOperationFacade.getFollowed(eq(user.getUserId()), Mockito.anySet(), Mockito.anySet(), Mockito.eq(ComponentTypeEnum.RESOURCE))) + .thenReturn(Either.left(resources)); + Mockito.when(toscaOperationFacade.getFollowed(eq(user.getUserId()), anySet(), anySet(), eq(ComponentTypeEnum.SERVICE))) + .thenReturn(Either.left(services)); - Map<String, List<? extends Component>> result = elementBusinessLogic.getFollowed(user).left().value(); - Assert.assertTrue(result.get("services").size() == 1); - Assert.assertTrue(result.get("resources").size() == 1); - } + Map<String, List<? extends Component>> result = elementBusinessLogic.getFollowed(user).left().value(); + Assert.assertTrue(result.get("services").size() == 1); + Assert.assertTrue(result.get("resources").size() == 1); + } - @Test - public void testGetFollowed_givenUserWithProductStrategistRole_thenReturnsEmptyList(){ - user.setUserId("pstra1"); - user.setRole(Role.PRODUCT_STRATEGIST.name()); + @Test + public void testGetFollowed_givenUserWithProductStrategistRole_thenReturnsEmptyList() { + user.setUserId("pstra1"); + user.setRole(Role.PRODUCT_STRATEGIST.name()); - Map<String, List<? extends Component>> result = elementBusinessLogic.getFollowed(user).left().value(); - Assert.assertEquals("products list should be empty", 0, result.get("products").size()); + Map<String, List<? extends Component>> result = elementBusinessLogic.getFollowed(user).left().value(); + Assert.assertEquals("products list should be empty", 0, result.get("products").size()); - } + } - @Test - public void testGetFollowed_givenUserWithProductManagerRole_thenReturnsProducts(){ - user.setUserId("pmanager1"); - user.setRole(Role.PRODUCT_MANAGER.name()); + @Test + public void testGetFollowed_givenUserWithProductManagerRole_thenReturnsProducts() { + user.setUserId("pmanager1"); + user.setRole(Role.PRODUCT_MANAGER.name()); - Set<Component> products = new HashSet<>(); - products.add(new Product()); + Set<Component> products = new HashSet<>(); + products.add(new Product()); - when(toscaOperationFacade.getFollowed(any(), anySet(), any(), eq(ComponentTypeEnum.PRODUCT))) - .thenReturn(Either.left(products)); + when(toscaOperationFacade.getFollowed(any(), anySet(), any(), eq(ComponentTypeEnum.PRODUCT))) + .thenReturn(Either.left(products)); - Map<String, List<? extends Component>> result = elementBusinessLogic.getFollowed(user).left().value(); - Assert.assertEquals("1 product should exist", 1, result.get("products").size()); + Map<String, List<? extends Component>> result = elementBusinessLogic.getFollowed(user).left().value(); + Assert.assertEquals("1 product should exist", 1, result.get("products").size()); - } + } - @Test - public void testGetFollowed_givenUserWithRoleAdminErrorOccursGettingResources_thenReturnsError() { - user.setUserId("admin1"); - user.setRole(Role.ADMIN.name()); + @Test + public void testGetFollowed_givenUserWithRoleAdminErrorOccursGettingResources_thenReturnsError() { + user.setUserId("admin1"); + user.setRole(Role.ADMIN.name()); - when(toscaOperationFacade.getFollowed(any(), anySet(), any(), eq(ComponentTypeEnum.RESOURCE))) - .thenReturn(Either.right(StorageOperationStatus.NOT_FOUND)); + when(toscaOperationFacade.getFollowed(any(), anySet(), any(), eq(ComponentTypeEnum.RESOURCE))) + .thenReturn(Either.right(StorageOperationStatus.NOT_FOUND)); - Assert.assertTrue(elementBusinessLogic.getFollowed(user).isRight()); - } + Assert.assertTrue(elementBusinessLogic.getFollowed(user).isRight()); + } - @Test - public void testGetAllCategories_givenUserIsNull_thenReturnsError() { - Assert.assertTrue(elementBusinessLogic.getAllCategories(null, null).isRight()); - } + @Test + public void testGetAllCategories_givenUserIsNull_thenReturnsError() { + Assert.assertTrue(elementBusinessLogic.getAllCategories(null, null).isRight()); + } - @Test(expected = ComponentException.class) - public void testGetAllCategories_givenValidationOfUserFails_thenReturnsError() { - doThrow(new ByResponseFormatComponentException(new ResponseFormat())).when(userValidations).validateUserExists(eq(user.getUserId())); - elementBusinessLogic.getAllCategories(null, user.getUserId()); - } + @Test(expected = ComponentException.class) + public void testGetAllCategories_givenValidationOfUserFails_thenReturnsError() { + doThrow(new ByResponseFormatComponentException(new ResponseFormat())).when(userValidations).validateUserExists(eq(user.getUserId())); + elementBusinessLogic.getAllCategories(null, user.getUserId()); + } - @Test - public void testGetAllCategories_givenInvalidComponentType_thenReturnsError() { - when(userValidations.validateUserExists(eq(user.getUserId()))).thenReturn(user); + @Test + public void testGetAllCategories_givenInvalidComponentType_thenReturnsError() { + when(userValidations.validateUserExists(eq(user.getUserId()))).thenReturn(user); - Assert.assertTrue(elementBusinessLogic.getAllCategories("NONE", user.getUserId()).isRight()); + Assert.assertTrue(elementBusinessLogic.getAllCategories("NONE", user.getUserId()).isRight()); - } + } - @Test - public void testGetAllCategories_givenValidUserAndComponentType_thenReturnsSuccessful() { + @Test + public void testGetAllCategories_givenValidUserAndComponentType_thenReturnsSuccessful() { - List<CategoryDefinition> categoryDefinitionList = new ArrayList<>(); - categoryDefinitionList.add(new CategoryDefinition()); + List<CategoryDefinition> categoryDefinitionList = new ArrayList<>(); + categoryDefinitionList.add(new CategoryDefinition()); - when(userValidations.validateUserExists(eq(user.getUserId()))).thenReturn(user); - when(elementDao.getAllCategories(NodeTypeEnum.ResourceNewCategory, false)) - .thenReturn(Either.left(categoryDefinitionList)); - Assert.assertTrue(elementBusinessLogic.getAllCategories(ComponentTypeEnum.RESOURCE_PARAM_NAME, user.getUserId()) - .isLeft()); - } + when(userValidations.validateUserExists(eq(user.getUserId()))).thenReturn(user); + when(elementDao.getAllCategories(NodeTypeEnum.ResourceNewCategory, false)) + .thenReturn(Either.left(categoryDefinitionList)); + Assert.assertTrue(elementBusinessLogic.getAllCategories(ComponentTypeEnum.RESOURCE_PARAM_NAME, user.getUserId()) + .isLeft()); + } - @Test - public void testGetAllCategories_givenValidUserId_thenReturnsSuccessful() { + @Test + public void testGetAllCategories_givenValidUserId_thenReturnsSuccessful() { - List<CategoryDefinition> dummyCategoryDefinitionList = new ArrayList<>(); - dummyCategoryDefinitionList.add(new CategoryDefinition()); + List<CategoryDefinition> dummyCategoryDefinitionList = new ArrayList<>(); + dummyCategoryDefinitionList.add(new CategoryDefinition()); - when(userValidations.validateUserExists(eq(user.getUserId()))) - .thenReturn(user); - when(elementDao.getAllCategories(any(NodeTypeEnum.class), anyBoolean())) - .thenReturn(Either.left(dummyCategoryDefinitionList)); + when(userValidations.validateUserExists(eq(user.getUserId()))) + .thenReturn(user); + when(elementDao.getAllCategories(any(NodeTypeEnum.class), anyBoolean())) + .thenReturn(Either.left(dummyCategoryDefinitionList)); - Assert.assertTrue(elementBusinessLogic.getAllCategories(user.getUserId()).isLeft()); - } + Assert.assertTrue(elementBusinessLogic.getAllCategories(user.getUserId()).isLeft()); + } - @Test - public void testDeleteCategory_givenValidComponentTypeAndCategoryId_thenReturnsSuccessful() { + @Test + public void testDeleteCategory_givenValidComponentTypeAndCategoryId_thenReturnsSuccessful() { - when(elementDao.deleteCategory(any(NodeTypeEnum.class), anyString())) - .thenReturn(Either.left(new CategoryDefinition())); + when(elementDao.deleteCategory(any(NodeTypeEnum.class), anyString())) + .thenReturn(Either.left(new CategoryDefinition())); - Assert.assertTrue(elementBusinessLogic.deleteCategory("cat1", "resources", user.getUserId()).isLeft()); - } + Assert.assertTrue(elementBusinessLogic.deleteCategory("cat1", "resources", user.getUserId()).isLeft()); + } - @Test - public void testCreateSubCategory_givenValidSubCategory_thenReturnsSuccessful() { - user.setRole(Role.ADMIN.name()); - SubCategoryDefinition subCatDef = new SubCategoryDefinition(); - subCatDef.setName("subCat1"); + @Test + public void testCreateSubCategory_givenValidSubCategory_thenReturnsSuccessful() { + user.setRole(Role.ADMIN.name()); + SubCategoryDefinition subCatDef = new SubCategoryDefinition(); + subCatDef.setName("subCat1"); + + when(userValidations.validateUserExists(eq(user.getUserId()))) + .thenReturn(user); + when(elementDao.getCategory(any(NodeTypeEnum.class), anyString())) + .thenReturn(Either.left(new CategoryDefinition())); + when(elementDao.isSubCategoryUniqueForCategory(any(NodeTypeEnum.class), anyString(), anyString())) + .thenReturn(Either.left(Boolean.TRUE)); + when(elementDao.getSubCategoryUniqueForType(any(NodeTypeEnum.class), anyString())) + .thenReturn(Either.left(subCatDef)); + when(elementDao.createSubCategory(anyString(), any(SubCategoryDefinition.class), any(NodeTypeEnum.class))) + .thenReturn(Either.left(subCatDef)); + + Assert.assertTrue(elementBusinessLogic.createSubCategory(subCatDef, "resources", + "cat1", user.getUserId()).isLeft()); + } - when(userValidations.validateUserExists(eq(user.getUserId()))) - .thenReturn(user); - when(elementDao.getCategory(any(NodeTypeEnum.class), anyString())) - .thenReturn(Either.left(new CategoryDefinition())); - when(elementDao.isSubCategoryUniqueForCategory(any(NodeTypeEnum.class), anyString(), anyString())) - .thenReturn(Either.left(Boolean.TRUE)); - when(elementDao.getSubCategoryUniqueForType(any(NodeTypeEnum.class), anyString())) - .thenReturn(Either.left(subCatDef)); - when(elementDao.createSubCategory(anyString(), any(SubCategoryDefinition.class), any(NodeTypeEnum.class))) - .thenReturn(Either.left(subCatDef)); + @Test + public void testCreateSubCategory_givenNullSubCategory_thenReturnsError() { + Assert.assertTrue(elementBusinessLogic.createSubCategory(null, "resources", + "cat1", user.getUserId()).isRight()); + } - Assert.assertTrue(elementBusinessLogic.createSubCategory(subCatDef, "resources", - "cat1", user.getUserId()).isLeft()); - } + @Test(expected = ComponentException.class) + public void testCreateSubCategory_givenUserValidationFails_thenReturnsException() { + SubCategoryDefinition subCategoryDefinition = new SubCategoryDefinition(); + doThrow(new ByResponseFormatComponentException(new ResponseFormat())).when(userValidations).validateUserExists(eq(user.getUserId())); + elementBusinessLogic.createSubCategory(subCategoryDefinition, "resources", "cat1", user.getUserId()); + } - @Test - public void testCreateSubCategory_givenNullSubCategory_thenReturnsError() { - Assert.assertTrue(elementBusinessLogic.createSubCategory(null, "resources", - "cat1", user.getUserId()).isRight()); - } - - @Test(expected = ComponentException.class) - public void testCreateSubCategory_givenUserValidationFails_thenReturnsException() { - SubCategoryDefinition subCategoryDefinition = new SubCategoryDefinition(); - doThrow(new ByResponseFormatComponentException(new ResponseFormat())).when(userValidations).validateUserExists(eq(user.getUserId())); - elementBusinessLogic.createSubCategory(subCategoryDefinition, "resources", "cat1", user.getUserId()); - } - - @Test(expected=ComponentException.class) + @Test(expected = ComponentException.class) public void testcreateCategory_VALIDATION_OF_USER_FAILED() { CategoryDefinition catdefinition = new CategoryDefinition(); String userid = ""; ResponseFormat responseFormat = new ResponseFormat(7); when(userValidations.validateUserExists("")).thenThrow(new ByResponseFormatComponentException(responseFormat)); - elementBusinessLogic.createCategory(catdefinition,"Service", userid); + elementBusinessLogic.createCategory(catdefinition, "Service", userid); } @Test @@ -270,7 +270,7 @@ public class ElementBusinessLogicTest extends BaseBusinessLogicMock { User user = new User(); when(userValidations.validateUserExists("USR")).thenReturn(user); when(componentsUtils.getResponseFormat(ActionStatus.INVALID_CONTENT)).thenReturn(responseFormat); - Either<CategoryDefinition, ResponseFormat> response = elementBusinessLogic.createCategory(catdefinition,"Service", "USR"); + Either<CategoryDefinition, ResponseFormat> response = elementBusinessLogic.createCategory(catdefinition, "Service", "USR"); Assert.assertTrue(response.isRight()); Assert.assertEquals((Integer) 9, response.right().value().getStatus()); } @@ -286,7 +286,7 @@ public class ElementBusinessLogicTest extends BaseBusinessLogicMock { when(userValidations.validateUserExists("USR")).thenReturn(user); when(componentsUtils.getResponseFormat(ActionStatus.INVALID_CONTENT)).thenReturn(responseFormat); - Either<CategoryDefinition, ResponseFormat> response = elementBusinessLogic.createCategory(catdefinition,"Service", "USR"); + Either<CategoryDefinition, ResponseFormat> response = elementBusinessLogic.createCategory(catdefinition, "Service", "USR"); Assert.assertTrue(response.isRight()); Assert.assertEquals((Integer) 9, response.right().value().getStatus()); } @@ -301,11 +301,11 @@ public class ElementBusinessLogicTest extends BaseBusinessLogicMock { when(userValidations.validateUserExists("USR")).thenReturn(user); when(componentsUtils.getResponseFormat(ActionStatus.INVALID_CONTENT)).thenReturn(responseFormat); - Either<CategoryDefinition, ResponseFormat> response = elementBusinessLogic.createCategory(catdefinition,"SERVICE_PARAM_NAME", "USR"); + Either<CategoryDefinition, ResponseFormat> response = elementBusinessLogic.createCategory(catdefinition, "SERVICE_PARAM_NAME", "USR"); Assert.assertTrue(response.isRight()); Assert.assertEquals((Integer) 9, response.right().value().getStatus()); } - + @Test public void testGetBaseTypes_givenValidUserAndComponentType_thenReturnsSuccessful() { @@ -316,10 +316,9 @@ public class ElementBusinessLogicTest extends BaseBusinessLogicMock { when(userValidations.validateUserExistsActionStatus(eq(user.getUserId()))).thenReturn(ActionStatus.OK); when(elementDao.getBaseTypes(categoryName, modelName)).thenReturn(baseTypes); - Assert.assertTrue(elementBusinessLogic.getBaseTypes(categoryName, user.getUserId(), modelName) - .isLeft()); + Assert.assertTrue(elementBusinessLogic.getBaseTypes(categoryName, user.getUserId(), modelName).isLeft()); } - + @Test public void testGetBaseTypes_givenUserValidationFails_thenReturnsException() { when(userValidations.validateUserExistsActionStatus(eq(user.getUserId()))).thenReturn(ActionStatus.RESTRICTED_OPERATION); diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ElementServletTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ElementServletTest.java index f4ca52b0c2..c9e41bfa5f 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ElementServletTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ElementServletTest.java @@ -28,11 +28,11 @@ import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.reset; import static org.mockito.Mockito.when; +import fj.data.Either; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; - import javax.servlet.ServletContext; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; @@ -40,7 +40,6 @@ import javax.ws.rs.client.Entity; import javax.ws.rs.core.Application; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; - import org.apache.commons.text.StrSubstitutor; import org.apache.http.HttpStatus; import org.assertj.core.util.Lists; @@ -92,8 +91,6 @@ import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.web.context.WebApplicationContext; -import fj.data.Either; - class ElementServletTest extends JerseyTest { public static final HttpServletRequest request = Mockito.mock(HttpServletRequest.class); @@ -103,8 +100,7 @@ class ElementServletTest extends JerseyTest { public static final BeGenericServlet beGenericServlet = Mockito.mock(BeGenericServlet.class); public static final Resource resource = Mockito.mock(Resource.class); public static final UserBusinessLogic userBusinessLogic = Mockito.mock(UserBusinessLogic.class); - public static final ComponentInstanceBusinessLogic componentInstanceBusinessLogic = Mockito - .mock(ComponentInstanceBusinessLogic.class); + public static final ComponentInstanceBusinessLogic componentInstanceBusinessLogic = Mockito.mock(ComponentInstanceBusinessLogic.class); public static final ArtifactsBusinessLogic artifactsBusinessLogic = Mockito.mock(ArtifactsBusinessLogic.class); private static final ServletContext servletContext = Mockito.mock(ServletContext.class); @@ -113,15 +109,13 @@ class ElementServletTest extends JerseyTest { private static final ServletUtils servletUtils = Mockito.mock(ServletUtils.class); private static final UserBusinessLogic userAdmin = Mockito.mock(UserBusinessLogic.class); private static final ComponentsUtils componentUtils = Mockito.mock(ComponentsUtils.class); - private static final ComponentsCleanBusinessLogic componentsCleanBusinessLogic = Mockito - .mock(ComponentsCleanBusinessLogic.class); + private static final ComponentsCleanBusinessLogic componentsCleanBusinessLogic = Mockito.mock(ComponentsCleanBusinessLogic.class); private static final ElementBusinessLogic elementBusinessLogic = Mockito.mock(ElementBusinessLogic.class); private static final ModelBusinessLogic modelBusinessLogic = Mockito.mock(ModelBusinessLogic.class); private static final ResponseFormat okResponseFormat = new ResponseFormat(HttpStatus.SC_OK); private static final ResponseFormat conflictResponseFormat = new ResponseFormat(HttpStatus.SC_CONFLICT); - private static final ResponseFormat generalErrorResponseFormat = new ResponseFormat( - HttpStatus.SC_INTERNAL_SERVER_ERROR); + private static final ResponseFormat generalErrorResponseFormat = new ResponseFormat(HttpStatus.SC_INTERNAL_SERVER_ERROR); private static final ResponseFormat createdResponseFormat = new ResponseFormat(HttpStatus.SC_CREATED); private static final ResponseFormat noContentResponseFormat = new ResponseFormat(HttpStatus.SC_NO_CONTENT); private static final ResponseFormat unauthorizedResponseFormat = Mockito.mock(ResponseFormat.class); @@ -137,8 +131,7 @@ class ElementServletTest extends JerseyTest { /* Users */ private static User designerUser = new User("designer", "designer", "designer", "designer@email.com", - Role.DESIGNER.name(), System - .currentTimeMillis()); + Role.DESIGNER.name(), System.currentTimeMillis()); private static ConfigurationManager configurationManager; @@ -146,14 +139,12 @@ class ElementServletTest extends JerseyTest { public static void setup() { //Needed for User Authorization - when(servletContext.getAttribute(Constants.WEB_APPLICATION_CONTEXT_WRAPPER_ATTR)) - .thenReturn(webAppContextWrapper); + when(servletContext.getAttribute(Constants.WEB_APPLICATION_CONTEXT_WRAPPER_ATTR)).thenReturn(webAppContextWrapper); when(webAppContextWrapper.getWebAppContext(servletContext)).thenReturn(webApplicationContext); when(webApplicationContext.getBean(ServletUtils.class)).thenReturn(servletUtils); when(servletUtils.getUserAdmin()).thenReturn(userAdmin); when(servletUtils.getComponentsUtils()).thenReturn(componentUtils); - when(componentUtils.getResponseFormat(ActionStatus.RESTRICTED_OPERATION)) - .thenReturn(unauthorizedResponseFormat); + when(componentUtils.getResponseFormat(ActionStatus.RESTRICTED_OPERATION)).thenReturn(unauthorizedResponseFormat); when(unauthorizedResponseFormat.getStatus()).thenReturn(HttpStatus.SC_UNAUTHORIZED); when(componentUtils.getResponseFormat(ActionStatus.OK)).thenReturn(okResponseFormat); @@ -161,8 +152,7 @@ class ElementServletTest extends JerseyTest { when(componentUtils.getResponseFormat(ActionStatus.NO_CONTENT)).thenReturn(noContentResponseFormat); when(componentUtils.getResponseFormat(ActionStatus.INVALID_CONTENT)).thenReturn(badRequestResponseFormat); when(componentUtils.getResponseFormat(ActionStatus.GENERAL_ERROR)).thenReturn(generalErrorResponseFormat); - when(componentUtils.getResponseFormat(any(ComponentException.class))) - .thenReturn(generalErrorResponseFormat); + when(componentUtils.getResponseFormat(any(ComponentException.class))).thenReturn(generalErrorResponseFormat); ByResponseFormatComponentException ce = Mockito.mock(ByResponseFormatComponentException.class); when(ce.getResponseFormat()).thenReturn(unauthorizedResponseFormat); @@ -1044,7 +1034,7 @@ class ElementServletTest extends JerseyTest { Either<Map<String, List<CatalogComponent>>, ResponseFormat> screenEither = Either .right(badRequestResponseFormat); - when(elementBusinessLogic.getCatalogComponents(eq(designerUser.getUserId()), any())) + when(elementBusinessLogic.getCatalogComponents(any())) .thenReturn(screenEither); Response response = target() @@ -1061,7 +1051,7 @@ class ElementServletTest extends JerseyTest { void screenExceptionDuringProcessingTest() { String path = "/v1/screen"; - when(elementBusinessLogic.getCatalogComponents(eq(designerUser.getUserId()), any())) + when(elementBusinessLogic.getCatalogComponents(any())) .thenThrow(new RuntimeException("Test exception: screen")); Response response = target() @@ -1079,7 +1069,7 @@ class ElementServletTest extends JerseyTest { String path = "/v1/screen"; Either<Map<String, List<CatalogComponent>>, ResponseFormat> screenEither = Either.left(new HashMap<>()); - when(elementBusinessLogic.getCatalogComponents(eq(designerUser.getUserId()), any())) + when(elementBusinessLogic.getCatalogComponents(any())) .thenReturn(screenEither); Response response = target() @@ -1095,7 +1085,7 @@ class ElementServletTest extends JerseyTest { @Override protected Application configure() { ApplicationContext context = new AnnotationConfigApplicationContext(SpringConfig.class); - forceSet(TestProperties.CONTAINER_PORT, "0"); + forceSet(TestProperties.CONTAINER_PORT, "0"); return new ResourceConfig(ElementServlet.class) .register(new AbstractBinder() { @@ -1112,13 +1102,12 @@ class ElementServletTest extends JerseyTest { }) .property("contextConfig", context); } - + @Test void getBaseTypesTest() { String path = "/v1/category/services/CAT1/baseTypes"; Either<List<BaseType>, ActionStatus> baseTypesEither = Either.left(new ArrayList<>()); - when(elementBusinessLogic.getBaseTypes("CAT1", designerUser.getUserId(), null)) - .thenReturn(baseTypesEither); + when(elementBusinessLogic.getBaseTypes("CAT1", designerUser.getUserId(), null)).thenReturn(baseTypesEither); Response response = target() .path(path) @@ -1129,14 +1118,13 @@ class ElementServletTest extends JerseyTest { assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_OK); } - + @Test void getBaseTypesNoBaseTypesFoundTest() { String path = "/v1/category/services/CAT1/baseTypes"; Either<List<BaseType>, ActionStatus> baseTypesEither = Either.right(ActionStatus.NO_CONTENT); - when(elementBusinessLogic.getBaseTypes("CAT1", designerUser.getUserId(), null)) - .thenReturn(baseTypesEither); + when(elementBusinessLogic.getBaseTypes("CAT1", designerUser.getUserId(), null)).thenReturn(baseTypesEither); Response response = target() .path(path) @@ -1147,5 +1135,5 @@ class ElementServletTest extends JerseyTest { assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_NO_CONTENT); } - -}
\ No newline at end of file + +} |