use of com.ginsberg.junit.exit.SystemExitPreventedException in project SchemaCrawler by schemacrawler.
the class SqliteCommandlineTest method testSqliteMainMissingDatabase.
@Test
@ExpectSystemExitWithStatus(1)
public void testSqliteMainMissingDatabase() throws Exception {
final Path sqliteDbFile = Paths.get(System.getProperty("java.io.tmpdir"), RandomStringUtils.randomAlphanumeric(12).toLowerCase() + ".db");
assertThat("SQLite database should exist before the test", sqliteDbFile.toFile(), not(anExistingFile()));
final Map<String, String> argsMap = new HashMap<>();
argsMap.put("--server", "sqlite");
argsMap.put("--database", sqliteDbFile.toString());
argsMap.put("--no-info", Boolean.TRUE.toString());
argsMap.put("--command", "list");
argsMap.put("--info-level", InfoLevel.minimum.name());
try {
Main.main(flattenCommandlineArgs(argsMap));
} catch (final SystemExitPreventedException e) {
assertThat("An empty SQLite database should not be created when SchemaCrawler connects", sqliteDbFile.toFile(), not(anExistingFile()));
final int exitCode = e.getStatusCode();
assertThat(exitCode, is(1));
}
}
use of com.ginsberg.junit.exit.SystemExitPreventedException in project SchemaCrawler by schemacrawler.
the class MetadataRetrievalStrategyTest method overrideMetadataRetrievalStrategyDataDictionary.
@Test
@ExpectSystemExitWithStatus(1)
public void overrideMetadataRetrievalStrategyDataDictionary(final TestContext testContext, final DatabaseConnectionInfo connectionInfo) throws Exception {
final SchemaTextDetailType schemaTextDetailType = SchemaTextDetailType.schema;
final InfoLevel infoLevel = InfoLevel.minimum;
final OutputFormat outputFormat = TextOutputFormat.text;
final Map<String, Object> config = new HashMap<>();
config.put("schemacrawler.schema.retrieval.strategy.tables", MetadataRetrievalStrategy.data_dictionary_all.name());
final Map<String, String> argsMap = new HashMap<>();
argsMap.put("--info-level", infoLevel.name());
// Check that System.err has an error, since the SQL for retrieving tables was not provided
try {
assertThat(outputOf(commandlineExecution(connectionInfo, schemaTextDetailType.name(), argsMap, config, outputFormat)), hasNoContent());
} catch (final SystemExitPreventedException e) {
// Continue execution
}
assertThat(outputOf(err), hasSameContentAs(classpathResource(METADATA_RETRIEVAL_STRATEGY_OUTPUT + testContext.testMethodName() + ".stderr.txt")));
}
Aggregations