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));
});
}
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)));
}
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));
});
}
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));
}
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)));
}
Aggregations