use of org.springframework.aop.framework.ProxyFactory in project spring-framework by spring-projects.
the class LocalSlsbInvokerInterceptorTests method testException.
private void testException(Exception expected) throws Exception {
LocalInterfaceWithBusinessMethods ejb = mock(LocalInterfaceWithBusinessMethods.class);
given(ejb.targetMethod()).willThrow(expected);
String jndiName = "foobar";
Context mockContext = mockContext(jndiName, ejb);
LocalSlsbInvokerInterceptor si = configuredInterceptor(mockContext, jndiName);
ProxyFactory pf = new ProxyFactory(new Class<?>[] { LocalInterfaceWithBusinessMethods.class });
pf.addAdvice(si);
LocalInterfaceWithBusinessMethods target = (LocalInterfaceWithBusinessMethods) pf.getProxy();
try {
target.targetMethod();
fail("Should have thrown exception");
} catch (Exception thrown) {
assertTrue(thrown == expected);
}
verify(mockContext).close();
}
use of org.springframework.aop.framework.ProxyFactory in project spring-framework by spring-projects.
the class FormattingConversionServiceTests method proxiedFormatter.
@Test
public void proxiedFormatter() throws ParseException {
Formatter<?> formatter = new NumberStyleFormatter();
formattingService.addFormatter((Formatter<?>) new ProxyFactory(formatter).getProxy());
assertNull(formattingService.convert(null, TypeDescriptor.valueOf(String.class), TypeDescriptor.valueOf(Integer.class)));
}
use of org.springframework.aop.framework.ProxyFactory in project spring-framework by spring-projects.
the class FormattingConversionServiceTests method proxiedConverter.
@Test
public void proxiedConverter() {
Converter<?, ?> converter = new IntegerConverter();
formattingService.addConverter((Converter<?, ?>) new ProxyFactory(converter).getProxy());
assertEquals(Integer.valueOf(1), formattingService.convert("1", Integer.class));
}
use of org.springframework.aop.framework.ProxyFactory in project spring-framework by spring-projects.
the class MBeanExporterTests method testExportJdkProxy.
@Test
public void testExportJdkProxy() throws Exception {
JmxTestBean bean = new JmxTestBean();
bean.setName("Rob Harrop");
ProxyFactory factory = new ProxyFactory();
factory.setTarget(bean);
factory.addAdvice(new NopInterceptor());
factory.setInterfaces(IJmxTestBean.class);
IJmxTestBean proxy = (IJmxTestBean) factory.getProxy();
String name = "bean:mmm=whatever";
Map<String, Object> beans = new HashMap<>();
beans.put(name, proxy);
MBeanExporter exporter = new MBeanExporter();
exporter.setServer(server);
exporter.setBeans(beans);
exporter.registerBeans();
ObjectName oname = ObjectName.getInstance(name);
Object nameValue = server.getAttribute(oname, "Name");
assertEquals("Rob Harrop", nameValue);
}
use of org.springframework.aop.framework.ProxyFactory in project spring-framework by spring-projects.
the class JmsListenerContainerFactoryIntegrationTests method parameterAnnotationWithJdkProxy.
@Test
public void parameterAnnotationWithJdkProxy() throws JMSException {
ProxyFactory pf = new ProxyFactory(sample);
listener = (JmsEndpointSampleInterface) pf.getProxy();
containerFactory.setMessageConverter(new UpperCaseMessageConverter());
MethodJmsListenerEndpoint endpoint = createDefaultMethodJmsEndpoint(JmsEndpointSampleInterface.class, "handleIt", String.class, String.class);
Message message = new StubTextMessage("foo-bar");
message.setStringProperty("my-header", "my-value");
invokeListener(endpoint, message);
assertListenerMethodInvocation("handleIt");
}
Aggregations