@Test
  public void testSchema() throws Exception {
    final SchemaCrawlerOptions schemaCrawlerOptions =
        (SchemaCrawlerOptions) appContext.getBean("schemaCrawlerOptions");

    final Schema schema = testUtility.getSchema(schemaCrawlerOptions, "PUBLIC");
    assertNotNull("Could not obtain schema", schema);

    assertEquals("Unexpected number of tables in the schema", 6, schema.getTables().length);
  }
  private void executeAndCheckForOutputFile(
      final String executableName, final Executable executable, final List<String> failures)
      throws Exception {
    final File testOutputFile =
        File.createTempFile("schemacrawler." + executableName + ".", ".test");
    testOutputFile.delete();

    executable.getOutputOptions().setOutputFileName(testOutputFile.getAbsolutePath());
    executable.execute(testUtility.getConnection());

    failures.addAll(
        TestUtility.compareOutput(executableName + ".txt", testOutputFile, (OutputFormat) null));
  }
  @Test
  public void compareInfoLevelOutput() throws Exception {
    final List<String> failures = new ArrayList<String>();
    for (final InfoLevel infoLevel : InfoLevel.values()) {
      if (infoLevel == InfoLevel.unknown) {
        continue;
      }
      for (final SchemaTextDetailType schemaTextDetailType : SchemaTextDetailType.values()) {
        final String referenceFile = schemaTextDetailType + "_" + infoLevel + ".txt";

        final File testOutputFile =
            File.createTempFile("schemacrawler." + referenceFile + ".", ".test");
        testOutputFile.delete();

        final OutputOptions outputOptions =
            new OutputOptions(OutputFormat.text.name(), testOutputFile);
        outputOptions.setNoInfo(false);
        outputOptions.setNoHeader(false);
        outputOptions.setNoFooter(false);

        final Config config =
            Config.load(
                SchemaCrawlerOutputTest.class.getResourceAsStream(
                    "/hsqldb.INFORMATION_SCHEMA.config.properties"));
        final SchemaCrawlerOptions schemaCrawlerOptions = new SchemaCrawlerOptions(config);
        schemaCrawlerOptions.setSchemaInfoLevel(infoLevel.getSchemaInfoLevel());

        final DatabaseConnectionOptions connectionOptions =
            testUtility.getDatabaseConnectionOptions();

        final Executable executable = new SchemaCrawlerExecutable(schemaTextDetailType.name());
        executable.setSchemaCrawlerOptions(schemaCrawlerOptions);
        executable.setOutputOptions(outputOptions);
        executable.execute(connectionOptions.getConnection());

        failures.addAll(
            TestUtility.compareOutput(
                INFO_LEVEL_OUTPUT + referenceFile,
                testOutputFile,
                outputOptions.getOutputFormat()));
      }
    }
    if (failures.size() > 0) {
      fail(failures.toString());
    }
  }
 @BeforeClass
 public static void beforeAllTests() throws Exception {
   TestDatabase.initializeApplicationLogging();
   testUtility.createMemoryDatabase();
 }
 @AfterClass
 public static void afterAllTests() {
   testUtility.shutdownDatabase();
 }
  @Test
  public void compareCompositeOutput() throws Exception {
    final String queryCommand1 = "all_tables";
    final Config queriesConfig = new Config();
    queriesConfig.put(queryCommand1, "SELECT * FROM INFORMATION_SCHEMA.SYSTEM_TABLES");
    final String queryCommand2 = "dump_tables";
    queriesConfig.put(
        queryCommand2, "SELECT ${orderbycolumns} FROM ${table} ORDER BY ${orderbycolumns}");

    final String[] commands =
        new String[] {
          SchemaTextDetailType.details + "," + Operation.count + "," + Operation.dump,
          SchemaTextDetailType.list + "," + Operation.count,
          queryCommand1
              + ","
              + queryCommand2
              + ","
              + Operation.count
              + ","
              + SchemaTextDetailType.list,
        };

    final List<String> failures = new ArrayList<String>();
    for (final OutputFormat outputFormat : OutputFormat.values()) {
      for (final String command : commands) {
        final String referenceFile = command + "." + outputFormat.name();

        final File testOutputFile =
            File.createTempFile("schemacrawler." + referenceFile + ".", ".test");
        testOutputFile.delete();

        final OutputOptions outputOptions = new OutputOptions(outputFormat.name(), testOutputFile);
        outputOptions.setNoInfo(false);
        outputOptions.setNoHeader(false);
        outputOptions.setNoFooter(false);

        final Config config =
            Config.load(
                SchemaCrawlerOutputTest.class.getResourceAsStream(
                    "/hsqldb.INFORMATION_SCHEMA.config.properties"));
        final SchemaCrawlerOptions schemaCrawlerOptions = new SchemaCrawlerOptions(config);
        schemaCrawlerOptions.setSchemaInfoLevel(SchemaInfoLevel.maximum());

        final DatabaseConnectionOptions connectionOptions =
            testUtility.getDatabaseConnectionOptions();

        final SchemaCrawlerExecutable executable = new SchemaCrawlerExecutable(command);
        executable.setSchemaCrawlerOptions(schemaCrawlerOptions);
        executable.setOutputOptions(outputOptions);
        executable.setAdditionalConfiguration(queriesConfig);
        executable.execute(connectionOptions.getConnection());

        failures.addAll(
            TestUtility.compareOutput(
                COMPOSITE_OUTPUT + referenceFile, testOutputFile, outputFormat));
      }
    }
    if (failures.size() > 0) {
      fail(failures.toString());
    }
  }
 @BeforeClass
 public static void beforeAllTests() throws Exception {
   TestDatabase.initializeApplicationLogging();
   testUtility.startMemoryDatabase();
   XMLUnit.setControlEntityResolver(new LocalEntityResolver());
 }
Ejemplo n.º 8
0
 @Test(expected = SQLException.class)
 public void retrieverConnectionClosed() throws SQLException, SchemaCrawlerException {
   final Connection connection = testUtility.getConnection();
   connection.close();
   final RetrieverConnection retrieverConnection = new RetrieverConnection(connection, null);
 }