Search in sources :

Example 6 with ExpectSystemExitWithStatus

use of com.ginsberg.junit.exit.ExpectSystemExitWithStatus 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 7 with ExpectSystemExitWithStatus

use of com.ginsberg.junit.exit.ExpectSystemExitWithStatus 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)

Example 8 with ExpectSystemExitWithStatus

use of com.ginsberg.junit.exit.ExpectSystemExitWithStatus in project SchemaCrawler by schemacrawler.

the class ShellCommandsTest method exit.

@Test
@ExpectSystemExitWithStatus(0)
public void exit(final TestContext testContext) {
    new ExitCommand().run();
    assertThat(outputOf(err), hasNoContent());
    assertThat(outputOf(out), hasNoContent());
}
Also used : ExitCommand(schemacrawler.tools.commandline.shell.ExitCommand) Test(org.junit.jupiter.api.Test) ExpectSystemExitWithStatus(com.ginsberg.junit.exit.ExpectSystemExitWithStatus)

Example 9 with ExpectSystemExitWithStatus

use of com.ginsberg.junit.exit.ExpectSystemExitWithStatus in project keycloak-config-cli by adorsys.

the class CommandLineImportFilesIT method testImportDirectory.

@Test
@ExpectSystemExitWithStatus(0)
void testImportDirectory() {
    KeycloakConfigApplication.main(new String[] { "--keycloak.sslVerify=false", "--import.path=src/test/resources/import-files/cli/dir/" });
    RealmRepresentation file1Realm = keycloakProvider.getInstance().realm("file1").toRepresentation();
    assertThat(file1Realm.getRealm(), is("file1"));
    assertThat(file1Realm.isEnabled(), is(true));
    RealmRepresentation file2Realm = keycloakProvider.getInstance().realm("file2").toRepresentation();
    assertThat(file2Realm.getRealm(), is("file2"));
    assertThat(file2Realm.isEnabled(), is(true));
}
Also used : RealmRepresentation(org.keycloak.representations.idm.RealmRepresentation) Test(org.junit.jupiter.api.Test) ExpectSystemExitWithStatus(com.ginsberg.junit.exit.ExpectSystemExitWithStatus)

Aggregations

ExpectSystemExitWithStatus (com.ginsberg.junit.exit.ExpectSystemExitWithStatus)9 Test (org.junit.jupiter.api.Test)9 File (java.io.File)3 SystemExitPreventedException (com.ginsberg.junit.exit.SystemExitPreventedException)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 PrintStream (java.io.PrintStream)2 HashMap (java.util.HashMap)2 RealmRepresentation (org.keycloak.representations.idm.RealmRepresentation)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 FileInputStream (java.io.FileInputStream)1 FileOutputStream (java.io.FileOutputStream)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 URL (java.net.URL)1 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