मेरा सरल एकीकरण परीक्षण है
@Test
public void shouldReturnErrorMessageToAdminWhenCreatingUserWithUsedUserName() throws Exception {
mockMvc.perform(post("/api/users").header("Authorization", base64ForTestUser).contentType(MediaType.APPLICATION_JSON)
.content("{\"userName\":\"testUserDetails\",\"firstName\":\"xxx\",\"lastName\":\"xxx\",\"password\":\"xxx\"}"))
.andDo(print())
.andExpect(status().isBadRequest())
.andExpect(?);
}
अंतिम पंक्ति में मैं प्रतिक्रिया शरीर में प्राप्त स्ट्रिंग की तुलना अपेक्षित स्ट्रिंग से करना चाहता हूं
और जवाब में मुझे मिलता है:
MockHttpServletResponse:
Status = 400
Error message = null
Headers = {Content-Type=[application/json]}
Content type = application/json
Body = "Username already taken"
Forwarded URL = null
Redirected URL = null
सामग्री (), बॉडी () के साथ कुछ ट्रिक्स अपनाईं लेकिन कुछ भी काम नहीं आया।
"Username already taken"
। यह एक 409 संघर्ष का अधिक होना चाहिए।