From 19c5312d89d50c46d5121e9801050e094ad3c2bc Mon Sep 17 00:00:00 2001 From: Anne Marsan Date: Tue, 5 Nov 2024 16:16:33 -0500 Subject: [PATCH 1/7] Proposed fix --- .../ohdsi/webapi/cdmresults/service/CDMCacheService.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/ohdsi/webapi/cdmresults/service/CDMCacheService.java b/src/main/java/org/ohdsi/webapi/cdmresults/service/CDMCacheService.java index a4ec88b38e..e3870609d4 100644 --- a/src/main/java/org/ohdsi/webapi/cdmresults/service/CDMCacheService.java +++ b/src/main/java/org/ohdsi/webapi/cdmresults/service/CDMCacheService.java @@ -145,9 +145,9 @@ private void cacheRecordsById(Source source, List ids) { PreparedStatementRenderer psr = getPartialPreparedStatementRenderer(source, idsSlice); Set cachedIds = loadCache(source, psr, mapper, jdbcTemplate); // in this batch, need to save any concepts that were not found when loading cache - idsSlice.removeAll(cachedIds); - if (!idsSlice.isEmpty()) { // store zeros in cache - List zeroConcepts = idsSlice.stream().map(id -> { + List notFoundIds = new ArrayList(CollectionUtils.subtract(idsSlice, cachedIds)); + if (!notFoundIds.isEmpty()) { // store zeros in cache + List zeroConcepts = notFoundIds.stream().map(id -> { CDMCacheEntity ce = new CDMCacheEntity(); ce.setConceptId(id); ce.setRecordCount(0L); From a52afe2474fa9bcaae0ec1ebdc359e9af4ae59c9 Mon Sep 17 00:00:00 2001 From: Anne Marsan Date: Tue, 5 Nov 2024 16:16:41 -0500 Subject: [PATCH 2/7] Attempt at a unit test --- .../service/CDMCacheServiceTest.java | 118 ++++++++++++++++++ 1 file changed, 118 insertions(+) create mode 100644 src/test/java/org/ohdsi/webapi/cdmresults/service/CDMCacheServiceTest.java diff --git a/src/test/java/org/ohdsi/webapi/cdmresults/service/CDMCacheServiceTest.java b/src/test/java/org/ohdsi/webapi/cdmresults/service/CDMCacheServiceTest.java new file mode 100644 index 0000000000..9d3d1e9f4f --- /dev/null +++ b/src/test/java/org/ohdsi/webapi/cdmresults/service/CDMCacheServiceTest.java @@ -0,0 +1,118 @@ +package org.ohdsi.webapi.cdmresults.service; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.mockito.Mockito.when; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.mockito.runners.MockitoJUnitRunner; +import org.ohdsi.webapi.cdmresults.domain.CDMCacheEntity; +import org.ohdsi.webapi.cdmresults.repository.CDMCacheRepository; +import org.springframework.core.convert.ConversionService; + +import com.odysseusinc.arachne.commons.types.DBMSType; +import com.odysseusinc.arachne.execution_engine_common.api.v1.dto.KerberosAuthMechanism; + +import org.ohdsi.webapi.source.Source; +import org.ohdsi.webapi.source.SourceDaimon; +import org.ohdsi.webapi.source.SourceHelper; + +@RunWith(MockitoJUnitRunner.class) +public class CDMCacheServiceTest { + + private static final String PGSQL_CONN_STR = "jdbc:postgresql://localhost:5432/ohdsi?ssl=true&user=user&password=secret"; + + @Mock + private CDMCacheRepository cdmCacheRepositoryMock; + + @Mock + private CDMCacheBatchService batchServiceMock; + + @Mock + private ConversionService conversionServiceMock; + + @Mock + private SourceHelper sourceHelper = new SourceHelper(); + + @InjectMocks + private CDMCacheService service; + + @Before + public void setUp() { + MockitoAnnotations.initMocks(this); + assertNotNull(service); + } + + @Test + public void findAndCache_nothingCached_fetchesItemsAndReturnsThem() { + + // Arrange + List ids = Arrays.asList(1, 2, 3, 4); + Source source = getCdmSource(); + + when(cdmCacheRepositoryMock.findBySourceAndConceptIds(0, ids)).thenReturn(new ArrayList()); + when(sourceHelper.getSourceConnectionString(source)).thenReturn(PGSQL_CONN_STR); + + // Act + List result = service.findAndCache(source, ids); + + // Assert + assertEquals(4, result.size()); + + // cdmCacheMock.when() + // when(function.apply(any())).thenReturn( + // ids.stream().map(CDMResultsCacheTest.this::createDescendantRecordCount).collect(Collectors.toList())); + + // Collection records = cache.findAndCache(ids, + // function); + // assertEquals(4, records.size()); + // assertEquals(ids, + // records.stream().map(DescendantRecordCount::getId).collect(Collectors.toList())); + } + + protected final String SOURCE_KEY = "Embedded_PG"; + protected static final String CDM_SCHEMA_NAME = "cdm"; + protected static final String RESULT_SCHEMA_NAME = "results"; + + private Source getCdmSource() { + Source source = new Source(); + source.setSourceName("Embedded PG"); + source.setSourceKey(SOURCE_KEY); + source.setSourceDialect(DBMSType.POSTGRESQL.getOhdsiDB()); + source.setSourceConnection(PGSQL_CONN_STR); + source.setUsername("postgres"); + source.setPassword("postgres"); + source.setKrbAuthMethod(KerberosAuthMechanism.PASSWORD); + + SourceDaimon cdmDaimon = new SourceDaimon(); + cdmDaimon.setPriority(1); + cdmDaimon.setDaimonType(SourceDaimon.DaimonType.CDM); + cdmDaimon.setTableQualifier(CDM_SCHEMA_NAME); + cdmDaimon.setSource(source); + + SourceDaimon vocabDaimon = new SourceDaimon(); + vocabDaimon.setPriority(1); + vocabDaimon.setDaimonType(SourceDaimon.DaimonType.Vocabulary); + vocabDaimon.setTableQualifier(CDM_SCHEMA_NAME); + vocabDaimon.setSource(source); + + SourceDaimon resultsDaimon = new SourceDaimon(); + resultsDaimon.setPriority(1); + resultsDaimon.setDaimonType(SourceDaimon.DaimonType.Results); + resultsDaimon.setTableQualifier(RESULT_SCHEMA_NAME); + resultsDaimon.setSource(source); + + source.setDaimons(Arrays.asList(cdmDaimon, vocabDaimon, resultsDaimon)); + + return source; + } + +} From 4228211f345b78e8c17dfcabca6fa7d80b8a63a5 Mon Sep 17 00:00:00 2001 From: Anne Marsan Date: Thu, 7 Nov 2024 16:16:13 -0500 Subject: [PATCH 3/7] Change required to get the project to build from the test runner. --- pom.xml | 6 +++++ .../AbstractForEachValidatorBuilder.java | 25 ++++++++++++++++--- .../check/builder/ValidatorGroupBuilder.java | 22 +++++++++++++--- 3 files changed, 45 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index f44b0e08a0..f82a63ccb3 100644 --- a/pom.xml +++ b/pom.xml @@ -769,6 +769,12 @@ json-smart 2.4.9 + + net.minidev + asm + 1.0.2 + test + org.apache.commons commons-lang3 diff --git a/src/main/java/org/ohdsi/webapi/check/builder/AbstractForEachValidatorBuilder.java b/src/main/java/org/ohdsi/webapi/check/builder/AbstractForEachValidatorBuilder.java index ea93a7c0c2..47854ea21a 100644 --- a/src/main/java/org/ohdsi/webapi/check/builder/AbstractForEachValidatorBuilder.java +++ b/src/main/java/org/ohdsi/webapi/check/builder/AbstractForEachValidatorBuilder.java @@ -41,15 +41,14 @@ public final AbstractForEachValidatorBuilder groups(ValidatorGroupBuilder< } protected List> initGroups() { - return initAndBuildList(this.validatorGroupBuilders); + return initAndBuildGroup(this.validatorGroupBuilders); } protected List> initValidators() { return initAndBuildList(this.validatorBuilders); } - private List initAndBuildList(List> builders) { - + private List> initAndBuildGroup(List> builders) { builders.forEach(builder -> { if (Objects.isNull(builder.getBasePath())) { builder.basePath(createChildPath()); @@ -67,7 +66,25 @@ private List initAndBuildList(List List initAndBuildList(List> builders) { + builders.forEach(builder -> { + if (Objects.isNull(builder.getBasePath())) { + builder.basePath(createChildPath()); + } + if (Objects.isNull(builder.getErrorMessage())) { + builder.errorMessage(this.errorMessage); + } + if (Objects.isNull(builder.getSeverity())) { + builder.severity(this.severity); + } + if (Objects.isNull(builder.getAttrName())) { + builder.attrName(this.attrName); + } + }); + return builders.stream() + .map(ValidatorBaseBuilder::build) + .collect(Collectors.toList()); } } diff --git a/src/main/java/org/ohdsi/webapi/check/builder/ValidatorGroupBuilder.java b/src/main/java/org/ohdsi/webapi/check/builder/ValidatorGroupBuilder.java index cc00145080..c7adb4dcd5 100644 --- a/src/main/java/org/ohdsi/webapi/check/builder/ValidatorGroupBuilder.java +++ b/src/main/java/org/ohdsi/webapi/check/builder/ValidatorGroupBuilder.java @@ -63,14 +63,13 @@ protected Path createChildPath() { public ValidatorGroup build() { - List> groups = initAndBuildList(this.validatorGroupBuilders); + List> groups = initAndBuildGroup(this.validatorGroupBuilders); List> validators = initAndBuildList(this.validatorBuilders); return new ValidatorGroup<>(validators, groups, valueGetter, conditionGetter); } - private List initAndBuildList(List> builders) { - + private List> initAndBuildGroup(List> builders) { builders.forEach(builder -> { if (Objects.nonNull(this.errorMessage)) { builder.errorMessage(this.errorMessage); @@ -85,8 +84,23 @@ private List initAndBuildList(List List initAndBuildList(List> builders) { + builders.forEach(builder -> { + if (Objects.nonNull(this.errorMessage)) { + builder.errorMessage(this.errorMessage); + } + if (Objects.isNull(builder.getBasePath())) { + builder.basePath(createChildPath()); + } + if (Objects.isNull(builder.severity)) { + builder.severity(this.severity); + } + }); + return builders.stream() + .map(ValidatorBaseBuilder::build) + .collect(Collectors.toList()); } } From fa6fecc4a44ae1b52bd3d15714f07b5b06f02b3c Mon Sep 17 00:00:00 2001 From: Anne Marsan Date: Thu, 7 Nov 2024 16:16:29 -0500 Subject: [PATCH 4/7] Add integration test --- .../results/achilles_result_concept_count.sql | 8 ++ .../service/CDMCacheServiceTest.java | 118 ------------------ .../ohdsi/webapi/test/CDMCacheServiceIT.java | 82 ++++++++++++ .../java/org/ohdsi/webapi/test/WebApiIT.java | 3 +- .../resources/application-test.properties | 4 + src/test/resources/database/cdm_results.sql | 2 + 6 files changed, 98 insertions(+), 119 deletions(-) create mode 100644 src/main/resources/ddl/results/achilles_result_concept_count.sql delete mode 100644 src/test/java/org/ohdsi/webapi/cdmresults/service/CDMCacheServiceTest.java create mode 100644 src/test/java/org/ohdsi/webapi/test/CDMCacheServiceIT.java create mode 100644 src/test/resources/database/cdm_results.sql diff --git a/src/main/resources/ddl/results/achilles_result_concept_count.sql b/src/main/resources/ddl/results/achilles_result_concept_count.sql new file mode 100644 index 0000000000..b11087a543 --- /dev/null +++ b/src/main/resources/ddl/results/achilles_result_concept_count.sql @@ -0,0 +1,8 @@ +IF OBJECT_ID('@results_schema.achilles_result_concept_count', 'U') IS NULL +CREATE TABLE @results_schema.achilles_result_concept_count ( + concept_id int, + record_count bigint, + descendant_record_count bigint, + person_count bigint, + descendant_person_count bigint +); \ No newline at end of file diff --git a/src/test/java/org/ohdsi/webapi/cdmresults/service/CDMCacheServiceTest.java b/src/test/java/org/ohdsi/webapi/cdmresults/service/CDMCacheServiceTest.java deleted file mode 100644 index 9d3d1e9f4f..0000000000 --- a/src/test/java/org/ohdsi/webapi/cdmresults/service/CDMCacheServiceTest.java +++ /dev/null @@ -1,118 +0,0 @@ -package org.ohdsi.webapi.cdmresults.service; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.mockito.Mockito.when; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; -import org.mockito.runners.MockitoJUnitRunner; -import org.ohdsi.webapi.cdmresults.domain.CDMCacheEntity; -import org.ohdsi.webapi.cdmresults.repository.CDMCacheRepository; -import org.springframework.core.convert.ConversionService; - -import com.odysseusinc.arachne.commons.types.DBMSType; -import com.odysseusinc.arachne.execution_engine_common.api.v1.dto.KerberosAuthMechanism; - -import org.ohdsi.webapi.source.Source; -import org.ohdsi.webapi.source.SourceDaimon; -import org.ohdsi.webapi.source.SourceHelper; - -@RunWith(MockitoJUnitRunner.class) -public class CDMCacheServiceTest { - - private static final String PGSQL_CONN_STR = "jdbc:postgresql://localhost:5432/ohdsi?ssl=true&user=user&password=secret"; - - @Mock - private CDMCacheRepository cdmCacheRepositoryMock; - - @Mock - private CDMCacheBatchService batchServiceMock; - - @Mock - private ConversionService conversionServiceMock; - - @Mock - private SourceHelper sourceHelper = new SourceHelper(); - - @InjectMocks - private CDMCacheService service; - - @Before - public void setUp() { - MockitoAnnotations.initMocks(this); - assertNotNull(service); - } - - @Test - public void findAndCache_nothingCached_fetchesItemsAndReturnsThem() { - - // Arrange - List ids = Arrays.asList(1, 2, 3, 4); - Source source = getCdmSource(); - - when(cdmCacheRepositoryMock.findBySourceAndConceptIds(0, ids)).thenReturn(new ArrayList()); - when(sourceHelper.getSourceConnectionString(source)).thenReturn(PGSQL_CONN_STR); - - // Act - List result = service.findAndCache(source, ids); - - // Assert - assertEquals(4, result.size()); - - // cdmCacheMock.when() - // when(function.apply(any())).thenReturn( - // ids.stream().map(CDMResultsCacheTest.this::createDescendantRecordCount).collect(Collectors.toList())); - - // Collection records = cache.findAndCache(ids, - // function); - // assertEquals(4, records.size()); - // assertEquals(ids, - // records.stream().map(DescendantRecordCount::getId).collect(Collectors.toList())); - } - - protected final String SOURCE_KEY = "Embedded_PG"; - protected static final String CDM_SCHEMA_NAME = "cdm"; - protected static final String RESULT_SCHEMA_NAME = "results"; - - private Source getCdmSource() { - Source source = new Source(); - source.setSourceName("Embedded PG"); - source.setSourceKey(SOURCE_KEY); - source.setSourceDialect(DBMSType.POSTGRESQL.getOhdsiDB()); - source.setSourceConnection(PGSQL_CONN_STR); - source.setUsername("postgres"); - source.setPassword("postgres"); - source.setKrbAuthMethod(KerberosAuthMechanism.PASSWORD); - - SourceDaimon cdmDaimon = new SourceDaimon(); - cdmDaimon.setPriority(1); - cdmDaimon.setDaimonType(SourceDaimon.DaimonType.CDM); - cdmDaimon.setTableQualifier(CDM_SCHEMA_NAME); - cdmDaimon.setSource(source); - - SourceDaimon vocabDaimon = new SourceDaimon(); - vocabDaimon.setPriority(1); - vocabDaimon.setDaimonType(SourceDaimon.DaimonType.Vocabulary); - vocabDaimon.setTableQualifier(CDM_SCHEMA_NAME); - vocabDaimon.setSource(source); - - SourceDaimon resultsDaimon = new SourceDaimon(); - resultsDaimon.setPriority(1); - resultsDaimon.setDaimonType(SourceDaimon.DaimonType.Results); - resultsDaimon.setTableQualifier(RESULT_SCHEMA_NAME); - resultsDaimon.setSource(source); - - source.setDaimons(Arrays.asList(cdmDaimon, vocabDaimon, resultsDaimon)); - - return source; - } - -} diff --git a/src/test/java/org/ohdsi/webapi/test/CDMCacheServiceIT.java b/src/test/java/org/ohdsi/webapi/test/CDMCacheServiceIT.java new file mode 100644 index 0000000000..e015d65f45 --- /dev/null +++ b/src/test/java/org/ohdsi/webapi/test/CDMCacheServiceIT.java @@ -0,0 +1,82 @@ +package org.ohdsi.webapi.test; + +import com.odysseusinc.arachne.commons.types.DBMSType; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +import org.junit.Before; +import org.junit.Test; +import org.ohdsi.circe.helper.ResourceHelper; +import org.ohdsi.sql.SqlRender; +import org.ohdsi.sql.SqlTranslate; +import org.ohdsi.webapi.source.SourceRepository; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.http.ResponseEntity; + +public class CDMCacheServiceIT extends WebApiIT { + private static final String CDM_RESULTS_FILE_PATH = "/database/cdm_results.sql"; + + @Value("${cdmService.endpoint.results}") + private String cdmResultsEndpoint; + + @Autowired + private SourceRepository sourceRepository; + + @Before + public void init() throws Exception { + truncateTable(String.format("%s.%s", "public", "source")); + resetSequence(String.format("%s.%s", "public", "source_sequence")); + sourceRepository.saveAndFlush(getCdmSource()); + prepareCdmSchema(); + prepareResultSchema(); + addCDMResults(); + } + + private void addCDMResults() { + String resultSql = SqlRender.renderSql(ResourceHelper.GetResourceAsString( + CDM_RESULTS_FILE_PATH), + new String[] { "results_schema" }, new String[] { RESULT_SCHEMA_NAME }); + String sql = SqlTranslate.translateSql(resultSql, DBMSType.POSTGRESQL.getOhdsiDB()); + jdbcTemplate.execute(sql); + } + + @Test + public void searchVocabulary_firstTime_returnsResults() { + + // Arrange + Map queryParameters = new HashMap(); + queryParameters.put("sourceName", SOURCE_KEY); + List conceptIds = Arrays.asList(1); + + List>> list = new ArrayList<>(); + @SuppressWarnings("unchecked") + Class>>> returnClass = (Class>>>)list.getClass(); + + // Act + final ResponseEntity>>> entity = getRestTemplate().postForEntity(this.cdmResultsEndpoint, conceptIds, + returnClass, queryParameters ); + + // Assertion + assertOK(entity); + List>> results = entity.getBody(); + assertEquals(1, results.size()); + LinkedHashMap> resultHashMap = results.get(0); + assertEquals(1, resultHashMap.size()); + assertTrue(resultHashMap.containsKey("1")); + List counts = resultHashMap.get("1"); + assertEquals(100, counts.get(0).intValue()); + assertEquals(101, counts.get(1).intValue()); + assertEquals(102, counts.get(2).intValue()); + assertEquals(103, counts.get(3).intValue()); + } + +} diff --git a/src/test/java/org/ohdsi/webapi/test/WebApiIT.java b/src/test/java/org/ohdsi/webapi/test/WebApiIT.java index dd7dd57c0d..ed2af1e0c5 100644 --- a/src/test/java/org/ohdsi/webapi/test/WebApiIT.java +++ b/src/test/java/org/ohdsi/webapi/test/WebApiIT.java @@ -64,7 +64,8 @@ public abstract class WebApiIT { "/ddl/results/pathway_analysis_codes.sql", "/ddl/results/pathway_analysis_events.sql", "/ddl/results/pathway_analysis_paths.sql", - "/ddl/results/pathway_analysis_stats.sql" + "/ddl/results/pathway_analysis_stats.sql", + "/ddl/results/achilles_result_concept_count.sql" ); diff --git a/src/test/resources/application-test.properties b/src/test/resources/application-test.properties index f11c6df1b7..4f6a1da5d3 100644 --- a/src/test/resources/application-test.properties +++ b/src/test/resources/application-test.properties @@ -1,6 +1,7 @@ baseUri=http://localhost:${local.server.port}${server.context-path} security.db.datasource.url=http://localhost:${datasource.url}/arachne_portal_enterprise vocabularyservice.endpoint=${baseUri}/vocabulary +cdmService.endpoint=${baseUri}/cdmresults #GET vocabularies vocabularyservice.endpoint.vocabularies=${vocabularyservice.endpoint}/vocabularies #GET domains @@ -10,6 +11,9 @@ vocabularyservice.endpoint.concept=${vocabularyservice.endpoint}/concept/1 #GET cohortdefinitions cohortdefinitionservice.endpoint.cohortdefinitions=${baseUri}/cohortdefinition +#POST cdmResults +cdmService.endpoint.results=${cdmService.endpoint}/{sourceName}/conceptRecordCount + #Example application service exampleservice.endpoint=${baseUri}/example diff --git a/src/test/resources/database/cdm_results.sql b/src/test/resources/database/cdm_results.sql new file mode 100644 index 0000000000..ce261c3c5a --- /dev/null +++ b/src/test/resources/database/cdm_results.sql @@ -0,0 +1,2 @@ +insert into @results_schema.achilles_result_concept_count (concept_id, record_count, descendant_record_count, person_count, descendant_person_count) +values (1,100,101,102,103); \ No newline at end of file From a765c8255e3c944dabb8db31cd2b9c4a1462ab3e Mon Sep 17 00:00:00 2001 From: Anne Marsan Date: Thu, 7 Nov 2024 16:23:44 -0500 Subject: [PATCH 5/7] Rename test class --- .../webapi/test/CDMResultsServiceIT.java | 81 +++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 src/test/java/org/ohdsi/webapi/test/CDMResultsServiceIT.java diff --git a/src/test/java/org/ohdsi/webapi/test/CDMResultsServiceIT.java b/src/test/java/org/ohdsi/webapi/test/CDMResultsServiceIT.java new file mode 100644 index 0000000000..6a631c62f8 --- /dev/null +++ b/src/test/java/org/ohdsi/webapi/test/CDMResultsServiceIT.java @@ -0,0 +1,81 @@ +package org.ohdsi.webapi.test; + +import com.odysseusinc.arachne.commons.types.DBMSType; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +import org.junit.Before; +import org.junit.Test; +import org.ohdsi.circe.helper.ResourceHelper; +import org.ohdsi.sql.SqlRender; +import org.ohdsi.sql.SqlTranslate; +import org.ohdsi.webapi.source.SourceRepository; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.http.ResponseEntity; + +public class CDMResultsServiceIT extends WebApiIT { + private static final String CDM_RESULTS_FILE_PATH = "/database/cdm_results.sql"; + + @Value("${cdmService.endpoint.results}") + private String cdmResultsEndpoint; + + @Autowired + private SourceRepository sourceRepository; + + @Before + public void init() throws Exception { + truncateTable(String.format("%s.%s", "public", "source")); + resetSequence(String.format("%s.%s", "public", "source_sequence")); + sourceRepository.saveAndFlush(getCdmSource()); + prepareCdmSchema(); + prepareResultSchema(); + addCDMResults(); + } + + private void addCDMResults() { + String resultSql = SqlRender.renderSql(ResourceHelper.GetResourceAsString( + CDM_RESULTS_FILE_PATH), + new String[] { "results_schema" }, new String[] { RESULT_SCHEMA_NAME }); + String sql = SqlTranslate.translateSql(resultSql, DBMSType.POSTGRESQL.getOhdsiDB()); + jdbcTemplate.execute(sql); + } + + @Test + public void requestCDMResultsForConcept_firstTime_returnsResults() { + + // Arrange + List conceptIds = Arrays.asList(1); + Map queryParameters = new HashMap(); + queryParameters.put("sourceName", SOURCE_KEY); + + List>> list = new ArrayList<>(); + @SuppressWarnings("unchecked") + Class>>> returnClass = (Class>>>)list.getClass(); + + // Act + final ResponseEntity>>> entity = getRestTemplate().postForEntity(this.cdmResultsEndpoint, conceptIds, + returnClass, queryParameters ); + + // Assertion + assertOK(entity); + List>> results = entity.getBody(); + assertEquals(1, results.size()); + LinkedHashMap> resultHashMap = results.get(0); + assertEquals(1, resultHashMap.size()); + assertTrue(resultHashMap.containsKey("1")); + List counts = resultHashMap.get("1"); + assertEquals(100, counts.get(0).intValue()); + assertEquals(101, counts.get(1).intValue()); + assertEquals(102, counts.get(2).intValue()); + assertEquals(103, counts.get(3).intValue()); + } +} From 2fbbccca1ce327f443e655e77fd3bf73df450132 Mon Sep 17 00:00:00 2001 From: Anne Marsan Date: Thu, 7 Nov 2024 16:25:20 -0500 Subject: [PATCH 6/7] Rename --- .../ohdsi/webapi/test/CDMCacheServiceIT.java | 82 ------------------- 1 file changed, 82 deletions(-) delete mode 100644 src/test/java/org/ohdsi/webapi/test/CDMCacheServiceIT.java diff --git a/src/test/java/org/ohdsi/webapi/test/CDMCacheServiceIT.java b/src/test/java/org/ohdsi/webapi/test/CDMCacheServiceIT.java deleted file mode 100644 index e015d65f45..0000000000 --- a/src/test/java/org/ohdsi/webapi/test/CDMCacheServiceIT.java +++ /dev/null @@ -1,82 +0,0 @@ -package org.ohdsi.webapi.test; - -import com.odysseusinc.arachne.commons.types.DBMSType; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; - -import org.junit.Before; -import org.junit.Test; -import org.ohdsi.circe.helper.ResourceHelper; -import org.ohdsi.sql.SqlRender; -import org.ohdsi.sql.SqlTranslate; -import org.ohdsi.webapi.source.SourceRepository; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.http.ResponseEntity; - -public class CDMCacheServiceIT extends WebApiIT { - private static final String CDM_RESULTS_FILE_PATH = "/database/cdm_results.sql"; - - @Value("${cdmService.endpoint.results}") - private String cdmResultsEndpoint; - - @Autowired - private SourceRepository sourceRepository; - - @Before - public void init() throws Exception { - truncateTable(String.format("%s.%s", "public", "source")); - resetSequence(String.format("%s.%s", "public", "source_sequence")); - sourceRepository.saveAndFlush(getCdmSource()); - prepareCdmSchema(); - prepareResultSchema(); - addCDMResults(); - } - - private void addCDMResults() { - String resultSql = SqlRender.renderSql(ResourceHelper.GetResourceAsString( - CDM_RESULTS_FILE_PATH), - new String[] { "results_schema" }, new String[] { RESULT_SCHEMA_NAME }); - String sql = SqlTranslate.translateSql(resultSql, DBMSType.POSTGRESQL.getOhdsiDB()); - jdbcTemplate.execute(sql); - } - - @Test - public void searchVocabulary_firstTime_returnsResults() { - - // Arrange - Map queryParameters = new HashMap(); - queryParameters.put("sourceName", SOURCE_KEY); - List conceptIds = Arrays.asList(1); - - List>> list = new ArrayList<>(); - @SuppressWarnings("unchecked") - Class>>> returnClass = (Class>>>)list.getClass(); - - // Act - final ResponseEntity>>> entity = getRestTemplate().postForEntity(this.cdmResultsEndpoint, conceptIds, - returnClass, queryParameters ); - - // Assertion - assertOK(entity); - List>> results = entity.getBody(); - assertEquals(1, results.size()); - LinkedHashMap> resultHashMap = results.get(0); - assertEquals(1, resultHashMap.size()); - assertTrue(resultHashMap.containsKey("1")); - List counts = resultHashMap.get("1"); - assertEquals(100, counts.get(0).intValue()); - assertEquals(101, counts.get(1).intValue()); - assertEquals(102, counts.get(2).intValue()); - assertEquals(103, counts.get(3).intValue()); - } - -} From ef20dc5ba8b90da9376bb6f52daf20fb96f1194b Mon Sep 17 00:00:00 2001 From: Anne Marsan Date: Thu, 7 Nov 2024 16:34:06 -0500 Subject: [PATCH 7/7] Fix some names --- .../java/org/ohdsi/webapi/test/CDMResultsServiceIT.java | 8 ++++---- src/test/resources/application-test.properties | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/test/java/org/ohdsi/webapi/test/CDMResultsServiceIT.java b/src/test/java/org/ohdsi/webapi/test/CDMResultsServiceIT.java index 6a631c62f8..72635bad7a 100644 --- a/src/test/java/org/ohdsi/webapi/test/CDMResultsServiceIT.java +++ b/src/test/java/org/ohdsi/webapi/test/CDMResultsServiceIT.java @@ -25,8 +25,8 @@ public class CDMResultsServiceIT extends WebApiIT { private static final String CDM_RESULTS_FILE_PATH = "/database/cdm_results.sql"; - @Value("${cdmService.endpoint.results}") - private String cdmResultsEndpoint; + @Value("${cdmResultsService.endpoint.conceptRecordCount}") + private String conceptRecordCountEndpoint; @Autowired private SourceRepository sourceRepository; @@ -50,7 +50,7 @@ private void addCDMResults() { } @Test - public void requestCDMResultsForConcept_firstTime_returnsResults() { + public void requestConceptRecordCounts_firstTime_returnsResults() { // Arrange List conceptIds = Arrays.asList(1); @@ -62,7 +62,7 @@ public void requestCDMResultsForConcept_firstTime_returnsResults() { Class>>> returnClass = (Class>>>)list.getClass(); // Act - final ResponseEntity>>> entity = getRestTemplate().postForEntity(this.cdmResultsEndpoint, conceptIds, + final ResponseEntity>>> entity = getRestTemplate().postForEntity(this.conceptRecordCountEndpoint, conceptIds, returnClass, queryParameters ); // Assertion diff --git a/src/test/resources/application-test.properties b/src/test/resources/application-test.properties index 4f6a1da5d3..3d9a789b5b 100644 --- a/src/test/resources/application-test.properties +++ b/src/test/resources/application-test.properties @@ -1,7 +1,7 @@ baseUri=http://localhost:${local.server.port}${server.context-path} security.db.datasource.url=http://localhost:${datasource.url}/arachne_portal_enterprise vocabularyservice.endpoint=${baseUri}/vocabulary -cdmService.endpoint=${baseUri}/cdmresults +cdmResultsService.endpoint=${baseUri}/cdmresults #GET vocabularies vocabularyservice.endpoint.vocabularies=${vocabularyservice.endpoint}/vocabularies #GET domains @@ -12,7 +12,7 @@ vocabularyservice.endpoint.concept=${vocabularyservice.endpoint}/concept/1 cohortdefinitionservice.endpoint.cohortdefinitions=${baseUri}/cohortdefinition #POST cdmResults -cdmService.endpoint.results=${cdmService.endpoint}/{sourceName}/conceptRecordCount +cdmResultsService.endpoint.conceptRecordCount=${cdmResultsService.endpoint}/{sourceName}/conceptRecordCount #Example application service exampleservice.endpoint=${baseUri}/example