Search in sources :

Example 1 with CallCounter

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

the class GroovyScriptFactoryTests method testRefreshableFromTag.

@Test
public void testRefreshableFromTag() throws Exception {
    ApplicationContext ctx = new ClassPathXmlApplicationContext("groovy-with-xsd.xml", getClass());
    assertTrue(Arrays.asList(ctx.getBeanNamesForType(Messenger.class)).contains("refreshableMessenger"));
    Messenger messenger = (Messenger) ctx.getBean("refreshableMessenger");
    CallCounter countingAspect = (CallCounter) ctx.getBean("getMessageAspect");
    assertTrue(AopUtils.isAopProxy(messenger));
    assertTrue(messenger instanceof Refreshable);
    assertEquals(0, countingAspect.getCalls());
    assertEquals("Hello World!", messenger.getMessage());
    assertEquals(1, countingAspect.getCalls());
    assertTrue(ctx.getBeansOfType(Messenger.class).values().contains(messenger));
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) CallCounter(org.springframework.scripting.CallCounter) 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 2 with CallCounter

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

the class GroovyScriptFactoryTests method testResourceScriptFromTag.

@Test
public void testResourceScriptFromTag() throws Exception {
    ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("groovy-with-xsd.xml", getClass());
    Messenger messenger = (Messenger) ctx.getBean("messenger");
    CallCounter countingAspect = (CallCounter) ctx.getBean("getMessageAspect");
    assertTrue(AopUtils.isAopProxy(messenger));
    assertFalse(messenger instanceof Refreshable);
    assertEquals(0, countingAspect.getCalls());
    assertEquals("Hello World!", messenger.getMessage());
    assertEquals(1, countingAspect.getCalls());
    ctx.close();
    assertEquals(-200, countingAspect.getCalls());
}
Also used : CallCounter(org.springframework.scripting.CallCounter) 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)2 Refreshable (org.springframework.aop.target.dynamic.Refreshable)2 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)2 CallCounter (org.springframework.scripting.CallCounter)2 ConfigurableMessenger (org.springframework.scripting.ConfigurableMessenger)2 Messenger (org.springframework.scripting.Messenger)2 ApplicationContext (org.springframework.context.ApplicationContext)1