title: Spring restful service test case fail HTTP status is 500
body: <p>I want to implement test case for spring restful web services which return a json
  MY controller test class is : </p>
  
  <pre><code>@RunWith(SpringJUnit4ClassRunner.class)
  @ContextConfiguration(classes = {WebAppContext.class,JpaTestConfiguration.class
  })
  @WebAppConfiguration
  
  public class DominProfileRestControllerTest {
  
  private MockMvc mockMvc;
  
  @Autowired
  private WebApplicationContext webApplicationContext;
  
  
  private MediaType contentType = new MediaType(MediaType.APPLICATION_JSON.getType(),
          MediaType.APPLICATION_JSON.getSubtype(),
          Charset.forName("utf8"));
  @Before
  public void setUp() {
      mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build();
  }
  
  
  @Test
  public void testGetDomainProfile() throws Exception {
  
      String profileId = domainProfile.getId().toString();
      System.out.print("testing restful"+profileId);
  
      mockMvc.perform(get("/service/domainprofile/get/{id}", profileId) )
              .andExpect(status().isOk())
              .andExpect(content().contentType(contentType))
              .andExpect(jsonPath("$.city", is("Chandigrah")));
  
   /*              mockMvc.perform(get("/service/domainprofile/get/{id}",profileId).accept(MediaType.TEXT_PLAIN))
              .andExpect(status().isOk())
              .andExpect(content().contentType("text/plain;charset=ISO-8859-1"))
              .andExpect(content().string("hello Prashant"));
  */
  }
  </code></pre>
  
  <p>My Controller class Is :</p>
  
  <pre><code>@RestController
   @RequestMapping("/service/domainprofile")
   public class DominProfileRestController {
  
  @Autowired
  private JpaDomainProfileRepository jpaDomainProfileRepository;
  
  @RequestMapping(value = "/get/{id}", method = RequestMethod.GET)
  public DomainProfileResource getDomainProfile(@PathVariable String id) {
      JpaDomainProfile domainProfile = jpaDomainProfileRepository.findOne(Long.valueOf(id));
     DomainProfileResource domainProfileResource = new  DomainProfileResource();
      System.out.println("domainProfile.getCity()*************" + domainProfile.getCity());
      System.out.println("domainProfile.getAddress()*************" + domainProfile.getAddress());
      domainProfileResource.setCity(domainProfile.getCity());
      domainProfileResource.setAddress(domainProfile.getAddress());
  
    //  return new ResponseEntity&lt;DomainProfileResource&gt;(domainProfileResource, HttpStatus.OK);
     return domainProfileResource;
     // return domainProfile;
  
  }
  }
  </code></pre>
  
  <p>When I run test case I got An error while we got values in domainprofile.city and domainprofile.address. 
  Error Is :
  java.lang.AssertionError: Status 
  Expected :200
  Actual   :500
  It Is Working Fine When I return a plain text</p>