use of com.commercetools.project.sync.model.response.LastSyncCustomObject in project commercetools-project-sync by commercetools.
the class CustomObjectServiceImplTest method getLastSyncCustomObject_OnFailedQuery_ShouldCompleteExceptionally.
@Test
@SuppressWarnings("unchecked")
void getLastSyncCustomObject_OnFailedQuery_ShouldCompleteExceptionally() {
// preparation
final PagedQueryResult<CustomObject<LastSyncCustomObject>> queriedCustomObjects = spy(PagedQueryResult.empty());
when(queriedCustomObjects.getResults()).thenReturn(singletonList(LAST_SYNC_CUSTOM_OBJECT));
when(CLIENT.execute(any(CustomObjectQuery.class))).thenReturn(CompletableFutureUtils.exceptionallyCompletedFuture(new BadGatewayException("CTP error!")));
final CustomObjectService customObjectService = new CustomObjectServiceImpl(CLIENT);
// test
final CompletionStage<Optional<CustomObject<LastSyncCustomObject>>> lastSyncCustomObject = customObjectService.getLastSyncCustomObject("foo", "bar", DEFAULT_RUNNER_NAME);
// assertions
assertThat(lastSyncCustomObject).hasFailedWithThrowableThat().isInstanceOf(BadGatewayException.class).hasMessageContaining("CTP error!");
}
use of com.commercetools.project.sync.model.response.LastSyncCustomObject in project commercetools-project-sync by commercetools.
the class SyncerFactoryTest method sync_WithErrorOnQueryLastSyncTimestamp_ShouldCloseClientAndCompleteExceptionallyWithoutSyncing.
@Test
@SuppressWarnings("unchecked")
void sync_WithErrorOnQueryLastSyncTimestamp_ShouldCloseClientAndCompleteExceptionallyWithoutSyncing() {
// preparation
final SphereClient sourceClient = mock(SphereClient.class);
when(sourceClient.getConfig()).thenReturn(SphereClientConfig.of("foo", "foo", "foo"));
final SphereClient targetClient = mock(SphereClient.class);
when(targetClient.getConfig()).thenReturn(SphereClientConfig.of("bar", "bar", "bar"));
final BadGatewayException badGatewayException = new BadGatewayException();
when(targetClient.execute(any(CustomObjectQuery.class))).thenReturn(CompletableFutureUtils.exceptionallyCompletedFuture(badGatewayException));
final CustomObject<LastSyncCustomObject<ProductSyncStatistics>> lastSyncCustomObjectCustomObject = mockLastSyncCustomObject(ZonedDateTime.now());
when(targetClient.execute(any(CustomObjectUpsertCommand.class))).thenReturn(CompletableFuture.completedFuture(lastSyncCustomObjectCustomObject));
final SyncerFactory syncerFactory = SyncerFactory.of(() -> sourceClient, () -> targetClient, getMockedClock());
// test
final CompletionStage<Void> result = syncerFactory.sync(new String[] { "inventoryEntries" }, "bar", false, false, null);
// assertions
verifyTimestampGeneratorCustomObjectUpsertIsCalled(targetClient, "InventorySync", "bar");
verifyLastSyncCustomObjectQuery(targetClient, "inventorySync", "bar", "foo", 1);
verify(sourceClient, times(0)).execute(any(InventoryEntryQuery.class));
verifyInteractionsWithClientAfterSync(sourceClient, 1);
assertThat(result).failsWithin(1, TimeUnit.SECONDS).withThrowableOfType(ExecutionException.class).withCauseExactlyInstanceOf(BadGatewayException.class);
}
Aggregations