Commit e7b52229 authored by Jean-Baptiste Nizet's avatar Jean-Baptiste Nizet
Browse files

feat: support passing the germplasm id as request parameter

parent 5e1ff4eb
...@@ -77,6 +77,17 @@ public class GermplasmController { ...@@ -77,6 +77,17 @@ public class GermplasmController {
return toModelAndView(germplasm); return toModelAndView(germplasm);
} }
@GetMapping(params = "id")
public ModelAndView getById(@RequestParam("id") String germplasmId) {
GermplasmVO germplasm = germplasmRepository.getById(germplasmId);
if (germplasm == null) {
throw new NotFoundException("Germplasm with ID " + germplasmId + " not found");
}
return toModelAndView(germplasm);
}
@GetMapping(params = "pui") @GetMapping(params = "pui")
public ModelAndView getByPui(@RequestParam("pui") String pui) { public ModelAndView getByPui(@RequestParam("pui") String pui) {
GermplasmGETSearchCriteria criteria = new GermplasmGETSearchCriteria(); GermplasmGETSearchCriteria criteria = new GermplasmGETSearchCriteria();
......
...@@ -2,17 +2,21 @@ package fr.inra.urgi.faidare.web.germplasm; ...@@ -2,17 +2,21 @@ package fr.inra.urgi.faidare.web.germplasm;
import static fr.inra.urgi.faidare.web.Fixtures.htmlContent; import static fr.inra.urgi.faidare.web.Fixtures.htmlContent;
import static org.mockito.ArgumentMatchers.*; import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.request; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.request;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections;
import java.util.List; import java.util.List;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import fr.inra.urgi.faidare.config.FaidareProperties; import fr.inra.urgi.faidare.config.FaidareProperties;
import fr.inra.urgi.faidare.domain.criteria.GermplasmGETSearchCriteria;
import fr.inra.urgi.faidare.domain.criteria.GermplasmSearchCriteria;
import fr.inra.urgi.faidare.domain.data.germplasm.GermplasmAttributeValueListVO; import fr.inra.urgi.faidare.domain.data.germplasm.GermplasmAttributeValueListVO;
import fr.inra.urgi.faidare.domain.data.germplasm.GermplasmMcpdVO; import fr.inra.urgi.faidare.domain.data.germplasm.GermplasmMcpdVO;
import fr.inra.urgi.faidare.domain.data.germplasm.GermplasmSitemapVO; import fr.inra.urgi.faidare.domain.data.germplasm.GermplasmSitemapVO;
...@@ -26,6 +30,7 @@ import fr.inra.urgi.faidare.repository.es.XRefDocumentRepository; ...@@ -26,6 +30,7 @@ import fr.inra.urgi.faidare.repository.es.XRefDocumentRepository;
import fr.inra.urgi.faidare.web.Fixtures; import fr.inra.urgi.faidare.web.Fixtures;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.mockito.ArgumentMatcher;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.boot.test.mock.mockito.MockBean;
...@@ -104,6 +109,57 @@ public class GermplasmControllerTest { ...@@ -104,6 +109,57 @@ public class GermplasmControllerTest {
.andExpect(htmlContent().endsCorrectly()); .andExpect(htmlContent().endsCorrectly());
} }
@Test
void shouldDisplayGermplasmWithIdAsParameter() throws Exception {
mockMvc.perform(get("/germplasms").param("id", germplasm.getGermplasmDbId()))
.andExpect(status().isOk())
.andExpect(content().contentTypeCompatibleWith(MediaType.TEXT_HTML))
.andExpect(htmlContent().hasTitle("Germplasm: BLE BARBU DU ROUSSILLON"))
.andExpect(htmlContent().containsH2s("Identification",
"Depositary",
"Collector",
"Breeder",
"Donors",
"Distributors",
"Evaluation Data",
"Genealogy",
"Population",
"Collection",
"Panel",
"Cross references"))
.andExpect(htmlContent().endsCorrectly());
}
@Test
void shouldDisplayGermplasmWithPuiAsParameter() throws Exception {
PaginatedList<GermplasmVO> puiList = new PaginatedList<>(null, Collections.singletonList(germplasm));
when(mockGermplasmRepository.find(any())).thenReturn(puiList);
mockMvc.perform(get("/germplasms").param("pui", germplasm.getGermplasmPUI()))
.andExpect(status().isOk())
.andExpect(content().contentTypeCompatibleWith(MediaType.TEXT_HTML))
.andExpect(htmlContent().hasTitle("Germplasm: BLE BARBU DU ROUSSILLON"))
.andExpect(htmlContent().containsH2s("Identification",
"Depositary",
"Collector",
"Breeder",
"Donors",
"Distributors",
"Evaluation Data",
"Genealogy",
"Population",
"Collection",
"Panel",
"Cross references"))
.andExpect(htmlContent().endsCorrectly());
ArgumentMatcher<GermplasmSearchCriteria> criteriaMatcher = criteria ->
criteria instanceof GermplasmGETSearchCriteria
&& ((GermplasmGETSearchCriteria) criteria).getGermplasmPUI()
.equals(Collections.singletonList(germplasm.getGermplasmPUI()));
verify(mockGermplasmRepository).find(argThat(criteriaMatcher));
}
@Test @Test
void shouldGenerateSitemap() throws Exception { void shouldGenerateSitemap() throws Exception {
List<GermplasmSitemapVO> germplasms = Arrays.asList( List<GermplasmSitemapVO> germplasms = Arrays.asList(
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment