<commit_before>/*
 * Copyright (c) 2005-2009 Grameen Foundation USA
 * All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
 * implied. See the License for the specific language governing
 * permissions and limitations under the License.
 *
 * See also http://www.apache.org/licenses/LICENSE-2.0.html for an
 * explanation of the license and how it is applied.
 */

package org.mifos.framework.persistence;

import static org.mifos.framework.persistence.DatabaseVersionPersistence.APPLICATION_VERSION;
import static org.mifos.framework.persistence.DatabaseVersionPersistence.LATEST_CHECKPOINT_VERSION;
import static org.mifos.framework.util.helpers.DatabaseSetup.executeScript;

import java.io.InputStream;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import junit.framework.Assert;

import org.dbunit.Assertion;
import org.dbunit.database.DatabaseConnection;
import org.dbunit.database.IDatabaseConnection;
import org.dbunit.dataset.IDataSet;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.mifos.application.accounts.financial.util.helpers.FinancialInitializer;
import org.mifos.framework.components.logger.MifosLogManager;
import org.mifos.framework.exceptions.SystemException;
import org.mifos.framework.hibernate.helper.StaticHibernateUtil;

/*
 * This class runs tests on database upgrade scripts (both SQL
 * based and java based).  It uses a version of the database referred to as
 * a "checkpoint" as a starting point.  The database checkpoint version that
 * it starts with can be adjusted by updating sql/latest-schema-checkupoint.sql
 * and sql/latest-data-checkupoint.sql with a pair of the corresponding 
 * latest-schema.sql and latest-data.sql files for a given database version.
 * The static variable DatabaseVersionPersistence.LATEST_CHECKPOINT_VERSION 
 * must then be set to the database version number of the latest-xxx.sql files 
 * that have been used to update the latest-xxx-checkpoint.sql files.  
 * This test will run upgrade scripts using LATEST_CHECKPOINT_VERSION
 * as a starting point.  In general LATEST_CHECKPOINT_VERSION should be a 
 * database version that is at least 3-5 upgrades ago in order to allow for 
 * fixes to be made to recent upgrades when necessary.
 */

public class LatestTestAfterCheckpointIntegrationTest {

    private static Connection connection;

    @BeforeClass
    public static void beforeClass() throws Exception {
        MifosLogManager.configureLogging();
        StaticHibernateUtil.initialize();
        connection = StaticHibernateUtil.getSessionTL().connection();
        connection.setAutoCommit(false);
    }

    @Before
    public void setUp() throws Exception {
        dropLatestDatabase();
    }

    @AfterClass
    public static void afterClass() throws Exception {
        // Cleaning the database
        executeScript("mifosdroptables.sql", connection);
        executeScript("latest-schema.sql", connection);<commit_msg>Allow LatestTestAfterCheckpointIntegrationTest to be run by itself in Eclipse, and ensure that this test always uses the integration database.<commit_after>/*
 * Copyright (c) 2005-2009 Grameen Foundation USA
 * All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
 * implied. See the License for the specific language governing
 * permissions and limitations under the License.
 *
 * See also http://www.apache.org/licenses/LICENSE-2.0.html for an
 * explanation of the license and how it is applied.
 */

package org.mifos.framework.persistence;

import static org.mifos.framework.persistence.DatabaseVersionPersistence.APPLICATION_VERSION;
import static org.mifos.framework.persistence.DatabaseVersionPersistence.LATEST_CHECKPOINT_VERSION;
import static org.mifos.framework.util.helpers.DatabaseSetup.executeScript;

import java.io.InputStream;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import junit.framework.Assert;

import org.dbunit.Assertion;
import org.dbunit.database.DatabaseConnection;
import org.dbunit.database.IDatabaseConnection;
import org.dbunit.dataset.IDataSet;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.Test;
import org.mifos.application.accounts.financial.util.helpers.FinancialInitializer;
import org.mifos.framework.MifosIntegrationTestCase;
import org.mifos.framework.exceptions.ApplicationException;
import org.mifos.framework.exceptions.SystemException;
import org.mifos.framework.hibernate.helper.StaticHibernateUtil;

/*
 * This class runs tests on database upgrade scripts (both SQL
 * based and java based).  It uses a version of the database referred to as
 * a "checkpoint" as a starting point.  The database checkpoint version that
 * it starts with can be adjusted by updating sql/latest-schema-checkupoint.sql
 * and sql/latest-data-checkupoint.sql with a pair of the corresponding 
 * latest-schema.sql and latest-data.sql files for a given database version.
 * The static variable DatabaseVersionPersistence.LATEST_CHECKPOINT_VERSION 
 * must then be set to the database version number of the latest-xxx.sql files 
 * that have been used to update the latest-xxx-checkpoint.sql files.  
 * This test will run upgrade scripts using LATEST_CHECKPOINT_VERSION
 * as a starting point.  In general LATEST_CHECKPOINT_VERSION should be a 
 * database version that is at least 3-5 upgrades ago in order to allow for 
 * fixes to be made to recent upgrades when necessary.
 */

public class LatestTestAfterCheckpointIntegrationTest extends MifosIntegrationTestCase {

    public LatestTestAfterCheckpointIntegrationTest() throws SystemException, ApplicationException {
        super();
    }

    private static Connection connection;

    @Override
    @Before
    public void setUp() throws Exception {
        super.setUp();
        if (null == connection) {
            connection = StaticHibernateUtil.getSessionTL().connection();
        }
        dropLatestDatabase();
    }

    @AfterClass
    public static void afterClass() throws Exception {
        // Cleaning the database
        executeScript("mifosdroptables.sql", connection);
        executeScript("latest-schema.sql", connection);
{'fraction_non_alphanumeric': 0.07328072153325817, 'fraction_numerical': 0.004509582863585118, 'mean_word_length': 4.328078078078078, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, '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': '7397243', 'n_tokens_mistral': 1904, 'n_tokens_neox': 1853, 'n_words': 654}