|
4 | 4 | import static com.commercetools.sync.commons.asserts.statistics.AssertionsForStatistics.assertThat; |
5 | 5 | import static com.commercetools.sync.integration.commons.utils.ProductITUtils.deleteAllProducts; |
6 | 6 | import static com.commercetools.sync.integration.commons.utils.ProductTypeITUtils.ATTRIBUTE_DEFINITION_DRAFT_1; |
7 | | -import static com.commercetools.sync.integration.commons.utils.ProductTypeITUtils.deleteProductTypes; |
| 7 | +import static com.commercetools.sync.integration.commons.utils.ProductTypeITUtils.removeAttributeReferencesAndDeleteProductTypes; |
8 | 8 | import static com.commercetools.sync.integration.commons.utils.TestClientUtils.CTP_TARGET_CLIENT; |
9 | 9 | import static java.lang.String.format; |
10 | 10 | import static java.util.Collections.singletonList; |
@@ -52,15 +52,16 @@ class ProductTypeSyncBenchmark { |
52 | 52 | @AfterAll |
53 | 53 | static void tearDown() { |
54 | 54 | deleteAllProducts(CTP_TARGET_CLIENT); |
55 | | - deleteProductTypes(CTP_TARGET_CLIENT); |
| 55 | + removeAttributeReferencesAndDeleteProductTypes(CTP_TARGET_CLIENT); |
56 | 56 | } |
57 | 57 |
|
58 | 58 | @BeforeEach |
59 | 59 | void setupTest() { |
60 | 60 | clearSyncTestCollections(); |
61 | 61 | // Delete products first because they reference product types |
62 | 62 | deleteAllProducts(CTP_TARGET_CLIENT); |
63 | | - deleteProductTypes(CTP_TARGET_CLIENT); |
| 63 | + // Remove attribute references between product types before deleting them |
| 64 | + removeAttributeReferencesAndDeleteProductTypes(CTP_TARGET_CLIENT); |
64 | 65 | productTypeSyncOptions = buildSyncOptions(); |
65 | 66 | } |
66 | 67 |
|
@@ -94,6 +95,23 @@ private void clearSyncTestCollections() { |
94 | 95 |
|
95 | 96 | @Test |
96 | 97 | void sync_NewProductTypes_ShouldCreateProductTypes() throws IOException { |
| 98 | + // Verify the project is clean before starting |
| 99 | + final Integer initialProductTypeCount = |
| 100 | + CTP_TARGET_CLIENT |
| 101 | + .productTypes() |
| 102 | + .get() |
| 103 | + .execute() |
| 104 | + .thenApply(ApiHttpResponse::getBody) |
| 105 | + .thenApply(ProductTypePagedQueryResponse::getTotal) |
| 106 | + .thenApply(Long::intValue) |
| 107 | + .toCompletableFuture() |
| 108 | + .join(); |
| 109 | + assertThat(initialProductTypeCount) |
| 110 | + .withFailMessage( |
| 111 | + "Project should be clean before benchmark, but found %d product types", |
| 112 | + initialProductTypeCount) |
| 113 | + .isZero(); |
| 114 | + |
97 | 115 | // preparation |
98 | 116 | final List<ProductTypeDraft> productTypeDrafts = |
99 | 117 | buildProductTypeDrafts(NUMBER_OF_RESOURCE_UNDER_TEST); |
|
0 commit comments