Search in sources :

Example 96 with ClassPathXmlApplicationContext

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

the class BshScriptFactoryTests method nonStaticPrototypeScript.

@Test
public void nonStaticPrototypeScript() throws Exception {
    ApplicationContext ctx = new ClassPathXmlApplicationContext("bshRefreshableContext.xml", getClass());
    ConfigurableMessenger messenger = (ConfigurableMessenger) ctx.getBean("messengerPrototype");
    ConfigurableMessenger messenger2 = (ConfigurableMessenger) ctx.getBean("messengerPrototype");
    assertTrue("Should be a proxy for refreshable scripts", AopUtils.isAopProxy(messenger));
    assertTrue("Should be an instance of Refreshable", messenger instanceof Refreshable);
    assertEquals("Hello World!", messenger.getMessage());
    assertEquals("Hello World!", messenger2.getMessage());
    messenger.setMessage("Bye World!");
    messenger2.setMessage("Byebye World!");
    assertEquals("Bye World!", messenger.getMessage());
    assertEquals("Byebye World!", messenger2.getMessage());
    Refreshable refreshable = (Refreshable) messenger;
    refreshable.refresh();
    assertEquals("Hello World!", messenger.getMessage());
    assertEquals("Byebye World!", messenger2.getMessage());
    assertEquals("Incorrect refresh count", 2, refreshable.getRefreshCount());
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) Refreshable(org.springframework.aop.target.dynamic.Refreshable) ConfigurableMessenger(org.springframework.scripting.ConfigurableMessenger) Test(org.junit.Test)

Example 97 with ClassPathXmlApplicationContext

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

the class BshScriptFactoryTests method staticScriptWithTwoInterfacesSpecified.

@Test
public void staticScriptWithTwoInterfacesSpecified() throws Exception {
    ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("bshContext.xml", getClass());
    assertTrue(Arrays.asList(ctx.getBeanNamesForType(Messenger.class)).contains("messengerWithConfigExtra"));
    ConfigurableMessenger messenger = (ConfigurableMessenger) ctx.getBean("messengerWithConfigExtra");
    messenger.setMessage(null);
    assertNull(messenger.getMessage());
    assertTrue(ctx.getBeansOfType(Messenger.class).values().contains(messenger));
    ctx.close();
    assertNull(messenger.getMessage());
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) TestBeanAwareMessenger(org.springframework.scripting.TestBeanAwareMessenger) ConfigurableMessenger(org.springframework.scripting.ConfigurableMessenger) Messenger(org.springframework.scripting.Messenger) ConfigurableMessenger(org.springframework.scripting.ConfigurableMessenger) Test(org.junit.Test)

Example 98 with ClassPathXmlApplicationContext

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

the class BshScriptFactoryTests method refreshableFromTag.

@Test
public void refreshableFromTag() throws Exception {
    ApplicationContext ctx = new ClassPathXmlApplicationContext("bsh-with-xsd.xml", getClass());
    Messenger messenger = (Messenger) ctx.getBean("refreshableMessenger");
    assertEquals("Hello World!", messenger.getMessage());
    assertTrue("Messenger should be Refreshable", messenger instanceof Refreshable);
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) TestBeanAwareMessenger(org.springframework.scripting.TestBeanAwareMessenger) ConfigurableMessenger(org.springframework.scripting.ConfigurableMessenger) Messenger(org.springframework.scripting.Messenger) Refreshable(org.springframework.aop.target.dynamic.Refreshable) Test(org.junit.Test)

Example 99 with ClassPathXmlApplicationContext

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

the class BshScriptFactoryTests method applicationEventListener.

@Test
public void applicationEventListener() throws Exception {
    ApplicationContext ctx = new ClassPathXmlApplicationContext("bsh-with-xsd.xml", getClass());
    Messenger eventListener = (Messenger) ctx.getBean("eventListener");
    ctx.publishEvent(new MyEvent(ctx));
    assertEquals("count=2", eventListener.getMessage());
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) TestBeanAwareMessenger(org.springframework.scripting.TestBeanAwareMessenger) ConfigurableMessenger(org.springframework.scripting.ConfigurableMessenger) Messenger(org.springframework.scripting.Messenger) Test(org.junit.Test)

Example 100 with ClassPathXmlApplicationContext

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

the class BshScriptFactoryTests method staticScriptWithNullReturnValue.

@Test
public void staticScriptWithNullReturnValue() throws Exception {
    ApplicationContext ctx = new ClassPathXmlApplicationContext("bshContext.xml", getClass());
    assertTrue(Arrays.asList(ctx.getBeanNamesForType(Messenger.class)).contains("messengerWithConfig"));
    ConfigurableMessenger messenger = (ConfigurableMessenger) ctx.getBean("messengerWithConfig");
    messenger.setMessage(null);
    assertNull(messenger.getMessage());
    assertTrue(ctx.getBeansOfType(Messenger.class).values().contains(messenger));
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) TestBeanAwareMessenger(org.springframework.scripting.TestBeanAwareMessenger) ConfigurableMessenger(org.springframework.scripting.ConfigurableMessenger) Messenger(org.springframework.scripting.Messenger) ConfigurableMessenger(org.springframework.scripting.ConfigurableMessenger) 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