}
public void testIndexDiscardState()
{
SQLAppender origAppender = m_manager.getSQLAppender();
RelationalSchema schema = new RelationalSchema();
Table table = new Table(schema);
Column column = new Column("col", table);
Index index = new Index("indx", Index.CLUSTER, table);
table.setName("test"); // table name required to add table to schema, to add index to schema
schema.addTable(table);
column.setType(Primitive.INTEGER);
table.addColumn(column);
index.addIndexColumn(new IndexColumn(column, true));
table.addIndex(index);
table.setPrimaryKey(index);
schema.setDataSource(m_database);
// validate initial schema state
assertEquals(1, schema.getIndexCount());
assertEquals(index, schema.findIndex("indx"));
try
{
m_manager.setSQLAppender(m_manager.new SQLWriterAppender(new StringWriter()));
m_manager.discardIndex(index, true);
}
finally
{
m_manager.setSQLAppender(origAppender);
}
// schema definition is untouched
assertEquals(1, schema.getIndexCount());
assertEquals(index, schema.findIndex("indx"));
// index either removed or renamed
assertTrue(table.getIndexCount() == 0 || !index.getName().equals("indx"));
}