@@ -54,6 +54,7 @@ public class ActionsServiceTest {
54
54
private static final String VARIANT_ID = "variant_id" ;
55
55
56
56
private static final String LIST_NAME = "myList" ;
57
+ private static final String LIST_NAME_VARIANT = "myListVariant" ;
57
58
58
59
private static final String VERY_LARGE_LIST_NAME = "veryLargelist" ;
59
60
@@ -92,25 +93,31 @@ private String initMockWebServer() throws IOException {
92
93
String jsonExpected = objectMapper .writeValueAsString (List .of (CONTINGENCY ));
93
94
String veryLargeJsonExpected = objectMapper .writeValueAsString (createVeryLargeList ());
94
95
String jsonVariantExpected = objectMapper .writeValueAsString (List .of (CONTINGENCY_VARIANT ));
96
+ String jsonExpectedForList = objectMapper .writeValueAsString (List .of (CONTINGENCY , CONTINGENCY_VARIANT ));
95
97
96
98
final Dispatcher dispatcher = new Dispatcher () {
97
99
@ NotNull
98
100
@ Override
99
101
public MockResponse dispatch (RecordedRequest request ) {
100
102
String requestPath = Objects .requireNonNull (request .getPath ());
101
- if (requestPath .equals (String .format ("/v1/contingency-lists/contingency-infos/%s/export?networkUuid=%s&variantId=%s" , LIST_NAME , NETWORK_UUID , VARIANT_ID ))) {
103
+
104
+ if (requestPath .equals (String .format ("/v1/contingency-lists/contingency-infos/export?networkUuid=%s&variantId=%s&ids=%s" , NETWORK_UUID , VARIANT_ID , LIST_NAME ))) {
102
105
return new MockResponse ().setResponseCode (HttpStatus .OK .value ())
103
106
.setBody (jsonVariantExpected )
104
107
.addHeader ("Content-Type" , "application/json; charset=utf-8" );
105
- } else if (requestPath .equals (String .format ("/v1/contingency-lists/contingency-infos/%s/ export?networkUuid=%s" , LIST_NAME , NETWORK_UUID ))) {
108
+ } else if (requestPath .equals (String .format ("/v1/contingency-lists/contingency-infos/export?networkUuid=%s&ids=%s " , NETWORK_UUID , LIST_NAME ))) {
106
109
return new MockResponse ().setResponseCode (HttpStatus .OK .value ())
107
110
.setBody (jsonExpected )
108
111
.addHeader ("Content-Type" , "application/json; charset=utf-8" );
109
- } else if (requestPath .equals (String .format ("/v1/contingency-lists/contingency-infos/%s/ export?networkUuid=%s&variantId=%s" , VERY_LARGE_LIST_NAME , NETWORK_UUID , VARIANT_ID ))
110
- || requestPath .equals (String .format ("/v1/contingency-lists/contingency-infos/%s/ export?networkUuid=%s" , VERY_LARGE_LIST_NAME , NETWORK_UUID ))) {
112
+ } else if (requestPath .equals (String .format ("/v1/contingency-lists/contingency-infos/export?networkUuid=%s&variantId=%s&ids=%s " , NETWORK_UUID , VARIANT_ID , VERY_LARGE_LIST_NAME ))
113
+ || requestPath .equals (String .format ("/v1/contingency-lists/contingency-infos/export?networkUuid=%s&ids=%s " , NETWORK_UUID , VERY_LARGE_LIST_NAME ))) {
111
114
return new MockResponse ().setResponseCode (HttpStatus .OK .value ())
112
115
.setBody (veryLargeJsonExpected )
113
116
.addHeader ("Content-Type" , "application/json; charset=utf-8" );
117
+ } else if (requestPath .equals (String .format ("/v1/contingency-lists/contingency-infos/export?networkUuid=%s&ids=%s&ids=%s" , NETWORK_UUID , LIST_NAME , LIST_NAME_VARIANT ))) {
118
+ return new MockResponse ().setResponseCode (HttpStatus .OK .value ())
119
+ .setBody (jsonExpectedForList )
120
+ .addHeader ("Content-Type" , "application/json; charset=utf-8" );
114
121
} else {
115
122
return new MockResponse ().setResponseCode (HttpStatus .NOT_FOUND .value ()).setBody ("Path not supported: " + request .getPath ());
116
123
}
@@ -131,20 +138,26 @@ private List<ContingencyInfos> createVeryLargeList() {
131
138
132
139
@ Test
133
140
public void test () {
134
- List <ContingencyInfos > list = actionsService .getContingencyList (LIST_NAME , UUID .fromString (NETWORK_UUID ), null );
141
+ List <ContingencyInfos > list = actionsService .getContingencyList (List . of ( LIST_NAME ) , UUID .fromString (NETWORK_UUID ), null );
135
142
list .forEach (contingencyInfos -> assertArrayEquals (List .of (WRONG_ID ).toArray (new Object [0 ]), contingencyInfos .getNotFoundElements ().toArray (new String [0 ])));
136
143
assertEquals (Stream .of (CONTINGENCY ).map (ContingencyInfos ::getContingency ).toList (), list .stream ().map (ContingencyInfos ::getContingency ).collect (Collectors .toList ()));
137
- list = actionsService .getContingencyList (LIST_NAME , UUID .fromString (NETWORK_UUID ), VARIANT_ID );
144
+ list = actionsService .getContingencyList (List . of ( LIST_NAME ) , UUID .fromString (NETWORK_UUID ), VARIANT_ID );
138
145
assertEquals (Stream .of (CONTINGENCY_VARIANT ).map (ContingencyInfos ::getContingency ).toList (), list .stream ().map (ContingencyInfos ::getContingency ).collect (Collectors .toList ()));
139
146
}
140
147
141
148
@ Test
142
149
public void testVeryLargeList () {
143
150
// DataBufferLimitException should not be thrown with this message : "Exceeded limit on max bytes to buffer : DATA_BUFFER_LIMIT"
144
- List <ContingencyInfos > list = actionsService .getContingencyList (VERY_LARGE_LIST_NAME , UUID .fromString (NETWORK_UUID ), null );
151
+ List <ContingencyInfos > list = actionsService .getContingencyList (List . of ( VERY_LARGE_LIST_NAME ) , UUID .fromString (NETWORK_UUID ), null );
145
152
list .forEach (contingencyInfos -> assertArrayEquals (List .of ().toArray (new Object [0 ]), contingencyInfos .getNotFoundElements ().toArray (new String [0 ])));
146
153
assertEquals (createVeryLargeList ().stream ().map (ContingencyInfos ::getContingency ).collect (Collectors .toList ()), list .stream ().map (ContingencyInfos ::getContingency ).collect (Collectors .toList ()));
147
- list = actionsService .getContingencyList (VERY_LARGE_LIST_NAME , UUID .fromString (NETWORK_UUID ), VARIANT_ID );
154
+ list = actionsService .getContingencyList (List . of ( VERY_LARGE_LIST_NAME ) , UUID .fromString (NETWORK_UUID ), VARIANT_ID );
148
155
assertEquals (createVeryLargeList ().stream ().map (ContingencyInfos ::getContingency ).collect (Collectors .toList ()), list .stream ().map (ContingencyInfos ::getContingency ).collect (Collectors .toList ()));
149
156
}
157
+
158
+ @ Test
159
+ public void testGetContingenciesByListOfIds () {
160
+ List <ContingencyInfos > list = actionsService .getContingencyList (List .of (LIST_NAME , LIST_NAME_VARIANT ), UUID .fromString (NETWORK_UUID ), null );
161
+ assertEquals (Stream .of (CONTINGENCY , CONTINGENCY_VARIANT ).map (ContingencyInfos ::getContingency ).toList (), list .stream ().map (ContingencyInfos ::getContingency ).collect (Collectors .toList ()));
162
+ }
150
163
}
0 commit comments