Example #1
0
 @Test
 public void testAddOne() throws Exception {
   CountingPhaseInterceptor interceptor = new CountingPhaseInterceptor("phase1", "id1");
   control.replay();
   System.out.println(interceptor.getId());
   chain.add(interceptor);
   Iterator<Interceptor<? extends Message>> it = chain.iterator();
   Interceptor<? extends Message> next = it.next();
   assertSame(interceptor, next);
   assertTrue(!it.hasNext());
 }
Example #2
0
  /** 测试从指定拦截器开始执行 */
  @Test
  public void testDoInterceptorAfter() throws Exception {
    CountingPhaseInterceptor p1 = new CountingPhaseInterceptor("phase1", "p1");
    CountingPhaseInterceptor p2 = new CountingPhaseInterceptor("phase2", "p2");
    CountingPhaseInterceptor p3 = new CountingPhaseInterceptor("phase3", "p3");
    message.getInterceptorChain();
    EasyMock.expectLastCall().andReturn(chain).anyTimes();

    control.replay();
    chain.add(p1);
    chain.add(p2);
    chain.add(p3);
    chain.doInterceptAfter(message, p2.getId());
    assertEquals(0, p1.invoked);
    assertEquals(0, p2.invoked);
    assertEquals(1, p3.invoked);

    chain.reset();
    chain.doInterceptAt(message, p2.getId());
    assertEquals(0, p1.invoked);
    assertEquals(1, p2.invoked);
    assertEquals(2, p3.invoked);
  }