Search in sources :

Example 11 with CategoryService

use of com.commercetools.sync.services.CategoryService in project commercetools-sync-java by commercetools.

the class CategorySyncTest method sync_WithIdenticalExistingCategory_ShouldNotUpdateCategory.

@Test
void sync_WithIdenticalExistingCategory_ShouldNotUpdateCategory() {
    final Category mockCategory = getMockCategory(UUID.randomUUID().toString(), "key");
    final CategoryDraft identicalCategoryDraft = CategoryDraftBuilder.of(mockCategory).build();
    final CategoryService mockCategoryService = mockCategoryService(singleton(mockCategory), null, mockCategory);
    when(mockCategoryService.fetchCategory(Mockito.eq("key"))).thenReturn(CompletableFuture.completedFuture(Optional.of(mockCategory)));
    final CategorySync mockCategorySync = new CategorySync(categorySyncOptions, getMockTypeService(), mockCategoryService, mockUnresolvedReferencesService);
    final List<CategoryDraft> categoryDrafts = singletonList(identicalCategoryDraft);
    final CategorySyncStatistics syncStatistics = mockCategorySync.sync(categoryDrafts).toCompletableFuture().join();
    assertThat(errorCallBackMessages).hasSize(0);
    assertThat(errorCallBackExceptions).hasSize(0);
    assertThat(syncStatistics).hasValues(1, 0, 0, 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 12 with CategoryService

use of com.commercetools.sync.services.CategoryService 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 13 with CategoryService

use of com.commercetools.sync.services.CategoryService in project commercetools-sync-java by commercetools.

the class CategoryReferenceResolverTest method setup.

/**
 * Sets up the services and the options needed for reference resolution.
 */
@BeforeEach
void setup() {
    typeService = getMockTypeService();
    categoryService = mock(CategoryService.class);
    when(categoryService.fetchCachedCategoryId(CACHED_CATEGORY_KEY)).thenReturn(CompletableFuture.completedFuture(Optional.of(CACHED_CATEGORY_ID)));
    final CategorySyncOptions syncOptions = CategorySyncOptionsBuilder.of(mock(SphereClient.class)).build();
    referenceResolver = new CategoryReferenceResolver(syncOptions, typeService, categoryService);
}
Also used : CategorySyncOptions(com.commercetools.sync.categories.CategorySyncOptions) CategoryService(com.commercetools.sync.services.CategoryService) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 14 with CategoryService

use of com.commercetools.sync.services.CategoryService 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 15 with CategoryService

use of com.commercetools.sync.services.CategoryService 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)

Aggregations

CategoryService (com.commercetools.sync.services.CategoryService)35 Test (org.junit.jupiter.api.Test)32 MockUtils.mockCategoryService (com.commercetools.sync.commons.MockUtils.mockCategoryService)27 Category (io.sphere.sdk.categories.Category)24 CategorySyncMockUtils.getMockCategory (com.commercetools.sync.categories.CategorySyncMockUtils.getMockCategory)20 CategoryDraft (io.sphere.sdk.categories.CategoryDraft)19 HashSet (java.util.HashSet)18 CategorySyncMockUtils.getMockCategoryDraft (com.commercetools.sync.categories.CategorySyncMockUtils.getMockCategoryDraft)15 CategorySyncStatistics (com.commercetools.sync.categories.helpers.CategorySyncStatistics)15 SphereClient (io.sphere.sdk.client.SphereClient)15 Set (java.util.Set)15 Collections (java.util.Collections)14 List (java.util.List)14 Map (java.util.Map)14 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)14 Mockito.when (org.mockito.Mockito.when)14 ReferenceResolutionException (com.commercetools.sync.commons.exceptions.ReferenceResolutionException)12 SphereException (io.sphere.sdk.models.SphereException)12 CompletableFuture (java.util.concurrent.CompletableFuture)12 ResourceIdentifier (io.sphere.sdk.models.ResourceIdentifier)11