Search in sources :

Example 1 with ExperienceFragment

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

the class ClientLibrariesImplTest method testUtilsGetXFResourceTypes.

// 
// Below are tests for the specific methods in com.adobe.cq.wcm.core.components.internal.Utils
// 
@Test
void testUtilsGetXFResourceTypes() {
    Resource xfResource = context.currentResource(EXPERIENCE_FRAGMENT_PATH);
    ModelFactory modelFactory = mock(ModelFactory.class);
    doAnswer(invocation -> {
        Object[] args = invocation.getArguments();
        Resource resource = (Resource) args[1];
        String fragmentPath = resource.getValueMap().get("fragmentVariationPath", String.class);
        ExperienceFragment experienceFragment = mock(ExperienceFragment.class);
        when(experienceFragment.getLocalizedFragmentVariationPath()).thenReturn(fragmentPath);
        return experienceFragment;
    }).when(modelFactory).getModelFromWrappedRequest(any(SlingHttpServletRequest.class), any(Resource.class), eq(ExperienceFragment.class));
    Set<String> resourceTypes = Utils.getXFResourceTypes(xfResource, context.request(), modelFactory);
    Set<String> expectedResourceTypes = new HashSet<>(Arrays.asList("core/wcm/components/page/v2/page", "cq:Page", "core/wcm/components/teaser/v1/teaser", "wcm/foundation/components/responsivegrid"));
    assertEquals(expectedResourceTypes, resourceTypes);
}
Also used : Resource(org.apache.sling.api.resource.Resource) ModelFactory(org.apache.sling.models.factory.ModelFactory) SlingHttpServletRequest(org.apache.sling.api.SlingHttpServletRequest) ExperienceFragment(com.adobe.cq.wcm.core.components.models.ExperienceFragment) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 2 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 testCaching.

/**
 * Tests that methods that cache results return the same object on subsequent calls.
 */
@Test
void testCaching() {
    ExperienceFragment experienceFragment = getExperienceFragmentUnderTest(NO_LOC_PAGE + "/jcr:content/root/xf-component-1");
    assertNotNull(experienceFragment.getName());
    assertSame(experienceFragment.getName(), experienceFragment.getName());
    assertNotNull(experienceFragment.getCssClassNames());
    assertSame(experienceFragment.getCssClassNames(), experienceFragment.getCssClassNames());
    assertNotNull(experienceFragment.getExportedItems());
    assertSame(experienceFragment.getExportedItems(), experienceFragment.getExportedItems());
    assertNotNull(experienceFragment.getLocalizedFragmentVariationPath());
    assertSame(experienceFragment.getLocalizedFragmentVariationPath(), experienceFragment.getLocalizedFragmentVariationPath());
}
Also used : ExperienceFragment(com.adobe.cq.wcm.core.components.models.ExperienceFragment) Test(org.junit.jupiter.api.Test)

Example 3 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 testUndefinedXFInTemplateWithLocalizationWithDifferentCountryLanguage.

/**
 * Site with country-language localization
 * XF component is defined in the template
 * fragmentVariationPath is undefined
 */
@Test
void testUndefinedXFInTemplateWithLocalizationWithDifferentCountryLanguage() {
    ExperienceFragment experienceFragment = getExperienceFragmentUnderTest(PRODUCT_PAGE_TEMPLATE + "/structure/jcr:content/xf-component-22a", US_EN_PAGE);
    Utils.testJSONExport(experienceFragment, Utils.getTestExporterJSONPath(TEST_BASE, "xf22a"));
}
Also used : ExperienceFragment(com.adobe.cq.wcm.core.components.models.ExperienceFragment) Test(org.junit.jupiter.api.Test)

Example 4 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 testUndefinedXFInTemplateWithLocalization.

/**
 * Site with language localization
 * XF component is defined in the template
 * fragmentVariationPath is undefined
 */
@Test
void testUndefinedXFInTemplateWithLocalization() {
    ExperienceFragment experienceFragment = getExperienceFragmentUnderTest(PRODUCT_PAGE_TEMPLATE + "/structure/jcr:content/xf-component-12a", EN_PAGE);
    Utils.testJSONExport(experienceFragment, Utils.getTestExporterJSONPath(TEST_BASE, "xf12a"));
}
Also used : ExperienceFragment(com.adobe.cq.wcm.core.components.models.ExperienceFragment) Test(org.junit.jupiter.api.Test)

Example 5 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 testValidXFInPageWithLocalizationWithSameCountryLanguage.

/* ------------------------------- Tests for a site with country/language localization (us/en) -----------------  */
/**
 * Site with country-language localization
 * XF component is defined in the page
 * XF component points to the same country-language branch as the page
 */
@Test
void testValidXFInPageWithLocalizationWithSameCountryLanguage() {
    ExperienceFragment experienceFragment = getExperienceFragmentUnderTest(US_EN_PAGE + "/jcr:content/root/xf-component-20");
    assertEquals(XF_NAME, experienceFragment.getName());
    Utils.testJSONExport(experienceFragment, Utils.getTestExporterJSONPath(TEST_BASE, "xf20"));
}
Also used : ExperienceFragment(com.adobe.cq.wcm.core.components.models.ExperienceFragment) Test(org.junit.jupiter.api.Test)

Aggregations

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