Jean-Francois Leveque

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

...@@ -23,4 +23,16 @@ public class IndexedPublisher { ...@@ -23,4 +23,16 @@ public class IndexedPublisher {
23 this.publisherName = publisherVersion.getPublisherName(); 23 this.publisherName = publisherVersion.getPublisherName();
24 this.publisherHistory = publisherVersion.getPublisherHistory(); 24 this.publisherHistory = publisherVersion.getPublisherHistory();
25 } 25 }
26 +
27 + public int getPublisherId() {
28 + return publisherId;
29 + }
30 +
31 + public String getPublisherName() {
32 + return publisherName;
33 + }
34 +
35 + public String getPublisherHistory() {
36 + return publisherHistory;
37 + }
26 } 38 }
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -9,5 +9,11 @@ public interface PublisherSearchRepository /*extends SolrCrudRepository<IndexedP ...@@ -9,5 +9,11 @@ public interface PublisherSearchRepository /*extends SolrCrudRepository<IndexedP
9 // @Query("?0") 9 // @Query("?0")
10 // List<IndexedPublisher> search(String search); 10 // List<IndexedPublisher> search(String search);
11 11
12 + /*
13 + @param IndexedPublisher
14 + @return IndexedPublisher
15 +
16 + Indexe la version simplifiée de Publisher, IndexedPublisher.
17 + */
12 public IndexedPublisher save(IndexedPublisher indexedPublisher); 18 public IndexedPublisher save(IndexedPublisher indexedPublisher);
13 } 19 }
......
...@@ -9,6 +9,9 @@ import org.slf4j.LoggerFactory; ...@@ -9,6 +9,9 @@ import org.slf4j.LoggerFactory;
9 import javax.inject.Inject; 9 import javax.inject.Inject;
10 import java.io.IOException; 10 import java.io.IOException;
11 11
12 +/*
13 + Classe implémentant l'interface PublisherSearchRepository avec l'API SolrJ
14 + */
12 public class PublisherSearchRepositorySolrj implements PublisherSearchRepository { 15 public class PublisherSearchRepositorySolrj implements PublisherSearchRepository {
13 Logger logger = LoggerFactory.getLogger(getClass()); 16 Logger logger = LoggerFactory.getLogger(getClass());
14 17
......
...@@ -9,7 +9,10 @@ import org.junit.runner.RunWith; ...@@ -9,7 +9,10 @@ import org.junit.runner.RunWith;
9 import org.legrog.entities.*; 9 import org.legrog.entities.*;
10 import org.legrog.test.MockitoExtension; 10 import org.legrog.test.MockitoExtension;
11 import org.legrog.web.xyz.SharedService; 11 import org.legrog.web.xyz.SharedService;
12 +import org.mockito.ArgumentCaptor;
13 +import org.mockito.Captor;
12 import org.mockito.Mock; 14 import org.mockito.Mock;
15 +import org.mockito.Mockito;
13 16
14 import javax.inject.Inject; 17 import javax.inject.Inject;
15 import java.util.ArrayList; 18 import java.util.ArrayList;
...@@ -38,6 +41,9 @@ public class PublisherServiceSpringTest { ...@@ -38,6 +41,9 @@ public class PublisherServiceSpringTest {
38 @Mock 41 @Mock
39 PublisherVersion publisherVersionMock; 42 PublisherVersion publisherVersionMock;
40 43
44 + @Captor
45 + ArgumentCaptor<IndexedPublisher> indexedPublisherArgumentCaptor;
46 +
41 @BeforeEach 47 @BeforeEach
42 public void setUp(@Mock PublisherRepository publisherRepository, 48 public void setUp(@Mock PublisherRepository publisherRepository,
43 @Mock PublisherVersionRepository publisherVersionRepository, 49 @Mock PublisherVersionRepository publisherVersionRepository,
...@@ -75,22 +81,50 @@ public class PublisherServiceSpringTest { ...@@ -75,22 +81,50 @@ public class PublisherServiceSpringTest {
75 verify(publisherVersionRepository).save(publisherVersion1); 81 verify(publisherVersionRepository).save(publisherVersion1);
76 } 82 }
77 83
78 - @DisplayName("Validates a version by creating a VALIDATE action that links to publisher and version, sets versions in publisher's validated and saves it") 84 + @DisplayName("When a PublisherVersion is validated, it should be the right one")
79 @Test 85 @Test
80 - public void testValidateVersion(@Mock PublisherActionRepository publisherActionRepository) { 86 + public void testValidateVersionRight() {
81 Set<PublisherVersion> publisherVersions; 87 Set<PublisherVersion> publisherVersions;
82 - ActionType actionType = ActionType.VALIDATE;
83 88
84 publisher = new Publisher(); 89 publisher = new Publisher();
85 publisherVersion = new PublisherVersion(); 90 publisherVersion = new PublisherVersion();
86 -
87 -
88 publisherVersions = new HashSet<PublisherVersion>(); 91 publisherVersions = new HashSet<PublisherVersion>();
89 publisherVersions.add(publisherVersion); 92 publisherVersions.add(publisherVersion);
90 publisherVersions.add(publisherVersionMock); 93 publisherVersions.add(publisherVersionMock);
94 + publisher.setVersions(publisherVersions);
95 +
96 + when(publisherVersionMock.getPublisher()).thenReturn(publisher);
97 + publisherServiceSpring.validatePublisherVersion(publisherVersionMock);
98 + assertThat(publisher.getValidatedVersion()).isEqualTo(publisherVersionMock);
99 + }
100 +
101 + @DisplayName("When a publisherVersion is validated, the indexed IndexedPublisher should have all attributes right")
102 + @Test
103 + public void testValidateIndexPublisher(@Mock PublisherSearchRepository publisherSearchRepository) {
104 +
105 + publisher = new Publisher();
106 + publisher.setPublisherId(111);
91 107
92 when(publisherVersionMock.getPublisher()).thenReturn(publisher); 108 when(publisherVersionMock.getPublisher()).thenReturn(publisher);
109 + when(publisherVersionMock.getPublisherName()).thenReturn("nom");
110 + when(publisherVersionMock.getPublisherHistory()).thenReturn("histoire");
111 + publisherServiceSpring.validatePublisherVersion(publisherVersionMock);
112 + Mockito.verify(publisherSearchRepository).save(indexedPublisherArgumentCaptor.capture());
113 + IndexedPublisher indexedPublisher = indexedPublisherArgumentCaptor.getValue();
114 + assertThat(indexedPublisher.getPublisherId()).isEqualTo(111);
115 + assertThat(indexedPublisher.getPublisherName()).isEqualTo("nom");
116 + assertThat(indexedPublisher.getPublisherHistory()).isEqualTo("histoire");
117 + }
118 +
119 + @DisplayName("When a validate creates a PublisherAction it should be saved and have all attributes right")
120 + @Test
121 + public void testValidateCreateAction(@Mock PublisherActionRepository publisherActionRepository) {
93 PublisherAction publisherAction; 122 PublisherAction publisherAction;
123 + ActionType actionType = ActionType.VALIDATE;
124 +
125 + publisher = new Publisher();
126 +
127 + when(publisherVersionMock.getPublisher()).thenReturn(publisher);
94 publisherAction = publisherServiceSpring.validatePublisherVersion(publisherVersionMock); 128 publisherAction = publisherServiceSpring.validatePublisherVersion(publisherVersionMock);
95 verify(publisherActionRepository).save(publisherAction); 129 verify(publisherActionRepository).save(publisherAction);
96 assertThat(publisherAction.getPublisherVersion()).isEqualTo(publisherVersionMock); 130 assertThat(publisherAction.getPublisherVersion()).isEqualTo(publisherVersionMock);
...@@ -98,4 +132,5 @@ public class PublisherServiceSpringTest { ...@@ -98,4 +132,5 @@ public class PublisherServiceSpringTest {
98 assertThat(publisherAction.getPublisher().getValidatedVersion()).isEqualTo(publisherVersionMock); 132 assertThat(publisherAction.getPublisher().getValidatedVersion()).isEqualTo(publisherVersionMock);
99 assertThat(publisherAction.getActionType()).isEqualTo(actionType); 133 assertThat(publisherAction.getActionType()).isEqualTo(actionType);
100 } 134 }
135 +
101 } 136 }
......