Skip to content

Commit

Permalink
added FilterByPropertyIsMultiple: matches all nodes where a given pro…
Browse files Browse the repository at this point in the history
…perty is a multi-value property (such as an array or list) and contains a specific value or values
  • Loading branch information
michielspiritus7 committed Jul 14, 2023
1 parent cc49fa4 commit 4f0b66d
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

import de.valtech.aecu.api.groovy.console.bindings.GStringConverter;

import java.util.Arrays;

/**
* Filters resources by a given property. The filter only matches if the attribute exists and has
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/*
* Copyright 2023 Valtech GmbH
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
* associated documentation files (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge, publish, distribute,
* sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
* NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package de.valtech.aecu.core.groovy.console.bindings.filters;

import org.apache.sling.api.resource.ValueMap;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.when;

import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ValueMap;
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 de.valtech.aecu.api.groovy.console.bindings.filters.FilterByPropertyIsMultiple;

import java.util.Arrays;
import java.util.List;

/**
* Tests FilterByPropertyIsMultiple
*
* @author Roland Gruber
*/
@ExtendWith(MockitoExtension.class)
@MockitoSettings(strictness = Strictness.LENIENT)
public class FilterByPropertyIsMultipleTest {

private static final String NAME = "name";
private static final List<String> MULTIPLE_VALUE = Arrays.asList("value1", "value2");

@Mock
private Resource resource;

@Mock
ValueMap values;

@Mock
ValueMap valueMap;

@BeforeEach
public void setup() {
when(resource.getValueMap()).thenReturn(values);
}

@Test
void filterAttributeArray() {
Object[] attrArray = new Object[]{"value1", "value2", "value3"};
when(resource.getValueMap()).thenReturn(valueMap);
when(valueMap.get("name")).thenReturn(attrArray);

FilterByPropertyIsMultiple filter = new FilterByPropertyIsMultiple("name", attrArray);

assertTrue(filter.filter(resource, new StringBuilder()));
}



@Test
public void filterAttributeList() {
FilterByPropertyIsMultiple filter = new FilterByPropertyIsMultiple(NAME, MULTIPLE_VALUE);
when(values.get(NAME)).thenReturn(MULTIPLE_VALUE);

assertTrue(filter.filter(resource, new StringBuilder()));
}

@Test
public void filterAttributeNonMultiple() {
FilterByPropertyIsMultiple filter = new FilterByPropertyIsMultiple(NAME, "value");
when(values.get(NAME)).thenReturn("value");

assertFalse(filter.filter(resource, new StringBuilder()));
}

}
31 changes: 21 additions & 10 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<groupId>de.valtech.aecu</groupId>
<artifactId>aecu</artifactId>
<packaging>pom</packaging>
<version>6.5.1-SNAPSHOT</version>
<version>6.4.1-SNAPSHOT</version>
<name>AECU</name>
<description>AEM Easy Content Upgrade</description>
<url>https://github.com/valtech/aem-easy-content-upgrade</url>
Expand All @@ -25,9 +25,9 @@

<properties>
<aem.host>localhost</aem.host>
<aem.port>4502</aem.port>
<aem.port>5602</aem.port>
<aem.publish.host>localhost</aem.publish.host>
<aem.publish.port>4502</aem.publish.port>
<aem.publish.port>5705</aem.publish.port>
<sling.user>admin</sling.user>
<sling.password>admin</sling.password>
<vault.user>admin</vault.user>
Expand Down Expand Up @@ -387,6 +387,23 @@
</lifecycleMappingMetadata>
</configuration>
</plugin>
<plugin>
<groupId>org.owasp</groupId>
<artifactId>dependency-check-maven</artifactId>
<version>8.1.2</version>
<configuration>
<failBuildOnCVSS>0</failBuildOnCVSS>
<failBuildOnAnyVulnerability>true</failBuildOnAnyVulnerability>
<skipProvidedScope>true</skipProvidedScope>
</configuration>
<executions>
<execution>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
Expand Down Expand Up @@ -628,12 +645,6 @@
<version>2.0.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>de.valtech.aecu</groupId>
<artifactId>aecu.bundle</artifactId>
<version>LATEST</version>
<type>zip</type>
</dependency>
</dependencies>
</dependencyManagement>

Expand Down Expand Up @@ -724,4 +735,4 @@
</pluginRepository>
</pluginRepositories>

</project>
</project>

0 comments on commit 4f0b66d

Please sign in to comment.