Search in sources :

Example 1 with SystemExitPreventedException

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));
    }
}
Also used : Path(java.nio.file.Path) HashMap(java.util.HashMap) SystemExitPreventedException(com.ginsberg.junit.exit.SystemExitPreventedException) Test(org.junit.jupiter.api.Test) BaseSqliteTest(schemacrawler.test.utility.BaseSqliteTest) ExpectSystemExitWithStatus(com.ginsberg.junit.exit.ExpectSystemExitWithStatus)

Example 2 with SystemExitPreventedException

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")));
}
Also used : HashMap(java.util.HashMap) SchemaTextDetailType(schemacrawler.tools.command.text.schema.options.SchemaTextDetailType) OutputFormat(schemacrawler.tools.options.OutputFormat) TextOutputFormat(schemacrawler.tools.command.text.schema.options.TextOutputFormat) SystemExitPreventedException(com.ginsberg.junit.exit.SystemExitPreventedException) InfoLevel(schemacrawler.schemacrawler.InfoLevel) Test(org.junit.jupiter.api.Test) ExpectSystemExitWithStatus(com.ginsberg.junit.exit.ExpectSystemExitWithStatus)

Aggregations

ExpectSystemExitWithStatus (com.ginsberg.junit.exit.ExpectSystemExitWithStatus)2 SystemExitPreventedException (com.ginsberg.junit.exit.SystemExitPreventedException)2 HashMap (java.util.HashMap)2 Test (org.junit.jupiter.api.Test)2 Path (java.nio.file.Path)1 InfoLevel (schemacrawler.schemacrawler.InfoLevel)1 BaseSqliteTest (schemacrawler.test.utility.BaseSqliteTest)1 SchemaTextDetailType (schemacrawler.tools.command.text.schema.options.SchemaTextDetailType)1 TextOutputFormat (schemacrawler.tools.command.text.schema.options.TextOutputFormat)1 OutputFormat (schemacrawler.tools.options.OutputFormat)1