Skip to content

Commit 47fc8be

Browse files
committed
added test for custom controller stereotype
1 parent c7f8d1b commit 47fc8be

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/mvc/annotation/ServletAnnotationControllerTests.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818

1919
import java.io.IOException;
2020
import java.io.Writer;
21+
import java.lang.annotation.ElementType;
22+
import java.lang.annotation.Retention;
23+
import java.lang.annotation.RetentionPolicy;
24+
import java.lang.annotation.Target;
2125
import java.lang.reflect.Method;
2226
import java.security.Principal;
2327
import java.text.SimpleDateFormat;
@@ -116,6 +120,16 @@ public void standardHandleMethod() throws Exception {
116120
assertEquals("test", response.getContentAsString());
117121
}
118122

123+
@Test
124+
public void customAnnotationController() throws Exception {
125+
initServlet(CustomAnnotationController.class);
126+
127+
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/myPath.do");
128+
MockHttpServletResponse response = new MockHttpServletResponse();
129+
servlet.service(request, response);
130+
assertEquals("Invalid response status code", HttpServletResponse.SC_OK, response.getStatus());
131+
}
132+
119133
@Test
120134
public void requiredParamMissing() throws Exception {
121135
initServlet(RequiredParamController.class);
@@ -124,6 +138,7 @@ public void requiredParamMissing() throws Exception {
124138
MockHttpServletResponse response = new MockHttpServletResponse();
125139
servlet.service(request, response);
126140
assertEquals("Invalid response status code", HttpServletResponse.SC_BAD_REQUEST, response.getStatus());
141+
assertTrue(servlet.getWebApplicationContext().isSingleton("controller"));
127142
}
128143

129144
@Test
@@ -1440,6 +1455,20 @@ public void doGet(HttpServletRequest req, HttpServletResponse resp, @RequestPara
14401455
}
14411456
}
14421457

1458+
@Target({ElementType.TYPE})
1459+
@Retention(RetentionPolicy.RUNTIME)
1460+
@Controller
1461+
public @interface MyControllerAnnotation {
1462+
}
1463+
1464+
@MyControllerAnnotation
1465+
public static class CustomAnnotationController {
1466+
1467+
@RequestMapping("/myPath.do")
1468+
public void myHandle() {
1469+
}
1470+
}
1471+
14431472
@Controller
14441473
public static class RequiredParamController {
14451474

0 commit comments

Comments
 (0)