01: /*
02: * Copyright 2005-2006 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
05: * in compliance with the License. You may obtain a copy of the License at
06: *
07: * http://www.apache.org/licenses/LICENSE-2.0
08: *
09: * Unless required by applicable law or agreed to in writing, software distributed under the License
10: * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11: * or implied. See the License for the specific language governing permissions and limitations under
12: * the License.
13: */
14:
15: package org.strecks.interceptor.internal;
16:
17: import static org.testng.Assert.assertEquals;
18:
19: import java.util.Iterator;
20: import java.util.List;
21:
22: import org.strecks.interceptor.ActionLoggingInterceptor;
23: import org.strecks.interceptor.AfterInterceptor;
24: import org.strecks.interceptor.BeforeInterceptor;
25: import org.strecks.interceptor.HistoryRecorder;
26: import org.strecks.interceptor.RedirectBeforeInterceptor;
27: import org.strecks.interceptor.internal.impl.EmptyInterceptorAction;
28: import org.strecks.interceptor.internal.impl.InterceptorAction;
29: import org.strecks.interceptor.internal.impl.InterceptorAwareImpl;
30: import org.testng.annotations.Test;
31:
32: /**
33: * @author Phil Zoio
34: */
35: public class TestActionBeanInterceptorReader {
36:
37: @Test
38: public void testInterceptorReader() {
39:
40: ActionBeanInterceptorReader reader = new ActionBeanInterceptorReader();
41: assert true == reader.readAnnotations(InterceptorAction.class);
42:
43: InterceptorAwareImpl interceptorAwareImpl = new InterceptorAwareImpl();
44: reader.populateController(interceptorAwareImpl);
45:
46: List<BeforeInterceptor> beforeInterceptors = interceptorAwareImpl
47: .getBeforeInterceptors();
48: List<AfterInterceptor> afterInterceptors = interceptorAwareImpl
49: .getAfterInterceptors();
50: assertEquals(2, beforeInterceptors.size());
51: assertEquals(2, afterInterceptors.size());
52:
53: for (BeforeInterceptor interceptor : beforeInterceptors) {
54: assert interceptor instanceof BeforeInterceptor;
55: }
56:
57: for (AfterInterceptor interceptor : afterInterceptors) {
58: assert interceptor instanceof AfterInterceptor;
59: }
60:
61: Iterator<BeforeInterceptor> beforeIterator = beforeInterceptors
62: .iterator();
63: Iterator<AfterInterceptor> afterIterator = afterInterceptors
64: .iterator();
65:
66: assert beforeIterator.next() instanceof RedirectBeforeInterceptor;
67: assert beforeIterator.next() instanceof ActionLoggingInterceptor;
68:
69: assert afterIterator.next() instanceof ActionLoggingInterceptor;
70: assert afterIterator.next() instanceof HistoryRecorder;
71:
72: }
73:
74: @Test
75: public void testEmptyInterceptorReader() {
76: ActionBeanInterceptorReader reader = new ActionBeanInterceptorReader();
77: assert false == reader
78: .readAnnotations(EmptyInterceptorAction.class);
79:
80: InterceptorAwareImpl interceptorAwareImpl = new InterceptorAwareImpl();
81: reader.populateController(interceptorAwareImpl);
82:
83: List<BeforeInterceptor> beforeInterceptors = interceptorAwareImpl
84: .getBeforeInterceptors();
85: List<AfterInterceptor> afterInterceptors = interceptorAwareImpl
86: .getAfterInterceptors();
87: assertEquals(0, beforeInterceptors.size());
88: assertEquals(0, afterInterceptors.size());
89: }
90:
91: }
|