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());
}
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));
}
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);
}
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;
}
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!");
}
Aggregations