Package org.springframework.beans

Examples of org.springframework.beans.ITestBean


    this.getAgeMethod = ITestBean.class.getMethod("getAge", new Class[0]);
    this.setAgeMethod = ITestBean.class.getMethod("setAge", new Class[] {int.class});
  }

  public void testIsProxy() throws Exception {
    ITestBean bean = getTestBean();
    assertTrue("testBean is not a proxy", AopUtils.isAopProxy(bean));
  }
View Full Code Here


    ITestBean bean = getTestBean();
    assertTrue("testBean is not a proxy", AopUtils.isAopProxy(bean));
  }

  public void testInvokeTransactional() 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);
View Full Code Here

    if (explicitClassLoader) {
      ((BeanClassLoaderAware) pfb.getHttpInvokerRequestExecutor()).setBeanClassLoader(getClass().getClassLoader());
    }

    pfb.afterPropertiesSet();
    ITestBean proxy = (ITestBean) pfb.getObject();
    assertEquals("myname", proxy.getName());
    assertEquals(99, proxy.getAge());
    proxy.setAge(50);
    assertEquals(50, proxy.getAge());
    proxy.setStringArray(new String[] {"str1", "str2"});
    assertTrue(Arrays.equals(new String[] {"str1", "str2"}, proxy.getStringArray()));

    try {
      proxy.exceptional(new IllegalStateException());
      fail("Should have thrown IllegalStateException");
    }
    catch (IllegalStateException ex) {
      // expected
    }
    try {
      proxy.exceptional(new IllegalAccessException());
      fail("Should have thrown IllegalAccessException");
    }
    catch (IllegalAccessException ex) {
      // expected
    }
View Full Code Here

        throw new IOException("argh");
      }
    });

    pfb.afterPropertiesSet();
    ITestBean proxy = (ITestBean) pfb.getObject();
    try {
      proxy.setAge(50);
      fail("Should have thrown RemoteAccessException");
    }
    catch (RemoteAccessException ex) {
      // expected
      assertTrue(ex.getCause() instanceof IOException);
View Full Code Here

        return new GZIPInputStream(is);
      }
    });

    pfb.afterPropertiesSet();
    ITestBean proxy = (ITestBean) pfb.getObject();
    assertEquals("myname", proxy.getName());
    assertEquals(99, proxy.getAge());
    proxy.setAge(50);
    assertEquals(50, proxy.getAge());

    try {
      proxy.exceptional(new IllegalStateException());
      fail("Should have thrown IllegalStateException");
    }
    catch (IllegalStateException ex) {
      // expected
    }
    try {
      proxy.exceptional(new IllegalAccessException());
      fail("Should have thrown IllegalAccessException");
    }
    catch (IllegalAccessException ex) {
      // expected
    }
View Full Code Here

        return ((TestRemoteInvocationResultWrapper) obj).remoteInvocationResult;
      }
    });

    pfb.afterPropertiesSet();
    ITestBean proxy = (ITestBean) pfb.getObject();
    assertEquals("myname", proxy.getName());
    assertEquals(99, proxy.getAge());
    proxy.setAge(50);
    assertEquals(50, proxy.getAge());

    try {
      proxy.exceptional(new IllegalStateException());
      fail("Should have thrown IllegalStateException");
    }
    catch (IllegalStateException ex) {
      // expected
    }
    try {
      proxy.exceptional(new IllegalAccessException());
      fail("Should have thrown IllegalAccessException");
    }
    catch (IllegalAccessException ex) {
      // expected
    }
View Full Code Here

        jp.toLongString();
       
        assertSame(target, AbstractAspectJAdvice.currentJoinPoint().getTarget());
        assertFalse(AopUtils.isAopProxy(AbstractAspectJAdvice.currentJoinPoint().getTarget()));
       
        ITestBean thisProxy = (ITestBean) AbstractAspectJAdvice.currentJoinPoint().getThis();
        assertTrue(AopUtils.isAopProxy(AbstractAspectJAdvice.currentJoinPoint().getThis()));
       
        assertNotSame(target, thisProxy);
       
        // Check getting again doesn't cause a problem
        assertSame(thisProxy, AbstractAspectJAdvice.currentJoinPoint().getThis());
       
        // Try reentrant call--will go through this advice.
        // Be sure to increment depth to avoid infinite recursion
        if (depth++ == 0) {
          // Check that toString doesn't cause a problem
          thisProxy.toString();
          // Change age, so this will be returned by invocation
          thisProxy.setAge(newAge);
          assertEquals(newAge, thisProxy.getAge());
        }
       
        assertSame(AopContext.currentProxy(), thisProxy);
        assertSame(target, raw);
       
        assertSame(method.getName(), AbstractAspectJAdvice.currentJoinPoint().getSignature().getName());
        assertEquals(method.getModifiers(), AbstractAspectJAdvice.currentJoinPoint().getSignature().getModifiers());
       
        MethodSignature msig = (MethodSignature) AbstractAspectJAdvice.currentJoinPoint().getSignature();
        assertSame("Return same MethodSignature repeatedly", msig, AbstractAspectJAdvice.currentJoinPoint().getSignature());
        assertSame("Return same JoinPoint repeatedly", AbstractAspectJAdvice.currentJoinPoint(), AbstractAspectJAdvice.currentJoinPoint());
        assertEquals(method.getDeclaringClass(), msig.getDeclaringType());
        assertTrue(Arrays.equals(method.getParameterTypes(), msig.getParameterTypes()));
        assertEquals(method.getReturnType(), msig.getReturnType());
        assertTrue(Arrays.equals(method.getExceptionTypes(), msig.getExceptionTypes()));
        try {
          msig.getParameterNames();
          fail("Can't determine parameter names");
        }
        catch (UnsupportedOperationException ex) {
          // Expected
        }
        msig.toLongString();
        msig.toShortString();
      }
    });
    ITestBean itb = (ITestBean) pf.getProxy();
    // Any call will do
    assertEquals("Advice reentrantly set age", newAge, itb.getAge());
  }
View Full Code Here

        catch (UnsupportedOperationException ex) {
          // Expected
        }
      }
    });
    ITestBean itb = (ITestBean) pf.getProxy();
    // Any call will do
    itb.getAge();
  }
View Full Code Here

        assertEquals(ProceedingJoinPoint.METHOD_EXECUTION, staticPart.getKind());
        assertSame(AbstractAspectJAdvice.currentJoinPoint().getSignature(), staticPart.getSignature());
        assertEquals(AbstractAspectJAdvice.currentJoinPoint().getSourceLocation(), staticPart.getSourceLocation());
      }
    });
    ITestBean itb = (ITestBean) pf.getProxy();
    // Any call will do
    itb.getAge();
  }
View Full Code Here

    //miControl.setReturnValue(new Integer(age));
    // Have disabled strong argument checking
    miControl.setDefaultReturnValue(new Integer(age));
    miControl.replay();

    ITestBean tb = (ITestBean) aop.getProxy();
    assertTrue("correct return value", tb.getAge() == age);
    miControl.verify();
  }
View Full Code Here

TOP

Related Classes of org.springframework.beans.ITestBean

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.