Home | History | Annotate | Download | only in util
      1 package com.xtremelabs.robolectric.util;
      2 
      3 import com.xtremelabs.robolectric.WithTestDefaultsRunner;
      4 import org.junit.Before;
      5 import org.junit.Test;
      6 import org.junit.runner.RunWith;
      7 
      8 import java.sql.ResultSet;
      9 import java.sql.SQLException;
     10 
     11 import static org.hamcrest.CoreMatchers.equalTo;
     12 import static org.junit.Assert.assertThat;
     13 
     14 @RunWith(WithTestDefaultsRunner.class)
     15 public class H2MapTest {
     16 
     17     H2Map map;
     18 
     19     @Before
     20     public void setUp() throws Exception {
     21         map = new H2Map();
     22     }
     23 
     24     @Test
     25     public void testDriverClassName() {
     26         assertThat(map.getDriverClassName(), equalTo("org.h2.Driver"));
     27     }
     28 
     29     @Test
     30     public void testConnectionString() {
     31         assertThat(map.getConnectionString(), equalTo("jdbc:h2:mem:"));
     32     }
     33 
     34     @Test
     35     public void testScrubSQLReplacesAutoIncrement() throws SQLException {
     36         assertThat(map.getScrubSQL("autoincrement"), equalTo("auto_increment"));
     37     }
     38 
     39     @Test
     40     public void testScrubSQLReplacesIntegerWithBigInt() throws SQLException {
     41         assertThat(map.getScrubSQL("integer"), equalTo("bigint(19)"));
     42     }
     43 
     44     @Test
     45     public void testScrubSQLAcceptsIntegerPrimaryKey() throws SQLException {
     46         map.getScrubSQL("INTEGER PRIMARY KEY AUTOINCREMENT");
     47     }
     48 
     49     @Test(expected = SQLException.class)
     50     public void testScrubSQLRejectsIntPrimaryKeyThrowsException() throws SQLException {
     51         map.getScrubSQL("INT PRIMARY KEY AUTOINCREMENT");
     52     }
     53 
     54     @Test(expected = SQLException.class)
     55     public void testScrubSQLRejectsCharPrimaryKeyThrowsException2() throws SQLException {
     56         map.getScrubSQL("CHAR PRIMARY KEY AUTOINCREMENT");
     57     }
     58 
     59     @Test
     60     public void testGetSelectLastInsertIdentity() throws SQLException {
     61         assertThat(map.getSelectLastInsertIdentity(), equalTo("SELECT IDENTITY();"));
     62     }
     63 
     64     @Test
     65     public void testGetH2ResultSetIs_TYPE_SCROLL_INSENSITIVE() throws SQLException {
     66         assertThat(map.getResultSetType(), equalTo(ResultSet.TYPE_SCROLL_INSENSITIVE));
     67     }
     68 
     69     @Test
     70     public void scrubSQL_shouldRemoveConflictAlgorithms() throws Exception {
     71         assertThat(map.getScrubSQL("INSERT INTO "), equalTo("INSERT INTO "));
     72         assertThat(map.getScrubSQL("INSERT OR ROLLBACK INTO "), equalTo("INSERT INTO "));
     73         assertThat(map.getScrubSQL("INSERT OR ABORT INTO "), equalTo("INSERT INTO "));
     74         assertThat(map.getScrubSQL("INSERT OR FAIL INTO "), equalTo("INSERT INTO "));
     75         assertThat(map.getScrubSQL("INSERT OR IGNORE INTO "), equalTo("INSERT INTO "));
     76         assertThat(map.getScrubSQL("INSERT OR REPLACE INTO "), equalTo("INSERT INTO "));
     77     }
     78 }
     79