コード例 #1
0
  @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());
    }
  }
コード例 #2
0
  @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());
    }
  }