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();
}
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"));
}
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());
}
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());
}
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));
}
Aggregations