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 testing TelnetOptionHandler. It can be used to derive the actual test classes for TelnetOptionHadler
23   * derived classes, by adding creation of three new option handlers and testing of the specific subnegotiation behavior.
24   */
25  public abstract class AbstractTelnetOptionHandlerTest extends TestCase {
26      TelnetOptionHandler opthand1;
27      TelnetOptionHandler opthand2;
28      TelnetOptionHandler opthand3;
29  
30      /**
31       * setUp for the test. The derived test class must implement this method by creating opthand1, opthand2, opthand3 like in the following: opthand1 = new
32       * EchoOptionHandler(); opthand2 = new EchoOptionHandler(true, true, true, true); opthand3 = new EchoOptionHandler(false, false, false, false);
33       */
34      @Override
35      protected abstract void setUp();
36  
37      /**
38       * test of server-driven subnegotiation. Abstract test: the derived class should implement it.
39       */
40      public abstract void testAnswerSubnegotiation();
41      // test subnegotiation
42  
43      /**
44       * test of the constructors. The derived class may add test of the option code.
45       */
46      public void testConstructors() {
47          // add test of the option code
48          assertFalse(opthand1.getInitLocal());
49          assertFalse(opthand1.getInitRemote());
50          assertFalse(opthand1.getAcceptLocal());
51          assertFalse(opthand1.getAcceptRemote());
52  
53          assertTrue(opthand2.getInitLocal());
54          assertTrue(opthand2.getInitRemote());
55          assertTrue(opthand2.getAcceptLocal());
56          assertTrue(opthand2.getAcceptRemote());
57  
58          assertFalse(opthand3.getInitLocal());
59          assertFalse(opthand3.getInitRemote());
60          assertFalse(opthand3.getAcceptLocal());
61          assertFalse(opthand3.getAcceptRemote());
62      }
63  
64      /**
65       * test of setDo/getDo
66       */
67      public void testDo() {
68          opthand2.setDo(true);
69          opthand3.setDo(false);
70  
71          assertFalse(opthand1.getDo());
72          assertTrue(opthand2.getDo());
73          assertFalse(opthand3.getDo());
74      }
75  
76      /**
77       * test of client-driven subnegotiation. Abstract test: the derived class should implement it.
78       */
79      public abstract void testStartSubnegotiation();
80  
81      /**
82       * test of setWill/getWill
83       */
84      public void testWill() {
85          opthand2.setWill(true);
86          opthand3.setWill(false);
87  
88          assertFalse(opthand1.getWill());
89          assertTrue(opthand2.getWill());
90          assertFalse(opthand3.getWill());
91      }
92  }