Search in sources :

Example 16 with TypeSyncStatistics

use of com.commercetools.sync.types.helpers.TypeSyncStatistics in project commercetools-sync-java by commercetools.

the class TypeSyncIT method sync_WithUpdatedType_ShouldUpdateType.

@Test
void sync_WithUpdatedType_ShouldUpdateType() {
    // preparation
    final Optional<Type> oldTypeBefore = getTypeByKey(CTP_TARGET_CLIENT, TYPE_KEY_1);
    assertThat(oldTypeBefore).isNotEmpty();
    final TypeDraft newTypeDraft = TypeDraftBuilder.of(TYPE_KEY_1, TYPE_NAME_2, ResourceTypeIdsSetBuilder.of().addCategories().build()).description(TYPE_DESCRIPTION_2).fieldDefinitions(singletonList(FIELD_DEFINITION_1)).build();
    final TypeSyncOptions typeSyncOptions = TypeSyncOptionsBuilder.of(CTP_TARGET_CLIENT).build();
    final TypeSync typeSync = new TypeSync(typeSyncOptions);
    // test
    final TypeSyncStatistics typeSyncStatistics = typeSync.sync(singletonList(newTypeDraft)).toCompletableFuture().join();
    // assertions
    assertThat(typeSyncStatistics).hasValues(1, 0, 1, 0);
    final Optional<Type> oldTypeAfter = getTypeByKey(CTP_TARGET_CLIENT, TYPE_KEY_1);
    assertThat(oldTypeAfter).isNotEmpty();
    assertThat(oldTypeAfter).hasValueSatisfying(type -> {
        assertThat(type.getName()).isEqualTo(TYPE_NAME_2);
        assertThat(type.getDescription()).isEqualTo(TYPE_DESCRIPTION_2);
        assertFieldDefinitionsAreEqual(type.getFieldDefinitions(), singletonList(FIELD_DEFINITION_1));
    });
}
Also used : LocalizedEnumFieldType(io.sphere.sdk.types.LocalizedEnumFieldType) StringFieldType(io.sphere.sdk.types.StringFieldType) EnumFieldType(io.sphere.sdk.types.EnumFieldType) SetFieldType(io.sphere.sdk.types.SetFieldType) Type(io.sphere.sdk.types.Type) TypeSyncOptions(com.commercetools.sync.types.TypeSyncOptions) TypeSyncStatistics(com.commercetools.sync.types.helpers.TypeSyncStatistics) TypeDraft(io.sphere.sdk.types.TypeDraft) TypeSync(com.commercetools.sync.types.TypeSync) Test(org.junit.jupiter.api.Test)

Example 17 with TypeSyncStatistics

use of com.commercetools.sync.types.helpers.TypeSyncStatistics in project commercetools-sync-java by commercetools.

the class TypeSyncIT method sync_WithUpdatedType_WithoutOldFieldDefinition_ShouldUpdateTypeRemovingFieldDefinition.

@Test
void sync_WithUpdatedType_WithoutOldFieldDefinition_ShouldUpdateTypeRemovingFieldDefinition() {
    final Optional<Type> oldTypeBefore = getTypeByKey(CTP_TARGET_CLIENT, TYPE_KEY_1);
    assertThat(oldTypeBefore).isNotEmpty();
    final TypeDraft newTypeDraft = TypeDraftBuilder.of(TYPE_KEY_1, TYPE_NAME_1, ResourceTypeIdsSetBuilder.of().addCategories().build()).description(TYPE_DESCRIPTION_1).fieldDefinitions(singletonList(FIELD_DEFINITION_1)).build();
    final TypeSyncOptions typeSyncOptions = TypeSyncOptionsBuilder.of(CTP_TARGET_CLIENT).build();
    final TypeSync typeSync = new TypeSync(typeSyncOptions);
    final TypeSyncStatistics typeSyncStatistics = typeSync.sync(singletonList(newTypeDraft)).toCompletableFuture().join();
    assertThat(typeSyncStatistics).hasValues(1, 0, 1, 0);
    final Optional<Type> oldTypeAfter = getTypeByKey(CTP_TARGET_CLIENT, TYPE_KEY_1);
    assertThat(oldTypeAfter).hasValueSatisfying(type -> assertFieldDefinitionsAreEqual(type.getFieldDefinitions(), singletonList(FIELD_DEFINITION_1)));
}
Also used : LocalizedEnumFieldType(io.sphere.sdk.types.LocalizedEnumFieldType) StringFieldType(io.sphere.sdk.types.StringFieldType) EnumFieldType(io.sphere.sdk.types.EnumFieldType) SetFieldType(io.sphere.sdk.types.SetFieldType) Type(io.sphere.sdk.types.Type) TypeSyncOptions(com.commercetools.sync.types.TypeSyncOptions) TypeSyncStatistics(com.commercetools.sync.types.helpers.TypeSyncStatistics) TypeDraft(io.sphere.sdk.types.TypeDraft) TypeSync(com.commercetools.sync.types.TypeSync) Test(org.junit.jupiter.api.Test)

Example 18 with TypeSyncStatistics

use of com.commercetools.sync.types.helpers.TypeSyncStatistics in project commercetools-sync-java by commercetools.

the class TypeSyncIT method sync_WithNewType_ShouldCreateType.

@Test
void sync_WithNewType_ShouldCreateType() {
    // preparation
    final TypeDraft newTypeDraft = TypeDraftBuilder.of(TYPE_KEY_2, TYPE_NAME_2, ResourceTypeIdsSetBuilder.of().addCategories().build()).description(TYPE_DESCRIPTION_2).fieldDefinitions(singletonList(FIELD_DEFINITION_1)).build();
    final TypeSyncOptions typeSyncOptions = TypeSyncOptionsBuilder.of(CTP_TARGET_CLIENT).build();
    final TypeSync typeSync = new TypeSync(typeSyncOptions);
    // test
    final TypeSyncStatistics typeSyncStatistics = typeSync.sync(singletonList(newTypeDraft)).toCompletableFuture().join();
    // assertions
    assertThat(typeSyncStatistics).hasValues(1, 1, 0, 0);
    final Optional<Type> oldTypeAfter = getTypeByKey(CTP_TARGET_CLIENT, TYPE_KEY_2);
    assertThat(oldTypeAfter).isNotEmpty();
    assertThat(oldTypeAfter).hasValueSatisfying(type -> {
        assertThat(type.getName()).isEqualTo(TYPE_NAME_2);
        assertThat(type.getDescription()).isEqualTo(TYPE_DESCRIPTION_2);
        assertFieldDefinitionsAreEqual(type.getFieldDefinitions(), singletonList(FIELD_DEFINITION_1));
    });
}
Also used : LocalizedEnumFieldType(io.sphere.sdk.types.LocalizedEnumFieldType) StringFieldType(io.sphere.sdk.types.StringFieldType) EnumFieldType(io.sphere.sdk.types.EnumFieldType) SetFieldType(io.sphere.sdk.types.SetFieldType) Type(io.sphere.sdk.types.Type) TypeSyncOptions(com.commercetools.sync.types.TypeSyncOptions) TypeSyncStatistics(com.commercetools.sync.types.helpers.TypeSyncStatistics) TypeDraft(io.sphere.sdk.types.TypeDraft) TypeSync(com.commercetools.sync.types.TypeSync) Test(org.junit.jupiter.api.Test)

Example 19 with TypeSyncStatistics

use of com.commercetools.sync.types.helpers.TypeSyncStatistics in project commercetools-sync-java by commercetools.

the class TypeSyncIT method sync_WithConcurrentModificationException_ShouldRetryToUpdateNewTypeWithSuccess.

@Test
void sync_WithConcurrentModificationException_ShouldRetryToUpdateNewTypeWithSuccess() {
    // Preparation
    final SphereClient spyClient = buildClientWithConcurrentModificationUpdate();
    final TypeDraft typeDraft = TypeDraftBuilder.of(TYPE_KEY_2, TYPE_NAME_2, ResourceTypeIdsSetBuilder.of().addChannels()).build();
    CTP_TARGET_CLIENT.execute(TypeCreateCommand.of(typeDraft)).toCompletableFuture().join();
    final TypeDraft updatedDraft = TypeDraftBuilder.of(typeDraft).name(TYPE_NAME_1).build();
    final TypeSyncOptions typeSyncOptions = TypeSyncOptionsBuilder.of(spyClient).build();
    final TypeSync typeSync = new TypeSync(typeSyncOptions);
    // test
    final TypeSyncStatistics statistics = typeSync.sync(Collections.singletonList(updatedDraft)).toCompletableFuture().join();
    // assertion
    assertThat(statistics).hasValues(1, 0, 1, 0);
    // Assert CTP state.
    final PagedQueryResult<Type> queryResult = CTP_TARGET_CLIENT.execute(TypeQuery.of().plusPredicates(queryModel -> queryModel.key().is(typeDraft.getKey()))).toCompletableFuture().join();
    assertThat(queryResult.head()).hasValueSatisfying(type -> assertThat(type.getName()).isEqualTo(TYPE_NAME_1));
}
Also used : TypeDraft(io.sphere.sdk.types.TypeDraft) BeforeEach(org.junit.jupiter.api.BeforeEach) TYPE_DESCRIPTION_1(com.commercetools.sync.integration.commons.utils.TypeITUtils.TYPE_DESCRIPTION_1) TYPE_DESCRIPTION_2(com.commercetools.sync.integration.commons.utils.TypeITUtils.TYPE_DESCRIPTION_2) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Collections.singletonList(java.util.Collections.singletonList) FieldDefinition(io.sphere.sdk.types.FieldDefinition) LocalizedEnumFieldType(io.sphere.sdk.types.LocalizedEnumFieldType) AfterAll(org.junit.jupiter.api.AfterAll) FIELD_DEFINITION_LABEL_1(com.commercetools.sync.integration.commons.utils.TypeITUtils.FIELD_DEFINITION_LABEL_1) Arrays.asList(java.util.Arrays.asList) SphereClient(io.sphere.sdk.client.SphereClient) CompletableFutureUtils.exceptionallyCompletedFuture(io.sphere.sdk.utils.CompletableFutureUtils.exceptionallyCompletedFuture) EnumValue(io.sphere.sdk.models.EnumValue) ITUtils.deleteTypes(com.commercetools.sync.integration.commons.utils.ITUtils.deleteTypes) BadGatewayException(io.sphere.sdk.client.BadGatewayException) TypeSyncStatistics(com.commercetools.sync.types.helpers.TypeSyncStatistics) TypeSync(com.commercetools.sync.types.TypeSync) CompletionException(java.util.concurrent.CompletionException) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) FIELD_DEFINITION_1(com.commercetools.sync.integration.commons.utils.TypeITUtils.FIELD_DEFINITION_1) Test(org.junit.jupiter.api.Test) TYPE_KEY_1(com.commercetools.sync.integration.commons.utils.TypeITUtils.TYPE_KEY_1) LocalizedString(io.sphere.sdk.models.LocalizedString) FIELD_DEFINITION_3(com.commercetools.sync.integration.commons.utils.TypeITUtils.FIELD_DEFINITION_3) List(java.util.List) FIELD_DEFINITION_2(com.commercetools.sync.integration.commons.utils.TypeITUtils.FIELD_DEFINITION_2) LocalizedString.ofEnglish(io.sphere.sdk.models.LocalizedString.ofEnglish) TextInputHint(io.sphere.sdk.models.TextInputHint) TYPE_KEY_2(com.commercetools.sync.integration.commons.utils.TypeITUtils.TYPE_KEY_2) TypeITUtils.populateTargetProject(com.commercetools.sync.integration.commons.utils.TypeITUtils.populateTargetProject) Optional(java.util.Optional) Mockito.any(org.mockito.Mockito.any) CTP_TARGET_CLIENT(com.commercetools.sync.integration.commons.utils.SphereClientUtils.CTP_TARGET_CLIENT) IntStream(java.util.stream.IntStream) TypeSyncOptionsBuilder(com.commercetools.sync.types.TypeSyncOptionsBuilder) TypeUpdateCommand(io.sphere.sdk.types.commands.TypeUpdateCommand) ResourceTypeIdsSetBuilder(io.sphere.sdk.types.ResourceTypeIdsSetBuilder) AssertionsForStatistics.assertThat(com.commercetools.sync.commons.asserts.statistics.AssertionsForStatistics.assertThat) CompletableFuture(java.util.concurrent.CompletableFuture) Mockito.spy(org.mockito.Mockito.spy) TypeSyncOptions(com.commercetools.sync.types.TypeSyncOptions) ArrayList(java.util.ArrayList) Assertions.as(org.assertj.core.api.Assertions.as) TypeQuery(io.sphere.sdk.types.queries.TypeQuery) TypeDraftBuilder(io.sphere.sdk.types.TypeDraftBuilder) Nonnull(javax.annotation.Nonnull) StringFieldType(io.sphere.sdk.types.StringFieldType) TYPE_NAME_1(com.commercetools.sync.integration.commons.utils.TypeITUtils.TYPE_NAME_1) FIELD_DEFINITION_NAME_1(com.commercetools.sync.integration.commons.utils.TypeITUtils.FIELD_DEFINITION_NAME_1) TYPE_NAME_2(com.commercetools.sync.integration.commons.utils.TypeITUtils.TYPE_NAME_2) TypeCreateCommand(io.sphere.sdk.types.commands.TypeCreateCommand) LocalizedEnumValue(io.sphere.sdk.models.LocalizedEnumValue) Mockito.when(org.mockito.Mockito.when) ErrorResponseException(io.sphere.sdk.client.ErrorResponseException) PagedQueryResult(io.sphere.sdk.queries.PagedQueryResult) ConcurrentModificationException(io.sphere.sdk.client.ConcurrentModificationException) EnumFieldType(io.sphere.sdk.types.EnumFieldType) TypeITUtils.getTypeByKey(com.commercetools.sync.integration.commons.utils.TypeITUtils.getTypeByKey) STRING(org.assertj.core.api.InstanceOfAssertFactories.STRING) Collections(java.util.Collections) SetFieldType(io.sphere.sdk.types.SetFieldType) Type(io.sphere.sdk.types.Type) LocalizedEnumFieldType(io.sphere.sdk.types.LocalizedEnumFieldType) StringFieldType(io.sphere.sdk.types.StringFieldType) EnumFieldType(io.sphere.sdk.types.EnumFieldType) SetFieldType(io.sphere.sdk.types.SetFieldType) Type(io.sphere.sdk.types.Type) SphereClient(io.sphere.sdk.client.SphereClient) TypeSyncOptions(com.commercetools.sync.types.TypeSyncOptions) TypeSyncStatistics(com.commercetools.sync.types.helpers.TypeSyncStatistics) TypeDraft(io.sphere.sdk.types.TypeDraft) TypeSync(com.commercetools.sync.types.TypeSync) Test(org.junit.jupiter.api.Test)

Example 20 with TypeSyncStatistics

use of com.commercetools.sync.types.helpers.TypeSyncStatistics in project commercetools-sync-java by commercetools.

the class TypeSyncIT method sync_WithSetOfEnumsAndSetOfLenumsChanges_ShouldUpdateTypeAddingFieldDefinition.

@Test
void sync_WithSetOfEnumsAndSetOfLenumsChanges_ShouldUpdateTypeAddingFieldDefinition() {
    // preparation
    final FieldDefinition withSetOfEnumsOld = FieldDefinition.of(SetFieldType.of(EnumFieldType.of(asList(EnumValue.of("b", "b"), EnumValue.of("a", "a")))), "foo", ofEnglish("foo"), false);
    final FieldDefinition withSetOfSetOfLEnumsOld = FieldDefinition.of(SetFieldType.of(LocalizedEnumFieldType.of(asList(LocalizedEnumValue.of("b", ofEnglish("b")), LocalizedEnumValue.of("a", ofEnglish("a"))))), "bar", ofEnglish("bar"), false);
    final TypeDraft oldTypeDraft = TypeDraftBuilder.of("withSetOfEnums", ofEnglish("withSetOfEnums"), ResourceTypeIdsSetBuilder.of().addCategories().build()).fieldDefinitions(asList(withSetOfEnumsOld, withSetOfSetOfLEnumsOld)).build();
    CTP_TARGET_CLIENT.execute(TypeCreateCommand.of(oldTypeDraft)).toCompletableFuture().join();
    final FieldDefinition withSetOfEnumsNew = FieldDefinition.of(SetFieldType.of(EnumFieldType.of(asList(EnumValue.of("a", "a"), EnumValue.of("b", "b"), EnumValue.of("c", "c")))), "foo", ofEnglish("foo"), false);
    final FieldDefinition withSetOfSetOfLEnumsNew = FieldDefinition.of(SetFieldType.of(LocalizedEnumFieldType.of(asList(LocalizedEnumValue.of("a", ofEnglish("a")), LocalizedEnumValue.of("b", ofEnglish("b")), LocalizedEnumValue.of("c", ofEnglish("c"))))), "bar", ofEnglish("bar"), false);
    final TypeDraft newTypeDraft = TypeDraftBuilder.of("withSetOfEnums", ofEnglish("withSetOfEnums"), ResourceTypeIdsSetBuilder.of().addCategories().build()).fieldDefinitions(asList(withSetOfEnumsNew, withSetOfSetOfLEnumsNew)).build();
    final TypeSyncOptions typeSyncOptions = TypeSyncOptionsBuilder.of(CTP_TARGET_CLIENT).build();
    final TypeSync typeSync = new TypeSync(typeSyncOptions);
    // test
    final TypeSyncStatistics typeSyncStatistics = typeSync.sync(singletonList(newTypeDraft)).toCompletableFuture().join();
    // assertions
    assertThat(typeSyncStatistics).hasValues(1, 0, 1, 0);
    final Optional<Type> oldTypeAfter = getTypeByKey(CTP_TARGET_CLIENT, "withSetOfEnums");
    assertThat(oldTypeAfter).hasValueSatisfying(type -> assertFieldDefinitionsAreEqual(type.getFieldDefinitions(), asList(withSetOfEnumsNew, withSetOfSetOfLEnumsNew)));
}
Also used : LocalizedEnumFieldType(io.sphere.sdk.types.LocalizedEnumFieldType) StringFieldType(io.sphere.sdk.types.StringFieldType) EnumFieldType(io.sphere.sdk.types.EnumFieldType) SetFieldType(io.sphere.sdk.types.SetFieldType) Type(io.sphere.sdk.types.Type) FieldDefinition(io.sphere.sdk.types.FieldDefinition) TypeSyncOptions(com.commercetools.sync.types.TypeSyncOptions) TypeSyncStatistics(com.commercetools.sync.types.helpers.TypeSyncStatistics) TypeDraft(io.sphere.sdk.types.TypeDraft) TypeSync(com.commercetools.sync.types.TypeSync) Test(org.junit.jupiter.api.Test)

Aggregations

TypeSyncStatistics (com.commercetools.sync.types.helpers.TypeSyncStatistics)21 TypeDraft (io.sphere.sdk.types.TypeDraft)21 Test (org.junit.jupiter.api.Test)21 TypeSync (com.commercetools.sync.types.TypeSync)20 Type (io.sphere.sdk.types.Type)18 TypeSyncOptions (com.commercetools.sync.types.TypeSyncOptions)17 EnumFieldType (io.sphere.sdk.types.EnumFieldType)15 LocalizedEnumFieldType (io.sphere.sdk.types.LocalizedEnumFieldType)15 SetFieldType (io.sphere.sdk.types.SetFieldType)15 StringFieldType (io.sphere.sdk.types.StringFieldType)15 AssertionsForStatistics.assertThat (com.commercetools.sync.commons.asserts.statistics.AssertionsForStatistics.assertThat)11 PagedQueryResult (io.sphere.sdk.queries.PagedQueryResult)11 TypeDraftBuilder (io.sphere.sdk.types.TypeDraftBuilder)11 ArrayList (java.util.ArrayList)11 List (java.util.List)11 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)11 CTP_TARGET_CLIENT (com.commercetools.sync.integration.commons.utils.SphereClientUtils.CTP_TARGET_CLIENT)10 TypeITUtils.populateTargetProject (com.commercetools.sync.integration.commons.utils.TypeITUtils.populateTargetProject)10 TypeSyncOptionsBuilder (com.commercetools.sync.types.TypeSyncOptionsBuilder)10 LocalizedString (io.sphere.sdk.models.LocalizedString)10