testing - Spring MVC Controller Test -


I am writing a JUnit test case for a spring controller. The controller class Junit test case and MockHttpServletRequest and MockHttpServletResponse. The problem is that I can not find the body (i.e. the list of train items in the transcript). Can anyone help on this?

@controller @ request mapping ("/ trains") Public Class Train Controller {@Autowired Private TrainService trainService; @RequestMapping ("trainslist.json") public @ResponseBody list & lt; Train & gt; GetTrainList () {return trainService.getAllTrains (); }} The Junich Test Case Package for the above Controller class is com.xvitcoder.angualrspringapp.controller; Static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get Import; Import static org.springframework.test.web.servlet.result.MockMvcResultHandlers; Print; Import static organization. Import java.util.ArrayList; 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.Mockito; Import org.mockito.MockitoAnnotations; Import organization Source: Import organization Source: Import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; Import org.springframework.test.context.web.WebAppConfiguration; Import org.springframework.test.web.servlet.MockMvc; Import org.springframework.test.web.servlet.setup.MockMvcBuilders; Import org.springframework.web.context.WebApplicationContext; Import com.xvitcoder.angualrspringapp.beans.Train; Import com.xvitcoder.angualrspringapp.service.TrainService; @ Rnvith (SpringJUnit4ClassRunner.class) @ContextConfiguration (locations = { "classpath: /config/webapp-config.xml"}) @WebAppConfiguration public square Train Controller Test {private MockMvc mockMvc; @ Owned Personal WebApplicationContext wac; @InjectMocks Train Controller Train Controller; @ Mock Pvt. Train service service service; Personal Final List & lt; Train & gt; Train List = New Arrestist & lt; Train & gt; (); @private zero setup () throws exceptions before {// process fake annotations mokitiennotations Itmax (this); This.mockMvc = MockMvcBuilders.webAppContextSetup (this.wac) .build (); Train train = new train (); Train.setId (12L); Train.setName ("Chennai"); Train.setSpeed ​​(100); Train.setDiesel (true); Train Train 1 = New Train (); Train1.setId (15l); Train1.setName ("koai"); Train1.setSpeed ​​(150); Train1.setDiesel (wrong); TrainList.add (train); TrainList.add (train1); } @Test Public Zero TestGetTrainList () throws exception {System.out.println ("test"); Mockito.when (trainService.getAllTrains ()) thenReturn (trainList) MockMvc.perform (find ("/ trainslist.json") andDo (print ()) andExpect .. (Position () isOk ().); }}

MockHttpServletRequest: HTTP method = Request URI = /trainslist.json parameter = {} headers = {}

  handler type = org Springframework. web.servlet.resource.DefaultServletHttpRequestHandler async:  

had started async = false async result = null

solution exception: type = null

 ModelAndView: see name = null View = null model = null Flasmap:  

MockHttpServletResponse: status = 200 error message = null headers = {} content type = zero physical = forward url = default redirect URL = Null Ukijh = []


Comments

Popular posts from this blog

sqlite3 - UPDATE a table from the SELECT of another one -

c# - Showing a SelectedItem's Property -

javascript - Render HTML after each iteration in loop -