use of org.springframework.tests.sample.beans.ITestBean in project spring-framework by spring-projects.
the class HttpInvokerTests method httpInvokerWithSpecialLocalMethods.
@Test
public void httpInvokerWithSpecialLocalMethods() throws Exception {
String serviceUrl = "http://myurl";
HttpInvokerProxyFactoryBean pfb = new HttpInvokerProxyFactoryBean();
pfb.setServiceInterface(ITestBean.class);
pfb.setServiceUrl(serviceUrl);
pfb.setHttpInvokerRequestExecutor(new HttpInvokerRequestExecutor() {
@Override
public RemoteInvocationResult executeRequest(HttpInvokerClientConfiguration config, RemoteInvocation invocation) throws IOException {
throw new IOException("argh");
}
});
pfb.afterPropertiesSet();
ITestBean proxy = (ITestBean) pfb.getObject();
// shouldn't go through to remote service
assertTrue(proxy.toString().indexOf("HTTP invoker") != -1);
assertTrue(proxy.toString().indexOf(serviceUrl) != -1);
assertEquals(proxy.hashCode(), proxy.hashCode());
assertTrue(proxy.equals(proxy));
// should go through
try {
proxy.setAge(50);
fail("Should have thrown RemoteAccessException");
} catch (RemoteAccessException ex) {
// expected
assertTrue(ex.getCause() instanceof IOException);
}
}
use of org.springframework.tests.sample.beans.ITestBean in project spring-framework by spring-projects.
the class RequestScopedProxyTests method testGetFromScopeThroughDynamicProxy.
@Test
public void testGetFromScopeThroughDynamicProxy() throws Exception {
String name = "requestScopedProxy";
ITestBean bean = (ITestBean) this.beanFactory.getBean(name);
assertTrue(AopUtils.isJdkDynamicProxy(bean));
MockHttpServletRequest request = new MockHttpServletRequest();
RequestAttributes requestAttributes = new ServletRequestAttributes(request);
RequestContextHolder.setRequestAttributes(requestAttributes);
try {
assertNull(request.getAttribute("scopedTarget." + name));
assertEquals("scoped", bean.getName());
assertNotNull(request.getAttribute("scopedTarget." + name));
TestBean target = (TestBean) request.getAttribute("scopedTarget." + name);
assertEquals(TestBean.class, target.getClass());
assertEquals("scoped", target.getName());
assertSame(bean, this.beanFactory.getBean(name));
assertEquals(bean.toString(), target.toString());
} finally {
RequestContextHolder.setRequestAttributes(null);
}
}
use of org.springframework.tests.sample.beans.ITestBean in project spring-framework by spring-projects.
the class TxNamespaceHandlerTests method isProxy.
@Test
public void isProxy() throws Exception {
ITestBean bean = getTestBean();
assertTrue("testBean is not a proxy", AopUtils.isAopProxy(bean));
}
use of org.springframework.tests.sample.beans.ITestBean in project spring-framework by spring-projects.
the class TxNamespaceHandlerTests method invokeTransactional.
@Test
public void invokeTransactional() throws Exception {
ITestBean testBean = getTestBean();
CallCountingTransactionManager ptm = (CallCountingTransactionManager) context.getBean("transactionManager");
// try with transactional
assertEquals("Should not have any started transactions", 0, ptm.begun);
testBean.getName();
assertTrue(ptm.lastDefinition.isReadOnly());
assertEquals("Should have 1 started transaction", 1, ptm.begun);
assertEquals("Should have 1 committed transaction", 1, ptm.commits);
// try with non-transaction
testBean.haveBirthday();
assertEquals("Should not have started another transaction", 1, ptm.begun);
// try with exceptional
try {
testBean.exceptional(new IllegalArgumentException("foo"));
fail("Should NEVER get here");
} catch (Throwable throwable) {
assertEquals("Should have another started transaction", 2, ptm.begun);
assertEquals("Should have 1 rolled back transaction", 1, ptm.rollbacks);
}
}
use of org.springframework.tests.sample.beans.ITestBean in project spring-framework by spring-projects.
the class AbstractTransactionAspectTests method noTransaction.
@Test
public void noTransaction() throws Exception {
PlatformTransactionManager ptm = mock(PlatformTransactionManager.class);
TestBean tb = new TestBean();
TransactionAttributeSource tas = new MapTransactionAttributeSource();
// All the methods in this class use the advised() template method
// to obtain a transaction object, configured with the given PlatformTransactionManager
// and transaction attribute source
ITestBean itb = (ITestBean) advised(tb, ptm, tas);
checkTransactionStatus(false);
itb.getName();
checkTransactionStatus(false);
// expect no calls
verifyZeroInteractions(ptm);
}
Aggregations