Search in sources :

Example 6 with LastSyncCustomObject

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!");
}
Also used : CustomObjectService(com.commercetools.project.sync.service.CustomObjectService) CustomObject(io.sphere.sdk.customobjects.CustomObject) LastSyncCustomObject(com.commercetools.project.sync.model.response.LastSyncCustomObject) Optional(java.util.Optional) LastSyncCustomObject(com.commercetools.project.sync.model.response.LastSyncCustomObject) BadGatewayException(io.sphere.sdk.client.BadGatewayException) CustomObjectQuery(io.sphere.sdk.customobjects.queries.CustomObjectQuery) Test(org.junit.jupiter.api.Test)

Example 7 with LastSyncCustomObject

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);
}
Also used : CustomObjectUpsertCommand(io.sphere.sdk.customobjects.commands.CustomObjectUpsertCommand) InventoryEntryQuery(io.sphere.sdk.inventory.queries.InventoryEntryQuery) TestUtils.mockLastSyncCustomObject(com.commercetools.project.sync.util.TestUtils.mockLastSyncCustomObject) LastSyncCustomObject(com.commercetools.project.sync.model.response.LastSyncCustomObject) SphereClient(io.sphere.sdk.client.SphereClient) BadGatewayException(io.sphere.sdk.client.BadGatewayException) ExecutionException(java.util.concurrent.ExecutionException) CustomObjectQuery(io.sphere.sdk.customobjects.queries.CustomObjectQuery) Test(org.junit.jupiter.api.Test)

Aggregations

LastSyncCustomObject (com.commercetools.project.sync.model.response.LastSyncCustomObject)7 Test (org.junit.jupiter.api.Test)6 CustomObjectService (com.commercetools.project.sync.service.CustomObjectService)5 CustomObject (io.sphere.sdk.customobjects.CustomObject)4 CustomObjectQuery (io.sphere.sdk.customobjects.queries.CustomObjectQuery)4 ProductSyncStatistics (com.commercetools.sync.products.helpers.ProductSyncStatistics)3 BadGatewayException (io.sphere.sdk.client.BadGatewayException)3 CustomObjectUpsertCommand (io.sphere.sdk.customobjects.commands.CustomObjectUpsertCommand)3 Optional (java.util.Optional)3 TestUtils.mockLastSyncCustomObject (com.commercetools.project.sync.util.TestUtils.mockLastSyncCustomObject)1 SphereClient (io.sphere.sdk.client.SphereClient)1 InventoryEntryQuery (io.sphere.sdk.inventory.queries.InventoryEntryQuery)1 ExecutionException (java.util.concurrent.ExecutionException)1 Nonnull (javax.annotation.Nonnull)1