aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-be
diff options
context:
space:
mode:
Diffstat (limited to 'catalog-be')
-rw-r--r--catalog-be/src/main/docker/backend/chef-repo/cookbooks/sdc-catalog-be/templates/default/BE-configuration.yaml.erb3
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ElementBusinessLogic.java16
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ElementServlet.java49
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ElementBusinessLogicTest.java321
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ElementServletTest.java48
5 files changed, 209 insertions, 228 deletions
diff --git a/catalog-be/src/main/docker/backend/chef-repo/cookbooks/sdc-catalog-be/templates/default/BE-configuration.yaml.erb b/catalog-be/src/main/docker/backend/chef-repo/cookbooks/sdc-catalog-be/templates/default/BE-configuration.yaml.erb
index 118b48d04b..69fd11da97 100644
--- a/catalog-be/src/main/docker/backend/chef-repo/cookbooks/sdc-catalog-be/templates/default/BE-configuration.yaml.erb
+++ b/catalog-be/src/main/docker/backend/chef-repo/cookbooks/sdc-catalog-be/templates/default/BE-configuration.yaml.erb
@@ -1018,7 +1018,8 @@ genericAssetNodeTypes:
ETSI NFV Network Service: tosca.nodes.nfv.NS
serviceNodeTypes:
- ETSI NFV Network Service: tosca.nodes.nfv.NS
+ ETSI NFV Network Service:
+ - tosca.nodes.nfv.NS
workloadContext: Production
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ElementBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ElementBusinessLogic.java
index 1bffb4e789..42fa95e642 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ElementBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ElementBusinessLogic.java
@@ -116,7 +116,6 @@ public class ElementBusinessLogic extends BaseBusinessLogic {
private static final String COMPONENT_TYPE_IS_INVALID = "Component type {} is invalid";
private static final String VALIDATION_OF_USER_ROLE_FAILED_USER_ID = "Validation of user role failed, userId {}";
private final IElementOperation elementOperation;
- private final UserBusinessLogic userAdminManager;
@Autowired
public ElementBusinessLogic(IElementOperation elementDao, IGroupOperation groupOperation, IGroupInstanceOperation groupInstanceOperation,
@@ -126,7 +125,6 @@ public class ElementBusinessLogic extends BaseBusinessLogic {
super(elementDao, groupOperation, groupInstanceOperation, groupTypeOperation, interfaceOperation, interfaceLifecycleTypeOperation,
artifactToscaOperation);
this.elementOperation = elementOperation;
- this.userAdminManager = userAdminManager;
}
/**
@@ -324,7 +322,7 @@ public class ElementBusinessLogic extends BaseBusinessLogic {
return Either.right(responseFormat);
}
Boolean isCategoryUnique = categoryUniqueEither.left().value();
- if (!isCategoryUnique) {
+ if (Boolean.FALSE.equals(isCategoryUnique)) {
log.debug("Category is not unique, name {}, componentType {}", categoryName, componentType);
ResponseFormat responseFormat = componentsUtils
.getResponseFormat(ActionStatus.COMPONENT_CATEGORY_ALREADY_EXISTS, componentType, categoryName);
@@ -437,7 +435,7 @@ public class ElementBusinessLogic extends BaseBusinessLogic {
return Either.right(responseFormat);
}
Boolean isSubUnique = subCategoryUniqueForCategory.left().value();
- if (!isSubUnique) {
+ if (Boolean.FALSE.equals(isSubUnique)) {
log.debug("Sub-category is not unique for category, parent name {}, subcategory norm name {}, componentType {}", parentCategoryName,
normalizedName, componentType);
ResponseFormat responseFormat = componentsUtils
@@ -618,7 +616,7 @@ public class ElementBusinessLogic extends BaseBusinessLogic {
return Either.right(responseFormat);
}
Boolean isGroupingUnique = groupingUniqueForSubCategory.left().value();
- if (!isGroupingUnique) {
+ if (Boolean.FALSE.equals(isGroupingUnique)) {
log.debug("Grouping is not unique for sub-category, parent name {}, grouping norm name {}, componentType {}", parentSubCategoryName,
normalizedName, componentType);
ResponseFormat responseFormat = componentsUtils
@@ -902,7 +900,7 @@ public class ElementBusinessLogic extends BaseBusinessLogic {
return elementOperation.getDefaultHeatTimeout();
}
- public Either<Map<String, List<CatalogComponent>>, ResponseFormat> getCatalogComponents(String userId, List<OriginTypeEnum> excludeTypes) {
+ public Either<Map<String, List<CatalogComponent>>, ResponseFormat> getCatalogComponents(List<OriginTypeEnum> excludeTypes) {
try {
return toscaOperationFacade.getCatalogOrArchiveComponents(true, excludeTypes)
.bimap(this::groupByComponentType, err -> componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(err)));
@@ -1120,7 +1118,7 @@ public class ElementBusinessLogic extends BaseBusinessLogic {
}
CategoryData categoryData = categoryResult.left().value();
Either<List<ImmutablePair<SubCategoryData, GraphEdge>>, JanusGraphOperationStatus> childrenNodes = janusGraphGenericDao
- .getChildrenNodes(UniqueIdBuilder.getKeyByNodeType(NodeTypeEnum.ResourceNewCategory), (String) categoryData.getUniqueId(),
+ .getChildrenNodes(UniqueIdBuilder.getKeyByNodeType(NodeTypeEnum.ResourceNewCategory), categoryData.getUniqueId(),
GraphEdgeLabels.SUB_CATEGORY, NodeTypeEnum.ResourceSubcategory, SubCategoryData.class);
if (childrenNodes.isRight()) {
return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(childrenNodes.right().value()));
@@ -1280,14 +1278,14 @@ public class ElementBusinessLogic extends BaseBusinessLogic {
}
}
- public CatalogUpdateTimestamp getCatalogUpdateTime(String userId) {
+ public CatalogUpdateTimestamp getCatalogUpdateTime() {
try {
return toscaOperationFacade.getCatalogTimes();
} finally {
janusGraphDao.commit();
}
}
-
+
public Either<List<BaseType>, ActionStatus> getBaseTypes(final String categoryName, final String userId, final String modelName) {
final ActionStatus status = validateUserExistsActionStatus(userId);
if (ActionStatus.OK != status) {
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ElementServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ElementServlet.java
index f8028583b3..45f99a931e 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ElementServlet.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ElementServlet.java
@@ -19,12 +19,20 @@
*/
package org.openecomp.sdc.be.servlets;
+import com.jcabi.aspects.Loggable;
+import fj.data.Either;
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.Parameter;
+import io.swagger.v3.oas.annotations.media.ArraySchema;
+import io.swagger.v3.oas.annotations.media.Content;
+import io.swagger.v3.oas.annotations.media.Schema;
+import io.swagger.v3.oas.annotations.responses.ApiResponse;
+import io.swagger.v3.oas.annotations.servers.Server;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-
import javax.inject.Inject;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
@@ -40,7 +48,6 @@ import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
-
import org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic;
import org.openecomp.sdc.be.components.impl.ElementBusinessLogic;
import org.openecomp.sdc.be.components.impl.ModelBusinessLogic;
@@ -75,19 +82,6 @@ import org.openecomp.sdc.common.log.wrappers.Logger;
import org.openecomp.sdc.exception.ResponseFormat;
import org.springframework.stereotype.Controller;
-import com.jcabi.aspects.Loggable;
-
-import fj.data.Either;
-import io.swagger.v3.oas.annotations.Operation;
-import io.swagger.v3.oas.annotations.Parameter;
-import io.swagger.v3.oas.annotations.media.ArraySchema;
-import io.swagger.v3.oas.annotations.media.Content;
-import io.swagger.v3.oas.annotations.media.Schema;
-import io.swagger.v3.oas.annotations.responses.ApiResponse;
-import io.swagger.v3.oas.annotations.servers.Server;
-import io.swagger.v3.oas.annotations.servers.Servers;
-import io.swagger.v3.oas.annotations.tags.Tags;
-
@Path("/v1/")
/**
*
@@ -96,8 +90,8 @@ import io.swagger.v3.oas.annotations.tags.Tags;
*
*/
@Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
-@Tags({@io.swagger.v3.oas.annotations.tags.Tag(name = "SDCE-2 APIs")})
-@Servers({@Server(url = "/sdc2/rest")})
+@io.swagger.v3.oas.annotations.tags.Tag(name = "SDCE-2 APIs")
+@Server(url = "/sdc2/rest")
@Controller
public class ElementServlet extends BeGenericServlet {
@@ -197,24 +191,25 @@ public class ElementServlet extends BeGenericServlet {
throw e;
}
}
-
+
@GET
@Path("/category/{componentType}/{categoryName}/baseTypes")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Operation(description = "Get base types for category", method = "GET", summary = "Get base types for category",
- responses = {@ApiResponse(responseCode = "200", description = "Returns base types Ok"),
- @ApiResponse(responseCode = "404", description = "No base types were found"),
- @ApiResponse(responseCode = "500", description = "Internal Server Error")})
+ responses = {@ApiResponse(responseCode = "200", description = "Returns base types Ok"),
+ @ApiResponse(responseCode = "404", description = "No base types were found"),
+ @ApiResponse(responseCode = "500", description = "Internal Server Error")})
@PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
public Response getCategoryBaseTypes(@PathParam(value = "categoryName") final String categoryName,
- @PathParam(value = "componentType") final String componentType, @Context final HttpServletRequest request,
- @HeaderParam(value = Constants.USER_ID_HEADER) String userId,
- @Parameter(description = "model", required = false) @QueryParam("model") String modelName) {
+ @PathParam(value = "componentType") final String componentType,
+ @Context final HttpServletRequest request,
+ @HeaderParam(value = Constants.USER_ID_HEADER) String userId,
+ @Parameter(description = "model", required = false) @QueryParam("model") String modelName) {
try {
final ElementBusinessLogic elementBL = getElementBL(request.getSession().getServletContext());
final Either<List<BaseType>, ActionStatus> either = elementBL.getBaseTypes(categoryName, userId, modelName);
-
+
if (either.isRight() || either.left().value() == null) {
log.debug("No base types were found");
return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.NO_CONTENT));
@@ -553,7 +548,7 @@ public class ElementServlet extends BeGenericServlet {
String url = request.getMethod() + " " + request.getRequestURI();
log.debug(START_HANDLE_REQUEST_OF, url);
Either<Map<String, List<CatalogComponent>>, ResponseFormat> catalogData = getElementBL(request.getSession().getServletContext())
- .getCatalogComponents(userId, excludeTypes);
+ .getCatalogComponents(excludeTypes);
if (catalogData.isRight()) {
log.debug("failed to get catalog data");
return buildErrorResponse(catalogData.right().value());
@@ -625,7 +620,7 @@ public class ElementServlet extends BeGenericServlet {
public Response getCatalogUpdateTime(@Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
String url = request.getMethod() + " " + request.getRequestURI();
log.debug("(post) Start handle request of {}", url);
- CatalogUpdateTimestamp catalogUpdateTimestamp = getElementBL(request.getSession().getServletContext()).getCatalogUpdateTime(userId);
+ CatalogUpdateTimestamp catalogUpdateTimestamp = getElementBL(request.getSession().getServletContext()).getCatalogUpdateTime();
return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), catalogUpdateTimestamp);
}
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
+
+}