1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.ws.security.handler;
21
22 import org.apache.ws.security.WSConstants;
23 import org.apache.ws.security.WSSecurityEngineResult;
24
25 import org.apache.ws.security.common.CustomHandler;
26
27
28
29
30
31
32 public class ResultsOrderTest extends org.junit.Assert {
33
34
35
36 @org.junit.Test
37 public void
38 testOrder() throws Exception {
39 CustomHandler handler = new CustomHandler();
40
41 java.util.List<WSSecurityEngineResult> results = new java.util.ArrayList<WSSecurityEngineResult>();
42 results.add(
43 new WSSecurityEngineResult(WSConstants.UT)
44 );
45 results.add(
46 new WSSecurityEngineResult(WSConstants.TS)
47 );
48 results.add(
49 new WSSecurityEngineResult(WSConstants.SC)
50 );
51 results.add(
52 new WSSecurityEngineResult(WSConstants.SIGN)
53 );
54
55 java.util.List<Integer> actions = new java.util.ArrayList<Integer>();
56 actions.add(Integer.valueOf(WSConstants.UT));
57 actions.add(Integer.valueOf(WSConstants.TS));
58 actions.add(Integer.valueOf(WSConstants.SIGN));
59
60 assertTrue (handler.checkResults(results, actions));
61 assertTrue (handler.checkResultsAnyOrder(results, actions));
62 }
63
64
65
66 @org.junit.Test
67 public void
68 testReverseOrder() throws Exception {
69 CustomHandler handler = new CustomHandler();
70
71 java.util.List<WSSecurityEngineResult> results = new java.util.ArrayList<WSSecurityEngineResult>();
72 results.add(
73 new WSSecurityEngineResult(WSConstants.SIGN)
74 );
75 results.add(
76 new WSSecurityEngineResult(WSConstants.SC)
77 );
78 results.add(
79 new WSSecurityEngineResult(WSConstants.TS)
80 );
81 results.add(
82 new WSSecurityEngineResult(WSConstants.UT)
83 );
84
85 java.util.List<Integer> actions = new java.util.ArrayList<Integer>();
86 actions.add(Integer.valueOf(WSConstants.UT));
87 actions.add(Integer.valueOf(WSConstants.TS));
88 actions.add(Integer.valueOf(WSConstants.SIGN));
89
90 assertFalse (handler.checkResults(results, actions));
91 assertTrue (handler.checkResultsAnyOrder(results, actions));
92 assertTrue (results.size() == 4 && actions.size() == 3);
93 }
94
95
96
97 @org.junit.Test
98 public void
99 testMixedOrder() throws Exception {
100 CustomHandler handler = new CustomHandler();
101
102 java.util.List<WSSecurityEngineResult> results =
103 new java.util.ArrayList<WSSecurityEngineResult>();
104 results.add(
105 new WSSecurityEngineResult(WSConstants.TS)
106 );
107 results.add(
108 new WSSecurityEngineResult(WSConstants.SIGN)
109 );
110 results.add(
111 new WSSecurityEngineResult(WSConstants.SC)
112 );
113 results.add(
114 new WSSecurityEngineResult(WSConstants.UT)
115 );
116
117 java.util.List<Integer> actions = new java.util.ArrayList<Integer>();
118 actions.add(Integer.valueOf(WSConstants.UT));
119 actions.add(Integer.valueOf(WSConstants.TS));
120 actions.add(Integer.valueOf(WSConstants.SIGN));
121
122 assertFalse (handler.checkResults(results, actions));
123 assertTrue (handler.checkResultsAnyOrder(results, actions));
124 assertFalse (actions.isEmpty());
125 }
126
127
128
129 @org.junit.Test
130 public void
131 testMixedOrder2() throws Exception {
132 CustomHandler handler = new CustomHandler();
133
134 java.util.List<WSSecurityEngineResult> results =
135 new java.util.ArrayList<WSSecurityEngineResult>();
136 results.add(
137 new WSSecurityEngineResult(WSConstants.TS)
138 );
139 results.add(
140 new WSSecurityEngineResult(WSConstants.SIGN)
141 );
142 results.add(
143 new WSSecurityEngineResult(WSConstants.SC)
144 );
145 results.add(
146 new WSSecurityEngineResult(WSConstants.UT)
147 );
148
149 java.util.List<Integer> actions = new java.util.ArrayList<Integer>();
150 actions.add(Integer.valueOf(WSConstants.SIGN));
151 actions.add(Integer.valueOf(WSConstants.UT));
152 actions.add(Integer.valueOf(WSConstants.TS));
153
154 assertFalse (handler.checkResults(results, actions));
155 assertTrue (handler.checkResultsAnyOrder(results, actions));
156 }
157
158
159
160 @org.junit.Test
161 public void
162 testMissingResult() throws Exception {
163 CustomHandler handler = new CustomHandler();
164
165 java.util.List<WSSecurityEngineResult> results =
166 new java.util.ArrayList<WSSecurityEngineResult>();
167 results.add(
168 new WSSecurityEngineResult(WSConstants.UT)
169 );
170 results.add(
171 new WSSecurityEngineResult(WSConstants.TS)
172 );
173 results.add(
174 new WSSecurityEngineResult(WSConstants.SC)
175 );
176
177 java.util.List<Integer> actions = new java.util.ArrayList<Integer>();
178 actions.add(Integer.valueOf(WSConstants.TS));
179 actions.add(Integer.valueOf(WSConstants.UT));
180 actions.add(Integer.valueOf(WSConstants.SIGN));
181
182 assertFalse (handler.checkResults(results, actions));
183 assertFalse (handler.checkResultsAnyOrder(results, actions));
184 }
185
186
187
188 @org.junit.Test
189 public void
190 testMissingAction() throws Exception {
191 CustomHandler handler = new CustomHandler();
192
193 java.util.List<WSSecurityEngineResult> results =
194 new java.util.ArrayList<WSSecurityEngineResult>();
195 results.add(
196 new WSSecurityEngineResult(WSConstants.UT)
197 );
198 results.add(
199 new WSSecurityEngineResult(WSConstants.TS)
200 );
201 results.add(
202 new WSSecurityEngineResult(WSConstants.SIGN)
203 );
204 results.add(
205 new WSSecurityEngineResult(WSConstants.SC)
206 );
207
208 java.util.List<Integer> actions = new java.util.ArrayList<Integer>();
209 actions.add(Integer.valueOf(WSConstants.TS));
210 actions.add(Integer.valueOf(WSConstants.UT));
211
212 assertFalse (handler.checkResults(results, actions));
213 assertFalse (handler.checkResultsAnyOrder(results, actions));
214 }
215
216
217
218 @org.junit.Test
219 public void
220 testNoResult() throws Exception {
221 CustomHandler handler = new CustomHandler();
222
223 java.util.List<WSSecurityEngineResult> results =
224 new java.util.ArrayList<WSSecurityEngineResult>();
225
226 java.util.List<Integer> actions = new java.util.ArrayList<Integer>();
227 actions.add(Integer.valueOf(WSConstants.TS));
228
229 assertFalse (handler.checkResults(results, actions));
230 assertFalse (handler.checkResultsAnyOrder(results, actions));
231 }
232
233
234
235 @org.junit.Test
236 public void
237 testNoAction() throws Exception {
238 CustomHandler handler = new CustomHandler();
239
240 java.util.List<WSSecurityEngineResult> results =
241 new java.util.ArrayList<WSSecurityEngineResult>();
242 results.add(
243 new WSSecurityEngineResult(WSConstants.TS)
244 );
245
246 java.util.List<Integer> actions = new java.util.ArrayList<Integer>();
247
248 assertFalse (handler.checkResults(results, actions));
249 assertFalse (handler.checkResultsAnyOrder(results, actions));
250 }
251
252
253
254 @org.junit.Test
255 public void
256 testMultipleIdenticalResults() throws Exception {
257 CustomHandler handler = new CustomHandler();
258
259 java.util.List<WSSecurityEngineResult> results =
260 new java.util.ArrayList<WSSecurityEngineResult>();
261 results.add(
262 new WSSecurityEngineResult(WSConstants.ENCR)
263 );
264 results.add(
265 new WSSecurityEngineResult(WSConstants.UT)
266 );
267 results.add(
268 new WSSecurityEngineResult(WSConstants.ENCR)
269 );
270
271 java.util.List<Integer> actions = new java.util.ArrayList<Integer>();
272 actions.add(Integer.valueOf(WSConstants.ENCR));
273 actions.add(Integer.valueOf(WSConstants.UT));
274 actions.add(Integer.valueOf(WSConstants.UT));
275
276 assertFalse (handler.checkResults(results, actions));
277 assertFalse (handler.checkResultsAnyOrder(results, actions));
278 }
279
280 }