Search in sources :

Example 21 with ExperienceFragment

use of com.adobe.cq.wcm.core.components.models.ExperienceFragment in project aem-core-wcm-components by Adobe-Marketing-Cloud.

the class ExperienceFragmentImplTest method testValidXFInPageWithLocalizationWithDifferentCountrySiteLanguage.

/**
 * Site with country-language localization (optional): eu/mysite/en
 * XF component is defined in the page
 * XF component points to a different country-language branch as the page
 */
@Test
void testValidXFInPageWithLocalizationWithDifferentCountrySiteLanguage() {
    ExperienceFragment experienceFragment = getExperienceFragmentUnderTest(CH_MYSITE_FR_PAGE + "/jcr:content/root/xf-component-31");
    assertEquals(XF_NAME, experienceFragment.getName());
    Utils.testJSONExport(experienceFragment, Utils.getTestExporterJSONPath(TEST_BASE, "xf31"));
}
Also used : ExperienceFragment(com.adobe.cq.wcm.core.components.models.ExperienceFragment) Test(org.junit.jupiter.api.Test)

Example 22 with ExperienceFragment

use of com.adobe.cq.wcm.core.components.models.ExperienceFragment in project aem-core-wcm-components by Adobe-Marketing-Cloud.

the class ExperienceFragmentImplTest method testUndefinedXFInPageWithLocalizationWithDifferentCountrySiteLanguage.

/**
 * Site with country-language localization (optional): eu/mysite/en
 * XF component is defined in the page
 * fragmentVariationPath is undefined
 */
@Test
void testUndefinedXFInPageWithLocalizationWithDifferentCountrySiteLanguage() {
    ExperienceFragment experienceFragment = getExperienceFragmentUnderTest(CH_MYSITE_FR_PAGE + "/jcr:content/root/xf-component-32");
    Utils.testJSONExport(experienceFragment, Utils.getTestExporterJSONPath(TEST_BASE, "xf32"));
}
Also used : ExperienceFragment(com.adobe.cq.wcm.core.components.models.ExperienceFragment) Test(org.junit.jupiter.api.Test)

Example 23 with ExperienceFragment

use of com.adobe.cq.wcm.core.components.models.ExperienceFragment in project aem-core-wcm-components by Adobe-Marketing-Cloud.

the class ExperienceFragmentImplTest method testXFWithItems.

/**
 * XF with content
 */
@Test
void testXFWithItems() {
    ExperienceFragment experienceFragment = getExperienceFragmentUnderTest(PRODUCT_PAGE_TEMPLATE + "/structure/jcr:content/xf-component-70", LIVECOPY_PAGE);
    assertEquals("header", experienceFragment.getName());
    Utils.testJSONExport(experienceFragment, Utils.getTestExporterJSONPath(TEST_BASE, "xf70"));
}
Also used : ExperienceFragment(com.adobe.cq.wcm.core.components.models.ExperienceFragment) Test(org.junit.jupiter.api.Test)

Example 24 with ExperienceFragment

use of com.adobe.cq.wcm.core.components.models.ExperienceFragment in project aem-core-wcm-components by Adobe-Marketing-Cloud.

the class ExperienceFragmentImplTest method testEmptyXFInPageWithoutLocalization.

/**
 * No localization structure
 * XF component is defined in the page
 * fragmentVariationPath is empty
 */
@Test
void testEmptyXFInPageWithoutLocalization() {
    ExperienceFragment experienceFragment = getExperienceFragmentUnderTest(NO_LOC_PAGE + "/jcr:content/root/xf-component-3");
    Utils.testJSONExport(experienceFragment, Utils.getTestExporterJSONPath(TEST_BASE, "xf3"));
}
Also used : ExperienceFragment(com.adobe.cq.wcm.core.components.models.ExperienceFragment) Test(org.junit.jupiter.api.Test)

Example 25 with ExperienceFragment

use of com.adobe.cq.wcm.core.components.models.ExperienceFragment in project aem-core-wcm-components by Adobe-Marketing-Cloud.

the class ExperienceFragmentDataImpl method getLocalizedFragmentVariationPath.

/**
 * Returns the localized path of the experience fragment variation if the experience fragment resource is defined
 * in a template.
 *
 * @return Localized experience fragment variation path
 * @see ExperienceFragment#getLocalizedFragmentVariationPath()
 */
@Nullable
public String getLocalizedFragmentVariationPath() {
    if (localizedFragmentVariationPath != null) {
        return localizedFragmentVariationPath;
    }
    // get the configured fragment variation path
    String fragmentVariationPath = resource.getValueMap().get(ExperienceFragment.PN_FRAGMENT_VARIATION_PATH, String.class);
    if (currentPage != null && inTemplate()) {
        final Resource pageResource = Optional.ofNullable(currentPage).map(p -> p.adaptTo(Resource.class)).orElse(null);
        final String currentPageRootPath = pageResource != null ? LocalizationUtils.getLocalizationRoot(pageResource, resourceResolver, languageManager, relationshipManager) : null;
        // we should use getLocalizationRoot instead of getXfLocalizationRoot once the XF UI supports creating Live and Language Copies
        String xfRootPath = getXfLocalizationRoot(fragmentVariationPath, currentPageRootPath);
        if (StringUtils.isNotEmpty(currentPageRootPath) && StringUtils.isNotEmpty(xfRootPath)) {
            String xfRelativePath = StringUtils.substring(fragmentVariationPath, xfRootPath.length());
            String localizedXfRootPath = StringUtils.replace(currentPageRootPath, CONTENT_ROOT, ExperienceFragmentsConstants.CONTENT_PATH, 1);
            localizedFragmentVariationPath = StringUtils.join(localizedXfRootPath, xfRelativePath, PATH_DELIMITER_CHAR, NN_CONTENT);
        }
    }
    String xfContentPath = String.join(Character.toString(PATH_DELIMITER_CHAR), fragmentVariationPath, NN_CONTENT);
    if (!resourceExists(localizedFragmentVariationPath) && resourceExists(xfContentPath)) {
        localizedFragmentVariationPath = xfContentPath;
    }
    if (!isExperienceFragmentVariation(localizedFragmentVariationPath)) {
        localizedFragmentVariationPath = null;
    }
    return localizedFragmentVariationPath;
}
Also used : ResourceResolver(org.apache.sling.api.resource.ResourceResolver) ExperienceFragmentsConstants(com.adobe.cq.xf.ExperienceFragmentsConstants) Resource(org.apache.sling.api.resource.Resource) ExperienceFragment(com.adobe.cq.wcm.core.components.models.ExperienceFragment) Text(com.day.text.Text) LanguageManager(com.day.cq.wcm.api.LanguageManager) NN_CONTENT(com.day.cq.wcm.api.NameConstants.NN_CONTENT) StringUtils(org.apache.commons.lang3.StringUtils) Page(com.day.cq.wcm.api.Page) SlingHttpServletRequest(org.apache.sling.api.SlingHttpServletRequest) LiveRelationshipManager(com.day.cq.wcm.msm.api.LiveRelationshipManager) LocalizationUtils(com.adobe.cq.wcm.core.components.util.LocalizationUtils) PageManager(com.day.cq.wcm.api.PageManager) Nullable(org.jetbrains.annotations.Nullable) ScriptVariable(org.apache.sling.models.annotations.injectorspecific.ScriptVariable) InjectionStrategy(org.apache.sling.models.annotations.injectorspecific.InjectionStrategy) Template(com.day.cq.wcm.api.Template) Model(org.apache.sling.models.annotations.Model) PostConstruct(javax.annotation.PostConstruct) Optional(java.util.Optional) OSGiService(org.apache.sling.models.annotations.injectorspecific.OSGiService) SlingObject(org.apache.sling.models.annotations.injectorspecific.SlingObject) Resource(org.apache.sling.api.resource.Resource) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

ExperienceFragment (com.adobe.cq.wcm.core.components.models.ExperienceFragment)90 Test (org.junit.jupiter.api.Test)88 SlingHttpServletRequest (org.apache.sling.api.SlingHttpServletRequest)4 Resource (org.apache.sling.api.resource.Resource)4 LocalizationUtils (com.adobe.cq.wcm.core.components.util.LocalizationUtils)2 ExperienceFragmentsConstants (com.adobe.cq.xf.ExperienceFragmentsConstants)2 LanguageManager (com.day.cq.wcm.api.LanguageManager)2 NN_CONTENT (com.day.cq.wcm.api.NameConstants.NN_CONTENT)2 Page (com.day.cq.wcm.api.Page)2 PageManager (com.day.cq.wcm.api.PageManager)2 Template (com.day.cq.wcm.api.Template)2 LiveRelationshipManager (com.day.cq.wcm.msm.api.LiveRelationshipManager)2 Text (com.day.text.Text)2 HashSet (java.util.HashSet)2 Optional (java.util.Optional)2 PostConstruct (javax.annotation.PostConstruct)2 StringUtils (org.apache.commons.lang3.StringUtils)2 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)2 Model (org.apache.sling.models.annotations.Model)2 InjectionStrategy (org.apache.sling.models.annotations.injectorspecific.InjectionStrategy)2