Package org.aopalliance.intercept

Examples of org.aopalliance.intercept.MethodInvocation


  public void testSunnyDayPathLogsCorrectly() throws Throwable {
    MockControl mockLog = MockControl.createControl(Log.class);
    Log log = (Log) mockLog.getMock();

    MockControl mockMethodInvocation = MockControl.createControl(MethodInvocation.class);
    MethodInvocation methodInvocation = (MethodInvocation) mockMethodInvocation.getMock();

    Method toString = String.class.getMethod("toString", new Class[]{});

    log.isTraceEnabled();
    mockLog.setReturnValue(true);
    methodInvocation.getMethod();
    mockMethodInvocation.setReturnValue(toString, 4);
    methodInvocation.getThis();
    mockMethodInvocation.setReturnValue(this, 2);
    log.trace("Some tracing output");
    mockLog.setMatcher(MockControl.ALWAYS_MATCHER);
    methodInvocation.proceed();
    mockMethodInvocation.setReturnValue(null);
    log.trace("Some more tracing output");
    mockLog.setMatcher(MockControl.ALWAYS_MATCHER);
    mockLog.setVoidCallable();
View Full Code Here


  public void testExceptionPathLogsCorrectly() throws Throwable {
    MockControl mockLog = MockControl.createControl(Log.class);
    Log log = (Log) mockLog.getMock();

    MockControl mockMethodInvocation = MockControl.createControl(MethodInvocation.class);
    MethodInvocation methodInvocation = (MethodInvocation) mockMethodInvocation.getMock();

    Method toString = String.class.getMethod("toString", new Class[]{});

    log.isTraceEnabled();
    mockLog.setReturnValue(true);
    methodInvocation.getMethod();
    mockMethodInvocation.setReturnValue(toString, 4);
    methodInvocation.getThis();
    mockMethodInvocation.setReturnValue(this, 2);
    log.trace("Some tracing output");
    mockLog.setMatcher(MockControl.ALWAYS_MATCHER);
    methodInvocation.proceed();
    IllegalArgumentException exception = new IllegalArgumentException();
    mockMethodInvocation.setThrowable(exception);
    log.trace("Some more tracing output", exception);
    mockLog.setMatcher(MockControl.ALWAYS_MATCHER);
    mockLog.setVoidCallable();
View Full Code Here

  public void testSunnyDayPathLogsCorrectlyWithPrettyMuchAllPlaceholdersMatching() throws Throwable {
    MockControl mockLog = MockControl.createControl(Log.class);
    Log log = (Log) mockLog.getMock();

    MockControl mockMethodInvocation = MockControl.createControl(MethodInvocation.class);
    MethodInvocation methodInvocation = (MethodInvocation) mockMethodInvocation.getMock();

    Method toString = String.class.getMethod("toString", new Class[0]);
    Object[] arguments = new Object[]{"$ One \\$", new Long(2)};

    log.isTraceEnabled();
    mockLog.setReturnValue(true);
    methodInvocation.getMethod();
    mockMethodInvocation.setReturnValue(toString, 7);
    methodInvocation.getThis();
    mockMethodInvocation.setReturnValue(this, 2);
    methodInvocation.getArguments();
    mockMethodInvocation.setReturnValue(arguments, 2);
    log.trace("Some tracing output");
    mockLog.setMatcher(MockControl.ALWAYS_MATCHER);
    methodInvocation.proceed();
    mockMethodInvocation.setReturnValue("Hello!");
    log.trace("Some more tracing output");
    mockLog.setMatcher(MockControl.ALWAYS_MATCHER);
    mockLog.setVoidCallable();
View Full Code Here

* @author Rod Johnson
*/
public abstract class ExposedInvocationTestBean extends TestBean {

  public String getName() {
    MethodInvocation invocation = ExposeInvocationInterceptor.currentInvocation();
    assertions(invocation);
    return super.getName();
  }
View Full Code Here

    assertions(invocation);
    return super.getName();
  }

  public void absquatulate() {
    MethodInvocation invocation = ExposeInvocationInterceptor.currentInvocation();
    assertions(invocation);
    super.absquatulate();
  }
View Full Code Here

    MethodInterceptor twoBirthdayInterceptor = new MethodInterceptor() {
      public Object invoke(MethodInvocation mi) throws Throwable {
        // Clone the invocation to proceed three times
        // "The Moor's Last Sigh": this technology can cause premature aging
        MethodInvocation clone1 = ((ReflectiveMethodInvocation) mi).invocableClone();
        MethodInvocation clone2 = ((ReflectiveMethodInvocation) mi).invocableClone();
        clone1.proceed();
        clone2.proceed();
        return mi.proceed();
      }
    };
    StaticMethodMatcherPointcutAdvisor advisor = new StaticMethodMatcherPointcutAdvisor(twoBirthdayInterceptor) {
      public boolean matches(Method m, Class targetClass) {
View Full Code Here

    /**
     * Changes the name, then changes it back.
     */
    MethodInterceptor nameReverter = new MethodInterceptor() {
      public Object invoke(MethodInvocation mi) throws Throwable {
        MethodInvocation clone = ((ReflectiveMethodInvocation) mi).invocableClone();
        String oldName = ((ITestBean) mi.getThis()).getName();
        clone.getArguments()[0] = oldName;
        // Original method invocation should be unaffected by changes to argument list of clone
        mi.proceed();
        return clone.proceed();
      }
    };

    class NameSaver implements MethodInterceptor {
      private List names = new LinkedList();
View Full Code Here

  public void testInterceptorWithNoSessionBoundAndNoSynchronizations() throws Throwable {
    MockControl sessionControl = MockControl.createControl(Session.class);
    Session session = (Session) sessionControl.getMock();
    MockControl methodInvocationControl = MockControl.createControl(MethodInvocation.class);
    MethodInvocation methodInvocation = (MethodInvocation) methodInvocationControl.getMock();

    SessionFactory factory = new SingleSessionFactory(session);

    TopLinkInterceptor interceptor = new TopLinkInterceptor();
    interceptor.setSessionFactory(factory);

    methodInvocation.proceed();
    methodInvocationControl.setReturnValue(null, 1);
    session.release();
    sessionControl.setVoidCallable(1);

    methodInvocationControl.replay();
View Full Code Here

  public void testInterceptorWithNoSessionBoundAndSynchronizationsActive() {
    MockControl sessionControl = MockControl.createControl(Session.class);
    Session session = (Session) sessionControl.getMock();
    MockControl methodInvocationControl = MockControl.createControl(MethodInvocation.class);
    MethodInvocation methodInvocation = (MethodInvocation) methodInvocationControl.getMock();

    SessionFactory factory = new SingleSessionFactory(session);

    TopLinkInterceptor interceptor = new TopLinkInterceptor();
    interceptor.setSessionFactory(factory);

    try {
      methodInvocation.proceed();
    }
    catch (Throwable e) {
      fail();
    }
    methodInvocationControl.setReturnValue(null, 1);
View Full Code Here

                // Fault message
                } else if (exchange.getFault() != null) {
                    // TODO: find a way to send it back to the bean before setting the DONE status
                    done(exchange);
                } else {
                    MethodInvocation invocation = getMethodInvocationStrategy().createInvocation(
                            req.getBean(), getBeanInfo(), exchange, this);
                    if (invocation == null) {
                        throw new UnknownMessageExchangeTypeException(exchange, this);
                    }
                    try {
                        invocation.proceed();
                    } catch (Exception e) {
                        throw e;
                    } catch (Throwable throwable) {
                        throw new MethodInvocationFailedException(req.getBean(), invocation, exchange, this, throwable);
                    }
View Full Code Here

TOP

Related Classes of org.aopalliance.intercept.MethodInvocation

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.