aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/Service.java9
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/ElementOperation.java72
-rw-r--r--catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/ElementOperationTest.java775
-rw-r--r--catalog-model/src/test/resources/config/configuration.yaml9
-rw-r--r--common-app-api/src/main/java/org/openecomp/sdc/be/config/Configuration.java2
10 files changed, 636 insertions, 668 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
+
+}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/Service.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/Service.java
index 9728e8ccb8..a06f737c83 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/Service.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/Service.java
@@ -19,9 +19,11 @@
*/
package org.openecomp.sdc.be.model;
+import static java.util.Optional.ofNullable;
+
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
-import java.util.Optional;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
@@ -165,8 +167,9 @@ public class Service extends Component {
}
private String fetchToscaNameFromConfigBasedOnService(final String serviceCategory) {
- return Optional.ofNullable(ConfigurationManager.getConfigurationManager().getConfiguration().getServiceNodeTypes())
- .map(serviceNames -> serviceNames.get(serviceCategory)).orElse(null);
+ final Map<String, List<String>> serviceNodeTypes = ConfigurationManager.getConfigurationManager().getConfiguration().getServiceNodeTypes();
+ final List<String> stringList = ofNullable(serviceNodeTypes).map(serviceNames -> serviceNames.get(serviceCategory)).orElse(null);
+ return stringList != null ? stringList.get(0) : null;
}
@Override
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/ElementOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/ElementOperation.java
index 4c97b45830..b98f8d9dea 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/ElementOperation.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/ElementOperation.java
@@ -40,10 +40,10 @@ import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.dao.graph.datatype.GraphEdge;
import org.openecomp.sdc.be.dao.graph.datatype.GraphNode;
import org.openecomp.sdc.be.dao.graph.datatype.GraphRelation;
+import org.openecomp.sdc.be.dao.janusgraph.HealingJanusGraphDao;
import org.openecomp.sdc.be.dao.janusgraph.JanusGraphGenericDao;
import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
import org.openecomp.sdc.be.dao.jsongraph.GraphVertex;
-import org.openecomp.sdc.be.dao.janusgraph.HealingJanusGraphDao;
import org.openecomp.sdc.be.dao.jsongraph.types.EdgeLabelEnum;
import org.openecomp.sdc.be.dao.jsongraph.types.JsonParseFlagEnum;
import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum;
@@ -80,10 +80,12 @@ public class ElementOperation implements IElementOperation {
private static final String COULDN_T_FETCH_janusGraph_GRAPH = "Couldn't fetch janusgraph graph";
private static final String UNKNOWN_CATEGORY_TYPE = "Unknown category type {}";
private static final Logger log = Logger.getLogger(ElementOperation.class.getName());
+ private static final String PROBLEM_WHILE_CREATING_CATEGORY_REASON = "Problem while creating category, reason {}";
private JanusGraphGenericDao janusGraphGenericDao;
private HealingJanusGraphDao janusGraphDao;
- public ElementOperation(@Qualifier("janusgraph-generic-dao") JanusGraphGenericDao janusGraphGenericDao, @Qualifier("janusgraph-dao") HealingJanusGraphDao janusGraphDao) {
+ public ElementOperation(@Qualifier("janusgraph-generic-dao") JanusGraphGenericDao janusGraphGenericDao,
+ @Qualifier("janusgraph-dao") HealingJanusGraphDao janusGraphDao) {
super();
this.janusGraphGenericDao = janusGraphGenericDao;
this.janusGraphDao = janusGraphDao;
@@ -143,7 +145,7 @@ public class ElementOperation implements IElementOperation {
if (createNode.isRight()) {
JanusGraphOperationStatus value = createNode.right().value();
ActionStatus actionStatus = ActionStatus.GENERAL_ERROR;
- log.debug("Problem while creating category, reason {}", value);
+ log.debug(PROBLEM_WHILE_CREATING_CATEGORY_REASON, value);
if (value == JanusGraphOperationStatus.JANUSGRAPH_SCHEMA_VIOLATION) {
actionStatus = ActionStatus.COMPONENT_CATEGORY_ALREADY_EXISTS;
}
@@ -179,7 +181,7 @@ public class ElementOperation implements IElementOperation {
if (updatedNode.isRight()) {
JanusGraphOperationStatus value = updatedNode.right().value();
ActionStatus actionStatus = ActionStatus.GENERAL_ERROR;
- log.debug("Problem while creating category, reason {}", value);
+ log.debug(PROBLEM_WHILE_CREATING_CATEGORY_REASON, value);
result = Either.right(actionStatus);
return result;
}
@@ -228,7 +230,7 @@ public class ElementOperation implements IElementOperation {
.createNode(subCategoryData, SubCategoryData.class);
if (subCategoryNode.isRight()) {
JanusGraphOperationStatus janusGraphOperationStatus = subCategoryNode.right().value();
- log.debug("Problem while creating category, reason {}", janusGraphOperationStatus);
+ log.debug(PROBLEM_WHILE_CREATING_CATEGORY_REASON, janusGraphOperationStatus);
if (janusGraphOperationStatus == JanusGraphOperationStatus.JANUSGRAPH_SCHEMA_VIOLATION) {
actionStatus = ActionStatus.COMPONENT_SUB_CATEGORY_EXISTS_FOR_CATEGORY;
}
@@ -380,50 +382,54 @@ public class ElementOperation implements IElementOperation {
}
@Override
- public List<BaseType> getBaseTypes(final String categoryName, final String modelName){
+ public List<BaseType> getBaseTypes(final String categoryName, final String modelName) {
final ArrayList<BaseType> baseTypes = new ArrayList<>();
- final Map<String, String> categoriesSpecificBaseTypes = ConfigurationManager.getConfigurationManager().getConfiguration().getServiceNodeTypes();
- final String categorySpecificBaseType = categoriesSpecificBaseTypes == null ? null : categoriesSpecificBaseTypes.get(categoryName);
+ final Map<String, List<String>> categoriesSpecificBaseTypes = ConfigurationManager.getConfigurationManager().getConfiguration().getServiceNodeTypes();
+ final List<String> categorySpecificBaseType = categoriesSpecificBaseTypes == null ? null : categoriesSpecificBaseTypes.get(categoryName);
final String generalBaseType = ConfigurationManager.getConfigurationManager().getConfiguration().getGenericAssetNodeTypes().get("Service");
- final String baseToscaResourceName = categorySpecificBaseType == null? generalBaseType : categorySpecificBaseType;
+ final List<String> baseToscaResourceNames = categorySpecificBaseType == null ? List.of(generalBaseType) : categorySpecificBaseType;
- final Map<GraphPropertyEnum, Object> props = new EnumMap<>(GraphPropertyEnum.class);
- props.put(GraphPropertyEnum.TOSCA_RESOURCE_NAME, baseToscaResourceName);
- props.put(GraphPropertyEnum.STATE, LifecycleStateEnum.CERTIFIED.name());
- final Either<List<GraphVertex>, JanusGraphOperationStatus> baseTypeVertex = janusGraphDao
+ baseToscaResourceNames.forEach(baseToscaResourceName -> {
+ final Map<GraphPropertyEnum, Object> props = new EnumMap<>(GraphPropertyEnum.class);
+ props.put(GraphPropertyEnum.TOSCA_RESOURCE_NAME, baseToscaResourceName);
+ props.put(GraphPropertyEnum.STATE, LifecycleStateEnum.CERTIFIED.name());
+ final Either<List<GraphVertex>, JanusGraphOperationStatus> baseTypeVertex = janusGraphDao
.getByCriteria(VertexTypeEnum.NODE_TYPE, props, null, JsonParseFlagEnum.ParseAll, modelName);
-
- if (baseTypeVertex.isLeft()) {
- BaseType baseType = new BaseType(baseToscaResourceName);
- baseTypes.add(baseType);
-
- final Map<String, List<String>> typesDerivedFromBaseType = new LinkedHashMap<>();
- baseTypeVertex.left().value().forEach(v -> {
- baseType.addVersion((String)v.getMetadataProperty(GraphPropertyEnum.VERSION));
- addTypesDerivedFromVertex(typesDerivedFromBaseType, v);
- });
-
- typesDerivedFromBaseType.forEach((k,v) -> baseTypes.add(new BaseType(k, v)));
- }
+
+ if (baseTypeVertex.isLeft()) {
+ BaseType baseType = new BaseType(baseToscaResourceName);
+ baseTypes.add(baseType);
+
+ final Map<String, List<String>> typesDerivedFromBaseType = new LinkedHashMap<>();
+ baseTypeVertex.left().value().forEach(v -> {
+ baseType.addVersion((String) v.getMetadataProperty(GraphPropertyEnum.VERSION));
+ addTypesDerivedFromVertex(typesDerivedFromBaseType, v);
+ });
+
+ typesDerivedFromBaseType.forEach((k, v) -> baseTypes.add(new BaseType(k, v)));
+ }
+ });
return baseTypes;
}
private Map<String, List<String>> addTypesDerivedFromVertex(final Map<String, List<String>> types, final GraphVertex vertex) {
final Either<List<GraphVertex>, JanusGraphOperationStatus> derivedFromVertex =
- janusGraphDao.getParentVertices(vertex, EdgeLabelEnum.DERIVED_FROM, JsonParseFlagEnum.ParseAll);
+ janusGraphDao.getParentVertices(vertex, EdgeLabelEnum.DERIVED_FROM, JsonParseFlagEnum.ParseAll);
if (derivedFromVertex.isLeft()) {
- derivedFromVertex.left().value().stream().filter(v -> v.getMetadataProperty(GraphPropertyEnum.STATE).equals(LifecycleStateEnum.CERTIFIED.name()))
+ derivedFromVertex.left().value().stream()
+ .filter(v -> v.getMetadataProperty(GraphPropertyEnum.STATE).equals(LifecycleStateEnum.CERTIFIED.name()))
.forEach(v -> {
- addBaseTypeVersion(types, (String) v.getMetadataProperty(GraphPropertyEnum.TOSCA_RESOURCE_NAME), (String) v.getMetadataProperty(GraphPropertyEnum.VERSION));
- addTypesDerivedFromVertex(types, v);
+ addBaseTypeVersion(types, (String) v.getMetadataProperty(GraphPropertyEnum.TOSCA_RESOURCE_NAME),
+ (String) v.getMetadataProperty(GraphPropertyEnum.VERSION));
+ addTypesDerivedFromVertex(types, v);
});
}
return types;
}
private void addBaseTypeVersion(final Map<String, List<String>> baseTypes, final String baseTypeToscaResourceName, final String baseTypeVersion) {
- List<String> versions = baseTypes.get(baseTypeToscaResourceName) == null ? new ArrayList<>(): baseTypes.get(baseTypeToscaResourceName);
+ List<String> versions = baseTypes.get(baseTypeToscaResourceName) == null ? new ArrayList<>() : baseTypes.get(baseTypeToscaResourceName);
versions.add(baseTypeVersion);
baseTypes.put(baseTypeToscaResourceName, versions);
}
@@ -619,7 +625,7 @@ public class ElementOperation implements IElementOperation {
}
Vertex artifactV = iterator.next();
artifactV.remove();
- ;
+
SubCategoryDefinition deleted = new SubCategoryDefinition(subCategoryDataEither.left().value().getSubCategoryDataDefinition());
result = Either.left(deleted);
return result;
@@ -664,7 +670,7 @@ public class ElementOperation implements IElementOperation {
}
Vertex artifactV = iterator.next();
artifactV.remove();
- ;
+
GroupingDefinition deleted = new GroupingDefinition(groupingDataEither.left().value().getGroupingDataDefinition());
result = Either.left(deleted);
return result;
diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/ElementOperationTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/ElementOperationTest.java
index 58ee0d52af..cf3b6dad8b 100644
--- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/ElementOperationTest.java
+++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/ElementOperationTest.java
@@ -7,9 +7,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -20,19 +20,36 @@
package org.openecomp.sdc.be.model.operations.impl;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.any;
+import static org.mockito.Mockito.eq;
+import static org.mockito.Mockito.isNull;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
import fj.data.Either;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
import org.apache.tinkerpop.gremlin.structure.T;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
import org.openecomp.sdc.be.config.ArtifactConfiguration;
import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.dao.impl.HealingPipelineDao;
+import org.openecomp.sdc.be.dao.janusgraph.HealingJanusGraphDao;
import org.openecomp.sdc.be.dao.janusgraph.JanusGraphClient;
import org.openecomp.sdc.be.dao.janusgraph.JanusGraphGenericDao;
import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
import org.openecomp.sdc.be.dao.jsongraph.GraphVertex;
-import org.openecomp.sdc.be.dao.janusgraph.HealingJanusGraphDao;
import org.openecomp.sdc.be.dao.jsongraph.types.EdgeLabelEnum;
import org.openecomp.sdc.be.dao.jsongraph.types.JsonParseFlagEnum;
import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum;
@@ -51,70 +68,62 @@ import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.be.model.operations.impl.util.OperationTestsUtil;
import org.openecomp.sdc.be.resources.data.category.CategoryData;
import org.springframework.test.context.ContextConfiguration;
-import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.Mockito.*;
-
-@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:application-context-test.xml")
public class ElementOperationTest extends ModelTestBase {
- @javax.annotation.Resource(name = "element-operation")
+ @InjectMocks
private ElementOperation elementOperation;
- @javax.annotation.Resource(name = "janusgraph-generic-dao")
+ @Mock
private JanusGraphGenericDao janusGraphDao;
private static String CATEGORY = "category";
private static String SUBCATEGORY = "subcategory";
- @BeforeClass
+ @BeforeAll
public static void setupBeforeClass() {
ModelTestBase.init();
}
+ @BeforeEach
+ void beforeEachInit() {
+ MockitoAnnotations.openMocks(this);
+ }
+
@Test
public void testGetArtifactsTypes() {
final List<ArtifactConfiguration> expectedArtifactConfigurationList = new ArrayList<>();
- final ArtifactConfiguration artifactConfiguration1 = new ArtifactConfiguration();
- artifactConfiguration1.setType("type1");
- expectedArtifactConfigurationList.add(artifactConfiguration1);
- final ArtifactConfiguration artifactConfiguration2 = new ArtifactConfiguration();
- artifactConfiguration2.setType("type2");
- expectedArtifactConfigurationList.add(artifactConfiguration2);
- final ArtifactConfiguration artifactConfiguration3 = new ArtifactConfiguration();
- artifactConfiguration3.setType("type3");
- expectedArtifactConfigurationList.add(artifactConfiguration3);
- configurationManager.getConfiguration().setArtifacts(expectedArtifactConfigurationList);
+ final ArtifactConfiguration artifactConfiguration1 = new ArtifactConfiguration();
+ artifactConfiguration1.setType("type1");
+ expectedArtifactConfigurationList.add(artifactConfiguration1);
+ final ArtifactConfiguration artifactConfiguration2 = new ArtifactConfiguration();
+ artifactConfiguration2.setType("type2");
+ expectedArtifactConfigurationList.add(artifactConfiguration2);
+ final ArtifactConfiguration artifactConfiguration3 = new ArtifactConfiguration();
+ artifactConfiguration3.setType("type3");
+ expectedArtifactConfigurationList.add(artifactConfiguration3);
+ configurationManager.getConfiguration().setArtifacts(expectedArtifactConfigurationList);
List<ArtifactType> actualArtifactTypes = elementOperation.getAllArtifactTypes();
- assertNotNull(actualArtifactTypes);
+ assertNotNull(actualArtifactTypes);
assertEquals(expectedArtifactConfigurationList.size(), actualArtifactTypes.size());
- boolean allMatch = actualArtifactTypes.stream().allMatch(artifactType ->
- expectedArtifactConfigurationList.stream()
- .anyMatch(artifactConfiguration -> artifactConfiguration.getType().equals(artifactType.getName()))
- );
- assertTrue(allMatch);
+ boolean allMatch = actualArtifactTypes.stream().allMatch(artifactType ->
+ expectedArtifactConfigurationList.stream()
+ .anyMatch(artifactConfiguration -> artifactConfiguration.getType().equals(artifactType.getName()))
+ );
+ assertTrue(allMatch);
expectedArtifactConfigurationList.remove(0);
actualArtifactTypes = elementOperation.getAllArtifactTypes();
- assertNotNull(actualArtifactTypes);
+ assertNotNull(actualArtifactTypes);
assertEquals(expectedArtifactConfigurationList.size(), actualArtifactTypes.size());
- allMatch = actualArtifactTypes.stream().allMatch(artifactType ->
- expectedArtifactConfigurationList.stream()
- .anyMatch(artifactConfiguration -> artifactConfiguration.getType().equals(artifactType.getName()))
- );
- assertTrue(allMatch);
+ allMatch = actualArtifactTypes.stream().allMatch(artifactType ->
+ expectedArtifactConfigurationList.stream()
+ .anyMatch(artifactConfiguration -> artifactConfiguration.getType().equals(artifactType.getName()))
+ );
+ assertTrue(allMatch);
}
// @Test
@@ -133,350 +142,318 @@ public class ElementOperationTest extends ModelTestBase {
assertTrue(res.isLeft());
categoryDefinition = (CategoryDefinition) res.left().value();
assertEquals(CATEGORY, categoryDefinition.getName());
- }
-
- private ElementOperation createTestSubject() {
- return new ElementOperation(new JanusGraphGenericDao(new JanusGraphClient()), new HealingJanusGraphDao(new HealingPipelineDao(), new JanusGraphClient()));
- }
-
-
- @Test
- public void testGetAllServiceCategories() throws Exception {
- ElementOperation testSubject;
- Either<List<CategoryDefinition>, ActionStatus> result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getAllServiceCategories();
- }
-
-
- @Test
- public void testGetAllResourceCategories() throws Exception {
- ElementOperation testSubject;
- Either<List<CategoryDefinition>, ActionStatus> result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getAllResourceCategories();
- }
-
-
- @Test
- public void testGetAllProductCategories() throws Exception {
- ElementOperation testSubject;
- Either<List<CategoryDefinition>, ActionStatus> result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getAllProductCategories();
- }
-
-
- @Test
- public void testCreateCategory() throws Exception {
- ElementOperation testSubject;
- CategoryDefinition category = new CategoryDefinition();
- NodeTypeEnum nodeType = NodeTypeEnum.AdditionalInfoParameters;
- Either<CategoryDefinition, ActionStatus> result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.createCategory(category, nodeType);
- }
-
-
- @Test
- public void testCreateCategory_1() throws Exception {
- ElementOperation testSubject;
- CategoryDefinition category = new CategoryDefinition();
- NodeTypeEnum nodeType = NodeTypeEnum.ArtifactRef;
- boolean inTransaction = false;
- Either<CategoryDefinition, ActionStatus> result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.createCategory(category, nodeType, inTransaction);
- }
-
-
- @Test
- public void testCreateSubCategory() throws Exception {
- ElementOperation testSubject;
- String categoryId = "";
- SubCategoryDefinition subCategory = null;
- NodeTypeEnum nodeType = null;
- Either<SubCategoryDefinition, ActionStatus> result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.createSubCategory(categoryId, subCategory, nodeType);
- }
-
-
- @Test
- public void testCreateSubCategory_1() throws Exception {
- ElementOperation testSubject;
- String categoryId = "";
- SubCategoryDefinition subCategory = null;
- NodeTypeEnum nodeType = null;
- boolean inTransaction = false;
- Either<SubCategoryDefinition, ActionStatus> result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.createSubCategory(categoryId, subCategory, nodeType, inTransaction);
- }
-
-
- @Test
- public void testCreateGrouping() throws Exception {
- ElementOperation testSubject;
- String subCategoryId = "";
- GroupingDefinition grouping = null;
- NodeTypeEnum nodeType = null;
- Either<GroupingDefinition, ActionStatus> result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.createGrouping(subCategoryId, grouping, nodeType);
- }
-
-
- @Test
- public void testGetAllCategories() throws Exception {
- ElementOperation testSubject;
- NodeTypeEnum nodeType = NodeTypeEnum.Capability;
- boolean inTransaction = false;
- Either<List<CategoryDefinition>, ActionStatus> result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getAllCategories(nodeType, inTransaction);
- }
-
-
-
-
-
-
-
-
-
- @Test
- public void testGetCategory() throws Exception {
- ElementOperation testSubject;
- NodeTypeEnum nodeType = NodeTypeEnum.CapabilityType;
- String categoryId = "";
- Either<CategoryDefinition, ActionStatus> result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getCategory(nodeType, categoryId);
- }
-
-
- @Test
- public void testGetSubCategory() throws Exception {
- ElementOperation testSubject;
- NodeTypeEnum nodeType = NodeTypeEnum.Group;
- String subCategoryId = "";
- Either<SubCategoryDefinition, ActionStatus> result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getSubCategory(nodeType, subCategoryId);
- }
-
-
- @Test
- public void testDeleteCategory() throws Exception {
- ElementOperation testSubject;
- NodeTypeEnum nodeType = NodeTypeEnum.getByName("resource");
- String categoryId = "";
- Either<CategoryDefinition, ActionStatus> result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.deleteCategory(nodeType, categoryId);
- }
-
-
- @Test
- public void testDeleteSubCategory() throws Exception {
- ElementOperation testSubject;
- NodeTypeEnum nodeType = NodeTypeEnum.Attribute;
- String subCategoryId = "";
- Either<SubCategoryDefinition, ActionStatus> result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.deleteSubCategory(nodeType, subCategoryId);
- }
-
-
- @Test
- public void testDeleteGrouping() throws Exception {
- ElementOperation testSubject;
- NodeTypeEnum nodeType = NodeTypeEnum.DataType;
- String groupingId = "";
- Either<GroupingDefinition, ActionStatus> result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.deleteGrouping(nodeType, groupingId);
- }
-
-
- @Test
- public void testIsCategoryUniqueForType() throws Exception {
- ElementOperation testSubject;
- NodeTypeEnum nodeType = null;
- String normalizedName = "";
- Either<Boolean, ActionStatus> result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.isCategoryUniqueForType(nodeType, normalizedName);
- }
-
-
- @Test
- public void testIsSubCategoryUniqueForCategory() throws Exception {
- ElementOperation testSubject;
- NodeTypeEnum nodeType = null;
- String subCategoryNormName = "";
- String parentCategoryId = "";
- Either<Boolean, ActionStatus> result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.isSubCategoryUniqueForCategory(nodeType, subCategoryNormName, parentCategoryId);
- }
-
-
- @Test
- public void testIsGroupingUniqueForSubCategory() throws Exception {
- ElementOperation testSubject;
- NodeTypeEnum nodeType = null;
- String groupingNormName = "";
- String parentSubCategoryId = "";
- Either<Boolean, ActionStatus> result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.isGroupingUniqueForSubCategory(nodeType, groupingNormName, parentSubCategoryId);
- }
-
-
- @Test
- public void testGetSubCategoryUniqueForType() throws Exception {
- ElementOperation testSubject;
- NodeTypeEnum nodeType = null;
- String normalizedName = "";
- Either<SubCategoryDefinition, ActionStatus> result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getSubCategoryUniqueForType(nodeType, normalizedName);
- }
-
-
- @Test
- public void testGetGroupingUniqueForType() throws Exception {
- ElementOperation testSubject;
- NodeTypeEnum nodeType = null;
- String groupingNormalizedName = "";
- Either<GroupingDefinition, ActionStatus> result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getGroupingUniqueForType(nodeType, groupingNormalizedName);
- }
-
-
- @Test
- public void testGetAllTags() throws Exception {
- ElementOperation testSubject;
- Either<List<Tag>, ActionStatus> result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getAllTags();
- }
-
-
- @Test
- public void testGetCategoryData() throws Exception {
- ElementOperation testSubject;
- String name = "";
- NodeTypeEnum type = NodeTypeEnum.DataType;
- Class<T> clazz = null;
- Either<org.openecomp.sdc.be.resources.data.CategoryData, StorageOperationStatus> result;
-
- // test 1
- testSubject = createTestSubject();
- name = null;
- result = testSubject.getCategoryData(name, type, null);
-
- // test 2
- testSubject = createTestSubject();
- name = "";
- result = testSubject.getCategoryData(name, type, null);
- }
-
-
-
-
-
- @Test
- public void testGetAllPropertyScopes() throws Exception {
- ElementOperation testSubject;
- Either<List<PropertyScope>, ActionStatus> result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getAllPropertyScopes();
- }
-
- @Test
- public void testGetResourceTypesMap() throws Exception {
- ElementOperation testSubject;
- Either<Map<String, String>, ActionStatus> result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getResourceTypesMap();
- }
-
- @Test
- public void testGetNewCategoryData() throws Exception {
- ElementOperation testSubject;
- String name = "";
- NodeTypeEnum type = NodeTypeEnum.HeatParameter;
- Class<T> clazz = null;
- Either<CategoryData, StorageOperationStatus> result;
-
- // test 1
- testSubject = createTestSubject();
- name = null;
- result = testSubject.getNewCategoryData(name, type, null);
-
- // test 2
- testSubject = createTestSubject();
- name = "";
- result = testSubject.getNewCategoryData(name, type, null);
}
-
+
+ private ElementOperation createTestSubject() {
+ return new ElementOperation(new JanusGraphGenericDao(new JanusGraphClient()),
+ new HealingJanusGraphDao(new HealingPipelineDao(), new JanusGraphClient()));
+ }
+
+ @Test
+ public void testGetAllServiceCategories() throws Exception {
+ ElementOperation testSubject;
+ Either<List<CategoryDefinition>, ActionStatus> result;
+
+ // default test
+ testSubject = createTestSubject();
+ result = testSubject.getAllServiceCategories();
+ }
+
+ @Test
+ public void testGetAllResourceCategories() throws Exception {
+ ElementOperation testSubject;
+ Either<List<CategoryDefinition>, ActionStatus> result;
+
+ // default test
+ testSubject = createTestSubject();
+ result = testSubject.getAllResourceCategories();
+ }
+
+ @Test
+ public void testGetAllProductCategories() throws Exception {
+ ElementOperation testSubject;
+ Either<List<CategoryDefinition>, ActionStatus> result;
+
+ // default test
+ testSubject = createTestSubject();
+ result = testSubject.getAllProductCategories();
+ }
+
+ @Test
+ public void testCreateCategory() throws Exception {
+ ElementOperation testSubject;
+ CategoryDefinition category = new CategoryDefinition();
+ NodeTypeEnum nodeType = NodeTypeEnum.AdditionalInfoParameters;
+ Either<CategoryDefinition, ActionStatus> result;
+
+ // default test
+ testSubject = createTestSubject();
+ result = testSubject.createCategory(category, nodeType);
+ }
+
+ @Test
+ public void testCreateCategory_1() throws Exception {
+ ElementOperation testSubject;
+ CategoryDefinition category = new CategoryDefinition();
+ NodeTypeEnum nodeType = NodeTypeEnum.ArtifactRef;
+ boolean inTransaction = false;
+ Either<CategoryDefinition, ActionStatus> result;
+
+ // default test
+ testSubject = createTestSubject();
+ result = testSubject.createCategory(category, nodeType, inTransaction);
+ }
+
+ @Test
+ public void testCreateSubCategory() throws Exception {
+ ElementOperation testSubject;
+ String categoryId = "";
+ SubCategoryDefinition subCategory = null;
+ NodeTypeEnum nodeType = null;
+ Either<SubCategoryDefinition, ActionStatus> result;
+
+ // default test
+ testSubject = createTestSubject();
+ result = testSubject.createSubCategory(categoryId, subCategory, nodeType);
+ }
+
+ @Test
+ public void testCreateSubCategory_1() throws Exception {
+ ElementOperation testSubject;
+ String categoryId = "";
+ SubCategoryDefinition subCategory = null;
+ NodeTypeEnum nodeType = null;
+ boolean inTransaction = false;
+ Either<SubCategoryDefinition, ActionStatus> result;
+
+ // default test
+ testSubject = createTestSubject();
+ result = testSubject.createSubCategory(categoryId, subCategory, nodeType, inTransaction);
+ }
+
+ @Test
+ public void testCreateGrouping() throws Exception {
+ ElementOperation testSubject;
+ String subCategoryId = "";
+ GroupingDefinition grouping = null;
+ NodeTypeEnum nodeType = null;
+ Either<GroupingDefinition, ActionStatus> result;
+
+ // default test
+ testSubject = createTestSubject();
+ result = testSubject.createGrouping(subCategoryId, grouping, nodeType);
+ }
+
+ @Test
+ public void testGetAllCategories() throws Exception {
+ ElementOperation testSubject;
+ NodeTypeEnum nodeType = NodeTypeEnum.Capability;
+ boolean inTransaction = false;
+ Either<List<CategoryDefinition>, ActionStatus> result;
+
+ // default test
+ testSubject = createTestSubject();
+ result = testSubject.getAllCategories(nodeType, inTransaction);
+ }
+
+ @Test
+ public void testGetCategory() throws Exception {
+ ElementOperation testSubject;
+ NodeTypeEnum nodeType = NodeTypeEnum.CapabilityType;
+ String categoryId = "";
+ Either<CategoryDefinition, ActionStatus> result;
+
+ // default test
+ testSubject = createTestSubject();
+ result = testSubject.getCategory(nodeType, categoryId);
+ }
+
+ @Test
+ public void testGetSubCategory() throws Exception {
+ ElementOperation testSubject;
+ NodeTypeEnum nodeType = NodeTypeEnum.Group;
+ String subCategoryId = "";
+ Either<SubCategoryDefinition, ActionStatus> result;
+
+ // default test
+ testSubject = createTestSubject();
+ result = testSubject.getSubCategory(nodeType, subCategoryId);
+ }
+
+ @Test
+ public void testDeleteCategory() throws Exception {
+ ElementOperation testSubject;
+ NodeTypeEnum nodeType = NodeTypeEnum.getByName("resource");
+ String categoryId = "";
+ Either<CategoryDefinition, ActionStatus> result;
+
+ // default test
+ testSubject = createTestSubject();
+ result = testSubject.deleteCategory(nodeType, categoryId);
+ }
+
+ @Test
+ public void testDeleteSubCategory() throws Exception {
+ ElementOperation testSubject;
+ NodeTypeEnum nodeType = NodeTypeEnum.Attribute;
+ String subCategoryId = "";
+ Either<SubCategoryDefinition, ActionStatus> result;
+
+ // default test
+ testSubject = createTestSubject();
+ result = testSubject.deleteSubCategory(nodeType, subCategoryId);
+ }
+
+ @Test
+ public void testDeleteGrouping() throws Exception {
+ ElementOperation testSubject;
+ NodeTypeEnum nodeType = NodeTypeEnum.DataType;
+ String groupingId = "";
+ Either<GroupingDefinition, ActionStatus> result;
+
+ // default test
+ testSubject = createTestSubject();
+ result = testSubject.deleteGrouping(nodeType, groupingId);
+ }
+
+ @Test
+ public void testIsCategoryUniqueForType() throws Exception {
+ ElementOperation testSubject;
+ NodeTypeEnum nodeType = null;
+ String normalizedName = "";
+ Either<Boolean, ActionStatus> result;
+
+ // default test
+ testSubject = createTestSubject();
+ result = testSubject.isCategoryUniqueForType(nodeType, normalizedName);
+ }
+
+ @Test
+ public void testIsSubCategoryUniqueForCategory() throws Exception {
+ ElementOperation testSubject;
+ NodeTypeEnum nodeType = null;
+ String subCategoryNormName = "";
+ String parentCategoryId = "";
+ Either<Boolean, ActionStatus> result;
+
+ // default test
+ testSubject = createTestSubject();
+ result = testSubject.isSubCategoryUniqueForCategory(nodeType, subCategoryNormName, parentCategoryId);
+ }
+
+ @Test
+ public void testIsGroupingUniqueForSubCategory() throws Exception {
+ ElementOperation testSubject;
+ NodeTypeEnum nodeType = null;
+ String groupingNormName = "";
+ String parentSubCategoryId = "";
+ Either<Boolean, ActionStatus> result;
+
+ // default test
+ testSubject = createTestSubject();
+ result = testSubject.isGroupingUniqueForSubCategory(nodeType, groupingNormName, parentSubCategoryId);
+ }
+
+ @Test
+ public void testGetSubCategoryUniqueForType() throws Exception {
+ ElementOperation testSubject;
+ NodeTypeEnum nodeType = null;
+ String normalizedName = "";
+ Either<SubCategoryDefinition, ActionStatus> result;
+
+ // default test
+ testSubject = createTestSubject();
+ result = testSubject.getSubCategoryUniqueForType(nodeType, normalizedName);
+ }
+
+ @Test
+ public void testGetGroupingUniqueForType() throws Exception {
+ ElementOperation testSubject;
+ NodeTypeEnum nodeType = null;
+ String groupingNormalizedName = "";
+ Either<GroupingDefinition, ActionStatus> result;
+
+ // default test
+ testSubject = createTestSubject();
+ result = testSubject.getGroupingUniqueForType(nodeType, groupingNormalizedName);
+ }
+
+ @Test
+ public void testGetAllTags() throws Exception {
+ ElementOperation testSubject;
+ Either<List<Tag>, ActionStatus> result;
+
+ // default test
+ testSubject = createTestSubject();
+ result = testSubject.getAllTags();
+ }
+
+ @Test
+ public void testGetCategoryData() throws Exception {
+ ElementOperation testSubject;
+ String name = "";
+ NodeTypeEnum type = NodeTypeEnum.DataType;
+ Class<T> clazz = null;
+ Either<org.openecomp.sdc.be.resources.data.CategoryData, StorageOperationStatus> result;
+
+ // test 1
+ testSubject = createTestSubject();
+ name = null;
+ result = testSubject.getCategoryData(name, type, null);
+
+ // test 2
+ testSubject = createTestSubject();
+ name = "";
+ result = testSubject.getCategoryData(name, type, null);
+ }
+
+ @Test
+ public void testGetAllPropertyScopes() throws Exception {
+ ElementOperation testSubject;
+ Either<List<PropertyScope>, ActionStatus> result;
+
+ // default test
+ testSubject = createTestSubject();
+ result = testSubject.getAllPropertyScopes();
+ }
+
+ @Test
+ public void testGetResourceTypesMap() throws Exception {
+ ElementOperation testSubject;
+ Either<Map<String, String>, ActionStatus> result;
+
+ // default test
+ testSubject = createTestSubject();
+ result = testSubject.getResourceTypesMap();
+ }
+
+ @Test
+ public void testGetNewCategoryData() throws Exception {
+ ElementOperation testSubject;
+ String name = "";
+ NodeTypeEnum type = NodeTypeEnum.HeatParameter;
+ Class<T> clazz = null;
+ Either<CategoryData, StorageOperationStatus> result;
+
+ // test 1
+ testSubject = createTestSubject();
+ name = null;
+ result = testSubject.getNewCategoryData(name, type, null);
+
+ // test 2
+ testSubject = createTestSubject();
+ name = "";
+ result = testSubject.getNewCategoryData(name, type, null);
+ }
+
@Test
public void testBaseTypes_serviceSpecific() {
- Map<String, String> preExistingServiceNodeTypes = configurationManager.getConfiguration().getServiceNodeTypes();
- Map<String, String> preExistingGenericNodeTypes =
- configurationManager.getConfiguration().getGenericAssetNodeTypes();
+ Map<String, List<String>> preExistingServiceNodeTypes = configurationManager.getConfiguration().getServiceNodeTypes();
+ Map<String, String> preExistingGenericNodeTypes = configurationManager.getConfiguration().getGenericAssetNodeTypes();
try {
- Map<String, String> serviceNodeTypes = new HashMap<>();
- serviceNodeTypes.put("serviceCategoryA", "org.base.type");
+ Map<String, List<String>> serviceNodeTypes = new HashMap<>();
+ serviceNodeTypes.put("serviceCategoryA", List.of("org.base.type"));
configurationManager.getConfiguration().setServiceNodeTypes(serviceNodeTypes);
Map<String, String> genericNodeTypes = new HashMap<>();
@@ -484,28 +461,27 @@ public class ElementOperationTest extends ModelTestBase {
configurationManager.getConfiguration().setGenericAssetNodeTypes(genericNodeTypes);
HealingJanusGraphDao healingJanusGraphDao = mock(HealingJanusGraphDao.class);
- ElementOperation elementOperation =
- new ElementOperation(new JanusGraphGenericDao(new JanusGraphClient()), healingJanusGraphDao);
+ ElementOperation elementOperation = new ElementOperation(new JanusGraphGenericDao(new JanusGraphClient()), healingJanusGraphDao);
GraphVertex baseTypeVertex = mock(GraphVertex.class);
when(baseTypeVertex.getMetadataProperty(GraphPropertyEnum.VERSION)).thenReturn("1.0");
when(healingJanusGraphDao.getByCriteria(eq(VertexTypeEnum.NODE_TYPE), any(), isNull(), eq(JsonParseFlagEnum.ParseAll), any()))
- .thenReturn(Either.left(Collections.singletonList(baseTypeVertex)));
+ .thenReturn(Either.left(Collections.singletonList(baseTypeVertex)));
GraphVertex derivedTypeVertex = mock(GraphVertex.class);
when(derivedTypeVertex.getMetadataProperty(GraphPropertyEnum.STATE)).thenReturn(LifecycleStateEnum.CERTIFIED.name());
when(derivedTypeVertex.getMetadataProperty(GraphPropertyEnum.VERSION)).thenReturn("1.0");
-
+
GraphVertex derivedTypeVertexUncertified = mock(GraphVertex.class);
- when(derivedTypeVertexUncertified.getMetadataProperty(GraphPropertyEnum.STATE)).thenReturn(LifecycleStateEnum.NOT_CERTIFIED_CHECKIN.name());
+ when(derivedTypeVertexUncertified.getMetadataProperty(GraphPropertyEnum.STATE)).thenReturn(
+ LifecycleStateEnum.NOT_CERTIFIED_CHECKIN.name());
when(derivedTypeVertexUncertified.getMetadataProperty(GraphPropertyEnum.VERSION)).thenReturn("1.1");
-
+
when(healingJanusGraphDao.getParentVertices(baseTypeVertex, EdgeLabelEnum.DERIVED_FROM,
- JsonParseFlagEnum.ParseAll)).thenReturn(Either.left(Collections.singletonList(derivedTypeVertex)));
+ JsonParseFlagEnum.ParseAll)).thenReturn(Either.left(Collections.singletonList(derivedTypeVertex)));
when(healingJanusGraphDao.getParentVertices(derivedTypeVertex, EdgeLabelEnum.DERIVED_FROM,
- JsonParseFlagEnum.ParseAll)).thenReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND));
- when(derivedTypeVertex.getMetadataProperty(GraphPropertyEnum.TOSCA_RESOURCE_NAME))
- .thenReturn("org.parent.type");
+ JsonParseFlagEnum.ParseAll)).thenReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND));
+ when(derivedTypeVertex.getMetadataProperty(GraphPropertyEnum.TOSCA_RESOURCE_NAME)).thenReturn("org.parent.type");
List<BaseType> baseTypes = elementOperation.getBaseTypes("serviceCategoryA", null);
@@ -519,12 +495,12 @@ public class ElementOperationTest extends ModelTestBase {
configurationManager.getConfiguration().setGenericAssetNodeTypes(preExistingGenericNodeTypes);
}
}
-
+
@Test
public void testBaseTypes_default() {
- Map<String, String> preExistingServiceNodeTypes = configurationManager.getConfiguration().getServiceNodeTypes();
+ Map<String, List<String>> preExistingServiceNodeTypes = configurationManager.getConfiguration().getServiceNodeTypes();
Map<String, String> preExistingGenericNodeTypes =
- configurationManager.getConfiguration().getGenericAssetNodeTypes();
+ configurationManager.getConfiguration().getGenericAssetNodeTypes();
try {
Map<String, String> genericNodeTypes = new HashMap<>();
@@ -533,16 +509,15 @@ public class ElementOperationTest extends ModelTestBase {
configurationManager.getConfiguration().setServiceNodeTypes(null);
HealingJanusGraphDao healingJanusGraphDao = mock(HealingJanusGraphDao.class);
- ElementOperation elementOperation =
- new ElementOperation(new JanusGraphGenericDao(new JanusGraphClient()), healingJanusGraphDao);
+ final var elementOperation = new ElementOperation(new JanusGraphGenericDao(new JanusGraphClient()), healingJanusGraphDao);
GraphVertex baseTypeVertex = mock(GraphVertex.class);
when(baseTypeVertex.getMetadataProperty(GraphPropertyEnum.VERSION)).thenReturn("1.0");
when(healingJanusGraphDao.getByCriteria(eq(VertexTypeEnum.NODE_TYPE), any(), isNull(), eq(JsonParseFlagEnum.ParseAll), any()))
- .thenReturn(Either.left(Collections.singletonList(baseTypeVertex)));
+ .thenReturn(Either.left(Collections.singletonList(baseTypeVertex)));
when(healingJanusGraphDao.getParentVertices(baseTypeVertex, EdgeLabelEnum.DERIVED_FROM,
- JsonParseFlagEnum.ParseAll)).thenReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND));
+ JsonParseFlagEnum.ParseAll)).thenReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND));
List<BaseType> baseTypes = elementOperation.getBaseTypes("serviceCategoryA", null);
diff --git a/catalog-model/src/test/resources/config/configuration.yaml b/catalog-model/src/test/resources/config/configuration.yaml
index 95695b7ce8..02b9af9c1b 100644
--- a/catalog-model/src/test/resources/config/configuration.yaml
+++ b/catalog-model/src/test/resources/config/configuration.yaml
@@ -394,9 +394,12 @@ genericAssetNodeTypes:
Service: org.openecomp.resource.abstract.nodes.service
serviceNodeTypes:
- CategoryA: org.openecomp.resource.abstract.nodes.A
- CategoryB: org.openecomp.resource.abstract.nodes.B
- CategoryC: org.openecomp.resource.abstract.nodes.C
+ CategoryA:
+ - org.openecomp.resource.abstract.nodes.A
+ CategoryB:
+ - org.openecomp.resource.abstract.nodes.B
+ CategoryC:
+ - org.openecomp.resource.abstract.nodes.C
workloadContext: Production
environmentContext:
diff --git a/common-app-api/src/main/java/org/openecomp/sdc/be/config/Configuration.java b/common-app-api/src/main/java/org/openecomp/sdc/be/config/Configuration.java
index 9b3772f4fc..29ef6c4cae 100644
--- a/common-app-api/src/main/java/org/openecomp/sdc/be/config/Configuration.java
+++ b/common-app-api/src/main/java/org/openecomp/sdc/be/config/Configuration.java
@@ -119,7 +119,7 @@ public class Configuration extends BasicConfiguration {
private Boolean consumerBusinessLogic;
private Map<String, VfModuleProperty> vfModuleProperties;
private Map<String, String> genericAssetNodeTypes;
- private Map<String, String> serviceNodeTypes;
+ private Map<String, List<String>> serviceNodeTypes;
private Map<String, Map<String, String>> resourceNodeTypes;
private String appVersion;
private String artifactGeneratorConfig;