Jean-Francois Leveque

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

...@@ -2,6 +2,7 @@ package org.legrog.entities; ...@@ -2,6 +2,7 @@ package org.legrog.entities;
2 2
3 import org.apache.solr.client.solrj.SolrClient; 3 import org.apache.solr.client.solrj.SolrClient;
4 import org.apache.solr.client.solrj.SolrServerException; 4 import org.apache.solr.client.solrj.SolrServerException;
5 +import org.apache.solr.client.solrj.beans.BindingException;
5 import org.junit.jupiter.api.*; 6 import org.junit.jupiter.api.*;
6 import org.junit.jupiter.api.extension.ExtendWith; 7 import org.junit.jupiter.api.extension.ExtendWith;
7 import org.junit.platform.runner.JUnitPlatform; 8 import org.junit.platform.runner.JUnitPlatform;
...@@ -14,6 +15,8 @@ import java.io.IOException; ...@@ -14,6 +15,8 @@ import java.io.IOException;
14 import static org.mockito.Mockito.verify; 15 import static org.mockito.Mockito.verify;
15 import static org.mockito.Mockito.when; 16 import static org.mockito.Mockito.when;
16 17
18 +import static org.assertj.core.api.Assertions.assertThat;
19 +
17 /* 20 /*
18 Classe testant PublisherSearchRepositorySolrj 21 Classe testant PublisherSearchRepositorySolrj
19 */ 22 */
...@@ -44,12 +47,22 @@ public class PublisherSearchRepositorySolrjTest { ...@@ -44,12 +47,22 @@ public class PublisherSearchRepositorySolrjTest {
44 } 47 }
45 48
46 @Test 49 @Test
47 - @DisplayName("When repository in error, should throw an IndexingException") 50 + @DisplayName("When repository in IO error, should throw an IndexingException")
48 public void addBeanIOETest(@Mock IndexedPublisher indexedPublisher) throws SolrServerException, IOException { 51 public void addBeanIOETest(@Mock IndexedPublisher indexedPublisher) throws SolrServerException, IOException {
49 when(solrClient.addBean(indexedPublisher, 1)).thenThrow(new IOException()); 52 when(solrClient.addBean(indexedPublisher, 1)).thenThrow(new IOException());
50 Assertions.assertThrows(IndexingException.class, () -> publisherSearchRepository.save(indexedPublisher)); 53 Assertions.assertThrows(IndexingException.class, () -> publisherSearchRepository.save(indexedPublisher));
51 } 54 }
52 55
56 + @Test
57 + @DisplayName("When repository in SolrServerException, should throw an IndexingException with its root cause")
58 + public void addBeanSSETest(@Mock IndexedPublisher indexedPublisher) throws SolrServerException, IOException{
59 + when(solrClient.addBean(indexedPublisher, 1)).thenThrow(new SolrServerException(new BindingException("BE test")));
60 + try {
61 + publisherSearchRepository.save(indexedPublisher);
62 + } catch (IndexingException ie) {
63 + assertThat(ie.getRootCause().getClass()).isEqualTo(BindingException.class);
64 + }
65 + }
53 } 66 }
54 67
55 } 68 }
......