aboutsummaryrefslogtreecommitdiffstats
path: root/workflow-designer-be/src/test/java/org/onap/sdc/workflow/api/WorkflowVersionControllerTest.java
diff options
context:
space:
mode:
authorvempo <vitaliy.emporopulo@amdocs.com>2018-07-24 17:34:04 +0300
committervempo <vitaliy.emporopulo@amdocs.com>2018-07-25 11:39:10 +0300
commita52d50e788792a63e97a9176ab319d53db7a2853 (patch)
treeb1c2222cacf4b8192aea16d1e0315b1f005c5347 /workflow-designer-be/src/test/java/org/onap/sdc/workflow/api/WorkflowVersionControllerTest.java
parent3c2665debb400aef7f0ed9e235698d2ff9f859db (diff)
Replaced old implementation at root
Old project files and directories has been moved under 'deprecated-workflow-designer'. The old project is not built by the CI anymore, but can be still built manually. New modules/directories have been moved up and integrated with the CI system. Change-Id: I1528c792bcbcce9e50bfc294a1328a20e72c91cf Issue-ID: SDC-1559 Signed-off-by: vempo <vitaliy.emporopulo@amdocs.com>
Diffstat (limited to 'workflow-designer-be/src/test/java/org/onap/sdc/workflow/api/WorkflowVersionControllerTest.java')
-rw-r--r--workflow-designer-be/src/test/java/org/onap/sdc/workflow/api/WorkflowVersionControllerTest.java117
1 files changed, 117 insertions, 0 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
new file mode 100644
index 00000000..ee9a56c8
--- /dev/null
+++ b/workflow-designer-be/src/test/java/org/onap/sdc/workflow/api/WorkflowVersionControllerTest.java
@@ -0,0 +1,117 @@
+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.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, null);
+ 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, null);
+ }
+
+
+ @Test
+ public void shouldCreateWorkflowVersionWhenCallingVersionsPostREST() throws Exception {
+
+ WorkflowVersion version = new WorkflowVersion();
+ 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, null, 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);
+
+ }
+
+}