View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.commons.net.telnet;
18  
19  import junit.framework.TestCase;
20  
21  /***
22   * The TelnetOptionHandlerTest is the abstract class for
23   * testing TelnetOptionHandler. It can be used to derive
24   * the actual test classes for TelnetOptionHadler derived
25   * classes, by adding creation of three new option handlers
26   * and testing of the specific subnegotiation behaviour.
27   * <p>
28   * @author Bruno D'Avanzo
29   ***/
30  public abstract class TelnetOptionHandlerTestAbstract extends TestCase
31  {
32      TelnetOptionHandler opthand1;
33      TelnetOptionHandler opthand2;
34      TelnetOptionHandler opthand3;
35  
36      /***
37       * setUp for the test. The derived test class must implement
38       * this method by creating opthand1, opthand2, opthand3
39       * like in the following:
40       *     opthand1 = new EchoOptionHandler();
41       *     opthand2 = new EchoOptionHandler(true, true, true, true);
42       *     opthand3 = new EchoOptionHandler(false, false, false, false);
43       ***/
44      @Override
45      protected abstract void setUp();
46  
47      /***
48       * test of the constructors. The derived class may add
49       * test of the option code.
50       ***/
51      public void testConstructors()
52      {
53          // add test of the option code
54          assertTrue(!opthand1.getInitLocal());
55          assertTrue(!opthand1.getInitRemote());
56          assertTrue(!opthand1.getAcceptLocal());
57          assertTrue(!opthand1.getAcceptRemote());
58  
59          assertTrue(opthand2.getInitLocal());
60          assertTrue(opthand2.getInitRemote());
61          assertTrue(opthand2.getAcceptLocal());
62          assertTrue(opthand2.getAcceptRemote());
63  
64          assertTrue(!opthand3.getInitLocal());
65          assertTrue(!opthand3.getInitRemote());
66          assertTrue(!opthand3.getAcceptLocal());
67          assertTrue(!opthand3.getAcceptRemote());
68      }
69  
70      /***
71       * test of setWill/getWill
72       ***/
73      public void testWill()
74      {
75          opthand2.setWill(true);
76          opthand3.setWill(false);
77  
78          assertTrue(!opthand1.getWill());
79          assertTrue(opthand2.getWill());
80          assertTrue(!opthand3.getWill());
81      }
82  
83      /***
84       * test of setDo/getDo
85       ***/
86      public void testDo()
87      {
88          opthand2.setDo(true);
89          opthand3.setDo(false);
90  
91          assertTrue(!opthand1.getDo());
92          assertTrue(opthand2.getDo());
93          assertTrue(!opthand3.getDo());
94      }
95  
96      /***
97       * test of client-driven subnegotiation. Abstract test:
98       * the derived class should implement it.
99       ***/
100     public abstract void testStartSubnegotiation();
101 
102     /***
103      * test of server-driven subnegotiation. Abstract test:
104      * the derived class should implement it.
105      ***/
106     public abstract void testAnswerSubnegotiation();
107         // test subnegotiation
108 }