db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arm...@apache.org
Subject cvs commit: db-ojb/src/test/org/apache/ojb/broker/sequence NativeIdentifierTest.java
Date Sat, 10 May 2003 18:21:19 GMT
arminw      2003/05/10 11:21:19

  Modified:    src/test/org/apache/ojb/broker/sequence
                        NativeIdentifierTest.java
  Log:
  update test case, now run on mysql and hsql
  
  Revision  Changes    Path
  1.2       +40 -13    db-ojb/src/test/org/apache/ojb/broker/sequence/NativeIdentifierTest.java
  
  Index: NativeIdentifierTest.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/broker/sequence/NativeIdentifierTest.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- NativeIdentifierTest.java	9 May 2003 23:58:18 -0000	1.1
  +++ NativeIdentifierTest.java	10 May 2003 18:21:19 -0000	1.2
  @@ -8,6 +8,8 @@
   import org.apache.ojb.broker.metadata.MetadataManager;
   import org.apache.ojb.broker.metadata.SequenceDescriptor;
   import org.apache.ojb.broker.platforms.PlatformHsqldbImpl;
  +import org.apache.ojb.broker.platforms.PlatformMySQLImpl;
  +import org.apache.ojb.broker.platforms.Platform;
   import org.apache.ojb.broker.query.Criteria;
   import org.apache.ojb.broker.query.QueryByCriteria;
   import org.apache.ojb.broker.query.QueryFactory;
  @@ -21,25 +23,35 @@
   import java.util.List;
   
   /**
  + * Test case for {@link SequenceManagerNativeImpl}. These test check
  + * support for native identity columns. Test case only works for
  + * Hsql and Mysql.
    *
    * @author <a href="mailto:armin@codeAuLait.de">Armin Waibel</a>
    * @version $Id$
    */
   public class NativeIdentifierTest extends TestCase
   {
  -    private static final String SELECT = "select * from NATIVE_TABLE";
  +    // Statements for NATIVE_TEST table
       private static final String DROP = "DROP TABLE NATIVE_TEST";
  -    private static final String CREATE =
  +    private static final String CREATE_MYSQL =
  +            "CREATE TABLE NATIVE_TEST(NATIVE_ID int(11) NOT NULL PRIMARY KEY auto_increment,NAME
VARCHAR(250))";
  +    private static final String CREATE_HSQL =
               "CREATE TABLE NATIVE_TEST(NATIVE_ID IDENTITY NOT NULL PRIMARY KEY,NAME VARCHAR(250))";
       private static final String INSERT_DUMMY = "INSERT INTO NATIVE_TEST (NAME) VALUES ('Dummy_1')";
   
  -    private static final String CREATE_REF =
  +
  +    // Statements for NATIVE_REF_TEST table
  +    private static final String CREATE_REF_MYSQL =
  +            "CREATE TABLE NATIVE_REF_TEST(NATIVE_ID int(11) NOT NULL PRIMARY KEY auto_increment,NAME
VARCHAR(250), FK_ID BIGINT)";
  +    private static final String CREATE_REF_HSQL =
               "CREATE TABLE NATIVE_REF_TEST(NATIVE_ID IDENTITY NOT NULL PRIMARY KEY,NAME
VARCHAR(250), FK_ID BIGINT)";
       private static final String DROP_REF = "DROP TABLE NATIVE_REF_TEST";
       private static final String INSERT_DUMMY_REF = "INSERT INTO NATIVE_REF_TEST (NAME)
VALUES ('Dummy_2')";
   
   
       private PersistenceBroker broker;
  +    private Platform platform;
       private Class oldSequenceManager;
   
       public NativeIdentifierTest(String s)
  @@ -55,18 +67,18 @@
   
       private boolean skipTest() throws Exception
       {
  -        PersistenceBroker pb = PersistenceBrokerFactory.defaultPersistenceBroker();
  -        boolean skip = !(pb.serviceConnectionManager().getSupportedPlatform() instanceof
PlatformHsqldbImpl);
  -        pb.close();
  +        boolean skip = !((platform instanceof PlatformMySQLImpl) || (platform instanceof
PlatformHsqldbImpl));
           return skip;
       }
   
       protected void setUp() throws Exception
       {
           super.setUp();
  -        if (skipTest()) return;
  +
   
           PersistenceBroker pb = PersistenceBrokerFactory.defaultPersistenceBroker();
  +        platform = pb.serviceConnectionManager().getSupportedPlatform();
  +        if (skipTest()) return;
           Connection con;
           Statement stmt;
           boolean needTableCreation = false;
  @@ -75,7 +87,14 @@
           {
               con = pb.serviceConnectionManager().getConnection();
               stmt = con.createStatement();
  -            stmt.executeQuery(CREATE);
  +            if(platform instanceof PlatformMySQLImpl)
  +            {
  +                stmt.execute(CREATE_MYSQL);
  +            }
  +            if(platform instanceof PlatformHsqldbImpl)
  +            {
  +                stmt.execute(CREATE_HSQL);
  +            }
               stmt.close();
   
               stmt = con.createStatement();
  @@ -83,7 +102,14 @@
               stmt.close();
   
               stmt = con.createStatement();
  -            stmt.executeQuery(CREATE_REF);
  +            if(platform instanceof PlatformMySQLImpl)
  +            {
  +                stmt.execute(CREATE_REF_MYSQL);
  +            }
  +            if(platform instanceof PlatformHsqldbImpl)
  +            {
  +                stmt.execute(CREATE_REF_HSQL);
  +            }
               stmt.close();
   
               stmt = con.createStatement();
  @@ -111,7 +137,6 @@
       protected void tearDown() throws Exception
       {
           super.tearDown();
  -        if (skipTest()) return;
   
           try
           {
  @@ -120,6 +145,8 @@
           catch (Exception e)
           {
           }
  +        if (skipTest()) return;
  +
           Connection con;
           Statement stmt;
           boolean needTableCreation = false;
  @@ -128,11 +155,11 @@
           {
               con = pb.serviceConnectionManager().getConnection();
               stmt = con.createStatement();
  -            stmt.executeQuery(DROP);
  +            stmt.execute(DROP);
               stmt.close();
   
               stmt = con.createStatement();
  -            stmt.executeQuery(DROP_REF);
  +            stmt.execute(DROP_REF);
               stmt.close();
   
               SequenceDescriptor sd = MetadataManager.getInstance().connectionRepository().
  
  
  

Mime
View raw message