1313import io .sphere .sdk .products .ProductVariantDraftBuilder ;
1414import io .sphere .sdk .products .commands .ProductCreateCommand ;
1515import io .sphere .sdk .products .queries .ProductProjectionQuery ;
16+ import io .sphere .sdk .products .queries .ProductQuery ;
1617import io .sphere .sdk .producttypes .ProductType ;
1718import io .sphere .sdk .queries .PagedQueryResult ;
18- import io .sphere .sdk .queries .QueryPredicate ;
1919import org .junit .AfterClass ;
2020import org .junit .Before ;
2121import org .junit .BeforeClass ;
@@ -116,17 +116,6 @@ public void sync_NewProducts_ShouldCreateProducts() throws IOException {
116116 diff , THRESHOLD ))
117117 .isLessThanOrEqualTo (THRESHOLD );
118118
119- // Assert actual state of CTP project (number of updated products)
120- final CompletableFuture <Integer > totalNumberOfUpdatedProducts =
121- CTP_TARGET_CLIENT .execute (ProductProjectionQuery .ofStaged ()
122- .withPredicates (QueryPredicate .of ("version = \" 2\" " )))
123- .thenApply (PagedQueryResult ::getTotal )
124- .thenApply (Long ::intValue )
125- .toCompletableFuture ();
126-
127- executeBlocking (totalNumberOfUpdatedProducts );
128- assertThat (totalNumberOfUpdatedProducts ).isCompletedWithValue (0 );
129-
130119 // Assert actual state of CTP project (total number of existing products)
131120 final CompletableFuture <Integer > totalNumberOfProducts =
132121 CTP_TARGET_CLIENT .execute (ProductProjectionQuery .ofStaged ())
@@ -148,11 +137,11 @@ public void sync_NewProducts_ShouldCreateProducts() throws IOException {
148137 @ Test
149138 public void sync_ExistingProducts_ShouldUpdateProducts () throws IOException {
150139 final List <ProductDraft > productDrafts = buildProductDrafts (NUMBER_OF_RESOURCE_UNDER_TEST );
151- // Create drafts to target project with different slugs
140+ // Create drafts to target project with different descriptions
152141 CompletableFuture .allOf (productDrafts .stream ()
153142 .map (ProductDraftBuilder ::of )
154- .map (builder -> builder .slug (
155- ofEnglish (builder . getSlug (). get ( ENGLISH ) + "_old " )))
143+ .map (builder -> builder .description (
144+ ofEnglish ("oldDescription " )))
156145 .map (builder -> builder .productType (productType .toReference ()))
157146 .map (ProductDraftBuilder ::build )
158147 .map (draft -> CTP_TARGET_CLIENT .execute (ProductCreateCommand .of (draft )))
@@ -177,8 +166,10 @@ public void sync_ExistingProducts_ShouldUpdateProducts() throws IOException {
177166
178167 // Assert actual state of CTP project (number of updated products)
179168 final CompletableFuture <Integer > totalNumberOfUpdatedProducts =
180- CTP_TARGET_CLIENT .execute (ProductProjectionQuery .ofStaged ()
181- .withPredicates (QueryPredicate .of ("version = \" 2\" " )))
169+ CTP_TARGET_CLIENT .execute (ProductQuery .of ()
170+ .withPredicates (p -> p .masterData ().staged ()
171+ .description ().locale (ENGLISH )
172+ .is ("newDescription" )))
182173 .thenApply (PagedQueryResult ::getTotal )
183174 .thenApply (Long ::intValue )
184175 .toCompletableFuture ();
@@ -210,11 +201,11 @@ public void sync_WithSomeExistingProducts_ShouldSyncProducts() throws IOExceptio
210201 final int halfNumberOfDrafts = productDrafts .size () / 2 ;
211202 final List <ProductDraft > firstHalf = productDrafts .subList (0 , halfNumberOfDrafts );
212203
213- // Create first half of drafts to target project with different slugs
204+ // Create first half of drafts to target project with different description
214205 CompletableFuture .allOf (firstHalf .stream ()
215206 .map (ProductDraftBuilder ::of )
216- .map (builder -> builder .slug (
217- ofEnglish (builder . getSlug (). get ( ENGLISH ) + "_old " )))
207+ .map (builder -> builder .description (
208+ ofEnglish ("oldDescription " )))
218209 .map (builder -> builder .productType (productType .toReference ()))
219210 .map (ProductDraftBuilder ::build )
220211 .map (draft -> CTP_TARGET_CLIENT .execute (ProductCreateCommand .of (draft )))
@@ -239,18 +230,20 @@ public void sync_WithSomeExistingProducts_ShouldSyncProducts() throws IOExceptio
239230
240231 // Assert actual state of CTP project (number of updated products)
241232 final CompletableFuture <Integer > totalNumberOfUpdatedProducts =
242- CTP_TARGET_CLIENT .execute (ProductProjectionQuery .ofStaged ()
243- .withPredicates (QueryPredicate .of ("version = \" 2\" " )))
233+ CTP_TARGET_CLIENT .execute (ProductQuery .of ()
234+ .withPredicates (p -> p .masterData ().staged ()
235+ .description ().locale (ENGLISH )
236+ .is ("oldDescription" )))
244237 .thenApply (PagedQueryResult ::getTotal )
245238 .thenApply (Long ::intValue )
246239 .toCompletableFuture ();
247240
248241 executeBlocking (totalNumberOfUpdatedProducts );
249- assertThat (totalNumberOfUpdatedProducts ).isCompletedWithValue (halfNumberOfDrafts );
242+ assertThat (totalNumberOfUpdatedProducts ).isCompletedWithValue (0 );
250243
251244 // Assert actual state of CTP project (total number of existing products)
252245 final CompletableFuture <Integer > totalNumberOfProducts =
253- CTP_TARGET_CLIENT .execute (ProductProjectionQuery . ofStaged ())
246+ CTP_TARGET_CLIENT .execute (ProductQuery . of ())
254247 .thenApply (PagedQueryResult ::getTotal )
255248 .thenApply (Long ::intValue )
256249 .toCompletableFuture ();
@@ -278,6 +271,7 @@ private List<ProductDraft> buildProductDrafts(final int numberOfProducts) {
278271 .build ();
279272 final ProductDraft productDraft = ProductDraftBuilder
280273 .of (draftsProductType , ofEnglish ("name_" + i ), ofEnglish ("slug_" + i ), masterVariantDraft )
274+ .description (ofEnglish ("newDescription" ))
281275 .key ("productKey_" + i )
282276 .build ();
283277 productDrafts .add (productDraft );
0 commit comments