Skip to content

Commit

Permalink
Add integration tests for LegacySearchController
Browse files Browse the repository at this point in the history
Introduce comprehensive integration tests to validate the LegacySearchController. Additionally, corrected the logic for handling `parentName`.
  • Loading branch information
Gcolon021 committed Nov 14, 2024
1 parent 7b49dd7 commit d703012
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ public Result mapContinuousMetadata(ResultSet rs) throws SQLException {
rs.getString("dsFullName"), parentName, parentDisplay, rs.getString("conceptPath"), min, max
);
return new Result(
metadata, jsonBlobParser.parseValues(rs.getString("values")), rs.getString("dataset"),
parentName == null || parentName.isBlank() ? "All Variables" : parentName, rs.getString("name"), false, true
metadata, jsonBlobParser.parseValues(rs.getString("values")), rs.getString("dataset"), parentName, rs.getString("name"), false,
true
);
}

Expand All @@ -53,7 +53,7 @@ private static String getParentDisplay(ResultSet rs) throws SQLException {
}

private static String getParentName(ResultSet rs) throws SQLException {
return rs.getString("parentName") == null || rs.getString("parentName").isBlank() ? "" : rs.getString("parentName");
return rs.getString("parentName") == null || rs.getString("parentName").isBlank() ? "All Variables" : rs.getString("parentName");
}

private static String getDescription(ResultSet rs) throws SQLException {
Expand All @@ -75,8 +75,8 @@ public Result mapCategoricalMetadata(ResultSet rs) throws SQLException {
);

return new Result(
metadata, jsonBlobParser.parseValues(rs.getString("values")), rs.getString("dataset"),
parentName == null || parentName.isBlank() ? "All Variables" : parentName, rs.getString("name"), true, false
metadata, jsonBlobParser.parseValues(rs.getString("values")), rs.getString("dataset"), parentName, rs.getString("name"), true,
false
);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package edu.harvard.dbmi.avillach.dictionary.legacysearch;

import edu.harvard.dbmi.avillach.dictionary.legacysearch.model.LegacyResponse;
import edu.harvard.dbmi.avillach.dictionary.legacysearch.model.Results;
import edu.harvard.dbmi.avillach.dictionary.legacysearch.model.SearchResult;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.test.context.DynamicPropertyRegistry;
import org.springframework.test.context.DynamicPropertySource;
import org.testcontainers.containers.PostgreSQLContainer;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;
import org.testcontainers.utility.MountableFile;

import java.io.IOException;
import java.util.List;

@SpringBootTest
@Testcontainers
class LegacySearchControllerIntegrationTest {

@Autowired
LegacySearchController legacySearchController;

@Container
static final PostgreSQLContainer<?> databaseContainer = new PostgreSQLContainer<>("postgres:16").withReuse(true)
.withCopyFileToContainer(MountableFile.forClasspathResource("seed.sql"), "/docker-entrypoint-initdb.d/seed.sql");

@DynamicPropertySource
static void mySQLProperties(DynamicPropertyRegistry registry) {
registry.add("spring.datasource.url", databaseContainer::getJdbcUrl);
registry.add("spring.datasource.username", databaseContainer::getUsername);
registry.add("spring.datasource.password", databaseContainer::getPassword);
registry.add("spring.datasource.db", databaseContainer::getDatabaseName);
}

@Test
void shouldGetLegacyResponseByStudyID() throws IOException {
String jsonString = """
{"query":{"searchTerm":"phs000007","includedTags":[],"excludedTags":[],"returnTags":"true","offset":0,"limit":100}}
""";

ResponseEntity<LegacyResponse> legacyResponseResponseEntity = legacySearchController.legacySearch(jsonString);
System.out.println(legacyResponseResponseEntity);
Assertions.assertEquals(HttpStatus.OK, legacyResponseResponseEntity.getStatusCode());
LegacyResponse legacyResponseBody = legacyResponseResponseEntity.getBody();
Assertions.assertNotNull(legacyResponseBody);
Results results = legacyResponseBody.results();
List<SearchResult> searchResults = results.searchResults();
searchResults.forEach(searchResult -> Assertions.assertEquals("phs000007", searchResult.result().studyId()));
}

}

0 comments on commit d703012

Please sign in to comment.