KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > net > telnet > TelnetOptionHandlerTestAbstract


1 /*
2  * Copyright 2003-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 org.apache.commons.net.telnet;
17
18 import junit.framework.TestCase;
19
20 /***
21  * The TelnetOptionHandlerTest is the abstract class for
22  * testing TelnetOptionHandler. It can be used to derive
23  * the actual test classes for TelnetOptionHadler derived
24  * classes, by adding creation of three new option handlers
25  * and testing of the specific subnegotiation behaviour.
26  * <p>
27  * @author Bruno D'Avanzo
28  ***/

29 public abstract class TelnetOptionHandlerTestAbstract extends TestCase
30 {
31     TelnetOptionHandler opthand1;
32     TelnetOptionHandler opthand2;
33     TelnetOptionHandler opthand3;
34
35     /***
36      * setUp for the test. The derived test class must implement
37      * this method by creating opthand1, opthand2, opthand3
38      * like in the following:
39      * opthand1 = new EchoOptionHandler();
40      * opthand2 = new EchoOptionHandler(true, true, true, true);
41      * opthand3 = new EchoOptionHandler(false, false, false, false);
42      ***/

43     protected abstract void setUp();
44
45     /***
46      * test of the constructors. The derived class may add
47      * test of the option code.
48      ***/

49     public void testConstructors()
50     {
51         // add test of the option code
52
assertTrue(!opthand1.getInitLocal());
53         assertTrue(!opthand1.getInitRemote());
54         assertTrue(!opthand1.getAcceptLocal());
55         assertTrue(!opthand1.getAcceptRemote());
56
57         assertTrue(opthand2.getInitLocal());
58         assertTrue(opthand2.getInitRemote());
59         assertTrue(opthand2.getAcceptLocal());
60         assertTrue(opthand2.getAcceptRemote());
61
62         assertTrue(!opthand3.getInitLocal());
63         assertTrue(!opthand3.getInitRemote());
64         assertTrue(!opthand3.getAcceptLocal());
65         assertTrue(!opthand3.getAcceptRemote());
66     }
67
68     /***
69      * test of setWill/getWill
70      ***/

71     public void testWill()
72     {
73         opthand2.setWill(true);
74         opthand3.setWill(false);
75
76         assertTrue(!opthand1.getWill());
77         assertTrue(opthand2.getWill());
78         assertTrue(!opthand3.getWill());
79     }
80
81     /***
82      * test of setDo/getDo
83      ***/

84     public void testDo()
85     {
86         opthand2.setDo(true);
87         opthand3.setDo(false);
88
89         assertTrue(!opthand1.getDo());
90         assertTrue(opthand2.getDo());
91         assertTrue(!opthand3.getDo());
92     }
93
94     /***
95      * test of client-driven subnegotiation. Abstract test:
96      * the derived class should implement it.
97      ***/

98     public abstract void testStartSubnegotiation();
99
100     /***
101      * test of server-driven subnegotiation. Abstract test:
102      * the derived class should implement it.
103      ***/

104     public abstract void testAnswerSubnegotiation();
105         // test subnegotiation
106
}
Popular Tags