-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
29 changed files
with
271 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
.../main/java/de/valtech/aecu/api/groovy/console/bindings/filters/FilterByNodeRootPaths.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package de.valtech.aecu.api.groovy.console.bindings.filters; | ||
|
||
import org.apache.sling.api.resource.Resource; | ||
|
||
import javax.annotation.Nonnull; | ||
import java.util.List; | ||
|
||
/** | ||
* Filters resources by node root paths. Only resource matching or starting with the root paths are accepted | ||
* | ||
* @author Dries Vanbilloen | ||
*/ | ||
public class FilterByNodeRootPaths implements FilterBy { | ||
|
||
private List<String> rootPaths; | ||
|
||
/** | ||
* Constructor | ||
* | ||
* @param rootPaths list of root paths | ||
*/ | ||
public FilterByNodeRootPaths(List<String> rootPaths) { | ||
this.rootPaths = rootPaths; | ||
} | ||
|
||
@Override | ||
public boolean filter(@Nonnull Resource resource, @Nonnull StringBuilder output) { | ||
final String currentPath = resource.getPath(); | ||
return rootPaths.stream() | ||
.anyMatch(rootPath -> rootPath.equals(currentPath) || (currentPath + "/").startsWith(rootPath)); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
...t/java/de/valtech/aecu/api/groovy/console/bindings/filters/FilterByNodeRootPathsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package de.valtech.aecu.api.groovy.console.bindings.filters; | ||
|
||
import org.apache.sling.api.resource.Resource; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
import org.mockito.junit.jupiter.MockitoSettings; | ||
import org.mockito.quality.Strictness; | ||
|
||
import java.util.Arrays; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
import static org.mockito.Mockito.when; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
@MockitoSettings(strictness = Strictness.LENIENT) | ||
class FilterByNodeRootPathsTest { | ||
|
||
private static final String TEST_PATH = "/content/my-site/nl/my-page"; | ||
|
||
@Mock | ||
Resource resource; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
when(resource.getPath()).thenReturn(TEST_PATH); | ||
} | ||
|
||
@Test | ||
void test_whenRootPathsMatches_filterAccepts() { | ||
boolean accept = new FilterByNodeRootPaths(Arrays.asList("/content/my-site")).filter(resource, new StringBuilder()); | ||
assertTrue(accept); | ||
} | ||
|
||
@Test | ||
void test_whenRootPathsDontMatch_filterDenies() { | ||
boolean accept = new FilterByNodeRootPaths(Arrays.asList("/content/my-other-site")).filter(resource, new StringBuilder()); | ||
assertFalse(accept); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.