added test for custom controller stereotype

git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@1104 50f2f4bb-b051-0410-bef5-90022cba6387
This commit is contained in:
Juergen Hoeller 2009-05-05 18:37:43 +00:00
parent befc8cfa4e
commit c5521dfed7
1 changed files with 29 additions and 0 deletions

View File

@ -18,6 +18,10 @@ package org.springframework.web.servlet.mvc.annotation;
import java.io.IOException; import java.io.IOException;
import java.io.Writer; import java.io.Writer;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.security.Principal; import java.security.Principal;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
@ -116,6 +120,16 @@ public class ServletAnnotationControllerTests {
assertEquals("test", response.getContentAsString()); assertEquals("test", response.getContentAsString());
} }
@Test
public void customAnnotationController() throws Exception {
initServlet(CustomAnnotationController.class);
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/myPath.do");
MockHttpServletResponse response = new MockHttpServletResponse();
servlet.service(request, response);
assertEquals("Invalid response status code", HttpServletResponse.SC_OK, response.getStatus());
}
@Test @Test
public void requiredParamMissing() throws Exception { public void requiredParamMissing() throws Exception {
initServlet(RequiredParamController.class); initServlet(RequiredParamController.class);
@ -124,6 +138,7 @@ public class ServletAnnotationControllerTests {
MockHttpServletResponse response = new MockHttpServletResponse(); MockHttpServletResponse response = new MockHttpServletResponse();
servlet.service(request, response); servlet.service(request, response);
assertEquals("Invalid response status code", HttpServletResponse.SC_BAD_REQUEST, response.getStatus()); assertEquals("Invalid response status code", HttpServletResponse.SC_BAD_REQUEST, response.getStatus());
assertTrue(servlet.getWebApplicationContext().isSingleton("controller"));
} }
@Test @Test
@ -1440,6 +1455,20 @@ public class ServletAnnotationControllerTests {
} }
} }
@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Controller
public @interface MyControllerAnnotation {
}
@MyControllerAnnotation
public static class CustomAnnotationController {
@RequestMapping("/myPath.do")
public void myHandle() {
}
}
@Controller @Controller
public static class RequiredParamController { public static class RequiredParamController {