Debian Codegraph @

test/chains/TestSimpleChain.java

raw
1 /*
2 * Copyright 2002-2004 The Apache Software Foundation.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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 package test.chains;
17
18 import junit.framework.Test;
19 import junit.framework.TestCase;
20 import junit.framework.TestSuite;
21 import org.apache.axis.AxisFault;
22 import org.apache.axis.Handler;
23 import org.apache.axis.InternalException;
24 import org.apache.axis.MessageContext;
25 import org.apache.axis.SimpleChain;
26 import org.apache.axis.handlers.BasicHandler;
27
28 public class TestSimpleChain extends TestCase
29 {
30 public TestSimpleChain (String name) {
31 super(name);
32 }
33
34 public static Test suite() {
35 return new TestSuite(TestSimpleChain.class);
36 }
37
38 protected void setup() {
39 }
40
41 private class TestHandler extends BasicHandler {
42 public TestHandler() {}
43 public void invoke(MessageContext msgContext) throws AxisFault {}
44 }
45
46 public void testSimpleChainAddHandler()
47 {
48 SimpleChain c = new SimpleChain();
49
50 Handler h1 = new TestHandler();
51 assertTrue("Empty chain has a handler", !c.contains(h1));
52
53 c.addHandler(h1);
54 assertTrue("Added handler not in chain", c.contains(h1));
55 }
56
57 public void testSimpleChainAddHandlerAfterInvoke()
58 {
59 try {
60 SimpleChain c = new SimpleChain();
61 Handler h1 = new TestHandler();
62 c.addHandler(h1);
63
64 // A null engine is good enough for this test
65 MessageContext mc = new MessageContext(null);
66 c.invoke(mc);
67
68 // while testing, disable noise
69 boolean oldLogging = InternalException.getLogging();
70 InternalException.setLogging(false);
71
72 try {
73 Handler h2 = new TestHandler();
74 c.addHandler(h2);
75 assertTrue("Handler added after chain invoked", false);
76 } catch (Exception e) {
77 // Correct behaviour. Exact exception isn't critical
78 }
79
80 // resume noise
81 InternalException.setLogging(oldLogging);
82 } catch (AxisFault af) {
83 assertTrue("Unexpected exception", false);
84 }
85 }
86 }