Jean-Francois Leveque

Nouveau test de contrôle des exceptions côté Solr.

......@@ -2,6 +2,7 @@ package org.legrog.entities;
import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.beans.BindingException;
import org.junit.jupiter.api.*;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.platform.runner.JUnitPlatform;
......@@ -14,6 +15,8 @@ import java.io.IOException;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.assertj.core.api.Assertions.assertThat;
/*
Classe testant PublisherSearchRepositorySolrj
*/
......@@ -44,12 +47,22 @@ public class PublisherSearchRepositorySolrjTest {
}
@Test
@DisplayName("When repository in error, should throw an IndexingException")
@DisplayName("When repository in IO error, should throw an IndexingException")
public void addBeanIOETest(@Mock IndexedPublisher indexedPublisher) throws SolrServerException, IOException {
when(solrClient.addBean(indexedPublisher, 1)).thenThrow(new IOException());
Assertions.assertThrows(IndexingException.class, () -> publisherSearchRepository.save(indexedPublisher));
}
@Test
@DisplayName("When repository in SolrServerException, should throw an IndexingException with its root cause")
public void addBeanSSETest(@Mock IndexedPublisher indexedPublisher) throws SolrServerException, IOException{
when(solrClient.addBean(indexedPublisher, 1)).thenThrow(new SolrServerException(new BindingException("BE test")));
try {
publisherSearchRepository.save(indexedPublisher);
} catch (IndexingException ie) {
assertThat(ie.getRootCause().getClass()).isEqualTo(BindingException.class);
}
}
}
}
......