View Javadoc
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.common.handlers;
23  
24  import junit.framework.TestCase;
25  
26  /**
27   * author: fede
28   * 29-lug-2003 16.14.18
29   * $Revision$
30   */
31  public class PipelineTest extends TestCase {
32      Pipeline line;
33  
34      public void testRemovingTheLastHandlerThrowsException () {
35          try {
36              line.removeFront();
37              line.removeFront();
38              fail ("Removing from an ampty pipeline should throw an exception");
39          } catch (PipelineException e) {}
40      }
41  
42      public void testAnHandlerCanBeAddedInFront () throws PipelineException {
43          PipelineComponent handler = SeparatorHandler.ACCEPT();
44          line.putFront(handler);
45          assertSame(handler, line.removeFront());
46          assertSame(line, handler.getPipeline());
47      }
48  
49      public void testTheFrontHandlerIsThereAfterAddingAndRemovingAnother () throws PipelineException {
50          PipelineComponent handler = SeparatorHandler.ACCEPT();
51          PipelineComponent handler2 = SeparatorHandler.ACCEPT();
52          line.putFront(handler);
53          line.putFront(handler2);
54          assertSame(handler2, line.removeFront());
55          assertSame(handler, line.removeFront());
56      }
57  
58      public void testEachHandlerIsCalled () throws IllegalInputCharacterException, PipelineException {
59          MockHandler component = new MockHandler();
60          MockHandler component2 = new MockHandler();
61          component.setExpectedHandleCalls(1);
62          component2.setExpectedHandleCalls(1);
63          line.putFront(component);
64          line.putFront(component2);
65  
66          // the last handler will throw an exception
67          try {
68              line.handle('x');
69              fail("Exception expected");
70          } catch (IllegalInputCharacterException seen) {}
71  
72          component.verify();
73          component2.verify();
74      }
75  
76      public void testWhenAPieceIsDoneIsAddedToProducts () throws IllegalInputCharacterException, PipelineException {
77          PipelineComponent c = AllHandler.ACCEPT();
78          line.putFront(c);
79          line.handle('x');
80          line.thePieceIsDone();
81          assertEquals(1, line.getProducts().size());
82          assertEquals("x", line.getProducts().get(0));
83      }
84  
85      public void testWhetAPieceIsDoneANewOneIsCreated () throws IllegalInputCharacterException, PipelineException {
86          PipelineComponent c = AllHandler.ACCEPT();
87          line.putFront(c);
88          line.handle('x');
89          line.thePieceIsDone();
90          assertEquals("", line.getCurrentProduct().toString());
91      }
92  
93  
94      protected void setUp() throws Exception {
95          line = new Pipeline();
96      }
97  }