KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > dbunit > dataset > csv > handlers > PipelineTest


1 /*
2  *
3  * The DbUnit Database Testing Framework
4  * Copyright (C)2002-2004, DbUnit.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  *
20  */

21
22 package org.dbunit.dataset.csv.handlers;
23
24 import junit.framework.TestCase;
25 import org.dbunit.dataset.csv.IllegalInputCharacterException;
26
27 /**
28  * author: fede
29  * 29-lug-2003 16.14.18
30  * $Revision: 1.1 $
31  */

32 public class PipelineTest extends TestCase {
33     Pipeline line;
34
35     public void testRemovingTheLastHandlerThrowsException () {
36         try {
37             line.removeFront();
38             line.removeFront();
39             fail ("Removing from an ampty pipeline should throw an exception");
40         } catch (PipelineException e) {}
41     }
42
43     public void testAnHandlerCanBeAddedInFront () throws PipelineException {
44         PipelineComponent handler = SeparatorHandler.ACCEPT();
45         line.putFront(handler);
46         assertSame(handler, line.removeFront());
47         assertSame(line, handler.getPipeline());
48     }
49
50     public void testTheFrontHandlerIsThereAfterAddingAndRemovingAnother () throws PipelineException {
51         PipelineComponent handler = SeparatorHandler.ACCEPT();
52         PipelineComponent handler2 = SeparatorHandler.ACCEPT();
53         line.putFront(handler);
54         line.putFront(handler2);
55         assertSame(handler2, line.removeFront());
56         assertSame(handler, line.removeFront());
57     }
58
59     public void testEachHandlerIsCalled () throws IllegalInputCharacterException, PipelineException {
60         MockHandler component = new MockHandler();
61         MockHandler component2 = new MockHandler();
62         component.setExpectedHandleCalls(1);
63         component2.setExpectedHandleCalls(1);
64         line.putFront(component);
65         line.putFront(component2);
66
67         // the last handler will throw an exception
68
try {
69             line.handle('x');
70             fail("Exception expected");
71         } catch (IllegalInputCharacterException seen) {}
72
73         component.verify();
74         component2.verify();
75     }
76
77     public void testWhenAPieceIsDoneIsAddedToProducts () throws IllegalInputCharacterException, PipelineException {
78         PipelineComponent c = AllHandler.ACCEPT();
79         line.putFront(c);
80         line.handle('x');
81         line.thePieceIsDone();
82         assertEquals(1, line.getProducts().size());
83         assertEquals("x", line.getProducts().get(0));
84     }
85
86     public void testWhetAPieceIsDoneANewOneIsCreated () throws IllegalInputCharacterException, PipelineException {
87         PipelineComponent c = AllHandler.ACCEPT();
88         line.putFront(c);
89         line.handle('x');
90         line.thePieceIsDone();
91         assertEquals("", line.getCurrentProduct().toString());
92     }
93
94
95     protected void setUp() throws Exception JavaDoc {
96         line = new Pipeline();
97     }
98 }
99
Popular Tags