use of com.commercetools.sync.integration.commons.utils.TaxCategoryITUtils.TAXCATEGORY_KEY in project commercetools-sync-java by commercetools.
the class TaxCategoryServiceImplIT method fetchMatchingTaxCategoriesByKeys_WithBadGateWayExceptionAlways_ShouldFail.
@Test
void fetchMatchingTaxCategoriesByKeys_WithBadGateWayExceptionAlways_ShouldFail() {
// Mock sphere client to return BadGatewayException on any request.
final SphereClient spyClient = spy(CTP_TARGET_CLIENT);
when(spyClient.execute(any(TaxCategoryQuery.class))).thenReturn(CompletableFutureUtils.exceptionallyCompletedFuture(new BadGatewayException())).thenCallRealMethod();
final TaxCategorySyncOptions spyOptions = TaxCategorySyncOptionsBuilder.of(spyClient).errorCallback((exception, oldResource, newResource, updateActions) -> {
errorCallBackMessages.add(exception.getMessage());
errorCallBackExceptions.add(exception.getCause());
}).build();
final TaxCategoryService spyTaxCategoryService = new TaxCategoryServiceImpl(spyOptions);
final Set<String> keys = new HashSet<>();
keys.add(TAXCATEGORY_KEY);
// test and assert
assertThat(errorCallBackExceptions).isEmpty();
assertThat(errorCallBackMessages).isEmpty();
assertThat(spyTaxCategoryService.fetchMatchingTaxCategoriesByKeys(keys)).failsWithin(10, TimeUnit.SECONDS).withThrowableOfType(ExecutionException.class).withCauseExactlyInstanceOf(BadGatewayException.class);
}
use of com.commercetools.sync.integration.commons.utils.TaxCategoryITUtils.TAXCATEGORY_KEY in project commercetools-sync-java by commercetools.
the class TaxCategoryServiceImplIT method createTaxCategory_WithDuplicateKey_ShouldHaveEmptyOptionalAsAResult.
@Test
void createTaxCategory_WithDuplicateKey_ShouldHaveEmptyOptionalAsAResult() {
// preparation
final TaxCategoryDraft newTaxCategoryDraft = TaxCategoryDraftBuilder.of(TAXCATEGORY_NAME_1, singletonList(createTaxRateDraft()), TAXCATEGORY_DESCRIPTION_1).key(TAXCATEGORY_KEY).build();
final TaxCategorySyncOptions options = TaxCategorySyncOptionsBuilder.of(CTP_TARGET_CLIENT).errorCallback((exception, oldResource, newResource, updateActions) -> {
errorCallBackMessages.add(exception.getMessage());
errorCallBackExceptions.add(exception.getCause());
}).build();
final TaxCategoryService taxCategoryService = new TaxCategoryServiceImpl(options);
// test
final Optional<TaxCategory> result = taxCategoryService.createTaxCategory(newTaxCategoryDraft).toCompletableFuture().join();
// assertion
assertThat(result).isEmpty();
assertThat(errorCallBackMessages).hasSize(1).singleElement(as(STRING)).contains("A duplicate value");
assertThat(errorCallBackExceptions).hasSize(1).singleElement().matches(exception -> {
assertThat(exception).isExactlyInstanceOf(ErrorResponseException.class);
final ErrorResponseException errorResponseException = (ErrorResponseException) exception;
final List<DuplicateFieldError> fieldErrors = errorResponseException.getErrors().stream().map(sphereError -> {
assertThat(sphereError.getCode()).isEqualTo(DuplicateFieldError.CODE);
return sphereError.as(DuplicateFieldError.class);
}).collect(toList());
return fieldErrors.size() == 1;
});
}
Aggregations