Search in sources :

Example 91 with ClassPathXmlApplicationContext

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

the class ContextNamespaceHandlerTests method propertyPlaceholderIgnored.

@Test
public void propertyPlaceholderIgnored() throws Exception {
    ApplicationContext applicationContext = new ClassPathXmlApplicationContext("contextNamespaceHandlerTests-replace-ignore.xml", getClass());
    assertEquals("${bar}", applicationContext.getBean("string"));
    assertEquals("null", applicationContext.getBean("nullString"));
}
Also used : GenericXmlApplicationContext(org.springframework.context.support.GenericXmlApplicationContext) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) Test(org.junit.Test)

Example 92 with ClassPathXmlApplicationContext

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

the class ContextNamespaceHandlerTests method propertyPlaceholderLocationWithSystemPropertyMissing.

@Test
public void propertyPlaceholderLocationWithSystemPropertyMissing() throws Exception {
    try {
        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("contextNamespaceHandlerTests-location-placeholder.xml", getClass());
        assertEquals("bar", applicationContext.getBean("foo"));
        assertEquals("foo", applicationContext.getBean("bar"));
        assertEquals("maps", applicationContext.getBean("spam"));
    } catch (FatalBeanException ex) {
        assertTrue(ex.getRootCause() instanceof FileNotFoundException);
    }
}
Also used : GenericXmlApplicationContext(org.springframework.context.support.GenericXmlApplicationContext) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) FatalBeanException(org.springframework.beans.FatalBeanException) FileNotFoundException(java.io.FileNotFoundException) Test(org.junit.Test)

Example 93 with ClassPathXmlApplicationContext

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

the class ContextNamespaceHandlerTests method propertyPlaceholderSystemProperties.

@Test
public void propertyPlaceholderSystemProperties() throws Exception {
    String value = System.setProperty("foo", "spam");
    try {
        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("contextNamespaceHandlerTests-system.xml", getClass());
        assertEquals("spam", applicationContext.getBean("string"));
        assertEquals("none", applicationContext.getBean("fallback"));
    } finally {
        if (value != null) {
            System.setProperty("foo", value);
        }
    }
}
Also used : GenericXmlApplicationContext(org.springframework.context.support.GenericXmlApplicationContext) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) Test(org.junit.Test)

Example 94 with ClassPathXmlApplicationContext

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

the class AnnotationDrivenEventListenerTests method simpleEventXmlConfig.

@Test
public void simpleEventXmlConfig() {
    this.context = new ClassPathXmlApplicationContext("org/springframework/context/event/simple-event-configuration.xml");
    TestEvent event = new TestEvent(this, "test");
    TestEventListener listener = this.context.getBean(TestEventListener.class);
    this.eventCollector = getEventCollector(this.context);
    this.eventCollector.assertNoEventReceived(listener);
    this.context.publishEvent(event);
    this.eventCollector.assertEvent(listener, event);
    this.eventCollector.assertTotalEventsCount(1);
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) TestEvent(org.springframework.context.event.test.TestEvent) AnotherTestEvent(org.springframework.context.event.test.AnotherTestEvent) Test(org.junit.Test)

Example 95 with ClassPathXmlApplicationContext

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

the class AnnotationLazyInitMBeanTests method lazyNaming.

@Test
public void lazyNaming() throws Exception {
    ConfigurableApplicationContext ctx = new ClassPathXmlApplicationContext("org/springframework/jmx/export/annotation/lazyNaming.xml");
    try {
        MBeanServer server = (MBeanServer) ctx.getBean("server");
        ObjectName oname = ObjectNameManager.getInstance("bean:name=testBean4");
        assertNotNull(server.getObjectInstance(oname));
        String name = (String) server.getAttribute(oname, "Name");
        assertEquals("Invalid name returned", "TEST", name);
    } finally {
        ctx.close();
    }
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Aggregations

ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)480 Test (org.junit.Test)212 ApplicationContext (org.springframework.context.ApplicationContext)149 Before (org.junit.Before)47 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)17 SpringCamelContext (org.apache.camel.spring.SpringCamelContext)16 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)13 AbstractApplicationContext (org.springframework.context.support.AbstractApplicationContext)13 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)12 DemoService (com.alibaba.dubbo.config.spring.api.DemoService)11 ProducerTemplate (org.apache.camel.ProducerTemplate)10 File (java.io.File)9 URL (com.alibaba.dubbo.common.URL)8 Service (org.apache.camel.Service)8