use of com.commercetools.sync.integration.commons.utils.TaxCategoryITUtils.TAXCATEGORY_KEY_1 in project commercetools-sync-java by commercetools.
the class TaxCategoryServiceImplIT method createTaxCategory_WithValidTaxCategory_ShouldCreateTaxCategoryAndCacheId.
@Test
void createTaxCategory_WithValidTaxCategory_ShouldCreateTaxCategoryAndCacheId() {
final TaxCategoryDraft newTaxCategoryDraft = TaxCategoryDraftBuilder.of(TAXCATEGORY_NAME_1, singletonList(createTaxRateDraft()), TAXCATEGORY_DESCRIPTION_1).key(TAXCATEGORY_KEY_1).build();
final SphereClient spyClient = spy(CTP_TARGET_CLIENT);
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);
// test
final Optional<TaxCategory> createdTaxCategory = spyTaxCategoryService.createTaxCategory(newTaxCategoryDraft).toCompletableFuture().join();
final Optional<TaxCategory> queriedOptional = CTP_TARGET_CLIENT.execute(TaxCategoryQuery.of().withPredicates(taxCategoryQueryModel -> taxCategoryQueryModel.key().is(TAXCATEGORY_KEY_1))).toCompletableFuture().join().head();
assertThat(queriedOptional).hasValueSatisfying(queried -> assertThat(createdTaxCategory).hasValueSatisfying(created -> {
assertThat(created.getKey()).isEqualTo(queried.getKey());
assertThat(created.getDescription()).isEqualTo(queried.getDescription());
assertThat(created.getName()).isEqualTo(queried.getName());
}));
// Assert that the created taxCategory is cached
final Optional<String> taxCategoryId = spyTaxCategoryService.fetchCachedTaxCategoryId(TAXCATEGORY_KEY_1).toCompletableFuture().join();
assertThat(taxCategoryId).isPresent();
verify(spyClient, times(0)).execute(any(TaxCategoryQuery.class));
}
Aggregations