77import com .commercetools .sync .products .ProductSyncOptionsBuilder ;
88import com .commercetools .sync .products .helpers .ProductSyncStatistics ;
99import io .sphere .sdk .categories .Category ;
10- import io .sphere .sdk .models .Reference ;
10+ import io .sphere .sdk .models .ResourceIdentifier ;
1111import io .sphere .sdk .products .Product ;
1212import io .sphere .sdk .products .ProductDraft ;
1313import io .sphere .sdk .products .commands .ProductCreateCommand ;
2222import java .util .ArrayList ;
2323import java .util .List ;
2424import java .util .Locale ;
25+ import java .util .Set ;
2526import java .util .concurrent .CompletionException ;
2627import java .util .stream .Collectors ;
2728
3132import static com .commercetools .sync .integration .commons .utils .CategoryITUtils .createCategories ;
3233import static com .commercetools .sync .integration .commons .utils .CategoryITUtils .createCategoriesCustomType ;
3334import static com .commercetools .sync .integration .commons .utils .CategoryITUtils .getCategoryDrafts ;
34- import static com .commercetools .sync .integration .commons .utils .ProductITUtils .PRODUCT_TYPE_NO_KEY_RESOURCE_PATH ;
35- import static com .commercetools .sync .integration .commons .utils .ProductITUtils .PRODUCT_TYPE_RESOURCE_PATH ;
3635import static com .commercetools .sync .integration .commons .utils .ProductITUtils .createProductType ;
3736import static com .commercetools .sync .integration .commons .utils .ProductITUtils .deleteAllProducts ;
3837import static com .commercetools .sync .integration .commons .utils .ProductITUtils .deleteProductSyncTestData ;
3938import static com .commercetools .sync .integration .commons .utils .SphereClientUtils .CTP_SOURCE_CLIENT ;
4039import static com .commercetools .sync .integration .commons .utils .SphereClientUtils .CTP_TARGET_CLIENT ;
4140import static com .commercetools .sync .products .ProductSyncMockUtils .PRODUCT_KEY_1_RESOURCE_PATH ;
41+ import static com .commercetools .sync .products .ProductSyncMockUtils .PRODUCT_TYPE_NO_KEY_RESOURCE_PATH ;
42+ import static com .commercetools .sync .products .ProductSyncMockUtils .PRODUCT_TYPE_RESOURCE_PATH ;
4243import static com .commercetools .sync .products .ProductSyncMockUtils .createProductDraft ;
4344import static com .commercetools .sync .products .ProductSyncMockUtils .createRandomCategoryOrderHints ;
4445import static java .lang .String .format ;
46+ import static java .util .stream .Collectors .toSet ;
4547import static org .assertj .core .api .Java6Assertions .assertThat ;
4648
4749public class ProductReferenceResolverIT {
4850 private static ProductType productTypeSource ;
4951 private static ProductType noKeyProductTypeSource ;
5052
51- private static List <Reference <Category >> categoryReferences ;
53+ private static Set <ResourceIdentifier <Category >> sourceCategoryResourcesWithIds ;
54+ private static Set <ResourceIdentifier <Category >> sourceCategories ;
5255 private ProductSync productSync ;
5356 private List <String > errorCallBackMessages ;
5457 private List <String > warningCallBackMessages ;
@@ -69,9 +72,16 @@ public static void setup() {
6972 OLD_CATEGORY_CUSTOM_TYPE_NAME , CTP_SOURCE_CLIENT );
7073
7174 createCategories (CTP_TARGET_CLIENT , getCategoryDrafts (null , 2 ));
72- categoryReferences =
73- createCategories (CTP_SOURCE_CLIENT , getCategoryDrafts (null , 2 ))
74- .stream ().map (Category ::toReference ).collect (Collectors .toList ());
75+ sourceCategories = createCategories (CTP_SOURCE_CLIENT , getCategoryDrafts (null , 2 ))
76+ .stream ()
77+ .map (category -> ResourceIdentifier .<Category >ofIdOrKey (category .getId (), category .getKey (),
78+ Category .referenceTypeId ())).collect (Collectors .toSet ());
79+ sourceCategoryResourcesWithIds =
80+ sourceCategories .stream ()
81+ .map (categoryResourceIdentifier ->
82+ ResourceIdentifier .<Category >ofId (categoryResourceIdentifier .getId (),
83+ Category .referenceTypeId ()))
84+ .collect (toSet ());
7585
7686 createProductType (PRODUCT_TYPE_RESOURCE_PATH , CTP_TARGET_CLIENT );
7787 createProductType (PRODUCT_TYPE_NO_KEY_RESOURCE_PATH , CTP_TARGET_CLIENT );
@@ -117,7 +127,8 @@ public static void tearDown() {
117127 @ Test
118128 public void sync_withNewProductWithExistingCategoryAndProductTypeReferences_ShouldCreateProduct () {
119129 final ProductDraft productDraft = createProductDraft (PRODUCT_KEY_1_RESOURCE_PATH ,
120- productTypeSource .toReference (), categoryReferences , createRandomCategoryOrderHints (categoryReferences ));
130+ productTypeSource .toReference (), sourceCategoryResourcesWithIds ,
131+ createRandomCategoryOrderHints (sourceCategories ));
121132 CTP_SOURCE_CLIENT .execute (ProductCreateCommand .of (productDraft )).toCompletableFuture ().join ();
122133
123134 final ProductQuery productQuery = ProductQuery .of ().withLimit (SphereClientUtils .QUERY_MAX_LIMIT )
@@ -147,8 +158,8 @@ public void sync_withNewProductWithExistingCategoryAndProductTypeReferences_Shou
147158 @ Test
148159 public void sync_withNewProductWithNoProductTypeKey_ShouldFailCreatingTheProduct () {
149160 final ProductDraft productDraft = createProductDraft (PRODUCT_KEY_1_RESOURCE_PATH ,
150- noKeyProductTypeSource .toReference (), categoryReferences ,
151- createRandomCategoryOrderHints (categoryReferences ));
161+ noKeyProductTypeSource .toReference (), sourceCategoryResourcesWithIds ,
162+ createRandomCategoryOrderHints (sourceCategories ));
152163 CTP_SOURCE_CLIENT .execute (ProductCreateCommand .of (productDraft )).toCompletableFuture ().join ();
153164
154165 final ProductQuery productQuery = ProductQuery .of ().withLimit (SphereClientUtils .QUERY_MAX_LIMIT )
0 commit comments