Search in sources :

Example 6 with FooService

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

the class ComponentScanWithBasePackagesAndValueAlias method withScopedProxyThroughAspectJPattern.

@Test
public void withScopedProxyThroughAspectJPattern() throws IOException, ClassNotFoundException {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
    ctx.register(ComponentScanWithScopedProxyThroughAspectJPattern.class);
    ctx.getBeanFactory().registerScope("myScope", new SimpleMapScope());
    ctx.refresh();
    // should cast to the interface
    FooService bean = (FooService) ctx.getBean("scopedProxyTestBean");
    // should be dynamic proxy
    assertThat(AopUtils.isJdkDynamicProxy(bean), is(true));
}
Also used : FooService(example.scannable.FooService) SimpleMapScope(org.springframework.tests.context.SimpleMapScope) Test(org.junit.Test)

Example 7 with FooService

use of example.scannable.FooService 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)7 Test (org.junit.Test)6 SimpleMapScope (org.springframework.tests.context.SimpleMapScope)4 ServiceInvocationCounter (example.scannable.ServiceInvocationCounter)3 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)3 FutureTask (java.util.concurrent.FutureTask)1