aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-be
diff options
context:
space:
mode:
authorPiotr Darosz <piotr.darosz@nokia.com>2019-08-29 08:53:10 +0200
committerPiotr Darosz <piotr.darosz@nokia.com>2019-08-29 09:57:42 +0200
commit7793441455f9981f0a8764a4cc9ac89a7e38342c (patch)
tree1bd6079f06c3173fd178e9ff351b1099d28a2613 /catalog-be
parentdafa368c6b069f86bf67265d5b17c69a06ca787b (diff)
catalog-be code coverage increase
Increase test code coverage in catalog-be ServiceBusinessLogic - part 1 Change-Id: I1ef29b46f41bfe7d41219ddbe5dbb0dd5a6649ad Issue-ID: SDC-2326 Signed-off-by: Piotr Darosz <piotr.darosz@nokia.com>
Diffstat (limited to 'catalog-be')
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogic.java5
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogicTest.java143
2 files changed, 142 insertions, 6 deletions
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogic.java
index fc0380a108..28fc2597b8 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogic.java
@@ -170,7 +170,8 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic {
private static final Logger log = Logger.getLogger(ServiceBusinessLogic.class);
private static final String INITIAL_VERSION = "0.1";
private static final String STATUS_SUCCESS_200 = "200";
- private static final String STATUS_DEPLOYED = "DEPLOYED";
+ private static final String STATUS_DEPLOYED = "DEPLOYED";
+ static final String IS_VALID = "isValid";
private ForwardingPathOperation forwardingPathOperation;
private AuditCassandraDao auditCassandraDao;
@@ -1035,7 +1036,7 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic {
if (dataModelResponse.isLeft()) {
Map<String, Boolean> result = new HashMap<>();
- result.put("isValid", dataModelResponse.left().value());
+ result.put(IS_VALID, dataModelResponse.left().value());
log.debug("validation was successfully performed.");
return Either.left(result);
}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogicTest.java
index 30cc8a2adc..d534cdf79e 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogicTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogicTest.java
@@ -22,8 +22,11 @@
package org.openecomp.sdc.be.components.impl;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
import fj.data.Either;
import org.apache.commons.lang3.tuple.ImmutablePair;
+import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;
@@ -43,6 +46,9 @@ import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.dao.cassandra.AuditCassandraDao;
import org.openecomp.sdc.be.dao.jsongraph.JanusGraphDao;
import org.openecomp.sdc.be.datamodel.utils.UiComponentDataConverter;
+import org.openecomp.sdc.be.datatypes.elements.ArtifactDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.InterfaceInstanceDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.ListDataDefinition;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
import org.openecomp.sdc.be.impl.ComponentsUtils;
@@ -57,6 +63,7 @@ import org.openecomp.sdc.be.model.operations.impl.GraphLockOperation;
import org.openecomp.sdc.be.resources.data.auditing.DistributionDeployEvent;
import org.openecomp.sdc.be.resources.data.auditing.DistributionNotificationEvent;
import org.openecomp.sdc.be.resources.data.auditing.ResourceAdminEvent;
+import org.openecomp.sdc.be.types.ServiceConsumptionData;
import org.openecomp.sdc.be.user.Role;
import org.openecomp.sdc.be.user.UserBusinessLogic;
import org.openecomp.sdc.common.api.ArtifactGroupTypeEnum;
@@ -66,6 +73,7 @@ import org.openecomp.sdc.common.impl.ExternalConfiguration;
import org.openecomp.sdc.common.impl.FSConfigurationSource;
import org.openecomp.sdc.common.util.ValidationUtils;
import org.openecomp.sdc.exception.ResponseFormat;
+import org.springframework.http.HttpStatus;
import org.springframework.web.context.WebApplicationContext;
import javax.servlet.ServletContext;
@@ -80,12 +88,13 @@ import static org.junit.Assert.assertNotNull;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.when;
-import static org.mockito.ArgumentMatchers.eq;
public class ServiceBusinessLogicTest extends ComponentBusinessLogicMock {
private static final String SERVICE_CATEGORY = "Mobility";
private static final String INSTANTIATION_TYPE = "A-la-carte";
+ private static final String ALREADY_EXIST = "alreadyExist";
+ private static final String DOES_NOT_EXIST = "doesNotExist";
private final ServletContext servletContext = Mockito.mock(ServletContext.class);
private UserBusinessLogic mockUserAdmin = Mockito.mock(UserBusinessLogic.class);
private WebAppContextWrapper webAppContextWrapper = Mockito.mock(WebAppContextWrapper.class);
@@ -162,7 +171,7 @@ public class ServiceBusinessLogicTest extends ComponentBusinessLogicMock {
Either<Boolean, StorageOperationStatus> eitherCount = Either.left(false);
when(toscaOperationFacade.validateComponentNameExists("Service", null, ComponentTypeEnum.SERVICE)).thenReturn(eitherCount);
Either<Boolean, StorageOperationStatus> eitherCountExist = Either.left(true);
- when(toscaOperationFacade.validateComponentNameExists("alreadyExist", null, ComponentTypeEnum.SERVICE)).thenReturn(eitherCountExist);
+ when(toscaOperationFacade.validateComponentNameExists(ALREADY_EXIST, null, ComponentTypeEnum.SERVICE)).thenReturn(eitherCountExist);
genericService = setupGenericServiceMock();
Either<Resource, StorageOperationStatus> findLatestGeneric = Either.left(genericService);
@@ -292,7 +301,7 @@ public class ServiceBusinessLogicTest extends ComponentBusinessLogicMock {
}
private void testServiceNameAlreadyExists() {
- String serviceName = "alreadyExist";
+ String serviceName = ALREADY_EXIST;
Service serviceExccedsNameLimit = createServiceObject(false);
// 51 chars, the limit is 50
serviceExccedsNameLimit.setName(serviceName);
@@ -850,7 +859,7 @@ public class ServiceBusinessLogicTest extends ComponentBusinessLogicMock {
}
}
- private Component createNewService() {
+ private Component createNewComponent() {
Service service = new Service();
int listSize = 3;
@@ -877,6 +886,10 @@ public class ServiceBusinessLogicTest extends ComponentBusinessLogicMock {
return service;
}
+ private Service createNewService() {
+ return (Service)createNewComponent();
+ }
+
@Test
public void testDerivedFromGeneric() {
@@ -932,4 +945,126 @@ public class ServiceBusinessLogicTest extends ComponentBusinessLogicMock {
genericService.setToscaResourceName(GENERIC_SERVICE_NAME);
return genericService;
}
+
+ @Test
+ public void testValidateServiceNameDoesExistTest() {
+ when(toscaOperationFacade.validateComponentNameUniqueness(ALREADY_EXIST, null, ComponentTypeEnum.SERVICE))
+ .thenReturn(Either.left(true));
+ Either<Map<String, Boolean>, ResponseFormat> actionResponse =
+ bl.validateServiceNameExists(ALREADY_EXIST, user.getUserId());
+ Assert.assertTrue(actionResponse.isLeft());
+ Map<String,Boolean> result = actionResponse.left().value();
+ Assert.assertEquals(true, result.get(ServiceBusinessLogic.IS_VALID));
+ }
+
+ @Test
+ public void testValidateServiceNameDoesNotExist() {
+ when(toscaOperationFacade.validateComponentNameUniqueness(DOES_NOT_EXIST, null, ComponentTypeEnum.SERVICE))
+ .thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
+ Either<Map<String, Boolean>, ResponseFormat> actionResponse =
+ bl.validateServiceNameExists(DOES_NOT_EXIST, user.getUserId());
+ Assert.assertTrue(actionResponse.isRight());
+ ResponseFormat responseFormat = actionResponse.right().value();
+ Assert.assertEquals(HttpStatus.NOT_FOUND.value(), responseFormat.getStatus().intValue());
+ }
+
+ @Test
+ public void testAddPropertyServiceConsumptionServiceNotFound() {
+ Mockito.when(toscaOperationFacade.getToscaElement(Mockito.anyString())).thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
+
+ Either<Operation, ResponseFormat> operationEither =
+ bl.addPropertyServiceConsumption("1", "2", "3",
+ user.getUserId(), new ServiceConsumptionData());
+ Assert.assertTrue(operationEither.isRight());
+ Assert.assertEquals(HttpStatus.NOT_FOUND.value(), operationEither.right().value().getStatus().intValue());
+ }
+
+ @Test
+ public void testAddPropertyServiceConsumptionParentServiceIsEmpty() {
+ Either<Component, StorageOperationStatus> eitherService = Either.left(createServiceObject(true));
+ Mockito.when(toscaOperationFacade.getToscaElement(Mockito.anyString())).thenReturn(eitherService);
+
+ Either<Operation, ResponseFormat> operationEither =
+ bl.addPropertyServiceConsumption("1", "2", "3",
+ user.getUserId(), new ServiceConsumptionData());
+ Assert.assertTrue(operationEither.isRight());
+ Assert.assertEquals(HttpStatus.INTERNAL_SERVER_ERROR.value(), operationEither.right().value().getStatus().intValue());
+ }
+
+ @Test
+ public void testAddPropertyServiceConsumptionNoMatchingComponent() {
+ Service aService = createNewService();
+ Either<Component, StorageOperationStatus> eitherService = Either.left(aService);
+ Mockito.when(toscaOperationFacade.getToscaElement(Mockito.anyString())).thenReturn(eitherService);
+
+ String weirdUniqueServiceInstanceId = UUID.randomUUID().toString();
+
+ Either<Operation, ResponseFormat> operationEither =
+ bl.addPropertyServiceConsumption("1", weirdUniqueServiceInstanceId, "3",
+ user.getUserId(), new ServiceConsumptionData());
+ Assert.assertTrue(operationEither.isRight());
+ Assert.assertEquals(HttpStatus.INTERNAL_SERVER_ERROR.value(), operationEither.right().value().getStatus().intValue());
+ }
+
+ @Test
+ public void testAddPropertyServiceConsumptionNotComponentInstancesInterfacesOnParentService() {
+ Service aService = createNewService();
+ aService.getComponentInstances().get(0).setUniqueId(aService.getUniqueId());
+ Either<Component, StorageOperationStatus> eitherService = Either.left(aService);
+ Mockito.when(toscaOperationFacade.getToscaElement(Mockito.anyString())).thenReturn(eitherService);
+
+ Either<Operation, ResponseFormat> operationEither =
+ bl.addPropertyServiceConsumption("1", aService.getUniqueId(), "3",
+ user.getUserId(), new ServiceConsumptionData());
+ Assert.assertTrue(operationEither.isRight());
+ Assert.assertEquals(HttpStatus.INTERNAL_SERVER_ERROR.value(), operationEither.right().value().getStatus().intValue());
+ }
+
+ @Test
+ public void testAddPropertyServiceConsumptionInterfaceCandidateNotPresent() {
+ Service aService = createNewService();
+ aService.getComponentInstances().get(0).setUniqueId(aService.getUniqueId());
+ Either<Component, StorageOperationStatus> eitherService = Either.left(aService);
+ Mockito.when(toscaOperationFacade.getToscaElement(Mockito.anyString())).thenReturn(eitherService);
+
+ Map<String, List<ComponentInstanceInterface>> componentInstancesInterfacesMap =
+ Maps.newHashMap();
+ componentInstancesInterfacesMap.put(aService.getUniqueId(),
+ Lists.newArrayList(new ComponentInstanceInterface("1", new InterfaceInstanceDataDefinition())));
+
+ aService.setComponentInstancesInterfaces(componentInstancesInterfacesMap);
+
+ Either<Operation, ResponseFormat> operationEither =
+ bl.addPropertyServiceConsumption("1", aService.getUniqueId(), "3",
+ user.getUserId(), new ServiceConsumptionData());
+ Assert.assertTrue(operationEither.isRight());
+ Assert.assertEquals(HttpStatus.INTERNAL_SERVER_ERROR.value(), operationEither.right().value().getStatus().intValue());
+ }
+
+ @Test
+ public void testAddPropertyServiceConsumptionNoInputsCandidate() {
+ Service aService = createNewService();
+ aService.getComponentInstances().get(0).setUniqueId(aService.getUniqueId());
+ Either<Component, StorageOperationStatus> eitherService = Either.left(aService);
+ Mockito.when(toscaOperationFacade.getToscaElement(Mockito.anyString())).thenReturn(eitherService);
+
+ String operationId = "operationId";
+ ComponentInstanceInterface componentInstanceInterface =
+ new ComponentInstanceInterface("interfaceId", new InterfaceInstanceDataDefinition());
+ Map<String, Operation> operationsMap = Maps.newHashMap();
+ operationsMap.put(operationId, new Operation(new ArtifactDataDefinition(), "1",
+ new ListDataDefinition<>(), new ListDataDefinition<>()));
+ componentInstanceInterface.setOperationsMap(operationsMap);
+
+ Map<String, List<ComponentInstanceInterface>> componentInstancesInterfacesMap = Maps.newHashMap();
+ componentInstancesInterfacesMap.put(aService.getUniqueId(), Lists.newArrayList(componentInstanceInterface));
+ aService.setComponentInstancesInterfaces(componentInstancesInterfacesMap);
+
+ Either<Operation, ResponseFormat> operationEither =
+ bl.addPropertyServiceConsumption("1", aService.getUniqueId(), operationId,
+ user.getUserId(), new ServiceConsumptionData());
+ Assert.assertTrue(operationEither.isRight());
+ Assert.assertEquals(HttpStatus.NOT_FOUND.value(), operationEither.right().value().getStatus().intValue());
+ }
+
}