Search in sources :

Example 1 with TIMESTAMP_GENERATOR_KEY

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;
}
Also used : CustomObjectQuery(io.sphere.sdk.customobjects.queries.CustomObjectQuery) ProductProjectionQuery(io.sphere.sdk.products.queries.ProductProjectionQuery) BeforeEach(org.junit.jupiter.api.BeforeEach) STAGED(io.sphere.sdk.products.ProductProjectionType.STAGED) TestLoggerFactory(uk.org.lidalia.slf4jtest.TestLoggerFactory) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ZonedDateTime(java.time.ZonedDateTime) DEFAULT_RUNNER_NAME(com.commercetools.project.sync.util.SyncUtils.DEFAULT_RUNNER_NAME) MockPagedQueryResult(com.commercetools.project.sync.util.MockPagedQueryResult) TestUtils.assertCategorySyncerLoggingEvents(com.commercetools.project.sync.util.TestUtils.assertCategorySyncerLoggingEvents) TestUtils.assertInventoryEntrySyncerLoggingEvents(com.commercetools.project.sync.util.TestUtils.assertInventoryEntrySyncerLoggingEvents) ShoppingListQuery(io.sphere.sdk.shoppinglists.queries.ShoppingListQuery) CartDiscountQuery(io.sphere.sdk.cartdiscounts.queries.CartDiscountQuery) CategoryQuery(io.sphere.sdk.categories.queries.CategoryQuery) CustomerQuery(io.sphere.sdk.customers.queries.CustomerQuery) Collections.singleton(java.util.Collections.singleton) ResourceKeyId(com.commercetools.sync.commons.models.ResourceKeyId) Arrays.asList(java.util.Arrays.asList) TestLogger(uk.org.lidalia.slf4jtest.TestLogger) TypeSyncer(com.commercetools.project.sync.type.TypeSyncer) Mockito.atLeast(org.mockito.Mockito.atLeast) SphereClient(io.sphere.sdk.client.SphereClient) ProductTypeSyncer(com.commercetools.project.sync.producttype.ProductTypeSyncer) ProductProjection(io.sphere.sdk.products.ProductProjection) SphereRequest(io.sphere.sdk.client.SphereRequest) BadGatewayException(io.sphere.sdk.client.BadGatewayException) ProductTypeQuery(io.sphere.sdk.producttypes.queries.ProductTypeQuery) TIMESTAMP_GENERATOR_KEY(com.commercetools.project.sync.service.impl.CustomObjectServiceImpl.TIMESTAMP_GENERATOR_KEY) TestUtils.assertProductSyncerLoggingEvents(com.commercetools.project.sync.util.TestUtils.assertProductSyncerLoggingEvents) ResourceKeyIdGraphQlRequest(com.commercetools.sync.commons.helpers.ResourceKeyIdGraphQlRequest) Collections.emptyList(java.util.Collections.emptyList) TestUtils.verifyInteractionsWithClientAfterSync(com.commercetools.project.sync.util.TestUtils.verifyInteractionsWithClientAfterSync) SyncUtils.getApplicationName(com.commercetools.project.sync.util.SyncUtils.getApplicationName) Product(io.sphere.sdk.products.Product) CategorySyncer(com.commercetools.project.sync.category.CategorySyncer) InventoryEntrySyncer(com.commercetools.project.sync.inventoryentry.InventoryEntrySyncer) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) CustomObjectUpsertCommand(io.sphere.sdk.customobjects.commands.CustomObjectUpsertCommand) TestUtils.assertTypeSyncerLoggingEvents(com.commercetools.project.sync.util.TestUtils.assertTypeSyncerLoggingEvents) Test(org.junit.jupiter.api.Test) List(java.util.List) ProductSyncStatistics(com.commercetools.sync.products.helpers.ProductSyncStatistics) CompletionStage(java.util.concurrent.CompletionStage) CartDiscountSyncer(com.commercetools.project.sync.cartdiscount.CartDiscountSyncer) StateSyncer(com.commercetools.project.sync.state.StateSyncer) ProductCreateCommand(io.sphere.sdk.products.commands.ProductCreateCommand) TestUtils.assertCartDiscountSyncerLoggingEvents(com.commercetools.project.sync.util.TestUtils.assertCartDiscountSyncerLoggingEvents) TestUtils.assertStateSyncerLoggingEvents(com.commercetools.project.sync.util.TestUtils.assertStateSyncerLoggingEvents) Mockito.mock(org.mockito.Mockito.mock) SYNC_MODULE_OPTION_DESCRIPTION(com.commercetools.project.sync.CliRunner.SYNC_MODULE_OPTION_DESCRIPTION) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) IntStream(java.util.stream.IntStream) TestUtils.stubClientsCustomObjectService(com.commercetools.project.sync.util.TestUtils.stubClientsCustomObjectService) CliException(com.commercetools.project.sync.exception.CliException) StateQuery(io.sphere.sdk.states.queries.StateQuery) Level(uk.org.lidalia.slf4jext.Level) CustomObject(io.sphere.sdk.customobjects.CustomObject) SphereJsonUtils(io.sphere.sdk.json.SphereJsonUtils) TaxCategoryQuery(io.sphere.sdk.taxcategories.queries.TaxCategoryQuery) CompletableFuture(java.util.concurrent.CompletableFuture) CustomerSyncer(com.commercetools.project.sync.customer.CustomerSyncer) CompletableFutureUtils(io.sphere.sdk.utils.CompletableFutureUtils) ArgumentCaptor(org.mockito.ArgumentCaptor) TestUtils.mockLastSyncCustomObject(com.commercetools.project.sync.util.TestUtils.mockLastSyncCustomObject) TestUtils.assertTaxCategorySyncerLoggingEvents(com.commercetools.project.sync.util.TestUtils.assertTaxCategorySyncerLoggingEvents) TypeQuery(io.sphere.sdk.types.queries.TypeQuery) InventoryEntryQuery(io.sphere.sdk.inventory.queries.InventoryEntryQuery) Nonnull(javax.annotation.Nonnull) LoggingEvent(uk.org.lidalia.slf4jtest.LoggingEvent) TestUtils.getMockedClock(com.commercetools.project.sync.util.TestUtils.getMockedClock) ResourceIdsGraphQlRequest(com.commercetools.sync.commons.models.ResourceIdsGraphQlRequest) TestUtils.assertProductTypeSyncerLoggingEvents(com.commercetools.project.sync.util.TestUtils.assertProductTypeSyncerLoggingEvents) CustomObjectSyncer(com.commercetools.project.sync.customobject.CustomObjectSyncer) InOrder(org.mockito.InOrder) TestUtils.assertCustomerSyncerLoggingEvents(com.commercetools.project.sync.util.TestUtils.assertCustomerSyncerLoggingEvents) CustomObjectDraft(io.sphere.sdk.customobjects.CustomObjectDraft) ResourceKeyIdGraphQlResult(com.commercetools.sync.commons.models.ResourceKeyIdGraphQlResult) QueryPredicate(io.sphere.sdk.queries.QueryPredicate) ProductSyncer(com.commercetools.project.sync.product.ProductSyncer) Mockito.times(org.mockito.Mockito.times) Mockito.when(org.mockito.Mockito.when) TestUtils.assertCustomObjectSyncerLoggingEvents(com.commercetools.project.sync.util.TestUtils.assertCustomObjectSyncerLoggingEvents) Mockito.verify(org.mockito.Mockito.verify) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) Mockito(org.mockito.Mockito) ShoppingListSyncer(com.commercetools.project.sync.shoppinglist.ShoppingListSyncer) SphereClientConfig(io.sphere.sdk.client.SphereClientConfig) PagedQueryResult(io.sphere.sdk.queries.PagedQueryResult) LastSyncCustomObject(com.commercetools.project.sync.model.response.LastSyncCustomObject) Condition(org.assertj.core.api.Condition) TestUtils.assertShoppingListSyncerLoggingEvents(com.commercetools.project.sync.util.TestUtils.assertShoppingListSyncerLoggingEvents) TaxCategorySyncer(com.commercetools.project.sync.taxcategory.TaxCategorySyncer) ReferenceTransformException(com.commercetools.sync.commons.exceptions.ReferenceTransformException) CustomObjectUpsertCommand(io.sphere.sdk.customobjects.commands.CustomObjectUpsertCommand) SphereRequest(io.sphere.sdk.client.SphereRequest) CustomObjectDraft(io.sphere.sdk.customobjects.CustomObjectDraft)

Aggregations

SYNC_MODULE_OPTION_DESCRIPTION (com.commercetools.project.sync.CliRunner.SYNC_MODULE_OPTION_DESCRIPTION)1 CartDiscountSyncer (com.commercetools.project.sync.cartdiscount.CartDiscountSyncer)1 CategorySyncer (com.commercetools.project.sync.category.CategorySyncer)1 CustomerSyncer (com.commercetools.project.sync.customer.CustomerSyncer)1 CustomObjectSyncer (com.commercetools.project.sync.customobject.CustomObjectSyncer)1 CliException (com.commercetools.project.sync.exception.CliException)1 InventoryEntrySyncer (com.commercetools.project.sync.inventoryentry.InventoryEntrySyncer)1 LastSyncCustomObject (com.commercetools.project.sync.model.response.LastSyncCustomObject)1 ProductSyncer (com.commercetools.project.sync.product.ProductSyncer)1 ProductTypeSyncer (com.commercetools.project.sync.producttype.ProductTypeSyncer)1 TIMESTAMP_GENERATOR_KEY (com.commercetools.project.sync.service.impl.CustomObjectServiceImpl.TIMESTAMP_GENERATOR_KEY)1 ShoppingListSyncer (com.commercetools.project.sync.shoppinglist.ShoppingListSyncer)1 StateSyncer (com.commercetools.project.sync.state.StateSyncer)1 TaxCategorySyncer (com.commercetools.project.sync.taxcategory.TaxCategorySyncer)1 TypeSyncer (com.commercetools.project.sync.type.TypeSyncer)1 MockPagedQueryResult (com.commercetools.project.sync.util.MockPagedQueryResult)1 DEFAULT_RUNNER_NAME (com.commercetools.project.sync.util.SyncUtils.DEFAULT_RUNNER_NAME)1 SyncUtils.getApplicationName (com.commercetools.project.sync.util.SyncUtils.getApplicationName)1 TestUtils.assertCartDiscountSyncerLoggingEvents (com.commercetools.project.sync.util.TestUtils.assertCartDiscountSyncerLoggingEvents)1 TestUtils.assertCategorySyncerLoggingEvents (com.commercetools.project.sync.util.TestUtils.assertCategorySyncerLoggingEvents)1