You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by GitBox <gi...@apache.org> on 2021/01/11 21:16:13 UTC

[GitHub] [sling-org-apache-sling-testing-resourceresolver-mock] stefanseifert opened a new pull request #2: SLING-10003 allow to provide mocked search results for findResources and queryResources

stefanseifert opened a new pull request #2:
URL: https://github.com/apache/sling-org-apache-sling-testing-resourceresolver-mock/pull/2


   alternative for PR #1 


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [sling-org-apache-sling-testing-resourceresolver-mock] sonarcloud[bot] commented on pull request #2: SLING-10003 allow to provide mocked search results for findResources and queryResources

Posted by GitBox <gi...@apache.org>.
sonarcloud[bot] commented on pull request #2:
URL: https://github.com/apache/sling-org-apache-sling-testing-resourceresolver-mock/pull/2#issuecomment-758230977


   Kudos, SonarCloud Quality Gate passed!
   
   [<img src='https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/bug.png' alt='Bug' width='16' height='16' />](https://sonarcloud.io/project/issues?id=apache_sling-org-apache-sling-testing-resourceresolver-mock&pullRequest=2&resolved=false&types=BUG) [<img src='https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A.png' alt='A' width='16' height='16' />](https://sonarcloud.io/project/issues?id=apache_sling-org-apache-sling-testing-resourceresolver-mock&pullRequest=2&resolved=false&types=BUG) [0 Bugs](https://sonarcloud.io/project/issues?id=apache_sling-org-apache-sling-testing-resourceresolver-mock&pullRequest=2&resolved=false&types=BUG)  
   [<img src='https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/vulnerability.png' alt='Vulnerability' width='16' height='16' />](https://sonarcloud.io/project/issues?id=apache_sling-org-apache-sling-testing-resourceresolver-mock&pullRequest=2&resolved=false&types=VULNERABILITY) [<img src='https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A.png' alt='A' width='16' height='16' />](https://sonarcloud.io/project/issues?id=apache_sling-org-apache-sling-testing-resourceresolver-mock&pullRequest=2&resolved=false&types=VULNERABILITY) [0 Vulnerabilities](https://sonarcloud.io/project/issues?id=apache_sling-org-apache-sling-testing-resourceresolver-mock&pullRequest=2&resolved=false&types=VULNERABILITY)  
   [<img src='https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/security_hotspot.png' alt='Security Hotspot' width='16' height='16' />](https://sonarcloud.io/project/security_hotspots?id=apache_sling-org-apache-sling-testing-resourceresolver-mock&pullRequest=2&resolved=false&types=SECURITY_HOTSPOT) [<img src='https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A.png' alt='A' width='16' height='16' />](https://sonarcloud.io/project/security_hotspots?id=apache_sling-org-apache-sling-testing-resourceresolver-mock&pullRequest=2&resolved=false&types=SECURITY_HOTSPOT) [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_sling-org-apache-sling-testing-resourceresolver-mock&pullRequest=2&resolved=false&types=SECURITY_HOTSPOT)  
   [<img src='https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/code_smell.png' alt='Code Smell' width='16' height='16' />](https://sonarcloud.io/project/issues?id=apache_sling-org-apache-sling-testing-resourceresolver-mock&pullRequest=2&resolved=false&types=CODE_SMELL) [<img src='https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A.png' alt='A' width='16' height='16' />](https://sonarcloud.io/project/issues?id=apache_sling-org-apache-sling-testing-resourceresolver-mock&pullRequest=2&resolved=false&types=CODE_SMELL) [0 Code Smells](https://sonarcloud.io/project/issues?id=apache_sling-org-apache-sling-testing-resourceresolver-mock&pullRequest=2&resolved=false&types=CODE_SMELL)
   
   [<img src='https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/CoverageChart/100.png' alt='100.0%' width='16' height='16' />](https://sonarcloud.io/component_measures?id=apache_sling-org-apache-sling-testing-resourceresolver-mock&pullRequest=2&metric=new_coverage&view=list) [100.0% Coverage](https://sonarcloud.io/component_measures?id=apache_sling-org-apache-sling-testing-resourceresolver-mock&pullRequest=2&metric=new_coverage&view=list)  
   [<img src='https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/Duplications/3.png' alt='0.0%' width='16' height='16' />](https://sonarcloud.io/component_measures?id=apache_sling-org-apache-sling-testing-resourceresolver-mock&pullRequest=2&metric=new_duplicated_lines_density&view=list) [0.0% Duplication](https://sonarcloud.io/component_measures?id=apache_sling-org-apache-sling-testing-resourceresolver-mock&pullRequest=2&metric=new_duplicated_lines_density&view=list)
   
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [sling-org-apache-sling-testing-resourceresolver-mock] sonarcloud[bot] removed a comment on pull request #2: SLING-10003 allow to provide mocked search results for findResources and queryResources

Posted by GitBox <gi...@apache.org>.
sonarcloud[bot] removed a comment on pull request #2:
URL: https://github.com/apache/sling-org-apache-sling-testing-resourceresolver-mock/pull/2#issuecomment-758230977


   Kudos, SonarCloud Quality Gate passed!
   
   [<img src='https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/bug.png' alt='Bug' width='16' height='16' />](https://sonarcloud.io/project/issues?id=apache_sling-org-apache-sling-testing-resourceresolver-mock&pullRequest=2&resolved=false&types=BUG) [<img src='https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A.png' alt='A' width='16' height='16' />](https://sonarcloud.io/project/issues?id=apache_sling-org-apache-sling-testing-resourceresolver-mock&pullRequest=2&resolved=false&types=BUG) [0 Bugs](https://sonarcloud.io/project/issues?id=apache_sling-org-apache-sling-testing-resourceresolver-mock&pullRequest=2&resolved=false&types=BUG)  
   [<img src='https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/vulnerability.png' alt='Vulnerability' width='16' height='16' />](https://sonarcloud.io/project/issues?id=apache_sling-org-apache-sling-testing-resourceresolver-mock&pullRequest=2&resolved=false&types=VULNERABILITY) [<img src='https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A.png' alt='A' width='16' height='16' />](https://sonarcloud.io/project/issues?id=apache_sling-org-apache-sling-testing-resourceresolver-mock&pullRequest=2&resolved=false&types=VULNERABILITY) [0 Vulnerabilities](https://sonarcloud.io/project/issues?id=apache_sling-org-apache-sling-testing-resourceresolver-mock&pullRequest=2&resolved=false&types=VULNERABILITY)  
   [<img src='https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/security_hotspot.png' alt='Security Hotspot' width='16' height='16' />](https://sonarcloud.io/project/security_hotspots?id=apache_sling-org-apache-sling-testing-resourceresolver-mock&pullRequest=2&resolved=false&types=SECURITY_HOTSPOT) [<img src='https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A.png' alt='A' width='16' height='16' />](https://sonarcloud.io/project/security_hotspots?id=apache_sling-org-apache-sling-testing-resourceresolver-mock&pullRequest=2&resolved=false&types=SECURITY_HOTSPOT) [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_sling-org-apache-sling-testing-resourceresolver-mock&pullRequest=2&resolved=false&types=SECURITY_HOTSPOT)  
   [<img src='https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/code_smell.png' alt='Code Smell' width='16' height='16' />](https://sonarcloud.io/project/issues?id=apache_sling-org-apache-sling-testing-resourceresolver-mock&pullRequest=2&resolved=false&types=CODE_SMELL) [<img src='https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A.png' alt='A' width='16' height='16' />](https://sonarcloud.io/project/issues?id=apache_sling-org-apache-sling-testing-resourceresolver-mock&pullRequest=2&resolved=false&types=CODE_SMELL) [0 Code Smells](https://sonarcloud.io/project/issues?id=apache_sling-org-apache-sling-testing-resourceresolver-mock&pullRequest=2&resolved=false&types=CODE_SMELL)
   
   [<img src='https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/CoverageChart/100.png' alt='100.0%' width='16' height='16' />](https://sonarcloud.io/component_measures?id=apache_sling-org-apache-sling-testing-resourceresolver-mock&pullRequest=2&metric=new_coverage&view=list) [100.0% Coverage](https://sonarcloud.io/component_measures?id=apache_sling-org-apache-sling-testing-resourceresolver-mock&pullRequest=2&metric=new_coverage&view=list)  
   [<img src='https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/Duplications/3.png' alt='0.0%' width='16' height='16' />](https://sonarcloud.io/component_measures?id=apache_sling-org-apache-sling-testing-resourceresolver-mock&pullRequest=2&metric=new_duplicated_lines_density&view=list) [0.0% Duplication](https://sonarcloud.io/component_measures?id=apache_sling-org-apache-sling-testing-resourceresolver-mock&pullRequest=2&metric=new_duplicated_lines_density&view=list)
   
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [sling-org-apache-sling-testing-resourceresolver-mock] stefanseifert merged pull request #2: SLING-10003 allow to provide mocked search results for findResources and queryResources

Posted by GitBox <gi...@apache.org>.
stefanseifert merged pull request #2:
URL: https://github.com/apache/sling-org-apache-sling-testing-resourceresolver-mock/pull/2


   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [sling-org-apache-sling-testing-resourceresolver-mock] stefanseifert commented on a change in pull request #2: SLING-10003 allow to provide mocked search results for findResources and queryResources

Posted by GitBox <gi...@apache.org>.
stefanseifert commented on a change in pull request #2:
URL: https://github.com/apache/sling-org-apache-sling-testing-resourceresolver-mock/pull/2#discussion_r555555784



##########
File path: src/main/java/org/apache/sling/testing/resourceresolver/MockResourceResolver.java
##########
@@ -447,22 +451,46 @@ public Resource getParent(@NotNull Resource child) {
         return this.getResource(parentPath);
     }
 
+    @Override
+    @SuppressWarnings("null")
+    public @NotNull Iterator<Resource> findResources(final @NotNull String query, final String language) {
+        return findResourcesHandlers.stream()
+            .map(handler -> handler.findResources(query, language))
+            .filter(Objects::nonNull)
+            .findFirst()
+            .orElse(Collections.emptyIterator());
+    }
 
-    // --- unsupported operations ---
+    /**
+     * @param handler Handler that can provide a mocked find resources result.
+     */

Review comment:
       updated docs

##########
File path: src/main/java/org/apache/sling/testing/resourceresolver/MockResourceResolver.java
##########
@@ -447,22 +451,46 @@ public Resource getParent(@NotNull Resource child) {
         return this.getResource(parentPath);
     }
 
+    @Override
+    @SuppressWarnings("null")
+    public @NotNull Iterator<Resource> findResources(final @NotNull String query, final String language) {
+        return findResourcesHandlers.stream()
+            .map(handler -> handler.findResources(query, language))
+            .filter(Objects::nonNull)
+            .findFirst()
+            .orElse(Collections.emptyIterator());
+    }
 
-    // --- unsupported operations ---
+    /**
+     * @param handler Handler that can provide a mocked find resources result.
+     */
+    public void addFindResourceHandler(@NotNull MockFindResourcesHandler handler) {
+        findResourcesHandlers.add(handler);
+    }
 
     @Override
-    @Deprecated
-    public @NotNull Resource resolve(final @NotNull HttpServletRequest request) {
-        throw new UnsupportedOperationException();
+    @SuppressWarnings("null")
+    public @NotNull Iterator<Map<String, Object>> queryResources(@NotNull String query, String language) {
+        return queryResourcesHandlers.stream()
+                .map(handler -> handler.queryResources(query, language))
+                .filter(Objects::nonNull)
+                .findFirst()
+                .orElse(Collections.emptyIterator());
     }
 
-    @Override
-    public @NotNull Iterator<Resource> findResources(final @NotNull String query, final String language) {
-        throw new UnsupportedOperationException();
+    /**
+     * @param handler Handler that can provide a mocked query resources result.
+     */
+    public void addQueryResourceHandler(@NotNull MockQueryResourceHandler handler) {

Review comment:
       updated docs




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [sling-org-apache-sling-testing-resourceresolver-mock] sonarcloud[bot] commented on pull request #2: SLING-10003 allow to provide mocked search results for findResources and queryResources

Posted by GitBox <gi...@apache.org>.
sonarcloud[bot] commented on pull request #2:
URL: https://github.com/apache/sling-org-apache-sling-testing-resourceresolver-mock/pull/2#issuecomment-758458015


   Kudos, SonarCloud Quality Gate passed!
   
   [<img src='https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/bug.png' alt='Bug' width='16' height='16' />](https://sonarcloud.io/project/issues?id=apache_sling-org-apache-sling-testing-resourceresolver-mock&pullRequest=2&resolved=false&types=BUG) [<img src='https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A.png' alt='A' width='16' height='16' />](https://sonarcloud.io/project/issues?id=apache_sling-org-apache-sling-testing-resourceresolver-mock&pullRequest=2&resolved=false&types=BUG) [0 Bugs](https://sonarcloud.io/project/issues?id=apache_sling-org-apache-sling-testing-resourceresolver-mock&pullRequest=2&resolved=false&types=BUG)  
   [<img src='https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/vulnerability.png' alt='Vulnerability' width='16' height='16' />](https://sonarcloud.io/project/issues?id=apache_sling-org-apache-sling-testing-resourceresolver-mock&pullRequest=2&resolved=false&types=VULNERABILITY) [<img src='https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A.png' alt='A' width='16' height='16' />](https://sonarcloud.io/project/issues?id=apache_sling-org-apache-sling-testing-resourceresolver-mock&pullRequest=2&resolved=false&types=VULNERABILITY) [0 Vulnerabilities](https://sonarcloud.io/project/issues?id=apache_sling-org-apache-sling-testing-resourceresolver-mock&pullRequest=2&resolved=false&types=VULNERABILITY)  
   [<img src='https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/security_hotspot.png' alt='Security Hotspot' width='16' height='16' />](https://sonarcloud.io/project/security_hotspots?id=apache_sling-org-apache-sling-testing-resourceresolver-mock&pullRequest=2&resolved=false&types=SECURITY_HOTSPOT) [<img src='https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A.png' alt='A' width='16' height='16' />](https://sonarcloud.io/project/security_hotspots?id=apache_sling-org-apache-sling-testing-resourceresolver-mock&pullRequest=2&resolved=false&types=SECURITY_HOTSPOT) [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_sling-org-apache-sling-testing-resourceresolver-mock&pullRequest=2&resolved=false&types=SECURITY_HOTSPOT)  
   [<img src='https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/code_smell.png' alt='Code Smell' width='16' height='16' />](https://sonarcloud.io/project/issues?id=apache_sling-org-apache-sling-testing-resourceresolver-mock&pullRequest=2&resolved=false&types=CODE_SMELL) [<img src='https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A.png' alt='A' width='16' height='16' />](https://sonarcloud.io/project/issues?id=apache_sling-org-apache-sling-testing-resourceresolver-mock&pullRequest=2&resolved=false&types=CODE_SMELL) [0 Code Smells](https://sonarcloud.io/project/issues?id=apache_sling-org-apache-sling-testing-resourceresolver-mock&pullRequest=2&resolved=false&types=CODE_SMELL)
   
   [<img src='https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/CoverageChart/100.png' alt='100.0%' width='16' height='16' />](https://sonarcloud.io/component_measures?id=apache_sling-org-apache-sling-testing-resourceresolver-mock&pullRequest=2&metric=new_coverage&view=list) [100.0% Coverage](https://sonarcloud.io/component_measures?id=apache_sling-org-apache-sling-testing-resourceresolver-mock&pullRequest=2&metric=new_coverage&view=list)  
   [<img src='https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/Duplications/3.png' alt='0.0%' width='16' height='16' />](https://sonarcloud.io/component_measures?id=apache_sling-org-apache-sling-testing-resourceresolver-mock&pullRequest=2&metric=new_duplicated_lines_density&view=list) [0.0% Duplication](https://sonarcloud.io/component_measures?id=apache_sling-org-apache-sling-testing-resourceresolver-mock&pullRequest=2&metric=new_duplicated_lines_density&view=list)
   
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [sling-org-apache-sling-testing-resourceresolver-mock] kwin commented on a change in pull request #2: SLING-10003 allow to provide mocked search results for findResources and queryResources

Posted by GitBox <gi...@apache.org>.
kwin commented on a change in pull request #2:
URL: https://github.com/apache/sling-org-apache-sling-testing-resourceresolver-mock/pull/2#discussion_r555373728



##########
File path: src/main/java/org/apache/sling/testing/resourceresolver/MockResourceResolver.java
##########
@@ -447,22 +451,46 @@ public Resource getParent(@NotNull Resource child) {
         return this.getResource(parentPath);
     }
 
+    @Override
+    @SuppressWarnings("null")
+    public @NotNull Iterator<Resource> findResources(final @NotNull String query, final String language) {
+        return findResourcesHandlers.stream()
+            .map(handler -> handler.findResources(query, language))
+            .filter(Objects::nonNull)
+            .findFirst()
+            .orElse(Collections.emptyIterator());
+    }
 
-    // --- unsupported operations ---
+    /**
+     * @param handler Handler that can provide a mocked find resources result.
+     */
+    public void addFindResourceHandler(@NotNull MockFindResourcesHandler handler) {
+        findResourcesHandlers.add(handler);
+    }
 
     @Override
-    @Deprecated
-    public @NotNull Resource resolve(final @NotNull HttpServletRequest request) {
-        throw new UnsupportedOperationException();
+    @SuppressWarnings("null")
+    public @NotNull Iterator<Map<String, Object>> queryResources(@NotNull String query, String language) {
+        return queryResourcesHandlers.stream()
+                .map(handler -> handler.queryResources(query, language))
+                .filter(Objects::nonNull)
+                .findFirst()
+                .orElse(Collections.emptyIterator());
     }
 
-    @Override
-    public @NotNull Iterator<Resource> findResources(final @NotNull String query, final String language) {
-        throw new UnsupportedOperationException();
+    /**
+     * @param handler Handler that can provide a mocked query resources result.
+     */
+    public void addQueryResourceHandler(@NotNull MockQueryResourceHandler handler) {

Review comment:
       It would be useful to add to javadoc that all handlers are queried until the first one returns a non-null value. And also that all registered handlers form a FIFO queue.

##########
File path: src/main/java/org/apache/sling/testing/resourceresolver/MockResourceResolver.java
##########
@@ -447,22 +451,46 @@ public Resource getParent(@NotNull Resource child) {
         return this.getResource(parentPath);
     }
 
+    @Override
+    @SuppressWarnings("null")
+    public @NotNull Iterator<Resource> findResources(final @NotNull String query, final String language) {
+        return findResourcesHandlers.stream()
+            .map(handler -> handler.findResources(query, language))
+            .filter(Objects::nonNull)
+            .findFirst()
+            .orElse(Collections.emptyIterator());
+    }
 
-    // --- unsupported operations ---
+    /**
+     * @param handler Handler that can provide a mocked find resources result.
+     */

Review comment:
       It would be useful to add to javadoc that all handlers are queried until the first one returns a non-null value. And also that all registered handlers form a FIFO queue. 




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [sling-org-apache-sling-testing-resourceresolver-mock] kwin commented on pull request #2: SLING-10003 allow to provide mocked search results for findResources and queryResources

Posted by GitBox <gi...@apache.org>.
kwin commented on pull request #2:
URL: https://github.com/apache/sling-org-apache-sling-testing-resourceresolver-mock/pull/2#issuecomment-759296007


   Thanks!


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org