Skip to content

Commit

Permalink
Merge pull request #232 from DemocracyDevelopers/227-adopt-refactorin…
Browse files Browse the repository at this point in the history
…g-of-testclasswithdatabases-from-model-tests

227 adopt refactoring of testclasswithdatabases from model tests
  • Loading branch information
vteague authored Jan 9, 2025
2 parents 5c54f39 + 94dcb4b commit 76cf74f
Show file tree
Hide file tree
Showing 28 changed files with 110 additions and 709 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@
import au.org.democracydevelopers.corla.util.testUtils;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.testcontainers.containers.PostgreSQLContainer;
import org.testcontainers.ext.ScriptUtils;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import us.freeandfair.corla.controller.ComparisonAuditController;
Expand All @@ -55,11 +52,6 @@ public class ComparisonAuditControllerTests extends TestClassWithDatabase {
*/
private static final Logger LOGGER = LogManager.getLogger(ComparisonAuditControllerTests.class);

/**
* Container for the mock-up database.
*/
static PostgreSQLContainer<?> postgres = createTestContainer();

/**
* IRV contest name.
*/
Expand All @@ -76,20 +68,11 @@ public class ComparisonAuditControllerTests extends TestClassWithDatabase {
private static final String tinyMixed = "PluralityExample2";

@BeforeClass
public static void beforeAll() {
public static void beforeAllThisClass() {

var containerDelegate = setupContainerStartPostgres(postgres);

ScriptUtils.runInitScript(containerDelegate,
"SQL/co-counties.sql");
ScriptUtils.runInitScript(containerDelegate,
"SQL/corla-three-candidates-ten-votes-inconsistent-types.sql");

}
runSQLSetupScript("SQL/co-counties.sql");
runSQLSetupScript("SQL/corla-three-candidates-ten-votes-inconsistent-types.sql");

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

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@

import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.testcontainers.containers.PostgreSQLContainer;
import org.testcontainers.ext.ScriptUtils;
import org.testcontainers.shaded.org.apache.commons.lang3.StringUtils;
import us.freeandfair.corla.csv.DominionCVRExportParser;
import us.freeandfair.corla.model.*;
Expand Down Expand Up @@ -78,11 +76,6 @@ public class DominionCVRExportParserTests extends TestClassWithDatabase {
*/
private static final Logger LOGGER = LogManager.getLogger(DominionCVRExportParserTests.class);

/**
* Container for the mock-up database.
*/
static PostgreSQLContainer<?> postgres = createTestContainer();

/**
* Error message to match.
*/
Expand Down Expand Up @@ -116,15 +109,8 @@ public class DominionCVRExportParserTests extends TestClassWithDatabase {
CAB, CAB, CAB);

@BeforeClass
public static void beforeAll() {

var containerDelegate = setupContainerStartPostgres(postgres);
ScriptUtils.runInitScript(containerDelegate, "SQL/co-counties.sql");
}

@AfterClass
public static void afterAll() {
postgres.stop();
public static void beforeAllThisClass() {
runSQLSetupScript("SQL/co-counties.sql");
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import au.org.democracydevelopers.corla.model.vote.IRVBallotInterpretation;
import au.org.democracydevelopers.corla.util.*;
import org.mockito.*;
import org.testcontainers.containers.PostgreSQLContainer;
import org.testcontainers.ext.ScriptUtils;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import spark.HaltException;
Expand Down Expand Up @@ -43,11 +41,6 @@ public class ACVRUploadTests extends TestClassWithAuth {

private final static Logger LOGGER = LogManager.getLogger(ACVRUploadTests.class);

/**
* Container for the mock-up database.
*/
private final static PostgreSQLContainer<?> postgres = createTestContainer();

/**
* An Audit CVR Upload endpoint to test.
*/
Expand Down Expand Up @@ -375,13 +368,10 @@ public class ACVRUploadTests extends TestClassWithAuth {
* Database init.
*/
@BeforeClass
public static void beforeAll() {

final var containerDelegate = setupContainerStartPostgres(postgres);

ScriptUtils.runInitScript(containerDelegate, "SQL/co-counties.sql");
ScriptUtils.runInitScript(containerDelegate, "SQL/corla-three-candidates-ten-votes-inconsistent-types.sql");
ScriptUtils.runInitScript(containerDelegate, "SQL/adams-partway-through-audit.sql");
public static void beforeAllThisClass() {
runSQLSetupScript("SQL/co-counties.sql");
runSQLSetupScript("SQL/corla-three-candidates-ten-votes-inconsistent-types.sql");
runSQLSetupScript("SQL/adams-partway-through-audit.sql");
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
import org.mockito.MockedStatic;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.testcontainers.containers.PostgreSQLContainer;
import org.testcontainers.ext.ScriptUtils;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import spark.HaltException;
Expand Down Expand Up @@ -39,11 +37,6 @@ public class EstimateSampleSizesTests extends TestClassWithAuth {

private final static Logger LOGGER = LogManager.getLogger(EstimateSampleSizesTests.class);

/**
* Container for the mock-up database.
*/
private final static PostgreSQLContainer<?> postgres = createTestContainer();

/**
* The estimate sample sizes endpoint.
*/
Expand All @@ -68,12 +61,10 @@ public class EstimateSampleSizesTests extends TestClassWithAuth {
* Database init.
*/
@BeforeClass
public static void beforeAll() {

final var containerDelegate = setupContainerStartPostgres(postgres);
public static void beforeAllThisClass() {

ScriptUtils.runInitScript(containerDelegate, "SQL/co-counties.sql");
ScriptUtils.runInitScript(containerDelegate, "SQL/simple-assertions.sql");
runSQLSetupScript("SQL/co-counties.sql");
runSQLSetupScript("SQL/simple-assertions.sql");

var s = Persistence.openSession();
s.beginTransaction();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@
import org.mockito.MockedStatic;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.testcontainers.containers.PostgreSQLContainer;
import org.testcontainers.ext.ScriptUtils;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
Expand Down Expand Up @@ -73,11 +71,6 @@ public class GenerateAssertionsAPITests extends TestClassWithAuth {
*/
private static final Logger LOGGER = LogManager.getLogger(GenerateAssertionsAPITests.class);

/**
* Container for the mock-up database.
*/
private final static PostgreSQLContainer<?> postgres = createTestContainer();

/**
* The Generate Assertions endpoint.
*/
Expand Down Expand Up @@ -127,15 +120,13 @@ public class GenerateAssertionsAPITests extends TestClassWithAuth {
* Database init.
*/
@BeforeClass
public static void beforeAll() {

final var containerDelegate = setupContainerStartPostgres(postgres);
public static void beforeAllThisClass() {

var s = Persistence.openSession();
s.beginTransaction();

// Used to initialize the database, particularly to set the ASM state to the DOS_INITIAL_STATE.
ScriptUtils.runInitScript(containerDelegate, "SQL/co-counties.sql");
runSQLSetupScript("SQL/co-counties.sql");
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public class GenerateAssertionsTests extends TestClassWithDatabase {
* Database init.
*/
@BeforeClass
public static void beforeAll() {
public static void beforeAllThisClass() {
Persistence.setProperties(config);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@
import org.mockito.MockedStatic;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.testcontainers.containers.PostgreSQLContainer;
import org.testcontainers.ext.ScriptUtils;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
Expand Down Expand Up @@ -72,11 +70,6 @@ public class GetAssertionsTests extends TestClassWithDatabase {

private static final Logger LOGGER = LogManager.getLogger(GetAssertionsTests.class);

/**
* Container for the mock-up database.
*/
private final static PostgreSQLContainer<?> postgres = createTestContainer();

/**
* Endpoint for getting assertions.
*/
Expand All @@ -103,12 +96,10 @@ public class GetAssertionsTests extends TestClassWithDatabase {
* Database init.
*/
@BeforeClass
public static void beforeAll() throws IOException {

var containerDelegate = setupContainerStartPostgres(postgres);
public static void beforeAllThisClass() {

// Load in the counties data, actually just for basic setup such as DoSDashboard.
ScriptUtils.runInitScript(containerDelegate, "SQL/co-counties.sql");
runSQLSetupScript("SQL/co-counties.sql");
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@
import java.util.OptionalInt;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.testcontainers.containers.PostgreSQLContainer;
import org.testcontainers.ext.ScriptUtils;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
import us.freeandfair.corla.model.CVRContestInfo;
Expand All @@ -58,11 +55,6 @@
*/
public class AssertionTests extends TestClassWithDatabase {

/**
* Container for the mock-up database.
*/
protected static PostgreSQLContainer<?> postgres = createTestContainer();

/**
* Establish a mocked CVRContestInfo for use in testing Assertion scoring.
*/
Expand Down Expand Up @@ -177,24 +169,11 @@ public class AssertionTests extends TestClassWithDatabase {
* Start the test container and establish persistence properties before the first test.
*/
@BeforeClass
public static void beforeAll() {

var containerDelegate = setupContainerStartPostgres(postgres);
ScriptUtils.runInitScript(containerDelegate, "SQL/co-counties.sql");
ScriptUtils.runInitScript(containerDelegate, "SQL/simple-assertions.sql");
}

/**
* After all test have run, stop the test container.
*/
@AfterClass
public static void afterAll() {
postgres.stop();
public static void beforeAllThisClass() {
runSQLSetupScript("SQL/co-counties.sql");
runSQLSetupScript("SQL/simple-assertions.sql");
}

/**
* Initialise mocked objects prior to the first test.
*/
@BeforeClass
public void initMocks() {
MockitoAnnotations.openMocks(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@
import java.util.List;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.testcontainers.containers.PostgreSQLContainer;
import org.testcontainers.ext.ScriptUtils;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

Expand All @@ -47,28 +44,13 @@ public class AssertionQueriesTests extends TestClassWithDatabase {

private static final Logger LOGGER = LogManager.getLogger(AssertionQueriesTests.class);

/**
* Container for the mock-up database.
*/
protected static PostgreSQLContainer<?> postgres = createTestContainer();

/**
* Start the test container and establish persistence properties before the first test.
*/
@BeforeClass
public static void beforeAll() {

var containerDelegate = setupContainerStartPostgres(postgres);
ScriptUtils.runInitScript(containerDelegate, "SQL/co-counties.sql");
ScriptUtils.runInitScript(containerDelegate, "SQL/simple-assertions.sql");
}

/**
* After all test have run, stop the test container.
*/
@AfterClass
public static void afterAll() {
postgres.stop();
public static void beforeAllThisClass() {
runSQLSetupScript("SQL/co-counties.sql");
runSQLSetupScript("SQL/simple-assertions.sql");
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@
import au.org.democracydevelopers.corla.util.testUtils;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.testcontainers.containers.PostgreSQLContainer;
import org.testcontainers.ext.ScriptUtils;
import org.testng.annotations.Test;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;

import java.util.Optional;
Expand All @@ -32,30 +29,14 @@ public class GenerateAssertionsSummaryQueriesTests extends TestClassWithDatabase

private static final Logger LOGGER = LogManager.getLogger(GenerateAssertionsSummaryQueriesTests.class);

/**
* Container for the mock-up database.
*/
private static final PostgreSQLContainer<?> postgres = createTestContainer();

/**
* Start the test container and establish persistence properties before the first test.
*/
@BeforeClass
public static void beforeAll() {

var containerDelegate = setupContainerStartPostgres(postgres);

ScriptUtils.runInitScript(containerDelegate, "SQL/co-counties.sql");
ScriptUtils.runInitScript(containerDelegate, "SQL/simple-assertions.sql");
ScriptUtils.runInitScript(containerDelegate, "SQL/summaries-generation-errors.sql");
}

/**
* After all test have run, stop the test container.
*/
@AfterClass
public static void afterAll() {
postgres.stop();
public static void beforeAllThisClass() {
runSQLSetupScript("SQL/co-counties.sql");
runSQLSetupScript("SQL/simple-assertions.sql");
runSQLSetupScript("SQL/summaries-generation-errors.sql");
}

/**
Expand Down
Loading

0 comments on commit 76cf74f

Please sign in to comment.