Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate product sync and ITs to java sdk v2 #947

Conversation

lojzatran
Copy link
Collaborator

@lojzatran lojzatran commented Apr 20, 2023

Summary

Main changes: https://github.com/commercetools/commercetools-sync-java/pull/947/files#diff-98a7b2c5b9b1ea946cc5fc3ded767a6a5395f36a81b18a8017f24bea79fd0e14, https://github.com/commercetools/commercetools-sync-java/pull/947/files#diff-d8e12c9e202ba3b3ac24469897c21c425021fa437481fddc3004f8f62927672f

Errors fixed in this PR

  1. Fixed this error:
{
  "statusCode" : 400,
  "message" : "Request body does not contain valid JSON.",
  "errors" : [ {
    "code" : "InvalidJsonInput",
    "message" : "Request body does not contain valid JSON.",
    "detailedErrorMessage" : "masterVariant -> prices -> channel: ResourceIdentifier requires an 'id' xor a 'key' but was id:3313a01a-fdad-49ff-9cda-1f4e8e0b4764 and key:missingKey"
  } ]
}

The problem was when using ResourceIdentifier we can set either key or id, but not both. dd113f1

  1. When categoryOrderHints is an empty object in the product, it is represented as null in Java object. Therefore we have to check to avoid NPE.

  2. I renamed the method createObjectFromResource to readObjectFromResource. Even though the name createObjectFromResource might be slightly better, it was impossible for me to find this method by name when I'm migrating the old code. In the old sdk we have a method called readObjectFromResource. So whenever I migrate the code, I expect a method with the same name exists for sdk v2. Lesson learnt: always keep the same name for the common methods so that they're easy to find.


Problem I could not fix

In the old test there was an integration test that verifies that in the method ProductSync.fetchAndUpdate() whenever sync fails to update with CT error, the sync would fail with a correct error message etc. This was achieved in the past mocking the execute method with ProductUpdate params. The other methods that fetches from CT were not mocked and were really calling CT. This is not possible anymore with the new sdk v2. To update a product now we have to call sth like products().update().execute(). So that means we have to mock products(), update() and execute(). However, when we mock products(), we also return the mock for all previous fetches that uses this endpoint in the sync (e.g. products().withKey().get().execute()), so we have to mock them too. So these kind of tests where you mock only the calls you need and the rest are real method calls are not possible anymore.


The rest I had to adapt to ProductSync.java class and its integration tests working. In tests I changed create methods to ensure methods because they were failing too much with Concurrency Exception. Afterwards the tests were not failing anymore.

@codecov-commenter
Copy link

codecov-commenter commented Apr 24, 2023

Codecov Report

Merging #947 (355b9b9) into java-sdk-v2-product-reference-resolver (a7f161d) will decrease coverage by 1.27%.
The diff coverage is 72.50%.

@@                             Coverage Diff                              @@
##             java-sdk-v2-product-reference-resolver     #947      +/-   ##
============================================================================
- Coverage                                     96.53%   95.26%   -1.27%     
- Complexity                                     3755     3921     +166     
============================================================================
  Files                                           328      339      +11     
  Lines                                         10703    11366     +663     
  Branches                                        633      688      +55     
============================================================================
+ Hits                                          10332    10828     +496     
- Misses                                          271      424     +153     
- Partials                                        100      114      +14     
Impacted Files Coverage Δ
...2/categories/models/CategoryCustomTypeAdapter.java 0.00% <0.00%> (ø)
...nc/sdk2/commons/helpers/BaseReferenceResolver.java 54.54% <0.00%> (-9.10%) ⬇️
...ync/sdk2/services/impl/ProductTypeServiceImpl.java 98.33% <ø> (+6.66%) ⬆️
...services/impl/UnresolvedReferencesServiceImpl.java 5.08% <5.08%> (ø)
...nc/sdk2/commons/utils/ResourceIdentifierUtils.java 50.00% <50.00%> (ø)
.../sdk2/products/utils/ProductUpdateActionUtils.java 96.68% <66.66%> (+0.47%) ⬆️
.../commercetools/sync/sdk2/products/ProductSync.java 70.00% <70.00%> (ø)
...dk2/products/helpers/ProductReferenceResolver.java 73.93% <73.93%> (ø)
...tools/sync/sdk2/products/utils/AttributeUtils.java 87.50% <87.50%> (ø)
...ync/sdk2/commons/utils/CompletableFutureUtils.java 88.00% <88.00%> (ø)
... and 13 more

... and 7 files with indirect coverage changes

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@lojzatran lojzatran marked this pull request as ready for review April 25, 2023 09:09
Copy link
Contributor

@salander85 salander85 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

…dk2/ctpprojectsource/products/ProductSyncIT.java

Co-authored-by: Sarah Lander <70885646+salander85@users.noreply.github.com>
@lojzatran lojzatran merged commit b2e8799 into java-sdk-v2-product-reference-resolver Apr 26, 2023
@lojzatran lojzatran deleted the java-sdk-v2-product-sync-and-tests branch April 26, 2023 07:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants