Skip to content

Commit

Permalink
Moving to @michelleblom's abstraction for db setup
Browse files Browse the repository at this point in the history
  • Loading branch information
umbernhard committed Jun 22, 2024
1 parent f787fb0 commit 781bd6a
Show file tree
Hide file tree
Showing 10 changed files with 865 additions and 319 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,56 +31,15 @@
import org.hibernate.Session;
import us.freeandfair.corla.query.CastVoteRecordQueries;
import us.freeandfair.corla.query.Setup;
import us.freeandfair.corla.util.TestClassWithDatabase;

@Test(groups = {"integration"})
public class BallotSelectionTest {
public class BallotSelectionTest extends TestClassWithDatabase {

private BallotSelectionTest() {};

private Boolean return_cvr = true;

/**
* Container for the mock-up database.
*/
static PostgreSQLContainer<?> postgres
= new PostgreSQLContainer<>("postgres:15-alpine")
// None of these actually have to be the same as the real database (except its name), but this
// makes it easy to match the setup scripts.
.withDatabaseName("corla")
.withUsername("corlaadmin")
.withPassword("corlasecret")
// .withInitScripts("corlaInit.sql","contest.sql");
.withInitScript("SQL/corlaInitEmpty.sql");

@BeforeClass
public static void beforeAll() {
postgres.start();
Properties hibernateProperties = new Properties();
hibernateProperties.setProperty("hibernate.driver", "org.postgresql.Driver");
hibernateProperties.setProperty("hibernate.url", postgres.getJdbcUrl());
hibernateProperties.setProperty("hibernate.user", postgres.getUsername());
hibernateProperties.setProperty("hibernate.pass", postgres.getPassword());
hibernateProperties.setProperty("hibernate.dialect", "org.hibernate.dialect.PostgreSQL9Dialect");
Persistence.setProperties(hibernateProperties);
Persistence.beginTransaction();

}

@AfterClass
public static void afterAll() {
postgres.stop();
}

@BeforeMethod
public static void beforeEach() {
Persistence.beginTransaction();
}

@AfterMethod
public static void afterEach() {
Persistence.rollbackTransaction();
}

@Test()
public void testAuditedPrefixLengthWithNone() {
List<Long> cvrIds = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,54 +10,14 @@
import us.freeandfair.corla.model.CountyDashboard;
import us.freeandfair.corla.persistence.Persistence;
import us.freeandfair.corla.query.Setup;
import us.freeandfair.corla.util.TestClassWithDatabase;

import java.util.Properties;

@Test(groups = {"integration"})
public class StartAuditRoundTest {
public class StartAuditRoundTest extends TestClassWithDatabase {

private StartAuditRoundTest() {};
/**
* Container for the mock-up database.
*/
static PostgreSQLContainer<?> postgres
= new PostgreSQLContainer<>("postgres:15-alpine")
// None of these actually have to be the same as the real database (except its name), but this
// makes it easy to match the setup scripts.
.withDatabaseName("corla")
.withUsername("corlaadmin")
.withPassword("corlasecret")
// .withInitScripts("corlaInit.sql","contest.sql");
.withInitScript("SQL/corlaInitEmpty.sql");

@BeforeClass
public static void beforeAll() {
postgres.start();
Properties hibernateProperties = new Properties();
hibernateProperties.setProperty("hibernate.driver", "org.postgresql.Driver");
hibernateProperties.setProperty("hibernate.url", postgres.getJdbcUrl());
hibernateProperties.setProperty("hibernate.user", postgres.getUsername());
hibernateProperties.setProperty("hibernate.pass", postgres.getPassword());
hibernateProperties.setProperty("hibernate.dialect", "org.hibernate.dialect.PostgreSQL9Dialect");
Persistence.setProperties(hibernateProperties);
Persistence.beginTransaction();

}

@AfterClass
public static void afterAll() {
postgres.stop();
}

@BeforeMethod
public static void beforeEach() {
Persistence.beginTransaction();
}

@AfterMethod
public static void afterEach() {
Persistence.rollbackTransaction();
}

// this test doesn't do much yet
@Test()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,49 +5,15 @@
import us.freeandfair.corla.model.Administrator;
import us.freeandfair.corla.model.County;
import us.freeandfair.corla.persistence.Persistence;
import us.freeandfair.corla.util.TestClassWithDatabase;

import java.util.Properties;

import static org.testng.AssertJUnit.assertEquals;
import static org.testng.AssertJUnit.assertNull;

@Test
public class AdministratorQueriesTest {

/**
* Container for the mock-up database.
*/
private static PostgreSQLContainer<?> postgres = new PostgreSQLContainer<>("postgres:15-alpine")
.withDatabaseName("corla")
.withUsername("corlaadmin")
.withPassword("corlasecret")
.withInitScript("SQL/corlaInitEmpty.sql");

@BeforeClass
public static void beforeAll() {
postgres.start();
Properties hibernateProperties = new Properties();
hibernateProperties.setProperty("hibernate.driver", "org.postgresql.Driver");
hibernateProperties.setProperty("hibernate.url", postgres.getJdbcUrl());
hibernateProperties.setProperty("hibernate.user", postgres.getUsername());
hibernateProperties.setProperty("hibernate.pass", postgres.getPassword());
hibernateProperties.setProperty("hibernate.dialect", "org.hibernate.dialect.PostgreSQL9Dialect");
Persistence.setProperties(hibernateProperties);
}
@BeforeMethod
public static void beforeEach() {
Persistence.beginTransaction();
}

@AfterMethod
public static void afterEach() {
Persistence.rollbackTransaction();
}

@AfterClass
public static void afterall() {
postgres.stop();
}
public class AdministratorQueriesTest extends TestClassWithDatabase {

@Test
public void testByUsernameState() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.testng.annotations.*;
import us.freeandfair.corla.model.*;
import us.freeandfair.corla.persistence.Persistence;
import us.freeandfair.corla.util.TestClassWithDatabase;

import javax.swing.text.html.Option;
import java.util.*;
Expand All @@ -14,42 +15,7 @@
import static org.testng.AssertJUnit.assertEquals;

@Test
public class BallotManifestInfoQueriesTest {

/**
* Container for the mock-up database.
*/
private static PostgreSQLContainer<?> postgres = new PostgreSQLContainer<>("postgres:15-alpine")
.withDatabaseName("corla")
.withUsername("corlaadmin")
.withPassword("corlasecret")
.withInitScript("SQL/corlaInitEmpty.sql");

@BeforeClass
public static void beforeAll() {
postgres.start();
Properties hibernateProperties = new Properties();
hibernateProperties.setProperty("hibernate.driver", "org.postgresql.Driver");
hibernateProperties.setProperty("hibernate.url", postgres.getJdbcUrl());
hibernateProperties.setProperty("hibernate.user", postgres.getUsername());
hibernateProperties.setProperty("hibernate.pass", postgres.getPassword());
hibernateProperties.setProperty("hibernate.dialect", "org.hibernate.dialect.PostgreSQL9Dialect");
Persistence.setProperties(hibernateProperties);
}
@BeforeMethod
public static void beforeEach() {
Persistence.beginTransaction();
}

@AfterMethod
public static void afterEach() {
Persistence.rollbackTransaction();
}

@AfterClass
public static void afterall() {
postgres.stop();
}
public class BallotManifestInfoQueriesTest extends TestClassWithDatabase {

public BallotManifestInfo setupBMI() {
return new BallotManifestInfo(1L,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,48 +23,10 @@
import us.freeandfair.corla.model.*;
import us.freeandfair.corla.persistence.Persistence;
import us.freeandfair.corla.query.Setup;
import us.freeandfair.corla.util.TestClassWithDatabase;

@Test(groups = {"integration"})
public class CastVoteRecordQueriesTest {

/**
* Container for the mock-up database.
*/
private static PostgreSQLContainer<?> postgres = new PostgreSQLContainer<>("postgres:15-alpine")
.withDatabaseName("corla")
.withUsername("corlaadmin")
.withPassword("corlasecret")
.withInitScript("SQL/corlaInitEmpty.sql");

@BeforeClass
public static void beforeAll() {
postgres.start();
Properties hibernateProperties = new Properties();
hibernateProperties.setProperty("hibernate.driver", "org.postgresql.Driver");
hibernateProperties.setProperty("hibernate.url", postgres.getJdbcUrl());
hibernateProperties.setProperty("hibernate.user", postgres.getUsername());
hibernateProperties.setProperty("hibernate.pass", postgres.getPassword());
hibernateProperties.setProperty("hibernate.dialect", "org.hibernate.dialect.PostgreSQL9Dialect");
Persistence.setProperties(hibernateProperties);
}
@BeforeMethod
public static void beforeEach() {
Persistence.beginTransaction();
}

@AfterMethod
public static void afterEach() {
try {
Persistence.rollbackTransaction();
} catch (IllegalStateException e) {
// Sometimes our tests intentionally kill the DB.
}
}

@AfterClass
public static void afterall() {
postgres.stop();
}
public class CastVoteRecordQueriesTest extends TestClassWithDatabase {

public List<CVRContestInfo> noisyContestSetup(){
return noisyContestSetup(1L);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import us.freeandfair.corla.model.*;
import us.freeandfair.corla.model.Choice;
import us.freeandfair.corla.persistence.Persistence;
import us.freeandfair.corla.util.TestClassWithDatabase;

import java.awt.*;
import java.util.*;
Expand All @@ -16,42 +17,7 @@
import static org.testng.Assert.*;

@Test(groups = {"integration"})
public class ContestQueriesTest {

/**
* Container for the mock-up database.
*/
private static PostgreSQLContainer<?> postgres = new PostgreSQLContainer<>("postgres:15-alpine")
.withDatabaseName("corla")
.withUsername("corlaadmin")
.withPassword("corlasecret")
.withInitScript("SQL/corlaInitEmpty.sql");

@BeforeClass
public static void beforeAll() {
postgres.start();
Properties hibernateProperties = new Properties();
hibernateProperties.setProperty("hibernate.driver", "org.postgresql.Driver");
hibernateProperties.setProperty("hibernate.url", postgres.getJdbcUrl());
hibernateProperties.setProperty("hibernate.user", postgres.getUsername());
hibernateProperties.setProperty("hibernate.pass", postgres.getPassword());
hibernateProperties.setProperty("hibernate.dialect", "org.hibernate.dialect.PostgreSQL9Dialect");
Persistence.setProperties(hibernateProperties);
}
@BeforeMethod
public static void beforeEach() {
Persistence.beginTransaction();
}

@AfterMethod
public static void afterEach() {
Persistence.rollbackTransaction();
}

@AfterClass
public static void afterall() {
postgres.stop();
}
public class ContestQueriesTest extends TestClassWithDatabase {

public County countySetup() {
return countySetup(1L);
Expand Down Expand Up @@ -158,7 +124,7 @@ public void testForCountyNull() {

}

@Test
@Test()
public void testDBError() {
// Close the database
Persistence.commitTransaction();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,49 +14,10 @@
import us.freeandfair.corla.model.ContestResult;
import us.freeandfair.corla.model.Contest;
import us.freeandfair.corla.model.County;
import us.freeandfair.corla.util.TestClassWithDatabase;

@Test(groups = {"integration"})
public class ContestResultQueriesTest {

/**
* Container for the mock-up database.
*/
static PostgreSQLContainer<?> postgres
= new PostgreSQLContainer<>("postgres:15-alpine")
// None of these actually have to be the same as the real database (except its name), but this
// makes it easy to match the setup scripts.
.withDatabaseName("corla")
.withUsername("corlaadmin")
.withPassword("corlasecret")
// .withInitScripts("corlaInit.sql","contest.sql");
.withInitScript("SQL/corlaInitEmpty.sql");

@BeforeClass
public static void beforeAll() {
postgres.start();
Properties hibernateProperties = new Properties();
hibernateProperties.setProperty("hibernate.driver", "org.postgresql.Driver");
hibernateProperties.setProperty("hibernate.url", postgres.getJdbcUrl());
hibernateProperties.setProperty("hibernate.user", postgres.getUsername());
hibernateProperties.setProperty("hibernate.pass", postgres.getPassword());
hibernateProperties.setProperty("hibernate.dialect", "org.hibernate.dialect.PostgreSQL9Dialect");
Persistence.setProperties(hibernateProperties);

}

@AfterClass
public static void afterAll() {
postgres.stop();
}

@BeforeMethod
public static void beforeEach() {
Persistence.beginTransaction();
}

@AfterMethod
public static void afterEach() { Persistence.rollbackTransaction(); }

public class ContestResultQueriesTest extends TestClassWithDatabase {

@Test()
public void findOrCreateTest() {
Expand Down
Loading

0 comments on commit 781bd6a

Please sign in to comment.