コード例 #1
0
  public void testPropagate() throws Exception {
    Transaction trx = EasyMock.createMock(Transaction.class);
    EasyMock.expect(tm.getTransaction()).andReturn(trx);

    TxInterceptor interceptor = new TxInterceptor(tm, TxAction.PROPAGATE, monitor);
    interceptor.setNext(next);
    EasyMock.expect(next.invoke(EasyMock.isA(Message.class))).andReturn(message);
    EasyMock.replay(tm, next);

    interceptor.invoke(message);

    EasyMock.verify(tm, next);
  }
コード例 #2
0
  public void testAlreadyBegunNoCommit() throws Exception {
    Transaction trx = EasyMock.createMock(Transaction.class);
    EasyMock.expect(tm.getTransaction()).andReturn(trx);
    EasyMock.expect(next.invoke(EasyMock.isA(Message.class))).andReturn(message);
    EasyMock.replay(trx, tm, next);

    TxInterceptor interceptor = new TxInterceptor(tm, TxAction.BEGIN, monitor);
    interceptor.setNext(next);

    interceptor.invoke(message);

    EasyMock.verify(trx, tm, next);
  }
コード例 #3
0
  public void testNoRollbackOnFaultWhenNotBegun() throws Exception {
    Message fault = new MessageImpl("", true, null);
    Transaction trx = EasyMock.createMock(Transaction.class);
    EasyMock.expect(tm.getTransaction()).andReturn(trx);
    EasyMock.expect(next.invoke(EasyMock.isA(Message.class))).andReturn(fault);
    EasyMock.replay(tm, next);

    TxInterceptor interceptor = new TxInterceptor(tm, TxAction.BEGIN, monitor);
    interceptor.setNext(next);

    interceptor.invoke(message);

    EasyMock.verify(tm, next);
  }
コード例 #4
0
  public void testBeginCommit() throws Exception {
    EasyMock.expect(tm.getTransaction()).andReturn(null);
    EasyMock.expect(tm.getStatus()).andReturn(Status.STATUS_ACTIVE);
    EasyMock.expect(next.invoke(EasyMock.isA(Message.class))).andReturn(message);
    tm.begin();
    tm.commit();
    EasyMock.replay(tm, next);

    TxInterceptor interceptor = new TxInterceptor(tm, TxAction.BEGIN, monitor);
    interceptor.setNext(next);

    interceptor.invoke(message);

    EasyMock.verify(tm, next);
  }
コード例 #5
0
  public void testRollbackOnFault() throws Exception {
    Message fault = new MessageImpl("", true, null);
    EasyMock.expect(tm.getTransaction()).andReturn(null);
    EasyMock.expect(next.invoke(EasyMock.isA(Message.class))).andReturn(fault);
    tm.begin();
    tm.rollback();
    EasyMock.replay(tm, next);

    TxInterceptor interceptor = new TxInterceptor(tm, TxAction.BEGIN, monitor);
    interceptor.setNext(next);

    interceptor.invoke(message);

    EasyMock.verify(tm, next);
  }
コード例 #6
0
  public void testNoRollbackOnThrownExceptionWhenNotBegun() throws Exception {
    Transaction trx = EasyMock.createMock(Transaction.class);
    EasyMock.expect(tm.getTransaction()).andReturn(trx);
    EasyMock.expect(next.invoke(EasyMock.isA(Message.class))).andThrow(new MockException());
    EasyMock.replay(trx, tm, next);

    try {
      TxInterceptor interceptor = new TxInterceptor(tm, TxAction.BEGIN, monitor);
      interceptor.setNext(next);

      interceptor.invoke(message);
      fail();
    } catch (MockException e) {
      // expected
    }

    EasyMock.verify(trx, tm, next);
  }
コード例 #7
0
 public Object intercept(Object object, Method method, Object[] args, MethodProxy proxy)
     throws Throwable {
   WorkContext context = WorkContextTunnel.getThreadWorkContext();
   authenticate(context);
   Message message = new MessageImpl(args, false, context);
   InvocationChain invocationChain = invocationChains.get(method.getName());
   if (invocationChain != null) {
     Interceptor headInterceptor = invocationChain.getHeadInterceptor();
     Message ret = headInterceptor.invoke(message);
     if (ret.isFault()) {
       throw (Throwable) ret.getBody();
     } else {
       return ret.getBody();
     }
   } else {
     return null;
   }
 }
コード例 #8
0
  public void testRollbackOnThrownException() throws Exception {
    EasyMock.expect(tm.getTransaction()).andReturn(null);
    EasyMock.expect(next.invoke(EasyMock.isA(Message.class))).andThrow(new MockException());
    tm.begin();
    tm.rollback();
    EasyMock.replay(tm, next);

    try {
      TxInterceptor interceptor = new TxInterceptor(tm, TxAction.BEGIN, monitor);
      interceptor.setNext(next);

      interceptor.invoke(message);
      fail();
    } catch (MockException e) {
      // expected
    }

    EasyMock.verify(tm, next);
  }