From 4839fdb76fe72e556646b5a1bdf10f582683d4b3 Mon Sep 17 00:00:00 2001 From: Lingyun Zhao <33519183+lingyun1010@users.noreply.github.com> Date: Wed, 4 Oct 2023 18:35:15 +0100 Subject: [PATCH] Add url decoder for cell type heatmap search (#355) * Add url decoder for cell type heatmap search * Cover the case when cell type contains a forward slash * Fix the test for checking the empty payload and improve the naming of the test methods --------- Co-authored-by: Karoly Erdos --- ...perimentCellTypeMarkerGenesController.java | 8 ++++-- ...imentCellTypeMarkerGenesControllerWIT.java | 28 ++++++++++++++++--- 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/uk/ac/ebi/atlas/search/metadata/JsonMultiexperimentCellTypeMarkerGenesController.java b/app/src/main/java/uk/ac/ebi/atlas/search/metadata/JsonMultiexperimentCellTypeMarkerGenesController.java index a035c6eef..9d6668c0c 100644 --- a/app/src/main/java/uk/ac/ebi/atlas/search/metadata/JsonMultiexperimentCellTypeMarkerGenesController.java +++ b/app/src/main/java/uk/ac/ebi/atlas/search/metadata/JsonMultiexperimentCellTypeMarkerGenesController.java @@ -9,6 +9,8 @@ import uk.ac.ebi.atlas.controllers.JsonExceptionHandlingController; import uk.ac.ebi.atlas.experimentpage.markergenes.HighchartsHeatmapAdapter; +import java.net.URLDecoder; +import java.nio.charset.StandardCharsets; import java.util.Collection; import static uk.ac.ebi.atlas.utils.GsonProvider.GSON; @@ -33,8 +35,10 @@ public String getCellTypeMarkerGenes( return GSON.toJson( highchartsHeatmapAdapter.getMarkerGeneHeatmapDataSortedLexicographically( experimentAccessions == null ? - multiexperimentCellTypeMarkerGenesService.getCellTypeMarkerGeneProfile(cellType) : multiexperimentCellTypeMarkerGenesService.getCellTypeMarkerGeneProfile( - ImmutableSet.copyOf(experimentAccessions), cellType))); + URLDecoder.decode(cellType, StandardCharsets.UTF_8)) : + multiexperimentCellTypeMarkerGenesService.getCellTypeMarkerGeneProfile( + ImmutableSet.copyOf(experimentAccessions), + URLDecoder.decode(cellType, StandardCharsets.UTF_8)))); } } diff --git a/app/src/test/java/uk/ac/ebi/atlas/search/metadata/JsonMultiexperimentCellTypeMarkerGenesControllerWIT.java b/app/src/test/java/uk/ac/ebi/atlas/search/metadata/JsonMultiexperimentCellTypeMarkerGenesControllerWIT.java index 43a25adfe..a3017db7a 100644 --- a/app/src/test/java/uk/ac/ebi/atlas/search/metadata/JsonMultiexperimentCellTypeMarkerGenesControllerWIT.java +++ b/app/src/test/java/uk/ac/ebi/atlas/search/metadata/JsonMultiexperimentCellTypeMarkerGenesControllerWIT.java @@ -14,6 +14,11 @@ import org.springframework.web.context.WebApplicationContext; import uk.ac.ebi.atlas.configuration.TestConfig; +import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; + +import static org.hamcrest.Matchers.empty; +import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.isA; import static org.springframework.test.context.jdbc.Sql.ExecutionPhase.AFTER_TEST_METHOD; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; @@ -56,9 +61,22 @@ void setUp() { } @Test - void returnsAValidJsonPayloadForAValidCellType() throws Exception { + void shouldReturnAValidJsonPayloadForAValidCellType() throws Exception { this.mockMvc.perform(get("/json/cell-type-marker-genes/{cellType}", "cell cycle S phase") - .param("experimentAccession", "E-ENAD-53")) + .param("experimentAccession", "E-ENAD-53")) + .andExpect(status().isOk()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) + .andExpect(jsonPath("$[0].cellGroupValue", isA(String.class))) + .andExpect(jsonPath("$[0].value", isA(Number.class))) + .andExpect(jsonPath("$[0].cellGroupValueWhereMarker", isA(String.class))) + .andExpect(jsonPath("$[0].pValue", isA(Number.class))); + } + + @Test + void shouldReturnAValidJsonPayloadForACellTypeContainingAForwardSlash() throws Exception { + final String encodedCellType = URLEncoder.encode("cell cycle G2/M phase", StandardCharsets.UTF_8); + this.mockMvc.perform(get("/json/cell-type-marker-genes/{cellType}", encodedCellType) + .param("experimentAccession", "E-ENAD-53")) .andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) .andExpect(jsonPath("$[0].cellGroupValue", isA(String.class))) @@ -68,9 +86,11 @@ void returnsAValidJsonPayloadForAValidCellType() throws Exception { } @Test - void returnsEmptyPayloadForAnInvalidCellType() throws Exception { + void shouldReturnEmptyPayloadForAnInvalidCellType() throws Exception { this.mockMvc.perform(get("/json/cell-type-marker-genes/{cellType}", "fooBar") .param("experimentAccession", "E-CURD-4")) - .andExpect(status().isOk()); + .andExpect(status().isOk()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) + .andExpect(jsonPath("$", is(empty()))); } }