aboutsummaryrefslogtreecommitdiffstats
path: root/workflow-designer-be/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'workflow-designer-be/src/test')
-rw-r--r--workflow-designer-be/src/test/java/org/onap/sdc/workflow/api/WorkflowVersionControllerTest.java12
-rw-r--r--workflow-designer-be/src/test/java/org/onap/sdc/workflow/persistence/impl/ArtifactRepositoryTest.java29
-rw-r--r--workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/WorkflowManagerTest.java8
-rw-r--r--workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/WorkflowVersionManagerTest.java119
4 files changed, 141 insertions, 27 deletions
diff --git a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/api/WorkflowVersionControllerTest.java b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/api/WorkflowVersionControllerTest.java
index b77e11a2..d38261b7 100644
--- a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/api/WorkflowVersionControllerTest.java
+++ b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/api/WorkflowVersionControllerTest.java
@@ -26,6 +26,8 @@ import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.onap.sdc.workflow.RestPath;
import org.onap.sdc.workflow.api.impl.WorkflowVersionControllerImpl;
+import org.onap.sdc.workflow.api.types.VersionRequestDto;
+import org.onap.sdc.workflow.persistence.types.WorkflowVersion;
import org.onap.sdc.workflow.services.WorkflowVersionManager;
import org.openecomp.sdc.versioning.dao.types.Version;
import org.springframework.http.HttpStatus;
@@ -75,7 +77,7 @@ public class WorkflowVersionControllerTest {
@Test
public void shouldCreateWorkflowVersionWhenCallingVersionsPostREST() throws Exception {
- Version version = new Version();
+ VersionRequestDto version = new VersionRequestDto();
version.setDescription("VersionDescription");
mockMvc.perform(post(RestPath.getWorkflowVersions(ITEM1_ID)).header(RestConstants.USER_ID_HEADER_PARAM, USER_ID)
.contentType(APPLICATION_JSON)
@@ -88,18 +90,18 @@ public class WorkflowVersionControllerTest {
@Test
public void shouldReturnWorkflowVersionWhenExists() throws Exception {
- Version version = new Version(VERSION1_ID);
- doReturn(version).when(workflowVersionManagerMock).get(ITEM1_ID, version);
+ WorkflowVersion version = new WorkflowVersion(VERSION1_ID);
+ doReturn(version).when(workflowVersionManagerMock).get(ITEM1_ID, VERSION1_ID);
mockMvc.perform(
get(RestPath.getWorkflowVersion(ITEM1_ID, VERSION1_ID)).header(RestConstants.USER_ID_HEADER_PARAM, USER_ID)
.contentType(APPLICATION_JSON)).andDo(print())
.andExpect(status().isOk()).andExpect(jsonPath("$.id", is(version.getId())));
- verify(workflowVersionManagerMock, times(1)).get(ITEM1_ID, version);
+ verify(workflowVersionManagerMock, times(1)).get(ITEM1_ID, VERSION1_ID);
}
@Test
public void shouldUpdateWorkflowVersionWhenCallingPutREST() throws Exception {
- Version version = new Version();
+ WorkflowVersion version = new WorkflowVersion();
version.setDescription("Updated");
MockHttpServletResponse result = mockMvc.perform(
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
new file mode 100644
index 00000000..4bec8b97
--- /dev/null
+++ b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/persistence/impl/ArtifactRepositoryTest.java
@@ -0,0 +1,29 @@
+package org.onap.sdc.workflow.persistence.impl;
+
+import java.io.IOException;
+import org.junit.Test;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.openecomp.core.zusammen.api.ZusammenAdaptor;
+
+public class ArtifactRepositoryTest {
+
+ private static final String FILE_NAME_PROPERTY = "fileName";
+ private static final String EMPTY_DATA = "{}";
+ private static final String ITEM1_ID = "item_id_1";
+ private static final String VERSION1_ID = "version_id_1";
+
+
+ @Mock
+ private ZusammenAdaptor zusammenAdaptorMock;
+
+ @InjectMocks
+ private ArtifactRepositoryImpl artifactRepository;
+
+ @Test
+ public void shouldUpdateArtifact() throws IOException {
+
+ }
+
+
+}
diff --git a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/WorkflowManagerTest.java b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/WorkflowManagerTest.java
index 74097b1e..11c50cde 100644
--- a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/WorkflowManagerTest.java
+++ b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/WorkflowManagerTest.java
@@ -16,7 +16,7 @@ import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.onap.sdc.workflow.persistence.types.Workflow;
import org.onap.sdc.workflow.services.UniqueValueService;
-import org.onap.sdc.workflow.services.exceptions.WorkflowNotFoundException;
+import org.onap.sdc.workflow.services.exceptions.EntityNotFoundException;
import org.onap.sdc.workflow.services.mappers.WorkflowMapper;
import org.openecomp.sdc.versioning.ItemManager;
import org.openecomp.sdc.versioning.types.Item;
@@ -32,7 +32,7 @@ public class WorkflowManagerTest {
private List<Item> itemList;
@Mock
- WorkflowMapper workflowMapperMock;
+ private WorkflowMapper workflowMapperMock;
@Mock
private ItemManager itemManagerMock;
@@ -59,7 +59,7 @@ public class WorkflowManagerTest {
verify(itemManagerMock).list(WorkflowManagerImpl.ITEM_PREDICATE);
}
- @Test(expected = WorkflowNotFoundException.class)
+ @Test(expected = EntityNotFoundException.class)
public void shouldThrowExceptionWhenWorkflowDontExist() {
Workflow nonExistingWorkflow = new Workflow();
nonExistingWorkflow.setId(ITEM1_ID);
@@ -110,7 +110,7 @@ public class WorkflowManagerTest {
}
- @Test(expected = WorkflowNotFoundException.class)
+ @Test(expected = EntityNotFoundException.class)
public void shouldThrowExceptionWhenWorkflowToUpdateNotFound() {
doReturn(null).when(itemManagerMock).get(ITEM1_ID);
workflowManager.update(createWorkflow(1, true));
diff --git a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/WorkflowVersionManagerTest.java b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/WorkflowVersionManagerTest.java
index 75146e28..543ca82a 100644
--- a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/WorkflowVersionManagerTest.java
+++ b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/WorkflowVersionManagerTest.java
@@ -1,24 +1,41 @@
package org.onap.sdc.workflow.services.impl;
import static org.junit.Assert.assertEquals;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Matchers.any;
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.persistence.types.VersionStatus.*;
+import java.io.IOException;
+import java.io.InputStream;
import java.util.Arrays;
-import java.util.Collection;
+import java.util.Collections;
+import java.util.Date;
import java.util.List;
-import org.junit.Before;
+import java.util.Optional;
+import java.util.Set;
+import org.apache.commons.io.IOUtils;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Spy;
import org.mockito.junit.MockitoJUnitRunner;
-import org.onap.sdc.workflow.services.exceptions.VersionNotFoundException;
+import org.onap.sdc.workflow.api.types.VersionRequestDto;
+import org.onap.sdc.workflow.persistence.ArtifactRepository;
+import org.onap.sdc.workflow.persistence.types.ArtifactEntity;
+import org.onap.sdc.workflow.persistence.types.WorkflowVersion;
+import org.onap.sdc.workflow.services.exceptions.CreateVersionException;
+import org.onap.sdc.workflow.services.exceptions.EntityNotFoundException;
+import org.onap.sdc.workflow.services.mappers.VersionMapper;
import org.openecomp.sdc.versioning.VersioningManager;
import org.openecomp.sdc.versioning.dao.types.Version;
+import org.openecomp.sdc.versioning.dao.types.VersionStatus;
import org.openecomp.sdc.versioning.types.VersionCreationMethod;
+import org.springframework.mock.web.MockMultipartFile;
@RunWith(MockitoJUnitRunner.class)
public class WorkflowVersionManagerTest {
@@ -27,59 +44,125 @@ public class WorkflowVersionManagerTest {
private static final String ITEM1_ID = "item_id_1";
private static final String VERSION1_ID = "version_id_1";
private static final String VERSION2_ID = "version_id_2";
- private List<Version> versionList;
+
+ @Mock
+ private VersionMapper versionMapperMock;
@Mock
private VersioningManager versioningManagerMock;
+ @Mock
+ private ArtifactRepository artifactRepositoryMock;
+
@Spy
@InjectMocks
private WorkflowVersionManagerImpl workflowVersionManager;
- @Before
- public void setUp(){
- versionList = Arrays.asList( new Version(VERSION1_ID),new Version(VERSION2_ID));
- }
-
- @Test(expected = VersionNotFoundException.class)
+ @Test(expected = EntityNotFoundException.class)
public void shouldThrowExceptionWhenVersionDontExist(){
Version nonExistingVersion = new Version(VERSION1_ID);
doThrow(new RuntimeException()).when(versioningManagerMock).get(ITEM1_ID, nonExistingVersion);
- workflowVersionManager.get(ITEM1_ID, nonExistingVersion);
+ workflowVersionManager.get(ITEM1_ID, VERSION1_ID);
}
@Test
public void shouldReturnWorkflowVersionWhenExist(){
Version version = new Version(VERSION1_ID);
doReturn(version).when(versioningManagerMock).get(ITEM1_ID,version);
- workflowVersionManager.get(ITEM1_ID,version);
+ workflowVersionManager.get(ITEM1_ID,VERSION1_ID);
verify(versioningManagerMock).get(ITEM1_ID,version);
}
@Test
public void shouldReturnWorkflowVersionList(){
+ List<Version> versionList =
+ Arrays.asList(new Version(VERSION1_ID), new Version(VERSION2_ID));
+ versionList.forEach(version -> {
+ version.setBaseId("baseVersionId");
+ version.setDescription("Version description");
+ version.setName("name");
+ version.setCreationTime(new Date());
+ version.setModificationTime(new Date());
+ });
doReturn(versionList).when(versioningManagerMock).list(ITEM1_ID);
- Collection<Version> result = workflowVersionManager.list(ITEM1_ID);
+ workflowVersionManager.list(ITEM1_ID);
verify(versioningManagerMock).list(ITEM1_ID);
- assertEquals(versionList,result);
+ verify(versionMapperMock ,times(2)).versionToWorkflowVersion(any(Version.class));
}
@Test
public void shouldUpdateWorkflowVersion(){
Version version = new Version(VERSION1_ID);
- workflowVersionManager.update(ITEM1_ID,version);
+ version.setName("1.0");
+ version.setDescription("WorkflowVersion description");
+ WorkflowVersion workflowVersion = new WorkflowVersion(VERSION1_ID);
+ workflowVersion.setName("1.0");
+ workflowVersion.setDescription("WorkflowVersion description");
+ doReturn(version).when(workflowVersionManager).mapVersionInfo(ITEM1_ID,workflowVersion);
+ workflowVersionManager.update(ITEM1_ID,workflowVersion);
verify(versioningManagerMock).updateVersion(ITEM1_ID,version);
}
@Test
public void shouldCreateWorkflowVersion(){
- Version version = new Version();
- workflowVersionManager.create(ITEM1_ID,version);
+ Version version = new Version(VERSION1_ID);
+ version.setDescription("version desc");
+ doReturn(version).when(versioningManagerMock).create(ITEM1_ID,version, VersionCreationMethod.major);
+ VersionRequestDto workflowVersion = new VersionRequestDto();
+ workflowVersion.setDescription("version desc");
+ workflowVersionManager.create(ITEM1_ID,workflowVersion);
verify(versioningManagerMock).create(ITEM1_ID,version, VersionCreationMethod.major);
- verify(workflowVersionManager).getLatestVersion(ITEM1_ID);
+
+ }
+
+ @Test(expected = CreateVersionException.class)
+ public void shouldTrowExceptionWhenDraftVersionExists(){
+ VersionRequestDto versionRequestDto = new VersionRequestDto();
+ versionRequestDto.setBaseVersionId(VERSION2_ID);
+
+ 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,versionRequestDto);
+ }
+
+ @Test
+ public void shouldUploadArtifact() throws IOException {
+
+ String mockFileName = "filename.txt";
+ MockMultipartFile mockFile =
+ new MockMultipartFile("data", mockFileName, "text/plain", "some xml".getBytes());
+ WorkflowVersion version = new WorkflowVersion(VERSION1_ID);
+ version.setStatus(org.onap.sdc.workflow.persistence.types.VersionStatus.Draft);
+ doReturn(version).when(workflowVersionManager).get(ITEM1_ID,VERSION1_ID);
+ workflowVersionManager.uploadArtifact(ITEM1_ID,version,mockFile);
+
+ verify(artifactRepositoryMock).update(eq(ITEM1_ID),eq(VERSION1_ID),any(ArtifactEntity.class));
}
+ @Test(expected = EntityNotFoundException.class)
+ public void shouldThrowExceptionWhenArtifactNotFound(){
+ WorkflowVersion version = new WorkflowVersion(VERSION1_ID);
+ version.setStatus(Draft);
+ doReturn(version).when(workflowVersionManager).get(ITEM1_ID,VERSION1_ID);
+ doReturn(Optional.empty()).when(artifactRepositoryMock).get(ITEM1_ID,VERSION1_ID);
+ workflowVersionManager.getArtifact(ITEM1_ID,version);
+ }
+ @Test
+ public void shouldReturnArtifact() throws IOException {
+ WorkflowVersion version = new WorkflowVersion(VERSION1_ID);
+ doReturn(version).when(workflowVersionManager).get(ITEM1_ID,VERSION1_ID);
+
+ InputStream inputStreamMock =
+ IOUtils.toInputStream("some test data for my input stream", "UTF-8");
+ ArtifactEntity artifactMock = new ArtifactEntity("fileName.txt",inputStreamMock);
+ doReturn(Optional.of(artifactMock)).when(artifactRepositoryMock).get(ITEM1_ID,VERSION1_ID);
+ ArtifactEntity returnedArtifact = workflowVersionManager.getArtifact(ITEM1_ID, new WorkflowVersion(VERSION1_ID));
+ assertEquals(artifactMock,returnedArtifact);
+ }
}