Search in sources :

Example 1 with FooService

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

the class ComponentScanParserScopedProxyTests method testInterfacesScopedProxy.

@Test
public void testInterfacesScopedProxy() throws Exception {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("org/springframework/context/annotation/scopedProxyInterfacesTests.xml");
    context.getBeanFactory().registerScope("myScope", new SimpleMapScope());
    // should cast to the interface
    FooService bean = (FooService) context.getBean("scopedProxyTestBean");
    // should be dynamic proxy
    assertTrue(AopUtils.isJdkDynamicProxy(bean));
    // test serializability
    assertEquals("bar", bean.foo(1));
    FooService deserialized = (FooService) SerializationTestUtils.serializeAndDeserialize(bean);
    assertNotNull(deserialized);
    assertEquals("bar", deserialized.foo(1));
    context.close();
}
Also used : FooService(example.scannable.FooService) SimpleMapScope(org.springframework.tests.context.SimpleMapScope) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) Test(org.junit.Test)

Example 2 with FooService

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

the class ComponentScanWithBasePackagesAndValueAlias method withScopedProxy.

@Test
public void withScopedProxy() throws IOException, ClassNotFoundException {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
    ctx.register(ComponentScanWithScopedProxy.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));
    // test serializability
    assertThat(bean.foo(1), equalTo("bar"));
    FooService deserialized = (FooService) SerializationTestUtils.serializeAndDeserialize(bean);
    assertThat(deserialized, notNullValue());
    assertThat(deserialized.foo(1), equalTo("bar"));
}
Also used : FooService(example.scannable.FooService) SimpleMapScope(org.springframework.tests.context.SimpleMapScope) Test(org.junit.Test)

Example 3 with FooService

use of example.scannable.FooService 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 4 with FooService

use of example.scannable.FooService 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 5 with FooService

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

the class ComponentScanWithBasePackagesAndValueAlias method withScopedProxyThroughRegex.

@Test
public void withScopedProxyThroughRegex() throws IOException, ClassNotFoundException {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
    ctx.register(ComponentScanWithScopedProxyThroughRegex.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)

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