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()))); } }