diff --git a/backend/src/main/java/fr/inra/urgi/faidare/web/germplasm/GermplasmController.java b/backend/src/main/java/fr/inra/urgi/faidare/web/germplasm/GermplasmController.java index 9cf89be05915532b1bc418c32108f865dfd330ac..906960cab4c00a92253aac5b7f2dd0b6eaca4435 100644 --- a/backend/src/main/java/fr/inra/urgi/faidare/web/germplasm/GermplasmController.java +++ b/backend/src/main/java/fr/inra/urgi/faidare/web/germplasm/GermplasmController.java @@ -77,6 +77,17 @@ public class GermplasmController { 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") public ModelAndView getByPui(@RequestParam("pui") String pui) { GermplasmGETSearchCriteria criteria = new GermplasmGETSearchCriteria(); diff --git a/backend/src/test/java/fr/inra/urgi/faidare/web/germplasm/GermplasmControllerTest.java b/backend/src/test/java/fr/inra/urgi/faidare/web/germplasm/GermplasmControllerTest.java index 37595c9b7669d49f357f49a4f365ebc12d0a3561..bb25798dbb5c1a05205b6c545b039cb3425fd382 100644 --- a/backend/src/test/java/fr/inra/urgi/faidare/web/germplasm/GermplasmControllerTest.java +++ b/backend/src/test/java/fr/inra/urgi/faidare/web/germplasm/GermplasmControllerTest.java @@ -2,17 +2,21 @@ package fr.inra.urgi.faidare.web.germplasm; import static fr.inra.urgi.faidare.web.Fixtures.htmlContent; import static org.mockito.ArgumentMatchers.*; +import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; 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.*; import java.util.Arrays; +import java.util.Collections; import java.util.List; import com.fasterxml.jackson.databind.ObjectMapper; import com.google.common.collect.Sets; 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.GermplasmMcpdVO; import fr.inra.urgi.faidare.domain.data.germplasm.GermplasmSitemapVO; @@ -26,6 +30,7 @@ import fr.inra.urgi.faidare.repository.es.XRefDocumentRepository; import fr.inra.urgi.faidare.web.Fixtures; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.mockito.ArgumentMatcher; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; import org.springframework.boot.test.mock.mockito.MockBean; @@ -104,6 +109,57 @@ public class GermplasmControllerTest { .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 void shouldGenerateSitemap() throws Exception { List<GermplasmSitemapVO> germplasms = Arrays.asList(