@@ -126,11 +126,17 @@ public class LoadFlowTest {
126
126
127
127
private static final long TIMEOUT = 1000 ;
128
128
129
+ private static final String USER_ID_HEADER = "userId" ;
130
+
131
+ private static final String DEFAULT_PROVIDER = "defaultProvider" ;
132
+ private static final String OTHER_PROVIDER = "otherProvider" ;
133
+
129
134
private static String LIMIT_VIOLATIONS_JSON ;
130
135
131
136
private static String COMPUTING_STATUS_JSON ;
132
137
133
138
private static String LOADFLOW_DEFAULT_PARAMETERS_JSON ;
139
+ private static String LOADFLOW_PROFILE_PARAMETERS_JSON ;
134
140
135
141
//output destinations
136
142
private final String studyUpdateDestination = "study.update" ;
@@ -224,6 +230,12 @@ public void setup() throws IOException {
224
230
.specificParametersPerProvider (Map .of ())
225
231
.build ();
226
232
LOADFLOW_DEFAULT_PARAMETERS_JSON = objectMapper .writeValueAsString (loadFlowParametersInfos );
233
+ LoadFlowParametersInfos profileLoadFlowParametersInfos = LoadFlowParametersInfos .builder ()
234
+ .provider (OTHER_PROVIDER )
235
+ .commonParameters (LoadFlowParameters .load ())
236
+ .specificParametersPerProvider (Map .of ())
237
+ .build ();
238
+ LOADFLOW_PROFILE_PARAMETERS_JSON = objectMapper .writeValueAsString (profileLoadFlowParametersInfos );
227
239
228
240
final Dispatcher dispatcher = new Dispatcher () {
229
241
@ SneakyThrows
@@ -314,13 +326,21 @@ public MockResponse dispatch(RecordedRequest request) {
314
326
} else if (path .matches ("/v1/parameters\\ ?duplicateFrom=" + PROFILE_LOADFLOW_INVALID_PARAMETERS_UUID_STRING ) && method .equals ("POST" )) {
315
327
// params duplication request KO
316
328
return new MockResponse ().setResponseCode (404 );
329
+ } else if (path .matches ("/v1/parameters/" + PROFILE_LOADFLOW_INVALID_PARAMETERS_UUID_STRING ) && method .equals ("GET" )) {
330
+ return new MockResponse ().setResponseCode (404 );
317
331
} else if (path .matches ("/v1/parameters\\ ?duplicateFrom=" + PROFILE_LOADFLOW_VALID_PARAMETERS_UUID_STRING ) && method .equals ("POST" )) {
318
332
// params duplication request OK
319
333
return new MockResponse ().setResponseCode (200 ).setBody (DUPLICATED_PARAMS_JSON )
320
334
.addHeader ("Content-Type" , "application/json; charset=utf-8" );
335
+ } else if (path .matches ("/v1/parameters/" + PROFILE_LOADFLOW_VALID_PARAMETERS_UUID_STRING ) && method .equals ("GET" )) {
336
+ // profile params get request OK
337
+ return new MockResponse ().setResponseCode (200 ).setBody (LOADFLOW_PROFILE_PARAMETERS_JSON )
338
+ .addHeader ("Content-Type" , "application/json; charset=utf-8" );
321
339
} else if (path .matches ("/v1/parameters/" + PROFILE_LOADFLOW_DUPLICATED_PARAMETERS_UUID_STRING + "/provider" ) && method .equals ("PATCH" )) {
322
340
// provider update in duplicated params OK
323
341
return new MockResponse ().setResponseCode (200 );
342
+ } else if (path .matches ("/v1/default-provider" )) {
343
+ return new MockResponse ().setResponseCode (200 ).setBody (DEFAULT_PROVIDER );
324
344
} else {
325
345
LOGGER .error ("Unhandled method+path: " + request .getMethod () + " " + request .getPath ());
326
346
return new MockResponse ().setResponseCode (418 ).setBody ("Unhandled method+path: " + request .getMethod () + " " + request .getPath ());
@@ -686,6 +706,48 @@ public void testResetLoadFlowParametersUserHasValidParamsInProfileButNoExistingL
686
706
assertTrue (requests .stream ().anyMatch (r -> r .equals ("/v1/parameters?duplicateFrom=" + PROFILE_LOADFLOW_VALID_PARAMETERS_UUID_STRING ))); // post duplicate ok
687
707
}
688
708
709
+ // the following testGetDefaultProviders tests are related to StudyTest::testGetDefaultProviders but with a user and different profile cases
710
+ @ Test
711
+ public void testGetDefaultProvidersFromProfile () throws Exception {
712
+ mockMvc .perform (get ("/v1/loadflow-default-provider" ).header (USER_ID_HEADER , VALID_PARAMS_IN_PROFILE_USER_ID )).andExpectAll (
713
+ status ().isOk (),
714
+ content ().string (OTHER_PROVIDER ));
715
+ var requests = TestUtils .getRequestsDone (2 , server );
716
+ assertTrue (requests .stream ().anyMatch (r -> r .equals ("/v1/users/" + VALID_PARAMS_IN_PROFILE_USER_ID + "/profile" )));
717
+ assertTrue (requests .stream ().anyMatch (r -> r .equals ("/v1/parameters/" + PROFILE_LOADFLOW_VALID_PARAMETERS_UUID_STRING ))); // GET provider
718
+ }
719
+
720
+ @ Test
721
+ public void testGetDefaultProvidersFromProfileInvalid () throws Exception {
722
+ mockMvc .perform (get ("/v1/loadflow-default-provider" ).header (USER_ID_HEADER , INVALID_PARAMS_IN_PROFILE_USER_ID )).andExpectAll (
723
+ status ().isOk (),
724
+ content ().string (DEFAULT_PROVIDER ));
725
+ var requests = TestUtils .getRequestsDone (3 , server );
726
+ assertTrue (requests .stream ().anyMatch (r -> r .equals ("/v1/users/" + INVALID_PARAMS_IN_PROFILE_USER_ID + "/profile" )));
727
+ assertTrue (requests .stream ().anyMatch (r -> r .equals ("/v1/parameters/" + PROFILE_LOADFLOW_INVALID_PARAMETERS_UUID_STRING ))); // GET provider
728
+ assertTrue (requests .stream ().anyMatch (r -> r .equals ("/v1/default-provider" ))); // GET fallback default provider
729
+ }
730
+
731
+ @ Test
732
+ public void testGetDefaultProvidersWithoutProfile () throws Exception {
733
+ mockMvc .perform (get ("/v1/loadflow-default-provider" ).header (USER_ID_HEADER , NO_PROFILE_USER_ID )).andExpectAll (
734
+ status ().isOk (),
735
+ content ().string (DEFAULT_PROVIDER ));
736
+ var requests = TestUtils .getRequestsDone (2 , server );
737
+ assertTrue (requests .stream ().anyMatch (r -> r .equals ("/v1/users/" + NO_PROFILE_USER_ID + "/profile" )));
738
+ assertTrue (requests .stream ().anyMatch (r -> r .equals ("/v1/default-provider" ))); // GET fallback default provider
739
+ }
740
+
741
+ @ Test
742
+ public void testGetDefaultProvidersWithoutParamInProfile () throws Exception {
743
+ mockMvc .perform (get ("/v1/loadflow-default-provider" ).header (USER_ID_HEADER , NO_PARAMS_IN_PROFILE_USER_ID )).andExpectAll (
744
+ status ().isOk (),
745
+ content ().string (DEFAULT_PROVIDER ));
746
+ var requests = TestUtils .getRequestsDone (2 , server );
747
+ assertTrue (requests .stream ().anyMatch (r -> r .equals ("/v1/users/" + NO_PARAMS_IN_PROFILE_USER_ID + "/profile" )));
748
+ assertTrue (requests .stream ().anyMatch (r -> r .equals ("/v1/default-provider" ))); // GET fallback default provider
749
+ }
750
+
689
751
@ Test
690
752
public void testLoadFlowParameters () throws Exception {
691
753
//insert a study
0 commit comments