Skip to content

Commit

Permalink
Cleanup: Remove all occurences of 'sphere'
Browse files Browse the repository at this point in the history
  • Loading branch information
salander85 committed Nov 13, 2023
1 parent 526b5e8 commit f1d786e
Show file tree
Hide file tree
Showing 26 changed files with 78 additions and 94 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ private static Channel createChannelIfNotAlreadyExisting(
/**
* Tries to fetch channel of key {@code channelKey} using {@code ctpClient}.
*
* @param ctpClient sphere client used to execute requests
* @param ctpClient client used to execute requests
* @param channelKey key of requested channel
* @return {@link java.util.Optional} which may contain channel of key {@code channelKey}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ public static CustomFieldsDraft getMockCustomFieldsDraft() {
* Tries to fetch inventory entry of {@code sku} and {@code supplyChannel} using {@code
* ctpClient}.
*
* @param ctpClient sphere client used to execute requests
* @param ctpClient client used to execute requests
* @param sku sku of requested inventory entry
* @param supplyChannel optional reference to supply channel of requested inventory entry
* @param expand
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ private static boolean productTypeExists(
/**
* Tries to fetch product type of {@code key} using {@code cptClient}.
*
* @param cptClient sphere client used to execute requests.
* @param cptClient client used to execute requests.
* @param key key of requested product type.
* @return {@link java.util.Optional} which may contain product type of {@code key}.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ void fetchMatchingCartDiscountsByKeys_WithAnyExistingKeys_ShouldReturnASetOfCart

@Test
void fetchMatchingCartDiscountsByKeys_WithBadGateWayExceptionAlways_ShouldFail() {
// Mock sphere client to return BadGatewayException on any request.
// Mock client to return BadGatewayException on any request.
final ProjectApiRoot spyClient = spy(CTP_TARGET_CLIENT);
final ByProjectKeyCartDiscountsRequestBuilder byProjectKeyCartDiscountsRequestBuilder = mock();
when(spyClient.cartDiscounts()).thenReturn(byProjectKeyCartDiscountsRequestBuilder);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ void fetchMatchingCategoriesByKeys_WithAllExistingSetOfKeys_ShouldReturnSetOfCat

@Test
void fetchMatchingCategoriesByKeys_WithBadGateWayExceptionAlways_ShouldFail() {
// Mock sphere client to return BadGatewayException on any request.
// Mock client to return BadGatewayException on any request.

final ProjectApiRoot spyClient = spy(CTP_TARGET_CLIENT);
when(spyClient.categories()).thenReturn(mock(ByProjectKeyCategoriesRequestBuilder.class));
Expand Down Expand Up @@ -547,10 +547,10 @@ void updateCategory_WithInvalidChanges_ShouldNotUpdateCategory() {
final List<DuplicateFieldError> fieldErrors =
badRequestException.getErrorResponse().getErrors().stream()
.map(
sphereError -> {
assertThat(sphereError.getCode())
error -> {
assertThat(error.getCode())
.isEqualTo(DuplicateFieldError.DUPLICATE_FIELD);
return (DuplicateFieldError) sphereError;
return (DuplicateFieldError) error;
})
.collect(toList());
assertThat(fieldErrors).hasSize(1);
Expand Down Expand Up @@ -602,7 +602,7 @@ void fetchCategory_WithNullKey_ShouldNotFetchCategory() {

@Test
void fetchCategory_WithBadGateWayExceptionAlways_ShouldFail() {
// Mock sphere client to return BadGatewayException on any request.
// Mock client to return BadGatewayException on any request.
final ProjectApiRoot spyClient = spy(CTP_TARGET_CLIENT);
when(spyClient.categories()).thenReturn(mock(ByProjectKeyCategoriesRequestBuilder.class));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ void fetchMatchingCustomObjects_WithNonExistingKeysAndContainers_ShouldReturnEmp

@Test
void fetchMatchingCustomObjectsByCompositeIdentifiers_WithBadGateWayExceptionAlways_ShouldFail() {
// Mock sphere client to return BadGatewayException on any request.
// Mock client to return BadGatewayException on any request.
final ProjectApiRoot spyClient = Mockito.spy(TestClientUtils.CTP_TARGET_CLIENT);
when(spyClient.customObjects()).thenReturn(mock(ByProjectKeyCustomObjectsRequestBuilder.class));
final ByProjectKeyCustomObjectsGet getMock = mock(ByProjectKeyCustomObjectsGet.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ void fetchMatchingProductTypesByKeys_WithAnyExistingKeys_ShouldReturnASetOfProdu

@Test
void fetchMatchingProductTypesByKeys_WithBadGateWayExceptionAlways_ShouldFail() {
// Mock sphere client to return BadGatewayException on any request.
// Mock client to return BadGatewayException on any request.

final ProjectApiRoot spyClient = spy(CTP_TARGET_CLIENT);
when(spyClient.productTypes()).thenReturn(mock(ByProjectKeyProductTypesRequestBuilder.class));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,7 @@ void fetchMatchingStatesByKeys_WithAnyExistingKeys_ShouldReturnASetOfStates() {

@Test
void fetchMatchingStatesByKeys_WithBadGateWayExceptionAlways_ShouldFail() {
// Mock sphere client to return BadGatewayException on any request.

// Mock client to return BadGatewayException on any request.
final ProjectApiRoot spyClient = spy(CTP_TARGET_CLIENT);
when(spyClient.states()).thenReturn(mock(ByProjectKeyStatesRequestBuilder.class));
final ByProjectKeyStatesGet getMock = mock(ByProjectKeyStatesGet.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ void fetchMatchingTaxCategoriesByKeys_WithAnyExistingKeys_ShouldReturnASetOfTaxC

@Test
void fetchMatchingTaxCategoriesByKeys_WithBadGateWayExceptionAlways_ShouldFail() {
// Mock sphere client to return BadGatewayException on any request.
// Mock client to return BadGatewayException on any request.
final ProjectApiRoot spyClient = spy(CTP_TARGET_CLIENT);
when(spyClient.taxCategories()).thenReturn(mock(ByProjectKeyTaxCategoriesRequestBuilder.class));
final ByProjectKeyTaxCategoriesGet getMock = mock(ByProjectKeyTaxCategoriesGet.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ void fetchMatchingTypesByKeys_WithAnyExistingKeys_ShouldReturnASetOfTypes() {

@Test
void fetchMatchingTypesByKeys_WithBadGateWayExceptionAlways_ShouldFail() {
// Mock sphere client to return BadGatewayException on any request.
// Mock client to return BadGatewayException on any request.
final ProjectApiRoot spyClient = Mockito.spy(TestClientUtils.CTP_TARGET_CLIENT);
when(spyClient.types()).thenReturn(mock(ByProjectKeyTypesRequestBuilder.class));
final ByProjectKeyTypesGet getMock = mock(ByProjectKeyTypesGet.class);
Expand Down
2 changes: 1 addition & 1 deletion src/integration-test/resources/it.properties.skeleton
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# rename to it.properties and fill the values to run the integration tests locally without env variables
# see SphereClientUtils for more info
# see TestClientUtils for more info

source.projectKey=<<create your project for local IT>>
source.clientId=YOUR client id without quotes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,20 +303,20 @@ private CompletionStage<Void> updateCartDiscount(
.handle(ImmutablePair::new)
.thenCompose(
updateResponse -> {
final Throwable sphereException = updateResponse.getValue();
if (sphereException != null) {
final Throwable throwable = updateResponse.getValue();
if (throwable != null) {
return executeSupplierIfConcurrentModificationException(
sphereException,
throwable,
() -> fetchAndUpdate(oldCartDiscount, newCartDiscount),
() -> {
final String errorMessage =
format(
CTP_CART_DISCOUNT_UPDATE_FAILED,
newCartDiscount.getKey(),
sphereException.getMessage());
throwable.getMessage());
handleError(
errorMessage,
sphereException,
throwable,
oldCartDiscount,
newCartDiscount,
updateActions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,14 +209,13 @@ private CompletionStage<Optional<CustomObject>> applyCallbackAndCreate(
return customObjectOptional;
})
.exceptionally(
sphereException -> {
throwable -> {
final String errorMessage =
format(
CTP_CUSTOM_OBJECT_CREATE_FAILED,
CustomObjectCompositeIdentifier.of(customObjectDraft).toString(),
sphereException.getMessage());
handleError(
errorMessage, sphereException, null, customObjectDraft, null, 1);
throwable.getMessage());
handleError(errorMessage, throwable, null, customObjectDraft, null, 1);
return Optional.empty();
}))
.orElse(completedFuture(Optional.empty()));
Expand Down Expand Up @@ -250,24 +249,19 @@ private CompletionStage<Optional<CustomObject>> updateCustomObject(
updatedResponseEntry -> {
final Optional<CustomObject> updateCustomObjectOptional =
updatedResponseEntry.getKey();
final Throwable sphereException = updatedResponseEntry.getValue();
if (sphereException != null) {
final Throwable throwable = updatedResponseEntry.getValue();
if (throwable != null) {
return executeSupplierIfConcurrentModificationException(
sphereException,
throwable,
() -> fetchAndUpdate(oldCustomObject, newCustomObject),
() -> {
final String errorMessage =
format(
CTP_CUSTOM_OBJECT_UPDATE_FAILED,
CustomObjectCompositeIdentifier.of(newCustomObject).toString(),
sphereException.getMessage());
throwable.getMessage());
handleError(
errorMessage,
sphereException,
oldCustomObject,
newCustomObject,
null,
1);
errorMessage, throwable, oldCustomObject, newCustomObject, null, 1);
return CompletableFuture.completedFuture(Optional.empty());
});
} else {
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/com/commercetools/sync/products/ProductSync.java
Original file line number Diff line number Diff line change
Expand Up @@ -463,16 +463,16 @@ private CompletionStage<Void> updateProduct(
.handle(ImmutablePair::new)
.thenCompose(
updateResponse -> {
final Throwable sphereException = updateResponse.getValue();
if (sphereException != null) {
final Throwable throwable = updateResponse.getValue();
if (throwable != null) {
return executeSupplierIfConcurrentModificationException(
sphereException,
throwable,
() -> fetchAndUpdate(oldProduct, newProduct),
() -> {
final String productKey = oldProduct.getKey();
handleProductSyncError(
format(UPDATE_FAILED, productKey, sphereException),
sphereException,
format(UPDATE_FAILED, productKey, throwable),
throwable,
oldProduct,
newProduct,
updateActions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -490,10 +490,10 @@ private CompletionStage<Void> resolveMissingNestedReferences(
.handle(ImmutablePair::new)
.thenCompose(
updateResponse -> {
final Throwable sphereException = updateResponse.getValue();
if (sphereException != null) {
final Throwable throwable = updateResponse.getValue();
if (throwable != null) {
return executeSupplierIfConcurrentModificationException(
sphereException,
throwable,
() ->
fetchAndUpdate(
oldProductType,
Expand All @@ -504,8 +504,8 @@ private CompletionStage<Void> resolveMissingNestedReferences(
format(
CTP_PRODUCT_TYPE_UPDATE_FAILED,
oldProductType.getKey(),
sphereException.getMessage());
handleError(errorMessage, sphereException, null, null, null, 1);
throwable.getMessage());
handleError(errorMessage, throwable, null, null, null, 1);
return CompletableFuture.completedFuture(null);
});
} else {
Expand Down Expand Up @@ -591,10 +591,10 @@ private CompletionStage<Void> updateProductType(
.handle(ImmutablePair::new)
.thenCompose(
updateResponse -> {
final Throwable sphereException = updateResponse.getValue();
if (sphereException != null) {
final Throwable throwable = updateResponse.getValue();
if (throwable != null) {
return executeSupplierIfConcurrentModificationException(
sphereException,
throwable,
() ->
fetchAndUpdate(
oldProductType,
Expand All @@ -605,10 +605,10 @@ private CompletionStage<Void> updateProductType(
format(
CTP_PRODUCT_TYPE_UPDATE_FAILED,
newProductType.getKey(),
sphereException.getMessage());
throwable.getMessage());
handleError(
errorMessage,
sphereException,
throwable,
oldProductType,
newProductType,
updateActions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public interface ChannelService {
* Creates a new channel with the supplied {@code key}.
*
* @param key key of supply channel.
* @return a future containing as a result the created {@link Channel} or a sphere exception.
* @return a future containing as a result the created {@link Channel} or empty optional.
*/
@Nonnull
CompletionStage<Optional<Channel>> createChannel(@Nonnull final String key);
Expand All @@ -56,7 +56,7 @@ public interface ChannelService {
* a cache map.
*
* @param key key of supply channel.
* @return a future containing as a result the created {@link Channel} or a sphere exception.
* @return a future containing as a result the created {@link Channel} or empty optional.
*/
@Nonnull
CompletionStage<Optional<Channel>> createAndCacheChannel(@Nonnull final String key);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,11 +219,11 @@ void sync_WithErrorOnFetchingUnresolvableCategory_ShouldNotCreateCategory() {

when(mockCategoryService.fetchCachedCategoryId(Mockito.eq("root")))
.thenReturn(completedFuture(Optional.of("rootID")));
final CompletableFuture<Set<WaitingToBeResolvedCategories>> futureThrowingSphereException =
final CompletableFuture<Set<WaitingToBeResolvedCategories>> futureThrowingException =
new CompletableFuture<>();
futureThrowingSphereException.completeExceptionally(new RuntimeException("CTP error on fetch"));
futureThrowingException.completeExceptionally(new RuntimeException("CTP error on fetch"));
when(mockUnresolvedReferencesService.fetch(any(), any(), any()))
.thenReturn(futureThrowingSphereException);
.thenReturn(futureThrowingException);
final CategorySync mockCategorySync =
new CategorySync(
categorySyncOptions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,9 @@ void resolveAssetsReferences_WithAssetReferences_ShouldResolveAssets() {
@Test
void resolveParentReference_WithExceptionOnFetch_ShouldNotResolveReferences() {
// Preparation
final CompletableFuture<Optional<String>> futureThrowingSphereException =
new CompletableFuture<>();
futureThrowingSphereException.completeExceptionally(new RuntimeException("CTP error on fetch"));
when(categoryService.fetchCachedCategoryId(any())).thenReturn(futureThrowingSphereException);
final CompletableFuture<Optional<String>> futureThrowingException = new CompletableFuture<>();
futureThrowingException.completeExceptionally(new RuntimeException("CTP error on fetch"));
when(categoryService.fetchCachedCategoryId(any())).thenReturn(futureThrowingException);

final CategoryDraftBuilder categoryDraft =
CategorySyncMockUtils.getMockCategoryDraftBuilder(
Expand Down Expand Up @@ -295,10 +294,9 @@ void resolveParentReference_WithNonNullKeyOnParentResId_ShouldResolveParentRefer
@Test
void resolveCustomTypeReference_WithExceptionOnCustomTypeFetch_ShouldNotResolveReferences() {
// Preparation
final CompletableFuture<Optional<String>> futureThrowingSphereException =
new CompletableFuture<>();
futureThrowingSphereException.completeExceptionally(new RuntimeException("CTP error on fetch"));
when(typeService.fetchCachedTypeId(any())).thenReturn(futureThrowingSphereException);
final CompletableFuture<Optional<String>> futureThrowingException = new CompletableFuture<>();
futureThrowingException.completeExceptionally(new RuntimeException("CTP error on fetch"));
when(typeService.fetchCachedTypeId(any())).thenReturn(futureThrowingException);

final CategoryDraftBuilder categoryDraft =
CategorySyncMockUtils.getMockCategoryDraftBuilder(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,11 +310,10 @@ void resolveCustomerGroupReference_WithExceptionOnCustomerGroupFetch_ShouldNotRe
.customerGroup(CustomerGroupResourceIdentifierBuilder.of().key("anyKey").build())
.key("dummyKey");

final CompletableFuture<Optional<String>> futureThrowingSphereException =
new CompletableFuture<>();
futureThrowingSphereException.completeExceptionally(new RuntimeException("CTP error on fetch"));
final CompletableFuture<Optional<String>> futureThrowingException = new CompletableFuture<>();
futureThrowingException.completeExceptionally(new RuntimeException("CTP error on fetch"));
when(customerGroupService.fetchCachedCustomerGroupId(anyString()))
.thenReturn(futureThrowingSphereException);
.thenReturn(futureThrowingException);

assertThat(referenceResolver.resolveCustomerGroupReference(customerDraftBuilder))
.failsWithin(1, TimeUnit.SECONDS)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,12 +185,11 @@ void resolveCustomerGroupReference_WithExceptionOnFetch_ShouldNotResolveReferenc
.build())
.customerGroup(customerGroupResourceIdentifier);

final CompletableFuture<Optional<String>> futureThrowingSphereException =
new CompletableFuture<>();
futureThrowingSphereException.completeExceptionally(
final CompletableFuture<Optional<String>> futureThrowingException = new CompletableFuture<>();
futureThrowingException.completeExceptionally(
new ReferenceResolutionException("CTP error on fetch"));
when(customerGroupService.fetchCachedCustomerGroupId(anyString()))
.thenReturn(futureThrowingSphereException);
.thenReturn(futureThrowingException);

assertThat(referenceResolver.resolveCustomerGroupReference(priceBuilder).toCompletableFuture())
.failsWithin(1, TimeUnit.SECONDS)
Expand Down
Loading

0 comments on commit f1d786e

Please sign in to comment.