Changeset 7262380c0bc232cba2cbdf8d19313ca8e4d5d268

Show
Ignore:
Timestamp:
02/17/08 17:20:32 (8 months ago)
Author:
Christopher Jung <bktheg@web.de>
git-committer:
Christopher Jung <bktheg@web.de> 1203265232 +0100
git-parent:

[a55e1ef5522b0215c6e961eebb95e1005be1be0c]

git-author:
Christopher Jung <bktheg@web.de> 1203265232 +0100
Message:

Unterstuetzung fuer Junit4-Testcases mit DB-Tests verbessert

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • test/java/net/driftingsouls/ds2/server/DriftingSoulsDBTestCase.java

    rd193343 r7262380  
    1919package net.driftingsouls.ds2.server; 
    2020 
     21import java.sql.Connection; 
     22import java.sql.ResultSet; 
     23import java.sql.SQLException; 
     24import java.sql.Statement; 
     25 
    2126import net.driftingsouls.ds2.server.framework.BasicContext; 
    2227import net.driftingsouls.ds2.server.framework.CmdLineRequest; 
    23 import net.driftingsouls.ds2.server.framework.Configuration; 
    2428import net.driftingsouls.ds2.server.framework.SimpleResponse; 
    2529 
    26 import org.dbunit.DBTestCase; 
    27 import org.dbunit.PropertiesBasedJdbcDatabaseTester; 
    28 import org.dbunit.operation.DatabaseOperation; 
     30import org.junit.After; 
     31import org.junit.Before; 
    2932 
    3033/** 
     
    3336 * 
    3437 */ 
    35 public abstract class DriftingSoulsDBTestCase extends DBTestCase { 
     38public abstract class DriftingSoulsDBTestCase implements DBTestable { 
    3639        protected BasicContext context; 
     40        protected DBTestCaseAdapter dbTester; 
    3741 
    3842        /** 
     
    4044         */ 
    4145        public DriftingSoulsDBTestCase() { 
    42                 try { 
    43                         Configuration.init("./test/cfg/"); 
    44                          
    45                         System.setProperty( PropertiesBasedJdbcDatabaseTester.DBUNIT_DRIVER_CLASS, "com.mysql.jdbc.Driver" ); 
    46                         System.setProperty( PropertiesBasedJdbcDatabaseTester.DBUNIT_CONNECTION_URL,  
    47                                         "jdbc:mysql://"+Configuration.getSetting("db_server")+"/"+Configuration.getSetting("db_database") ); 
    48                         System.setProperty( PropertiesBasedJdbcDatabaseTester.DBUNIT_USERNAME, Configuration.getSetting("db_user") ); 
    49                         System.setProperty( PropertiesBasedJdbcDatabaseTester.DBUNIT_PASSWORD, Configuration.getSetting("db_password") ); 
    50                 } 
    51                 catch( Exception e ) { 
    52                         if( e instanceof RuntimeException ) { 
    53                                 throw (RuntimeException)e; 
    54                         } 
    55  
    56                         throw new RuntimeException("Fehler beim Initalisieren des Testcases", e); 
    57                 } 
     46                dbTester = new DBTestCaseAdapter(this); 
    5847        } 
    5948         
    60         @Override 
    61         protected DatabaseOperation getTearDownOperation() throws Exception { 
    62                 return DatabaseOperation.DELETE_ALL; 
    63         } 
    64          
    65         @Override 
    66         protected void setUp() throws Exception { 
     49        /** 
     50         * SetUp-Methode 
     51         * @throws Exception 
     52         */ 
     53        @Before 
     54        public void setUp() throws Exception { 
    6755                SimpleResponse response = new SimpleResponse(); 
    6856                CmdLineRequest request = new CmdLineRequest(new String[0]); 
    6957                this.context = new BasicContext(request, response); 
    7058                 
    71                 super.setUp(); 
     59                Connection con = this.dbTester.getConnection().getConnection(); 
     60                Statement stmt = con.createStatement(); 
     61                stmt.executeUpdate("INSERT INTO config VALUES ('1', '', '', '')"); 
     62                stmt.close(); 
     63                 
     64                this.dbTester.setUp(); 
    7265        } 
    7366 
    74         @Override 
    75         protected void tearDown() throws Exception { 
     67        /** 
     68         * TearDown-Methode 
     69         * @throws Exception 
     70         */ 
     71        @After 
     72        public void tearDown() throws Exception { 
    7673                this.context.free(); 
    7774                 
    78                 super.tearDown(); 
     75                try { 
     76                        Connection con = this.dbTester.getConnection().getConnection(); 
     77                        Statement stmt = con.createStatement(); 
     78                        stmt.executeUpdate("SET FOREIGN_KEY_CHECKS=0"); 
     79                        ResultSet result = stmt.executeQuery("SHOW TABLES"); 
     80                        while( result.next() ) { 
     81                                String table = result.getString(1); 
     82                                Statement stmt2 = con.createStatement(); 
     83                                stmt2.executeUpdate("DELETE FROM "+table); 
     84                                stmt2.close(); 
     85                        } 
     86                        result.close(); 
     87                        stmt.executeUpdate("SET FOREIGN_KEY_CHECKS=1"); 
     88                        stmt.close(); 
     89                } 
     90                catch( SQLException e ) { 
     91                        e.printStackTrace(); 
     92                } 
     93                 
     94                this.dbTester.tearDown(); 
    7995        } 
    8096} 
  • test/java/net/driftingsouls/ds2/server/scripting/ShipUtilsTest.java

    r1f46047 r7262380  
    3939         
    4040        @Override 
    41         protected void setUp() throws Exception { 
     41        public void setUp() throws Exception { 
    4242                super.setUp(); 
    4343 
     
    4545        } 
    4646 
    47         @Override 
    48         protected IDataSet getDataSet() throws Exception { 
     47        public IDataSet getDataSet() throws Exception { 
    4948                return new FlatXmlDataSet(ShipUtilsTest.class.getResourceAsStream("ShipUtilsTest.xml")); 
    5049        } 
  • test/java/net/driftingsouls/ds2/server/scripting/roles/roleimpl/DeutTransporterTest.java

    r81cff56 r7262380  
    5959         
    6060        @Override 
    61         protected void setUp() throws Exception { 
     61        public void setUp() throws Exception { 
    6262                super.setUp(); 
    6363                 
     
    108108        } 
    109109 
    110         @Override 
    111         protected IDataSet getDataSet() throws Exception { 
     110        public IDataSet getDataSet() throws Exception { 
    112111                return new FlatXmlDataSet(DeutTransporterTest.class.getResourceAsStream("DeutTransporterTest.xml")); 
    113112        }