KickJava   Java API By Example, From Geeks To Geeks.

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


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 com.mockobjects.ExpectationCounter;
25 import com.mockobjects.Verifiable;
26 import org.dbunit.DatabaseUnitException;
27 import org.dbunit.database.IDatabaseConnection;
28 import org.dbunit.dataset.IDataSet;
29
30 import java.sql.SQLException JavaDoc;
31
32 /**
33  * @author Manuel Laflamme
34  * @version $Revision: 1.5 $
35  * @since Mar 16, 2002
36  */

37 public class MockDatabaseOperation extends DatabaseOperation implements Verifiable
38 {
39     private ExpectationCounter _executeCalls =
40             new ExpectationCounter("MockDatabaseOperation.execute");
41     private Exception JavaDoc _executeException = null;
42
43     public void setExpectedExecuteCalls(int callsCount)
44     {
45         _executeCalls.setExpected(callsCount);
46     }
47
48     public void setupThrowExceptionOnExecute(Exception JavaDoc exception)
49     {
50         _executeException = exception;
51     }
52
53
54     ///////////////////////////////////////////////////////////////////////////
55
// Verifiable interface
56

57     public void verify()
58     {
59         _executeCalls.verify();
60     }
61
62     ///////////////////////////////////////////////////////////////////////////
63
// DatabaseOperation class
64

65     public void execute(IDatabaseConnection connection, IDataSet dataSet)
66             throws DatabaseUnitException, SQLException JavaDoc
67     {
68         _executeCalls.inc();
69
70         if (_executeException instanceof SQLException JavaDoc)
71         {
72             throw (SQLException JavaDoc)_executeException;
73         }
74         else if (_executeException instanceof DatabaseUnitException)
75         {
76             throw (DatabaseUnitException)_executeException;
77         }
78         else if (_executeException instanceof RuntimeException JavaDoc)
79         {
80             throw (RuntimeException JavaDoc)_executeException;
81         }
82     }
83 }
84
85
86
Popular Tags