Search in sources :

Example 76 with AnnotationConfigApplicationContext

use of org.springframework.context.annotation.AnnotationConfigApplicationContext in project spring-framework by spring-projects.

the class ExceptionHandlerExceptionResolverTests method resolveExceptionControllerAdviceNoHandler.

@Test
public void resolveExceptionControllerAdviceNoHandler() throws Exception {
    AnnotationConfigApplicationContext cxt = new AnnotationConfigApplicationContext(MyControllerAdviceConfig.class);
    this.resolver.setApplicationContext(cxt);
    this.resolver.afterPropertiesSet();
    IllegalStateException ex = new IllegalStateException();
    ModelAndView mav = this.resolver.resolveException(this.request, this.response, null, ex);
    assertNotNull("Exception was not handled", mav);
    assertTrue(mav.isEmpty());
    assertEquals("DefaultTestExceptionResolver: IllegalStateException", this.response.getContentAsString());
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) ModelAndView(org.springframework.web.servlet.ModelAndView) Test(org.junit.Test)

Example 77 with AnnotationConfigApplicationContext

use of org.springframework.context.annotation.AnnotationConfigApplicationContext in project spring-framework by spring-projects.

the class ExceptionHandlerExceptionResolverTests method resolveExceptionWithAssertionErrorAsRootCause.

@Test
public void resolveExceptionWithAssertionErrorAsRootCause() throws Exception {
    AnnotationConfigApplicationContext cxt = new AnnotationConfigApplicationContext(MyConfig.class);
    this.resolver.setApplicationContext(cxt);
    this.resolver.afterPropertiesSet();
    AssertionError err = new AssertionError("argh");
    FatalBeanException ex = new FatalBeanException("wrapped", err);
    HandlerMethod handlerMethod = new HandlerMethod(new ResponseBodyController(), "handle");
    ModelAndView mav = this.resolver.resolveException(this.request, this.response, handlerMethod, ex);
    assertNotNull("Exception was not handled", mav);
    assertTrue(mav.isEmpty());
    assertEquals(err.toString(), this.response.getContentAsString());
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) FatalBeanException(org.springframework.beans.FatalBeanException) ModelAndView(org.springframework.web.servlet.ModelAndView) HandlerMethod(org.springframework.web.method.HandlerMethod) Test(org.junit.Test)

Example 78 with AnnotationConfigApplicationContext

use of org.springframework.context.annotation.AnnotationConfigApplicationContext in project spring-framework by spring-projects.

the class ExceptionHandlerExceptionResolverTests method resolveExceptionControllerAdviceHandler.

@Test
public void resolveExceptionControllerAdviceHandler() throws Exception {
    AnnotationConfigApplicationContext cxt = new AnnotationConfigApplicationContext(MyControllerAdviceConfig.class);
    this.resolver.setApplicationContext(cxt);
    this.resolver.afterPropertiesSet();
    IllegalStateException ex = new IllegalStateException();
    HandlerMethod handlerMethod = new HandlerMethod(new ResponseBodyController(), "handle");
    ModelAndView mav = this.resolver.resolveException(this.request, this.response, handlerMethod, ex);
    assertNotNull("Exception was not handled", mav);
    assertTrue(mav.isEmpty());
    assertEquals("BasePackageTestExceptionResolver: IllegalStateException", this.response.getContentAsString());
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) ModelAndView(org.springframework.web.servlet.ModelAndView) HandlerMethod(org.springframework.web.method.HandlerMethod) Test(org.junit.Test)

Example 79 with AnnotationConfigApplicationContext

use of org.springframework.context.annotation.AnnotationConfigApplicationContext in project spring-framework by spring-projects.

the class GroovyMarkupViewTests method createViewWithUrl.

private GroovyMarkupView createViewWithUrl(String viewUrl) throws Exception {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
    ctx.register(GroovyMarkupConfiguration.class);
    ctx.refresh();
    GroovyMarkupView view = new GroovyMarkupView();
    view.setUrl(viewUrl);
    view.setApplicationContext(ctx);
    view.afterPropertiesSet();
    return view;
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext)

Example 80 with AnnotationConfigApplicationContext

use of org.springframework.context.annotation.AnnotationConfigApplicationContext in project spring-framework by spring-projects.

the class KotlinScriptTemplateTests method createViewWithUrl.

private ScriptTemplateView createViewWithUrl(String viewUrl, Class<?> configuration) throws Exception {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
    ctx.register(configuration);
    ctx.refresh();
    ScriptTemplateView view = new ScriptTemplateView();
    view.setApplicationContext(ctx);
    view.setUrl(viewUrl);
    view.afterPropertiesSet();
    return view;
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext)

Aggregations

AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)800 Test (org.junit.Test)528 DSLContext (org.jooq.DSLContext)53 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)42 ApplicationContext (org.springframework.context.ApplicationContext)25 Before (org.junit.Before)23 DIConfiguration (com.khartec.waltz.service.DIConfiguration)15 Filter (javax.servlet.Filter)15 Map (java.util.Map)14 OncePerRequestFilter (org.springframework.web.filter.OncePerRequestFilter)14 TestBean (org.springframework.tests.sample.beans.TestBean)13 PropertyPlaceholderAutoConfiguration (org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration)12 MockMvc (org.springframework.test.web.servlet.MockMvc)12 EntityKind (com.khartec.waltz.model.EntityKind)11 List (java.util.List)10 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)10 MockEnvironment (org.springframework.mock.env.MockEnvironment)10 EntityReference (com.khartec.waltz.model.EntityReference)9 MapPropertySource (org.springframework.core.env.MapPropertySource)9 IOException (java.io.IOException)8