@Test
  public void shouldNotApplyScripts() throws Exception {
    List<ChangeScript> changes = new ArrayList<ChangeScript>();
    ChangeScript changeScript = new StubChangeScript(1, "script", "content");
    changes.add(changeScript);

    when(splitter.split("content")).thenReturn(Arrays.asList("content"));

    applier.apply(changes);

    verify(queryExecuter, never()).execute(anyString());
    verify(schemaVersionManager).recordScriptApplied(changeScript);
  }
示例#2
0
  public void go() throws Exception {
    System.err.println(getWelcomeString());

    validate();

    QueryExecuter queryExecuter;

    if (dataSource == null) {
      Class.forName(driver);
      queryExecuter = new QueryExecuter(url, userid, password);
    } else {
      queryExecuter = new QueryExecuter(dataSource);
    }

    DatabaseSchemaVersionManager databaseSchemaVersionManager =
        new DatabaseSchemaVersionManager(queryExecuter, changeLogTableName);

    ChangeScriptRepository changeScriptRepository =
        new ChangeScriptRepository(
            new DirectoryScanner(encoding).getChangeScriptsForDirectory(scriptdirectory));

    ChangeScriptApplier doScriptApplier;

    if (outputfile != null) {
      doScriptApplier =
          new TemplateBasedApplier(
              new PrintWriter(outputfile, encoding),
              dbms,
              changeLogTableName,
              delimiter,
              delimiterType,
              getTemplatedir());
    } else {
      QueryStatementSplitter splitter = new QueryStatementSplitter();
      splitter.setDelimiter(getDelimiter());
      splitter.setDelimiterType(getDelimiterType());
      splitter.setOutputLineEnding(lineEnding);
      doScriptApplier =
          new DirectToDbApplier(queryExecuter, databaseSchemaVersionManager, splitter);
    }

    ChangeScriptApplier undoScriptApplier = null;

    if (undoOutputfile != null) {
      undoScriptApplier =
          new UndoTemplateBasedApplier(
              new PrintWriter(undoOutputfile),
              dbms,
              changeLogTableName,
              delimiter,
              delimiterType,
              templatedir);
    }

    Controller controller =
        new Controller(
            changeScriptRepository,
            databaseSchemaVersionManager,
            doScriptApplier,
            undoScriptApplier);

    controller.processChangeScripts(lastChangeToApply);

    queryExecuter.close();
  }