|
20 | 20 | import org.datatransferproject.spi.cloud.storage.TemporaryPerJobDataStore; |
21 | 21 | import org.datatransferproject.spi.transfer.idempotentexecutor.InMemoryIdempotentImportExecutor; |
22 | 22 | import org.datatransferproject.spi.transfer.types.DestinationMemoryFullException; |
| 23 | +import org.datatransferproject.spi.transfer.types.SessionInvalidatedException; |
23 | 24 | import org.datatransferproject.transfer.JobMetadata; |
24 | 25 | import org.datatransferproject.types.common.models.IdOnlyContainerResource; |
25 | 26 | import org.datatransferproject.types.transfer.auth.AppCredentials; |
@@ -277,7 +278,7 @@ public void testGenericImporterBadRequest() throws Exception { |
277 | 278 | assertEquals("itemId", error.title()); |
278 | 279 | assertContains("(400) bad_request", error.exception()); |
279 | 280 | } |
280 | | - |
| 281 | + |
281 | 282 | @Test |
282 | 283 | public void testGenericImporterUnexpectedResponse() throws Exception { |
283 | 284 | InMemoryIdempotentImportExecutor executor = new InMemoryIdempotentImportExecutor(monitor); |
@@ -426,4 +427,30 @@ public void testGenericImporterPassingJobMetadataRecurringJob() throws Exception |
426 | 427 | assertTrue(executor.getErrors().isEmpty()); |
427 | 428 | } |
428 | 429 |
|
| 430 | + @Test |
| 431 | + public void testSessionInvalidatedException() throws Exception { |
| 432 | + InMemoryIdempotentImportExecutor executor = new InMemoryIdempotentImportExecutor(monitor); |
| 433 | + GenericImporter<IdOnlyContainerResource, String> importer = |
| 434 | + getImporter( |
| 435 | + importerClass, |
| 436 | + container -> |
| 437 | + List.of( |
| 438 | + new ImportableData<>( |
| 439 | + new GenericPayload<>(container.getId(), "schemasource"), |
| 440 | + container.getId(), |
| 441 | + container.getId()))); |
| 442 | + webServer.enqueue(new MockResponse() |
| 443 | + .setResponseCode(401) |
| 444 | + .setBody("{\"error\":\"invalid_token\"}")); |
| 445 | + webServer.enqueue(new MockResponse().setResponseCode(401).setBody("{\"error\":\"session_invalidated\"}")); |
| 446 | + |
| 447 | + assertThrows(SessionInvalidatedException.class, () -> { |
| 448 | + importer.importItem( |
| 449 | + UUID.randomUUID(), |
| 450 | + executor, |
| 451 | + new TokensAndUrlAuthData( |
| 452 | + "accessToken", "refreshToken", webServer.url("/refresh").toString()), |
| 453 | + new IdOnlyContainerResource("itemId")); |
| 454 | + }); |
| 455 | + } |
429 | 456 | } |
0 commit comments