Search in sources :

Example 21 with Refreshable

use of org.springframework.aop.target.dynamic.Refreshable in project spring-framework by spring-projects.

the class BshScriptFactoryTests method staticPrototypeScript.

@Test
public void staticPrototypeScript() throws Exception {
    ApplicationContext ctx = new ClassPathXmlApplicationContext("bshContext.xml", getClass());
    ConfigurableMessenger messenger = (ConfigurableMessenger) ctx.getBean("messengerPrototype");
    ConfigurableMessenger messenger2 = (ConfigurableMessenger) ctx.getBean("messengerPrototype");
    assertFalse("Shouldn't get proxy when refresh is disabled", AopUtils.isAopProxy(messenger));
    assertFalse("Scripted object should not be instance of Refreshable", messenger instanceof Refreshable);
    assertNotSame(messenger, messenger2);
    assertSame(messenger.getClass(), messenger2.getClass());
    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());
}
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 22 with Refreshable

use of org.springframework.aop.target.dynamic.Refreshable in project spring-framework by spring-projects.

the class BshScriptFactoryTests method inlineScriptFromTag.

@Test
public void inlineScriptFromTag() throws Exception {
    ApplicationContext ctx = new ClassPathXmlApplicationContext("bsh-with-xsd.xml", getClass());
    Calculator calculator = (Calculator) ctx.getBean("calculator");
    assertNotNull(calculator);
    assertFalse(calculator instanceof Refreshable);
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) Calculator(org.springframework.scripting.Calculator) Refreshable(org.springframework.aop.target.dynamic.Refreshable) Test(org.junit.Test)

Example 23 with Refreshable

use of org.springframework.aop.target.dynamic.Refreshable in project spring-framework by spring-projects.

the class BshScriptFactoryTests method resourceScriptFromTag.

@Test
public void resourceScriptFromTag() throws Exception {
    ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("bsh-with-xsd.xml", getClass());
    TestBean testBean = (TestBean) ctx.getBean("testBean");
    Collection<String> beanNames = Arrays.asList(ctx.getBeanNamesForType(Messenger.class));
    assertTrue(beanNames.contains("messenger"));
    assertTrue(beanNames.contains("messengerImpl"));
    assertTrue(beanNames.contains("messengerInstance"));
    Messenger messenger = (Messenger) ctx.getBean("messenger");
    assertEquals("Hello World!", messenger.getMessage());
    assertFalse(messenger instanceof Refreshable);
    Messenger messengerImpl = (Messenger) ctx.getBean("messengerImpl");
    assertEquals("Hello World!", messengerImpl.getMessage());
    Messenger messengerInstance = (Messenger) ctx.getBean("messengerInstance");
    assertEquals("Hello World!", messengerInstance.getMessage());
    TestBeanAwareMessenger messengerByType = (TestBeanAwareMessenger) ctx.getBean("messengerByType");
    assertEquals(testBean, messengerByType.getTestBean());
    TestBeanAwareMessenger messengerByName = (TestBeanAwareMessenger) ctx.getBean("messengerByName");
    assertEquals(testBean, messengerByName.getTestBean());
    Collection<Messenger> beans = ctx.getBeansOfType(Messenger.class).values();
    assertTrue(beans.contains(messenger));
    assertTrue(beans.contains(messengerImpl));
    assertTrue(beans.contains(messengerInstance));
    assertTrue(beans.contains(messengerByType));
    assertTrue(beans.contains(messengerByName));
    ctx.close();
    assertNull(messenger.getMessage());
    assertNull(messengerImpl.getMessage());
    assertNull(messengerInstance.getMessage());
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) TestBean(org.springframework.tests.sample.beans.TestBean) TestBeanAwareMessenger(org.springframework.scripting.TestBeanAwareMessenger) 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)

Aggregations

Test (org.junit.Test)23 Refreshable (org.springframework.aop.target.dynamic.Refreshable)23 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)23 ApplicationContext (org.springframework.context.ApplicationContext)20 ConfigurableMessenger (org.springframework.scripting.ConfigurableMessenger)20 Messenger (org.springframework.scripting.Messenger)16 Calculator (org.springframework.scripting.Calculator)5 TestBeanAwareMessenger (org.springframework.scripting.TestBeanAwareMessenger)4 CallCounter (org.springframework.scripting.CallCounter)2 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)1 Component (org.springframework.stereotype.Component)1 TestBean (org.springframework.tests.sample.beans.TestBean)1