use of org.springframework.context.support.ClassPathXmlApplicationContext in project spring-framework by spring-projects.
the class QuartzSupportTests method multipleSchedulers.
/**
* Tests the creation of multiple schedulers (SPR-772)
*/
@Test
public void multipleSchedulers() throws Exception {
ClassPathXmlApplicationContext ctx = context("multipleSchedulers.xml");
try {
Scheduler scheduler1 = (Scheduler) ctx.getBean("scheduler1");
Scheduler scheduler2 = (Scheduler) ctx.getBean("scheduler2");
assertNotSame(scheduler1, scheduler2);
assertEquals("quartz1", scheduler1.getSchedulerName());
assertEquals("quartz2", scheduler2.getSchedulerName());
} finally {
ctx.close();
}
}
use of org.springframework.context.support.ClassPathXmlApplicationContext in project spring-framework by spring-projects.
the class SimpleBeforeAdviceInterceptor method testAdvisorAdapterRegistrationManagerPresentInContext.
@Test
public void testAdvisorAdapterRegistrationManagerPresentInContext() {
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-with-bpp.xml", getClass());
ITestBean tb = (ITestBean) ctx.getBean("testBean");
// just invoke any method to see if advice fired
try {
tb.getName();
assertEquals(1, getAdviceImpl(tb).getInvocationCounter());
} catch (UnknownAdviceTypeException ex) {
fail("Should not throw UnknownAdviceTypeException");
}
}
use of org.springframework.context.support.ClassPathXmlApplicationContext in project spring-framework by spring-projects.
the class SelectivePrototypeTargetSourceCreator method testQuickTargetSourceCreator.
@Test
public void testQuickTargetSourceCreator() throws Exception {
ClassPathXmlApplicationContext bf = new ClassPathXmlApplicationContext(QUICK_TARGETSOURCE_CONTEXT, CLASS);
ITestBean test = (ITestBean) bf.getBean("test");
assertFalse(AopUtils.isAopProxy(test));
assertEquals("Rod", test.getName());
// Check that references survived pooling
assertEquals("Kerry", test.getSpouse().getName());
// Now test the pooled one
test = (ITestBean) bf.getBean(":test");
assertTrue(AopUtils.isAopProxy(test));
Advised advised = (Advised) test;
assertTrue(advised.getTargetSource() instanceof CommonsPool2TargetSource);
assertEquals("Rod", test.getName());
// Check that references survived pooling
assertEquals("Kerry", test.getSpouse().getName());
// Now test the ThreadLocal one
test = (ITestBean) bf.getBean("%test");
assertTrue(AopUtils.isAopProxy(test));
advised = (Advised) test;
assertTrue(advised.getTargetSource() instanceof ThreadLocalTargetSource);
assertEquals("Rod", test.getName());
// Check that references survived pooling
assertEquals("Kerry", test.getSpouse().getName());
// Now test the Prototype TargetSource
test = (ITestBean) bf.getBean("!test");
assertTrue(AopUtils.isAopProxy(test));
advised = (Advised) test;
assertTrue(advised.getTargetSource() instanceof PrototypeTargetSource);
assertEquals("Rod", test.getName());
// Check that references survived pooling
assertEquals("Kerry", test.getSpouse().getName());
ITestBean test2 = (ITestBean) bf.getBean("!test");
assertFalse("Prototypes cannot be the same object", test == test2);
assertEquals("Rod", test2.getName());
assertEquals("Kerry", test2.getSpouse().getName());
bf.close();
}
use of org.springframework.context.support.ClassPathXmlApplicationContext in project spring-framework by spring-projects.
the class UnsupportedInterceptor method testWithDependencyChecking.
@Test
@SuppressWarnings("resource")
public void testWithDependencyChecking() {
ApplicationContext ctx = new ClassPathXmlApplicationContext(DEPENDENCY_CHECK_CONTEXT, getClass());
ctx.getBean("testBean");
}
use of org.springframework.context.support.ClassPathXmlApplicationContext in project spring-framework by spring-projects.
the class ComponentScanParserScopedProxyTests method testInterfacesScopedProxy.
@Test
public void testInterfacesScopedProxy() throws Exception {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("org/springframework/context/annotation/scopedProxyInterfacesTests.xml");
context.getBeanFactory().registerScope("myScope", new SimpleMapScope());
// should cast to the interface
FooService bean = (FooService) context.getBean("scopedProxyTestBean");
// should be dynamic proxy
assertTrue(AopUtils.isJdkDynamicProxy(bean));
// test serializability
assertEquals("bar", bean.foo(1));
FooService deserialized = (FooService) SerializationTestUtils.serializeAndDeserialize(bean);
assertNotNull(deserialized);
assertEquals("bar", deserialized.foo(1));
context.close();
}
Aggregations