Search in sources :

Example 21 with GenericXmlApplicationContext

use of org.springframework.context.support.GenericXmlApplicationContext in project spring-framework by spring-projects.

the class GroovyAspectIntegrationTests method testGroovyBeanProxyTargetClass.

@Test
public void testGroovyBeanProxyTargetClass() {
    context = new GenericXmlApplicationContext(getClass(), getClass().getSimpleName() + "-groovy-proxy-target-class-context.xml");
    TestService bean = context.getBean("groovyBean", TestService.class);
    LogUserAdvice logAdvice = context.getBean(LogUserAdvice.class);
    assertThat(logAdvice.getCountThrows()).isEqualTo(0);
    assertThatExceptionOfType(RuntimeException.class).isThrownBy(bean::sayHello).withMessage("GroovyServiceImpl");
    assertThat(logAdvice.getCountBefore()).isEqualTo(1);
    assertThat(logAdvice.getCountThrows()).isEqualTo(1);
}
Also used : GenericXmlApplicationContext(org.springframework.context.support.GenericXmlApplicationContext) Test(org.junit.jupiter.api.Test)

Example 22 with GenericXmlApplicationContext

use of org.springframework.context.support.GenericXmlApplicationContext in project spring-framework by spring-projects.

the class GroovyAspectIntegrationTests method testGroovyBeanInterface.

@Test
public void testGroovyBeanInterface() {
    context = new GenericXmlApplicationContext(getClass(), getClass().getSimpleName() + "-groovy-interface-context.xml");
    TestService bean = context.getBean("groovyBean", TestService.class);
    LogUserAdvice logAdvice = context.getBean(LogUserAdvice.class);
    assertThat(logAdvice.getCountThrows()).isEqualTo(0);
    assertThatExceptionOfType(RuntimeException.class).isThrownBy(bean::sayHello).withMessage("GroovyServiceImpl");
    assertThat(logAdvice.getCountThrows()).isEqualTo(1);
}
Also used : GenericXmlApplicationContext(org.springframework.context.support.GenericXmlApplicationContext) Test(org.junit.jupiter.api.Test)

Example 23 with GenericXmlApplicationContext

use of org.springframework.context.support.GenericXmlApplicationContext in project spring-framework by spring-projects.

the class DestroyMethodInferenceTests method xml.

@Test
public void xml() {
    ConfigurableApplicationContext ctx = new GenericXmlApplicationContext(getClass(), "DestroyMethodInferenceTests-context.xml");
    WithLocalCloseMethod x1 = ctx.getBean("x1", WithLocalCloseMethod.class);
    WithLocalCloseMethod x2 = ctx.getBean("x2", WithLocalCloseMethod.class);
    WithLocalCloseMethod x3 = ctx.getBean("x3", WithLocalCloseMethod.class);
    WithNoCloseMethod x4 = ctx.getBean("x4", WithNoCloseMethod.class);
    WithInheritedCloseMethod x8 = ctx.getBean("x8", WithInheritedCloseMethod.class);
    WithDisposableBean x9 = ctx.getBean("x9", WithDisposableBean.class);
    WithAutoCloseable x10 = ctx.getBean("x10", WithAutoCloseable.class);
    assertThat(x1.closed).isFalse();
    assertThat(x2.closed).isFalse();
    assertThat(x3.closed).isFalse();
    assertThat(x4.closed).isFalse();
    assertThat(x8.closed).isFalse();
    assertThat(x9.closed).isFalse();
    assertThat(x10.closed).isFalse();
    ctx.close();
    assertThat(x1.closed).isFalse();
    assertThat(x2.closed).isTrue();
    assertThat(x3.closed).isTrue();
    assertThat(x4.closed).isFalse();
    assertThat(x8.closed).isFalse();
    assertThat(x9.closed).isTrue();
    assertThat(x10.closed).isTrue();
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) GenericXmlApplicationContext(org.springframework.context.support.GenericXmlApplicationContext) Test(org.junit.jupiter.api.Test)

Example 24 with GenericXmlApplicationContext

use of org.springframework.context.support.GenericXmlApplicationContext in project spring-framework by spring-projects.

the class EnableLoadTimeWeavingTests method control.

@Test
public void control() {
    GenericXmlApplicationContext ctx = new GenericXmlApplicationContext(getClass(), "EnableLoadTimeWeavingTests-context.xml");
    ctx.getBean("loadTimeWeaver", LoadTimeWeaver.class);
}
Also used : GenericXmlApplicationContext(org.springframework.context.support.GenericXmlApplicationContext) Test(org.junit.jupiter.api.Test)

Example 25 with GenericXmlApplicationContext

use of org.springframework.context.support.GenericXmlApplicationContext in project spring-framework by spring-projects.

the class AsyncAnnotationBeanPostProcessorTests method configuredThroughNamespace.

@Test
public void configuredThroughNamespace() {
    GenericXmlApplicationContext context = new GenericXmlApplicationContext();
    context.load(new ClassPathResource("taskNamespaceTests.xml", getClass()));
    context.refresh();
    ITestBean testBean = context.getBean("target", ITestBean.class);
    testBean.test();
    testBean.await(3000);
    Thread asyncThread = testBean.getThread();
    assertThat(asyncThread.getName().startsWith("testExecutor")).isTrue();
    TestableAsyncUncaughtExceptionHandler exceptionHandler = context.getBean("exceptionHandler", TestableAsyncUncaughtExceptionHandler.class);
    assertThat(exceptionHandler.isCalled()).as("handler should not have been called yet").isFalse();
    testBean.failWithVoid();
    exceptionHandler.await(3000);
    Method m = ReflectionUtils.findMethod(TestBean.class, "failWithVoid");
    exceptionHandler.assertCalledWith(m, UnsupportedOperationException.class);
    context.close();
}
Also used : Method(java.lang.reflect.Method) GenericXmlApplicationContext(org.springframework.context.support.GenericXmlApplicationContext) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.jupiter.api.Test)

Aggregations

GenericXmlApplicationContext (org.springframework.context.support.GenericXmlApplicationContext)61 Test (org.junit.Test)21 Test (org.junit.jupiter.api.Test)13 MBeanServer (javax.management.MBeanServer)5 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)5 Scanner (java.util.Scanner)4 ObjectName (javax.management.ObjectName)4 Resource (org.springframework.core.io.Resource)4 QueueChannel (org.springframework.integration.channel.QueueChannel)4 MessageChannel (org.springframework.messaging.MessageChannel)4 ApplicationContext (org.springframework.context.ApplicationContext)3 ByteArrayResource (org.springframework.core.io.ByteArrayResource)3 Message (org.springframework.messaging.Message)3 MBeanOperationInfo (javax.management.MBeanOperationInfo)2 Server (org.eclipse.jetty.server.Server)2 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)2 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)2 BatchStatus (org.springframework.batch.core.BatchStatus)2 BeanDefinitionParsingException (org.springframework.beans.factory.parsing.BeanDefinitionParsingException)2 CacheInterceptor (org.springframework.cache.interceptor.CacheInterceptor)2