Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#2872 update AEM mocks #2874

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading