Jean-Francois Leveque

Commentaires, tests et adaptation code et tests pour indexation Publisher validé.

......@@ -23,4 +23,16 @@ public class IndexedPublisher {
this.publisherName = publisherVersion.getPublisherName();
this.publisherHistory = publisherVersion.getPublisherHistory();
}
public int getPublisherId() {
return publisherId;
}
public String getPublisherName() {
return publisherName;
}
public String getPublisherHistory() {
return publisherHistory;
}
}
\ No newline at end of file
......
......@@ -9,5 +9,11 @@ public interface PublisherSearchRepository /*extends SolrCrudRepository<IndexedP
// @Query("?0")
// List<IndexedPublisher> search(String search);
/*
@param IndexedPublisher
@return IndexedPublisher
Indexe la version simplifiée de Publisher, IndexedPublisher.
*/
public IndexedPublisher save(IndexedPublisher indexedPublisher);
}
......
......@@ -9,6 +9,9 @@ import org.slf4j.LoggerFactory;
import javax.inject.Inject;
import java.io.IOException;
/*
Classe implémentant l'interface PublisherSearchRepository avec l'API SolrJ
*/
public class PublisherSearchRepositorySolrj implements PublisherSearchRepository {
Logger logger = LoggerFactory.getLogger(getClass());
......
......@@ -9,7 +9,10 @@ import org.junit.runner.RunWith;
import org.legrog.entities.*;
import org.legrog.test.MockitoExtension;
import org.legrog.web.xyz.SharedService;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.Mock;
import org.mockito.Mockito;
import javax.inject.Inject;
import java.util.ArrayList;
......@@ -38,6 +41,9 @@ public class PublisherServiceSpringTest {
@Mock
PublisherVersion publisherVersionMock;
@Captor
ArgumentCaptor<IndexedPublisher> indexedPublisherArgumentCaptor;
@BeforeEach
public void setUp(@Mock PublisherRepository publisherRepository,
@Mock PublisherVersionRepository publisherVersionRepository,
......@@ -75,22 +81,50 @@ public class PublisherServiceSpringTest {
verify(publisherVersionRepository).save(publisherVersion1);
}
@DisplayName("Validates a version by creating a VALIDATE action that links to publisher and version, sets versions in publisher's validated and saves it")
@DisplayName("When a PublisherVersion is validated, it should be the right one")
@Test
public void testValidateVersion(@Mock PublisherActionRepository publisherActionRepository) {
public void testValidateVersionRight() {
Set<PublisherVersion> publisherVersions;
ActionType actionType = ActionType.VALIDATE;
publisher = new Publisher();
publisherVersion = new PublisherVersion();
publisherVersions = new HashSet<PublisherVersion>();
publisherVersions.add(publisherVersion);
publisherVersions.add(publisherVersionMock);
publisher.setVersions(publisherVersions);
when(publisherVersionMock.getPublisher()).thenReturn(publisher);
publisherServiceSpring.validatePublisherVersion(publisherVersionMock);
assertThat(publisher.getValidatedVersion()).isEqualTo(publisherVersionMock);
}
@DisplayName("When a publisherVersion is validated, the indexed IndexedPublisher should have all attributes right")
@Test
public void testValidateIndexPublisher(@Mock PublisherSearchRepository publisherSearchRepository) {
publisher = new Publisher();
publisher.setPublisherId(111);
when(publisherVersionMock.getPublisher()).thenReturn(publisher);
when(publisherVersionMock.getPublisherName()).thenReturn("nom");
when(publisherVersionMock.getPublisherHistory()).thenReturn("histoire");
publisherServiceSpring.validatePublisherVersion(publisherVersionMock);
Mockito.verify(publisherSearchRepository).save(indexedPublisherArgumentCaptor.capture());
IndexedPublisher indexedPublisher = indexedPublisherArgumentCaptor.getValue();
assertThat(indexedPublisher.getPublisherId()).isEqualTo(111);
assertThat(indexedPublisher.getPublisherName()).isEqualTo("nom");
assertThat(indexedPublisher.getPublisherHistory()).isEqualTo("histoire");
}
@DisplayName("When a validate creates a PublisherAction it should be saved and have all attributes right")
@Test
public void testValidateCreateAction(@Mock PublisherActionRepository publisherActionRepository) {
PublisherAction publisherAction;
ActionType actionType = ActionType.VALIDATE;
publisher = new Publisher();
when(publisherVersionMock.getPublisher()).thenReturn(publisher);
publisherAction = publisherServiceSpring.validatePublisherVersion(publisherVersionMock);
verify(publisherActionRepository).save(publisherAction);
assertThat(publisherAction.getPublisherVersion()).isEqualTo(publisherVersionMock);
......@@ -98,4 +132,5 @@ public class PublisherServiceSpringTest {
assertThat(publisherAction.getPublisher().getValidatedVersion()).isEqualTo(publisherVersionMock);
assertThat(publisherAction.getActionType()).isEqualTo(actionType);
}
}
......