01: /*
02: * Copyright 2006 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16:
17: package org.springframework.ws.soap.security.xwss.callback;
18:
19: import javax.security.auth.callback.Callback;
20: import javax.security.auth.callback.CallbackHandler;
21: import javax.security.auth.callback.UnsupportedCallbackException;
22:
23: import junit.framework.TestCase;
24:
25: public class CallbackHandlerChainTest extends TestCase {
26:
27: private CallbackHandler supported = new CallbackHandler() {
28: public void handle(Callback[] callbacks) {
29: }
30: };
31:
32: private CallbackHandler unsupported = new CallbackHandler() {
33: public void handle(Callback[] callbacks)
34: throws UnsupportedCallbackException {
35: throw new UnsupportedCallbackException(callbacks[0]);
36: }
37: };
38:
39: private Callback callback = new Callback() {
40: };
41:
42: protected void setUp() throws Exception {
43: }
44:
45: public void testSupported() throws Exception {
46: CallbackHandlerChain chain = new CallbackHandlerChain(
47: new CallbackHandler[] { supported });
48: chain.handle(new Callback[] { callback });
49: }
50:
51: public void testUnsupportedNormal() throws Exception {
52: CallbackHandlerChain chain = new CallbackHandlerChain(
53: new CallbackHandler[] { unsupported, supported });
54: chain.handle(new Callback[] { callback });
55: }
56:
57: public void testUnsupported() throws Exception {
58: CallbackHandlerChain chain = new CallbackHandlerChain(
59: new CallbackHandler[] { unsupported });
60: try {
61: chain.handle(new Callback[] { callback });
62: fail("Expected UnsupportedCallbackException");
63: } catch (UnsupportedCallbackException ex) {
64: // expected behavior
65: }
66: }
67: }
|