Skip to content

Commit 066f03f

Browse files
refactor: delete the products
1 parent a891cc4 commit 066f03f

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

src/benchmark/java/com/commercetools/sync/benchmark/ProductTypeSyncBenchmark.java

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import static com.commercetools.sync.commons.asserts.statistics.AssertionsForStatistics.assertThat;
55
import static com.commercetools.sync.integration.commons.utils.ProductITUtils.deleteAllProducts;
66
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;
88
import static com.commercetools.sync.integration.commons.utils.TestClientUtils.CTP_TARGET_CLIENT;
99
import static java.lang.String.format;
1010
import static java.util.Collections.singletonList;
@@ -52,15 +52,16 @@ class ProductTypeSyncBenchmark {
5252
@AfterAll
5353
static void tearDown() {
5454
deleteAllProducts(CTP_TARGET_CLIENT);
55-
deleteProductTypes(CTP_TARGET_CLIENT);
55+
removeAttributeReferencesAndDeleteProductTypes(CTP_TARGET_CLIENT);
5656
}
5757

5858
@BeforeEach
5959
void setupTest() {
6060
clearSyncTestCollections();
6161
// Delete products first because they reference product types
6262
deleteAllProducts(CTP_TARGET_CLIENT);
63-
deleteProductTypes(CTP_TARGET_CLIENT);
63+
// Remove attribute references between product types before deleting them
64+
removeAttributeReferencesAndDeleteProductTypes(CTP_TARGET_CLIENT);
6465
productTypeSyncOptions = buildSyncOptions();
6566
}
6667

@@ -94,6 +95,23 @@ private void clearSyncTestCollections() {
9495

9596
@Test
9697
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+
97115
// preparation
98116
final List<ProductTypeDraft> productTypeDrafts =
99117
buildProductTypeDrafts(NUMBER_OF_RESOURCE_UNDER_TEST);

0 commit comments

Comments
 (0)