Search in sources :

Example 1 with ProductSyncStatistics

use of com.commercetools.sync.products.helpers.ProductSyncStatistics in project commercetools-project-sync by commercetools.

the class LastSyncCustomObjectTest method equals_WithUnequalDurations_ShouldReturnFalse.

@Test
void equals_WithUnequalDurations_ShouldReturnFalse() {
    // preparation
    final ZonedDateTime lastSyncTimestamp = ZonedDateTime.now();
    final int lastSyncDurationInSeconds = 100;
    final ProductSyncStatistics lastSyncStatistics = new ProductSyncStatistics();
    final LastSyncCustomObject<ProductSyncStatistics> lastSyncCustomObject = LastSyncCustomObject.of(lastSyncTimestamp, lastSyncStatistics, lastSyncDurationInSeconds);
    final LastSyncCustomObject<ProductSyncStatistics> otherLastSyncCustomObject = LastSyncCustomObject.of(lastSyncTimestamp, lastSyncStatistics, 90);
    // test
    final boolean result = lastSyncCustomObject.equals(otherLastSyncCustomObject);
    // assertions
    assertThat(result).isFalse();
}
Also used : ProductSyncStatistics(com.commercetools.sync.products.helpers.ProductSyncStatistics) ZonedDateTime(java.time.ZonedDateTime) Test(org.junit.jupiter.api.Test)

Example 2 with ProductSyncStatistics

use of com.commercetools.sync.products.helpers.ProductSyncStatistics in project commercetools-project-sync by commercetools.

the class CustomObjectServiceImplTest method createLastSyncCustomObject_WithValidTestRunnerName_ShouldCreateCorrectCustomObjectDraft.

@Test
@SuppressWarnings("unchecked")
void createLastSyncCustomObject_WithValidTestRunnerName_ShouldCreateCorrectCustomObjectDraft() {
    // preparation
    final SphereClient client = mock(SphereClient.class);
    final ArgumentCaptor<CustomObjectUpsertCommand> arg = ArgumentCaptor.forClass(CustomObjectUpsertCommand.class);
    when(client.execute(arg.capture())).thenReturn(null);
    final CustomObjectService customObjectService = new CustomObjectServiceImpl(client);
    final LastSyncCustomObject<ProductSyncStatistics> lastSyncCustomObject = LastSyncCustomObject.of(ZonedDateTime.now(), new ProductSyncStatistics(), 100);
    // test
    customObjectService.createLastSyncCustomObject("foo", "bar", "testRunnerName", lastSyncCustomObject);
    // assertions
    final CustomObjectDraft createdDraft = (CustomObjectDraft) arg.getValue().getDraft();
    assertThat(createdDraft.getContainer()).isEqualTo("commercetools-project-sync.testRunnerName.bar");
    assertThat(createdDraft.getKey()).isEqualTo("foo");
}
Also used : ProductSyncStatistics(com.commercetools.sync.products.helpers.ProductSyncStatistics) CustomObjectUpsertCommand(io.sphere.sdk.customobjects.commands.CustomObjectUpsertCommand) CustomObjectService(com.commercetools.project.sync.service.CustomObjectService) SphereClient(io.sphere.sdk.client.SphereClient) CustomObjectDraft(io.sphere.sdk.customobjects.CustomObjectDraft) Test(org.junit.jupiter.api.Test)

Example 3 with ProductSyncStatistics

use of com.commercetools.sync.products.helpers.ProductSyncStatistics in project commercetools-project-sync by commercetools.

the class CustomObjectServiceImplTest method createLastSyncCustomObject_WithNullRunnerName_ShouldCreateCorrectCustomObjectDraft.

@Test
@SuppressWarnings("unchecked")
void createLastSyncCustomObject_WithNullRunnerName_ShouldCreateCorrectCustomObjectDraft() {
    // preparation
    final SphereClient client = mock(SphereClient.class);
    final ArgumentCaptor<CustomObjectUpsertCommand> arg = ArgumentCaptor.forClass(CustomObjectUpsertCommand.class);
    when(client.execute(arg.capture())).thenReturn(null);
    final CustomObjectService customObjectService = new CustomObjectServiceImpl(client);
    final LastSyncCustomObject<ProductSyncStatistics> lastSyncCustomObject = LastSyncCustomObject.of(ZonedDateTime.now(), new ProductSyncStatistics(), 100);
    // test
    customObjectService.createLastSyncCustomObject("foo", "bar", null, lastSyncCustomObject);
    // assertions
    final CustomObjectDraft createdDraft = (CustomObjectDraft) arg.getValue().getDraft();
    assertThat(createdDraft.getContainer()).isEqualTo("commercetools-project-sync.runnerName.bar");
    assertThat(createdDraft.getKey()).isEqualTo("foo");
}
Also used : ProductSyncStatistics(com.commercetools.sync.products.helpers.ProductSyncStatistics) CustomObjectUpsertCommand(io.sphere.sdk.customobjects.commands.CustomObjectUpsertCommand) CustomObjectService(com.commercetools.project.sync.service.CustomObjectService) SphereClient(io.sphere.sdk.client.SphereClient) CustomObjectDraft(io.sphere.sdk.customobjects.CustomObjectDraft) Test(org.junit.jupiter.api.Test)

Example 4 with ProductSyncStatistics

use of com.commercetools.sync.products.helpers.ProductSyncStatistics in project commercetools-project-sync by commercetools.

the class CustomObjectServiceImplTest method createLastSyncCustomObject_OnSuccessfulCreation_ShouldCompleteWithLastSyncCustomObject.

@Test
@SuppressWarnings("unchecked")
void createLastSyncCustomObject_OnSuccessfulCreation_ShouldCompleteWithLastSyncCustomObject() {
    // preparation
    when(CLIENT.execute(any(CustomObjectUpsertCommand.class))).thenReturn(CompletableFuture.completedFuture(LAST_SYNC_CUSTOM_OBJECT));
    final CustomObjectService customObjectService = new CustomObjectServiceImpl(CLIENT);
    // test
    final LastSyncCustomObject<ProductSyncStatistics> lastSyncCustomObject = LastSyncCustomObject.of(ZonedDateTime.now(), new ProductSyncStatistics(), 100);
    final CustomObject<LastSyncCustomObject> createdCustomObject = customObjectService.createLastSyncCustomObject("foo", "bar", DEFAULT_RUNNER_NAME, lastSyncCustomObject).toCompletableFuture().join();
    // assertions
    assertThat(createdCustomObject).isEqualTo(LAST_SYNC_CUSTOM_OBJECT);
}
Also used : ProductSyncStatistics(com.commercetools.sync.products.helpers.ProductSyncStatistics) CustomObjectUpsertCommand(io.sphere.sdk.customobjects.commands.CustomObjectUpsertCommand) CustomObjectService(com.commercetools.project.sync.service.CustomObjectService) LastSyncCustomObject(com.commercetools.project.sync.model.response.LastSyncCustomObject) Test(org.junit.jupiter.api.Test)

Example 5 with ProductSyncStatistics

use of com.commercetools.sync.products.helpers.ProductSyncStatistics in project commercetools-project-sync by commercetools.

the class CustomObjectServiceImplTest method createLastSyncCustomObject_WithEmptyRunnerName_ShouldCreateCorrectCustomObjectDraft.

@Test
@SuppressWarnings("unchecked")
void createLastSyncCustomObject_WithEmptyRunnerName_ShouldCreateCorrectCustomObjectDraft() {
    // preparation
    final SphereClient client = mock(SphereClient.class);
    final ArgumentCaptor<CustomObjectUpsertCommand> arg = ArgumentCaptor.forClass(CustomObjectUpsertCommand.class);
    when(client.execute(arg.capture())).thenReturn(null);
    final CustomObjectService customObjectService = new CustomObjectServiceImpl(client);
    final LastSyncCustomObject<ProductSyncStatistics> lastSyncCustomObject = LastSyncCustomObject.of(ZonedDateTime.now(), new ProductSyncStatistics(), 100);
    // test
    customObjectService.createLastSyncCustomObject("foo", "bar", "", lastSyncCustomObject);
    // assertions
    final CustomObjectDraft createdDraft = (CustomObjectDraft) arg.getValue().getDraft();
    assertThat(createdDraft.getContainer()).isEqualTo("commercetools-project-sync.runnerName.bar");
    assertThat(createdDraft.getKey()).isEqualTo("foo");
}
Also used : ProductSyncStatistics(com.commercetools.sync.products.helpers.ProductSyncStatistics) CustomObjectUpsertCommand(io.sphere.sdk.customobjects.commands.CustomObjectUpsertCommand) CustomObjectService(com.commercetools.project.sync.service.CustomObjectService) SphereClient(io.sphere.sdk.client.SphereClient) CustomObjectDraft(io.sphere.sdk.customobjects.CustomObjectDraft) Test(org.junit.jupiter.api.Test)

Aggregations

ProductSyncStatistics (com.commercetools.sync.products.helpers.ProductSyncStatistics)136 Test (org.junit.jupiter.api.Test)135 ProductDraft (io.sphere.sdk.products.ProductDraft)117 ProductSync (com.commercetools.sync.products.ProductSync)87 Product (io.sphere.sdk.products.Product)65 AttributeDraft (io.sphere.sdk.products.attributes.AttributeDraft)65 ProductProjection (io.sphere.sdk.products.ProductProjection)62 ProductVariantDraft (io.sphere.sdk.products.ProductVariantDraft)61 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)41 Attribute (io.sphere.sdk.products.attributes.Attribute)41 ArrayList (java.util.ArrayList)41 AssertionsForStatistics.assertThat (com.commercetools.sync.commons.asserts.statistics.AssertionsForStatistics.assertThat)35 ProductSyncOptions (com.commercetools.sync.products.ProductSyncOptions)35 ProductDraftBuilder (io.sphere.sdk.products.ProductDraftBuilder)35 List (java.util.List)35 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)35 ProductSyncMockUtils.createProductDraft (com.commercetools.sync.products.ProductSyncMockUtils.createProductDraft)34 SetAttribute (io.sphere.sdk.products.commands.updateactions.SetAttribute)33 Collections.singletonList (java.util.Collections.singletonList)33 Optional (java.util.Optional)33