Search in sources :

Example 21 with ClassPathXmlApplicationContext

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();
    }
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) Scheduler(org.quartz.Scheduler) Test(org.junit.Test)

Example 22 with ClassPathXmlApplicationContext

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");
    }
}
Also used : ITestBean(org.springframework.tests.sample.beans.ITestBean) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) Test(org.junit.Test)

Example 23 with ClassPathXmlApplicationContext

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();
}
Also used : ITestBean(org.springframework.tests.sample.beans.ITestBean) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) Advised(org.springframework.aop.framework.Advised) CommonsPool2TargetSource(org.springframework.aop.target.CommonsPool2TargetSource) PrototypeTargetSource(org.springframework.aop.target.PrototypeTargetSource) ThreadLocalTargetSource(org.springframework.aop.target.ThreadLocalTargetSource) Test(org.junit.Test)

Example 24 with ClassPathXmlApplicationContext

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");
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) Test(org.junit.Test)

Example 25 with ClassPathXmlApplicationContext

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();
}
Also used : FooService(example.scannable.FooService) SimpleMapScope(org.springframework.tests.context.SimpleMapScope) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) Test(org.junit.Test)

Aggregations

ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)561 Test (org.junit.Test)265 ApplicationContext (org.springframework.context.ApplicationContext)167 Before (org.junit.Before)53 ConfigurableMessenger (org.springframework.scripting.ConfigurableMessenger)33 ITestBean (org.springframework.tests.sample.beans.ITestBean)30 Messenger (org.springframework.scripting.Messenger)29 CamelContext (org.apache.camel.CamelContext)25 Refreshable (org.springframework.aop.target.dynamic.Refreshable)23 AbstractXmlApplicationContext (org.springframework.context.support.AbstractXmlApplicationContext)22 DataSource (javax.sql.DataSource)18 SpringCamelContext (org.apache.camel.spring.SpringCamelContext)16 AbstractApplicationContext (org.springframework.context.support.AbstractApplicationContext)16 Bus (org.apache.cxf.Bus)14 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)14 ArrayList (java.util.ArrayList)13 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)12 DemoService (com.alibaba.dubbo.config.spring.api.DemoService)11 IOException (java.io.IOException)10 ProducerTemplate (org.apache.camel.ProducerTemplate)10