Search in sources :

Example 1 with LastSyncCustomObject

use of com.commercetools.project.sync.model.response.LastSyncCustomObject in project commercetools-project-sync by commercetools.

the class CustomObjectServiceImplTest method getLastSyncCustomObject_OnSuccessfulQueryWithNoResults_ShouldCompleteWithEmptyOptional.

@Test
@SuppressWarnings("unchecked")
void getLastSyncCustomObject_OnSuccessfulQueryWithNoResults_ShouldCompleteWithEmptyOptional() {
    // preparation
    final PagedQueryResult<CustomObject<LastSyncCustomObject>> queriedCustomObjects = PagedQueryResult.empty();
    when(CLIENT.execute(any(CustomObjectQuery.class))).thenReturn(CompletableFuture.completedFuture(queriedCustomObjects));
    final CustomObjectService customObjectService = new CustomObjectServiceImpl(CLIENT);
    // test
    final CompletionStage<Optional<CustomObject<LastSyncCustomObject>>> lastSyncCustomObject = customObjectService.getLastSyncCustomObject("foo", "bar", DEFAULT_RUNNER_NAME);
    // assertions
    assertThat(lastSyncCustomObject).isCompletedWithValue(empty());
}
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) CustomObjectQuery(io.sphere.sdk.customobjects.queries.CustomObjectQuery) Test(org.junit.jupiter.api.Test)

Example 2 with LastSyncCustomObject

use of com.commercetools.project.sync.model.response.LastSyncCustomObject in project commercetools-project-sync by commercetools.

the class CustomObjectServiceImplTest method getLastSyncCustomObject_OnSuccessfulQueryWithResults_ShouldCompleteWithLastSyncCustomObject.

@Test
@SuppressWarnings("unchecked")
void getLastSyncCustomObject_OnSuccessfulQueryWithResults_ShouldCompleteWithLastSyncCustomObject() {
    // 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(CompletableFuture.completedFuture(queriedCustomObjects));
    final CustomObjectService customObjectService = new CustomObjectServiceImpl(CLIENT);
    // test
    final CompletionStage<Optional<CustomObject<LastSyncCustomObject>>> lastSyncCustomObject = customObjectService.getLastSyncCustomObject("foo", "bar", DEFAULT_RUNNER_NAME);
    // assertions
    assertThat(lastSyncCustomObject).isCompletedWithValue(Optional.of(LAST_SYNC_CUSTOM_OBJECT));
}
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) CustomObjectQuery(io.sphere.sdk.customobjects.queries.CustomObjectQuery) Test(org.junit.jupiter.api.Test)

Example 3 with LastSyncCustomObject

use of com.commercetools.project.sync.model.response.LastSyncCustomObject in project commercetools-project-sync by commercetools.

the class CustomObjectServiceImplTest method createLastSyncCustomObject_OnSuccessfulCreation_ShouldCompleteWithLastSyncCustomObject.

@Test
@SuppressWarnings("unchecked")
void createLastSyncCustomObject_OnSuccessfulCreation_ShouldCompleteWithLastSyncCustomObject() {
    // preparation
    when(CLIENT.execute(any(CustomObjectUpsertCommand.class))).thenReturn(CompletableFuture.completedFuture(LAST_SYNC_CUSTOM_OBJECT));
    final CustomObjectService customObjectService = new CustomObjectServiceImpl(CLIENT);
    // test
    final LastSyncCustomObject<ProductSyncStatistics> lastSyncCustomObject = LastSyncCustomObject.of(ZonedDateTime.now(), new ProductSyncStatistics(), 100);
    final CustomObject<LastSyncCustomObject> createdCustomObject = customObjectService.createLastSyncCustomObject("foo", "bar", DEFAULT_RUNNER_NAME, lastSyncCustomObject).toCompletableFuture().join();
    // assertions
    assertThat(createdCustomObject).isEqualTo(LAST_SYNC_CUSTOM_OBJECT);
}
Also used : ProductSyncStatistics(com.commercetools.sync.products.helpers.ProductSyncStatistics) CustomObjectUpsertCommand(io.sphere.sdk.customobjects.commands.CustomObjectUpsertCommand) CustomObjectService(com.commercetools.project.sync.service.CustomObjectService) LastSyncCustomObject(com.commercetools.project.sync.model.response.LastSyncCustomObject) Test(org.junit.jupiter.api.Test)

Example 4 with LastSyncCustomObject

use of com.commercetools.project.sync.model.response.LastSyncCustomObject in project commercetools-project-sync by commercetools.

the class TestUtils method mockLastSyncCustomObject.

@Nonnull
@SuppressWarnings("unchecked")
public static CustomObject<LastSyncCustomObject<ProductSyncStatistics>> mockLastSyncCustomObject(@Nonnull ZonedDateTime currentCtpTimestamp) {
    final CustomObject<LastSyncCustomObject<ProductSyncStatistics>> customObject = mock(CustomObject.class);
    final LastSyncCustomObject<ProductSyncStatistics> lastSyncCustomObject = LastSyncCustomObject.of(ZonedDateTime.now(), new ProductSyncStatistics(), 100);
    when(customObject.getLastModifiedAt()).thenReturn(currentCtpTimestamp);
    when(customObject.getValue()).thenReturn(lastSyncCustomObject);
    return customObject;
}
Also used : ProductSyncStatistics(com.commercetools.sync.products.helpers.ProductSyncStatistics) LastSyncCustomObject(com.commercetools.project.sync.model.response.LastSyncCustomObject) Nonnull(javax.annotation.Nonnull)

Example 5 with LastSyncCustomObject

use of com.commercetools.project.sync.model.response.LastSyncCustomObject in project commercetools-project-sync by commercetools.

the class CustomObjectServiceImplTest method createLastSyncCustomObject_OnFailedCreation_ShouldCompleteExceptionally.

@Test
@SuppressWarnings("unchecked")
void createLastSyncCustomObject_OnFailedCreation_ShouldCompleteExceptionally() {
    // preparation
    when(CLIENT.execute(any(CustomObjectUpsertCommand.class))).thenReturn(CompletableFutureUtils.exceptionallyCompletedFuture(new BadGatewayException("CTP error!")));
    final CustomObjectService customObjectService = new CustomObjectServiceImpl(CLIENT);
    // test
    final LastSyncCustomObject<ProductSyncStatistics> lastSyncCustomObject = LastSyncCustomObject.of(ZonedDateTime.now(), new ProductSyncStatistics(), 100);
    final CompletionStage<CustomObject<LastSyncCustomObject>> createdCustomObject = customObjectService.createLastSyncCustomObject("foo", "bar", DEFAULT_RUNNER_NAME, lastSyncCustomObject);
    // assertions
    assertThat(createdCustomObject).hasFailedWithThrowableThat().isInstanceOf(BadGatewayException.class).hasMessageContaining("CTP error!");
}
Also used : ProductSyncStatistics(com.commercetools.sync.products.helpers.ProductSyncStatistics) CustomObjectUpsertCommand(io.sphere.sdk.customobjects.commands.CustomObjectUpsertCommand) CustomObjectService(com.commercetools.project.sync.service.CustomObjectService) CustomObject(io.sphere.sdk.customobjects.CustomObject) LastSyncCustomObject(com.commercetools.project.sync.model.response.LastSyncCustomObject) BadGatewayException(io.sphere.sdk.client.BadGatewayException) 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