@@ -1015,6 +1015,121 @@ void sync_shouldSyncProductsWithoutAnyVariants() {
10151015 assertThat (syncStatistics ).hasValues (2 , 1 , 1 , 0 , 0 );
10161016 }
10171017
1018+ @ Test
1019+ void sync_withNoChangesInIntegerAttribute_shouldNotUpdateTheProduct () {
1020+ // preparation
1021+ final List <ProductUpdateAction > updateActions = new ArrayList <>();
1022+ final TriConsumer <SyncException , Optional <ProductDraft >, Optional <ProductProjection >>
1023+ warningCallBack =
1024+ (exception , newResource , oldResource ) ->
1025+ warningCallBackMessages .add (exception .getMessage ());
1026+
1027+ final ProductSyncOptions customOptions =
1028+ ProductSyncOptionsBuilder .of (TestClientUtils .CTP_TARGET_CLIENT )
1029+ .errorCallback (
1030+ (exception , oldResource , newResource , actions ) ->
1031+ collectErrors (exception .getMessage (), exception .getCause ()))
1032+ .warningCallback (warningCallBack )
1033+ .beforeUpdateCallback (
1034+ (actions , draft , old ) -> {
1035+ updateActions .addAll (actions );
1036+ return actions ;
1037+ })
1038+ .build ();
1039+
1040+ final ProductDraft productDraft =
1041+ createProductDraftBuilder (
1042+ PRODUCT_KEY_1_RESOURCE_PATH ,
1043+ ProductTypeResourceIdentifierBuilder .of ().key (productType .getKey ()).build ())
1044+ .categories (emptyList ())
1045+ .taxCategory ((TaxCategoryResourceIdentifier ) null )
1046+ .state ((StateResourceIdentifier ) null )
1047+ .build ();
1048+
1049+ // Creating the attribute draft with the changes
1050+ final Attribute sortAttrDraft = AttributeBuilder .of ().name ("sort" ).value (10 ).build ();
1051+
1052+ // Creating the product variant draft with the product reference attribute
1053+ final List <Attribute > attributes = singletonList (sortAttrDraft );
1054+
1055+ final ProductVariantDraft masterVariant =
1056+ ProductVariantDraftBuilder .of (productDraft .getMasterVariant ())
1057+ .attributes (attributes )
1058+ .build ();
1059+
1060+ final ProductDraft productDraftWithChangedAttributes =
1061+ ProductDraftBuilder .of (productDraft ).masterVariant (masterVariant ).build ();
1062+
1063+ // test
1064+ final ProductSync productSync = new ProductSync (customOptions );
1065+ productSync .sync (singletonList (productDraftWithChangedAttributes )).toCompletableFuture ().join ();
1066+ final ProductSyncStatistics syncStatistics =
1067+ productSync
1068+ .sync (singletonList (productDraftWithChangedAttributes ))
1069+ .toCompletableFuture ()
1070+ .join ();
1071+
1072+ assertThat (syncStatistics ).hasValues (2 , 0 , 1 , 0 , 0 );
1073+ }
1074+
1075+ @ Test
1076+ void sync_withNoChangesInLenumAttribute_shouldNotUpdateTheProduct () {
1077+ // preparation
1078+ final List <ProductUpdateAction > updateActions = new ArrayList <>();
1079+ final TriConsumer <SyncException , Optional <ProductDraft >, Optional <ProductProjection >>
1080+ warningCallBack =
1081+ (exception , newResource , oldResource ) ->
1082+ warningCallBackMessages .add (exception .getMessage ());
1083+
1084+ final ProductSyncOptions customOptions =
1085+ ProductSyncOptionsBuilder .of (TestClientUtils .CTP_TARGET_CLIENT )
1086+ .errorCallback (
1087+ (exception , oldResource , newResource , actions ) ->
1088+ collectErrors (exception .getMessage (), exception .getCause ()))
1089+ .warningCallback (warningCallBack )
1090+ .beforeUpdateCallback (
1091+ (actions , draft , old ) -> {
1092+ updateActions .addAll (actions );
1093+ return actions ;
1094+ })
1095+ .build ();
1096+
1097+ final ProductDraft productDraft =
1098+ createProductDraftBuilder (
1099+ PRODUCT_KEY_1_RESOURCE_PATH ,
1100+ ProductTypeResourceIdentifierBuilder .of ().key (productType .getKey ()).build ())
1101+ .categories (emptyList ())
1102+ .taxCategory ((TaxCategoryResourceIdentifier ) null )
1103+ .state ((StateResourceIdentifier ) null )
1104+ .build ();
1105+
1106+ // Creating the attribute draft with the changes
1107+ final Attribute technologyAttrDraft =
1108+ AttributeBuilder .of ().name ("technology" ).value ("laser" ).build ();
1109+
1110+ // Creating the product variant draft with the product reference attribute
1111+ final List <Attribute > attributes = singletonList (technologyAttrDraft );
1112+
1113+ final ProductVariantDraft masterVariant =
1114+ ProductVariantDraftBuilder .of (productDraft .getMasterVariant ())
1115+ .attributes (attributes )
1116+ .build ();
1117+
1118+ final ProductDraft productDraftWithChangedAttributes =
1119+ ProductDraftBuilder .of (productDraft ).masterVariant (masterVariant ).build ();
1120+
1121+ // test
1122+ final ProductSync productSync = new ProductSync (customOptions );
1123+ productSync .sync (singletonList (productDraftWithChangedAttributes )).toCompletableFuture ().join ();
1124+ final ProductSyncStatistics syncStatistics =
1125+ productSync
1126+ .sync (singletonList (productDraftWithChangedAttributes ))
1127+ .toCompletableFuture ()
1128+ .join ();
1129+
1130+ assertThat (syncStatistics ).hasValues (2 , 0 , 1 , 0 , 0 );
1131+ }
1132+
10181133 @ Test
10191134 void sync_withProductContainingAttributeChanges_shouldSyncProductCorrectly () {
10201135 // preparation
0 commit comments