Skip to content

Commit

Permalink
broken tets
Browse files Browse the repository at this point in the history
  • Loading branch information
averyniceday committed Sep 23, 2020
1 parent 95ce989 commit 1eb2d10
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public TopBraidSessionManager mskVocabularySessionManager() {
return new TopBraidSessionManager(mskVocabularySessionConfiguration());
}

@Bean
// @Bean
// TODO : rename to knowledgeSystemsRepository
@Qualifier("knowledgeSystemsClinicalAttributeMetadataRepository")
public KnowledgeSystemsClinicalAttributeMetadataRepository knowledgeSystemsClinicalAttributeMetadataRepository() {
Expand Down
21 changes: 21 additions & 0 deletions src/main/resources/logback.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration scan="true">
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>/srv/www/schultz-tomcat/tomcat/logs/test-cdd.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- daily rollover. Make sure the path matches the one in the file element or else
the rollover logs are placed in the working directory. -->
<fileNamePattern>/srv/www/schultz-tomcat/tomcat/logs/test-cdd.log.%d{yyyy-MM-dd}.gz</fileNamePattern>
</rollingPolicy>
<encoder>
<charset>UTF-8</charset>
<pattern>%d %-4relative [%thread] %-5level %logger{35} - %msg%n</pattern>
</encoder>
</appender>
<logger name="org.cbioportal.cdd" additivity="false" level="info">
<appender-ref ref="FILE" />
</logger>
<root level="INFO">
<appender-ref ref="FILE"/>
</root>
</configuration>
24 changes: 12 additions & 12 deletions src/test/java/org/cbioportal/cdd/ClinicalDataDictionaryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public class ClinicalDataDictionaryTest {
private TestRestTemplate restTemplate;

@Autowired
private KnowledgeSystemsClinicalAttributeMetadataRepository clinicalAttributesRepository;
private KnowledgeSystemsClinicalAttributeMetadataRepository mockClinicalAttributesRepository;

@Autowired
private ClinicalAttributeMetadataCache clinicalAttributesCache;
Expand All @@ -63,7 +63,7 @@ public class ClinicalDataDictionaryTest {
// make sure repository is working version before each test
public void resetToWorkingRepository() {
ClinicalDataDictionaryTestConfig config = new ClinicalDataDictionaryTestConfig();
config.resetWorkingClinicalAttributesRepository(clinicalAttributesRepository);
config.resetWorkingClinicalAttributesRepository(mockClinicalAttributesRepository);
ResponseEntity<String> response = restTemplate.getForEntity("/api/refreshCache", String.class);
}

Expand Down Expand Up @@ -169,7 +169,7 @@ public void validateCacheTest() throws Exception {
public void failedCacheRefreshTest() throws Exception {
// resetting cache with a broken repository should throw a FailedCacheRefreshException
ClinicalDataDictionaryTestConfig config = new ClinicalDataDictionaryTestConfig();
config.resetNotWorkingClinicalAttributesRepository(clinicalAttributesRepository);
config.resetNotWorkingClinicalAttributesRepository(mockClinicalAttributesRepository);
clinicalAttributesCache.resetCache();
}

Expand Down Expand Up @@ -232,24 +232,24 @@ public void forceResetCacheTest() throws Exception {
// test that cache is updated after GET /api/refreshCache
ClinicalDataDictionaryTestConfig config = new ClinicalDataDictionaryTestConfig();
// change repository to version with 2 attributes/1 override
config.resetUpdatedClinicalAttributesRepository(clinicalAttributesRepository);
config.resetUpdatedClinicalAttributesRepository(mockClinicalAttributesRepository);
ResponseEntity<String> response = restTemplate.getForEntity("/api/refreshCache", String.class);
assertThat(response.getBody(), equalTo("{\"response\":\"Success!\"}"));
assertThat(response.getStatusCode(), equalTo(HttpStatus.OK));
assertThat(clinicalAttributesRepository.getClinicalAttributeMetadata().size(), equalTo(2));
assertThat(clinicalAttributesRepository.getClinicalAttributeMetadataOverrides(), hasKey("updated_override_study"));
assertThat(clinicalAttributesRepository.getClinicalAttributeMetadataOverrides().size(), equalTo(1));
assertThat(mockClinicalAttributesRepository.getClinicalAttributeMetadata().size(), equalTo(2));
assertThat(mockClinicalAttributesRepository.getClinicalAttributeMetadataOverrides(), hasKey("updated_override_study"));
assertThat(mockClinicalAttributesRepository.getClinicalAttributeMetadataOverrides().size(), equalTo(1));
// change repository to non-working version
config.resetNotWorkingClinicalAttributesRepository(clinicalAttributesRepository);
config.resetNotWorkingClinicalAttributesRepository(mockClinicalAttributesRepository);
response = restTemplate.getForEntity("/api/refreshCache", String.class);
assertThat(response.getBody(), containsString("org.cbioportal.cdd.service.exception.FailedCacheRefreshException"));
assertThat(response.getStatusCode(), equalTo(HttpStatus.SERVICE_UNAVAILABLE));
// change repository to version with 5 attributes/2 overrides
config.resetWorkingClinicalAttributesRepository(clinicalAttributesRepository);
config.resetWorkingClinicalAttributesRepository(mockClinicalAttributesRepository);
restTemplate.getForEntity("/api/refreshCache", String.class);
assertThat(clinicalAttributesRepository.getClinicalAttributeMetadata().size(), equalTo(5));
assertThat(clinicalAttributesRepository.getClinicalAttributeMetadataOverrides().size(), equalTo(2));
assertThat(clinicalAttributesRepository.getClinicalAttributeMetadataOverrides(), not(hasKey("updated_override_study")));
assertThat(mockClinicalAttributesRepository.getClinicalAttributeMetadata().size(), equalTo(5));
assertThat(mockClinicalAttributesRepository.getClinicalAttributeMetadataOverrides().size(), equalTo(2));
assertThat(mockClinicalAttributesRepository.getClinicalAttributeMetadataOverrides(), not(hasKey("updated_override_study")));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,27 +26,27 @@
public class ClinicalDataDictionaryTestConfig {

@Bean
public KnowledgeSystemsClinicalAttributeMetadataRepository clinicalAttributesRepository() {
KnowledgeSystemsClinicalAttributeMetadataRepository clinicalAttributesRepository = Mockito.mock(KnowledgeSystemsClinicalAttributeMetadataRepository.class);
return clinicalAttributesRepository;
public KnowledgeSystemsClinicalAttributeMetadataRepository mockClinicalAttributesRepository() {
KnowledgeSystemsClinicalAttributeMetadataRepository mockClinicalAttributesRepository = Mockito.mock(KnowledgeSystemsClinicalAttributeMetadataRepository.class);
return mockClinicalAttributesRepository;
}

public void resetWorkingClinicalAttributesRepository(KnowledgeSystemsClinicalAttributeMetadataRepository clinicalAttributesRepository) {
Mockito.reset(clinicalAttributesRepository);
Mockito.when(clinicalAttributesRepository.getClinicalAttributeMetadata()).thenReturn(makeMockAttributeList());
Mockito.when(clinicalAttributesRepository.getClinicalAttributeMetadataOverrides()).thenReturn(makeMockOverridesMap());
public void resetWorkingClinicalAttributesRepository(KnowledgeSystemsClinicalAttributeMetadataRepository mockClinicalAttributesRepository) {
Mockito.reset(mockClinicalAttributesRepository);
Mockito.when(mockClinicalAttributesRepository.getClinicalAttributeMetadata()).thenReturn(makeMockAttributeList());
Mockito.when(mockClinicalAttributesRepository.getClinicalAttributeMetadataOverrides()).thenReturn(makeMockOverridesMap());
}

public void resetUpdatedClinicalAttributesRepository(KnowledgeSystemsClinicalAttributeMetadataRepository clinicalAttributesRepository) {
Mockito.reset(clinicalAttributesRepository);
Mockito.when(clinicalAttributesRepository.getClinicalAttributeMetadata()).thenReturn(makeUpdatedMockAttributeList());
Mockito.when(clinicalAttributesRepository.getClinicalAttributeMetadataOverrides()).thenReturn(makeUpdatedMockOverridesMap());
public void resetUpdatedClinicalAttributesRepository(KnowledgeSystemsClinicalAttributeMetadataRepository mockClinicalAttributesRepository) {
Mockito.reset(mockClinicalAttributesRepository);
Mockito.when(mockClinicalAttributesRepository.getClinicalAttributeMetadata()).thenReturn(makeUpdatedMockAttributeList());
Mockito.when(mockClinicalAttributesRepository.getClinicalAttributeMetadataOverrides()).thenReturn(makeUpdatedMockOverridesMap());
}

public void resetNotWorkingClinicalAttributesRepository(KnowledgeSystemsClinicalAttributeMetadataRepository clinicalAttributesRepository) {
Mockito.reset(clinicalAttributesRepository);
Mockito.when(clinicalAttributesRepository.getClinicalAttributeMetadata()).thenThrow(new RuntimeException("faking a problem getting the clinical attribute data"));
Mockito.when(clinicalAttributesRepository.getClinicalAttributeMetadataOverrides()).thenThrow(new RuntimeException("faking a problem getting the clinical attribute data"));
public void resetNotWorkingClinicalAttributesRepository(KnowledgeSystemsClinicalAttributeMetadataRepository mockClinicalAttributesRepository) {
Mockito.reset(mockClinicalAttributesRepository);
Mockito.when(mockClinicalAttributesRepository.getClinicalAttributeMetadata()).thenThrow(new RuntimeException("faking a problem getting the clinical attribute data"));
Mockito.when(mockClinicalAttributesRepository.getClinicalAttributeMetadataOverrides()).thenThrow(new RuntimeException("faking a problem getting the clinical attribute data"));
}

private ArrayList<ClinicalAttributeMetadata> makeMockAttributeList() {
Expand Down
7 changes: 7 additions & 0 deletions src/test/resources/test.application.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# ehcache unit test properties
ehcache.dev.persistence.path=/data/wanga5/unittesting
ehcache.dev.enable.statistics=false
ehcache.dev.clinicalAttributeMetadataEHCache.maxBytesLocalDisk=1000
ehcache.dev.clinicalAttributeMetadataEHCache.maxBytesLocalDiskUnits=kB
ehcache.dev.clinicalAttributeMetadataOverridesEHCache.maxBytesLocalDisk=1000
ehcache.dev.clinicalAttributeMetadataOverridesEHCache.maxBytesLocalDiskUnits=kB

0 comments on commit 1eb2d10

Please sign in to comment.