Search in sources :

Example 1 with ServiceInvocationCounter

use of example.scannable.ServiceInvocationCounter in project spring-framework by spring-projects.

the class EnableAspectJAutoProxyTests method aspectIsApplied.

private void aspectIsApplied(ApplicationContext ctx) {
    FooService fooService = ctx.getBean(FooService.class);
    ServiceInvocationCounter counter = ctx.getBean(ServiceInvocationCounter.class);
    assertEquals(0, counter.getCount());
    assertTrue(fooService.isInitCalled());
    assertEquals(1, counter.getCount());
    String value = fooService.foo(1);
    assertEquals("bar", value);
    assertEquals(2, counter.getCount());
    fooService.foo(1);
    assertEquals(3, counter.getCount());
}
Also used : FooService(example.scannable.FooService) ServiceInvocationCounter(example.scannable.ServiceInvocationCounter)

Example 2 with ServiceInvocationCounter

use of example.scannable.ServiceInvocationCounter in project spring-framework by spring-projects.

the class SimpleScanTests method testFooService.

@Test
public void testFooService() throws Exception {
    ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(getConfigLocations(), getClass());
    FooService fooService = (FooService) ctx.getBean("fooServiceImpl");
    ServiceInvocationCounter serviceInvocationCounter = (ServiceInvocationCounter) ctx.getBean("serviceInvocationCounter");
    assertEquals(0, serviceInvocationCounter.getCount());
    assertTrue(fooService.isInitCalled());
    assertEquals(1, serviceInvocationCounter.getCount());
    String value = fooService.foo(1);
    assertEquals("bar", value);
    assertEquals(2, serviceInvocationCounter.getCount());
    fooService.foo(1);
    assertEquals(3, serviceInvocationCounter.getCount());
}
Also used : FooService(example.scannable.FooService) ServiceInvocationCounter(example.scannable.ServiceInvocationCounter) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) Test(org.junit.Test)

Example 3 with ServiceInvocationCounter

use of example.scannable.ServiceInvocationCounter in project spring-framework by spring-projects.

the class SimpleConfigTests method testFooService.

@Test
public void testFooService() throws Exception {
    ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(getConfigLocations(), getClass());
    FooService fooService = ctx.getBean("fooServiceImpl", FooService.class);
    ServiceInvocationCounter serviceInvocationCounter = ctx.getBean("serviceInvocationCounter", ServiceInvocationCounter.class);
    String value = fooService.foo(1);
    assertEquals("bar", value);
    Future<?> future = fooService.asyncFoo(1);
    assertTrue(future instanceof FutureTask);
    assertEquals("bar", future.get());
    assertEquals(2, serviceInvocationCounter.getCount());
    fooService.foo(1);
    assertEquals(3, serviceInvocationCounter.getCount());
}
Also used : FooService(example.scannable.FooService) ServiceInvocationCounter(example.scannable.ServiceInvocationCounter) FutureTask(java.util.concurrent.FutureTask) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) Test(org.junit.Test)

Aggregations

FooService (example.scannable.FooService)3 ServiceInvocationCounter (example.scannable.ServiceInvocationCounter)3 Test (org.junit.Test)2 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)2 FutureTask (java.util.concurrent.FutureTask)1