Skip to content

Commit

Permalink
DEVX-245 fix category syncer IT (#514)
Browse files Browse the repository at this point in the history
* DEVX-245 fix category syncer IT

* DEVX-245 fix formatting
  • Loading branch information
lojzatran authored Oct 31, 2023
1 parent 60ae002 commit a1c830c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.commercetools.project.sync.service.CustomObjectService;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.vrap.rmf.base.client.ApiHttpResponse;
import io.vrap.rmf.base.client.error.NotFoundException;
import io.vrap.rmf.base.client.utils.json.JsonUtils;
import java.time.ZonedDateTime;
import java.util.Optional;
Expand Down Expand Up @@ -75,16 +76,25 @@ public CompletableFuture<Optional<LastSyncCustomObject>> getLastSyncCustomObject
.withContainerAndKey(containerName, sourceProjectKey)
.get()
.execute()
.thenApply(
(customObjectApiHttpResponse) -> {
final CustomObject responseBody = customObjectApiHttpResponse.getBody();
final ObjectMapper objectMapper = JsonUtils.getConfiguredObjectMapper();
final LastSyncCustomObject lastSyncCustomObject =
responseBody == null
? null
: objectMapper.convertValue(
responseBody.getValue(), LastSyncCustomObject.class);
return Optional.ofNullable(lastSyncCustomObject);
.handle(
(customObjectApiHttpResponse, throwable) -> {
if (throwable != null) {
if (throwable.getCause() != null
&& throwable.getCause().getClass().equals(NotFoundException.class)) {
return Optional.empty();
} else {
throw new RuntimeException(throwable);
}
} else {
final CustomObject responseBody = customObjectApiHttpResponse.getBody();
final ObjectMapper objectMapper = JsonUtils.getConfiguredObjectMapper();
final LastSyncCustomObject lastSyncCustomObject =
responseBody == null
? null
: objectMapper.convertValue(
responseBody.getValue(), LastSyncCustomObject.class);
return Optional.ofNullable(lastSyncCustomObject);
}
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1018,7 +1018,12 @@ void sync_WithErrorOnFetch_ShouldCloseClientAndCompleteExceptionally() {
assertThat(result)
.failsWithin(1, TimeUnit.SECONDS)
.withThrowableOfType(ExecutionException.class)
.withCauseExactlyInstanceOf(BadGatewayException.class);
.withCauseExactlyInstanceOf(RuntimeException.class)
.satisfies(
exception ->
assertThat(exception.getCause().getCause())
.isInstanceOf(BadGatewayException.class)
.hasMessageContaining("test"));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,12 @@ void getLastSyncCustomObject_OnFailedQuery_ShouldCompleteExceptionally() {
assertThat(lastSyncCustomObject)
.failsWithin(Duration.ZERO)
.withThrowableOfType(ExecutionException.class)
.withCauseExactlyInstanceOf(BadGatewayException.class)
.withMessageContaining("test");
.withCauseExactlyInstanceOf(RuntimeException.class)
.satisfies(
exception ->
assertThat(exception.getCause().getCause())
.isInstanceOf(BadGatewayException.class)
.hasMessageContaining("test"));
}

@Test
Expand Down

0 comments on commit a1c830c

Please sign in to comment.