This repository is for active development of the Azure SDK for Java. For consumers of the SDK we recommend visiting our public developer docs at https://docs.microsoft.com/java/azure/ or our versioned developer docs at https://azure.github.io/azure-sdk-for-java.
MIT License
2.3k
stars
1.96k
forks
source link
[FEATURE REQ] Make `CosmosPatchOperations#getPatchOperations()` public to allow easier testing (mocking and asserting) #41214
Is your feature request related to a problem? Please describe.
Very similarly to a completed issue in the .NET library, it would be beneficial if we could access the patchOperations list within CosmosPatchOperations for testing purposes.
(Following examples are based on AddressRepositoryIT.java within azure-spring-data-cosmos)
// This and following examples are based on AddressRepositoryIT.java#testPatchEntitySet() within azure-spring-data-cosmos
var patchSetOperations = CosmosPatchOperations.create()
.set("/street", TestConstants.NEW_STREET);
// calling from spring-cosmos's .save() method
repository.save(TestConstants.POSTAL_CODE, new PartitionKey(CITY), Address.class, patchSetOperations);
I would like to be able to validate if the patchOperations contains the necessary changes, in this case, if the "/street" path has the new TestConstants.NEW_STREET value.
Describe the solution you'd like
I would like the getter method (List<PatchOperation> getPatchOperations()) to be public in CosmosPatchOperations, so that I can make assertions on the values in a patchOperation.
var operations = patchSetOperation.getPatchOperations();
var changedValue = ((PatchOperationCore<String>) operations.get(0)).getResource();
assertThat(changedValue).isEqualTo(TestConstants.NEW_STREET);
Describe alternatives you've considered
Currently I can see that the package-private getPatchOperations is used from ModelBridgeInternal, which has a public static method named getPatchOperationsFromCosmosPatch(), but it has a warning that says "Internal use only, not meant for public usage as this API may change in future". Not exactly sure if it's referring to this static method or even the underlying package-private getPatchOperations method as well. But as this warning is there, I wouldn't try to rely on it.
var operations = ModelBridgeInternal.getPatchOperationsFromCosmosPatch(patchSetOperation);
var changedValue = ((PatchOperationCore<String>) operations.get(0)).getResource();
assertThat(changedValue).isEqualTo(TestConstants.NEW_STREET);
Additional context
I'm happy to create a PR if the proposed solution is acceptable.
Information Checklist
Kindly make sure that you have added all the following information above and checkoff the required fields otherwise we will treat the issuer as an incomplete report
Is your feature request related to a problem? Please describe.
Very similarly to a completed issue in the .NET library, it would be beneficial if we could access the
patchOperations
list withinCosmosPatchOperations
for testing purposes. (Following examples are based on AddressRepositoryIT.java within azure-spring-data-cosmos)I would like to be able to validate if the
patchOperations
contains the necessary changes, in this case, if the"/street"
path has the newTestConstants.NEW_STREET
value.Describe the solution you'd like
I would like the getter method (
List<PatchOperation> getPatchOperations()
) to bepublic
inCosmosPatchOperations
, so that I can make assertions on the values in a patchOperation.Describe alternatives you've considered
Currently I can see that the package-private
getPatchOperations
is used fromModelBridgeInternal
, which has apublic static
method namedgetPatchOperationsFromCosmosPatch()
, but it has a warning that says"Internal use only, not meant for public usage as this API may change in future"
. Not exactly sure if it's referring to this static method or even the underlying package-privategetPatchOperations
method as well. But as this warning is there, I wouldn't try to rely on it.Additional context I'm happy to create a PR if the proposed solution is acceptable.
Information Checklist Kindly make sure that you have added all the following information above and checkoff the required fields otherwise we will treat the issuer as an incomplete report