diff options
author | talig <talig@amdocs.com> | 2018-07-15 15:41:31 +0300 |
---|---|---|
committer | talig <talig@amdocs.com> | 2018-07-15 15:41:31 +0300 |
commit | 39c01dd3ccb69f53d2e9350994e25f6e64412aa4 (patch) | |
tree | 35e083da4f89b54aa51c1188a36365096500dfdc /workflow-designer-be/src/test | |
parent | dfdaff5a207726a25a1625a4af88eaededd46a7c (diff) |
Get and update workflow version state
Remove redundant controller interfaces, rename WorkflowVersionStatus to State
Change-Id: I8ddc9cd656fc8bed607c68aa326c7fa7d2980116
Issue-ID: SDC-1503
Signed-off-by: talig <talig@amdocs.com>
Diffstat (limited to 'workflow-designer-be/src/test')
7 files changed, 291 insertions, 203 deletions
diff --git a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/api/WorkflowControllerTest.java b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/api/WorkflowControllerTest.java index d23d3f90..69b25b01 100644 --- a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/api/WorkflowControllerTest.java +++ b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/api/WorkflowControllerTest.java @@ -8,6 +8,7 @@ import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.onap.sdc.workflow.TestUtil.createWorkflow; +import static org.onap.sdc.workflow.api.RestConstants.USER_ID_HEADER_PARAM; import static org.springframework.http.MediaType.APPLICATION_JSON; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; @@ -25,7 +26,6 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; import org.onap.sdc.workflow.RestPath; -import org.onap.sdc.workflow.api.impl.WorkflowControllerImpl; import org.onap.sdc.workflow.persistence.types.Workflow; import org.onap.sdc.workflow.services.WorkflowManager; import org.openecomp.sdc.versioning.types.Item; @@ -42,13 +42,12 @@ public class WorkflowControllerTest { "Missing request header '%s' for method parameter of type String"; private static final String USER_ID = "userId"; private static final Gson GSON = new Gson(); - public static final String USER_ID_HEADER = "USER_ID"; private MockMvc mockMvc; @InjectMocks - private WorkflowControllerImpl workflowController; + private WorkflowController workflowController; @Mock private WorkflowManager workflowManagerMock; @@ -73,7 +72,7 @@ public class WorkflowControllerTest { Workflow workflowMock = createWorkflow(1, true); doReturn(workflowMock).when(workflowManagerMock).get(any(Workflow.class)); mockMvc.perform( - get(RestPath.getWorkflowPath(workflowMock.getId())).header(RestConstants.USER_ID_HEADER_PARAM, USER_ID) + get(RestPath.getWorkflowPath(workflowMock.getId())).header(USER_ID_HEADER_PARAM, USER_ID) .contentType(APPLICATION_JSON)).andDo(print()) .andExpect(status().isOk()).andExpect(jsonPath("$.id", is(workflowMock.getId()))) .andExpect(jsonPath("$.name", is(workflowMock.getName()))); @@ -84,7 +83,7 @@ public class WorkflowControllerTest { MockHttpServletResponse response = mockMvc.perform(get(RestPath.getWorkflowsPath()).contentType(APPLICATION_JSON)).andDo(print()) .andExpect(status().isBadRequest()).andExpect(status().is(400)).andReturn().getResponse(); - assertEquals(String.format(MISSING_REQUEST_HEADER_ERRROR_FORMAT, USER_ID_HEADER), response.getErrorMessage()); + assertEquals(String.format(MISSING_REQUEST_HEADER_ERRROR_FORMAT, USER_ID_HEADER_PARAM), response.getErrorMessage()); } @Test @@ -93,7 +92,7 @@ public class WorkflowControllerTest { List<Workflow> workflowMocks = createWorkflows(numOfWorkflows); doReturn(workflowMocks).when(workflowManagerMock).list(); mockMvc.perform( - get(RestPath.getWorkflowsPath()).header(RestConstants.USER_ID_HEADER_PARAM, USER_ID).contentType(APPLICATION_JSON)) + get(RestPath.getWorkflowsPath()).header(USER_ID_HEADER_PARAM, USER_ID).contentType(APPLICATION_JSON)) .andDo(print()).andExpect(status().isOk()).andExpect(jsonPath("$.results", hasSize(numOfWorkflows))); } @@ -103,7 +102,7 @@ public class WorkflowControllerTest { item.setId("abc"); Workflow reqWorkflow = createWorkflow(1, false); mockMvc.perform( - post(RestPath.getWorkflowsPath()).header(RestConstants.USER_ID_HEADER_PARAM, USER_ID).contentType(APPLICATION_JSON) + post(RestPath.getWorkflowsPath()).header(USER_ID_HEADER_PARAM, USER_ID).contentType(APPLICATION_JSON) .content(GSON.toJson(reqWorkflow))).andDo(print()).andExpect(status().isCreated()) .andExpect(MockMvcResultMatchers.content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)); verify(workflowManagerMock, times(1)).create(reqWorkflow); 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 d38261b7..75b132ad 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 @@ -25,7 +25,6 @@ import org.mockito.InjectMocks; 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; @@ -52,7 +51,7 @@ public class WorkflowVersionControllerTest { private WorkflowVersionManager workflowVersionManagerMock; @InjectMocks - private WorkflowVersionControllerImpl workflowVersionController; + private WorkflowVersionController workflowVersionController; @Before public void setUp() { 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/WorkflowManagerImplTest.java index 5173b063..3e228759 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/WorkflowManagerImplTest.java @@ -24,7 +24,7 @@ import org.openecomp.sdc.versioning.types.ItemStatus; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @RunWith(SpringJUnit4ClassRunner.class) -public class WorkflowManagerTest { +public class WorkflowManagerImplTest { private static final String ITEM1_ID = "workflowId1"; private static final String WORKFLOW_TYPE = "WORKFLOW"; 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 new file mode 100644 index 00000000..ae69b280 --- /dev/null +++ b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/WorkflowVersionManagerImplTest.java @@ -0,0 +1,258 @@ +package org.onap.sdc.workflow.services.impl; + +import static org.junit.Assert.assertEquals; +import static org.mockito.ArgumentMatchers.argThat; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.ArgumentMatchers.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.WorkflowVersionState.CERTIFIED; +import static org.onap.sdc.workflow.persistence.types.WorkflowVersionState.DRAFT; + +import java.io.IOException; +import java.io.InputStream; +import java.util.Arrays; +import java.util.Collections; +import java.util.Date; +import java.util.List; +import java.util.Optional; +import org.apache.commons.io.IOUtils; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.ArgumentCaptor; +import org.mockito.ArgumentMatcher; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnitRunner; +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.persistence.types.WorkflowVersionState; +import org.onap.sdc.workflow.services.exceptions.EntityNotFoundException; +import org.onap.sdc.workflow.services.exceptions.VersionCreationException; +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; +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 WorkflowVersionManagerImplTest { + + 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"; + + @Mock + private VersioningManager versioningManagerMock; + @Mock + private ArtifactRepository artifactRepositoryMock; + @Mock + private VersionMapper versionMapperMock; + @Mock + private VersionStateMapper versionStateMapperMock; + @InjectMocks + private WorkflowVersionManagerImpl workflowVersionManager; + + @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, VERSION1_ID); + } + + @Test + public void shouldReturnWorkflowVersionWhenExist() { + Version version = new Version(VERSION1_ID); + doReturn(version).when(versioningManagerMock).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); + workflowVersionManager.list(ITEM1_ID); + verify(versioningManagerMock).list(ITEM1_ID); + verify(versionMapperMock, times(2)).versionToWorkflowVersion(any(Version.class)); + } + + @Test + public void shouldUpdateWorkflowVersion() { + Version retrievedVersion = new Version(VERSION1_ID); + retrievedVersion.setName("1.0"); + retrievedVersion.setDescription("WorkflowVersion description"); + retrievedVersion.setStatus(VersionStatus.Draft); + doReturn(retrievedVersion).when(versioningManagerMock).get(eq(ITEM1_ID), eqVersion(VERSION1_ID)); + doReturn(DRAFT).when(versionStateMapperMock).versionStatusToWorkflowVersionState(retrievedVersion.getStatus()); + + WorkflowVersion inputVersion = new WorkflowVersion(VERSION1_ID); + inputVersion.setName("1.0"); + inputVersion.setDescription("WorkflowVersion description updated"); + + Version mappedInputVersion = new Version(VERSION1_ID); + mappedInputVersion.setName("1.0"); + mappedInputVersion.setDescription("WorkflowVersion description updated"); + doReturn(mappedInputVersion).when(versionMapperMock).workflowVersionToVersion(inputVersion); + + ArgumentCaptor<Version> versionArgCaptor = ArgumentCaptor.forClass(Version.class); + workflowVersionManager.update(ITEM1_ID, inputVersion); + + verify(versioningManagerMock).updateVersion(eq(ITEM1_ID), versionArgCaptor.capture()); + Version captorVersion = versionArgCaptor.getValue(); + assertEquals("1.0", captorVersion.getName()); + assertEquals("WorkflowVersion description updated", captorVersion.getDescription()); + assertEquals(VersionStatus.Draft, captorVersion.getStatus()); + verify(versioningManagerMock).publish(ITEM1_ID, mappedInputVersion, "Update version"); + } + + @Test + public void shouldCreateWorkflowVersion() { + 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); + + } + + @Test(expected = VersionCreationException.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(expected = EntityNotFoundException.class) + public void getStateOfNonExisting() { + doThrow(new RuntimeException()).when(versioningManagerMock).get(eq(ITEM1_ID), eqVersion(VERSION1_ID)); + workflowVersionManager.getState(ITEM1_ID, VERSION1_ID); + } + + @Test + public void getState() { + Version version = new Version(VERSION1_ID); + version.setStatus(VersionStatus.Certified); + doReturn(version).when(versioningManagerMock).get(eq(ITEM1_ID), eqVersion(VERSION1_ID)); + doReturn(CERTIFIED).when(versionStateMapperMock).versionStatusToWorkflowVersionState(version.getStatus()); + + WorkflowVersionState state = workflowVersionManager.getState(ITEM1_ID, VERSION1_ID); + assertEquals(CERTIFIED, state); + } + + @Test(expected = EntityNotFoundException.class) + public void updateStateOfNonExisting() { + doThrow(new RuntimeException()).when(versioningManagerMock).get(eq(ITEM1_ID), eqVersion(VERSION1_ID)); + workflowVersionManager.updateState(ITEM1_ID, VERSION1_ID, CERTIFIED); + } + + @Test(expected = VersionStateModificationException.class) + public void updateStateToCurrentState() { + Version version = new Version(VERSION1_ID); + version.setStatus(VersionStatus.Draft); + doReturn(version).when(versioningManagerMock).get(eq(ITEM1_ID), eqVersion(VERSION1_ID)); + doReturn(DRAFT).when(versionStateMapperMock).versionStatusToWorkflowVersionState(version.getStatus()); + + workflowVersionManager.updateState(ITEM1_ID, VERSION1_ID, DRAFT); + } + + @Test(expected = VersionStateModificationException.class) + public void updateStateWhenCertified() { + Version version = new Version(VERSION1_ID); + version.setStatus(VersionStatus.Certified); + doReturn(version).when(versioningManagerMock).get(eq(ITEM1_ID), eqVersion(VERSION1_ID)); + doReturn(CERTIFIED).when(versionStateMapperMock).versionStatusToWorkflowVersionState(version.getStatus()); + + workflowVersionManager.updateState(ITEM1_ID, VERSION1_ID, CERTIFIED); + } + + @Test + public void updateState() { + Version retrievedVersion = new Version(VERSION1_ID); + retrievedVersion.setStatus(VersionStatus.Draft); + doReturn(retrievedVersion).when(versioningManagerMock).get(eq(ITEM1_ID), eqVersion(VERSION1_ID)); + doReturn(DRAFT).when(versionStateMapperMock).versionStatusToWorkflowVersionState(VersionStatus.Draft); + doReturn(VersionStatus.Certified).when(versionStateMapperMock).workflowVersionStateToVersionStatus(CERTIFIED); + + ArgumentCaptor<Version> versionArgCaptor = ArgumentCaptor.forClass(Version.class); + workflowVersionManager.updateState(ITEM1_ID, VERSION1_ID, CERTIFIED); + + verify(versioningManagerMock).updateVersion(eq(ITEM1_ID), versionArgCaptor.capture()); + assertEquals(VersionStatus.Certified, versionArgCaptor.getValue().getStatus()); + verify(versioningManagerMock) + .publish(eq(ITEM1_ID), eqVersion(VERSION1_ID), eq("Update version state from DRAFT to CERTIFIED")); + } + + @Test + public void shouldUploadArtifact() { + Version version = new Version(VERSION1_ID); + version.setStatus(VersionStatus.Draft); + doReturn(version).when(versioningManagerMock).get(eq(ITEM1_ID), eqVersion(VERSION1_ID)); + doReturn(DRAFT).when(versionStateMapperMock).versionStatusToWorkflowVersionState(version.getStatus()); + + MockMultipartFile mockFile = new MockMultipartFile("data", "filename.txt", "text/plain", "some xml".getBytes()); + workflowVersionManager.uploadArtifact(ITEM1_ID, VERSION1_ID, mockFile); + + verify(artifactRepositoryMock).update(eq(ITEM1_ID), eq(VERSION1_ID), any(ArtifactEntity.class)); + } + + @Test(expected = EntityNotFoundException.class) + public void shouldThrowExceptionWhenArtifactNotFound() { + doReturn(new Version(VERSION1_ID)).when(versioningManagerMock).get(eq(ITEM1_ID), eqVersion(VERSION1_ID)); + + doReturn(Optional.empty()).when(artifactRepositoryMock).get(ITEM1_ID, VERSION1_ID); + workflowVersionManager.getArtifact(ITEM1_ID, VERSION1_ID); + } + + @Test + public void shouldReturnArtifact() throws IOException { + doReturn(new Version(VERSION1_ID)).when(versioningManagerMock).get(eq(ITEM1_ID), eqVersion(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, VERSION1_ID); + assertEquals(artifactMock, returnedArtifact); + } + + private static Version eqVersion(String versionId) { + return argThat(new EqVersion(versionId)); + } + + private static class EqVersion implements ArgumentMatcher<Version> { + + private final String versionId; + + EqVersion(String versionId) { + this.versionId = versionId; + } + + @Override + public boolean matches(Version version) { + return versionId.equals(version.getId()); + } + } + +} 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 deleted file mode 100644 index a82b5f3d..00000000 --- a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/WorkflowVersionManagerTest.java +++ /dev/null @@ -1,168 +0,0 @@ -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.WorkflowVersionStatus.*; - -import java.io.IOException; -import java.io.InputStream; -import java.util.Arrays; -import java.util.Collections; -import java.util.Date; -import java.util.List; -import java.util.Optional; -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.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.persistence.types.WorkflowVersionStatus; -import org.onap.sdc.workflow.services.exceptions.CreateVersionException; -import org.onap.sdc.workflow.services.exceptions.EntityNotFoundException; -import org.onap.sdc.workflow.services.impl.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 { - - - 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"; - - @Mock - private VersionMapper versionMapperMock; - - @Mock - private VersioningManager versioningManagerMock; - - @Mock - private ArtifactRepository artifactRepositoryMock; - - @Spy - @InjectMocks - private WorkflowVersionManagerImpl workflowVersionManager; - - - @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, VERSION1_ID); - } - - @Test - public void shouldReturnWorkflowVersionWhenExist(){ - Version version = new Version(VERSION1_ID); - doReturn(version).when(versioningManagerMock).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); - workflowVersionManager.list(ITEM1_ID); - verify(versioningManagerMock).list(ITEM1_ID); - verify(versionMapperMock ,times(2)).versionToWorkflowVersion(any(Version.class)); - } - - @Test - public void shouldUpdateWorkflowVersion(){ - Version version = new Version(VERSION1_ID); - 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(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); - - } - - @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(WorkflowVersionStatus.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); - } - -} diff --git a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/mappers/VersionMapperTest.java b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/mappers/VersionMapperTest.java index f9d65bd3..b778de47 100644 --- a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/mappers/VersionMapperTest.java +++ b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/mappers/VersionMapperTest.java @@ -6,7 +6,7 @@ import java.util.Date; import org.junit.Test; import org.junit.runner.RunWith; import org.onap.sdc.workflow.persistence.types.WorkflowVersion; -import org.onap.sdc.workflow.persistence.types.WorkflowVersionStatus; +import org.onap.sdc.workflow.persistence.types.WorkflowVersionState; import org.openecomp.sdc.versioning.dao.types.Version; import org.openecomp.sdc.versioning.dao.types.VersionStatus; import org.springframework.beans.factory.annotation.Autowired; @@ -20,7 +20,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; public class VersionMapperTest { @Configuration - @ComponentScan(basePackageClasses = {VersionMapper.class, VersionStatusMapper.class}) + @ComponentScan(basePackageClasses = {VersionMapper.class, VersionStateMapper.class}) public static class VersionMapperSpringTestConfig { } @Autowired @@ -73,7 +73,7 @@ public class VersionMapperTest { workflowVersion.setCreationTime(new Date()); workflowVersion.setModificationTime(new Date()); workflowVersion.setDescription("version_description"); - workflowVersion.setStatus(WorkflowVersionStatus.CERTIFIED); + workflowVersion.setState(WorkflowVersionState.CERTIFIED); return workflowVersion; } diff --git a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/mappers/VersionStatusMapperTest.java b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/mappers/VersionStateMapperTest.java index 0d4b6cd5..59d16289 100644 --- a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/mappers/VersionStatusMapperTest.java +++ b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/mappers/VersionStateMapperTest.java @@ -4,7 +4,7 @@ import static org.junit.Assert.assertEquals; import org.junit.Test; import org.junit.runner.RunWith; -import org.onap.sdc.workflow.persistence.types.WorkflowVersionStatus; +import org.onap.sdc.workflow.persistence.types.WorkflowVersionState; import org.openecomp.sdc.versioning.dao.types.VersionStatus; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.ComponentScan; @@ -12,64 +12,64 @@ import org.springframework.context.annotation.Configuration; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -@ContextConfiguration(classes = VersionStatusMapperTest.VersionStatusMapperSpringTestConfig.class) +@ContextConfiguration(classes = VersionStateMapperTest.VersionStatusMapperSpringTestConfig.class) @RunWith(SpringJUnit4ClassRunner.class) -public class VersionStatusMapperTest { +public class VersionStateMapperTest { @Configuration - @ComponentScan(basePackageClasses = {VersionStatusMapper.class}) + @ComponentScan(basePackageClasses = {VersionStateMapper.class}) public static class VersionStatusMapperSpringTestConfig { } @Autowired - VersionStatusMapper versionStatusMapper; + VersionStateMapper versionStateMapper; @Test public void shouldMapCertifiedVersionStatusToWorkflowVersionStatus() { - WorkflowVersionStatus mappedVersionStatus = - versionStatusMapper.versionStatusToWorkflowVersionStatus(VersionStatus.Certified); - assertEquals(WorkflowVersionStatus.CERTIFIED, mappedVersionStatus); + WorkflowVersionState mappedVersionStatus = + versionStateMapper.versionStatusToWorkflowVersionState(VersionStatus.Certified); + assertEquals(WorkflowVersionState.CERTIFIED, mappedVersionStatus); } @Test public void shouldMapDraftVersionStatusToWorkflowVersionStatus() { - WorkflowVersionStatus mappedVersionStatus = - versionStatusMapper.versionStatusToWorkflowVersionStatus(VersionStatus.Draft); - assertEquals(WorkflowVersionStatus.DRAFT, mappedVersionStatus); + WorkflowVersionState mappedVersionStatus = + versionStateMapper.versionStatusToWorkflowVersionState(VersionStatus.Draft); + assertEquals(WorkflowVersionState.DRAFT, mappedVersionStatus); } @Test public void shouldMapDeletedVersionStatusToWorkflowVersionStatus() { - WorkflowVersionStatus mappedVersionStatus = - versionStatusMapper.versionStatusToWorkflowVersionStatus(VersionStatus.Deleted); - assertEquals(WorkflowVersionStatus.DRAFT, mappedVersionStatus); + WorkflowVersionState mappedVersionStatus = + versionStateMapper.versionStatusToWorkflowVersionState(VersionStatus.Deleted); + assertEquals(WorkflowVersionState.DRAFT, mappedVersionStatus); } @Test public void shouldMapLockedVersionStatusToWorkflowVersionStatus() { - WorkflowVersionStatus mappedVersionStatus = - versionStatusMapper.versionStatusToWorkflowVersionStatus(VersionStatus.Locked); - assertEquals(WorkflowVersionStatus.DRAFT, mappedVersionStatus); + WorkflowVersionState mappedVersionStatus = + versionStateMapper.versionStatusToWorkflowVersionState(VersionStatus.Locked); + assertEquals(WorkflowVersionState.DRAFT, mappedVersionStatus); } @Test public void shouldMapDeprecatedVersionStatusToWorkflowVersionStatus() { - WorkflowVersionStatus mappedVersionStatus = - versionStatusMapper.versionStatusToWorkflowVersionStatus(VersionStatus.Deprecated); - assertEquals(WorkflowVersionStatus.DRAFT, mappedVersionStatus); + WorkflowVersionState mappedVersionStatus = + versionStateMapper.versionStatusToWorkflowVersionState(VersionStatus.Deprecated); + assertEquals(WorkflowVersionState.DRAFT, mappedVersionStatus); } @Test public void shouldMapCertifiedWorkflowVersionStatusToVersionStatus() { VersionStatus mappedVersionStatus = - versionStatusMapper.workflowVersionStatusToVersionStatus(WorkflowVersionStatus.CERTIFIED); + versionStateMapper.workflowVersionStateToVersionStatus(WorkflowVersionState.CERTIFIED); assertEquals(VersionStatus.Certified, mappedVersionStatus); } @Test public void shouldMapDraftWorkflowVersionStatusToVersionStatus() { VersionStatus mappedVersionStatus = - versionStatusMapper.workflowVersionStatusToVersionStatus(WorkflowVersionStatus.DRAFT); + versionStateMapper.workflowVersionStateToVersionStatus(WorkflowVersionState.DRAFT); assertEquals(VersionStatus.Draft, mappedVersionStatus); } } |