Ich habe diese Junit-Test mit Mockito (ein Open-Source-Test-Framework für Java unter der MIT-Lizenz veröffentlicht) in einem Spring Web Model-View-Controller (MVC) Framework-Anwendung Ich habe dies in der Controller-Methoden:Mockito: check response Header und Status
@RequestMapping(value = { "/devices" } , method = { RequestMethod.GET, RequestMethod.POST})
public void initGetForm(@ModelAttribute("searchForm") final SearchForm searchForm,
HttpServletRequest request,
HttpServletResponse response,
Locale locale) throws Exception {
String newUrl = request.getContextPath() + "/devices/" + locale;
if (locale !=null && isValid(locale)) {
newUrl = request.getContextPath() + "/devices/" + DEFAULT_LOCALE;
}
redirectPermanently (response, newUrl);
}
protected void redirectPermanently (HttpServletResponse response, String to) {
response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);
response.setHeader("Location", to);
response.setHeader("Connection", "close");
}
und dies ist mein Test-Klasse:
@Test
public void testInitGetForm() throws Exception {
controller.initGetForm(emptySearchForm(), request, response, null);
}
@Before
public void setUpTest() {
request = new MockHttpServletRequest();
response = new MockHttpServletResponse();
}
ist es möglich, die Kopf- und Status der Antwort zu überprüfen ?????
Dieser Test verwendet Mockito nicht. –