|
5 | 5 | import static com.commercetools.sync.integration.commons.utils.ProductTypeITUtils.PRODUCT_TYPE_DESCRIPTION_5; |
6 | 6 | import static com.commercetools.sync.integration.commons.utils.ProductTypeITUtils.PRODUCT_TYPE_KEY_5; |
7 | 7 | import static com.commercetools.sync.integration.commons.utils.ProductTypeITUtils.PRODUCT_TYPE_NAME_5; |
| 8 | +import static com.commercetools.sync.integration.commons.utils.ProductTypeITUtils.assertAttributesAreEqual; |
| 9 | +import static com.commercetools.sync.integration.commons.utils.ProductTypeITUtils.getProductTypeByKey; |
8 | 10 | import static com.commercetools.sync.integration.commons.utils.ProductTypeITUtils.populateProjectWithNestedAttributes; |
9 | 11 | import static com.commercetools.sync.integration.commons.utils.ProductTypeITUtils.removeAttributeReferencesAndDeleteProductTypes; |
10 | 12 | import static com.commercetools.sync.integration.commons.utils.TestClientUtils.CTP_SOURCE_CLIENT; |
11 | 13 | import static com.commercetools.sync.integration.commons.utils.TestClientUtils.CTP_TARGET_CLIENT; |
12 | 14 | import static org.assertj.core.api.Assertions.assertThat; |
13 | 15 |
|
14 | 16 | import com.commercetools.api.models.common.LocalizedString; |
| 17 | +import com.commercetools.api.models.product_type.AttributeDefinition; |
15 | 18 | import com.commercetools.api.models.product_type.AttributeDefinitionDraft; |
16 | 19 | import com.commercetools.api.models.product_type.AttributeDefinitionDraftBuilder; |
17 | 20 | import com.commercetools.api.models.product_type.AttributeNestedType; |
18 | 21 | import com.commercetools.api.models.product_type.AttributeNestedTypeBuilder; |
| 22 | +import com.commercetools.api.models.product_type.AttributeSetType; |
19 | 23 | import com.commercetools.api.models.product_type.AttributeSetTypeBuilder; |
20 | 24 | import com.commercetools.api.models.product_type.ProductType; |
21 | 25 | import com.commercetools.api.models.product_type.ProductTypeChangeLabelActionBuilder; |
22 | 26 | import com.commercetools.api.models.product_type.ProductTypeDraft; |
23 | 27 | import com.commercetools.api.models.product_type.ProductTypeDraftBuilder; |
24 | 28 | import com.commercetools.api.models.product_type.ProductTypePagedQueryResponse; |
| 29 | +import com.commercetools.api.models.product_type.ProductTypeReference; |
25 | 30 | import com.commercetools.api.models.product_type.ProductTypeReferenceBuilder; |
26 | 31 | import com.commercetools.api.models.product_type.ProductTypeUpdateAction; |
27 | 32 | import com.commercetools.sync.commons.utils.CaffeineReferenceIdToKeyCacheImpl; |
|
34 | 39 | import io.vrap.rmf.base.client.ApiHttpResponse; |
35 | 40 | import java.util.ArrayList; |
36 | 41 | import java.util.List; |
| 42 | +import java.util.Optional; |
37 | 43 | import java.util.stream.Collectors; |
38 | 44 | import org.junit.jupiter.api.AfterAll; |
39 | 45 | import org.junit.jupiter.api.BeforeEach; |
@@ -133,20 +139,12 @@ void sync_WithProductTypeReferencingItselfAsAttribute_ShouldCreateProductType() |
133 | 139 | .type( |
134 | 140 | AttributeSetTypeBuilder.of() |
135 | 141 | .elementType( |
136 | | - AttributeSetTypeBuilder.of() |
137 | | - .elementType( |
138 | | - AttributeSetTypeBuilder.of() |
139 | | - .elementType( |
140 | | - AttributeNestedTypeBuilder.of() |
141 | | - .typeReference( |
142 | | - ProductTypeReferenceBuilder.of() |
143 | | - .id(PRODUCT_TYPE_KEY_5) |
144 | | - .build()) |
145 | | - .build()) |
146 | | - .build()) |
| 142 | + AttributeNestedTypeBuilder.of() |
| 143 | + .typeReference( |
| 144 | + ProductTypeReferenceBuilder.of().id(PRODUCT_TYPE_KEY_5).build()) |
147 | 145 | .build()) |
148 | 146 | .build()) |
149 | | - .isSearchable(false) |
| 147 | + .isSearchable(true) |
150 | 148 | .isRequired(false) |
151 | 149 | .build(); |
152 | 150 |
|
@@ -190,6 +188,26 @@ void sync_WithProductTypeReferencingItselfAsAttribute_ShouldCreateProductType() |
190 | 188 | "Summary: 1 product types were processed in total" |
191 | 189 | + " (1 created, 0 updated, 0 failed to sync and 0 product types with at least one NestedType or a Set" |
192 | 190 | + " of NestedType attribute definition(s) referencing a missing product type)."); |
| 191 | + |
| 192 | + final Optional<ProductType> newProductType = |
| 193 | + getProductTypeByKey(CTP_TARGET_CLIENT, PRODUCT_TYPE_KEY_5); |
| 194 | + assertThat(newProductType).isPresent(); |
| 195 | + assertThat(newProductType) |
| 196 | + .hasValueSatisfying( |
| 197 | + productType -> { |
| 198 | + assertAttributesAreEqual(productType.getAttributes(), List.of(nestedTypeAttr)); |
| 199 | + final AttributeDefinition attributeDefinition1 = productType.getAttributes().get(0); |
| 200 | + assertThat(attributeDefinition1.getType()).isInstanceOf(AttributeSetType.class); |
| 201 | + final AttributeSetType attributeSetType = |
| 202 | + (AttributeSetType) attributeDefinition1.getType(); |
| 203 | + assertThat(attributeSetType.getElementType()).isInstanceOf(AttributeNestedType.class); |
| 204 | + final AttributeNestedType attributeNestedType = |
| 205 | + (AttributeNestedType) attributeSetType.getElementType(); |
| 206 | + assertThat(attributeNestedType.getTypeReference()) |
| 207 | + .isInstanceOf(ProductTypeReference.class); |
| 208 | + assertThat(attributeNestedType.getTypeReference().getId()) |
| 209 | + .isEqualTo(productType.getId()); |
| 210 | + }); |
193 | 211 | } |
194 | 212 |
|
195 | 213 | @Test |
|
0 commit comments