Skip to content

Commit

Permalink
Add url decoder for cell type heatmap search (#355)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
lingyun1010 and ke4 authored Oct 4, 2023
1 parent a994341 commit 4839fdb
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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))));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)))
Expand All @@ -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())));
}
}

0 comments on commit 4839fdb

Please sign in to comment.