Skip to content

Commit

Permalink
Merge pull request #96 from KPMP/KPMP-4545_total_files_count
Browse files Browse the repository at this point in the history
KPMP-4545: updated query and resolved test nullptr exceptions
  • Loading branch information
zwright authored Aug 18, 2023
2 parents 50b6718 + 2e6a665 commit 8f07dcf
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public interface DataSummaryRepository extends CrudRepository<DataSummaryValue,
String getParticipantIDString(@Param("redcap_id") String redcapId);

@Cacheable("participantTotalFileCount")
@Query(value = "SELECT count(*) FROM file_participant fp JOIN ar_file_info ar ON fp.file_id = ar.file_id "
@Query(value = "SELECT count(DISTINCT fp.file_id) FROM file_participant fp JOIN ar_file_info ar ON fp.file_id = ar.file_id "
+ "WHERE fp.participant_id= :participant_id AND ar.release_sunset_version IS NULL", nativeQuery = true)
Integer getParticipantTotalFileCount(@Param("participant_id") String participantId);

Expand Down
27 changes: 20 additions & 7 deletions src/test/java/org/kpmp/autocomplete/AutocompleteServiceTest.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.kpmp.autocomplete;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.when;

import java.io.IOException;
Expand All @@ -12,6 +12,8 @@
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.TestInstance.Lifecycle;
import org.kpmp.cellType.CellType;
import org.kpmp.cellType.CellTypeRepository;
import org.kpmp.cellType.CellTypeSynonym;
Expand All @@ -20,6 +22,7 @@
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;

@TestInstance(Lifecycle.PER_CLASS)
class AutocompleteServiceTest {

private AutocompleteService autocompleteService;
Expand All @@ -31,7 +34,7 @@ class AutocompleteServiceTest {
private CellTypeRepository cellTypeRepository;

@BeforeEach
void setUp() {
void setUp() throws Exception {
MockitoAnnotations.openMocks(this);
autocompleteService = new AutocompleteService(geneService, cellTypeRepository);
}
Expand Down Expand Up @@ -92,42 +95,52 @@ void testConvertCellTypesToAutocompleteResultsRemovesDuplicatesForCellTypeResult
List<CellType> cellTypes = new ArrayList<>();
cellTypes.add(ct1);
cellTypes.add(ct2);
List<CellType> regions = new ArrayList<>();
List<CellType> subregions = new ArrayList<>();

assertEquals(ct1, ct2);
List<AutocompleteResult> autocompleteResults = autocompleteService
.convertCellTypesToAutocompleteResults(cellTypes, null, null);
.convertCellTypesToAutocompleteResults(cellTypes, regions, subregions);
assertEquals(1, autocompleteResults.size());
}

@Test
void testConvertCellTypesToAutocompleteResultsRemovesDuplicatesForStructureRegionResults() throws Exception {
CellType ct1 = new CellType();
ct1.setCellType("abc");
ct1.setStructureRegion("same name");
CellType ct2 = new CellType();
ct2.setCellType("abc");
ct2.setStructureRegion("same name");
List<CellType> regions = new ArrayList<>();
regions.add(ct1);
regions.add(ct2);
List<CellType> subregions = new ArrayList<>();
List<CellType> cellTypes = new ArrayList<>();

assertEquals(ct1, ct2);
List<AutocompleteResult> autocompleteResults = autocompleteService.convertCellTypesToAutocompleteResults(null,
regions, null);
List<AutocompleteResult> autocompleteResults = autocompleteService.convertCellTypesToAutocompleteResults(cellTypes,
regions, subregions);
assertEquals(1, autocompleteResults.size());
}

@Test
void testConvertCellTypesToAutocompleteResultsRemovesDuplicatesForStructureSubregionResults() throws Exception {
CellType ct1 = new CellType();
ct1.setCellType("abc");
ct1.setStructureSubregion("same name");
CellType ct2 = new CellType();
ct2.setCellType("abc");
ct2.setStructureSubregion("same name");
List<CellType> subregions = new ArrayList<>();
subregions.add(ct1);
subregions.add(ct2);
List<CellType> regions = new ArrayList<>();
List<CellType> cellTypes = new ArrayList<>();

assertEquals(ct1, ct2);
List<AutocompleteResult> autocompleteResults = autocompleteService.convertCellTypesToAutocompleteResults(null,
null, subregions);
List<AutocompleteResult> autocompleteResults = autocompleteService.convertCellTypesToAutocompleteResults(cellTypes,
regions, subregions);
assertEquals(1, autocompleteResults.size());
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
package org.kpmp.geneExpressionSummary;

import org.junit.After;
import org.junit.Before;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.TestInstance.Lifecycle;

import static org.junit.jupiter.api.Assertions.*;

@TestInstance(Lifecycle.PER_CLASS)
class RTParticipantValueTest {

RTParticipantValue rtParticipantValue;

@Before
@BeforeAll
public void setUp() throws Exception {
rtParticipantValue = new RTParticipantValue();
}

@After
@AfterAll
public void tearDown() throws Exception {
rtParticipantValue = null;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
package org.kpmp.participant;

import org.junit.After;
import org.junit.Before;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.TestInstance.Lifecycle;

import static org.junit.jupiter.api.Assertions.*;

@TestInstance(Lifecycle.PER_CLASS)
class ParticipantSummaryDatasetTest {
ParticipantSummaryDataset participantSummaryDataset;

@Before

@BeforeAll
public void setUp() throws Exception {
participantSummaryDataset = new ParticipantSummaryDataset();
this.participantSummaryDataset = new ParticipantSummaryDataset();
}

@After
@AfterAll
public void tearDown() throws Exception {
participantSummaryDataset = null;
}
Expand Down

0 comments on commit 8f07dcf

Please sign in to comment.