-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Co-authored-by: Roy Teeuwen <[email protected]> Co-authored-by: Stefan Seifert <[email protected]>
- Loading branch information
1 parent
14f8afd
commit 4119165
Showing
8 changed files
with
564 additions
and
1 deletion.
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
78 changes: 78 additions & 0 deletions
78
core/src/main/java/io/wcm/testing/mock/aem/xf/MockExperienceFragment.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,78 @@ | ||
/* | ||
* #%L | ||
* wcm.io | ||
* %% | ||
* Copyright (C) 2019 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.xf; | ||
|
||
import static com.adobe.cq.xf.ExperienceFragmentsConstants.PN_XF_VARIANT_TYPE; | ||
import static com.adobe.cq.xf.ExperienceFragmentsConstants.RT_EXPERIENCE_FRAGMENT_PAGE; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashSet; | ||
import java.util.Iterator; | ||
import java.util.List; | ||
import java.util.Set; | ||
|
||
import org.apache.commons.lang3.StringUtils; | ||
import org.apache.sling.api.resource.ValueMap; | ||
|
||
import com.adobe.cq.xf.ExperienceFragment; | ||
import com.adobe.cq.xf.ExperienceFragmentVariation; | ||
import com.day.cq.commons.Filter; | ||
import com.day.cq.wcm.api.Page; | ||
|
||
/** | ||
* Mock implementation of {@link ExperienceFragment}. | ||
*/ | ||
class MockExperienceFragment extends MockExperienceFragmentBase implements ExperienceFragment { | ||
|
||
MockExperienceFragment(Page page) { | ||
super(page); | ||
} | ||
|
||
@Override | ||
public List<ExperienceFragmentVariation> getVariations() { | ||
List<ExperienceFragmentVariation> variations = new ArrayList<>(); | ||
Iterator<Page> it = getPage().listChildren(element -> element.getContentResource().isResourceType(RT_EXPERIENCE_FRAGMENT_PAGE)); | ||
while (it.hasNext()) { | ||
Page thePage = it.next(); | ||
variations.add(thePage.adaptTo(ExperienceFragmentVariation.class)); | ||
} | ||
return variations; | ||
} | ||
|
||
@Override | ||
public List<ExperienceFragmentVariation> getVariations(String... type) { | ||
final Set<String> typeValues = new HashSet<>(List.of(type)); | ||
Filter<Page> typeFilter = element -> { | ||
ValueMap properties = element.getProperties(); | ||
String variantType = properties.get(PN_XF_VARIANT_TYPE, ""); | ||
if (StringUtils.isEmpty(variantType)) { | ||
return false; | ||
} | ||
return typeValues.contains(variantType); | ||
}; | ||
List<ExperienceFragmentVariation> variations = new ArrayList<>(); | ||
for (Iterator<Page> it = getPage().listChildren(typeFilter); it.hasNext();) { | ||
Page page = it.next(); | ||
variations.add(page.adaptTo(ExperienceFragmentVariation.class)); | ||
} | ||
return variations; | ||
} | ||
|
||
} |
62 changes: 62 additions & 0 deletions
62
core/src/main/java/io/wcm/testing/mock/aem/xf/MockExperienceFragmentAdapterFactory.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,62 @@ | ||
/* | ||
* #%L | ||
* wcm.io | ||
* %% | ||
* Copyright (C) 2019 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.xf; | ||
|
||
import org.apache.sling.api.adapter.AdapterFactory; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
import org.osgi.annotation.versioning.ProviderType; | ||
import org.osgi.service.component.annotations.Component; | ||
|
||
import com.adobe.cq.xf.ExperienceFragment; | ||
import com.adobe.cq.xf.ExperienceFragmentVariation; | ||
import com.adobe.cq.xf.ExperienceFragmentsConstants; | ||
import com.day.cq.wcm.api.Page; | ||
|
||
/** | ||
* Mock adapter factory for AEM Experience Fragment-related adaptions. | ||
*/ | ||
@Component(service = AdapterFactory.class, | ||
property = { | ||
AdapterFactory.ADAPTABLE_CLASSES + "=com.day.cq.wcm.api.Page", | ||
AdapterFactory.ADAPTER_CLASSES + "=com.adobe.cq.xf.ExperienceFragment", | ||
AdapterFactory.ADAPTER_CLASSES + "=com.adobe.cq.xf.ExperienceFragmentVariation" | ||
}) | ||
@ProviderType | ||
public final class MockExperienceFragmentAdapterFactory implements AdapterFactory { | ||
|
||
@SuppressWarnings("unchecked") | ||
@Override | ||
public @Nullable <AdapterType> AdapterType getAdapter(@NotNull Object object, @NotNull Class<AdapterType> type) { | ||
if (object instanceof Page) { | ||
Page page = (Page)object; | ||
if (page.getContentResource().isResourceType(ExperienceFragmentsConstants.RT_EXPERIENCE_FRAGMENT_MASTER) && (type == ExperienceFragment.class)) { | ||
return (AdapterType)new MockExperienceFragment(page); | ||
|
||
} | ||
if (page.getContentResource().isResourceType(ExperienceFragmentsConstants.RT_EXPERIENCE_FRAGMENT_PAGE) && (type == ExperienceFragmentVariation.class)) { | ||
return (AdapterType)new MockExperienceFragmentVariation(page); | ||
|
||
} | ||
} | ||
return null; | ||
} | ||
|
||
} |
75 changes: 75 additions & 0 deletions
75
core/src/main/java/io/wcm/testing/mock/aem/xf/MockExperienceFragmentBase.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,75 @@ | ||
/* | ||
* #%L | ||
* wcm.io | ||
* %% | ||
* Copyright (C) 2019 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.xf; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
import org.apache.sling.api.adapter.SlingAdaptable; | ||
import org.apache.sling.api.resource.Resource; | ||
import org.apache.sling.api.resource.ValueMap; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import com.day.cq.commons.inherit.HierarchyNodeInheritanceValueMap; | ||
import com.day.cq.commons.inherit.InheritanceValueMap; | ||
import com.day.cq.wcm.api.Page; | ||
|
||
class MockExperienceFragmentBase extends SlingAdaptable { | ||
|
||
private final Page page; | ||
|
||
protected MockExperienceFragmentBase(Page page) { | ||
this.page = page; | ||
} | ||
|
||
public String getPath() { | ||
return page.getPath(); | ||
} | ||
|
||
public ValueMap getProperties() { | ||
return page.getProperties(); | ||
} | ||
|
||
public List<String> getCloudserviceConfigurationsPaths() { | ||
return Arrays.asList(getInheritedProperties().getInherited("cq:cloudserviceconfigs", new String[0])); | ||
} | ||
|
||
protected InheritanceValueMap getInheritedProperties() { | ||
return new HierarchyNodeInheritanceValueMap(page.getContentResource()); | ||
} | ||
|
||
@Override | ||
@SuppressWarnings({ "unchecked", "null" }) | ||
public @Nullable <AdapterType> AdapterType adaptTo(@NotNull Class<AdapterType> type) { | ||
if (type == Resource.class) { | ||
return (AdapterType)page.adaptTo(Resource.class); | ||
} | ||
if (type == Page.class) { | ||
return (AdapterType)page; | ||
} | ||
return super.adaptTo(type); | ||
} | ||
|
||
protected Page getPage() { | ||
return page; | ||
} | ||
|
||
} |
74 changes: 74 additions & 0 deletions
74
core/src/main/java/io/wcm/testing/mock/aem/xf/MockExperienceFragmentVariation.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,74 @@ | ||
/* | ||
* #%L | ||
* wcm.io | ||
* %% | ||
* Copyright (C) 2019 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.xf; | ||
|
||
import static com.adobe.cq.xf.ExperienceFragmentsConstants.CUSTOM_XF_VARIANT_TYPE; | ||
import static com.adobe.cq.xf.ExperienceFragmentsConstants.PN_XF_VARIANT_TYPE; | ||
|
||
import org.apache.sling.api.resource.ValueMap; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import com.adobe.cq.xf.ExperienceFragment; | ||
import com.adobe.cq.xf.ExperienceFragmentVariation; | ||
import com.day.cq.commons.inherit.InheritanceValueMap; | ||
import com.day.cq.wcm.api.Page; | ||
|
||
/** | ||
* Mock implementation of {@link ExperienceFragmentVariation}. | ||
*/ | ||
class MockExperienceFragmentVariation extends MockExperienceFragmentBase implements ExperienceFragmentVariation { | ||
|
||
private ExperienceFragment parent; | ||
|
||
MockExperienceFragmentVariation(Page page) { | ||
super(page); | ||
} | ||
|
||
@Override | ||
public ExperienceFragment getParent() { | ||
if (this.parent == null) { | ||
this.parent = new MockExperienceFragment(getPage().getParent()); | ||
} | ||
return this.parent; | ||
} | ||
|
||
@Override | ||
public String getType() { | ||
ValueMap properties = getPage().getProperties(); | ||
String type = properties.get(PN_XF_VARIANT_TYPE, String.class); | ||
return (type != null) ? type : CUSTOM_XF_VARIANT_TYPE; | ||
} | ||
|
||
@Override | ||
@SuppressWarnings("unchecked") | ||
public @Nullable <AdapterType> AdapterType adaptTo(@NotNull Class<AdapterType> type) { | ||
if (type == Page.class) { | ||
return (AdapterType)getPage(); | ||
} | ||
return super.adaptTo(type); | ||
} | ||
|
||
@Override | ||
public InheritanceValueMap getPropertiesTree() { | ||
return getInheritedProperties(); | ||
} | ||
|
||
} |
Oops, something went wrong.