<commit_before>package sg.ncl;

import org.flywaydb.core.Flyway;
import org.junit.Before;
import org.junit.Test;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.SimpleDriverDataSource;

import javax.sql.DataSource;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import static org.assertj.core.api.Assertions.assertThat;

/**
 * Created by dcszwang on 10/13/2016.
 */

public class FlywayTest {

    private static final String ADDRESSES = "addresses";
    private static final String CREDENTIALS = "credentials";
    private static final String CREDENTIALS_ROLES = "credentials_roles";
    private static final String DATA = "data";
    private static final String DATA_ACCESS_REQUESTS = "data_access_requests";
    private static final String DATA_CATEGORIES = "data_categories";
    private static final String DATA_DOWNLOADS = "data_downloads";
    private static final String DATA_KEYWORDS = "data_keywords";
    private static final String DATA_LICENSES = "data_licenses";
    private static final String DATA_PUBLIC_DOWNLOADS = "data_public_downloads";
    private static final String DATA_PUBLIC_USERS = "data_public_users";
    private static final String DATA_RESOURCES = "data_resources";
    private static final String DATA_USERS = "data_users";
    private static final String DETERLAB_PROJECT = "deterlab_project";
    private static final String DETERLAB_USER = "deterlab_user";
    private static final String EMAIL_RETRIES = "email_retries";
    private static final String EXPERIMENTS = "experiments";
    private static final String IMAGES = "images";
    private static final String LOGIN_ACTIVITIES = "login_activities";
    private static final String PASSWORD_RESET_REQUESTS = "password_reset_requests";
    private static final String PROJECT_DETAILS = "project_details";
    private static final String PROJECT_USAGE = "project_usage";
    private static final String REALIZATIONS = "realizations";
    private static final String REGISTRATIONS = "registrations";
    private static final String TEAM_MEMBERS = "team_members";
    private static final String TEAM_QUOTAS = "team_quotas";
    private static final String TEAMS = "teams";
    private static final String USER_DETAILS = "user_details";
    private static final String USERS = "users";
    private static final String USERS_TEAMS = "users_teams";
    private static final String SCHEMA = "prod";

    private DataSource dataSource;
    private JdbcTemplate template;
    private Flyway flyway;
    private List<String> tables;

    @Before
    public void setup() throws SQLException {
        this.dataSource = createDataSource();
        this.template = new JdbcTemplate(dataSource);
        this.flyway = new Flyway();
        this.flyway.setDataSource(dataSource);
        this.flyway.migrate();

        this.tables = new ArrayList<>();
        this.tables.add(ADDRESSES);
        this.tables.add(CREDENTIALS);
        this.tables.add(CREDENTIALS_ROLES);
        this.tables.add(DATA);
        this.tables.add(DATA_ACCESS_REQUESTS);
        this.tables.add(DATA_CATEGORIES);
        this.tables.add(DATA_DOWNLOADS);
        this.tables.add(DATA_KEYWORDS);
        this.tables.add(DATA_LICENSES);
        this.tables.add(DATA_PUBLIC_DOWNLOADS);
        this.tables.add(DATA_PUBLIC_USERS);
        this.tables.add(DATA_RESOURCES);
        this.tables.add(DATA_USERS);
        this.tables.add(DETERLAB_PROJECT);
        this.tables.add(DETERLAB_USER);
        this.tables.add(EMAIL_RETRIES);
        this.tables.add(EXPERIMENTS);
        this.tables.add(IMAGES);
        this.tables.add(LOGIN_ACTIVITIES);
        this.tables.add(PASSWORD_RESET_REQUESTS);
        this.tables.add(PROJECT_DETAILS);
        this.tables.add(PROJECT_USAGE);
        this.tables.add(REALIZATIONS);
        this.tables.add(REGISTRATIONS);
        this.tables.add(TEAM_MEMBERS);
        this.tables.add(TEAM_QUOTAS);
        this.tables.add(TEAMS);
        this.tables.add(USER_DETAILS);
        this.tables.add(USERS);
        this.tables.add(USERS_TEAMS);
    }

    @Test
    public void testNumOfTables() throws Exception {
        // make sure that we have the exact number of tables
        List<Map<String, Object>> tableNames = this.template.queryForList("SHOW TABLES FROM " + SCHEMA);
        assertThat(tableNames.size()).isEqualTo(this.tables.size());
    }

    @Test
    public void testTableNames() throws Exception {
        // make sure all tables name matches
        List<Map<String, Object>> tableNames = this.template.queryForList("SHOW TABLES FROM " + SCHEMA);
        for (int i = 0; i < this.tables.size(); i++) {
            assertThat((String) tableNames.get(i).get("TABLE_NAME")).isEqualTo(tables.get(i));
            assertThat((String) tableNames.get(i).get("TABLE_SCHEMA")).isEqualTo(SCHEMA);
        }
    }

    @Test
    public void testAddressesTable() throws Exception {
        // make sure 'addresses' table has expected number of columns
        List<Map<String, Object>> addressesTable = this.template.queryForList("SHOW COLUMNS FROM " + SCHEMA + "." + ADDRESSES);
        assertThat(addressesTable.size()).isEqualTo(10);

        // make sure 'addresses' table has expected column name and type
        assertThat((String) addressesTable.get(0).get("FIELD")).isEqualTo("id");
        assertThat((String) addressesTable.get(0).get("TYPE")).contains("bigint");
        assertThat((String) addressesTable.get(0).get("NULL")).isEqualTo("NO");
        assertThat((String) addressesTable.get(0).get("KEY")).isEqualTo("PRI");<commit_msg>Added table Node Usage reservation to resolve the Flywaytest issue<commit_after>package sg.ncl;

import org.flywaydb.core.Flyway;
import org.junit.Before;
import org.junit.Test;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.SimpleDriverDataSource;

import javax.sql.DataSource;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import static org.assertj.core.api.Assertions.assertThat;

/**
 * Created by dcszwang on 10/13/2016.
 */

public class FlywayTest {

    private static final String ADDRESSES = "addresses";
    private static final String CREDENTIALS = "credentials";
    private static final String CREDENTIALS_ROLES = "credentials_roles";
    private static final String DATA = "data";
    private static final String DATA_ACCESS_REQUESTS = "data_access_requests";
    private static final String DATA_CATEGORIES = "data_categories";
    private static final String DATA_DOWNLOADS = "data_downloads";
    private static final String DATA_KEYWORDS = "data_keywords";
    private static final String DATA_LICENSES = "data_licenses";
    private static final String DATA_PUBLIC_DOWNLOADS = "data_public_downloads";
    private static final String DATA_PUBLIC_USERS = "data_public_users";
    private static final String DATA_RESOURCES = "data_resources";
    private static final String DATA_USERS = "data_users";
    private static final String DETERLAB_PROJECT = "deterlab_project";
    private static final String DETERLAB_USER = "deterlab_user";
    private static final String EMAIL_RETRIES = "email_retries";
    private static final String EXPERIMENTS = "experiments";
    private static final String IMAGES = "images";
    private static final String LOGIN_ACTIVITIES = "login_activities";
    private static final String PASSWORD_RESET_REQUESTS = "password_reset_requests";
    private static final String PROJECT_DETAILS = "project_details";
    private static final String PROJECT_USAGE = "project_usage";
    private static final String REALIZATIONS = "realizations";
    private static final String REGISTRATIONS = "registrations";
    private static final String TEAM_MEMBERS = "team_members";
    private static final String TEAM_QUOTAS = "team_quotas";
    private static final String TEAMS = "teams";
    private static final String USER_DETAILS = "user_details";
    private static final String USERS = "users";
    private static final String USERS_TEAMS = "users_teams";
    private static final String NODES_USAGE_RESERVATION = "nodes_usage_reservation";
    private static final String SCHEMA = "prod";

    private DataSource dataSource;
    private JdbcTemplate template;
    private Flyway flyway;
    private List<String> tables;

    @Before
    public void setup() throws SQLException {
        this.dataSource = createDataSource();
        this.template = new JdbcTemplate(dataSource);
        this.flyway = new Flyway();
        this.flyway.setDataSource(dataSource);
        this.flyway.migrate();

        this.tables = new ArrayList<>();
        this.tables.add(ADDRESSES);
        this.tables.add(CREDENTIALS);
        this.tables.add(CREDENTIALS_ROLES);
        this.tables.add(DATA);
        this.tables.add(DATA_ACCESS_REQUESTS);
        this.tables.add(DATA_CATEGORIES);
        this.tables.add(DATA_DOWNLOADS);
        this.tables.add(DATA_KEYWORDS);
        this.tables.add(DATA_LICENSES);
        this.tables.add(DATA_PUBLIC_DOWNLOADS);
        this.tables.add(DATA_PUBLIC_USERS);
        this.tables.add(DATA_RESOURCES);
        this.tables.add(DATA_USERS);
        this.tables.add(DETERLAB_PROJECT);
        this.tables.add(DETERLAB_USER);
        this.tables.add(EMAIL_RETRIES);
        this.tables.add(EXPERIMENTS);
        this.tables.add(IMAGES);
        this.tables.add(LOGIN_ACTIVITIES);
        this.tables.add(NODES_USAGE_RESERVATION);
        this.tables.add(PASSWORD_RESET_REQUESTS);
        this.tables.add(PROJECT_DETAILS);
        this.tables.add(PROJECT_USAGE);
        this.tables.add(REALIZATIONS);
        this.tables.add(REGISTRATIONS);
        this.tables.add(TEAM_MEMBERS);
        this.tables.add(TEAM_QUOTAS);
        this.tables.add(TEAMS);
        this.tables.add(USER_DETAILS);
        this.tables.add(USERS);
        this.tables.add(USERS_TEAMS);

    }

    @Test
    public void testNumOfTables() throws Exception {
        // make sure that we have the exact number of tables
        List<Map<String, Object>> tableNames = this.template.queryForList("SHOW TABLES FROM " + SCHEMA);
        assertThat(tableNames.size()).isEqualTo(this.tables.size());
    }

    @Test
    public void testTableNames() throws Exception {
        // make sure all tables name matches
        List<Map<String, Object>> tableNames = this.template.queryForList("SHOW TABLES FROM " + SCHEMA);
        for (int i = 0; i < this.tables.size(); i++) {
            assertThat((String) tableNames.get(i).get("TABLE_NAME")).isEqualTo(tables.get(i));
            assertThat((String) tableNames.get(i).get("TABLE_SCHEMA")).isEqualTo(SCHEMA);
        }
    }

    @Test
    public void testAddressesTable() throws Exception {
        // make sure 'addresses' table has expected number of columns
        List<Map<String, Object>> addressesTable = this.template.queryForList("SHOW COLUMNS FROM " + SCHEMA + "." + ADDRESSES);
        assertThat(addressesTable.size()).isEqualTo(10);

        // make sure 'addresses' table has expected column name and type
        assertThat((String) addressesTable.get(0).get("FIELD")).isEqualTo("id");
        assertThat((String) addressesTable.get(0).get("TYPE")).contains("bigint");
        assertThat((String) addressesTable.get(0).get("NULL")).isEqualTo("NO");
        assertThat((String) addressesTable.get(0).get("KEY")).isEqualTo("PRI");
{'fraction_non_alphanumeric': 0.10349638155026593, 'fraction_numerical': 0.0026157467957101752, 'mean_word_length': 3.641845406717928, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4922108', 'n_tokens_mistral': 3450, 'n_tokens_neox': 3388, 'n_words': 767}