Announcement Announcement Module
Collapse
No announcement yet.
Spring Test Framework Testing Spring REST Call Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring Test Framework Testing Spring REST Call

    I am trying to change the following Spring Test Framework to test for a the following json return:

    Code:
       {"user":"John ","name":"JohnSmith"}
    Here is my test code and I just dont know how to change it to check for JSON and the value in JSON. It will be great if someone can tell me what to change.. thanks


    Code:
     @RunWith(SpringJUnit4ClassRunner.class)
        @ContextConfiguration(classes = {WebMVCConfig.class})
        @WebAppConfiguration
        public class TestHelloWorldWeb
        {
            @Autowired
            private WebApplicationContext wac;
        
            private MockMvc mockMvc;
        
            @Before
            public void setup()
            {
                this.mockMvc = MockMvcBuilders.webAppContextSetup(this.wac).build();
            }
        
            @Test
            public void getFoo() throws Exception
            {
                this.mockMvc.perform(get("/ask")
                        .accept(MediaType.TEXT_HTML))
                        .andExpect(status().isOk())
                        .andExpect(view().name("helloworld"))
                        .andExpect(MockMvcResultMatchers.model().attribute("user", "JohnSmith"))
                ;
        
        
            }
        }
Working...
X