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

Adding fix for SLING-8974 #26

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Conversation

pat-lego
Copy link
Contributor

Added unit test to validate NonExistingResource and Post Servlet Returns a 400

@rombert
Copy link
Contributor

rombert commented Nov 27, 2023

@kwin @stefanseifert - any thoughts on this? Look OK to me, but I don't know this area in depth.

@pat-lego
Copy link
Contributor Author

Please note that this PR returns a 400 in the case of a NonExistingResource as agreed upon here: https://issues.apache.org/jira/browse/SLING-8974?focusedCommentId=17764586&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-17764586

Copy link
Contributor

@joerghoh joerghoh left a comment

Choose a reason for hiding this comment

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

LGTM, although that improvement in the test would be nice.


public class DeleteOperationTest {

@Test
Copy link
Contributor

Choose a reason for hiding this comment

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

instead of doing the exception handling in this method in the try-catch block you can mark this test to expect to fail with that exception.

Suggested change
@Test
@Test(expected=ResourceNotFoundException.class)

Method doRun = deleteOperation.getClass().getDeclaredMethod("doRun", SlingHttpServletRequest.class, PostResponse.class, List.class);
doRun.setAccessible(true);

try {
Copy link
Contributor

Choose a reason for hiding this comment

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

see above

Copy link
Contributor

@enapps-enorman enapps-enorman left a comment

Choose a reason for hiding this comment

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

Please see my review comments related to handling for delete of non-existing resources specified via ":applyTo" request parameters.

Also, there still seems to be some backward incompatibly with the previous behavior. Perhaps that can be sufficiently dealt with via new documentation?

@@ -69,6 +71,9 @@ protected void doRun(final SlingHttpServletRequest request,
final Iterator<Resource> res = getApplyToResources(request);
if (res == null) {
final Resource resource = request.getResource();
if (resource instanceof NonExistingResource) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this could still use some clarification about what should happen in the alternate code path where the resources to delete are provided by one or more ":applyTo" request parameters. If I am not mistaken, this looks like you are only checking if the resource exists in the simple case where the resource to delete is itself and no ":applyTo" arguments are provided?

public class DeleteOperationTest {

@Test
public void testDeletingNonExistingResource() throws Exception {
Copy link
Contributor

Choose a reason for hiding this comment

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

Would also be good to have a test for the scenario where the (non-existing) resource(s) to delete are provided via ":applyTo" request parameters.

@enapps-enorman enapps-enorman self-requested a review November 29, 2023 20:01
Copy link
Contributor

@enapps-enorman enapps-enorman left a comment

Choose a reason for hiding this comment

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

@pat-lego Thanks for the changes to address my concerns. It looks better to me. I see that the sonarcloud analysis has detected a new (Replace this lambda with method reference) "Code Smell" in the code that was just changed that looks like a trivial fix that could be cleaned up?

Also, it seems like the only way to solve the sonarcloud code coverage quality gate check would be to add some additional tests that cover the delete operation when the resource does exist so it touches those other code paths that were also modified. Is that something you could do?

Perhaps utilizing the sling-mock stuff for the tests could make them easier and more succinct to write with less Mockito code?

@pat-lego
Copy link
Contributor Author

@enapps-enorman I suggest that we log a new SLING ticket for that. This would require some additional work that is outside the scope of this ticket. I am in agreement that this should be done but it should be done in an appropriately described ticket.

Also, we should limit the code changes to reflect the scope of the work so that we do not include file changes that do not reflect the work being done.

I can log the appropriate ticket and when time permits start working on it.

cc: @joerghoh

@enapps-enorman
Copy link
Contributor

I suggest that we log a new SLING ticket for that. This would require some additional work that is outside the scope of this ticket.

@pat-lego I'm not opposed to further refactoring in another ticket. I was just hoping to not have merge while there are known failures in the quality gate rules. If we can get the quality gate checking to be green before merging it would be better. That would mean getting the code coverage on the changed lines from 53.3% to greater than 80%. The current report shows that the testing does not exercise 3 lines on new code and 4 conditions on new code.

Also provide new tests to improve code coverage
@enapps-enorman
Copy link
Contributor

@pat-lego After a closer look at this, it seems that any existing resources specified via ":applyTo" parameters would not get deleted after these changes since the applyTo resources iterator is consumed during the check to see if all are all existing. The second iteration would always be empty so no deleteResource calls would be performed.

I discovered this while experimenting with new tests to improve the code coverage. I have fixed the problem and refactored a bit to remove duplication. I have committed the changes to this PR at 3e371ee for the others to review.

Copy link

SonarCloud Quality Gate failed.    Quality Gate failed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

54.5% 54.5% Coverage
0.0% 0.0% Duplication

idea Catch issues before they fail your Quality Gate with our IDE extension sonarlint SonarLint

@pat-lego
Copy link
Contributor Author

pat-lego commented Dec 1, 2023

@enapps-enorman thank you for the review and additional code. I am away travelling for a few days I will take a look at this when I get back.

Copy link

sonarqubecloud bot commented May 1, 2024

Quality Gate Failed Quality Gate failed

Failed conditions
54.5% Coverage on New Code (required ≥ 80%)

See analysis details on SonarCloud

2 similar comments
Copy link

sonarqubecloud bot commented Sep 6, 2024

Quality Gate Failed Quality Gate failed

Failed conditions
54.5% Coverage on New Code (required ≥ 80%)

See analysis details on SonarCloud

Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
54.5% Coverage on New Code (required ≥ 80%)

See analysis details on SonarCloud

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.

4 participants