java.lang.AssertionError: Status expected:<200> but was:<500>

Spring JIRA | Preston Crawford | 4 years ago
tip
Your exception is missing from the Samebug knowledge base.
Here are the best solutions we found on the Internet.
Click on the to mark the helpful solution and get rewards for you help.
  1. 0

    We're using Spring MVC Test (the version rolled into 3.2) extensively where I work. Currently we're experiencing an issue where a REST service that's not passed an Accept header will default to a serializer for CURL calls and other client calls. In our integration tests, however, we get a 500 error instead. This is an example test call we have. {code} final MvcResult result = context.perform(get(ourRestURL)) .andExpect(status().isOk()) .andExpect(content().string(containsString(expectedResult))) .andReturn(); {code} This results in the following. Debugging this in the IDE it doesn't even fall into the REST method being referenced. {panel} java.lang.AssertionError: Status expected:<200> but was:<500> at org.springframework.test.util.AssertionErrors.fail(AssertionErrors.java:60) at org.springframework.test.util.AssertionErrors.assertEquals(AssertionErrors.java:89) at org.springframework.test.web.servlet.result.StatusResultMatchers$5.match(StatusResultMatchers.java:549) at org.springframework.test.web.servlet.MockMvc$1.andExpect(MockMvc.java:141) {panel} This is the definition of the REST endpoint. {code} @RequestMapping(value = "/v1/keys/{keyName}", method = RequestMethod.GET, produces = { "application/json" }) @ResponseBody public GenericKey getKey(@RequestHeader("Accept") final String acceptHeader, @PathVariable("keyName") final String keyName, @RequestParam(value = "callback", required = false) final String callback) { // ... } {code}

    Spring JIRA | 4 years ago | Preston Crawford
    java.lang.AssertionError: Status expected:<200> but was:<500>
  2. 0

    We're using Spring MVC Test (the version rolled into 3.2) extensively where I work. Currently we're experiencing an issue where a REST service that's not passed an Accept header will default to a serializer for CURL calls and other client calls. In our integration tests, however, we get a 500 error instead. This is an example test call we have. {code} final MvcResult result = context.perform(get(ourRestURL)) .andExpect(status().isOk()) .andExpect(content().string(containsString(expectedResult))) .andReturn(); {code} This results in the following. Debugging this in the IDE it doesn't even fall into the REST method being referenced. {panel} java.lang.AssertionError: Status expected:<200> but was:<500> at org.springframework.test.util.AssertionErrors.fail(AssertionErrors.java:60) at org.springframework.test.util.AssertionErrors.assertEquals(AssertionErrors.java:89) at org.springframework.test.web.servlet.result.StatusResultMatchers$5.match(StatusResultMatchers.java:549) at org.springframework.test.web.servlet.MockMvc$1.andExpect(MockMvc.java:141) {panel} This is the definition of the REST endpoint. {code} @RequestMapping(value = "/v1/keys/{keyName}", method = RequestMethod.GET, produces = { "application/json" }) @ResponseBody public GenericKey getKey(@RequestHeader("Accept") final String acceptHeader, @PathVariable("keyName") final String keyName, @RequestParam(value = "callback", required = false) final String callback) { // ... } {code}

    Spring JIRA | 4 years ago | Preston Crawford
    java.lang.AssertionError: Status expected:<200> but was:<500>
  3. 0

    GitHub comment 15#35897674

    GitHub | 3 years ago | mathieubodin
    java.lang.AssertionError: Status expected:<200> but was:<500>
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    @Mock of an @Autowired dependency causes random junit test failures

    Stack Overflow | 10 months ago | mikerott
    java.lang.AssertionError: Status expected:<200> but was:<500>
  6. 0

    Combine @WebMcvTest with @PathVariable annotated controllers in Spring Boot 1.41

    Stack Overflow | 5 months ago | Olivier Le Merdy
    java.lang.AssertionError: Status expected:<200> but was:<500>

  1. olle.hallin 20 times, last 5 days ago
  2. tvrmsmith 1 times, last 1 week ago
  3. iferca 1 times, last 3 months ago
58 unregistered visitors
Not finding the right solution?
Take a tour to get the most out of Samebug.

Tired of useless tips?

Automated exception search integrated into your IDE

Root Cause Analysis

  1. java.lang.AssertionError

    Status expected:<200> but was:<500>

    at org.springframework.test.util.AssertionErrors.fail()
  2. Spring TestContext
    MockMvc$1.andExpect
    1. org.springframework.test.util.AssertionErrors.fail(AssertionErrors.java:60)
    2. org.springframework.test.util.AssertionErrors.assertEquals(AssertionErrors.java:89)
    3. org.springframework.test.web.servlet.result.StatusResultMatchers$5.match(StatusResultMatchers.java:549)
    4. org.springframework.test.web.servlet.MockMvc$1.andExpect(MockMvc.java:141)
    4 frames