-
Notifications
You must be signed in to change notification settings - Fork 580
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
cbioportal import user
committed
Dec 27, 2024
1 parent
50b052b
commit 0723054
Showing
10 changed files
with
530 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
src/main/resources/fed-sources.properties → src/main/resources/federator.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
fed.sources[0].name=Test cBioPortal 1 | ||
fed.sources[0].base-url=https://test.cbioportal.dev.aws.mskcc.org/api-fed | ||
|
||
fed.sources[0].name=Test cBioPortal 2 | ||
fed.sources[0].base-url=https://test2.cbioportal.dev.aws.mskcc.org/api-fed | ||
fed.sources[1].name=Test cBioPortal 2 | ||
fed.sources[1].base-url=https://test2.cbioportal.dev.aws.mskcc.org/api-fed |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
182 changes: 182 additions & 0 deletions
182
src/test/java/org/cbioportal/service/impl/FederatedViewServiceImplTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,182 @@ | ||
package org.cbioportal.service.impl; | ||
|
||
import org.cbioportal.model.ClinicalAttribute; | ||
import org.cbioportal.model.Sample; | ||
import org.cbioportal.persistence.ClinicalAttributeRepository; | ||
import org.cbioportal.persistence.ClinicalDataRepository; | ||
import org.cbioportal.persistence.SampleRepository; | ||
import org.cbioportal.service.ClinicalAttributeService; | ||
import org.cbioportal.service.ClinicalDataService; | ||
import org.cbioportal.service.exception.FederationException; | ||
import org.junit.Assert; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.Mockito; | ||
import org.mockito.Spy; | ||
import org.mockito.junit.MockitoJUnitRunner; | ||
import org.springframework.test.util.ReflectionTestUtils; | ||
|
||
import java.util.List; | ||
|
||
@RunWith(MockitoJUnitRunner.class) | ||
public class FederatedViewServiceImplTest extends BaseServiceImplTest { | ||
|
||
@InjectMocks | ||
private FederatedViewServiceImpl federatedViewService; | ||
|
||
@Mock | ||
private List<String> dataSourceStudies = List.of( | ||
STUDY_ID, | ||
STUDY_ID_2 | ||
); | ||
|
||
@Mock | ||
private ClinicalAttributeService clinicalAttributeService; | ||
|
||
@Mock | ||
private ClinicalDataService clinicalDataService; | ||
|
||
|
||
private List<ClinicalAttribute> mockClinicalAttributes() { | ||
|
||
var attrib11 = new ClinicalAttribute(); | ||
attrib11.setDisplayName("Sex"); | ||
attrib11.setDescription("Sex"); | ||
attrib11.setDatatype("STRING"); | ||
attrib11.setPatientAttribute(false); | ||
attrib11.setPriority("1"); | ||
attrib11.setAttrId("SEX"); | ||
attrib11.setCancerStudyIdentifier(STUDY_ID); | ||
|
||
var attrib21 = new ClinicalAttribute(); | ||
attrib21.setDisplayName("Age"); | ||
attrib21.setDescription("Age"); | ||
attrib21.setDatatype("NUMBER"); | ||
attrib21.setPatientAttribute(false); | ||
attrib21.setPriority("1"); | ||
attrib21.setAttrId("AGE"); | ||
attrib21.setCancerStudyIdentifier(STUDY_ID); | ||
|
||
var attrib12 = new ClinicalAttribute(); | ||
attrib12.setDisplayName("Sex"); | ||
attrib12.setDescription("Sex"); | ||
attrib12.setDatatype("STRING"); | ||
attrib12.setPatientAttribute(false); | ||
attrib12.setPriority("1"); | ||
attrib12.setAttrId("SEX"); | ||
attrib12.setCancerStudyIdentifier(STUDY_ID_2); | ||
|
||
var attrib22 = new ClinicalAttribute(); | ||
attrib22.setDisplayName("Age"); | ||
attrib22.setDescription("Age"); | ||
attrib22.setDatatype("NUMBER"); | ||
attrib22.setPatientAttribute(false); | ||
attrib22.setPriority("1"); | ||
attrib22.setAttrId("AGE"); | ||
attrib22.setCancerStudyIdentifier(STUDY_ID_2); | ||
|
||
return List.of(attrib11, attrib21, attrib12, attrib22); | ||
} | ||
|
||
private List<Sample> mockSamples() { | ||
var sample1 = new Sample(); | ||
sample1.setStableId(SAMPLE_ID1); | ||
sample1.setPatientStableId(PATIENT_ID_1); | ||
sample1.setCancerStudyIdentifier(STUDY_ID); | ||
|
||
var sample2 = new Sample(); | ||
sample2.setStableId(SAMPLE_ID2); | ||
sample2.setPatientStableId(PATIENT_ID_2); | ||
sample2.setCancerStudyIdentifier(STUDY_ID); | ||
|
||
var sample3 = new Sample(); | ||
sample3.setStableId(SAMPLE_ID3); | ||
sample3.setPatientStableId(PATIENT_ID_3); | ||
sample3.setCancerStudyIdentifier(STUDY_ID_2); | ||
|
||
return List.of(sample1, sample2, sample3); | ||
} | ||
|
||
@Before | ||
public void setup() { | ||
ReflectionTestUtils.setField(federatedViewService, "federationMode", FederationMode.DATASOURCE); | ||
|
||
List<ClinicalAttribute> attribs = mockClinicalAttributes(); | ||
|
||
// Methods used by fetchClinicalAttributes | ||
} | ||
|
||
@Test | ||
public void fetchClinicalAttributes() throws FederationException { | ||
// Arrange | ||
var expected = mockClinicalAttributes(); | ||
|
||
// Act | ||
var result = federatedViewService.fetchClinicalAttributes(); | ||
|
||
// Assert | ||
Assert.assertEquals(expected, result); | ||
} | ||
|
||
// @Test | ||
// public void fetchClinicalDataCountsNoFilter() throws FederationException { | ||
// // Arrange | ||
// // Mock out: the cohort, ie. | ||
// // - 1 person is this race & this age & this study | ||
// // - .. 2 other people .. | ||
// var filter = new ClinicalDataCountFilter(); | ||
// // First we get the cohort | ||
//// Mockito.when( | ||
//// studyViewFilterApplier.apply() | ||
//// ).thenReturn( | ||
//// | ||
//// ); | ||
// // Then we extract the study and sample IDs from this cohort | ||
// Mockito.when().thenReturn(); | ||
// // Then we call clinicalDataService | ||
// Mockito.when( | ||
// clinicalDataService.fetchClinicalDataCounts( | ||
// studyIds, | ||
// sampleIds, | ||
// attributeIds | ||
// ) | ||
// ).thenReturn( | ||
// /* ... */ | ||
// ); | ||
// | ||
// // Act | ||
// var result = federatedViewService.fetchClinicalDataCounts(filter); | ||
// | ||
// // Assert | ||
// // - Returns some list of SampleIdentifiers | ||
// // - Extracts them into study ID + sample ID list | ||
// // - Calls fetchClinicalDataCounts() | ||
// } | ||
// | ||
// // TODO test with filter | ||
// | ||
// @Test | ||
// public void fetchClinicalDataBinCountsNoFilter() throws FederationException { | ||
// // Arrange | ||
// var filter = new ClinicalDataBinCountFilter(); | ||
// Mockito.when( | ||
// clinicalDataBinUtil.fetchClinicalDataBinCounts( | ||
// DataBinMethod.STATIC, | ||
// filter, | ||
// false | ||
// ) | ||
// ).thenReturn( | ||
// /* ... */ | ||
// ); | ||
// | ||
// // Act | ||
// var result = federatedViewService.fetchClinicalDataBinCounts(); | ||
// | ||
// // Assert ... | ||
// } | ||
// | ||
// // TODO test with filter | ||
} |
46 changes: 46 additions & 0 deletions
46
src/test/java/org/cbioportal/test/integration/FederatedApiIntegrationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package org.cbioportal.test.integration; | ||
|
||
import org.cbioportal.model.ClinicalAttribute; | ||
import org.cbioportal.model.Sample; | ||
import org.cbioportal.persistence.ClinicalAttributeRepository; | ||
import org.cbioportal.persistence.ClinicalDataRepository; | ||
import org.cbioportal.persistence.SampleRepository; | ||
import org.cbioportal.service.ClinicalDataService; | ||
import org.cbioportal.service.FederatedViewService; | ||
import org.cbioportal.web.FederatedViewController; | ||
import org.cbioportal.web.config.TestConfig; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; | ||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.boot.test.mock.mockito.MockBean; | ||
import org.springframework.context.annotation.ComponentScan; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.security.test.context.support.WithMockUser; | ||
import org.springframework.test.context.ContextConfiguration; | ||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; | ||
import org.springframework.test.web.servlet.MockMvc; | ||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; | ||
|
||
import java.util.List; | ||
|
||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.Mockito.when; | ||
import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.csrf; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; | ||
|
||
@RunWith(SpringJUnit4ClassRunner.class) | ||
//@WebMvcTest | ||
//@AutoConfigureMockMvc // load the whole Spring Boot application context | ||
@ContextConfiguration(classes = { | ||
FederatedViewController.class, | ||
FederatedViewService.class, | ||
ClinicalDataService.class, | ||
TestConfig.class | ||
}) | ||
public class FederatedApiIntegrationTest { | ||
} |
Oops, something went wrong.