Skip to content

Commit

Permalink
Consistent config via test.properties.
Browse files Browse the repository at this point in the history
  • Loading branch information
vteague committed Dec 24, 2024
1 parent d5c0b68 commit 712f875
Show file tree
Hide file tree
Showing 13 changed files with 48 additions and 572 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 @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,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;

Expand Down Expand Up @@ -64,21 +62,9 @@ public class RankedBallotInterpretationReportTests extends TestClassWithDatabase
private static final Logger LOGGER
= LogManager.getLogger(RankedBallotInterpretationReportTests.class);

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

@BeforeClass
public static void beforeAll() {

final 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
Loading

0 comments on commit 712f875

Please sign in to comment.