use of com.commercetools.sync.integration.commons.utils.StateITUtils.STATE_KEY_1 in project commercetools-sync-java by commercetools.
the class StateServiceImplIT method createState_WithValidState_ShouldCreateStateAndCacheId.
@Test
void createState_WithValidState_ShouldCreateStateAndCacheId() {
final StateDraft newStateDraft = StateDraftBuilder.of(STATE_KEY_1, STATE_TYPE).name(STATE_NAME_1).description(STATE_DESCRIPTION_1).build();
final SphereClient spyClient = spy(CTP_TARGET_CLIENT);
final StateSyncOptions spyOptions = StateSyncOptionsBuilder.of(spyClient).errorCallback((exception, oldResource, newResource, updateActions) -> {
errorCallBackMessages.add(exception.getMessage());
errorCallBackExceptions.add(exception.getCause());
}).build();
final StateService spyStateService = new StateServiceImpl(spyOptions);
// test
final Optional<State> createdState = spyStateService.createState(newStateDraft).toCompletableFuture().join();
final Optional<State> queriedOptional = CTP_TARGET_CLIENT.execute(StateQuery.of().withPredicates(stateQueryModel -> stateQueryModel.key().is(STATE_KEY_1))).toCompletableFuture().join().head();
assertThat(queriedOptional).hasValueSatisfying(queried -> assertThat(createdState).hasValueSatisfying(created -> {
assertThat(created.getKey()).isEqualTo(queried.getKey());
assertThat(created.getDescription()).isEqualTo(queried.getDescription());
assertThat(created.getName()).isEqualTo(queried.getName());
}));
// Assert that the created state is cached
final Optional<String> stateId = spyStateService.fetchCachedStateId(STATE_KEY_1).toCompletableFuture().join();
assertThat(stateId).isPresent();
verify(spyClient, times(0)).execute(any(StateQuery.class));
}
Aggregations