-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Do not disable optimized Sling Alias resolution by default (#29)
- Loading branch information
1 parent
eb1eb2a
commit b35d383
Showing
7 changed files
with
156 additions
and
19 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
70 changes: 70 additions & 0 deletions
70
core/src/test/java/io/wcm/testing/mock/aem/context/SlingAlias_JcrMockTest.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,70 @@ | ||
/* | ||
* #%L | ||
* wcm.io | ||
* %% | ||
* Copyright (C) 2023 wcm.io | ||
* %% | ||
* Licensed 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. | ||
* #L% | ||
*/ | ||
package io.wcm.testing.mock.aem.context; | ||
|
||
import static com.day.cq.commons.jcr.JcrConstants.JCR_PRIMARYTYPE; | ||
import static com.day.cq.commons.jcr.JcrConstants.NT_UNSTRUCTURED; | ||
import static org.junit.Assert.assertEquals; | ||
|
||
import java.util.Map; | ||
|
||
import org.apache.sling.api.resource.PersistenceException; | ||
import org.apache.sling.api.resource.Resource; | ||
import org.apache.sling.testing.mock.sling.ResourceResolverType; | ||
import org.junit.Before; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
|
||
import io.wcm.testing.mock.aem.junit.AemContext; | ||
import io.wcm.testing.mock.aem.junit.AemContextBuilder; | ||
|
||
public class SlingAlias_JcrMockTest { | ||
|
||
@Rule | ||
public AemContext context = new AemContextBuilder(ResourceResolverType.JCR_MOCK) | ||
/* | ||
* The optimized alias resolution is based on ResourceChangeListener, which is not supported with JCR_MOCK, | ||
* because JCR_MOCK does not support JCR Observation events. So, to use sling:alias with JCR_MOCK | ||
* we have to disabled the optimized alias resolution. | ||
* But be warned: This old code path is deprecated and likely to be removed in future Sling versions. | ||
* See SLING-12054 and SLING-12025 as references. | ||
*/ | ||
.resourceResolverFactoryActivatorProps(Map.of("resource.resolver.optimize.alias.resolution", false)) | ||
.build(); | ||
|
||
private String contentRoot; | ||
|
||
@Before | ||
public void setUp() throws Exception { | ||
contentRoot = context.uniqueRoot().content() + "/sample"; | ||
} | ||
|
||
@Test | ||
public void testSlingAlias() throws PersistenceException { | ||
Resource resource = context.create().resource(contentRoot + "/myresource", | ||
JCR_PRIMARYTYPE, NT_UNSTRUCTURED, | ||
"sling:alias", "myalias"); | ||
context.resourceResolver().commit(); | ||
|
||
assertEquals(contentRoot + "/myresource", resource.getPath()); | ||
assertEquals(contentRoot + "/myalias", context.resourceResolver().map(resource.getPath())); | ||
} | ||
|
||
} |
64 changes: 64 additions & 0 deletions
64
core/src/test/java/io/wcm/testing/mock/aem/context/SlingAlias_JcrOakTest.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,64 @@ | ||
/* | ||
* #%L | ||
* wcm.io | ||
* %% | ||
* Copyright (C) 2023 wcm.io | ||
* %% | ||
* Licensed 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. | ||
* #L% | ||
*/ | ||
package io.wcm.testing.mock.aem.context; | ||
|
||
import static com.day.cq.commons.jcr.JcrConstants.JCR_PRIMARYTYPE; | ||
import static com.day.cq.commons.jcr.JcrConstants.NT_UNSTRUCTURED; | ||
import static java.util.concurrent.TimeUnit.SECONDS; | ||
import static org.awaitility.Awaitility.await; | ||
import static org.junit.Assert.assertEquals; | ||
|
||
import org.apache.commons.lang3.StringUtils; | ||
import org.apache.sling.api.resource.PersistenceException; | ||
import org.apache.sling.api.resource.Resource; | ||
import org.apache.sling.testing.mock.sling.ResourceResolverType; | ||
import org.junit.Before; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
|
||
import io.wcm.testing.mock.aem.junit.AemContext; | ||
|
||
public class SlingAlias_JcrOakTest { | ||
|
||
@Rule | ||
public AemContext context = new AemContext(ResourceResolverType.JCR_OAK); | ||
|
||
private String contentRoot; | ||
|
||
@Before | ||
public void setUp() throws Exception { | ||
contentRoot = context.uniqueRoot().content() + "/sample"; | ||
} | ||
|
||
@Test | ||
public void testSlingAlias() throws PersistenceException { | ||
Resource resource = context.create().resource(contentRoot + "/myresource", | ||
JCR_PRIMARYTYPE, NT_UNSTRUCTURED, | ||
"sling:alias", "myalias"); | ||
context.resourceResolver().commit(); | ||
|
||
assertEquals(contentRoot + "/myresource", resource.getPath()); | ||
|
||
// alias processing happens asynchronously, so it may take a bit until the alias resolution works | ||
await().atMost(2, SECONDS).until(() -> StringUtils.equals(contentRoot + "/myalias", | ||
context.resourceResolver().map(resource.getPath()))); | ||
} | ||
|
||
} |
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