001 /* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 package org.apache.commons.net.telnet; 018 019 import junit.framework.TestCase; 020 021 /*** 022 * The TelnetOptionHandlerTest is the abstract class for 023 * testing TelnetOptionHandler. It can be used to derive 024 * the actual test classes for TelnetOptionHadler derived 025 * classes, by adding creation of three new option handlers 026 * and testing of the specific subnegotiation behaviour. 027 * <p> 028 * @author Bruno D'Avanzo 029 ***/ 030 public abstract class TelnetOptionHandlerTestAbstract extends TestCase 031 { 032 TelnetOptionHandler opthand1; 033 TelnetOptionHandler opthand2; 034 TelnetOptionHandler opthand3; 035 036 /*** 037 * setUp for the test. The derived test class must implement 038 * this method by creating opthand1, opthand2, opthand3 039 * like in the following: 040 * opthand1 = new EchoOptionHandler(); 041 * opthand2 = new EchoOptionHandler(true, true, true, true); 042 * opthand3 = new EchoOptionHandler(false, false, false, false); 043 ***/ 044 @Override 045 protected abstract void setUp(); 046 047 /*** 048 * test of the constructors. The derived class may add 049 * test of the option code. 050 ***/ 051 public void testConstructors() 052 { 053 // add test of the option code 054 assertTrue(!opthand1.getInitLocal()); 055 assertTrue(!opthand1.getInitRemote()); 056 assertTrue(!opthand1.getAcceptLocal()); 057 assertTrue(!opthand1.getAcceptRemote()); 058 059 assertTrue(opthand2.getInitLocal()); 060 assertTrue(opthand2.getInitRemote()); 061 assertTrue(opthand2.getAcceptLocal()); 062 assertTrue(opthand2.getAcceptRemote()); 063 064 assertTrue(!opthand3.getInitLocal()); 065 assertTrue(!opthand3.getInitRemote()); 066 assertTrue(!opthand3.getAcceptLocal()); 067 assertTrue(!opthand3.getAcceptRemote()); 068 } 069 070 /*** 071 * test of setWill/getWill 072 ***/ 073 public void testWill() 074 { 075 opthand2.setWill(true); 076 opthand3.setWill(false); 077 078 assertTrue(!opthand1.getWill()); 079 assertTrue(opthand2.getWill()); 080 assertTrue(!opthand3.getWill()); 081 } 082 083 /*** 084 * test of setDo/getDo 085 ***/ 086 public void testDo() 087 { 088 opthand2.setDo(true); 089 opthand3.setDo(false); 090 091 assertTrue(!opthand1.getDo()); 092 assertTrue(opthand2.getDo()); 093 assertTrue(!opthand3.getDo()); 094 } 095 096 /*** 097 * test of client-driven subnegotiation. Abstract test: 098 * the derived class should implement it. 099 ***/ 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 }