<commit_before>package org.realityforge.dbdiff;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.Properties;
import java.util.logging.ConsoleHandler;
import java.util.logging.Logger;
import org.postgresql.Driver;
import static org.testng.Assert.*;

public abstract class AbstractDatabaseDiffTest
{
  protected abstract Dialect getDialect();

  protected abstract Driver getDriver();

  protected abstract String getDatabase1();

  protected abstract String getDatabase2();

  protected final void assertMatch( final String schema,
                                    final String ddl1,
                                    final String ddl2 )
    throws Exception
  {
    assertSameDDLMatches( schema, ddl1 );
    assertSameDDLMatches( schema, ddl2 );
    diff( schema, ddl1, ddl2, true );
  }

  protected final void assertNotMatch( final String schema,
                                       final String ddl1,
                                       final String ddl2 )
    throws Exception
  {
    assertSameDDLMatches( schema, ddl1 );
    assertSameDDLMatches( schema, ddl2 );
    diff( schema, ddl1, ddl2, false );
  }

  private void assertSameDDLMatches( final String schema, final String ddl1 )
    throws Exception
  {
    diff( schema, ddl1, ddl1, true );
  }

  private void diff( final String schema,
                     final String ddl1,
                     final String ddl2,
                     final boolean shouldMatch )
    throws Exception
  {
    setupDatabases();
    final DatabaseDiff dd = newDatabaseDiff();
    dd.setLogger( newLogger() );
    dd.getSchemas().add( schema );

    executeSQL( ddl1, getDatabase1() );
    executeSQL( ddl2, getDatabase2() );

    assertEquals( dd.diff(), !shouldMatch, "Does diff match expected" );
    tearDownDatabases();
  }

  protected abstract void setupDatabases()
    throws Exception;

  protected abstract void tearDownDatabases()
    throws Exception;

  private DatabaseDiff newDatabaseDiff()
  {
    final DatabaseDiff dd = new DatabaseDiff();
    dd.setDialect( getDialect() );
    dd.setDriver( getDriver() );
    dd.setDatabase1( getDatabase1() );
    dd.setDatabase2( getDatabase2() );
    return dd;
  }

  private Logger newLogger()
  {
    final Logger logger = Logger.getAnonymousLogger();
    logger.setUseParentHandlers( false );
    final ConsoleHandler handler = new ConsoleHandler();
    handler.setFormatter( new RawFormatter() );
    logger.addHandler( handler );
    return logger;
  }

  protected final void executeSQL( final String sql, final String database )
    throws SQLException
  {
    final Connection connection1 = getDriver().connect( database, new Properties() );
    connection1.createStatement().execute( sql );
    connection1.close();
  }<commit_msg>Make it possible to setup the database properties<commit_after>package org.realityforge.dbdiff;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.Properties;
import java.util.logging.ConsoleHandler;
import java.util.logging.Logger;
import org.postgresql.Driver;
import static org.testng.Assert.*;

public abstract class AbstractDatabaseDiffTest
{
  protected abstract Dialect getDialect();

  protected abstract Driver getDriver();

  protected abstract String getDatabase1();

  protected abstract String getDatabase2();

  protected Properties getDbProperties()
  {
    return new Properties();
  }

  protected final void assertMatch( final String schema,
                                    final String ddl1,
                                    final String ddl2 )
    throws Exception
  {
    assertSameDDLMatches( schema, ddl1 );
    assertSameDDLMatches( schema, ddl2 );
    diff( schema, ddl1, ddl2, true );
  }

  protected final void assertNotMatch( final String schema,
                                       final String ddl1,
                                       final String ddl2 )
    throws Exception
  {
    assertSameDDLMatches( schema, ddl1 );
    assertSameDDLMatches( schema, ddl2 );
    diff( schema, ddl1, ddl2, false );
  }

  private void assertSameDDLMatches( final String schema, final String ddl1 )
    throws Exception
  {
    diff( schema, ddl1, ddl1, true );
  }

  private void diff( final String schema,
                     final String ddl1,
                     final String ddl2,
                     final boolean shouldMatch )
    throws Exception
  {
    setupDatabases();
    final DatabaseDiff dd = newDatabaseDiff();
    dd.setLogger( newLogger() );
    dd.getSchemas().add( schema );

    executeSQL( ddl1, getDatabase1() );
    executeSQL( ddl2, getDatabase2() );

    assertEquals( dd.diff(), !shouldMatch, "Does diff match expected" );
    tearDownDatabases();
  }

  protected abstract void setupDatabases()
    throws Exception;

  protected abstract void tearDownDatabases()
    throws Exception;

  private DatabaseDiff newDatabaseDiff()
  {
    final DatabaseDiff dd = new DatabaseDiff();
    dd.setDialect( getDialect() );
    dd.setDriver( getDriver() );
    dd.setDatabase1( getDatabase1() );
    dd.setDatabase2( getDatabase2() );
    return dd;
  }

  private Logger newLogger()
  {
    final Logger logger = Logger.getAnonymousLogger();
    logger.setUseParentHandlers( false );
    final ConsoleHandler handler = new ConsoleHandler();
    handler.setFormatter( new RawFormatter() );
    logger.addHandler( handler );
    return logger;
  }

  protected final void executeSQL( final String sql, final String database )
    throws SQLException
  {
    final Connection connection1 = getDriver().connect( database, getDbProperties() );
    connection1.createStatement().execute( sql );
    connection1.close();
  }
{'fraction_non_alphanumeric': 0.08606124604012672, 'fraction_numerical': 0.010559662090813094, 'mean_word_length': 2.829514824797844, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1694503', 'n_tokens_mistral': 1578, 'n_tokens_neox': 1511, 'n_words': 448}