Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanseifert committed Aug 21, 2023
2 parents b4a6a28 + 0190741 commit 9c685db
Show file tree
Hide file tree
Showing 20 changed files with 302 additions and 147 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/maven-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ jobs:
java-version: ${{ matrix.java }}
maven-executable: ./mvnw
sonar-run-on-os: ubuntu-latest
sonar-run-on-java-version: 11
sonar-run-on-java-version: 17
sonar-token: ${{ secrets.SONAR_TOKEN }}
github-token: ${{ secrets.GITHUB_TOKEN }}
2 changes: 2 additions & 0 deletions .github/workflows/maven-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

name: Deploy

concurrency: ${{ github.workflow }}

on:
push:
branches:
Expand Down
Binary file modified .mvn/wrapper/maven-wrapper.jar
Binary file not shown.
8 changes: 4 additions & 4 deletions .mvn/wrapper/maven-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
#
# http://www.apache.org/licenses/LICENSE-2.0
#
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.4/apache-maven-3.8.4-bin.zip
wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.4/apache-maven-3.9.4-bin.zip
wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar
15 changes: 15 additions & 0 deletions changes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,21 @@
xsi:schemaLocation="http://maven.apache.org/changes/1.0.0 http://maven.apache.org/plugins/maven-changes-plugin/xsd/changes-1.0.0.xsd">
<body>

<release version="5.3.0" date="2023-08-21">
<action type="add" dev="catalinadumitruu" issue="19">
Implement MockTag.getLocalizedTitlePaths method.
</action>
<action type="add" dev="rubnig" issue="16">
Add mock implementation for JcrTagManagerFactory.
</action>
<action type="update" dev="sseifert">
Update to latest OSGI Mock, ResourceResolver Mock, Sling Mock.
</action>
<action type="fix" dev="sseifert">
Exclude transitive dependencies from com.day.commons:day-commons-gfx to avoid leaking in old dependencies in classpath.
</action>
</release>

<release version="5.2.2" date="2023-05-19">
<action type="update" dev="sseifert" issue="12">
MockAemBindingsValuesProvider: Support LazyBindings.
Expand Down
8 changes: 7 additions & 1 deletion core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<parent>
<groupId>io.wcm</groupId>
<artifactId>io.wcm.testing.aem-mock.parent</artifactId>
<version>5.2.2</version>
<version>5.3.0</version>
<relativePath>../parent/pom.xml</relativePath>
</parent>

Expand Down Expand Up @@ -240,6 +240,12 @@
<artifactId>day-commons-gfx</artifactId>
<version>2.1.28</version>
<scope>compile</scope>
<exclusions>
<exclusion>
<groupId>com.day.commons</groupId>
<artifactId>day-commons-any</artifactId>
</exclusion>
</exclusions>
</dependency>

<!-- Sling Hamcrest - include as compile dependency for convenience -->
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package io.wcm.testing.mock.aem;

import javax.jcr.Session;

import org.apache.sling.api.resource.ResourceResolver;
import org.osgi.annotation.versioning.ProviderType;
import org.osgi.service.component.annotations.Component;

import com.day.cq.tagging.JcrTagManagerFactory;
import com.day.cq.tagging.TagManager;

/**
* Mock implementation of {@link JcrTagManagerFactory}.
*/
@Component(service = JcrTagManagerFactory.class)
@ProviderType
public final class MockJcrTagManagerFactory implements JcrTagManagerFactory {

@Override
public TagManager getTagManager(final Session session) {
// Tried to implement this method by injecting the ResourceResolverFactory as an OSGi Service, but this is not possible, due to the fact that
// ResourceResolverType.NONE doesn't register the service on the BundleContext at construction of the AemContext.
// This method is deprecated and shouldn't be used anyway, so it shouldn't be a problem.
throw new UnsupportedOperationException();
}

@Override
public TagManager getTagManager(final ResourceResolver resourceResolver) {
if (resourceResolver == null) {
throw new IllegalArgumentException("ResourceResolver must not be null");
}
return new MockTagManager(resourceResolver);
}

}
30 changes: 25 additions & 5 deletions core/src/main/java/io/wcm/testing/mock/aem/MockTag.java
Original file line number Diff line number Diff line change
Expand Up @@ -372,15 +372,35 @@ public String getTitlePath(Locale locale) {
return titlePath.toString();
}

// --- unsupported operations ---

@Override
public String getGQLSearchExpression(String arg0) {
throw new UnsupportedOperationException("Unsupported operation");
public Map<Locale, String> getLocalizedTitlePaths() {
Tag parent = this.getParent();
Map<Locale, String> map = parent != null ? parent.getLocalizedTitlePaths() : new HashMap<>();

for (Map.Entry<Locale, String> entry : map.entrySet()) {
if (parent.isNamespace()) {
entry.setValue(entry.getValue() + TITLEPATH_NS_DELIMITER + getTitle(entry.getKey()));
} else {
entry.setValue(entry.getValue() + TITLEPATH_DELIMITER + getTitle(entry.getKey()));
}
}

Map<Locale, String> localMap = getLocalizedTitles();
for (Map.Entry<Locale, String> entry : localMap.entrySet()) {
if (parent == null) {
map.put(entry.getKey(), entry.getValue());
} else if (!map.containsKey(entry.getKey())) {
map.put(entry.getKey(), parent.getTitlePath(entry.getKey()) + TITLEPATH_DELIMITER + entry.getValue());
}
}

return map;
}

// --- unsupported operations ---

@Override
public Map<Locale, String> getLocalizedTitlePaths() {
public String getGQLSearchExpression(String arg0) {
throw new UnsupportedOperationException("Unsupported operation");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*/
package io.wcm.testing.mock.aem.context;

import io.wcm.testing.mock.aem.MockJcrTagManagerFactory;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
Expand Down Expand Up @@ -87,6 +88,7 @@ protected void registerDefaultServices() {
registerInjectActivateService(new MockResourceCollectionManager());
registerInjectActivateService(new MockSlingModelFilter());
registerInjectActivateService(new MockExternalizer());
registerInjectActivateService(new MockJcrTagManagerFactory());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@
/**
* Mock implementation of selected AEM APIs.
*/
@org.osgi.annotation.versioning.Version("2.2.1")
@org.osgi.annotation.versioning.Version("2.3.0")
package io.wcm.testing.mock.aem;
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package io.wcm.testing.mock.aem;

import static org.junit.Assert.assertNotNull;

import javax.jcr.Session;

import org.apache.sling.api.resource.ResourceResolver;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;

import com.day.cq.tagging.JcrTagManagerFactory;
import com.day.cq.tagging.Tag;
import com.day.cq.tagging.TagManager;

import io.wcm.testing.mock.aem.context.TestAemContext;
import io.wcm.testing.mock.aem.junit.AemContext;

public class MockJcrTagManagerFactoryTest {

@Rule
public AemContext context = TestAemContext.newAemContext();

private JcrTagManagerFactory underTest;

@Before
public void setUp() {
context.create().tag("test:test-tag");
underTest = context.getService(JcrTagManagerFactory.class);
}

@Test
public void testGetTagManagerFromResourceResolver() {
TagManager tagManager = underTest.getTagManager(context.resourceResolver());
assertNotNull(tagManager);

Tag tag = tagManager.resolve("test:test-tag");
assertNotNull(tag);
}

@Test(expected = IllegalArgumentException.class)
public void testGetTagManagerFromResourceResolverWithNull() {
underTest.getTagManager((ResourceResolver)null);
}

@SuppressWarnings("deprecation")
@Test(expected = UnsupportedOperationException.class)
public void testGetTagManagerFromSession() {
underTest.getTagManager((Session)null);
}

}
13 changes: 13 additions & 0 deletions core/src/test/java/io/wcm/testing/mock/aem/MockTagTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,19 @@ public void testGetXPathSearchExpression_DefaultNamespace() throws Exception {
assertTagExpression(tag, "tag3", "default/tag3");
}

@Test
public void getLocalizedTitlePaths() {
Map<Locale,String> localizedTitlePaths = aemApi.getLocalizedTitlePaths();

assertNotNull(localizedTitlePaths);
assertEquals(6, localizedTitlePaths.size());
assertEquals("WCM IO Tag Namespace : AEM / English AEM API", localizedTitlePaths.get(Locale.ENGLISH));
assertEquals("WCM IO Tag Namespace : AEM / AEM API for US", localizedTitlePaths.get(Locale.US));
assertEquals("WCM IO Tag Namespace : AEM / German AEM API", localizedTitlePaths.get(Locale.GERMAN));
assertEquals("WCM IO Tag Namespace : AEM / AEM API for Germany", localizedTitlePaths.get(Locale.GERMANY));
assertEquals("WCM IO Tag Namespace : AEM / Portuguese (Brazil) AEM API/:with special chars", localizedTitlePaths.get(LOCALE_PT_BR));
}

private void assertTagExpression(@NotNull final Tag tag,
@NotNull final String tagId,
@NotNull final String tagPath) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class MockOverrideSlingPathRequestWrapper extends SlingHttpServletRequestWrapper
super(request);
this.adapterManager = adapterManager;
this.myBindings = new SlingBindings();
this.adaptersCache = new HashMap();
this.adaptersCache = new HashMap<>();
SlingBindings slingBindings = (SlingBindings)this.getSlingRequest().getAttribute(ATTR_SLING_BINDINGS);
this.resource = this.getSlingRequest().getResourceResolver().resolve(this.getSlingRequest(), path);
if (slingBindings != null) {
Expand Down Expand Up @@ -84,6 +84,7 @@ public Resource getResource() {
* Overriding `adaptTo` to avoid using the original request as the adaptable.
*/
@Override
@SuppressWarnings({ "null", "unchecked" })
public <AdapterType> AdapterType adaptTo(Class<AdapterType> type) {
AdapterType result = null;
synchronized (this) {
Expand Down
6 changes: 3 additions & 3 deletions junit4/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<parent>
<groupId>io.wcm</groupId>
<artifactId>io.wcm.testing.aem-mock.parent</artifactId>
<version>5.2.2</version>
<version>5.3.0</version>
<relativePath>../parent/pom.xml</relativePath>
</parent>

Expand Down Expand Up @@ -54,7 +54,7 @@
<dependency>
<groupId>io.wcm</groupId>
<artifactId>io.wcm.testing.aem-mock.core</artifactId>
<version>5.2.2</version>
<version>5.3.0</version>
<scope>compile</scope>
</dependency>

Expand Down Expand Up @@ -87,7 +87,7 @@
<dependency>
<groupId>io.wcm</groupId>
<artifactId>io.wcm.testing.aem-mock.core</artifactId>
<version>5.2.2</version>
<version>5.3.0</version>
<classifier>tests</classifier>
<scope>test</scope>
</dependency>
Expand Down
6 changes: 3 additions & 3 deletions junit5/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<parent>
<groupId>io.wcm</groupId>
<artifactId>io.wcm.testing.aem-mock.parent</artifactId>
<version>5.2.2</version>
<version>5.3.0</version>
<relativePath>../parent/pom.xml</relativePath>
</parent>

Expand Down Expand Up @@ -54,14 +54,14 @@
<dependency>
<groupId>io.wcm</groupId>
<artifactId>io.wcm.testing.aem-mock.core</artifactId>
<version>5.2.2</version>
<version>5.3.0</version>
<scope>compile</scope>
</dependency>

<dependency>
<groupId>io.wcm</groupId>
<artifactId>io.wcm.testing.aem-mock.core</artifactId>
<version>5.2.2</version>
<version>5.3.0</version>
<classifier>tests</classifier>
<scope>test</scope>
</dependency>
Expand Down
Loading

0 comments on commit 9c685db

Please sign in to comment.