<commit_before>package liquibase;

import liquibase.ClassLoaderFileOpener;
import liquibase.FileOpener;
import liquibase.Liquibase;
import liquibase.lock.LockHandler;
import liquibase.test.DatabaseTestTemplate;
import liquibase.test.SqlStatementDatabaseTest;
import liquibase.test.DatabaseTest;
import liquibase.test.JdbcDatabaseTest;
import liquibase.database.*;
import liquibase.database.structure.DatabaseSnapshot;
import liquibase.database.sql.DropTableStatement;
import liquibase.database.template.JdbcOutputTemplate;
import liquibase.database.template.JdbcTemplate;
import liquibase.exception.JDBCException;
import static org.easymock.EasyMock.expect;
import static org.easymock.EasyMock.expectLastCall;
import static org.easymock.classextension.EasyMock.*;
import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Test;

import java.io.InputStream;
import java.io.PrintWriter;
import java.net.URL;
import java.sql.DatabaseMetaData;
import java.util.Enumeration;
import java.util.List;

/**
 * Tests for {@link liquibase.Liquibase}
 */
public class LiquibaseTest {

    private TestLiquibase testLiquibase;
    private DatabaseConnection connectionForConstructor;

    @Before
    public void setUp() throws Exception {
        if (connectionForConstructor != null) {
            reset(connectionForConstructor);
        }
        connectionForConstructor = createMock(DatabaseConnection.class);
        connectionForConstructor.setAutoCommit(false);
        expectLastCall().atLeastOnce();

        DatabaseMetaData metaData = createMock(DatabaseMetaData.class);
        expect(metaData.getDatabaseProductName()).andReturn("Oracle");
        replay(metaData);

        expect(connectionForConstructor.getMetaData()).andReturn(metaData);
        replay(connectionForConstructor);

        testLiquibase = new TestLiquibase();
    }

    @Test
    public void isSaveToRunMigration() throws Exception {
        TestLiquibase liquibase = testLiquibase;

        liquibase.setUrl("jdbc:oracle:thin:@localhost:1521:latest");
        assertTrue(liquibase.isSafeToRunMigration());

        liquibase.setUrl("jdbc:oracle:thin:@liquibase:1521:latest");
        assertFalse(liquibase.isSafeToRunMigration());

        testLiquibase.getDatabase().setJdbcTemplate(new JdbcOutputTemplate(new PrintWriter(System.out), testLiquibase.getDatabase()));
        assertTrue("Safe to run if outputing sql, even if non-localhost URL", liquibase.isSafeToRunMigration());

    }

    @Test
    public void getImplementedDatabases() throws Exception {
        List<Database> databases = DatabaseFactory.getInstance().getImplementedDatabases();
        assertEquals(13, databases.size());

        boolean foundOracle = false;
        boolean foundPostgres = false;
        boolean foundMSSQL = false;

        for (Database db : databases) {
            if (db instanceof OracleDatabase) {
                foundOracle = true;
            } else if (db instanceof PostgresDatabase) {
                foundPostgres = true;
            } else if (db instanceof MSSQLDatabase) {
                foundMSSQL = true;
            }
        }

        assertTrue("Oracle not in Implemented Databases", foundOracle);
        assertTrue("MSSQL not in Implemented Databases", foundMSSQL);
        assertTrue("Postgres not in Implemented Databases", foundPostgres);
    }

    private class TestLiquibase extends Liquibase {
        private String url;
        private Database database;
        private InputStream inputStream;

        public TestLiquibase() {
            super("liquibase/test.xml", new ClassLoaderFileOpener(), null);
            inputStream = createMock(InputStream.class);
            replay(inputStream);
        }

        public Database getDatabase() {
            if (database == null) {
                database = new OracleDatabase() {
                    public String getConnectionURL() {
                        return url;
                    }

                    public String getConnectionUsername() {
                        return "testUser";
                    }
                };
            }
            return database;
        }

        public void setDatabase(Database database) {
            this.database = database;
        }<commit_msg>fixed compilation issue<commit_after>package liquibase;

import liquibase.ClassLoaderFileOpener;
import liquibase.FileOpener;
import liquibase.Liquibase;
import liquibase.lock.LockHandler;
import liquibase.test.DatabaseTestTemplate;
import liquibase.test.SqlStatementDatabaseTest;
import liquibase.test.DatabaseTest;
import liquibase.test.JdbcDatabaseTest;
import liquibase.database.*;
import liquibase.database.structure.DatabaseSnapshot;
import liquibase.database.sql.DropTableStatement;
import liquibase.database.template.JdbcOutputTemplate;
import liquibase.database.template.JdbcTemplate;
import liquibase.exception.JDBCException;
import static org.easymock.EasyMock.expect;
import static org.easymock.EasyMock.expectLastCall;
import static org.easymock.classextension.EasyMock.*;
import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Test;

import java.io.InputStream;
import java.io.PrintWriter;
import java.net.URL;
import java.sql.DatabaseMetaData;
import java.util.Enumeration;
import java.util.List;

/**
 * Tests for {@link liquibase.Liquibase}
 */
public class LiquibaseTest {

    private TestLiquibase testLiquibase;
    private DatabaseConnection connectionForConstructor;

    @Before
    public void setUp() throws Exception {
        if (connectionForConstructor != null) {
            reset(connectionForConstructor);
        }
        connectionForConstructor = createMock(DatabaseConnection.class);
        connectionForConstructor.setAutoCommit(false);
        expectLastCall().atLeastOnce();

        DatabaseMetaData metaData = createMock(DatabaseMetaData.class);
        expect(metaData.getDatabaseProductName()).andReturn("Oracle");
        replay(metaData);

        expect(connectionForConstructor.getMetaData()).andReturn(metaData);
        replay(connectionForConstructor);

        testLiquibase = new TestLiquibase();
    }

    @Test
    public void isSaveToRunMigration() throws Exception {
        TestLiquibase liquibase = testLiquibase;

        liquibase.setUrl("jdbc:oracle:thin:@localhost:1521:latest");
        assertTrue(liquibase.isSafeToRunMigration());

        liquibase.setUrl("jdbc:oracle:thin:@liquibase:1521:latest");
        assertFalse(liquibase.isSafeToRunMigration());

        testLiquibase.getDatabase().setJdbcTemplate(new JdbcOutputTemplate(new PrintWriter(System.out), testLiquibase.getDatabase()));
        assertTrue("Safe to run if outputing sql, even if non-localhost URL", liquibase.isSafeToRunMigration());

    }

    @Test
    public void getImplementedDatabases() throws Exception {
        List<Database> databases = DatabaseFactory.getInstance().getImplementedDatabases();
        assertEquals(13, databases.size());

        boolean foundOracle = false;
        boolean foundPostgres = false;
        boolean foundMSSQL = false;

        for (Database db : databases) {
            if (db instanceof OracleDatabase) {
                foundOracle = true;
            } else if (db instanceof PostgresDatabase) {
                foundPostgres = true;
            } else if (db instanceof MSSQLDatabase) {
                foundMSSQL = true;
            }
        }

        assertTrue("Oracle not in Implemented Databases", foundOracle);
        assertTrue("MSSQL not in Implemented Databases", foundMSSQL);
        assertTrue("Postgres not in Implemented Databases", foundPostgres);
    }

    private class TestLiquibase extends Liquibase {
        private String url;
        private Database database;
        private InputStream inputStream;

        public TestLiquibase() {
            super("liquibase/test.xml", new ClassLoaderFileOpener(), ((Database) null));
            inputStream = createMock(InputStream.class);
            replay(inputStream);
        }

        public Database getDatabase() {
            if (database == null) {
                database = new OracleDatabase() {
                    public String getConnectionURL() {
                        return url;
                    }

                    public String getConnectionUsername() {
                        return "testUser";
                    }
                };
            }
            return database;
        }

        public void setDatabase(Database database) {
            this.database = database;
        }
{'fraction_non_alphanumeric': 0.08674361664917804, 'fraction_numerical': 0.002331817651859625, 'mean_word_length': 2.920475319926874, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '406712', 'n_tokens_mistral': 2304, 'n_tokens_neox': 2130, 'n_words': 473}