// @Test public void testSingleInterceptorFail() throws Exception { CountingPhaseInterceptor p = new CountingPhaseInterceptor("phase1", "p1"); setUpPhaseInterceptorInvocations(p, true, true); control.replay(); chain.add(p); chain.doIntercept(message); }
/** 测试拦截器执行 */ @Test public void testDoInterceptor() 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.doIntercept(message); assertEquals(1, p1.invoked); assertEquals(1, p2.invoked); assertEquals(1, p3.invoked); }
@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()); }
/** 测试在同一个阶段的先后顺序 */ @Test public void testAddTwoAtSamePhase() throws Exception { CountingPhaseInterceptor p1 = new CountingPhaseInterceptor("phase1", "p1"); Set<String> after = new HashSet<String>(); after.add("p1"); CountingPhaseInterceptor p2 = new CountingPhaseInterceptor("phase1", "p2", null, after); chain.add(p2); chain.add(p1); Iterator<Interceptor<? extends Message>> it = chain.iterator(); assertSame(p1, it.next()); assertSame(p2, it.next()); assertTrue(!it.hasNext()); }
@Override public void handleMessage(Message m) { insertionChain.add(insertionInterceptor); invoked++; }