Jean-Francois Leveque

Implémentation TDD de recherche, ajout de la page de recherche

......@@ -28,6 +28,10 @@ public class IndexedPublisher {
this.publisherHistory = publisherVersion.getPublisherHistory();
}
public IndexedPublisher() {
}
public int getPublisherId() {
return publisherId;
}
......@@ -39,4 +43,16 @@ public class IndexedPublisher {
public String getPublisherHistory() {
return publisherHistory;
}
public void setPublisherId(int publisherId) {
this.publisherId = publisherId;
}
public void setPublisherName(String publisherName) {
this.publisherName = publisherName;
}
public void setPublisherHistory(String publisherHistory) {
this.publisherHistory = publisherHistory;
}
}
\ No newline at end of file
......
......@@ -3,15 +3,23 @@ package org.legrog.web.publisher;
import org.legrog.entities.PublisherVersion;
import org.legrog.entities.SearchingException;
import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
import javax.inject.Named;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
/**
* View behind publisherSearch.xhtml
*/
@Named
@RequestScoped
public class PublisherSearchView implements Serializable {
List<PublisherVersion> publisherVersions = new ArrayList<>();
String searchString;
transient PublisherService publisherService;
/**
......@@ -30,11 +38,29 @@ public class PublisherSearchView implements Serializable {
/**
*
* @param string String which you expect to find in indexed publishers
* @return List<PublisherVersion>
* @throws SearchingException when getting an error from PublisherSearchRepository
*/
public List<PublisherVersion> search(String string) throws SearchingException{
return publisherService.search(string);
public void search() {
try {
this.publisherVersions = publisherService.search(this.searchString);
} catch (SearchingException se) {
// TODO Handle Exception
}
}
public String getSearchString() {
return searchString;
}
public void setSearchString(String searchString) {
this.searchString = searchString;
}
public List<PublisherVersion> getPublisherVersions() {
return publisherVersions;
}
public void setPublisherVersions(List<PublisherVersion> publisherVersions) {
this.publisherVersions = publisherVersions;
}
}
......
......@@ -145,7 +145,11 @@ public class PublisherServiceDefault implements PublisherService {
List<Integer> integers = new ArrayList<>(indexedPublishers.size());
indexedPublishers.forEach(indexedPublisher -> integers.add(indexedPublisher.getPublisherId()));
if (integers.size() > 0) {
return publisherVersionRepository.findByPublisherVersionIdIn(integers);
}
return new ArrayList<>();
}
}
......
......@@ -4,8 +4,53 @@
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:f="http://xmlns.jcp.org/jsf/core">
<f:view>
<h:outputLabel value="Hello, world"/>
</f:view>
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:jsf="http://xmlns.jcp.org/jsf">
<head>
<link rel="stylesheet" type="text/css" href="/minimal.css"/>
</head>
<body>
<form action="" jsf:id="search">
<h:panelGrid columns="2">
<label for="searchString">Élément recherché dans les éditeurs</label>
<input type="text" id="searchString" jsf:value='#{publisherSearchView.searchString}'/>
<button jsf:action="#{publisherSearchView.search}">Rechercher</button>
</h:panelGrid>
</form>
<p jsf:rendered="#{publisherSearchView.publisherVersions.isEmpty() and !publisherSearchView.searchString.isEmpty()}">Aucun éditeur ne correspond à votre recherche : ${publisherSearchView.searchString}.</p>
<h:dataTable rendered="#{!publisherSearchView.publisherVersions.isEmpty()}" value="#{publisherSearchView.publisherVersions}" var="version">
<h:column>
<f:facet name="header">Name</f:facet>
${version.publisherName}
</h:column>
<h:column>
<f:facet name="header">Address</f:facet>
${version.publisherPostOfficeBoxNumber}<br />
${version.publisherStreetAddress}<br />
${version.publisherPostalCode} ${version.publisherAddressLocality}<br />
${version.publisherAddressRegion}<br />
${version.publisherAddressCountry.countryName}
</h:column>
<h:column>
<f:facet name="header">Telephone</f:facet>
${version.publisherTelephone}
</h:column>
<h:column>
<f:facet name="header">Email</f:facet>
${version.publisherEmail}
</h:column>
<h:column>
<f:facet name="header">URL</f:facet>
${version.publisherURL}
</h:column>
<h:column>
<f:facet name="header">History</f:facet>
<h:outputText escape="false" value="#{version.publisherHistory}"/>
</h:column>
</h:dataTable>
</body>
</html>
......
......@@ -43,7 +43,8 @@ public class PublisherSearchViewTest {
@Test
@DisplayName("when called, should delegate search to PublisherService with same string")
public void searchUsesPublisherService(@Mock PublisherService publisherService) throws SearchingException{
publisherSearchView.search("1");
publisherSearchView.setSearchString("1");
publisherSearchView.search();
Mockito.verify(publisherService).search("1");
}
......@@ -52,7 +53,9 @@ public class PublisherSearchViewTest {
public void searchReturnsDataFromPublisherService(@Mock PublisherService publisherService) throws SearchingException {
List<PublisherVersion> publisherVersionList = new ArrayList<>();
when(publisherService.search("2")).thenReturn(publisherVersionList);
assertThat(publisherSearchView.search("2")).isEqualTo(publisherVersionList);
publisherSearchView.setSearchString("2");
publisherSearchView.search();
assertThat(publisherSearchView.getPublisherVersions()).isEqualTo(publisherVersionList);
}
}
}
......