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 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;
"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;
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())));
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
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)));
}
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);