Search in sources :

Example 6 with Refreshable

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

the class GroovyScriptFactoryTests method testStaticPrototypeScriptUsingJsr223.

@Test
public void testStaticPrototypeScriptUsingJsr223() throws Exception {
    ApplicationContext ctx = new ClassPathXmlApplicationContext("groovyContextWithJsr223.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 : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) Refreshable(org.springframework.aop.target.dynamic.Refreshable) ConfigurableMessenger(org.springframework.scripting.ConfigurableMessenger) Test(org.junit.Test)

Example 7 with Refreshable

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

the class GroovyScriptFactoryTests method testStaticScriptWithInlineDefinedInstance.

@Test
public void testStaticScriptWithInlineDefinedInstance() throws Exception {
    ApplicationContext ctx = new ClassPathXmlApplicationContext("groovyContext.xml", getClass());
    assertTrue(Arrays.asList(ctx.getBeanNamesForType(Messenger.class)).contains("messengerInstanceInline"));
    Messenger messenger = (Messenger) ctx.getBean("messengerInstanceInline");
    assertFalse("Shouldn't get proxy when refresh is disabled", AopUtils.isAopProxy(messenger));
    assertFalse("Scripted object should not be instance of Refreshable", messenger instanceof Refreshable);
    String desiredMessage = "Hello World!";
    assertEquals("Message is incorrect", desiredMessage, messenger.getMessage());
    assertTrue(ctx.getBeansOfType(Messenger.class).values().contains(messenger));
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) Messenger(org.springframework.scripting.Messenger) ConfigurableMessenger(org.springframework.scripting.ConfigurableMessenger) Refreshable(org.springframework.aop.target.dynamic.Refreshable) Test(org.junit.Test)

Example 8 with Refreshable

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

the class GroovyScriptFactoryTests method testStaticScriptWithInlineDefinedInstanceUsingJsr223.

@Test
public void testStaticScriptWithInlineDefinedInstanceUsingJsr223() throws Exception {
    ApplicationContext ctx = new ClassPathXmlApplicationContext("groovyContextWithJsr223.xml", getClass());
    assertTrue(Arrays.asList(ctx.getBeanNamesForType(Messenger.class)).contains("messengerInstanceInline"));
    Messenger messenger = (Messenger) ctx.getBean("messengerInstanceInline");
    assertFalse("Shouldn't get proxy when refresh is disabled", AopUtils.isAopProxy(messenger));
    assertFalse("Scripted object should not be instance of Refreshable", messenger instanceof Refreshable);
    String desiredMessage = "Hello World!";
    assertEquals("Message is incorrect", desiredMessage, messenger.getMessage());
    assertTrue(ctx.getBeansOfType(Messenger.class).values().contains(messenger));
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) Messenger(org.springframework.scripting.Messenger) ConfigurableMessenger(org.springframework.scripting.ConfigurableMessenger) Refreshable(org.springframework.aop.target.dynamic.Refreshable) Test(org.junit.Test)

Example 9 with Refreshable

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

the class GroovyScriptFactoryTests method testStaticScriptWithInstanceUsingJsr223.

@Test
public void testStaticScriptWithInstanceUsingJsr223() throws Exception {
    ApplicationContext ctx = new ClassPathXmlApplicationContext("groovyContextWithJsr223.xml", getClass());
    assertTrue(Arrays.asList(ctx.getBeanNamesForType(Messenger.class)).contains("messengerInstance"));
    Messenger messenger = (Messenger) ctx.getBean("messengerInstance");
    assertFalse("Shouldn't get proxy when refresh is disabled", AopUtils.isAopProxy(messenger));
    assertFalse("Scripted object should not be instance of Refreshable", messenger instanceof Refreshable);
    String desiredMessage = "Hello World!";
    assertEquals("Message is incorrect", desiredMessage, messenger.getMessage());
    assertTrue(ctx.getBeansOfType(Messenger.class).values().contains(messenger));
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) Messenger(org.springframework.scripting.Messenger) ConfigurableMessenger(org.springframework.scripting.ConfigurableMessenger) Refreshable(org.springframework.aop.target.dynamic.Refreshable) Test(org.junit.Test)

Example 10 with Refreshable

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

the class GroovyScriptFactoryTests method testRefreshableFromTagProxyTargetClass.

// SPR-6268
@Test
public void testRefreshableFromTagProxyTargetClass() throws Exception {
    ApplicationContext ctx = new ClassPathXmlApplicationContext("groovy-with-xsd-proxy-target-class.xml", getClass());
    assertTrue(Arrays.asList(ctx.getBeanNamesForType(Messenger.class)).contains("refreshableMessenger"));
    Messenger messenger = (Messenger) ctx.getBean("refreshableMessenger");
    assertTrue(AopUtils.isAopProxy(messenger));
    assertTrue(messenger instanceof Refreshable);
    assertEquals("Hello World!", messenger.getMessage());
    assertTrue(ctx.getBeansOfType(ConcreteMessenger.class).values().contains(messenger));
    // Check that AnnotationUtils works with concrete proxied script classes
    assertNotNull(AnnotationUtils.findAnnotation(messenger.getClass(), Component.class));
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) Messenger(org.springframework.scripting.Messenger) ConfigurableMessenger(org.springframework.scripting.ConfigurableMessenger) Refreshable(org.springframework.aop.target.dynamic.Refreshable) Component(org.springframework.stereotype.Component) 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