samedi 10 janvier 2015

Spring MVC controller testing with gradle

When I moved my application form Maven (Eclipse) to Gradle (InteliJ) All my Controller tests stopped working. Tests were working on old application with Maven.


My Controller method:



@RequestMapping(value = "submit", method = RequestMethod.POST, consumes =

MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
public @ResponseBody FormResponse submitForm(@RequestBody TagData form) throws BusinessException {
tagService.saveTag(form);
return FormResponse.success("admin.tag.saved");


}


My test:



@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"/pl/dk/web/controllers/controllers-test-context.xml"})
@WebAppConfiguration
public class TagControllerTest {

@Autowired
TagController controller;

@Autowired
WebApplicationContext webContext;

@Autowired
TagManagerService tagService;

private MockMvc mockMvc;

@Before
public void setUp() {
mockMvc = MockMvcBuilders.webAppContextSetup(webContext).build();
EasyMock.reset(tagService);
}

@Test
public void testSave() throws Exception {
TagData form = new TagData();
form.setName("Test tag");
form.setDescription("Test description");

EasyMock.expect(tagService.saveTag(form)).andReturn(1L);
controller.tagService = tagService;

RequestBuilder reqBuilder = MockMvcRequestBuilders.post("/admin/recipes/tag/submit").contentType(MediaType.APPLICATION_JSON)
.content(TestUtil.convertObjectToString(form));
MvcResult result = mockMvc.perform(reqBuilder).andExpect(MockMvcResultMatchers.status().isOk()).andReturn();
Assert.assertNotNull(result);
}


In my worst scenario, this problem may be connected with InteliJ integration with gradle or something, and I am fighting ghosts here. Can anyone help me with this?


My error:



java.lang.AssertionError: Status
Expected :200
Actual :415

Aucun commentaire:

Enregistrer un commentaire