Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 41 additions & 18 deletions src/test/java/org/cbioportal/legacy/web/InfoControllerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,21 @@
import org.cbioportal.legacy.model.InfoDb;
import org.cbioportal.legacy.service.InfoService;
import org.cbioportal.legacy.web.config.TestConfig;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.http.MediaType;
import org.springframework.security.test.context.support.WithMockUser;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;

@RunWith(SpringJUnit4ClassRunner.class)
@ExtendWith(SpringExtension.class)
@WebMvcTest
@ContextConfiguration(classes = {InfoController.class, TestConfig.class})
@TestPropertySource(
Expand All @@ -30,9 +30,11 @@
})
public class InfoControllerTest {

@Autowired private MockMvc mockMvc;
@Autowired
private MockMvc mockMvc;

@MockBean private InfoService infoService;
@MockBean
private InfoService infoService;

@Test
@WithMockUser
Expand All @@ -41,9 +43,14 @@ public void getInfo() throws Exception {
.perform(MockMvcRequestBuilders.get("/api/info").accept(MediaType.APPLICATION_JSON))
.andExpect(MockMvcResultMatchers.status().isOk())
.andExpect(
MockMvcResultMatchers.content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
.andExpect(MockMvcResultMatchers.jsonPath("$.portalVersion").value("test_portal_version"))
.andExpect(MockMvcResultMatchers.jsonPath("$.dbVersion").value("test_db_version"))
MockMvcResultMatchers.content()
.contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
.andExpect(
MockMvcResultMatchers.jsonPath("$.portalVersion")
.value("test_portal_version"))
.andExpect(
MockMvcResultMatchers.jsonPath("$.dbVersion")
.value("test_db_version"))
.andExpect(
MockMvcResultMatchers.jsonPath("$.derivedTableVersion")
.value("test_derived_table_version"));
Expand All @@ -63,15 +70,22 @@ public void getInfo_usesDbThenOverrides() throws Exception {
.perform(MockMvcRequestBuilders.get("/api/info").accept(MediaType.APPLICATION_JSON))
.andExpect(MockMvcResultMatchers.status().isOk())
.andExpect(
MockMvcResultMatchers.content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
MockMvcResultMatchers.content()
.contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
// property overrides should win for db and derived
.andExpect(MockMvcResultMatchers.jsonPath("$.dbVersion").value("test_db_version"))
.andExpect(
MockMvcResultMatchers.jsonPath("$.dbVersion")
.value("test_db_version"))
.andExpect(
MockMvcResultMatchers.jsonPath("$.derivedTableVersion")
.value("test_derived_table_version"))
// geneTableVersion and genesetVersion should be present from DB
.andExpect(MockMvcResultMatchers.jsonPath("$.geneTableVersion").value("gene_table_from_db"))
.andExpect(MockMvcResultMatchers.jsonPath("$.genesetVersion").value("geneset_from_db"));
.andExpect(
MockMvcResultMatchers.jsonPath("$.geneTableVersion")
.value("gene_table_from_db"))
.andExpect(
MockMvcResultMatchers.jsonPath("$.genesetVersion")
.value("geneset_from_db"));
}

@Test
Expand All @@ -84,15 +98,24 @@ public void getInfo_schemaMismatchFallback() throws Exception {
.perform(MockMvcRequestBuilders.get("/api/info").accept(MediaType.APPLICATION_JSON))
.andExpect(MockMvcResultMatchers.status().isOk())
.andExpect(
MockMvcResultMatchers.content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
MockMvcResultMatchers.content()
.contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
// Should fall back to property values when DB is unavailable
.andExpect(MockMvcResultMatchers.jsonPath("$.portalVersion").value("test_portal_version"))
.andExpect(MockMvcResultMatchers.jsonPath("$.dbVersion").value("test_db_version"))
.andExpect(
MockMvcResultMatchers.jsonPath("$.portalVersion")
.value("test_portal_version"))
.andExpect(
MockMvcResultMatchers.jsonPath("$.dbVersion")
.value("test_db_version"))
.andExpect(
MockMvcResultMatchers.jsonPath("$.derivedTableVersion")
.value("test_derived_table_version"))
// DB fields should not be present when schema mismatch
.andExpect(MockMvcResultMatchers.jsonPath("$.geneTableVersion").doesNotExist())
.andExpect(MockMvcResultMatchers.jsonPath("$.genesetVersion").doesNotExist());
.andExpect(
MockMvcResultMatchers.jsonPath("$.geneTableVersion")
.doesNotExist())
.andExpect(
MockMvcResultMatchers.jsonPath("$.genesetVersion")
.doesNotExist());
}
}