15
15
import static java .util .stream .Collectors .toList ;
16
16
import static java .util .stream .Collectors .toMap ;
17
17
import static org .folio .HttpStatus .HTTP_CREATED ;
18
+ import static org .folio .rest .jaxrs .model .Request .Status .CLOSED_CANCELLED ;
19
+ import static org .folio .rest .jaxrs .model .Request .Status .CLOSED_FILLED ;
20
+ import static org .folio .rest .jaxrs .model .Request .Status .CLOSED_PICKUP_EXPIRED ;
21
+ import static org .folio .rest .jaxrs .model .Request .Status .CLOSED_UNFILLED ;
18
22
19
23
import java .io .InputStream ;
20
24
import java .nio .charset .StandardCharsets ;
27
31
import java .util .Objects ;
28
32
import java .util .UUID ;
29
33
import java .util .concurrent .CompletableFuture ;
34
+ import java .util .stream .Stream ;
30
35
import java .util .stream .StreamSupport ;
31
36
32
37
import org .apache .commons .io .IOUtils ;
33
38
import org .folio .postgres .testing .PostgresTesterContainer ;
34
39
import org .folio .rest .RestVerticle ;
35
40
import org .folio .rest .client .TenantClient ;
36
41
import org .folio .rest .jaxrs .model .Parameter ;
42
+ import org .folio .rest .jaxrs .model .Request ;
37
43
import org .folio .rest .jaxrs .model .TenantAttributes ;
38
44
import org .folio .rest .jaxrs .model .TenantJob ;
39
45
import org .folio .rest .persist .PostgresClient ;
65
71
public class TenantRefApiTests {
66
72
protected static final String OLD_MODULE_VERSION = "13.0.0" ;
67
73
protected static final String PREVIOUS_MODULE_VERSION = "13.1.0" ;
68
- protected static final String MIGRATION_MODULE_VERSION = "13.2 .0" ;
69
- protected static final String NEXT_MODULE_VERSION = "13.4 .0" ;
74
+ protected static final String TLR_MIGRATION_MODULE_VERSION = "14.0 .0" ;
75
+ protected static final String NEXT_MODULE_VERSION = "14.1 .0" ;
70
76
protected static final String MODULE_NAME = "mod_circulation_storage" ;
71
77
protected static final int PORT = NetworkUtils .nextFreePort ();
72
78
protected static final String URL = "http://localhost:" + PORT ;
@@ -169,7 +175,7 @@ public void migrationShouldBeSkippedWhenUpgradingToLowerVersion(final TestContex
169
175
public void migrationShouldBeSkippedWhenUpgradingFromAlreadyMigratedVersion (final TestContext context ) {
170
176
Async async = context .async ();
171
177
172
- postTenant (context , MIGRATION_MODULE_VERSION , NEXT_MODULE_VERSION )
178
+ postTenant (context , TLR_MIGRATION_MODULE_VERSION , NEXT_MODULE_VERSION )
173
179
.onSuccess (job -> {
174
180
assertThatNoRequestsWereUpdated (context );
175
181
async .complete ();
@@ -180,7 +186,7 @@ public void migrationShouldBeSkippedWhenUpgradingFromAlreadyMigratedVersion(fina
180
186
public void jobCompletedWhenMigrationIsSuccessful (TestContext context ) {
181
187
Async async = context .async ();
182
188
183
- postTenant (context , PREVIOUS_MODULE_VERSION , MIGRATION_MODULE_VERSION )
189
+ postTenant (context , PREVIOUS_MODULE_VERSION , TLR_MIGRATION_MODULE_VERSION )
184
190
.onSuccess (job -> {
185
191
context .assertNull (job .getError ());
186
192
validateMigrationResult (context , async );
@@ -209,7 +215,7 @@ public void jobFailsWhenItemWasNotFound(final TestContext context) {
209
215
}
210
216
211
217
private void jobFailsWhenRemoteCallFails (TestContext context , Async async ) {
212
- postTenant (context , PREVIOUS_MODULE_VERSION , MIGRATION_MODULE_VERSION )
218
+ postTenant (context , PREVIOUS_MODULE_VERSION , TLR_MIGRATION_MODULE_VERSION )
213
219
.onSuccess (job -> {
214
220
context .assertTrue (job .getError ().contains ("Request failed: GET" ));
215
221
context .assertTrue (job .getError ().contains ("Response: [404]" ));
@@ -231,7 +237,7 @@ public void useDefaultValuesForInstanceIdAndHoldingsRecordIdWhenItemWasNotFound(
231
237
String requestId = getId (randomRequest );
232
238
233
239
postgresClient .update (REQUEST_TABLE_NAME , randomRequest , requestId )
234
- .compose (r -> postTenant (context , PREVIOUS_MODULE_VERSION , MIGRATION_MODULE_VERSION ))
240
+ .compose (r -> postTenant (context , PREVIOUS_MODULE_VERSION , TLR_MIGRATION_MODULE_VERSION ))
235
241
.compose (job -> getRequestAsJson (requestId ))
236
242
.onFailure (context ::fail )
237
243
.onSuccess (updatedRequest -> {
@@ -261,7 +267,7 @@ public void changesMadeForAllBatchesAreRevertedInCaseOfError(TestContext context
261
267
.whenScenarioStateIs (FIRST_CALL_MADE_SCENARIO_STATE )
262
268
.willReturn (serverError ()));
263
269
264
- postTenant (context , PREVIOUS_MODULE_VERSION , MIGRATION_MODULE_VERSION )
270
+ postTenant (context , PREVIOUS_MODULE_VERSION , TLR_MIGRATION_MODULE_VERSION )
265
271
.onSuccess (job -> {
266
272
context .assertFalse (job .getError ().isEmpty ());
267
273
assertThatNoRequestsWereUpdated (context );
@@ -299,11 +305,36 @@ public void jobFailsWhenRequestDoesNotHaveRequiredItemLevelRequestField(TestCont
299
305
"request does not contain required ILR fields: " + getId (randomRequest ));
300
306
}
301
307
308
+ @ Test
309
+ public void migrationRemovesPositionFromClosedRequests (TestContext context ) {
310
+ Async async = context .async ();
311
+
312
+ List <String > closedStatuses = Stream .of (CLOSED_FILLED , CLOSED_UNFILLED , CLOSED_PICKUP_EXPIRED ,
313
+ CLOSED_CANCELLED )
314
+ .map (Request .Status ::value )
315
+ .collect (toList ());
316
+
317
+ postTenant (context , PREVIOUS_MODULE_VERSION , TLR_MIGRATION_MODULE_VERSION )
318
+ .compose (job -> getAllRequestsAsJson ())
319
+ .onFailure (context ::fail )
320
+ .onSuccess (requestsAfterMigration -> {
321
+ requestsAfterMigration .forEach (request -> {
322
+ Integer position = request .getInteger ("position" );
323
+ if (closedStatuses .contains (request .getString ("status" ))) {
324
+ context .assertNull (position );
325
+ } else {
326
+ context .assertNotNull (position );
327
+ }
328
+ async .complete ();
329
+ });
330
+ });
331
+ }
332
+
302
333
private void jobFailsWhenRequestValidationFails (TestContext context , Async async ,
303
334
JsonObject request , String expectedErrorMessage ) {
304
335
305
336
postgresClient .update (REQUEST_TABLE_NAME , request , getId (request ))
306
- .compose (r -> postTenant (context , PREVIOUS_MODULE_VERSION , MIGRATION_MODULE_VERSION ))
337
+ .compose (r -> postTenant (context , PREVIOUS_MODULE_VERSION , TLR_MIGRATION_MODULE_VERSION ))
307
338
.onFailure (context ::fail )
308
339
.onSuccess (job -> {
309
340
context .assertTrue (job .getError ().contains (expectedErrorMessage ));
0 commit comments