001: /* ====================================================================
002: The Jicarilla Software License
003:
004: Copyright (c) 2003 Leo Simons.
005: All rights reserved.
006:
007: Permission is hereby granted, free of charge, to any person obtaining
008: a copy of this software and associated documentation files (the
009: "Software"), to deal in the Software without restriction, including
010: without limitation the rights to use, copy, modify, merge, publish,
011: distribute, sublicense, and/or sell copies of the Software, and to
012: permit persons to whom the Software is furnished to do so, subject to
013: the following conditions:
014:
015: The above copyright notice and this permission notice shall be
016: included in all copies or substantial portions of the Software.
017:
018: THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
019: EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
020: MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
021: IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
022: CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
023: TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
024: SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
025: ==================================================================== */
026: package org.jicarilla.http.test;
027:
028: import org.jicarilla.http.HTTPMessageGenerator;
029: import org.jicarilla.http.MessageReceivedListener;
030: import org.jicarilla.http.MessageFactory;
031: import org.jicarilla.http.HTTPMessage;
032: import org.jicarilla.lang.ExceptionListener;
033: import org.easymock.MockControl;
034: import org.apache.commons.pool.ObjectPool;
035: import org.apache.commons.pool.impl.SoftReferenceObjectPool;
036:
037: import junit.framework.TestCase;
038:
039: /**
040: *
041: *
042: * @author <a href="lsimons at jicarilla dot org">Leo Simons</a>
043: * @version $Id: HTTPMessageGeneratorTestCase.java,v 1.3 2004/03/23 13:37:50 lsimons Exp $
044: */
045: public class HTTPMessageGeneratorTestCase extends TestCase {
046: protected ExceptionListener el;
047: protected MockControl elControl;
048:
049: protected MessageReceivedListener mrl;
050: protected MockControl mrlControl;
051:
052: protected HTTPMessage m;
053: protected MockControl mControl;
054:
055: protected ObjectPool messagePool;
056:
057: protected HTTPMessageGenerator generator;
058:
059: public void setUp() throws Exception {
060: super .setUp();
061:
062: elControl = MockControl.createControl(ExceptionListener.class);
063: el = (ExceptionListener) elControl.getMock();
064:
065: mrlControl = MockControl
066: .createControl(MessageReceivedListener.class);
067: mrl = (MessageReceivedListener) mrlControl.getMock();
068:
069: messagePool = new SoftReferenceObjectPool(new MessageFactory());
070:
071: generator = new HTTPMessageGenerator(el, mrl, messagePool);
072:
073: m = new HTTPMessage();
074: }
075:
076: public void testConstructor() {
077: elControl.replay();
078: mrlControl.replay();
079:
080: new HTTPMessageGenerator(el, mrl, messagePool);
081:
082: elControl.verify();
083: mrlControl.verify();
084:
085: try {
086: new HTTPMessageGenerator(null, mrl, messagePool);
087: fail("Expected an exception!");
088: } catch (AssertionError th) {
089: }
090:
091: try {
092: new HTTPMessageGenerator(el, null, messagePool);
093: fail("Expected an exception!");
094: } catch (AssertionError th) {
095: }
096:
097: try {
098: new HTTPMessageGenerator(el, mrl, null);
099: fail("Expected an exception!");
100: } catch (AssertionError th) {
101: }
102: }
103:
104: public void testGetSetMessage() {
105: elControl.replay();
106: mrlControl.replay();
107:
108: generator.setMessage(new HTTPMessage());
109: assertNotNull(generator.getMessage());
110:
111: generator.setMessage(null);
112: assertNull(generator.getMessage());
113:
114: final HTTPMessage msg = new HTTPMessage();
115: generator.setMessage(msg);
116: assertEquals(msg, generator.getMessage());
117:
118: elControl.verify();
119: mrlControl.verify();
120: }
121:
122: public void testGetMessageType() {
123: generator.setMessage(m);
124: assertEquals(m.getMessageType(), generator.getMessageType());
125:
126: generator.setMessage(null);
127: try {
128: generator.getMessageType();
129: fail("Expected an exception!");
130: } catch (AssertionError ae) {
131: }
132: }
133:
134: public void testSetMessageType() {
135: generator.setMessage(m);
136: generator.setMessageType(false);
137: assertEquals(false, m.getMessageType());
138:
139: generator.setMessage(null);
140: try {
141: generator.setMessageType(false);
142: fail("Expected an exception!");
143: } catch (AssertionError ae) {
144: }
145:
146: }
147:
148: }
|