use of com.commercetools.sync.integration.commons.utils.TypeITUtils.TYPE_DESCRIPTION_1 in project commercetools-sync-java by commercetools.
the class TypeServiceImplIT method createType_WithValidType_ShouldCreateTypeAndCacheId.
@Test
void createType_WithValidType_ShouldCreateTypeAndCacheId() {
final TypeDraft newTypeDraft = TypeDraftBuilder.of(TYPE_KEY_1, TYPE_NAME_1, ResourceTypeIdsSetBuilder.of().addCategories().build()).description(TYPE_DESCRIPTION_1).fieldDefinitions(singletonList(FIELD_DEFINITION_1)).build();
final SphereClient spyClient = spy(CTP_TARGET_CLIENT);
final TypeSyncOptions spyOptions = TypeSyncOptionsBuilder.of(spyClient).errorCallback((exception, oldResource, newResource, updateActions) -> {
errorCallBackMessages.add(exception.getMessage());
errorCallBackExceptions.add(exception.getCause());
}).build();
final TypeService spyTypeService = new TypeServiceImpl(spyOptions);
// test
final Optional<Type> createdType = spyTypeService.createType(newTypeDraft).toCompletableFuture().join();
final Optional<Type> queriedOptional = CTP_TARGET_CLIENT.execute(TypeQuery.of().withPredicates(typeQueryModel -> typeQueryModel.key().is(TYPE_KEY_1))).toCompletableFuture().join().head();
assertThat(queriedOptional).hasValueSatisfying(queried -> assertThat(createdType).hasValueSatisfying(created -> {
assertThat(created.getKey()).isEqualTo(queried.getKey());
assertThat(created.getDescription()).isEqualTo(queried.getDescription());
assertThat(created.getName()).isEqualTo(queried.getName());
assertThat(created.getFieldDefinitions()).isEqualTo(queried.getFieldDefinitions());
}));
// Assert that the created type is cached
final Optional<String> typeId = spyTypeService.fetchCachedTypeId(TYPE_KEY_1).toCompletableFuture().join();
assertThat(typeId).isPresent();
verify(spyClient, times(0)).execute(any(TypeQuery.class));
}
Aggregations