1 | /**************************************************************** |
2 | ??*??Licensed??to??the??Apache??Software??Foundation??(ASF)??under??one??????* |
3 | ??*??or??more??contributor??license??agreements.????See??the??NOTICE??file??* |
4 | ??*??distributed??with??this??work??for??additional??information????????????????* |
5 | ??*??regarding??copyright??ownership.????The??ASF??licenses??this??file??????* |
6 | ??*??to??you??under??the??Apache??License,??Version??2.0??(the????????????????????????* |
7 | ??*??"License");??you??may??not??use??this??file??except??in??compliance??????* |
8 | ??*??with??the??License.????You??may??obtain??a??copy??of??the??License??at??????* |
9 | ??*????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????* |
10 | ??*??????http://www.apache.org/licenses/LICENSE-2.0??????????????????????????????????* |
11 | ??*????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????* |
12 | ??*??Unless??required??by??applicable??law??or??agreed??to??in??writing,??????* |
13 | ??*??software??distributed??under??the??License??is??distributed??on??an????* |
14 | ??*??"AS??IS"??BASIS,??WITHOUT??WARRANTIES??OR??CONDITIONS??OF??ANY??????????????* |
15 | ??*??KIND,??either??express??or??implied.????See??the??License??for??the????????* |
16 | ??*??specific??language??governing??permissions??and??limitations????????????* |
17 | ??*??under??the??License.??????????????????????????????????????????????????????????????????????????????????????* |
18 | ??****************************************************************/ |
19 | ?? |
20 | package??org.apache.james.mpt; |
21 | ?? |
22 | /** |
23 | ??*??Runs??protocol??scripts. |
24 | ??*/ |
25 | public??class??Runner??{ |
26 | ???????? |
27 | ????????/**??The??Protocol??session??which??is??run??before??the??testElements??*/ |
28 | ????????private??final??ProtocolSession??preElements??=??new??ProtocolSession(); |
29 | ?? |
30 | ????????/**??The??Protocol??session??which??contains??the??tests??elements??*/ |
31 | ????????private??final??ProtocolSession??testElements??=??new??ProtocolSession(); |
32 | ?? |
33 | ????????/**??The??Protocol??session??which??is??run??after??the??testElements.??*/ |
34 | ????????private??final??ProtocolSession??postElements??=??new??ProtocolSession(); |
35 | ???????? |
36 | ????????public??void??continueAfterFailure()??{ |
37 | ????????????????preElements.setContinueAfterFailure(true); |
38 | ????????????????testElements.setContinueAfterFailure(true); |
39 | ????????????????postElements.setContinueAfterFailure(true); |
40 | ????????} |
41 | ???????? |
42 | ????????/** |
43 | ??????????*??Gets??protocol??session??run??after??test. |
44 | ??????????*??@return??not??null |
45 | ??????????*/ |
46 | ????????public??ProtocolInteractor??getPostElements()??{ |
47 | ????????????????return??postElements; |
48 | ????????} |
49 | ?? |
50 | ????????/** |
51 | ??????????*??Gets??protocol??session??run??before??test. |
52 | ??????????*??@return??not??null |
53 | ??????????*/ |
54 | ????????public??ProtocolInteractor??getPreElements()??{ |
55 | ????????????????return??preElements; |
56 | ????????} |
57 | ????????/** |
58 | ??????????*??Gets??protocol??session??run??on??test. |
59 | ??????????*??@return??not??null |
60 | ??????????*/ |
61 | ????????public??ProtocolInteractor??getTestElements()??{ |
62 | ????????????????return??testElements; |
63 | ????????} |
64 | ?? |
65 | ?? |
66 | ?? |
67 | ????????/** |
68 | ??????????*??Runs??the??pre,test??and??post??protocol??sessions??against??a??local??copy??of??the |
69 | ??????????*??ImapServer.??This??does??not??require??that??James??be??running,??and??is??useful |
70 | ??????????*??for??rapid??development??and??debugging. |
71 | ??????????*?? |
72 | ??????????*??Instead??of??sending??requests??to??a??socket??connected??to??a??running??instance |
73 | ??????????*??of??James,??this??method??uses??the??{@link??MockImapServer}??to??simplify |
74 | ??????????*??testing.??One??mock??instance??is??required??per??protocol??session/connection. |
75 | ??????????*??These??share??the??same??underlying??Mailboxes,??because??of??the??way |
76 | ??????????*??{@link??MockImapServer#getImapSession()}??works. |
77 | ??????????*/ |
78 | ????????public??void??runSessions(final??SessionFactory??factory)??throws??Exception??{ |
79 | ????????????????class??SessionContinuation??implements??HostSystem.Continuation??{ |
80 | ?? |
81 | ????????????????????????public??ProtocolSession??session; |
82 | ?? |
83 | ????????????????????????public??void??doContinue()??{ |
84 | ????????????????????????????????if??(session??!=??null)??{ |
85 | ????????????????????????????????????????session.doContinue(); |
86 | ????????????????????????????????} |
87 | ????????????????????????} |
88 | ?? |
89 | ????????????????} |
90 | ????????????????SessionContinuation??continuation??=??new??SessionContinuation(); |
91 | ?? |
92 | ????????????????Session[]??sessions??=??new??Session[testElements |
93 | ????????????????????????????????.getSessionCount()]; |
94 | ?? |
95 | ????????????????for??(int??i??=??0;??i??<??sessions.length;??i++)??{ |
96 | ????????????????????????sessions[i]??=??factory.newSession(continuation); |
97 | ????????????????????????sessions[i].start(); |
98 | ????????????????} |
99 | ????????????????try??{ |
100 | ????????????????????????continuation.session??=??preElements; |
101 | ????????????????????????preElements.runSessions(sessions); |
102 | ????????????????????????continuation.session??=??testElements; |
103 | ????????????????????????testElements.runSessions(sessions); |
104 | ????????????????????????continuation.session??=??postElements; |
105 | ????????????????????????postElements.runSessions(sessions); |
106 | ????????????????}??finally??{ |
107 | ????????????????????????for??(int??i??=??0;??i??<??sessions.length;??i++)??{ |
108 | ????????????????????????????????sessions[i].stop(); |
109 | ????????????????????????} |
110 | ????????????????} |
111 | ????????} |
112 | ?? |
113 | ????????/** |
114 | ??????????*??Constructs??a??<code>String</code>??with??all??attributes |
115 | ??????????*??in??name??=??value??format. |
116 | ??????????* |
117 | ??????????*??@return??a??<code>String</code>??representation?? |
118 | ??????????*??of??this??object. |
119 | ??????????*/ |
120 | ????????public??String??toString() |
121 | ????????{ |
122 | ????????????????final??String??TAB??=??"??"; |
123 | ???????????????? |
124 | ????????????????String??result????=??"Runner??(??" |
125 | ????????????????????????+??"preElements??=??"??+??this.preElements??+??TAB |
126 | ????????????????????????+??"testElements??=??"??+??this.testElements??+??TAB |
127 | ????????????????????????+??"postElements??=??"??+??this.postElements??+??TAB |
128 | ????????????????????????+??"??)"; |
129 | ???????? |
130 | ????????????????return??result; |
131 | ????????} |
132 | ?? |
133 | ???????? |
134 | } |