diff options
Diffstat (limited to 'workflow-designer-be/src/test/java/org/onap')
5 files changed, 66 insertions, 44 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 new file mode 100644 index 00000000..266ca91b --- /dev/null +++ b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/RestPath.java @@ -0,0 +1,24 @@ +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/api/WorkflowControllerTest.java b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/api/WorkflowControllerTest.java index eb579148..d23d3f90 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 @@ -7,6 +7,7 @@ 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.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; @@ -23,7 +24,7 @@ import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; -import static org.onap.sdc.workflow.TestUtil.createWorkflow; +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; @@ -34,15 +35,14 @@ 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 String WORKFLOWS_URL = "/workflows"; private static final Gson GSON = new Gson(); + public static final String USER_ID_HEADER = "USER_ID"; private MockMvc mockMvc; @@ -62,7 +62,7 @@ public class WorkflowControllerTest { public void shouldReturnErrorWhenMissingUserIdInGetReqHeader() throws Exception { Workflow workflowMock = createWorkflow(1, true); MockHttpServletResponse response = - mockMvc.perform(get(WORKFLOWS_URL + "/" + workflowMock.getId()).contentType(APPLICATION_JSON)) + 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()); @@ -73,8 +73,8 @@ public class WorkflowControllerTest { Workflow workflowMock = createWorkflow(1, true); doReturn(workflowMock).when(workflowManagerMock).get(any(Workflow.class)); mockMvc.perform( - get(WORKFLOWS_URL + "/" + workflowMock.getId()).header(RestConstants.USER_ID_HEADER_PARAM, USER_ID) - .contentType(APPLICATION_JSON)).andDo(print()) + get(RestPath.getWorkflowPath(workflowMock.getId())).header(RestConstants.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()))); } @@ -82,29 +82,29 @@ public class WorkflowControllerTest { @Test public void shouldReturnErrorWhenMissingUserIdInListReqHeader() throws Exception { MockHttpServletResponse response = - mockMvc.perform(get(WORKFLOWS_URL).contentType(APPLICATION_JSON)).andDo(print()) + 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"), response.getErrorMessage()); + assertEquals(String.format(MISSING_REQUEST_HEADER_ERRROR_FORMAT, USER_ID_HEADER), response.getErrorMessage()); } @Test - public void shouldReturnListOfWorkflows() throws Exception { + public void shouldReturn5WorkflowWhen5WorkflowsExists() throws Exception { int numOfWorkflows = 5; List<Workflow> workflowMocks = createWorkflows(numOfWorkflows); doReturn(workflowMocks).when(workflowManagerMock).list(); mockMvc.perform( - get(WORKFLOWS_URL).header(RestConstants.USER_ID_HEADER_PARAM, USER_ID).contentType(APPLICATION_JSON)) + get(RestPath.getWorkflowsPath()).header(RestConstants.USER_ID_HEADER_PARAM, USER_ID).contentType(APPLICATION_JSON)) .andDo(print()).andExpect(status().isOk()).andExpect(jsonPath("$.results", hasSize(numOfWorkflows))); } @Test - public void create() throws Exception { + public void shouldCreateWorkflowWhenCallingPostRESTRequest() throws Exception { Item item = new Item(); item.setId("abc"); Workflow reqWorkflow = createWorkflow(1, false); mockMvc.perform( - post(WORKFLOWS_URL).header(RestConstants.USER_ID_HEADER_PARAM, USER_ID).contentType(APPLICATION_JSON) - .content(GSON.toJson(reqWorkflow))).andDo(print()).andExpect(status().isCreated()) + post(RestPath.getWorkflowsPath()).header(RestConstants.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 b47d2f37..b77e11a2 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 @@ -24,6 +24,7 @@ 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.impl.WorkflowVersionControllerImpl; import org.onap.sdc.workflow.services.WorkflowVersionManager; import org.openecomp.sdc.versioning.dao.types.Version; @@ -58,11 +59,11 @@ public class WorkflowVersionControllerTest { } @Test - public void shouldReturnVersionListOfWorkflow() throws Exception { + public void shouldReturnWorkflowVersionListWhenCallingVersionGetREST() throws Exception { doReturn(versionList).when(workflowVersionManagerMock).list(ITEM1_ID); - mockMvc.perform(get("/workflows/item_id_1/versions").header(RestConstants.USER_ID_HEADER_PARAM, USER_ID) - .contentType(APPLICATION_JSON)).andExpect(status().isOk()) + 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))); @@ -72,13 +73,13 @@ public class WorkflowVersionControllerTest { @Test - public void shouldCreateWorkflowVersion() throws Exception { + public void shouldCreateWorkflowVersionWhenCallingVersionsPostREST() throws Exception { Version version = new Version(); version.setDescription("VersionDescription"); - mockMvc.perform(post("/workflows/item_id_1/versions").header(RestConstants.USER_ID_HEADER_PARAM, USER_ID) - .contentType(APPLICATION_JSON) - .content(GSON.toJson(version))) + 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); @@ -90,21 +91,21 @@ public class WorkflowVersionControllerTest { Version version = new Version(VERSION1_ID); doReturn(version).when(workflowVersionManagerMock).get(ITEM1_ID, version); mockMvc.perform( - get("/workflows/item_id_1/versions/" + VERSION1_ID).header(RestConstants.USER_ID_HEADER_PARAM, USER_ID) - .contentType(APPLICATION_JSON)).andDo(print()) + 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); } @Test - public void shouldUpdateWorkflowVersion() throws Exception { + public void shouldUpdateWorkflowVersionWhenCallingPutREST() throws Exception { Version version = new Version(); version.setDescription("Updated"); MockHttpServletResponse result = mockMvc.perform( - put("/workflows/item_id_1/versions/" + VERSION1_ID).header(RestConstants.USER_ID_HEADER_PARAM, USER_ID) - .contentType(APPLICATION_JSON) - .content(GSON.toJson(version))).andReturn() + 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()); 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 31da825a..74097b1e 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 @@ -27,7 +27,6 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; public class WorkflowManagerTest { private static final String ITEM1_ID = "workflowId1"; - private static final String ITEM2_ID = "workflowId2"; private static final String WORKFLOW_TYPE = "WORKFLOW"; private static final String WORKFLOW_NAME_UNIQUE_TYPE = "WORKFLOW_NAME"; private List<Item> itemList; @@ -45,37 +44,35 @@ public class WorkflowManagerTest { private WorkflowManagerImpl workflowManager; - @Before - public void setUp(){ - itemList = Arrays.asList(createItem(1,true,true), - createItem(2,true,true),createItem(3,true,true)); + public void setUp() { + itemList = Arrays.asList(createItem(1, true, true), createItem(2, true, true), createItem(3, true, true)); } @Test - public void shouldReturnWorkflowVersionList(){ + public void shouldReturnWorkflowVersionList() { - doReturn(itemList).when(itemManagerMock).list(workflowManager.ITEM_PREDICATE); + doReturn(itemList).when(itemManagerMock).list(WorkflowManagerImpl.ITEM_PREDICATE); workflowManager.list(); - verify(itemManagerMock).list(workflowManager.ITEM_PREDICATE); + verify(itemManagerMock).list(WorkflowManagerImpl.ITEM_PREDICATE); } @Test(expected = WorkflowNotFoundException.class) - public void shouldThrowExceptionWhenWorkflowDontExist(){ + 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)); + verify(workflowMapperMock, times(3)).itemToWorkflow(any(Item.class)); } @Test - public void shouldReturnWorkflow(){ - Item retrievedItem = createItem(1,true,true); + public void shouldReturnWorkflow() { + Item retrievedItem = createItem(1, true, true); doReturn(retrievedItem).when(itemManagerMock).get(ITEM1_ID); - Workflow workflow = createWorkflow(1,true); + Workflow workflow = createWorkflow(1, true); workflowManager.get(workflow); verify(itemManagerMock).get(ITEM1_ID); verify(workflowMapperMock).itemToWorkflow(retrievedItem); @@ -84,7 +81,7 @@ public class WorkflowManagerTest { } @Test - public void shouldCreateWorkflow() { + public void shouldCreateWorkflowItemFromWorkflow() { Workflow workflowToBeCreated = createWorkflow(1, false); Item createdWorkflowItem = createItem(1, false, true); doReturn(createdWorkflowItem).when(workflowMapperMock).workflowToItem(workflowToBeCreated); @@ -101,7 +98,7 @@ public class WorkflowManagerTest { } @Test - public void shouldUpdateWorkflow(){ + public void shouldUpdateWorkflow() { Item workflowItem = createItem(1, true, true); doReturn(workflowItem).when(itemManagerMock).get(ITEM1_ID); Workflow workflowToBeUpdated = createWorkflow(1, true); @@ -109,12 +106,12 @@ public class WorkflowManagerTest { workflowManager.update(workflowToBeUpdated); verify(itemManagerMock).update(workflowItem); verify(uniqueValueServiceMock) - .updateUniqueValue(WORKFLOW_NAME_UNIQUE_TYPE,workflowItem.getName(),workflowToBeUpdated.getName()); + .updateUniqueValue(WORKFLOW_NAME_UNIQUE_TYPE, workflowItem.getName(), workflowToBeUpdated.getName()); } @Test(expected = WorkflowNotFoundException.class) - public void shouldThrowExceptionWhenWorkflowToUpdateNotFound(){ + 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 d805a2b2..75146e28 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 @@ -50,7 +50,7 @@ public class WorkflowVersionManagerTest { } @Test - public void shouldReturnWorkflowVersion(){ + public void shouldReturnWorkflowVersionWhenExist(){ Version version = new Version(VERSION1_ID); doReturn(version).when(versioningManagerMock).get(ITEM1_ID,version); workflowVersionManager.get(ITEM1_ID,version); |