Skip to content

Commit

Permalink
#2872 update AEM mocks
Browse files Browse the repository at this point in the history
  • Loading branch information
joerghoh committed Sep 30, 2024
1 parent d2a7b02 commit aace37b
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.apache.commons.lang3.tuple.Pair;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ValueMap;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
Expand Down Expand Up @@ -246,7 +247,10 @@ private String validateLinkAttributeValue(@Nullable final String value) {
*/
@NotNull
private String getPageLinkURL(@NotNull Page page) {
return page.getPath() + HTML_EXTENSION;
Resource resource = page.adaptTo(Resource.class);
assert resource!=null;
ResourceResolver resolver = resource.getResourceResolver();
return resolver.map(page.getPath()) + HTML_EXTENSION;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ void testResourcePageLink() {
PN_LINK_URL, page.getPath());
context.currentResource(linkResource);
Link link = getUnderTest().get(linkResource).build();
assertValidLink(link, page.getPath() + ".html");
assertValidLink(link, context.resourceResolver().map(page.getPath()) + ".html");
assertEquals(page, link.getReference());
assertEquals((page.getPath() + ".html").replaceAll("^\\/content\\/links\\/site1\\/(.+)","/content/site1/$1"),
link.getMappedURL());
Expand Down Expand Up @@ -142,8 +142,8 @@ void testResourceInvalidPageLink() {
void testPageLink() {
Link link = getUnderTest().get(page).build();

assertValidLink(link, page.getPath() + ".html");
assertEquals("https://example.org" + page.getPath() + ".html", link.getExternalizedURL());
assertValidLink(link, context.resourceResolver().map(page.getPath()) + ".html");
assertEquals("https://example.org" + context.resourceResolver().map(page.getPath()) + ".html", link.getExternalizedURL());
assertEquals(page, link.getReference());
}

Expand All @@ -167,7 +167,7 @@ void testEmptyLink() {
void testLinkURLPageLinkWithTarget() {
Link link = getUnderTest().get(page.getPath()).withLinkTarget("_blank").build();

assertValidLink(link, page.getPath() + ".html", "_blank");
assertValidLink(link, context.resourceResolver().map(page.getPath()) + ".html", "_blank");
assertEquals(page, link.getReference());
}

Expand Down Expand Up @@ -198,8 +198,8 @@ void testLinkWithRedirect() {
Link link = getUnderTest().get(linkResource).build();

assertTrue(link.isValid());
assertValidLink(link, targetPage2.getPath() + ".html");
assertEquals("https://example.org" + targetPage2.getPath() + ".html", link.getExternalizedURL());
assertValidLink(link, context.resourceResolver().map(targetPage2.getPath()) + ".html");
assertEquals("https://example.org" + context.resourceResolver().map(targetPage2.getPath()) + ".html", link.getExternalizedURL());
assertEquals(targetPage2, link.getReference());
}

Expand All @@ -225,8 +225,8 @@ void testLinkWithRedirect_shadowingDisabledByProperty() {
Link link = getUnderTest().get(linkResource).build();

assertTrue(link.isValid());
assertValidLink(link, targetPage1.getPath() + ".html");
assertEquals("https://example.org" + targetPage1.getPath() + ".html", link.getExternalizedURL());
assertValidLink(link, context.resourceResolver().map(targetPage1.getPath()) + ".html");
assertEquals("https://example.org" + context.resourceResolver().map(targetPage1.getPath()) + ".html", link.getExternalizedURL());
assertEquals(targetPage1, link.getReference());
}

Expand Down Expand Up @@ -255,8 +255,8 @@ void testLinkWithRedirect_shadowingDisabledByStyle() {
Link link = getUnderTest().get(linkResource).build();

assertTrue(link.isValid());
assertValidLink(link, targetPage1.getPath() + ".html");
assertEquals("https://example.org" + targetPage1.getPath() + ".html", link.getExternalizedURL());
assertValidLink(link, context.resourceResolver().map(targetPage1.getPath()) + ".html");
assertEquals("https://example.org" + context.resourceResolver().map(targetPage1.getPath()) + ".html", link.getExternalizedURL());
assertEquals(targetPage1, link.getReference());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ void testVanityConfig() {
DefaultPathProcessor underTest = context.registerInjectActivateService(new DefaultPathProcessor(), ImmutableMap.of(
"vanityConfig", "shouldBeDefault"));
assertEquals("/content/site1/en.html", underTest.map(page.getPath() + HTML_EXTENSION, context.request()));
assertEquals("https://example.org/content/links/site1/en.html", underTest.externalize(page.getPath() + HTML_EXTENSION, context.request()));
assertEquals("https://example.org/content/site1/en.html", underTest.externalize(page.getPath() + HTML_EXTENSION, context.request()));
context.request().setContextPath("/cp");
underTest = context.registerInjectActivateService(new DefaultPathProcessor(), ImmutableMap.of(
"vanityConfig", DefaultPathProcessor.VanityConfig.ALWAYS.getValue()));
Expand Down
2 changes: 1 addition & 1 deletion parent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -796,7 +796,7 @@
<dependency>
<groupId>io.wcm</groupId>
<artifactId>io.wcm.testing.aem-mock.junit5</artifactId>
<version>5.5.2</version>
<version>5.6.2</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down

0 comments on commit aace37b

Please sign in to comment.