Skip to content

Commit

Permalink
Extra clean ups for tests
Browse files Browse the repository at this point in the history
* Move postgres container name to one place
* correct typo on CodesService response
* better testing asserts (assertFalse is backwards to thinkabout often)
  • Loading branch information
BryceStevenWilley committed Oct 6, 2023
1 parent 2db9d6d commit 2e5231d
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public Response getCodesUnderCaseType(
Optional<CaseType> maybeType = cd.getCaseTypeWith(courtId, caseTypeId);
if (maybeType.isEmpty()) {
return Response.status(404)
.entity("\"Case type " + caseTypeId + " does not exist is court " + courtId + "\"")
.entity("\"Case type " + caseTypeId + " does not exist in court " + courtId + "\"")
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,18 @@
import edu.suffolk.litlab.efspserver.tyler.codes.PartyType;

public class DatabaseVersionTest {

public static final String POSTGRES_DOCKER_NAME = "postgres:14";

private final static Logger log =
LoggerFactory.getLogger(DatabaseVersionTest.class);

@Container
public PostgreSQLContainer<?> userDb =
new PostgreSQLContainer<>(DockerImageName.parse("postgres:14"));
new PostgreSQLContainer<>(DockerImageName.parse(POSTGRES_DOCKER_NAME));

@Container
public PostgreSQLContainer<?> codeDb = new PostgreSQLContainer<>(DockerImageName.parse("postgres:14"));
public PostgreSQLContainer<?> codeDb = new PostgreSQLContainer<>(POSTGRES_DOCKER_NAME);

private static final String v0AtRestInsert = """
INSERT INTO at_rest_keys (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class LoginDatabaseTest {

@Container
public PostgreSQLContainer<?> postgres =
new PostgreSQLContainer<>(DockerImageName.parse("postgres:13.2"));
new PostgreSQLContainer<>(DockerImageName.parse(DatabaseVersionTest.POSTGRES_DOCKER_NAME));

@BeforeEach
public void setUp() throws SQLException, NoSuchAlgorithmException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class UserDatabaseTest {

@Container
public PostgreSQLContainer<?> postgres =
new PostgreSQLContainer<>(DockerImageName.parse("postgres:13.2"));
new PostgreSQLContainer<>(DockerImageName.parse(DatabaseVersionTest.POSTGRES_DOCKER_NAME));

/** Start's the Container and creates the UserDatabase.
* More info on the TestContainer Library at: https://www.testcontainers.org/,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import com.fasterxml.jackson.jakarta.rs.json.JacksonJsonProvider;

import edu.suffolk.litlab.efspserver.db.DatabaseCreator;
import edu.suffolk.litlab.efspserver.db.DatabaseVersionTest;
import edu.suffolk.litlab.efspserver.tyler.codes.CodeDatabase;
import edu.suffolk.litlab.efspserver.tyler.codes.EcfCodesService;

Expand All @@ -41,7 +42,7 @@ public class CodesServiceTest {

@Container
public PostgreSQLContainer<?> postgres =
new PostgreSQLContainer<>(DockerImageName.parse("postgres:13.2"));
new PostgreSQLContainer<>(DockerImageName.parse(DatabaseVersionTest.POSTGRES_DOCKER_NAME));

private static final String ENDPOINT_ADDRESS = "http://localhost:9090";
private Server server;
Expand Down Expand Up @@ -136,7 +137,7 @@ public void testGetSubCourt() throws JsonMappingException, JsonProcessingExcepti
public void testGetCase() throws JsonMappingException, JsonProcessingException {
ObjectMapper mapper = new ObjectMapper();
JsonNode node = mapper.readTree(getServerResponseAt("/courts/adams/case_types/25361"));
assertTrue(node.has("getCaseSubtypes"), "didn't have case sub types: " + node);
assertTrue(node.has("getCaseSubtypes"), "didn't have case sub types. Response was: " + node);
assertEquals(
ServiceHelpers.EXTERNAL_URL + "/jurisdictions/illinois/codes/courts/adams/case_types/25361/case_subtypes",
node.get("getCaseSubtypes").get("url").asText());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.testcontainers.utility.DockerImageName;

import edu.suffolk.litlab.efspserver.db.DatabaseCreator;
import edu.suffolk.litlab.efspserver.db.DatabaseVersionTest;
import edu.suffolk.litlab.efspserver.ecfcodes.CodeUpdater;

public class CodeDatabaseTest {
Expand All @@ -31,7 +32,7 @@ public class CodeDatabaseTest {

@Container
public PostgreSQLContainer<?> postgres =
new PostgreSQLContainer<>(DockerImageName.parse("postgres:13.2"));
new PostgreSQLContainer<>(DockerImageName.parse(DatabaseVersionTest.POSTGRES_DOCKER_NAME));

@BeforeEach
public void setUp() throws SQLException {
Expand Down Expand Up @@ -83,20 +84,20 @@ public void testFromNothing() throws Exception {
loadFromXmls();

List<CaseCategory> cats = cd.getCaseCategoriesFor("adams");
assertFalse(cats.isEmpty());
assertTrue(cats.size() > 0);
List<CaseType> types = cd.getCaseTypesFor("adams", "183527", Optional.empty());
assertFalse(types.isEmpty());
assertTrue(types.size() > 0, "No case types available for category 183527");
cd.getCaseSubtypesFor("adams", types.get(0).code);
List<OptionalServiceCode> optServs = cd.getOptionalServices("adams", "183612");
assertFalse(optServs.isEmpty());
assertTrue(optServs.size() > 0);
List<ServiceCodeType> services = cd.getServiceTypes("adams");
assertFalse(services.isEmpty());
assertTrue(services.size() > 0);

Optional<CourtLocationInfo> info = cd.getFullLocationInfo("adams");
List<String> allCourts = cd.getAllLocations();
assertFalse(allCourts.isEmpty());
assertTrue(allCourts.size() > 0);
List<String> fileable = cd.getFileableLocations();
assertFalse(fileable.isEmpty());
assertTrue(fileable.size() > 0);
assertTrue(info.isPresent());
}

Expand Down

0 comments on commit 2e5231d

Please sign in to comment.