Search in sources :

Example 16 with ResourceKeyId

use of com.commercetools.sync.commons.models.ResourceKeyId in project commercetools-sync-java by commercetools.

the class BaseServiceImplTest method cacheKeysToIdsUsingGraphQl_WithNoCachedKeys_ShouldMakeRequestAndReturnCachedEntry.

@Test
void cacheKeysToIdsUsingGraphQl_WithNoCachedKeys_ShouldMakeRequestAndReturnCachedEntry() {
    // preparation
    final ResourceKeyIdGraphQlResult resourceKeyIdGraphQlResult = mock(ResourceKeyIdGraphQlResult.class);
    final ResourceKeyId mockResourceKeyId = mock(ResourceKeyId.class);
    final String key = "testKey";
    final String id = "testId";
    when(mockResourceKeyId.getKey()).thenReturn(key);
    when(mockResourceKeyId.getId()).thenReturn(id);
    when(resourceKeyIdGraphQlResult.getResults()).thenReturn(singleton(mockResourceKeyId));
    when(client.execute(any())).thenReturn(completedFuture(resourceKeyIdGraphQlResult));
    // test
    final Map<String, String> optional = service.cacheKeysToIds(singleton("testKey")).toCompletableFuture().join();
    // assertions
    assertThat(optional).containsExactly(MapEntry.entry(key, id));
    verify(client, times(1)).execute(any(ResourceKeyIdGraphQlRequest.class));
}
Also used : ResourceKeyIdGraphQlResult(com.commercetools.sync.commons.models.ResourceKeyIdGraphQlResult) ResourceKeyIdGraphQlRequest(com.commercetools.sync.commons.helpers.ResourceKeyIdGraphQlRequest) ResourceKeyId(com.commercetools.sync.commons.models.ResourceKeyId) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

ResourceKeyId (com.commercetools.sync.commons.models.ResourceKeyId)16 Test (org.junit.jupiter.api.Test)16 ResourceKeyIdGraphQlRequest (com.commercetools.sync.commons.helpers.ResourceKeyIdGraphQlRequest)13 ResourceKeyIdGraphQlResult (com.commercetools.sync.commons.models.ResourceKeyIdGraphQlResult)13 CategoryQuery (io.sphere.sdk.categories.queries.CategoryQuery)7 List (java.util.List)7 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)7 Category (io.sphere.sdk.categories.Category)6 SphereClient (io.sphere.sdk.client.SphereClient)6 ArrayList (java.util.ArrayList)6 HashSet (java.util.HashSet)6 Set (java.util.Set)6 Collectors (java.util.stream.Collectors)6 BeforeEach (org.junit.jupiter.api.BeforeEach)6 Collections.singleton (java.util.Collections.singleton)5 GraphQlQueryResources (com.commercetools.sync.commons.models.GraphQlQueryResources)4 CtpQueryUtils.queryAll (com.commercetools.sync.commons.utils.CtpQueryUtils.queryAll)4 CategoryDraft (io.sphere.sdk.categories.CategoryDraft)4 Locale (java.util.Locale)4 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4