schema.addTable(schema.getVersionTable());
upgrade.setMetadata(metadata);
// setup for first upgrade version
ExecStep execStep = new ExecStep(); // step lacking match for current adapter
SQLScript stepScript = new SQLScript();
SQLStatement stepStmt = new SQLStatement();
stepStmt.addAdapter(invalid.getName(), ds.getType());
stepStmt.setSQL("SQLStatement SQL");
stepScript.addStatement(stepStmt);
execStep.getScriptHolder().addScript(stepScript);
// single incompatible step
metadata.setVersion("1-step");
upgradeVersion = new RelationalSchemaUpgrade(metadata.getVersion());
upgradeVersion.addStep(execStep);
upgradeVersion.setDataSource(ds);
upgrade.addVersion(upgradeVersion);
try
{
upgrade.validate(null, null); // must fail since an incompatible step "1-step" exists
fail(); // exception expected
}
catch (MetadataException e)
{
assertTrue(e.getCause() instanceof MetadataException);
e = (MetadataException)e.getCause();
assertTrue(e.getCause() instanceof MetadataException);
e = (MetadataException)e.getCause();
assertTrue(e.getCause() instanceof MetadataException);
e = (MetadataException)e.getCause();
assertEquals("err.meta.sql.statementAdapter", e.getErrorCode());
}
try
{
manager.upgrade(schema, null); //must fail since no compatible versions found to start with
fail(); // exception expected
}
catch (MetadataException e)
{
assertTrue(e.getCause() instanceof MetadataException);
e = (MetadataException)e.getCause();
assertTrue(e.getCause() instanceof MetadataException);
e = (MetadataException)e.getCause();
assertTrue(e.getCause() instanceof MetadataException);
e = (MetadataException)e.getCause();
assertEquals("err.meta.sql.statementAdapter", e.getErrorCode());
}
try
{
manager.upgrade(schema, "1-step"); // must fail since step "1-step" is incompatible
fail(); // exception expected
}
catch (MetadataException e)
{
assertTrue(e.getCause() instanceof MetadataException);
e = (MetadataException)e.getCause();
assertTrue(e.getCause() instanceof MetadataException);
e = (MetadataException)e.getCause();
assertTrue(e.getCause() instanceof MetadataException);
e = (MetadataException)e.getCause();
assertEquals("err.meta.sql.statementAdapter", e.getErrorCode());
}
// setup for second upgrade version
SupportAdapterStep adapterStep = new SupportAdapterStep();
CreateTableStep createTableStep = new CreateTableStep(); // step has match for current adapter
Table table = new Table(schema);
SQLScript tableScript = new SQLScript();
SQLStatement tableStmtInvalid = new SQLStatement();
SQLStatement tableStmtValid = new SQLStatement();
tableStmtInvalid.addAdapter(invalid.getName(), ds.getType());
tableStmtInvalid.setSQL("SQLStatement Table SQL Invalid");
tableStmtValid.addAdapter(ds.getAdapter().getName(), ds.getType());
tableStmtValid.setSQL("SQLStatement Table SQL Valid");
tableScript.addStatement(tableStmtValid);
tableScript.addStatement(tableStmtInvalid);
tableScript.addStatement(stepStmt);
table.setName("Table");
table.setType(Table.VIEW);
table.setViewScript(tableScript);
schema.addTable(table);
createTableStep.setName(table.getName());