@@ -181,13 +181,11 @@ class SensitivityAnalysisTest {
181
181
private static final String SENSITIVITY_ANALYSIS_STOPPED_DESTINATION = "sensitivityanalysis.stopped" ;
182
182
private static final String SENSITIVITY_ANALYSIS_FAILED_DESTINATION = "sensitivityanalysis.run.dlx" ;
183
183
184
- private static final byte [] SENSITIVITY_RESULTS_AS_CSV = {0x00 , 0x01 };
184
+ private static final byte [] SENSITIVITY_RESULTS_AS_ZIPPED_CSV = {0x00 , 0x01 };
185
185
186
186
@ Autowired
187
187
private RootNetworkNodeInfoService rootNetworkNodeInfoService ;
188
188
@ Autowired
189
- private StudyService studyService ;
190
- @ Autowired
191
189
private TestUtils studyTestUtils ;
192
190
193
191
@ BeforeEach
@@ -254,9 +252,11 @@ public MockResponse dispatch(RecordedRequest request) {
254
252
} else if (path .matches ("/v1/results/" + SENSITIVITY_ANALYSIS_RESULT_UUID + "/filter-options" + "\\ ?.*" )
255
253
|| path .matches ("/v1/results/" + SENSITIVITY_ANALYSIS_OTHER_NODE_RESULT_UUID + "/filter-options" + "\\ ?.*" )) {
256
254
return new MockResponse (200 , Headers .of (HttpHeaders .CONTENT_TYPE , MediaType .APPLICATION_JSON_VALUE ), FAKE_RESULT_JSON );
257
- } else if (path .matches ("/v1/results/" + SENSITIVITY_ANALYSIS_RESULT_UUID + "/csv" )
258
- || path .matches ("/v1/results/" + SENSITIVITY_ANALYSIS_OTHER_NODE_RESULT_UUID + "/csv" ) && request .getMethod ().equals ("POST" )) {
259
- return new MockResponse .Builder ().code (200 ).body (getBinaryAsBuffer (SENSITIVITY_RESULTS_AS_CSV ))
255
+ } else if (path .matches ("/v1/results/" + SENSITIVITY_ANALYSIS_RESULT_UUID + "/csv\\ ?selector=fakeJsonSelector" )
256
+ || path .matches ("/v1/results/" + SENSITIVITY_ANALYSIS_RESULT_UUID + "/csv\\ ?selector=fakeJsonSelector&filters=lineId2&globalFilters=ss&networkUuid=.*&variantId=.*" )
257
+ || path .matches ("/v1/results/" + SENSITIVITY_ANALYSIS_OTHER_NODE_RESULT_UUID + "/csv\\ ?selector=fakeJsonSelector" )
258
+ || path .matches ("/v1/results/" + SENSITIVITY_ANALYSIS_OTHER_NODE_RESULT_UUID + "/csv\\ ?selector=fakeJsonSelector&filters=lineId2&globalFilters=ss&networkUuid=.*&variantId=.*" )) {
259
+ return new MockResponse .Builder ().code (200 ).body (getBinaryAsBuffer (SENSITIVITY_RESULTS_AS_ZIPPED_CSV ))
260
260
.addHeader (HttpHeaders .CONTENT_TYPE , MediaType .APPLICATION_JSON_VALUE ).build ();
261
261
} else if (path .matches ("/v1/results/" + SENSITIVITY_ANALYSIS_RESULT_UUID ) && request .getMethod ().equals ("DELETE" )) {
262
262
return new MockResponse (200 , Headers .of (HttpHeaders .CONTENT_TYPE , MediaType .APPLICATION_JSON_VALUE ), SENSITIVITY_ANALYSIS_STATUS_JSON );
@@ -306,7 +306,7 @@ public MockResponse dispatch(RecordedRequest request) {
306
306
} else if (path .matches ("/v1/results/" + SENSITIVITY_ANALYSIS_RESULT_UUID + "\\ ?filters=.*globalFilters=.*networkUuid=.*variantId.*sort=.*" )) {
307
307
return new MockResponse (200 , Headers .of (HttpHeaders .CONTENT_TYPE , MediaType .APPLICATION_JSON_VALUE ), SENSITIVITY_ANALYSIS_RESULT_UUID );
308
308
} else {
309
- LOGGER .error ("Unhandled method+path: " + request .getMethod () + " " + request .getPath ());
309
+ LOGGER .error ("Unhandled method+path: {} {}" , request .getMethod (), request .getPath ());
310
310
return new MockResponse .Builder ().code (418 ).body ("Unhandled method+path: " + request .getMethod () + " " + request .getPath ()).build ();
311
311
}
312
312
}
@@ -374,19 +374,29 @@ private void testSensitivityAnalysisWithRootNetworkUuidAndNodeUuid(final MockWeb
374
374
.language ("en" )
375
375
.build ());
376
376
377
- mockMvc .perform (post ("/v1/studies/{studyUuid}/root-networks/{rootNetworkUuid}/nodes/{nodeUuid}/sensitivity-analysis/result/csv" , studyUuid , rootNetworkUuid , UUID .randomUUID ())
377
+ // error case
378
+ mockMvc .perform (post ("/v1/studies/{studyUuid}/root-networks/{rootNetworkUuid}/nodes/{nodeUuid}/sensitivity-analysis/result/csv?selector=fakeJsonSelector" , studyUuid , rootNetworkUuid , UUID .randomUUID ())
379
+ .contentType (MediaType .APPLICATION_JSON )
380
+ .header ("userId" , "userId" )
381
+ .content (content ))
382
+ .andExpectAll (status ().isNotFound (), content ().string ("\" ROOT_NETWORK_NOT_FOUND\" " ));
383
+
384
+ // csv export with no filter
385
+ mockMvc .perform (post ("/v1/studies/{studyUuid}/root-networks/{rootNetworkUuid}/nodes/{nodeUuid}/sensitivity-analysis/result/csv?selector=fakeJsonSelector" , studyUuid , rootNetworkUuid , nodeUuid )
378
386
.contentType (MediaType .APPLICATION_JSON )
379
387
.header ("userId" , "userId" )
380
388
.content (content ))
381
- .andExpectAll (status ().isNotFound (), content ().string ("\" SENSITIVITY_ANALYSIS_NOT_FOUND\" " ));
389
+ .andExpectAll (status ().isOk (), content ().bytes (SENSITIVITY_RESULTS_AS_ZIPPED_CSV ));
390
+ assertTrue (TestUtils .getRequestsDone (1 , server ).stream ().anyMatch (r -> r .contains ("/v1/results/" + resultUuid + "/csv?selector=fakeJsonSelector" )));
382
391
383
- mockMvc .perform (post ("/v1/studies/{studyUuid}/root-networks/{rootNetworkUuid}/nodes/{nodeUuid}/sensitivity-analysis/result/csv" , studyUuid , rootNetworkUuid , nodeUuid )
392
+ // csv export with filters
393
+ mockMvc .perform (post ("/v1/studies/{studyUuid}/root-networks/{rootNetworkUuid}/nodes/{nodeUuid}/sensitivity-analysis/result/csv?selector=fakeJsonSelector&filters=lineId2&globalFilters=ss" , studyUuid , rootNetworkUuid , nodeUuid )
384
394
.contentType (MediaType .APPLICATION_JSON )
385
395
.header ("userId" , "userId" )
386
396
.content (content ))
387
- .andExpectAll (status ().isOk (), content ().bytes (SENSITIVITY_RESULTS_AS_CSV ));
397
+ .andExpectAll (status ().isOk (), content ().bytes (SENSITIVITY_RESULTS_AS_ZIPPED_CSV ));
398
+ assertTrue (TestUtils .getRequestsDone (1 , server ).stream ().anyMatch (r -> r .contains ("/v1/results/" + resultUuid + "/csv" ) && r .contains ("filters=lineId2" ) && r .contains ("globalFilters=ss" )));
388
399
389
- assertTrue (TestUtils .getRequestsDone (1 , server ).stream ().anyMatch (r -> r .contains ("/v1/results/" + resultUuid + "/csv" )));
390
400
// stop sensitivity analysis
391
401
mockMvc .perform (put ("/v1/studies/{studyUuid}/root-networks/{rootNetworkUuid}/nodes/{nodeUuid}/sensitivity-analysis/stop" , studyUuid , rootNetworkUuid , nodeUuid )
392
402
.header (HEADER_USER_ID , "userId" ))
@@ -395,7 +405,7 @@ private void testSensitivityAnalysisWithRootNetworkUuidAndNodeUuid(final MockWeb
395
405
sensitivityAnalysisStatusMessage = output .receive (TIMEOUT , STUDY_UPDATE_DESTINATION );
396
406
assertEquals (studyUuid , sensitivityAnalysisStatusMessage .getHeaders ().get (NotificationService .HEADER_STUDY_UUID ));
397
407
updateType = (String ) sensitivityAnalysisStatusMessage .getHeaders ().get (HEADER_UPDATE_TYPE );
398
- assertTrue (updateType . equals ( NotificationService .UPDATE_TYPE_SENSITIVITY_ANALYSIS_STATUS ) || updateType . equals ( NotificationService .UPDATE_TYPE_SENSITIVITY_ANALYSIS_RESULT ));
408
+ assertTrue (NotificationService .UPDATE_TYPE_SENSITIVITY_ANALYSIS_STATUS . equals ( updateType ) || NotificationService .UPDATE_TYPE_SENSITIVITY_ANALYSIS_RESULT . equals ( updateType ));
399
409
400
410
assertTrue (TestUtils .getRequestsDone (1 , server ).stream ().anyMatch (r -> r .matches ("/v1/results/" + resultUuid + "/stop\\ ?receiver=.*nodeUuid.*" )));
401
411
}
@@ -542,12 +552,12 @@ void testResetUuidResultWhenSAFailed() throws Exception {
542
552
assertNotNull (rootNetworkNodeInfoService .getComputationResultUuid (modificationNode .getId (), firstRootNetworkUuid , SENSITIVITY_ANALYSIS ));
543
553
assertEquals (resultUuid , rootNetworkNodeInfoService .getComputationResultUuid (modificationNode .getId (), firstRootNetworkUuid , SENSITIVITY_ANALYSIS ));
544
554
545
- StudyService studyService = Mockito .mock (StudyService .class );
555
+ StudyService studyServiceMock = Mockito .mock (StudyService .class );
546
556
doAnswer (invocation -> {
547
557
input .send (MessageBuilder .withPayload ("" ).setHeader (HEADER_RECEIVER , resultUuidJson ).build (), SENSITIVITY_ANALYSIS_FAILED_DESTINATION );
548
558
return resultUuid ;
549
- }).when (studyService ).runSensitivityAnalysis (any (), any (), any (), any ());
550
- studyService .runSensitivityAnalysis (studyEntity .getId (), modificationNode .getId (), firstRootNetworkUuid , "testUserId" );
559
+ }).when (studyServiceMock ).runSensitivityAnalysis (any (), any (), any (), any ());
560
+ studyServiceMock .runSensitivityAnalysis (studyEntity .getId (), modificationNode .getId (), firstRootNetworkUuid , "testUserId" );
551
561
552
562
// Test reset uuid result in the database
553
563
assertNull (rootNetworkNodeInfoService .getComputationResultUuid (modificationNode .getId (), firstRootNetworkUuid , SENSITIVITY_ANALYSIS ));
0 commit comments