diff options
author | 2018-07-16 19:25:05 +0530 | |
---|---|---|
committer | 2018-07-16 19:25:07 +0530 | |
commit | 7e78cd19bbb2b0730fafc0b328a71c69f5730e16 (patch) | |
tree | 24b4b72ef67f64304bfee867076517c37896db5b /workflow-designer-be/src/test | |
parent | 39c01dd3ccb69f53d2e9350994e25f6e64412aa4 (diff) |
Workflow Docker containers
1. Implemented workflow init container.
2. Implemented workflow backend container.
3. Added a placeholder for frontend module container.
4. Modifiled directory structure and POM files.
5. Added a ReadMe with sample commands to detail how to run the containers.
Change-Id: Ib110fcc104ce72ff28fce514a1475a032cc2d82b
Issue-ID: SDC-1482
Signed-off-by: priyanshu <pagarwal@amdocs.com>
Signed-off-by: vempo <vitaliy.emporopulo@amdocs.com>
Signed-off-by: priyanshu <pagarwal@amdocs.com>
Diffstat (limited to 'workflow-designer-be/src/test')
11 files changed, 0 insertions, 1010 deletions
diff --git a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/RestPath.java b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/RestPath.java deleted file mode 100644 index 266ca91b..00000000 --- a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/RestPath.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.onap.sdc.workflow; - -public class RestPath { - private static final String WORKFLOWS_URL = "/workflows"; - private static final String WORKFLOW_URL_FORMATTER = WORKFLOWS_URL + "/%s"; - private static final String VERSIONS_URL_FORMATTER = WORKFLOWS_URL + "/%s/versions"; - private static final String VERSION_URL_FORMATTER = WORKFLOWS_URL + "/%s/versions/%s"; - - public static String getWorkflowsPath(){ - return WORKFLOWS_URL; - } - - public static String getWorkflowPath(String workflowId){ - return String.format(WORKFLOW_URL_FORMATTER, workflowId); - } - - public static String getWorkflowVersions(String workflowId){ - return String.format(VERSIONS_URL_FORMATTER, workflowId); - } - - public static String getWorkflowVersion(String workflowId, String versionId){ - return String.format(VERSION_URL_FORMATTER, workflowId, versionId); - } -} diff --git a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/TestUtil.java b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/TestUtil.java deleted file mode 100644 index 47ce060b..00000000 --- a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/TestUtil.java +++ /dev/null @@ -1,38 +0,0 @@ -package org.onap.sdc.workflow; - -import org.onap.sdc.workflow.persistence.types.Workflow; -import org.openecomp.sdc.versioning.types.Item; - -public class TestUtil { - - private static final String WORKFLOW_TYPE = "WORKFLOW"; - - public static Workflow createWorkflow(int workflowPropertySuffix, boolean createId) { - Workflow workflow = new Workflow(); - if (createId) { - workflow.setId("workflowId" + workflowPropertySuffix); - } - workflow.setName("workflowName" + workflowPropertySuffix); - workflow.setDescription("workflowDesc" + workflowPropertySuffix); - - return workflow; - } - - public static Item createItem(int itemNum,boolean setType, boolean setId){ - Item item = new Item(); - if(setId) { - item.setId("workflowId" + itemNum); - } - item.addProperty("category","category_" + itemNum); - item.setName("Workflow_" + itemNum); - item.setDescription("Description_" + itemNum); - if(setType) { - item.setType(WORKFLOW_TYPE); - } - - return item; - } - - - -} 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 deleted file mode 100644 index 69b25b01..00000000 --- a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/api/WorkflowControllerTest.java +++ /dev/null @@ -1,121 +0,0 @@ -package org.onap.sdc.workflow.api; - -import static org.hamcrest.Matchers.is; -import static org.hamcrest.collection.IsCollectionWithSize.hasSize; -import static org.junit.Assert.assertEquals; -import static org.mockito.ArgumentMatchers.any; -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; -import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; - -import com.google.gson.Gson; -import java.util.ArrayList; -import java.util.List; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; -import org.onap.sdc.workflow.RestPath; -import org.onap.sdc.workflow.persistence.types.Workflow; -import org.onap.sdc.workflow.services.WorkflowManager; -import org.openecomp.sdc.versioning.types.Item; -import org.springframework.http.MediaType; -import org.springframework.mock.web.MockHttpServletResponse; -import org.springframework.test.web.servlet.MockMvc; -import org.springframework.test.web.servlet.result.MockMvcResultMatchers; -import org.springframework.test.web.servlet.setup.MockMvcBuilders; - -@RunWith(MockitoJUnitRunner.class) -public class WorkflowControllerTest { - - private static final String MISSING_REQUEST_HEADER_ERRROR_FORMAT = - "Missing request header '%s' for method parameter of type String"; - private static final String USER_ID = "userId"; - private static final Gson GSON = new Gson(); - - private MockMvc mockMvc; - - - @InjectMocks - private WorkflowController workflowController; - - @Mock - private WorkflowManager workflowManagerMock; - - @Before - public void setUp() { - mockMvc = MockMvcBuilders.standaloneSetup(workflowController).build(); - } - - @Test - public void shouldReturnErrorWhenMissingUserIdInGetReqHeader() throws Exception { - Workflow workflowMock = createWorkflow(1, true); - MockHttpServletResponse response = - mockMvc.perform(get(RestPath.getWorkflowPath(workflowMock.getId())).contentType(APPLICATION_JSON)) - .andDo(print()).andExpect(status().isBadRequest()).andExpect(status().is(400)).andReturn() - .getResponse(); - assertEquals(String.format(MISSING_REQUEST_HEADER_ERRROR_FORMAT, "USER_ID"), response.getErrorMessage()); - } - - @Test - public void shouldReturnWorkflowDataWhenRequestPathIsOk() throws Exception { - Workflow workflowMock = createWorkflow(1, true); - doReturn(workflowMock).when(workflowManagerMock).get(any(Workflow.class)); - mockMvc.perform( - 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()))); - } - - @Test - public void shouldReturnErrorWhenMissingUserIdInListReqHeader() throws Exception { - 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_PARAM), response.getErrorMessage()); - } - - @Test - public void shouldReturn5WorkflowWhen5WorkflowsExists() throws Exception { - int numOfWorkflows = 5; - List<Workflow> workflowMocks = createWorkflows(numOfWorkflows); - doReturn(workflowMocks).when(workflowManagerMock).list(); - mockMvc.perform( - get(RestPath.getWorkflowsPath()).header(USER_ID_HEADER_PARAM, USER_ID).contentType(APPLICATION_JSON)) - .andDo(print()).andExpect(status().isOk()).andExpect(jsonPath("$.results", hasSize(numOfWorkflows))); - } - - @Test - public void shouldCreateWorkflowWhenCallingPostRESTRequest() throws Exception { - Item item = new Item(); - item.setId("abc"); - Workflow reqWorkflow = createWorkflow(1, false); - mockMvc.perform( - 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); - } - - private List<Workflow> createWorkflows(int numOfWorkflows) { - List<Workflow> workflowList = new ArrayList<>(numOfWorkflows); - for (int i = 0; i < numOfWorkflows; i++) { - workflowList.add(createWorkflow(i, true)); - } - - return workflowList; - } - - -}
\ No newline at end of file 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 deleted file mode 100644 index 75b132ad..00000000 --- a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/api/WorkflowVersionControllerTest.java +++ /dev/null @@ -1,118 +0,0 @@ -package org.onap.sdc.workflow.api; - -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.collection.IsCollectionWithSize.hasSize; -import static org.junit.Assert.assertEquals; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -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; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put; -import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; - -import com.google.gson.Gson; -import java.util.Arrays; -import java.util.List; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -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.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; -import org.springframework.mock.web.MockHttpServletResponse; -import org.springframework.test.web.servlet.MockMvc; -import org.springframework.test.web.servlet.setup.MockMvcBuilders; - -@RunWith(MockitoJUnitRunner.class) -public class WorkflowVersionControllerTest { - - private static final String USER_ID = "cs0008"; - 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; - - private static final Gson GSON = new Gson(); - - private MockMvc mockMvc; - - @Mock - private WorkflowVersionManager workflowVersionManagerMock; - - @InjectMocks - private WorkflowVersionController workflowVersionController; - - @Before - public void setUp() { - versionList = Arrays.asList( new Version(VERSION1_ID),new Version(VERSION2_ID)); - mockMvc = MockMvcBuilders.standaloneSetup(workflowVersionController).build(); - } - - @Test - public void shouldReturnWorkflowVersionListWhenCallingVersionGetREST() throws Exception { - - doReturn(versionList).when(workflowVersionManagerMock).list(ITEM1_ID); - mockMvc.perform(get(RestPath.getWorkflowVersions(ITEM1_ID)).header(RestConstants.USER_ID_HEADER_PARAM, USER_ID) - .contentType(APPLICATION_JSON)).andExpect(status().isOk()) - .andExpect(jsonPath("$.results", hasSize(2))) - .andExpect(jsonPath("$.results[0].id", equalTo(VERSION1_ID))) - .andExpect(jsonPath("$.results[1].id", equalTo(VERSION2_ID))); - - verify(workflowVersionManagerMock, times(1)).list(ITEM1_ID); - } - - - @Test - public void shouldCreateWorkflowVersionWhenCallingVersionsPostREST() throws Exception { - - 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) - .content(GSON.toJson(version))) - .andExpect(status().isCreated()); - - verify(workflowVersionManagerMock, times(1)).create(ITEM1_ID, version); - } - - - @Test - public void shouldReturnWorkflowVersionWhenExists() throws Exception { - 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, VERSION1_ID); - } - - @Test - public void shouldUpdateWorkflowVersionWhenCallingPutREST() throws Exception { - WorkflowVersion version = new WorkflowVersion(); - version.setDescription("Updated"); - - MockHttpServletResponse result = mockMvc.perform( - put(RestPath.getWorkflowVersion(ITEM1_ID, VERSION1_ID)).header(RestConstants.USER_ID_HEADER_PARAM, USER_ID) - .contentType(APPLICATION_JSON) - .content(GSON.toJson(version))).andReturn() - .getResponse(); - - assertEquals(HttpStatus.OK.value(), result.getStatus()); - version.setId(VERSION1_ID); - verify(workflowVersionManagerMock, times(1)).update(ITEM1_ID, version); - - } - -} 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 deleted file mode 100644 index 4bec8b97..00000000 --- a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/persistence/impl/ArtifactRepositoryTest.java +++ /dev/null @@ -1,29 +0,0 @@ -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/UniqueValueServiceTest.java b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/UniqueValueServiceTest.java deleted file mode 100644 index 4911060a..00000000 --- a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/UniqueValueServiceTest.java +++ /dev/null @@ -1,98 +0,0 @@ -package org.onap.sdc.workflow.services; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.never; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; - -import java.util.Optional; -import org.junit.Before; -import org.junit.Test; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; -import org.mockito.Spy; -import org.onap.sdc.workflow.persistence.UniqueValueRepository; -import org.onap.sdc.workflow.persistence.types.UniqueValueEntity; -import org.onap.sdc.workflow.services.exceptions.UniqueValueViolationException; - -public class UniqueValueServiceTest { - - private static final String TYPE = "ss"; - private static final String DUMMY_COMBINATION = "dummy"; - - @Mock - private UniqueValueRepository uniqueValueRepositoryMock; - - @Spy - @InjectMocks - private UniqueValueService uniqueValueService; - - @Before - public void setUp() { - MockitoAnnotations.initMocks(this); - } - - @Test - public void shouldCallRepositoryInsertIfValueUnique(){ - doReturn(Optional.empty()).when(uniqueValueRepositoryMock).findById(any()); - uniqueValueService.createUniqueValue(TYPE, new String[]{DUMMY_COMBINATION}); - verify(uniqueValueRepositoryMock, times(1)).insert(any(UniqueValueEntity.class)); - } - - @Test - public void shouldNotCheckValueIfNoUniqueCombination(){ - uniqueValueService.createUniqueValue(TYPE, null); - verify(uniqueValueRepositoryMock, never()).findById(any(UniqueValueEntity.class)); - } - - @Test(expected = UniqueValueViolationException.class) - public void shouldThrowExceptionIfValueIsNotUnique(){ - doReturn(Optional.of("xxx")).when(uniqueValueRepositoryMock).findById(any()); - uniqueValueService.createUniqueValue(TYPE, new String[]{DUMMY_COMBINATION}); - } - - @Test - public void shouldCallRepositoryDeleteIfValueValid(){ - uniqueValueService.deleteUniqueValue(TYPE, new String[]{DUMMY_COMBINATION}); - verify(uniqueValueRepositoryMock, times(1)).delete(any(UniqueValueEntity.class)); - } - - @Test - public void shouldNotCallRepositoryDeleteIfValueNouniqueCombination(){ - uniqueValueService.deleteUniqueValue(TYPE, new String[]{}); - verify(uniqueValueRepositoryMock, never()).delete(any(UniqueValueEntity.class)); - } - - @Test - public void shouldNotUpdateIfNewAndOldValueAreEqualsCaseIgnore(){ - String value = "value"; - uniqueValueService.updateUniqueValue(TYPE, value, value.toUpperCase()); - verify(uniqueValueService, never()).createUniqueValue(anyString(), any()); - } - - @Test - public void shouldUpdateIfNewAndOldValueAreNotEqualsCaseIgnore(){ - String oldValue = "oldValue"; - String newValue = "newValue"; - uniqueValueService.updateUniqueValue(TYPE, oldValue, newValue); - verify(uniqueValueService, times(1)).createUniqueValue(anyString(), any()); - verify(uniqueValueService, times(1)).deleteUniqueValue(anyString(), any()); - } - - @Test - public void shouldReturnTrueIfValueExist() { - doReturn(Optional.of("xxx")).when(uniqueValueRepositoryMock).findById(any()); - assertTrue(uniqueValueService.isUniqueValueOccupied(TYPE, new String[]{DUMMY_COMBINATION})); - } - - @Test - public void shouldReturnFalseIfValueNotExist() { - doReturn(Optional.empty()).when(uniqueValueRepositoryMock).findById(any()); - assertFalse(uniqueValueService.isUniqueValueOccupied(TYPE, new String[]{DUMMY_COMBINATION})); - } -} diff --git a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/WorkflowManagerImplTest.java b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/WorkflowManagerImplTest.java deleted file mode 100644 index 3e228759..00000000 --- a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/WorkflowManagerImplTest.java +++ /dev/null @@ -1,119 +0,0 @@ -package org.onap.sdc.workflow.services.impl; - -import static org.mockito.ArgumentMatchers.any; -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.createItem; -import static org.onap.sdc.workflow.TestUtil.createWorkflow; - -import java.util.Arrays; -import java.util.List; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -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.EntityNotFoundException; -import org.onap.sdc.workflow.services.impl.mappers.WorkflowMapper; -import org.openecomp.sdc.versioning.ItemManager; -import org.openecomp.sdc.versioning.types.Item; -import org.openecomp.sdc.versioning.types.ItemStatus; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -@RunWith(SpringJUnit4ClassRunner.class) -public class WorkflowManagerImplTest { - - private static final String ITEM1_ID = "workflowId1"; - private static final String WORKFLOW_TYPE = "WORKFLOW"; - private static final String WORKFLOW_NAME_UNIQUE_TYPE = "WORKFLOW_NAME"; - private List<Item> itemList; - - @Mock - private WorkflowMapper workflowMapperMock; - - @Mock - private ItemManager itemManagerMock; - - @Mock - private UniqueValueService uniqueValueServiceMock; - - @InjectMocks - private WorkflowManagerImpl workflowManager; - - - @Before - public void setUp() { - itemList = Arrays.asList(createItem(1, true, true), createItem(2, true, true), createItem(3, true, true)); - - } - - - @Test - public void shouldReturnWorkflowVersionList() { - - doReturn(itemList).when(itemManagerMock).list(WorkflowManagerImpl.ITEM_PREDICATE); - workflowManager.list(); - verify(itemManagerMock).list(WorkflowManagerImpl.ITEM_PREDICATE); - } - - @Test(expected = EntityNotFoundException.class) - public void shouldThrowExceptionWhenWorkflowDontExist() { - Workflow nonExistingWorkflow = new Workflow(); - nonExistingWorkflow.setId(ITEM1_ID); - doReturn(null).when(itemManagerMock).get(ITEM1_ID); - workflowManager.get(nonExistingWorkflow); - verify(workflowMapperMock, times(3)).itemToWorkflow(any(Item.class)); - } - - @Test - public void shouldReturnWorkflow() { - Item retrievedItem = createItem(1, true, true); - doReturn(retrievedItem).when(itemManagerMock).get(ITEM1_ID); - Workflow workflow = createWorkflow(1, true); - workflowManager.get(workflow); - verify(itemManagerMock).get(ITEM1_ID); - verify(workflowMapperMock).itemToWorkflow(retrievedItem); - - - } - - @Test - public void shouldCreateWorkflowItemFromWorkflow() { - Workflow workflowToBeCreated = createWorkflow(1, false); - Item createdWorkflowItem = createItem(1, false, true); - doReturn(createdWorkflowItem).when(workflowMapperMock).workflowToItem(workflowToBeCreated); - doReturn(createdWorkflowItem).when(itemManagerMock).create(createdWorkflowItem); - workflowManager.create(workflowToBeCreated); - verify(uniqueValueServiceMock) - .validateUniqueValue(WORKFLOW_NAME_UNIQUE_TYPE, new String[] {workflowToBeCreated.getName()}); - - createdWorkflowItem.setStatus(ItemStatus.ACTIVE); - createdWorkflowItem.setType(WORKFLOW_TYPE); - verify(itemManagerMock).create(createdWorkflowItem); - verify(uniqueValueServiceMock) - .createUniqueValue(WORKFLOW_NAME_UNIQUE_TYPE, new String[] {workflowToBeCreated.getName()}); - } - - @Test - public void shouldUpdateWorkflow() { - Item workflowItem = createItem(1, true, true); - doReturn(workflowItem).when(itemManagerMock).get(ITEM1_ID); - Workflow workflowToBeUpdated = createWorkflow(1, true); - doReturn(workflowItem).when(workflowMapperMock).workflowToItem(workflowToBeUpdated); - workflowManager.update(workflowToBeUpdated); - verify(itemManagerMock).update(workflowItem); - verify(uniqueValueServiceMock) - .updateUniqueValue(WORKFLOW_NAME_UNIQUE_TYPE, workflowItem.getName(), workflowToBeUpdated.getName()); - - } - - @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/WorkflowVersionManagerImplTest.java b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/WorkflowVersionManagerImplTest.java deleted file mode 100644 index ae69b280..00000000 --- a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/WorkflowVersionManagerImplTest.java +++ /dev/null @@ -1,258 +0,0 @@ -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/mappers/VersionMapperTest.java b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/mappers/VersionMapperTest.java deleted file mode 100644 index b778de47..00000000 --- a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/mappers/VersionMapperTest.java +++ /dev/null @@ -1,80 +0,0 @@ -package org.onap.sdc.workflow.services.impl.mappers; - -import static org.junit.Assert.assertEquals; - -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.WorkflowVersionState; -import org.openecomp.sdc.versioning.dao.types.Version; -import org.openecomp.sdc.versioning.dao.types.VersionStatus; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.ComponentScan; -import org.springframework.context.annotation.Configuration; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -@ContextConfiguration(classes = VersionMapperTest.VersionMapperSpringTestConfig.class) -@RunWith(SpringJUnit4ClassRunner.class) -public class VersionMapperTest { - - @Configuration - @ComponentScan(basePackageClasses = {VersionMapper.class, VersionStateMapper.class}) - public static class VersionMapperSpringTestConfig { } - - @Autowired - VersionMapper versionMapper; - - - @Test - public void shouldMapVersionToWorkflowVersion() { - Version version = createVersion(); - WorkflowVersion mappedWorkflowVersion = versionMapper.versionToWorkflowVersion(version); - assertEquals(mappedWorkflowVersion.getId(), version.getId()); - assertEquals(mappedWorkflowVersion.getBaseId(), version.getBaseId()); - assertEquals(mappedWorkflowVersion.getDescription(), version.getDescription()); - assertEquals(mappedWorkflowVersion.getName(), version.getName()); - assertEquals(mappedWorkflowVersion.getCreationTime(), version.getCreationTime()); - assertEquals(mappedWorkflowVersion.getModificationTime(), version.getModificationTime()); - } - - @Test - public void shouldMapWorkflowVersionToVersion() { - WorkflowVersion workflowVersion = createWorkflowVersion(); - Version mappedVersion = versionMapper.workflowVersionToVersion(workflowVersion); - assertEquals(mappedVersion.getId(), workflowVersion.getId()); - assertEquals(mappedVersion.getBaseId(), workflowVersion.getBaseId()); - assertEquals(mappedVersion.getDescription(), workflowVersion.getDescription()); - assertEquals(mappedVersion.getName(), workflowVersion.getName()); - assertEquals(mappedVersion.getCreationTime(), workflowVersion.getCreationTime()); - assertEquals(mappedVersion.getModificationTime(), workflowVersion.getModificationTime()); - - } - - private Version createVersion() { - Version version = new Version("version_id"); - version.setBaseId("base_version_id"); - version.setName("1.0"); - version.setCreationTime(new Date()); - version.setModificationTime(new Date()); - version.setDescription("version_description"); - version.setStatus(VersionStatus.Draft); - - return version; - - } - - private WorkflowVersion createWorkflowVersion() { - WorkflowVersion workflowVersion = new WorkflowVersion(); - workflowVersion.setId("wf_version_id"); - workflowVersion.setBaseId("wf_base_version_id"); - workflowVersion.setName("1.0"); - workflowVersion.setCreationTime(new Date()); - workflowVersion.setModificationTime(new Date()); - workflowVersion.setDescription("version_description"); - workflowVersion.setState(WorkflowVersionState.CERTIFIED); - - return workflowVersion; - } -} diff --git a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/mappers/VersionStateMapperTest.java b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/mappers/VersionStateMapperTest.java deleted file mode 100644 index 59d16289..00000000 --- a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/mappers/VersionStateMapperTest.java +++ /dev/null @@ -1,75 +0,0 @@ -package org.onap.sdc.workflow.services.impl.mappers; - -import static org.junit.Assert.assertEquals; - -import org.junit.Test; -import org.junit.runner.RunWith; -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; -import org.springframework.context.annotation.Configuration; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -@ContextConfiguration(classes = VersionStateMapperTest.VersionStatusMapperSpringTestConfig.class) -@RunWith(SpringJUnit4ClassRunner.class) -public class VersionStateMapperTest { - - @Configuration - @ComponentScan(basePackageClasses = {VersionStateMapper.class}) - public static class VersionStatusMapperSpringTestConfig { } - - - @Autowired - VersionStateMapper versionStateMapper; - - @Test - public void shouldMapCertifiedVersionStatusToWorkflowVersionStatus() { - WorkflowVersionState mappedVersionStatus = - versionStateMapper.versionStatusToWorkflowVersionState(VersionStatus.Certified); - assertEquals(WorkflowVersionState.CERTIFIED, mappedVersionStatus); - } - - @Test - public void shouldMapDraftVersionStatusToWorkflowVersionStatus() { - WorkflowVersionState mappedVersionStatus = - versionStateMapper.versionStatusToWorkflowVersionState(VersionStatus.Draft); - assertEquals(WorkflowVersionState.DRAFT, mappedVersionStatus); - } - - @Test - public void shouldMapDeletedVersionStatusToWorkflowVersionStatus() { - WorkflowVersionState mappedVersionStatus = - versionStateMapper.versionStatusToWorkflowVersionState(VersionStatus.Deleted); - assertEquals(WorkflowVersionState.DRAFT, mappedVersionStatus); - } - - @Test - public void shouldMapLockedVersionStatusToWorkflowVersionStatus() { - WorkflowVersionState mappedVersionStatus = - versionStateMapper.versionStatusToWorkflowVersionState(VersionStatus.Locked); - assertEquals(WorkflowVersionState.DRAFT, mappedVersionStatus); - } - - @Test - public void shouldMapDeprecatedVersionStatusToWorkflowVersionStatus() { - WorkflowVersionState mappedVersionStatus = - versionStateMapper.versionStatusToWorkflowVersionState(VersionStatus.Deprecated); - assertEquals(WorkflowVersionState.DRAFT, mappedVersionStatus); - } - - @Test - public void shouldMapCertifiedWorkflowVersionStatusToVersionStatus() { - VersionStatus mappedVersionStatus = - versionStateMapper.workflowVersionStateToVersionStatus(WorkflowVersionState.CERTIFIED); - assertEquals(VersionStatus.Certified, mappedVersionStatus); - } - - @Test - public void shouldMapDraftWorkflowVersionStatusToVersionStatus() { - VersionStatus mappedVersionStatus = - versionStateMapper.workflowVersionStateToVersionStatus(WorkflowVersionState.DRAFT); - assertEquals(VersionStatus.Draft, mappedVersionStatus); - } -} diff --git a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/mappers/WorkflowMapperTest.java b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/mappers/WorkflowMapperTest.java deleted file mode 100644 index 55802cc0..00000000 --- a/workflow-designer-be/src/test/java/org/onap/sdc/workflow/services/impl/mappers/WorkflowMapperTest.java +++ /dev/null @@ -1,50 +0,0 @@ -package org.onap.sdc.workflow.services.impl.mappers; - - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.onap.sdc.workflow.TestUtil.createItem; -import static org.onap.sdc.workflow.TestUtil.createWorkflow; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.onap.sdc.workflow.persistence.types.Workflow; -import org.openecomp.sdc.versioning.types.Item; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.ComponentScan; -import org.springframework.context.annotation.Configuration; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -@ContextConfiguration(classes = WorkflowMapperTest.WorkflowMapperSpringTestConfig.class) -@RunWith(SpringJUnit4ClassRunner.class) -public class WorkflowMapperTest { - - @Configuration - @ComponentScan(basePackageClasses = {WorkflowMapper.class}) - public static class WorkflowMapperSpringTestConfig { } - - @Autowired - WorkflowMapper workflowMapper; - - @Test - public void shouldMapItemToWorkflow() { - - Item item = createItem(1,false,true); - Workflow mappedWorkflow = workflowMapper.itemToWorkflow(item); - assertEquals(mappedWorkflow.getId(), item.getId()); - assertEquals(mappedWorkflow.getDescription(), item.getDescription()); - assertEquals(mappedWorkflow.getName(), item.getName()); - } - - @Test - public void shouldMapWorkflowToItem(){ - - Workflow workflow = createWorkflow(1,true); - Item mappedItem = workflowMapper.workflowToItem(workflow); - assertEquals(mappedItem.getId(), workflow.getId()); - assertEquals(mappedItem.getDescription(), workflow.getDescription()); - assertEquals(mappedItem.getName(), workflow.getName()); - } - -}
\ No newline at end of file |