Code example for MockMvc

Methods: perform

0
        /* 
        * 
        * curl -X POST -vu android-crm:123456 http://localhost:8080/oauth/token -H "Accept: application/json" 
         *     -d "password=cowbell&username=joshlong&grant_type=password&scope=write&client_secret=123456&client_id=android-crm 
        */ 
        MockHttpServletResponse response = mockMvc.perform(tokenRequest) 
                .andExpect(status().isOk()) 
                .andExpect(content().contentTypeCompatibleWith(applicationJsonMediaType)).andReturn().getResponse(); 
 
        String bodyContent = response.getContentAsString(); 
 
        ObjectMapper objectMapper = new ObjectMapper(); 
 
        Map map = objectMapper.readValue(bodyContent, Map.class); 
 
        Assert.assertTrue(map.containsKey("access_token")); 
        accessToken = (String) map.get("access_token"); 
        Assert.assertNotNull(accessToken); 
 
        log("access_token: " + accessToken); 
Connect your IDE to all the code out there  Get Codota for Java