use of com.commercetools.project.sync.service.impl.CustomObjectServiceImpl.TIMESTAMP_GENERATOR_KEY in project commercetools-project-sync by commercetools.
the class SyncerFactoryTest method findTimestampGeneratorCustomObjectUpsert.
private static CustomObjectDraft findTimestampGeneratorCustomObjectUpsert(@Nonnull SphereClient client, @Nonnull String syncMethodName, @Nonnull String syncRunnerName) {
// fact: SphereRequest is a very broad interface and we actually wanted to capture only
// CustomObjectUpsertCommand.
// I tried it but argumentcaptor captures also CustomObjectQueryImpl classes, because we call
// both query and upsert in the mocked SphereClient.
// This situation throws runtime NPE error later in the method as query doesnt contain a draft.
// I guess generics doesnt work here as type is not know on compile time.
// That's why we need to filter instanceof CustomObjectUpsertCommand in the streams.
final ArgumentCaptor<SphereRequest> sphereClientArgumentCaptor = ArgumentCaptor.forClass(CustomObjectUpsertCommand.class);
verify(client, atLeast(0)).execute(sphereClientArgumentCaptor.capture());
final List<SphereRequest> allValues = sphereClientArgumentCaptor.getAllValues();
final CustomObjectDraft customObjectDraft = allValues.stream().filter(sphereRequest -> sphereRequest instanceof CustomObjectUpsertCommand).map(sphereRequest -> (CustomObjectUpsertCommand) sphereRequest).map(command -> (CustomObjectDraft) command.getDraft()).filter(draft -> {
return draft.getContainer().equals(format("%s.%s.%s.%s", getApplicationName(), syncRunnerName, syncMethodName, TIMESTAMP_GENERATOR_KEY)) && draft.getKey().equals(TIMESTAMP_GENERATOR_KEY);
}).findAny().orElse(null);
return customObjectDraft;
}
Aggregations