Mahidhar Chaluvadi created SLING-11499:
------------------------------------------
Summary: ContentFileResource - Unable to adapt to
ModifiableValueMap
Key: SLING-11499
URL: https://issues.apache.org/jira/browse/SLING-11499
Project: Sling
Issue Type: Bug
Reporter: Mahidhar Chaluvadi
When trying to load Sling Mocks using File Vault (Content XML files instead of
Json files), the src code that relies on adapting to ModifiableValueMap is
returning null. Please advise on what's the right way to handle this or advise
us with the fix details if this is a valid bug. Additionally feel free to reach
out to me for testing the fixes or to include me in any development efforts.
Here is the sample code for reproducing the issue.
Assumptions:
# Sample content is available as a content package module as part of the
project structure
# Content does contain a valid page with any component below responsive grid
{code:java}
package com.junit.sling.mocks;
import org.apache.jackrabbit.vault.util.PathUtil;
import org.apache.sling.api.resource.ModifiableValueMap;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ValueMap;
import org.apache.sling.testing.mock.sling.ResourceResolverType;
import org.apache.sling.testing.mock.sling.junit5.SlingContext;
import org.apache.sling.testing.mock.sling.junit5.SlingContextExtension;
import org.apache.sling.testing.mock.sling.loader.ContentLoader;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import java.io.File;
@ExtendWith({SlingContextExtension.class})
public class AEMMocksJUnit5ModifiableValueMap {
public final SlingContext slingContext = new
SlingContext(ResourceResolverType.RESOURCERESOLVER_MOCK);
private static final String TEST_RESOURCE =
"/content/junit-core-mock-data/somepage/jcr:content/root/responsivegrid/somecomponent";
private static final String VAULT_FS_HOME =
"/ui.content.sample/src/main/content/jcr_root";
private final ResourceResolver resourceResolver =
slingContext.resourceResolver();
private Resource finalJsonResource;
@BeforeEach
public void setUpDefaultMockContent() {
ContentLoader contentLoader = slingContext.load();
File bundleDirectory = new
File(System.getProperty("user.dir")).getParentFile();
final String VAULT_FS_HOME_ABS_PATH =
PathUtil.append(bundleDirectory.getPath(),VAULT_FS_HOME);
contentLoader.folderFileVaultXml(VAULT_FS_HOME_ABS_PATH,"/conf");
contentLoader.folderFileVaultXml(VAULT_FS_HOME_ABS_PATH,"/content");
slingContext.runMode("author");
}
@Test
public void testModifiableValueMap() {
finalJsonResource = resourceResolver.getResource(TEST_RESOURCE);
if (finalJsonResource != null)
Assertions.assertNotNull(finalJsonResource.adaptTo(ValueMap.class));
// Code below is not meant to return null
Assertions.assertNull(finalJsonResource.adaptTo(ModifiableValueMap.class));
}
} {code}
Thanks
--
This message was sent by Atlassian Jira
(v8.20.10#820010)