aboutsummaryrefslogtreecommitdiffstats
path: root/workflow-designer-be
diff options
context:
space:
mode:
authorayalaben <ayala.benzvi@amdocs.com>2018-10-08 14:43:06 +0300
committerOren Kleks <orenkle@amdocs.com>2018-10-14 04:44:15 +0000
commit09bf44f072107e1e0c9dff8cf948b1c589265dd6 (patch)
treece97a42c06ae29ebd517238b2d32d6bf183b561e /workflow-designer-be
parentbb1a685f4454e87ff5ba3bc55d0d2965ccd2086e (diff)
Unit Test coverage
Change-Id: Icc8453823906f89603862ad60a8dd3273936ebce Issue-ID: SDC-1822 Signed-off-by: ayalaben <ayala.benzvi@amdocs.com>
Diffstat (limited to 'workflow-designer-be')
-rw-r--r--workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/impl/ParameterRepositoryImpl.java6
-rw-r--r--workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/ParameterEntity.java6
-rw-r--r--workflow-designer-be/src/test/java/org/onap/sdc/workflow/persistence/impl/ArtifactRepositoryTest.java33
-rw-r--r--workflow-designer-be/src/test/java/org/onap/sdc/workflow/persistence/impl/ParameterRepositoryTest.java34
-rw-r--r--workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/WorkflowVersionManagerImplTest.java110
5 files changed, 174 insertions, 15 deletions
diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/impl/ParameterRepositoryImpl.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/impl/ParameterRepositoryImpl.java
index 483c7097..00dadead 100644
--- a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/impl/ParameterRepositoryImpl.java
+++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/impl/ParameterRepositoryImpl.java
@@ -32,11 +32,11 @@ import java.util.Collection;
import java.util.Optional;
import java.util.stream.Collectors;
import org.onap.sdc.workflow.persistence.ParameterRepository;
-import org.onap.sdc.workflow.persistence.types.ParameterEntity;
import org.onap.sdc.workflow.persistence.impl.types.ParameterPropertyName;
+import org.onap.sdc.workflow.persistence.impl.types.WorkflowElementType;
+import org.onap.sdc.workflow.persistence.types.ParameterEntity;
import org.onap.sdc.workflow.persistence.types.ParameterRole;
import org.onap.sdc.workflow.persistence.types.ParameterType;
-import org.onap.sdc.workflow.persistence.impl.types.WorkflowElementType;
import org.openecomp.core.zusammen.api.ZusammenAdaptor;
import org.openecomp.types.ElementPropertyName;
import org.springframework.beans.factory.annotation.Autowired;
@@ -86,7 +86,7 @@ public class ParameterRepositoryImpl implements ParameterRepository {
zusammenAdaptor.getElementInfoByName(context, elementContext, null, getParentElementType(role));
if (!optionalParentElement.isPresent()) {
- return;
+ throw new IllegalStateException(String.format("Missing data for workflow id %s version id %s",id,versionId));
}
ZusammenElement parentElement = buildElement(optionalParentElement.get().getId(), Action.IGNORE);
parentElement.setSubElements(optionalParentElement.get().getSubElements().stream()
diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/ParameterEntity.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/ParameterEntity.java
index 4b57ba71..4dfd1e4f 100644
--- a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/ParameterEntity.java
+++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/ParameterEntity.java
@@ -17,12 +17,18 @@
package org.onap.sdc.workflow.persistence.types;
import lombok.Data;
+import lombok.NoArgsConstructor;
@Data
+@NoArgsConstructor
public class ParameterEntity {
private String id;
private String name;
private ParameterType type;
private boolean mandatory;
+
+ public ParameterEntity(String name) {
+ this.name = name;
+ }
}
diff --git a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/persistence/impl/ArtifactRepositoryTest.java b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/persistence/impl/ArtifactRepositoryTest.java
index 9d202fce..df65909a 100644
--- a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/persistence/impl/ArtifactRepositoryTest.java
+++ b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/persistence/impl/ArtifactRepositoryTest.java
@@ -1,6 +1,7 @@
package org.onap.sdc.workflow.persistence.impl;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Matchers.any;
@@ -10,11 +11,13 @@ import static org.mockito.Mockito.verify;
import static org.openecomp.core.zusammen.api.ZusammenUtil.buildStructuralElement;
import com.amdocs.zusammen.adaptor.inbound.api.types.item.Element;
+import com.amdocs.zusammen.adaptor.inbound.api.types.item.ElementInfo;
import com.amdocs.zusammen.adaptor.inbound.api.types.item.ZusammenElement;
import com.amdocs.zusammen.datatypes.Id;
import com.amdocs.zusammen.datatypes.SessionContext;
import com.amdocs.zusammen.datatypes.item.Action;
import com.amdocs.zusammen.datatypes.item.ElementContext;
+import com.amdocs.zusammen.datatypes.item.Info;
import java.io.IOException;
import java.io.InputStream;
import java.util.Optional;
@@ -82,6 +85,19 @@ public class ArtifactRepositoryTest {
}
@Test
+ public void shouldReturnOptionalEmptyWhenDoesNotExist() throws IOException {
+
+ doReturn(Optional.empty()).when(zusammenAdaptorMock)
+ .getElementByName(any(SessionContext.class), any(ElementContext.class), isNull(Id.class),
+ eq(WorkflowElementType.ARTIFACT.name()));
+
+ Optional<ArtifactEntity> result = artifactRepository.get(ITEM1_ID, VERSION1_ID);
+ verify(zusammenAdaptorMock).getElementByName(any(SessionContext.class), any(ElementContext.class), isNull(Id.class),
+ eq(WorkflowElementType.ARTIFACT.name()));
+ assertFalse(result.isPresent());
+ }
+
+ @Test
public void shouldCreateArtifactStructure() {
artifactRepository.createStructure(ITEM1_ID, VERSION1_ID);
verify(zusammenAdaptorMock)
@@ -90,10 +106,25 @@ public class ArtifactRepositoryTest {
}
@Test
- public void shouldDeleteArtifact(){
+ public void shouldDeleteArtifact() {
artifactRepository.delete(ITEM1_ID,VERSION1_ID);
verify(zusammenAdaptorMock).saveElement(any(SessionContext.class), any(ElementContext.class), any(ZusammenElement.class),
eq("Delete WorkflowVersion Artifact Data"));
}
+ @Test
+ public void shouldReturnTrueIfExists() {
+ ElementInfo elementInfo = new ElementInfo();
+ elementInfo.setId(new Id("test_id"));
+ Info info = new Info();
+ info.addProperty(FILE_NAME_PROPERTY, "test_fileName");
+ elementInfo.setInfo(info);
+
+ doReturn(Optional.of(elementInfo)).when(zusammenAdaptorMock)
+ .getElementInfoByName(any(SessionContext.class), any(ElementContext.class), isNull(),
+ eq(WorkflowElementType.ARTIFACT.name()));
+
+ assertTrue(artifactRepository.isExist(ITEM1_ID, VERSION1_ID));
+ }
+
}
diff --git a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/persistence/impl/ParameterRepositoryTest.java b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/persistence/impl/ParameterRepositoryTest.java
index 546a3fe6..771a4b77 100644
--- a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/persistence/impl/ParameterRepositoryTest.java
+++ b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/persistence/impl/ParameterRepositoryTest.java
@@ -25,11 +25,11 @@ import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Spy;
import org.mockito.junit.MockitoJUnitRunner;
-import org.onap.sdc.workflow.persistence.types.ParameterEntity;
import org.onap.sdc.workflow.persistence.impl.types.ParameterPropertyName;
+import org.onap.sdc.workflow.persistence.impl.types.WorkflowElementType;
+import org.onap.sdc.workflow.persistence.types.ParameterEntity;
import org.onap.sdc.workflow.persistence.types.ParameterRole;
import org.onap.sdc.workflow.persistence.types.ParameterType;
-import org.onap.sdc.workflow.persistence.impl.types.WorkflowElementType;
import org.openecomp.core.zusammen.api.ZusammenAdaptor;
import org.openecomp.sdc.common.session.SessionContextProviderFactory;
@@ -163,4 +163,34 @@ public class ParameterRepositoryTest {
eq("Delete all INPUT"));
}
+ @Test(expected = IllegalStateException.class)
+ public void shouldFailIfParentElementDoesNotExist() {
+ doReturn(Optional.empty()).when(zusammenAdaptorMock)
+ .getElementInfoByName(any(SessionContext.class), any(ElementContext.class), isNull(),
+ eq(WorkflowElementType.INPUTS.name()));
+ parameterRepository.deleteAll(ITEM1_ID, VERSION1_ID, ParameterRole.INPUT);
+ }
+
+ @Test
+ public void shouldCreateParameter() {
+ ZusammenElement zusammenParentElement = new ZusammenElement();
+ zusammenParentElement.setElementId(new Id(PARAMETERS_PARENT_ID));
+ ZusammenElement zusammenElement = new ZusammenElement();
+ zusammenElement.setElementId(new Id(PARAMETER1_ID));
+ zusammenParentElement.addSubElement(zusammenElement);
+ doReturn(zusammenParentElement).when(zusammenAdaptorMock)
+ .saveElement(any(SessionContext.class), any(ElementContext.class),
+ any(ZusammenElement.class), eq("Create WorkflowVersion Parameter Element"));
+ ParameterEntity parameterEntity = new ParameterEntity("test_input_parameter");
+ parameterEntity.setType(ParameterType.INTEGER);
+ parameterEntity.setMandatory(true);
+
+ ParameterEntity returnedParameter =
+ parameterRepository.create(ITEM1_ID, VERSION1_ID, ParameterRole.INPUT, parameterEntity);
+ verify(zusammenAdaptorMock)
+ .saveElement(any(SessionContext.class), any(ElementContext.class), any(ZusammenElement.class),
+ eq("Create WorkflowVersion Parameter Element"));
+ assertEquals(PARAMETER1_ID, returnedParameter.getId());
+ }
+
}
diff --git a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/WorkflowVersionManagerImplTest.java b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/WorkflowVersionManagerImplTest.java
index 57829875..8b09e15d 100644
--- a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/WorkflowVersionManagerImplTest.java
+++ b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/WorkflowVersionManagerImplTest.java
@@ -1,12 +1,14 @@
package org.onap.sdc.workflow.services.impl;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.argThat;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.doThrow;
+import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.onap.sdc.workflow.services.types.WorkflowVersionState.CERTIFIED;
import static org.onap.sdc.workflow.services.types.WorkflowVersionState.DRAFT;
@@ -14,9 +16,12 @@ import static org.onap.sdc.workflow.services.types.WorkflowVersionState.DRAFT;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
+import java.util.Set;
import org.apache.commons.io.IOUtils;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -28,9 +33,11 @@ import org.mockito.junit.MockitoJUnitRunner;
import org.onap.sdc.workflow.persistence.ArtifactRepository;
import org.onap.sdc.workflow.persistence.ParameterRepository;
import org.onap.sdc.workflow.persistence.types.ArtifactEntity;
+import org.onap.sdc.workflow.persistence.types.ParameterEntity;
import org.onap.sdc.workflow.persistence.types.ParameterRole;
import org.onap.sdc.workflow.services.exceptions.EntityNotFoundException;
import org.onap.sdc.workflow.services.exceptions.VersionCreationException;
+import org.onap.sdc.workflow.services.exceptions.VersionModificationException;
import org.onap.sdc.workflow.services.exceptions.VersionStateModificationException;
import org.onap.sdc.workflow.services.impl.mappers.VersionMapper;
import org.onap.sdc.workflow.services.impl.mappers.VersionStateMapper;
@@ -41,6 +48,7 @@ import org.openecomp.sdc.versioning.dao.types.Version;
import org.openecomp.sdc.versioning.dao.types.VersionState;
import org.openecomp.sdc.versioning.dao.types.VersionStatus;
import org.openecomp.sdc.versioning.types.VersionCreationMethod;
+import org.springframework.boot.test.autoconfigure.web.client.RestClientTest;
import org.springframework.mock.web.MockMultipartFile;
@RunWith(MockitoJUnitRunner.class)
@@ -77,21 +85,60 @@ public class WorkflowVersionManagerImplTest {
WorkflowVersion workflowVersion = new WorkflowVersion(VERSION1_ID);
doReturn(workflowVersion).when(versionMapperMock).versionToWorkflowVersion(any(Version.class));
doReturn(version).when(versioningManagerMock).get(eq(ITEM1_ID), any(Version.class));
- doReturn(new ArrayList()).when(parameterRepositoryMock)
+ doReturn(Collections.emptyList()).when(parameterRepositoryMock)
.list(eq(ITEM1_ID), eq(VERSION1_ID), any(ParameterRole.class));
workflowVersionManager.get(ITEM1_ID, VERSION1_ID);
verify(versioningManagerMock).get(ITEM1_ID, version);
}
-/* @Test
+ @Test
public void shouldReturnWorkflowVersionList() {
- List<Version> versionList = Arrays.asList(new Version(VERSION1_ID), new Version(VERSION2_ID));
+ Version version1 = new Version(VERSION1_ID);
+ Version version2 = new Version(VERSION2_ID);
+ List<Version> versionList = Arrays.asList(version1,version2);
doReturn(versionList).when(versioningManagerMock).list(ITEM1_ID);
- doReturn(new WorkflowVersion()).when(versionMapperMock).versionToWorkflowVersion(any(Version.class));
+ WorkflowVersion workflowVersion1 = new WorkflowVersion();
+ workflowVersion1.setId(VERSION1_ID);
+ workflowVersion1.setName(VERSION1_ID);
+ WorkflowVersion workflowVersion2 = new WorkflowVersion();
+ workflowVersion2.setId(VERSION2_ID);
+ workflowVersion2.setName(VERSION2_ID);
+ doReturn(workflowVersion2).when(versionMapperMock).versionToWorkflowVersion(version2);
+ doReturn(Collections.emptyList()).when(parameterRepositoryMock).list(eq(ITEM1_ID),anyString(),eq(ParameterRole.INPUT));
+ doReturn(Collections.emptyList()).when(parameterRepositoryMock).list(eq(ITEM1_ID),anyString(),eq(ParameterRole.OUTPUT));
workflowVersionManager.list(ITEM1_ID, null);
verify(versioningManagerMock).list(ITEM1_ID);
verify(versionMapperMock, times(2)).versionToWorkflowVersion(any(Version.class));
- }*/
+ }
+
+ @Test
+ public void shouldReturnCertifiedWorkflowVersionList() {
+ Version version1 = new Version(VERSION1_ID);
+ version1.setStatus(VersionStatus.Certified);
+ Version version2 = new Version(VERSION2_ID);
+ version2.setStatus(VersionStatus.Draft);
+ List<Version> versionList = Arrays.asList(version1, version2);
+ doReturn(versionList).when(versioningManagerMock).list(ITEM1_ID);
+ WorkflowVersion workflowVersion1 = new WorkflowVersion();
+ workflowVersion1.setId(VERSION1_ID);
+ workflowVersion1.setName(VERSION1_ID);
+ WorkflowVersion workflowVersion2 = new WorkflowVersion();
+ workflowVersion2.setId(VERSION2_ID);
+ workflowVersion2.setName(VERSION2_ID);
+ doReturn(workflowVersion1).when(versionMapperMock).versionToWorkflowVersion(version1);
+ doReturn(Collections.emptyList()).when(parameterRepositoryMock)
+ .list(eq(ITEM1_ID), anyString(), eq(ParameterRole.INPUT));
+ doReturn(Collections.emptyList()).when(parameterRepositoryMock)
+ .list(eq(ITEM1_ID), anyString(), eq(ParameterRole.OUTPUT));
+ doReturn(VersionStatus.Certified).when(versionStateMapperMock)
+ .workflowVersionStateToVersionStatus(
+ WorkflowVersionState.CERTIFIED);
+
+ assertEquals(1, workflowVersionManager.list(ITEM1_ID, Collections.singleton(WorkflowVersionState.CERTIFIED)).size());
+ verify(versioningManagerMock).list(ITEM1_ID);
+ verify(versionMapperMock, times(1)).versionToWorkflowVersion(any(Version.class));
+
+ }
@Test
public void shouldUpdateWorkflowVersion() {
@@ -109,8 +156,15 @@ public class WorkflowVersionManagerImplTest {
WorkflowVersion inputVersion = new WorkflowVersion(VERSION1_ID);
inputVersion.setName("1.0");
inputVersion.setDescription(updatedDescription);
- inputVersion.setInputs(new ArrayList<>());
- inputVersion.setOutputs(new ArrayList<>());
+ ParameterEntity toBeCreated = new ParameterEntity("Input1");
+ inputVersion.setInputs(Collections.singleton(toBeCreated));
+ ParameterEntity toBeUpdated = new ParameterEntity("Output1");
+ inputVersion.setOutputs(Collections.singleton(toBeUpdated));
+ doReturn(Collections.emptyList()).when(parameterRepositoryMock).list(ITEM1_ID,VERSION1_ID,ParameterRole.INPUT);
+ ParameterEntity toBeDeleted = new ParameterEntity("Output2");
+ toBeDeleted.setId("parameter_id_1");
+ Collection<ParameterEntity> currentOutputs = Arrays.asList(toBeDeleted, toBeUpdated);
+ doReturn(currentOutputs).when(parameterRepositoryMock).list(ITEM1_ID,VERSION1_ID,ParameterRole.OUTPUT);
Version mappedInputVersion = new Version(VERSION1_ID);
mappedInputVersion.setName("1.0");
@@ -126,6 +180,11 @@ public class WorkflowVersionManagerImplTest {
assertEquals(updatedDescription, captorVersion.getDescription());
assertEquals(VersionStatus.Draft, captorVersion.getStatus());
verify(versioningManagerMock).publish(ITEM1_ID, mappedInputVersion, "Update version");
+
+ verify(parameterRepositoryMock).delete(ITEM1_ID,VERSION1_ID,"parameter_id_1");
+ verify(parameterRepositoryMock).create(ITEM1_ID,VERSION1_ID,ParameterRole.INPUT,toBeCreated);
+ verify(parameterRepositoryMock).update(ITEM1_ID,VERSION1_ID,ParameterRole.OUTPUT,toBeUpdated);
+
}
@@ -136,8 +195,8 @@ public class WorkflowVersionManagerImplTest {
doReturn(version).when(versioningManagerMock).create(ITEM1_ID, version, VersionCreationMethod.major);
WorkflowVersion versionRequest = new WorkflowVersion();
versionRequest.setDescription("version desc");
- versionRequest.setInputs(new ArrayList<>());
- versionRequest.setOutputs(new ArrayList<>());
+ versionRequest.setInputs(Collections.emptyList());
+ versionRequest.setOutputs(Collections.emptyList());
WorkflowVersion workflowVersion = new WorkflowVersion(VERSION1_ID);
doReturn(workflowVersion).when(workflowVersionManager).get(ITEM1_ID, VERSION1_ID);
workflowVersionManager.create(ITEM1_ID, null, versionRequest);
@@ -156,6 +215,18 @@ public class WorkflowVersionManagerImplTest {
workflowVersionManager.create(ITEM1_ID, VERSION2_ID, versionRequestDto);
}
+ @Test(expected = VersionCreationException.class)
+ public void shouldTrowExceptionWhenInputsSupplied() {
+ WorkflowVersion versionRequestDto = new WorkflowVersion();
+ versionRequestDto.setInputs(Collections.singleton(new ParameterEntity()));
+ Version baseVersion = new Version(VERSION2_ID);
+ baseVersion.setStatus(VersionStatus.Draft);
+ List<Version> versions = Collections.singletonList(baseVersion);
+ doReturn(versions).when(versioningManagerMock).list(ITEM1_ID);
+
+ workflowVersionManager.create(ITEM1_ID, VERSION2_ID, versionRequestDto);
+ }
+
@Test(expected = EntityNotFoundException.class)
public void getStateOfNonExisting() {
doThrow(new RuntimeException()).when(versioningManagerMock).get(eq(ITEM1_ID), eqVersion(VERSION1_ID));
@@ -248,6 +319,27 @@ public class WorkflowVersionManagerImplTest {
assertEquals(artifactMock, returnedArtifact);
}
+ @Test(expected = VersionModificationException.class)
+ public void shouldThrowExceptionInDeleteArtifactWhenVersionIsCertified() {
+ Version version = new Version(VERSION1_ID);
+ doReturn(version).when(versioningManagerMock).get(ITEM1_ID,version);
+ WorkflowVersion workflowVersion = new WorkflowVersion(VERSION1_ID);
+ workflowVersion.setState(WorkflowVersionState.CERTIFIED);
+ doReturn(workflowVersion).when(versionMapperMock).versionToWorkflowVersion(version);
+ workflowVersionManager.deleteArtifact(ITEM1_ID,VERSION1_ID);
+ }
+
+ @Test
+ public void shouldDeleteArtifact() {
+ Version version = new Version(VERSION1_ID);
+ doReturn(version).when(versioningManagerMock).get(ITEM1_ID,version);
+ WorkflowVersion workflowVersion = new WorkflowVersion(VERSION1_ID);
+ doReturn(workflowVersion).when(versionMapperMock).versionToWorkflowVersion(version);
+ workflowVersionManager.deleteArtifact(ITEM1_ID,VERSION1_ID);
+ verify(artifactRepositoryMock).delete(ITEM1_ID,VERSION1_ID);
+ verify(versioningManagerMock).publish(ITEM1_ID,version,"Delete Artifact");
+ }
+
private static Version eqVersion(String versionId) {
return argThat(version -> versionId.equals(version.getId()));
}