Search in sources :

Example 11 with Messenger

use of org.springframework.scripting.Messenger 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 12 with Messenger

use of org.springframework.scripting.Messenger in project spring-framework by spring-projects.

the class GroovyScriptFactoryTests method testJsr223FromTag.

@Test
public void testJsr223FromTag() throws Exception {
    ApplicationContext ctx = new ClassPathXmlApplicationContext("groovy-with-xsd-jsr223.xml", getClass());
    assertTrue(Arrays.asList(ctx.getBeanNamesForType(Messenger.class)).contains("messenger"));
    Messenger messenger = (Messenger) ctx.getBean("messenger");
    assertFalse(AopUtils.isAopProxy(messenger));
    assertEquals("Hello World!", messenger.getMessage());
}
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) Test(org.junit.Test)

Example 13 with Messenger

use of org.springframework.scripting.Messenger in project spring-framework by spring-projects.

the class GroovyScriptFactoryTests method testJsr223FromTagWithInterface.

@Test
public void testJsr223FromTagWithInterface() throws Exception {
    ApplicationContext ctx = new ClassPathXmlApplicationContext("groovy-with-xsd-jsr223.xml", getClass());
    assertTrue(Arrays.asList(ctx.getBeanNamesForType(Messenger.class)).contains("messengerWithInterface"));
    Messenger messenger = (Messenger) ctx.getBean("messengerWithInterface");
    assertFalse(AopUtils.isAopProxy(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) Test(org.junit.Test)

Example 14 with Messenger

use of org.springframework.scripting.Messenger 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 15 with Messenger

use of org.springframework.scripting.Messenger 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)

Aggregations

Test (org.junit.Test)35 Messenger (org.springframework.scripting.Messenger)35 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)29 ConfigurableMessenger (org.springframework.scripting.ConfigurableMessenger)27 ApplicationContext (org.springframework.context.ApplicationContext)24 Refreshable (org.springframework.aop.target.dynamic.Refreshable)16 TestBeanAwareMessenger (org.springframework.scripting.TestBeanAwareMessenger)10 GenericApplicationContext (org.springframework.context.support.GenericApplicationContext)5 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)4 BeanDefinitionBuilder (org.springframework.beans.factory.support.BeanDefinitionBuilder)3 Calculator (org.springframework.scripting.Calculator)3 CallCounter (org.springframework.scripting.CallCounter)2 GroovyObject (groovy.lang.GroovyObject)1 FatalBeanException (org.springframework.beans.FatalBeanException)1 ScriptSource (org.springframework.scripting.ScriptSource)1 Component (org.springframework.stereotype.Component)1 TestBean (org.springframework.tests.sample.beans.TestBean)1