Example #1
0
 /** Test method for {@link org.melati.poem.dbms.Dbms#getStringSqlDefinition(int)}. */
 public void testGetStringSqlDefinition() throws Exception {
   assertEquals("VARCHAR(0)", it.getStringSqlDefinition(0));
   try {
     it.getStringSqlDefinition(-1);
     fail("Should have blown up");
   } catch (SQLException e) {
     e = null;
   }
 }
Example #2
0
 /** Test method for {@link org.melati.poem.dbms.Dbms# getBinarySqlDefinition(int)}. */
 public void testGetBinarySqlDefinition() throws Exception {
   assertEquals("LONGVARBINARY(0)", it.getBinarySqlDefinition(0));
   try {
     it.getBinarySqlDefinition(-1);
     fail("Should have blown up");
   } catch (SQLException e) {
     e = null;
   }
 }
Example #3
0
 /**
  * Test method for {@link org.melati.poem.dbms.Dbms# getForeignKeyDefinition(java.lang.String,
  * java.lang.String, java.lang.String, java.lang.String, java.lang.String)}.
  */
 public void testGetForeignKeyDefinition() {
   assertEquals(
       " ADD FOREIGN KEY (\"user\") REFERENCES \"user\"(\"id\") ON DELETE RESTRICT",
       it.getForeignKeyDefinition("test", "user", "user", "id", "prevent"));
   assertEquals(
       " ADD FOREIGN KEY (\"user\") REFERENCES \"user\"(\"id\") ON DELETE SET NULL",
       it.getForeignKeyDefinition("test", "user", "user", "id", "clear"));
   assertEquals(
       " ADD FOREIGN KEY (\"user\") REFERENCES \"user\"(\"id\") ON DELETE CASCADE",
       it.getForeignKeyDefinition("test", "user", "user", "id", "delete"));
 }
Example #4
0
  /**
   * Test method for {@link org.melati.poem.dbms.Dbms# canRepresent(org.melati.poem.PoemType,
   * org.melati.poem.PoemType)}.
   */
  public void testCanRepresent() {
    assertNull(it.canRepresent(StringPoemType.nullableInstance, IntegerPoemType.nullableInstance));
    assertNull(it.canRepresent(IntegerPoemType.nullableInstance, StringPoemType.nullableInstance));

    assertNull(it.canRepresent(new BigDecimalPoemType(false), new BigDecimalPoemType(true)));
    assertTrue(
        it.canRepresent(new BigDecimalPoemType(true), new BigDecimalPoemType(false))
            instanceof BigDecimalPoemType);

    assertNull(it.canRepresent(new StringPoemType(true, 250), new StringPoemType(true, -1)));
  }
Example #5
0
 /**
  * Test method for {@link org.melati.poem.dbms.Dbms# getFixedPtSqlDefinition(int, int)}.
  *
  * @throws Exception
  */
 public void testGetFixedPtSqlDefinition() throws Exception {
   assertEquals("DECIMAL(2,22)", it.getFixedPtSqlDefinition(22, 2));
   try {
     it.getFixedPtSqlDefinition(-1, 2);
     fail("Should have blown up");
   } catch (SQLException e) {
     e = null;
   }
   try {
     it.getFixedPtSqlDefinition(22, -1);
     fail("Should have blown up");
   } catch (SQLException e) {
     e = null;
   }
 }
Example #6
0
 /**
  * Test method for {@link org.melati.poem.dbms.Dbms# getSqlDefinition(java.lang.String)}.
  *
  * @throws Exception
  */
 public void testGetSqlDefinition() throws Exception {
   assertEquals("BOOLEAN", it.getSqlDefinition("BOOLEAN"));
   assertEquals("DOUBLE PRECISION", it.getSqlDefinition("DOUBLE PRECISION"));
   assertEquals("INT8", it.getSqlDefinition("INT8"));
   assertEquals("INT", it.getSqlDefinition("INT"));
   assertEquals("Big Decimal", it.getSqlDefinition("Big Decimal"));
   assertEquals("STRING", it.getSqlDefinition("STRING"));
 }
Example #7
0
 /**
  * Test method for {@link org.melati.poem.dbms.Dbms# caseInsensitiveRegExpSQL(java.lang.String,
  * java.lang.String)}.
  */
 public void testCaseInsensitiveRegExpSQLBlank() {
   String expected = " ILIKE '%%'";
   String actual = it.caseInsensitiveRegExpSQL("", "");
   assertEquals(expected, actual);
 }
Example #8
0
 /**
  * Test method for {@link org.melati.poem.dbms.Dbms# caseInsensitiveRegExpSQL(java.lang.String,
  * java.lang.String)}.
  */
 public void testCaseInsensitiveRegExpSQLQuoted() {
   String expected = "a ILIKE '%b%'";
   String actual = it.caseInsensitiveRegExpSQL("a", "\"b\"");
   assertEquals(expected, actual);
 }
Example #9
0
 /**
  * Test method for {@link org.melati.poem.dbms.Dbms# givesCapabilitySQL(java.lang.Integer,
  * java.lang.String)}.
  */
 public void testGivesCapabilitySQL() {
   String actual = it.givesCapabilitySQL(new Integer(42), "hello");
   String expected =
       "SELECT * FROM "
           + it.getQuotedName("groupmembership")
           + " WHERE "
           + it.getQuotedName("user")
           + " = 42 AND "
           + "EXISTS ( SELECT "
           + it.getQuotedName("groupcapability")
           + "."
           + it.getQuotedName("group")
           + " FROM "
           + it.getQuotedName("groupcapability")
           + " WHERE "
           + it.getQuotedName("groupcapability")
           + "."
           + it.getQuotedName("group")
           + " = "
           + it.getQuotedName("groupmembership")
           + "."
           + it.getQuotedName("group")
           + " AND "
           + it.getQuotedName("capability")
           + " = hello)";
   assertEquals(expected, actual);
 }
Example #10
0
 /**
  * Test method for {@link org.melati.poem.dbms.Dbms# getIndexLength(org.melati.poem.Column)}.
  *
  * @throws Exception
  */
 public void testGetIndexLength() throws Exception {
   assertEquals("", it.getIndexLength(null));
 }
Example #11
0
 /** Test method for {@link org.melati.poem.dbms.Dbms#melatiName(java.lang.String)}. */
 public void testMelatiName() {
   assertEquals("name", it.melatiName("name"));
   assertEquals(null, it.melatiName(null));
   assertEquals("~Special", it.melatiName("~Special"));
 }
Example #12
0
 /**
  * Test method for {@link org.melati.poem.dbms.Dbms#
  * preparedStatementPlaceholder(org.melati.poem.PoemType)}.
  */
 public void testPreparedStatementPlaceholder() {
   assertEquals("?", it.preparedStatementPlaceholder(new IntegerPoemType(true)));
   assertEquals("?", it.preparedStatementPlaceholder(new LongPoemType(true)));
   assertEquals("?", it.preparedStatementPlaceholder(new DoublePoemType(true)));
   assertEquals("?", it.preparedStatementPlaceholder(new StringPoemType(true, -1)));
 }
Example #13
0
 public String sqlDefaultValue(Dbms dbms) {
   return dbms.getSqlDefaultValue(this);
 }
Example #14
0
 /**
  * {@inheritDoc}
  *
  * @see junit.framework.TestCase#tearDown()
  */
 protected void tearDown() throws Exception {
   // super.tearDown();
   it.unloadDriver();
 }
Example #15
0
 /**
  * Test method for {@link org.melati.poem.dbms.Dbms# getPrimaryKeyDefinition(java.lang.String)}.
  */
 public void testGetPrimaryKeyDefinition() {
   assertEquals(" ADD PRIMARY KEY (\"name\")", it.getPrimaryKeyDefinition("name"));
 }
Example #16
0
 /** Test method for {@link org.melati.poem.dbms.Dbms#createTableSql()}. */
 public void testCreateTableSql() {
   if (getDb().getDbms() == it)
     assertEquals(
         "CREATE TABLE \"MELATI_USER\" (\"id\" INT NOT NULL, \"name\" VARCHAR(60) NOT NULL, \"login\" VARCHAR(255) NOT NULL, \"password\" VARCHAR(20) NOT NULL)",
         it.createTableSql(getDb().getUserTable()));
 }
Example #17
0
 /** Test method for {@link org.melati.poem.dbms.Dbms# sqlBooleanValueOfRaw(java.lang.Object)}. */
 public void testSqlBooleanValueOfRaw() {
   assertEquals("false", it.sqlBooleanValueOfRaw(Boolean.FALSE));
   assertEquals("true", it.sqlBooleanValueOfRaw(Boolean.TRUE));
 }
Example #18
0
 /** Test method for {@link org.melati.poem.dbms.Dbms# getLongSqlDefinition()}. */
 public void testGetLongSqlDefinition() {
   assertEquals("INT8", it.getLongSqlDefinition());
 }
Example #19
0
 /** Test method for {@link org.melati.poem.dbms.Dbms#createTableOptionsSql()}. */
 public void testCreateTableOptionsSql() {
   assertEquals("", it.createTableOptionsSql());
 }
Example #20
0
 /** Test method for {@link org.melati.poem.dbms.Dbms# selectLimit(java.lang.String, int)}. */
 public void testSelectLimit() {
   assertEquals("SELECT * FROM \"USER\" LIMIT 1", it.selectLimit("* FROM \"USER\"", 1));
 }
Example #21
0
 /** Test method for {@link org.melati.poem.dbms.Dbms# canDropColumns(java.sql.Connection)}. */
 public void testCanDropColumns() throws Exception {
   assertTrue(it.canDropColumns());
 }
Example #22
0
 /** Test method for {@link org.melati.poem.dbms.Dbms#getSchema()}. */
 public void testGetSchema() {
   assertNull(it.getSchema());
 }
Example #23
0
 /** Test method for {@link org.melati.poem.dbms.Dbms# unreservedName(java.lang.String)}. */
 public void testUnreservedName() {
   assertEquals("name", it.unreservedName("name"));
 }
Example #24
0
 protected String _sqlDefinition(Dbms dbms) {
   return dbms.getSqlDefinition(sqlTypeName);
 }
Example #25
0
 /** Test method for {@link org.melati.poem.dbms.Dbms# getJdbcMetadataName(java.lang.String)}. */
 public void testGetJdbcMetadataName() {
   assertEquals("name", it.getJdbcMetadataName("name"));
 }