@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = Application.class)
@WebMvcTest(value = JiraController.class, secure = false)
public class JiraControllerTest {
@Autowired
private MockMvc mockMvc;
@MockBean
private JiraService service;
@Test
public void testGetStory() throws Exception {
when(service.getallJIRAProjectsAggregrateData(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any()))
.thenReturn(getJiraEntity());
RequestBuilder requestBuilder = MockMvcRequestBuilders.get("/api/jira/story")
.param("facets", "allProjects").param("mode", "all").param("selectedtext", "All Projects")
.accept(MediaType.APPLICATION_JSON)
.content(new ObjectMapper().writeValueAsString(new ProjectIssueWiseDataAggregration()))
.contentType(MediaType.APPLICATION_JSON);
MvcResult result = mockMvc.perform(requestBuilder).andReturn();
MockHttpServletResponse response = result.getResponse();
assertEquals(HttpStatus.OK.value(), response.getStatus());
ProjectIssueWiseDataAggregration expectedUserEntity = new ObjectMapper()
.readValue(result.getResponse().getContentAsString(), ProjectIssueWiseDataAggregration.class);
System.out.println(result.getResponse().getContentAsString());
assertEquals("285.0", expectedUserEntity.getDefectsCount());
}
private List<ProjectIssueWiseDataAggregration> getJiraEntity() {
ProjectIssueWiseDataAggregration piwda = new ProjectIssueWiseDataAggregration();
List<ProjectIssueWiseDataAggregration> piwda2 = new ArrayList<ProjectIssueWiseDataAggregration>();
piwda.setDefectsCount(285.0);
piwda2.add(piwda);
return piwda2;
}
}
внутри requestBuilder я получаю 404, потому что он не достигает местоположения этого URI, и оттуда он возвращает нулевое значение в ответ.