Skip to content

Commit

Permalink
[Experience Fragment] Expand JSON content #943 (#941)
Browse files Browse the repository at this point in the history
* Experience Fragment also exports the actual contents of the experience fragment directly in itself
* Change fragment path to fragment variation path
* RAT files, test coverage
* Removed unused import
* improve test coverage to meet requirements
* formatting

Co-authored-by: Niek Raaijmakers <niek@adobe.com>
  • Loading branch information
niekraaijmakers and Niek Raaijmakers committed Jul 23, 2020
1 parent b179741 commit 80f3f56
Show file tree
Hide file tree
Showing 35 changed files with 684 additions and 143 deletions.

Large diffs are not rendered by default.

Expand Up @@ -15,10 +15,13 @@
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
package com.adobe.cq.wcm.core.components.models;

import com.adobe.cq.export.json.ComponentExporter;
import com.adobe.cq.export.json.ContainerExporter;
import org.jetbrains.annotations.NotNull;
import org.osgi.annotation.versioning.ConsumerType;

import com.adobe.cq.export.json.ComponentExporter;
import javax.annotation.Nullable;
import java.util.Map;

/**
* Defines the {@code ExperienceFragment} Sling Model used for the
Expand All @@ -27,7 +30,7 @@
* @since com.adobe.cq.wcm.core.components.models 12.9.0
*/
@ConsumerType
public interface ExperienceFragment extends Component {
public interface ExperienceFragment extends Component, ContainerExporter {

/**
* Name of the configuration policy property that specifies the experience fragment variation path. The property
Expand Down Expand Up @@ -63,6 +66,26 @@ default String getName() {
throw new UnsupportedOperationException();
}



/**
* Generates some container class names (needed for SPA framework)
* @return Css Class names
* @since com.adobe.cq.wcm.core.components.models 12.13.0
*/
@Nullable
default String getCssClassNames() {
throw new UnsupportedOperationException();
}

/**
* Simple boolean flag to check if the experience fragment variation and its underlying experience fragment is configured.
* If the localizedFragmentVariationPath path is not configured or the children are empty, this wis will return false.
* @return localizedFragmentVariationPath is configured and has entries
* @since com.adobe.cq.wcm.core.components.models 12.13.0
*/
default boolean isConfigured() {throw new UnsupportedOperationException(); }

/**
* @see ComponentExporter#getExportedType()
* @since com.adobe.cq.wcm.core.components.models 12.9.0
Expand All @@ -72,5 +95,25 @@ default String getName() {
default String getExportedType() {
throw new UnsupportedOperationException();
}

/**
* @see ContainerExporter#getExportedItemsOrder()
* @since com.adobe.cq.wcm.core.components.models.form 14.2.0
*/
@NotNull
@Override
default String[] getExportedItemsOrder() {
throw new UnsupportedOperationException();
}

/**
* @see ContainerExporter#getExportedItems()
* @since com.adobe.cq.wcm.core.components.models.form 14.2.0
*/
@NotNull
@Override
default Map<String, ? extends ComponentExporter> getExportedItems() {
throw new UnsupportedOperationException();
}

}
@@ -0,0 +1,52 @@
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~ Copyright 2017 Adobe
~
~ 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.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
package com.adobe.cq.wcm.core.components.internal.models.dummy;

import com.adobe.cq.export.json.ComponentExporter;
import com.adobe.cq.export.json.ExporterConstants;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.models.annotations.DefaultInjectionStrategy;
import org.apache.sling.models.annotations.Exporter;
import org.apache.sling.models.annotations.Model;
import org.apache.sling.models.annotations.injectorspecific.ValueMapValue;

import javax.annotation.Nonnull;

@Model(
adaptables = SlingHttpServletRequest.class,
adapters = {DummyTestImageModel.class, ComponentExporter.class},
defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL,
resourceType = DummyTestImageModel.RESOURCE_TYPE)
@Exporter(
name = ExporterConstants.SLING_MODEL_EXPORTER_NAME,
extensions = ExporterConstants.SLING_MODEL_EXTENSION)
public class DummyTestImageModel implements ComponentExporter {

static final String RESOURCE_TYPE = "my/test/image";

@ValueMapValue
private String url;

public String getUrl() {
return url;
}

@Nonnull
@Override
public String getExportedType() {
return RESOURCE_TYPE;
}
}
@@ -0,0 +1,52 @@
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~ Copyright 2017 Adobe
~
~ 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.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
package com.adobe.cq.wcm.core.components.internal.models.dummy;

import com.adobe.cq.export.json.ComponentExporter;
import com.adobe.cq.export.json.ExporterConstants;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.models.annotations.DefaultInjectionStrategy;
import org.apache.sling.models.annotations.Exporter;
import org.apache.sling.models.annotations.Model;
import org.apache.sling.models.annotations.injectorspecific.ValueMapValue;

import javax.annotation.Nonnull;

@Model(
adaptables = SlingHttpServletRequest.class,
adapters = {DummyTestTextModel.class, ComponentExporter.class},
defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL,
resourceType = DummyTestTextModel.RESOURCE_TYPE)
@Exporter(
name = ExporterConstants.SLING_MODEL_EXPORTER_NAME,
extensions = ExporterConstants.SLING_MODEL_EXTENSION)
public class DummyTestTextModel implements ComponentExporter {

static final String RESOURCE_TYPE = "my/test/text";

@ValueMapValue
private String text;

public String getText() {
return text;
}

@Nonnull
@Override
public String getExportedType() {
return RESOURCE_TYPE;
}
}
Expand Up @@ -70,6 +70,10 @@ class ExperienceFragmentImplTest {
void setUp() throws WCMException {
context.load().json(TEST_BASE + CoreComponentTestContext.TEST_CONTENT_JSON, "/content");
context.load().json(TEST_BASE + "/test-conf.json", "/conf/coretest/settings");

context.addModelsForPackage("com.adobe.cq.wcm.core.components.internal.models.dummy");
context.addModelsForClasses("com.adobe.cq.wcm.core.components.internal.models.v1");

context.registerService(LanguageManager.class, new MockLanguageManager());
LiveRelationshipManager relationshipManager = mock(LiveRelationshipManager.class);
when(relationshipManager.isSource(any(Resource.class))).then(
Expand Down Expand Up @@ -328,7 +332,7 @@ void testEmptyXFInPageWithLocalization() {
void testEmptyXFInTemplateWithLocalization() {
ExperienceFragment experienceFragment = getExperienceFragmentUnderTest(
PRODUCT_PAGE_TEMPLATE + "/structure/jcr:content/xf-component-13a", EN_PAGE);
Utils.testJSONExport(experienceFragment, Utils.getTestExporterJSONPath(TEST_BASE, "xf13"));
Utils.testJSONExport(experienceFragment, Utils.getTestExporterJSONPath(TEST_BASE, "xf13a"));
}


Expand Down Expand Up @@ -678,6 +682,34 @@ void testValidXFInTemplateWithLocalizationWithDifferentLivecopy() {
assertEquals(XF_NAME, experienceFragment.getName());
Utils.testJSONExport(experienceFragment, Utils.getTestExporterJSONPath(TEST_BASE, "xf61a"));
}


/**
* Site with language localization
* XF component is defined in the page
* XF component points to the same language branch as the page
* Underlying XF has actual components present which will be exported.
*/
@Test
void testValidXFInPageWithContent() {
ExperienceFragment experienceFragment = getExperienceFragmentUnderTest(EN_PAGE
+ "/jcr:content/root/xf-component-70");
assertEquals("header", experienceFragment.getName());
Utils.testJSONExport(experienceFragment, Utils.getTestExporterJSONPath(TEST_BASE, "xf70"));
}

/*
* Site with language localization
* XF component is defined in the page
* XF component points to the same language branch as the page
*/
@Test
void testValidXFInPageWithNoContent() {
ExperienceFragment experienceFragment = getExperienceFragmentUnderTest(EN_PAGE
+ "/jcr:content/root/xf-component-71");
assertEquals("header_empty", experienceFragment.getName());
Utils.testJSONExport(experienceFragment, Utils.getTestExporterJSONPath(TEST_BASE, "xf71"));
}


/* ------------------------------- private stuff ----------------------------------------- */
Expand Down
@@ -1,4 +1,8 @@
{
"localizedFragmentVariationPath":"/content/experience-fragments/mysite/en/footer/master/jcr:content",
":type": "core/wcm/components/experiencefragment/v1/experiencefragment"
}
"localizedFragmentVariationPath": "/content/experience-fragments/mysite/en/footer/master/jcr:content",
"configured": false,
":type": "core/wcm/components/experiencefragment/v1/experiencefragment",
":itemsOrder": [],
":items": {},
"classNames": "aem-xf empty"
}
@@ -1,4 +1,8 @@
{
"localizedFragmentVariationPath":"/content/experience-fragments/mysite/en/footer/master/jcr:content",
":type": "core/wcm/components/experiencefragment/v1/experiencefragment"
}
"localizedFragmentVariationPath": "/content/experience-fragments/mysite/en/footer/master/jcr:content",
"configured": false,
"classNames": "aem-xf empty",
":itemsOrder": [],
":items": {},
":type": "core/wcm/components/experiencefragment/v1/experiencefragment"
}
@@ -1,4 +1,8 @@
{
"localizedFragmentVariationPath":"/content/experience-fragments/mysite/es/footer/master/jcr:content",
":type": "core/wcm/components/experiencefragment/v1/experiencefragment"
}
"localizedFragmentVariationPath": "/content/experience-fragments/mysite/es/footer/master/jcr:content",
"configured": false,
":type": "core/wcm/components/experiencefragment/v1/experiencefragment",
"classNames": "aem-xf empty",
":itemsOrder": [],
":items": {}
}
@@ -1,4 +1,8 @@
{
"localizedFragmentVariationPath":"/content/experience-fragments/mysite/en/footer/master/jcr:content",
":type": "core/wcm/components/experiencefragment/v1/experiencefragment"
}
"localizedFragmentVariationPath": "/content/experience-fragments/mysite/en/footer/master/jcr:content",
"configured": false,
":itemsOrder": [],
":items": {},
"classNames": "aem-xf empty",
":type": "core/wcm/components/experiencefragment/v1/experiencefragment"
}
@@ -1,3 +1,7 @@
{
":type": "core/wcm/components/experiencefragment/v1/experiencefragment"
}
"configured": false,
":type": "core/wcm/components/experiencefragment/v1/experiencefragment",
":itemsOrder": [],
":items": {},
"classNames": "aem-xf empty"
}
@@ -1,3 +1,7 @@
{
":type": "core/wcm/components/experiencefragment/v1/experiencefragment"
}
"configured": false,
":type": "core/wcm/components/experiencefragment/v1/experiencefragment",
"classNames": "aem-xf empty",
":itemsOrder": [],
":items": {}
}
@@ -0,0 +1,7 @@
{
"configured": false,
":type": "core/wcm/components/experiencefragment/v1/experiencefragment",
"classNames": "aem-xf empty",
":itemsOrder": [],
":items": {}
}
@@ -1,3 +1,7 @@
{
":type": "core/wcm/components/experiencefragment/v1/experiencefragment"
"configured":false,
":type": "core/wcm/components/experiencefragment/v1/experiencefragment",
"classNames":"aem-xf empty",
":itemsOrder":[],
":items":{}
}
@@ -1,4 +1,8 @@
{
"localizedFragmentVariationPath":"/content/experience-fragments/mysite/us/en/footer/master/jcr:content",
":type": "core/wcm/components/experiencefragment/v1/experiencefragment"
}
"localizedFragmentVariationPath": "/content/experience-fragments/mysite/us/en/footer/master/jcr:content",
"configured": false,
":itemsOrder": [],
":items": {},
"classNames": "aem-xf empty",
":type": "core/wcm/components/experiencefragment/v1/experiencefragment"
}
@@ -1,4 +1,8 @@
{
"localizedFragmentVariationPath":"/content/experience-fragments/mysite/us/es/footer/master/jcr:content",
":type": "core/wcm/components/experiencefragment/v1/experiencefragment"
}
"localizedFragmentVariationPath": "/content/experience-fragments/mysite/us/es/footer/master/jcr:content",
"configured": false,
":type": "core/wcm/components/experiencefragment/v1/experiencefragment",
"classNames": "aem-xf empty",
":itemsOrder": [],
":items": {}
}
@@ -1,4 +1,8 @@
{
"localizedFragmentVariationPath":"/content/experience-fragments/mysite/us/en/footer/master/jcr:content",
":type": "core/wcm/components/experiencefragment/v1/experiencefragment"
}
"localizedFragmentVariationPath": "/content/experience-fragments/mysite/us/en/footer/master/jcr:content",
"configured": false,
":type": "core/wcm/components/experiencefragment/v1/experiencefragment",
"classNames": "aem-xf empty",
":itemsOrder": [],
":items": {}
}
@@ -1,3 +1,7 @@
{
":type": "core/wcm/components/experiencefragment/v1/experiencefragment"
}
"configured": false,
":type": "core/wcm/components/experiencefragment/v1/experiencefragment",
":itemsOrder": [],
":items": {},
"classNames": "aem-xf empty"
}
@@ -1,3 +1,7 @@
{
":type": "core/wcm/components/experiencefragment/v1/experiencefragment"
}
"configured": false,
":type": "core/wcm/components/experiencefragment/v1/experiencefragment",
"classNames": "aem-xf empty",
":itemsOrder": [],
":items": {}
}

0 comments on commit 80f3f56

Please sign in to comment.