Search in sources :

Example 21 with ProxyFactory

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();
}
Also used : Context(javax.naming.Context) ProxyFactory(org.springframework.aop.framework.ProxyFactory) CreateException(javax.ejb.CreateException) NamingException(javax.naming.NamingException)

Example 22 with ProxyFactory

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)));
}
Also used : ProxyFactory(org.springframework.aop.framework.ProxyFactory) NumberStyleFormatter(org.springframework.format.number.NumberStyleFormatter) Test(org.junit.Test)

Example 23 with ProxyFactory

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));
}
Also used : ProxyFactory(org.springframework.aop.framework.ProxyFactory) Test(org.junit.Test)

Example 24 with ProxyFactory

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);
}
Also used : NopInterceptor(org.springframework.tests.aop.interceptor.NopInterceptor) ProxyFactory(org.springframework.aop.framework.ProxyFactory) HashMap(java.util.HashMap) IJmxTestBean(org.springframework.jmx.IJmxTestBean) JmxTestBean(org.springframework.jmx.JmxTestBean) IJmxTestBean(org.springframework.jmx.IJmxTestBean) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Example 25 with ProxyFactory

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");
}
Also used : TextMessage(javax.jms.TextMessage) StubTextMessage(org.springframework.jms.StubTextMessage) Message(javax.jms.Message) ProxyFactory(org.springframework.aop.framework.ProxyFactory) StubTextMessage(org.springframework.jms.StubTextMessage) Test(org.junit.Test)

Aggregations

ProxyFactory (org.springframework.aop.framework.ProxyFactory)78 Test (org.junit.Test)48 ITestBean (org.springframework.tests.sample.beans.ITestBean)20 TestBean (org.springframework.tests.sample.beans.TestBean)20 TimeStamped (org.springframework.tests.TimeStamped)8 INestedTestBean (org.springframework.tests.sample.beans.INestedTestBean)8 NestedTestBean (org.springframework.tests.sample.beans.NestedTestBean)8 Method (java.lang.reflect.Method)6 HashMap (java.util.HashMap)5 MethodBeforeAdvice (org.springframework.aop.MethodBeforeAdvice)4 NopInterceptor (org.springframework.tests.aop.interceptor.NopInterceptor)4 Context (javax.naming.Context)3 TargetSource (org.springframework.aop.TargetSource)3 Advised (org.springframework.aop.framework.Advised)3 DefaultPointcutAdvisor (org.springframework.aop.support.DefaultPointcutAdvisor)3 IOException (java.io.IOException)2 EJBLocalObject (javax.ejb.EJBLocalObject)2 Message (javax.jms.Message)2 TextMessage (javax.jms.TextMessage)2 ObjectName (javax.management.ObjectName)2