1313import fr .insee .genesis .domain .service .metadata .QuestionnaireMetadataService ;
1414import fr .insee .genesis .domain .service .surveyunit .SurveyUnitQualityService ;
1515import fr .insee .genesis .domain .service .surveyunit .SurveyUnitService ;
16+ import fr .insee .genesis .exceptions .GenesisException ;
1617import fr .insee .genesis .infrastructure .utils .FileUtils ;
1718import fr .insee .genesis .stubs .ConfigStub ;
1819import fr .insee .modelefiliere .RawResponseDto ;
@@ -75,10 +76,10 @@ void init() {
7576 surveyUnitModelsCaptor = ArgumentCaptor .forClass (List .class );
7677 }
7778
78- //
7979 @ Nested
8080 @ DisplayName ("Non regression tests of #22875 : validation date and questionnaire state in processed responses" )
8181 class ValidationDateAndQuestionnaireStateTests {
82+ //OK cases
8283 @ ParameterizedTest
8384 @ DisplayName ("Process by collection instrument id OK test" )
8485 @ EnumSource (RawResponseDto .QuestionnaireStateEnum .class )
@@ -90,9 +91,7 @@ void processRawResponses_byCollectionInstrumentId_validation_date_questionnaire_
9091 processRawResponses_given (questionnaireState );
9192
9293 //WHEN
93- rawResponseService .processRawResponses (TestConstants .DEFAULT_COLLECTION_INSTRUMENT_ID );
94- verify (surveyUnitService ).saveSurveyUnits (surveyUnitModelsCaptor .capture ());
95- List <SurveyUnitModel > createdModels = surveyUnitModelsCaptor .getValue ();
94+ List <SurveyUnitModel > createdModels = whenProcessByCollectionInstrumentIdAndInterrogationIdList ();
9695
9796 //THEN
9897 processRawResponses_then (questionnaireState , createdModels );
@@ -109,17 +108,70 @@ void processRawResponses_byCollectionInstrumentIdAndInterrogationList_validation
109108 processRawResponses_given (questionnaireState );
110109
111110 //WHEN
112- rawResponseService .processRawResponses (
113- TestConstants .DEFAULT_COLLECTION_INSTRUMENT_ID ,
114- Collections .singletonList (TestConstants .DEFAULT_INTERROGATION_ID ),
115- new ArrayList <>()
116- );
117- verify (surveyUnitService ).saveSurveyUnits (surveyUnitModelsCaptor .capture ());
118- List <SurveyUnitModel > createdModels = surveyUnitModelsCaptor .getValue ();
111+ List <SurveyUnitModel > createdModels = whenProcessRawResponsesCollectionInstrumentId ();
119112
120113 //THEN
121114 processRawResponses_then (questionnaireState , createdModels );
122115 }
116+
117+ //Non-blocking exception tests
118+ //Invalid questionnaire state
119+ @ Test
120+ @ DisplayName ("Invalid questionnaireState test (process by collection id)" )
121+ @ SneakyThrows
122+ void processRawResponses_byCollectionInstrumentId_invalid_questionnaire_state_test () {
123+ //GIVEN
124+ processRawResponses_given_invalid_questionnaire_state ();
125+
126+ //WHEN
127+ List <SurveyUnitModel > createdModels = whenProcessRawResponsesCollectionInstrumentId ();
128+
129+ //THEN
130+ processRawResponses_then_questionnaire_state_null (createdModels );
131+ }
132+ @ Test
133+ @ DisplayName ("Invalid questionnaireState test (process by collection id and interrogation id list)" )
134+ @ SneakyThrows
135+ void processRawResponses_byCollectionInstrumentIdAndInterrogationList_invalid_questionnaire_state_test () {
136+ //GIVEN
137+ processRawResponses_given_invalid_questionnaire_state ();
138+
139+ //WHEN
140+ List <SurveyUnitModel > createdModels = whenProcessByCollectionInstrumentIdAndInterrogationIdList ();
141+
142+ //THEN
143+ processRawResponses_then_questionnaire_state_null (createdModels );
144+ }
145+
146+ //Invalid validationDate
147+ @ Test
148+ @ DisplayName ("Invalid validationDate test (process by collection id)" )
149+ @ SneakyThrows
150+ void processRawResponses_byCollectionId_invalid_validation_date_test (){
151+ //GIVEN
152+ processRawResponses_given_invalid_validation_date ();
153+
154+ //WHEN
155+ List <SurveyUnitModel > createdModels = whenProcessByCollectionInstrumentIdAndInterrogationIdList ();
156+
157+ //THEN
158+ processRawResponses_then_validation_date_null (createdModels );
159+ }
160+ @ Test
161+ @ DisplayName ("Invalid validationDate test (process by collection id and interrogation id list)" )
162+ @ SneakyThrows
163+ void processRawResponses_byCollectionIdAndInterrogationIds_invalid_validation_date_test (){
164+ //GIVEN
165+ processRawResponses_given_invalid_validation_date ();
166+
167+ //WHEN
168+ List <SurveyUnitModel > createdModels = whenProcessRawResponsesCollectionInstrumentId ();
169+
170+ //THEN
171+ processRawResponses_then_validation_date_null (createdModels );
172+ }
173+
174+ //GIVENS
123175 @ SneakyThrows
124176 private void processRawResponses_given (RawResponseDto .QuestionnaireStateEnum questionnaireState ){
125177 VariablesMap variablesMap = new VariablesMap ();
@@ -156,53 +208,6 @@ private void processRawResponses_given(RawResponseDto.QuestionnaireStateEnum que
156208 doReturn (metadataModel ).when (metadataService ).loadAndSaveIfNotExists (any (), any (), any (), any (), any ());
157209 doReturn (rawResponses ).when (rawResponsePersistencePort ).findRawResponses (any (), any (), any ());
158210 }
159- private void processRawResponses_then (RawResponseDto .QuestionnaireStateEnum questionnaireState ,
160- List <SurveyUnitModel > createdModels ) {
161- Assertions .assertThat (createdModels ).hasSize (1 );
162- Assertions .assertThat (createdModels .getFirst ().getValidationDate ()).isEqualTo (
163- LocalDateTime .parse (TEST_VALIDATION_DATE , DateTimeFormatter .ISO_OFFSET_DATE_TIME )
164- );
165- Assertions .assertThat (createdModels .getFirst ().getQuestionnaireState ()).isEqualTo (questionnaireState );
166- }
167-
168- //Non-blocking exception tests
169- //Invalid questionnaire state
170- @ Test
171- @ DisplayName ("Invalid questionnaireState test (process by collection id)" )
172- @ SneakyThrows
173- void processRawResponses_byCollectionInstrumentId_invalid_questionnaire_state_test () {
174- //GIVEN
175- processRawResponses_given_invalid_questionnaire_state ();
176-
177- //WHEN
178- rawResponseService .processRawResponses (
179- TestConstants .DEFAULT_COLLECTION_INSTRUMENT_ID ,
180- Collections .singletonList (TestConstants .DEFAULT_INTERROGATION_ID ),
181- new ArrayList <>()
182- );
183- verify (surveyUnitService ).saveSurveyUnits (surveyUnitModelsCaptor .capture ());
184- List <SurveyUnitModel > createdModels = surveyUnitModelsCaptor .getValue ();
185-
186- //THEN
187- processRawResponses_then_questionnaire_state_null (createdModels );
188- }
189- @ Test
190- @ DisplayName ("Invalid questionnaireState test (process by collection id and interrogation id list)" )
191- @ SneakyThrows
192- void processRawResponses_byCollectionInstrumentIdAndInterrogationList_invalid_questionnaire_state_test () {
193- //GIVEN
194- processRawResponses_given_invalid_questionnaire_state ();
195-
196- //WHEN
197- rawResponseService .processRawResponses (
198- TestConstants .DEFAULT_COLLECTION_INSTRUMENT_ID
199- );
200- verify (surveyUnitService ).saveSurveyUnits (surveyUnitModelsCaptor .capture ());
201- List <SurveyUnitModel > createdModels = surveyUnitModelsCaptor .getValue ();
202-
203- //THEN
204- processRawResponses_then_questionnaire_state_null (createdModels );
205- }
206211 @ SneakyThrows
207212 private void processRawResponses_given_invalid_questionnaire_state (){
208213 VariablesMap variablesMap = new VariablesMap ();
@@ -237,49 +242,6 @@ private void processRawResponses_given_invalid_questionnaire_state(){
237242 doReturn (metadataModel ).when (metadataService ).loadAndSaveIfNotExists (any (), any (), any (), any (), any ());
238243 doReturn (rawResponses ).when (rawResponsePersistencePort ).findRawResponses (any (), any (), any ());
239244 }
240- private void processRawResponses_then_questionnaire_state_null (List <SurveyUnitModel > createdModels ){
241- Assertions .assertThat (createdModels ).hasSize (1 );
242- Assertions .assertThat (createdModels .getFirst ().getQuestionnaireState ()).isNull ();
243- }
244-
245- //Invalid validationDate
246- @ Test
247- @ DisplayName ("Invalid validationDate test (process by collection id)" )
248- @ SneakyThrows
249- void processRawResponses_byCollectionId_invalid_validation_date_test (){
250- //GIVEN
251- processRawResponses_given_invalid_validation_date ();
252-
253- //WHEN
254- rawResponseService .processRawResponses (
255- TestConstants .DEFAULT_COLLECTION_INSTRUMENT_ID
256- );
257- verify (surveyUnitService ).saveSurveyUnits (surveyUnitModelsCaptor .capture ());
258- List <SurveyUnitModel > createdModels = surveyUnitModelsCaptor .getValue ();
259-
260- //THEN
261- processRawResponses_then_validation_date_null (createdModels );
262- }
263- @ Test
264- @ DisplayName ("Invalid validationDate test (process by collection id and interrogation id list)" )
265- @ SneakyThrows
266- void processRawResponses_byCollectionIdAndInterrogationIds_invalid_validation_date_test (){
267- //GIVEN
268- processRawResponses_given_invalid_validation_date ();
269-
270- //WHEN
271- rawResponseService .processRawResponses (
272- TestConstants .DEFAULT_COLLECTION_INSTRUMENT_ID ,
273- Collections .singletonList (TestConstants .DEFAULT_INTERROGATION_ID ),
274- new ArrayList <>()
275- );
276- verify (surveyUnitService ).saveSurveyUnits (surveyUnitModelsCaptor .capture ());
277- List <SurveyUnitModel > createdModels = surveyUnitModelsCaptor .getValue ();
278-
279- //THEN
280- processRawResponses_then_validation_date_null (createdModels );
281- }
282-
283245 @ SneakyThrows
284246 private void processRawResponses_given_invalid_validation_date (){
285247 VariablesMap variablesMap = new VariablesMap ();
@@ -314,11 +276,43 @@ private void processRawResponses_given_invalid_validation_date(){
314276 doReturn (metadataModel ).when (metadataService ).loadAndSaveIfNotExists (any (), any (), any (), any (), any ());
315277 doReturn (rawResponses ).when (rawResponsePersistencePort ).findRawResponses (any (), any (), any ());
316278 }
279+
280+ //WHENS
281+ private List <SurveyUnitModel > whenProcessByCollectionInstrumentIdAndInterrogationIdList () throws GenesisException {
282+ rawResponseService .processRawResponses (TestConstants .DEFAULT_COLLECTION_INSTRUMENT_ID );
283+ verify (surveyUnitService ).saveSurveyUnits (surveyUnitModelsCaptor .capture ());
284+ List <SurveyUnitModel > createdModels = surveyUnitModelsCaptor .getValue ();
285+ return createdModels ;
286+ }
287+ private List <SurveyUnitModel > whenProcessRawResponsesCollectionInstrumentId () throws GenesisException {
288+ rawResponseService .processRawResponses (
289+ TestConstants .DEFAULT_COLLECTION_INSTRUMENT_ID ,
290+ Collections .singletonList (TestConstants .DEFAULT_INTERROGATION_ID ),
291+ new ArrayList <>()
292+ );
293+ verify (surveyUnitService ).saveSurveyUnits (surveyUnitModelsCaptor .capture ());
294+ List <SurveyUnitModel > createdModels = surveyUnitModelsCaptor .getValue ();
295+ return createdModels ;
296+ }
297+
298+ //THENS
299+ private void processRawResponses_then (RawResponseDto .QuestionnaireStateEnum questionnaireState ,
300+ List <SurveyUnitModel > createdModels ) {
301+ Assertions .assertThat (createdModels ).hasSize (1 );
302+ Assertions .assertThat (createdModels .getFirst ().getValidationDate ()).isEqualTo (
303+ LocalDateTime .parse (TEST_VALIDATION_DATE , DateTimeFormatter .ISO_OFFSET_DATE_TIME )
304+ );
305+ Assertions .assertThat (createdModels .getFirst ().getQuestionnaireState ()).isEqualTo (questionnaireState );
306+ }
317307 private void processRawResponses_then_validation_date_null (
318308 List <SurveyUnitModel > createdModels
319309 ){
320310 Assertions .assertThat (createdModels ).hasSize (1 );
321311 Assertions .assertThat (createdModels .getFirst ().getValidationDate ()).isNull ();
322312 }
313+ private void processRawResponses_then_questionnaire_state_null (List <SurveyUnitModel > createdModels ){
314+ Assertions .assertThat (createdModels ).hasSize (1 );
315+ Assertions .assertThat (createdModels .getFirst ().getQuestionnaireState ()).isNull ();
316+ }
323317 }
324318}
0 commit comments