KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > dbunit > operation > CompositeOperationTest


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.operation;
23
24 import org.dbunit.AbstractDatabaseTest;
25 import org.dbunit.dataset.IDataSet;
26 import org.dbunit.dataset.ITable;
27 import org.dbunit.dataset.xml.XmlDataSet;
28
29 import java.io.File JavaDoc;
30 import java.io.FileReader JavaDoc;
31 import java.io.Reader JavaDoc;
32
33 /**
34  * @author Manuel Laflamme
35  * @version $Revision: 1.9 $
36  * @since Feb 19, 2002
37  */

38 public class CompositeOperationTest extends AbstractDatabaseTest
39 {
40     public CompositeOperationTest(String JavaDoc s)
41     {
42         super(s);
43     }
44
45     public void testExecute() throws Exception JavaDoc
46     {
47         String JavaDoc tableName = "PK_TABLE";
48         String JavaDoc columnName = "PK0";
49         Reader JavaDoc in = new FileReader JavaDoc(
50                 new File JavaDoc("src/xml/compositeOperationTest.xml"));
51         IDataSet xmlDataSet = new XmlDataSet(in);
52
53         // verify table before
54
ITable tableBefore = createOrderedTable(tableName, columnName);
55         assertEquals("row count before", 3, tableBefore.getRowCount());
56         assertEquals("before", "0", tableBefore.getValue(0, columnName).toString());
57         assertEquals("before", "1", tableBefore.getValue(1, columnName).toString());
58         assertEquals("before", "2", tableBefore.getValue(2, columnName).toString());
59
60         DatabaseOperation operation = new CompositeOperation(
61                 DatabaseOperation.DELETE_ALL, DatabaseOperation.INSERT);
62         operation.execute(_connection, xmlDataSet);
63
64         ITable tableAfter = createOrderedTable(tableName, columnName);
65         assertEquals("row count after", 2, tableAfter.getRowCount());
66         assertEquals("after", "1", tableAfter.getValue(0, columnName).toString());
67         assertEquals("after", "3", tableAfter.getValue(1, columnName).toString());
68     }
69
70 }
71
72
73
74
75
Popular Tags