Skip to content

Commit 47c3a28

Browse files
Merge pull request #216 from commercetools/186-improve-assertions
#186: Refactor all string-based statistics report message assertions …
2 parents ac9e5f6 + bb4870c commit 47c3a28

24 files changed

Lines changed: 367 additions & 488 deletions

File tree

docs/RELEASE_NOTES.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,14 @@
6060
6161
**Enhancements** (1)
6262
- **Build Tools** - Bumped Gradle to version 4.4. [#205](https://github.com/commercetools/commercetools-sync-java/issues/205)
63-
-->
6463
64+
**New Features** (1)
65+
- **Category Sync** - Exposed new method in CategorySyncStatistics#getNumberOfCategoriesWithMissingParents which gets the
66+
total number of categories with missing parents from the statistics instance. [#186](https://github.com/commercetools/commercetools-sync-java/issues/186)
67+
68+
**Changes** (1)
69+
- **Product Sync** - Changed product sync statistics report message wording. [#186](https://github.com/commercetools/commercetools-sync-java/issues/186)
70+
-->
6571

6672

6773
### v1.0.0-M7 - Dec 15, 2017

docs/usage/PRODUCT_SYNC.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ human readable format.
118118
````java
119119
final ProductSyncStatistics stats = syncStatisticsStage.toCompletebleFuture().join();
120120
stats.getReportMessage();
121-
/*"Summary: 2000 products were processed in total (1000 created, 995 updated and 5 products failed to sync)."*/
121+
/*"Summary: 2000 products were processed in total (1000 created, 995 updated and 5 failed to sync)."*/
122122
````
123123

124124
__Note__ The statistics object contains the processing time of the last batch only. This is due to two reasons:

src/integration-test/java/com/commercetools/sync/integration/ctpprojectsource/categories/CategorySyncIT.java

Lines changed: 9 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
import static com.commercetools.sync.categories.utils.CategoryReferenceReplacementUtils.buildCategoryQuery;
3030
import static com.commercetools.sync.categories.utils.CategoryReferenceReplacementUtils.replaceCategoriesReferenceIdsWithKeys;
31+
import static com.commercetools.sync.commons.asserts.statistics.AssertionsForStatistics.assertThat;
3132
import static com.commercetools.sync.commons.utils.SyncUtils.batchElements;
3233
import static com.commercetools.sync.integration.commons.utils.CategoryITUtils.OLD_CATEGORY_CUSTOM_TYPE_KEY;
3334
import static com.commercetools.sync.integration.commons.utils.CategoryITUtils.createCategories;
@@ -114,10 +115,7 @@ public void syncDrafts_withChangesOnly_ShouldUpdateCategories() {
114115

115116
final CategorySyncStatistics syncStatistics = categorySync.sync(categoryDrafts).toCompletableFuture().join();
116117

117-
assertThat(syncStatistics.getProcessed()).isEqualTo(2);
118-
assertThat(syncStatistics.getCreated()).isEqualTo(0);
119-
assertThat(syncStatistics.getUpdated()).isEqualTo(2);
120-
assertThat(syncStatistics.getFailed()).isEqualTo(0);
118+
assertThat(syncStatistics).hasValues(2, 0, 2, 0);
121119
assertThat(callBackErrorResponses).isEmpty();
122120
assertThat(callBackExceptions).isEmpty();
123121
assertThat(callBackWarningResponses).isEmpty();
@@ -136,10 +134,7 @@ public void syncDrafts_withNewCategories_ShouldCreateCategories() {
136134

137135
final CategorySyncStatistics syncStatistics = categorySync.sync(categoryDrafts).toCompletableFuture().join();
138136

139-
assertThat(syncStatistics.getReportMessage())
140-
.isEqualTo(format("Summary: %d categories were processed in total (%d created, %d updated, %d failed to "
141-
+ "sync and %s categories with a missing parent).", 3, 1, 2, 0, 0));
142-
137+
assertThat(syncStatistics).hasValues(3, 1, 2, 0, 0);
143138
assertThat(callBackErrorResponses).isEmpty();
144139
assertThat(callBackExceptions).isEmpty();
145140
assertThat(callBackWarningResponses).isEmpty();
@@ -159,9 +154,7 @@ public void syncDrafts_WithUpdatedCategoriesWithoutReferenceKeys_ShouldNotSyncCa
159154

160155
final CategorySyncStatistics syncStatistics = categorySync.sync(categoryDrafts).toCompletableFuture().join();
161156

162-
assertThat(syncStatistics.getReportMessage())
163-
.isEqualTo(format("Summary: %d categories were processed in total (%d created, %d updated, %d failed to "
164-
+ "sync and %s categories with a missing parent).", 2, 0, 0, 2, 0));
157+
assertThat(syncStatistics).hasValues(2, 0, 0, 2, 0);
165158
assertThat(callBackErrorResponses).hasSize(2);
166159
final String key1 = categoryDrafts.get(0).getKey();
167160
assertThat(callBackErrorResponses.get(0)).isEqualTo(format("Failed to resolve references on CategoryDraft with"
@@ -225,9 +218,7 @@ public void syncDrafts_withNewShuffledBatchOfCategories_ShouldCreateCategories()
225218
final CategorySyncStatistics syncStatistics = syncBatches(categorySync, batches,
226219
CompletableFuture.completedFuture(null)).toCompletableFuture().join();
227220

228-
assertThat(syncStatistics.getReportMessage())
229-
.isEqualTo(format("Summary: %d categories were processed in total (%d created, %d updated, %d failed to "
230-
+ "sync and %s categories with a missing parent).", 130, 130, 0, 0, 0));
221+
assertThat(syncStatistics).hasValues(130, 130, 0, 0, 0);
231222
assertThat(callBackErrorResponses).isEmpty();
232223
assertThat(callBackExceptions).isEmpty();
233224
assertThat(callBackWarningResponses).isEmpty();
@@ -281,10 +272,7 @@ public void syncDrafts_withExistingShuffledCategoriesWithChangingCategoryHierarc
281272
final CategorySyncStatistics syncStatistics = syncBatches(categorySync, batches,
282273
CompletableFuture.completedFuture(null)).toCompletableFuture().join();
283274

284-
assertThat(syncStatistics.getReportMessage())
285-
.isEqualTo(format("Summary: %d categories were processed in total (%d created, %d updated, %d failed to "
286-
+ "sync and %s categories with a missing parent).", 130, 0, 120, 0, 0));
287-
275+
assertThat(syncStatistics).hasValues(130, 0, 120, 0, 0);
288276
assertThat(callBackErrorResponses).isEmpty();
289277
assertThat(callBackExceptions).isEmpty();
290278
assertThat(callBackWarningResponses).isEmpty();
@@ -327,10 +315,7 @@ public void syncDrafts_withExistingCategoriesThatChangeParents_ShouldUpdateCateg
327315
final CategorySyncStatistics syncStatistics = syncBatches(categorySync, batches,
328316
CompletableFuture.completedFuture(null)).toCompletableFuture().join();
329317

330-
assertThat(syncStatistics.getReportMessage())
331-
.isEqualTo(format("Summary: %d categories were processed in total (%d created, %d updated, %d failed to "
332-
+ "sync and %s categories with a missing parent).", 3, 0, 1, 0, 0));
333-
318+
assertThat(syncStatistics).hasValues(3, 0, 1, 0, 0);
334319
assertThat(callBackErrorResponses).isEmpty();
335320
assertThat(callBackExceptions).isEmpty();
336321
assertThat(callBackWarningResponses).isEmpty();
@@ -399,10 +384,7 @@ public void syncDrafts_withANonExistingNewParent_ShouldUpdateCategories() {
399384
final CategorySyncStatistics syncStatistics = syncBatches(categorySync, batches,
400385
CompletableFuture.completedFuture(null)).toCompletableFuture().join();
401386

402-
assertThat(syncStatistics.getReportMessage())
403-
.isEqualTo(format("Summary: %d categories were processed in total (%d created, %d updated, %d failed to "
404-
+ "sync and %s categories with a missing parent).", 2, 1, 1, 0, 0));
405-
387+
assertThat(syncStatistics).hasValues(2, 1, 1, 0, 0);
406388
assertThat(callBackErrorResponses).isEmpty();
407389
assertThat(callBackExceptions).isEmpty();
408390
assertThat(callBackWarningResponses).isEmpty();
@@ -451,10 +433,7 @@ public void syncDrafts_fromCategoriesWithoutKeys_ShouldNotUpdateCategories() {
451433

452434
final CategorySyncStatistics syncStatistics = categorySync.sync(categoryDrafts).toCompletableFuture().join();
453435

454-
assertThat(syncStatistics.getReportMessage())
455-
.isEqualTo(format("Summary: %d categories were processed in total (%d created, %d updated, %d failed to "
456-
+ "sync and %s categories with a missing parent).", 2, 0, 0, 2, 0));
457-
436+
assertThat(syncStatistics).hasValues(2, 0, 0, 2, 0);
458437
assertThat(callBackErrorResponses).hasSize(2);
459438
assertThat(callBackErrorResponses.get(0))
460439
.containsPattern("A duplicate value '.*' exists for field 'slug\\.en' on ");

src/integration-test/java/com/commercetools/sync/integration/ctpprojectsource/products/ProductReferenceResolverIT.java

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import java.util.Locale;
2626
import java.util.concurrent.CompletionException;
2727

28+
import static com.commercetools.sync.commons.asserts.statistics.AssertionsForStatistics.assertThat;
2829
import static com.commercetools.sync.integration.commons.utils.CategoryITUtils.OLD_CATEGORY_CUSTOM_TYPE_KEY;
2930
import static com.commercetools.sync.integration.commons.utils.CategoryITUtils.OLD_CATEGORY_CUSTOM_TYPE_NAME;
3031
import static com.commercetools.sync.integration.commons.utils.CategoryITUtils.createCategories;
@@ -46,7 +47,7 @@
4647
import static com.commercetools.sync.products.utils.ProductReferenceReplacementUtils.buildProductQuery;
4748
import static com.commercetools.sync.products.utils.ProductReferenceReplacementUtils.replaceProductsReferenceIdsWithKeys;
4849
import static java.lang.String.format;
49-
import static org.assertj.core.api.Java6Assertions.assertThat;
50+
import static org.assertj.core.api.Assertions.assertThat;
5051

5152
public class ProductReferenceResolverIT {
5253
private static ProductType productTypeSource;
@@ -142,10 +143,7 @@ public void sync_withNewProductWithExistingCategoryAndProductTypeReferences_Shou
142143

143144
final ProductSyncStatistics syncStatistics = productSync.sync(productDrafts).toCompletableFuture().join();
144145

145-
assertThat(syncStatistics.getReportMessage())
146-
.isEqualTo(format("Summary: %d products were processed in total (%d created, %d updated and %d products"
147-
+ " failed to sync).", 1, 1, 0, 0));
148-
146+
assertThat(syncStatistics).hasValues(1, 1, 0, 0);
149147
assertThat(errorCallBackMessages).isEmpty();
150148
assertThat(errorCallBackExceptions).isEmpty();
151149
assertThat(warningCallBackMessages).hasSize(1);
@@ -167,10 +165,7 @@ public void sync_withNewProductWithNoProductTypeKey_ShouldFailCreatingTheProduct
167165

168166
final ProductSyncStatistics syncStatistics = productSync.sync(productDrafts).toCompletableFuture().join();
169167

170-
assertThat(syncStatistics.getReportMessage())
171-
.isEqualTo(format("Summary: %d products were processed in total (%d created, %d updated and %d products"
172-
+ " failed to sync).", 1, 0, 0, 1));
173-
168+
assertThat(syncStatistics).hasValues(1, 0, 0, 1);
174169
assertThat(errorCallBackMessages).hasSize(1);
175170
assertThat(errorCallBackMessages.get(0)).isEqualTo(format("Failed to resolve references on ProductDraft with"
176171
+ " key:'%s'. Reason: %s: Failed to resolve product type reference on ProductDraft with key:'%s'."

src/integration-test/java/com/commercetools/sync/integration/ctpprojectsource/products/ProductSyncIT.java

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import java.util.List;
3838
import java.util.Locale;
3939

40+
import static com.commercetools.sync.commons.asserts.statistics.AssertionsForStatistics.assertThat;
4041
import static com.commercetools.sync.integration.commons.utils.CategoryITUtils.OLD_CATEGORY_CUSTOM_TYPE_KEY;
4142
import static com.commercetools.sync.integration.commons.utils.CategoryITUtils.OLD_CATEGORY_CUSTOM_TYPE_NAME;
4243
import static com.commercetools.sync.integration.commons.utils.CategoryITUtils.createCategories;
@@ -66,8 +67,7 @@
6667
import static com.commercetools.sync.products.ProductSyncMockUtils.getProductReferenceWithId;
6768
import static com.commercetools.sync.products.utils.ProductReferenceReplacementUtils.buildProductQuery;
6869
import static com.commercetools.sync.products.utils.ProductReferenceReplacementUtils.replaceProductsReferenceIdsWithKeys;
69-
import static java.lang.String.format;
70-
import static org.assertj.core.api.Java6Assertions.assertThat;
70+
import static org.assertj.core.api.Assertions.assertThat;
7171

7272
public class ProductSyncIT {
7373
private static ProductType sourceProductType;
@@ -192,10 +192,7 @@ public void sync_withChangesOnly_ShouldUpdateProducts() {
192192

193193
final ProductSyncStatistics syncStatistics = productSync.sync(productDrafts).toCompletableFuture().join();
194194

195-
assertThat(syncStatistics.getReportMessage())
196-
.isEqualTo(format("Summary: %d products were processed in total (%d created, %d updated and %d products"
197-
+ " failed to sync).", 1, 0, 1, 0));
198-
195+
assertThat(syncStatistics).hasValues(1, 0, 1, 0);
199196
assertThat(errorCallBackMessages).isEmpty();
200197
assertThat(errorCallBackExceptions).isEmpty();
201198
assertThat(warningCallBackMessages).isEmpty();
@@ -225,10 +222,7 @@ public void sync_withChangesOnlyAndUnPublish_ShouldUpdateProducts() {
225222

226223
final ProductSyncStatistics syncStatistics = productSync.sync(productDrafts).toCompletableFuture().join();
227224

228-
assertThat(syncStatistics.getReportMessage())
229-
.isEqualTo(format("Summary: %d products were processed in total (%d created, %d updated and %d products"
230-
+ " failed to sync).", 1, 0, 1, 0));
231-
225+
assertThat(syncStatistics).hasValues(1, 0, 1, 0);
232226
assertThat(errorCallBackMessages).isEmpty();
233227
assertThat(errorCallBackExceptions).isEmpty();
234228
assertThat(warningCallBackMessages).isEmpty();
@@ -267,10 +261,7 @@ public void sync_withPriceChannels_ShouldUpdateProducts() {
267261

268262
final ProductSyncStatistics syncStatistics = productSync.sync(productDrafts).toCompletableFuture().join();
269263

270-
assertThat(syncStatistics.getReportMessage())
271-
.isEqualTo(format("Summary: %d products were processed in total (%d created, %d updated and %d products"
272-
+ " failed to sync).", 1, 0, 1, 0));
273-
264+
assertThat(syncStatistics).hasValues(1, 0, 1, 0);
274265
assertThat(errorCallBackMessages).isEmpty();
275266
assertThat(errorCallBackExceptions).isEmpty();
276267
assertThat(warningCallBackMessages).isEmpty();
@@ -367,10 +358,7 @@ public void sync_withProductTypeReference_ShouldUpdateProducts() {
367358

368359
final ProductSyncStatistics syncStatistics = customSync.sync(productDrafts).toCompletableFuture().join();
369360

370-
assertThat(syncStatistics.getReportMessage())
371-
.isEqualTo(format("Summary: %d products were processed in total (%d created, %d updated and %d products"
372-
+ " failed to sync).", 3, 0, 1, 0));
373-
361+
assertThat(syncStatistics).hasValues(3, 0, 1, 0);
374362
assertThat(errorCallBackMessages).isEmpty();
375363
assertThat(errorCallBackExceptions).isEmpty();
376364
assertThat(warningCallBackMessages).isEmpty();

0 commit comments

Comments
 (0)