Search in sources :

Example 21 with CategorySyncStatistics

use of com.commercetools.sync.categories.helpers.CategorySyncStatistics in project commercetools-sync-java by commercetools.

the class CategorySyncTest method sync_WithNoExistingCategory_ShouldCreateCategory.

@Test
void sync_WithNoExistingCategory_ShouldCreateCategory() {
    final Category mockCategory = getMockCategory(UUID.randomUUID().toString(), "newKey");
    final Category mockParentCategory = getMockCategory(UUID.randomUUID().toString(), "parentKey");
    final CategoryService mockCategoryService = mockCategoryService(singleton(mockParentCategory), mockCategory);
    when(mockCategoryService.fetchCachedCategoryId(Mockito.eq("parentKey"))).thenReturn(CompletableFuture.completedFuture(Optional.of("parentId")));
    final CategorySync mockCategorySync = new CategorySync(categorySyncOptions, getMockTypeService(), mockCategoryService, mockUnresolvedReferencesService);
    final List<CategoryDraft> categoryDrafts = singletonList(getMockCategoryDraft(Locale.ENGLISH, "name", "newKey", "parentKey", "customTypeId", new HashMap<>()));
    final CategorySyncStatistics syncStatistics = mockCategorySync.sync(categoryDrafts).toCompletableFuture().join();
    assertThat(syncStatistics).hasValues(1, 1, 0, 0);
    assertThat(errorCallBackMessages).hasSize(0);
    assertThat(errorCallBackExceptions).hasSize(0);
}
Also used : Category(io.sphere.sdk.categories.Category) CategorySyncMockUtils.getMockCategory(com.commercetools.sync.categories.CategorySyncMockUtils.getMockCategory) HashMap(java.util.HashMap) CategorySyncMockUtils.getMockCategoryDraft(com.commercetools.sync.categories.CategorySyncMockUtils.getMockCategoryDraft) CategoryDraft(io.sphere.sdk.categories.CategoryDraft) CategoryService(com.commercetools.sync.services.CategoryService) MockUtils.mockCategoryService(com.commercetools.sync.commons.MockUtils.mockCategoryService) CategorySyncStatistics(com.commercetools.sync.categories.helpers.CategorySyncStatistics) Test(org.junit.jupiter.api.Test)

Example 22 with CategorySyncStatistics

use of com.commercetools.sync.categories.helpers.CategorySyncStatistics in project commercetools-sync-java by commercetools.

the class CategorySyncTest method sync_WithExistingCategoryButWithNoCustomType_ShouldSync.

@Test
void sync_WithExistingCategoryButWithNoCustomType_ShouldSync() {
    final Category mockCategory = getMockCategory(UUID.randomUUID().toString(), "key");
    final CategoryService mockCategoryService = mockCategoryService(singleton(mockCategory), null, mockCategory);
    when(mockCategoryService.fetchCategory(Mockito.eq("key"))).thenReturn(CompletableFuture.completedFuture(Optional.of(mockCategory)));
    final CategorySync categorySync = new CategorySync(categorySyncOptions, getMockTypeService(), mockCategoryService, mockUnresolvedReferencesService);
    final CategoryDraft categoryDraft = mock(CategoryDraft.class);
    when(categoryDraft.getName()).thenReturn(LocalizedString.of(Locale.ENGLISH, "name"));
    when(categoryDraft.getKey()).thenReturn("key");
    when(categoryDraft.getCustom()).thenReturn(null);
    final List<CategoryDraft> categoryDrafts = singletonList(categoryDraft);
    final CategorySyncStatistics syncStatistics = categorySync.sync(categoryDrafts).toCompletableFuture().join();
    assertThat(errorCallBackMessages).hasSize(0);
    assertThat(errorCallBackExceptions).hasSize(0);
    assertThat(syncStatistics).hasValues(1, 0, 1, 0);
}
Also used : Category(io.sphere.sdk.categories.Category) CategorySyncMockUtils.getMockCategory(com.commercetools.sync.categories.CategorySyncMockUtils.getMockCategory) CategorySyncMockUtils.getMockCategoryDraft(com.commercetools.sync.categories.CategorySyncMockUtils.getMockCategoryDraft) CategoryDraft(io.sphere.sdk.categories.CategoryDraft) CategoryService(com.commercetools.sync.services.CategoryService) MockUtils.mockCategoryService(com.commercetools.sync.commons.MockUtils.mockCategoryService) CategorySyncStatistics(com.commercetools.sync.categories.helpers.CategorySyncStatistics) Test(org.junit.jupiter.api.Test)

Example 23 with CategorySyncStatistics

use of com.commercetools.sync.categories.helpers.CategorySyncStatistics in project commercetools-sync-java by commercetools.

the class CategorySyncTest method sync_WithEmptyListOfDrafts_ShouldNotProcessAnyCategories.

@Test
void sync_WithEmptyListOfDrafts_ShouldNotProcessAnyCategories() {
    final CategoryService mockCategoryService = mockCategoryService(emptySet(), null);
    final CategorySync mockCategorySync = new CategorySync(categorySyncOptions, getMockTypeService(), mockCategoryService, mockUnresolvedReferencesService);
    final CategorySyncStatistics syncStatistics = mockCategorySync.sync(emptyList()).toCompletableFuture().join();
    assertThat(syncStatistics).hasValues(0, 0, 0, 0);
    assertThat(errorCallBackMessages).isEmpty();
    assertThat(errorCallBackExceptions).isEmpty();
}
Also used : CategoryService(com.commercetools.sync.services.CategoryService) MockUtils.mockCategoryService(com.commercetools.sync.commons.MockUtils.mockCategoryService) CategorySyncStatistics(com.commercetools.sync.categories.helpers.CategorySyncStatistics) Test(org.junit.jupiter.api.Test)

Example 24 with CategorySyncStatistics

use of com.commercetools.sync.categories.helpers.CategorySyncStatistics in project commercetools-sync-java by commercetools.

the class CategorySyncTest method sync_WithExistingCategoryButWithEmptyParentReference_ShouldFailSync.

@Test
void sync_WithExistingCategoryButWithEmptyParentReference_ShouldFailSync() {
    final Category mockCategory = getMockCategory(UUID.randomUUID().toString(), "key");
    final CategoryService mockCategoryService = mockCategoryService(singleton(mockCategory), null, mockCategory);
    when(mockCategoryService.fetchCategory(Mockito.eq("key"))).thenReturn(CompletableFuture.completedFuture(Optional.of(mockCategory)));
    final CategorySync categorySync = new CategorySync(categorySyncOptions, getMockTypeService(), mockCategoryService, mockUnresolvedReferencesService);
    final List<CategoryDraft> categoryDrafts = singletonList(getMockCategoryDraft(Locale.ENGLISH, "name", "key", "", "customTypeId", new HashMap<>()));
    final CategorySyncStatistics syncStatistics = categorySync.sync(categoryDrafts).toCompletableFuture().join();
    assertThat(syncStatistics).hasValues(1, 0, 0, 1);
    assertThat(errorCallBackMessages).hasSize(1);
    assertThat(errorCallBackMessages.get(0)).contains(BLANK_KEY_VALUE_ON_RESOURCE_IDENTIFIER);
    assertThat(errorCallBackExceptions).hasSize(1);
}
Also used : Category(io.sphere.sdk.categories.Category) CategorySyncMockUtils.getMockCategory(com.commercetools.sync.categories.CategorySyncMockUtils.getMockCategory) HashMap(java.util.HashMap) CategorySyncMockUtils.getMockCategoryDraft(com.commercetools.sync.categories.CategorySyncMockUtils.getMockCategoryDraft) CategoryDraft(io.sphere.sdk.categories.CategoryDraft) CategoryService(com.commercetools.sync.services.CategoryService) MockUtils.mockCategoryService(com.commercetools.sync.commons.MockUtils.mockCategoryService) CategorySyncStatistics(com.commercetools.sync.categories.helpers.CategorySyncStatistics) Test(org.junit.jupiter.api.Test)

Example 25 with CategorySyncStatistics

use of com.commercetools.sync.categories.helpers.CategorySyncStatistics in project commercetools-sync-java by commercetools.

the class CategorySyncTest method sync_WithANullDraft_ShouldBeCountedAsFailed.

@Test
void sync_WithANullDraft_ShouldBeCountedAsFailed() {
    final CategoryService mockCategoryService = mockCategoryService(emptySet(), null);
    final CategorySync mockCategorySync = new CategorySync(categorySyncOptions, getMockTypeService(), mockCategoryService, mockUnresolvedReferencesService);
    final CategorySyncStatistics syncStatistics = mockCategorySync.sync(singletonList(null)).toCompletableFuture().join();
    assertThat(syncStatistics).hasValues(1, 0, 0, 1);
    assertThat(errorCallBackMessages).hasSize(1);
    assertThat(errorCallBackMessages.get(0)).isEqualTo("CategoryDraft is null.");
    assertThat(errorCallBackExceptions).hasSize(1);
    assertThat(errorCallBackExceptions.get(0)).isEqualTo(null);
}
Also used : CategoryService(com.commercetools.sync.services.CategoryService) MockUtils.mockCategoryService(com.commercetools.sync.commons.MockUtils.mockCategoryService) CategorySyncStatistics(com.commercetools.sync.categories.helpers.CategorySyncStatistics) Test(org.junit.jupiter.api.Test)

Aggregations

CategorySyncStatistics (com.commercetools.sync.categories.helpers.CategorySyncStatistics)36 Test (org.junit.jupiter.api.Test)36 CategoryDraft (io.sphere.sdk.categories.CategoryDraft)34 Category (io.sphere.sdk.categories.Category)22 ArrayList (java.util.ArrayList)14 MockUtils.mockCategoryService (com.commercetools.sync.commons.MockUtils.mockCategoryService)13 CategoryService (com.commercetools.sync.services.CategoryService)13 HashMap (java.util.HashMap)13 LocalizedString (io.sphere.sdk.models.LocalizedString)12 CategorySyncMockUtils.getMockCategoryDraft (com.commercetools.sync.categories.CategorySyncMockUtils.getMockCategoryDraft)11 CategorySyncMockUtils.getMockCategory (com.commercetools.sync.categories.CategorySyncMockUtils.getMockCategory)10 CategorySync (com.commercetools.sync.categories.CategorySync)9 AssertionsForStatistics.assertThat (com.commercetools.sync.commons.asserts.statistics.AssertionsForStatistics.assertThat)7 CategoryDraftBuilder (io.sphere.sdk.categories.CategoryDraftBuilder)7 CategoryCreateCommand (io.sphere.sdk.categories.commands.CategoryCreateCommand)7 CategoryQuery (io.sphere.sdk.categories.queries.CategoryQuery)7 ResourceIdentifier (io.sphere.sdk.models.ResourceIdentifier)7 CustomFieldsDraft (io.sphere.sdk.types.CustomFieldsDraft)7 Collections (java.util.Collections)7 List (java.util.List)7