Merge branch '1.2.x'

This commit is contained in:
Phillip Webb
2015-10-20 13:52:45 -07:00
2 changed files with 71 additions and 1 deletions

View File

@@ -24,6 +24,10 @@ import java.lang.annotation.Target;
import javax.servlet.ServletException;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.junit.After;
import org.junit.Rule;
import org.junit.Test;
@@ -34,6 +38,7 @@ import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfigurati
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.test.ApplicationContextTestUtils;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.context.annotation.Import;
import org.springframework.http.MediaType;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@@ -101,11 +106,21 @@ public class BasicErrorControllerDirectMockMvcTests {
setup((ConfigurableWebApplicationContext) new SpringApplication(
WebMvcIncludedConfiguration.class).run("--server.port=0",
"--server.error.whitelabel.enabled=false"));
this.thrown.expect(ServletException.class);
this.mockMvc.perform(get("/error").accept(MediaType.TEXT_HTML));
}
@Test
public void errorControllerWithAop() throws Exception {
setup((ConfigurableWebApplicationContext) new SpringApplication(
WithAopConfiguration.class).run("--server.port=0"));
MvcResult response = this.mockMvc
.perform(get("/error").accept(MediaType.TEXT_HTML))
.andExpect(status().isOk()).andReturn();
String content = response.getResponse().getContentAsString();
assertTrue("Wrong content: " + content, content.contains("status=999"));
}
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@@ -127,6 +142,7 @@ public class BasicErrorControllerDirectMockMvcTests {
@MinimalWebConfiguration
@EnableWebMvc
protected static class WebMvcIncludedConfiguration {
// For manual testing
public static void main(String[] args) {
SpringApplication.run(WebMvcIncludedConfiguration.class, args);
@@ -137,6 +153,7 @@ public class BasicErrorControllerDirectMockMvcTests {
@Configuration
@MinimalWebConfiguration
protected static class VanillaConfiguration {
// For manual testing
public static void main(String[] args) {
SpringApplication.run(VanillaConfiguration.class, args);
@@ -147,11 +164,30 @@ public class BasicErrorControllerDirectMockMvcTests {
@Configuration
@MinimalWebConfiguration
protected static class ChildConfiguration {
// For manual testing
public static void main(String[] args) {
new SpringApplicationBuilder(ParentConfiguration.class)
.child(ChildConfiguration.class).run(args);
}
}
@Configuration
@EnableAspectJAutoProxy(proxyTargetClass = false)
@MinimalWebConfiguration
@Aspect
protected static class WithAopConfiguration {
@Pointcut("within(@org.springframework.stereotype.Controller *)")
private void controllerPointCut() {
};
@Around("controllerPointCut()")
public Object mvcAdvice(ProceedingJoinPoint pjp) throws Throwable {
return pjp.proceed();
}
}
}