use of com.day.cq.wcm.msm.api.LiveRelationshipManager in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class ContainerServletTest method setUp.
@BeforeEach
public void setUp() throws WCMException, NoSuchFieldException {
context.load().json(TEST_BASE + CoreComponentTestContext.TEST_CONTENT_JSON, CONTENT_ROOT);
// make the carousel component the current resource
context.currentResource(CAROUSEL_PATH);
// set http method
context.request().setMethod("POST");
// live relationship manager
LiveRelationshipManager liveRelationshipManager = mock(LiveRelationshipManager.class);
when(liveRelationshipManager.getLiveRelationship(any(Resource.class), anyBoolean())).then(invocation -> {
Object[] arguments = invocation.getArguments();
Resource resource = (Resource) arguments[0];
if (LIVE_COPY_PATH.equals(resource.getPath())) {
LiveRelationship liveRelationship = mock(LiveRelationship.class);
LiveStatus liveStatus = mock(LiveStatus.class);
when(liveStatus.isSourceExisting()).thenReturn(true);
when(liveRelationship.getStatus()).thenReturn(liveStatus);
return liveRelationship;
}
return null;
});
FieldSetter.setField(servlet, servlet.getClass().getDeclaredField("liveRelationshipManager"), liveRelationshipManager);
}
use of com.day.cq.wcm.msm.api.LiveRelationshipManager in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class NavigationImplTest method internalSetup.
protected void internalSetup() throws WCMException {
context.load().json(testBase + CoreComponentTestContext.TEST_CONTENT_JSON, "/content");
context.load().json(testBase + "/test-conf.json", "/conf");
context.registerService(LanguageManager.class, new MockLanguageManager());
LiveRelationshipManager relationshipManager = mock(LiveRelationshipManager.class);
when(relationshipManager.getLiveRelationships(any(Resource.class), isNull(), isNull())).then(invocation -> {
Object[] arguments = invocation.getArguments();
Resource resource = (Resource) arguments[0];
if ("/content/navigation-blueprint".equals(resource.getPath())) {
LiveRelationship liveRelationship = mock(LiveRelationship.class);
when(liveRelationship.getTargetPath()).thenReturn("/content/navigation-livecopy");
final ArrayList<LiveRelationship> relationships = new ArrayList<>();
relationships.add(liveRelationship);
final Iterator<LiveRelationship> iterator = relationships.iterator();
return new RangeIterator() {
int index = 0;
@Override
public void skip(long skipNum) {
}
@Override
public long getSize() {
return relationships.size();
}
@Override
public long getPosition() {
return index;
}
@Override
public boolean hasNext() {
return iterator.hasNext();
}
@Override
public Object next() {
index++;
return iterator.next();
}
};
}
return null;
});
context.registerService(LiveRelationshipManager.class, relationshipManager);
}
use of com.day.cq.wcm.msm.api.LiveRelationshipManager in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class LocalizationUtils method getLocalPage.
/**
* Given the current requested page and a reference page, this method will determine a page belonging to the
* current site and locale that can be used instead of the reference site.
*
* Specifically, if the reference page and the current page are both found under a language root, and that language
* root is not the same, then the returned page is the page located under the current page's language root at the
* same relative path as the reference page is located under it's own language root; or empty if that page does not
* exist.
*
* If either the reference page or the current page are not located under a language root, or if they share the
* same language root, and if the reference page has a live relationship where the target is the current page or
* an ancestor of the current page, then the target of that live relationship is returned; or empty if that page
* does not exist.
*
* All other conditions return empty.
*
* @param referencePage The referenced page.
* @param currentPage The current page.
* @param resourceResolver A resource resolver.
* @param languageManager The language manager service.
* @param relationshipManager The live relationship manager service.
* @return A page, that belongs to the same language or live copy as the current page, and can be used as the local
* alternative to the referenced page, or empty if no such page exists.
*/
public static Optional<Page> getLocalPage(@NotNull final Page referencePage, @NotNull final Page currentPage, @NotNull final ResourceResolver resourceResolver, @NotNull final LanguageManager languageManager, @NotNull final LiveRelationshipManager relationshipManager) {
Page referencePageLanguageRoot = Optional.ofNullable(referencePage.getPath()).map(resourceResolver::getResource).map(languageManager::getLanguageRoot).orElse(null);
Page currentPageLanguageRoot = languageManager.getLanguageRoot(currentPage.getContentResource());
if (referencePageLanguageRoot != null && currentPageLanguageRoot != null && !referencePageLanguageRoot.equals(currentPageLanguageRoot)) {
// check if there's a language copy of the navigation root
return Optional.ofNullable(referencePage.getPageManager().getPage(ResourceUtil.normalize(String.join("/", currentPageLanguageRoot.getPath(), getRelativePath(referencePageLanguageRoot, referencePage)))));
} else {
try {
String currentPagePath = currentPage.getPath() + "/";
return Optional.of(Optional.ofNullable((Iterator<LiveRelationship>) relationshipManager.getLiveRelationships(referencePage.adaptTo(Resource.class), null, null)).map(liveRelationshipIterator -> StreamSupport.stream(((Iterable<LiveRelationship>) () -> liveRelationshipIterator).spliterator(), false)).orElseGet(Stream::empty).map(LiveRelationship::getTargetPath).filter(target -> currentPagePath.startsWith(target + "/")).map(referencePage.getPageManager()::getPage).findFirst().orElse(referencePage));
} catch (WCMException e) {
// ignore it
}
}
return Optional.empty();
}
use of com.day.cq.wcm.msm.api.LiveRelationshipManager in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class ExperienceFragmentImplTest method setUp.
@BeforeEach
void setUp() throws WCMException {
context.load().json(TEST_BASE + CoreComponentTestContext.TEST_CONTENT_JSON, CONTENT_ROOT);
context.load().json(TEST_BASE + CoreComponentTestContext.TEST_CONF_JSON, CONF_ROOT);
context.load().json(TEST_BASE + CoreComponentTestContext.TEST_APPS_JSON, APPS_ROOT);
LiveRelationshipManager relationshipManager = mock(LiveRelationshipManager.class);
when(relationshipManager.isSource(any(Resource.class))).then(invocation -> {
Object[] arguments = invocation.getArguments();
Resource resource = (Resource) arguments[0];
return BLUEPRINT_PAGE.equals(resource.getPath());
});
when(relationshipManager.getLiveRelationships(any(Resource.class), isNull(), isNull())).then(invocation -> {
Object[] arguments = invocation.getArguments();
Resource resource = (Resource) arguments[0];
if (BLUEPRINT_PAGE.equals(resource.getPath())) {
LiveRelationship liveRelationship = mock(LiveRelationship.class);
LiveCopy liveCopy = mock(LiveCopy.class);
when(liveCopy.getBlueprintPath()).thenReturn(BLUEPRINT_ROOT);
when(liveRelationship.getLiveCopy()).thenReturn(liveCopy);
final ArrayList<LiveRelationship> relationships = new ArrayList<>();
relationships.add(liveRelationship);
final Iterator<LiveRelationship> iterator = relationships.iterator();
return new RangeIterator() {
int index = 0;
@Override
public void skip(long skipNum) {
}
@Override
public long getSize() {
return relationships.size();
}
@Override
public long getPosition() {
return index;
}
@Override
public boolean hasNext() {
return iterator.hasNext();
}
@Override
public Object next() {
index++;
return iterator.next();
}
};
}
return null;
});
when(relationshipManager.hasLiveRelationship(any(Resource.class))).then(invocation -> {
Object[] arguments = invocation.getArguments();
Resource resource = (Resource) arguments[0];
return LIVECOPY_PAGE.equals(resource.getPath());
});
when(relationshipManager.getLiveRelationship(any(Resource.class), anyBoolean())).then(invocation -> {
Object[] arguments = invocation.getArguments();
Resource resource = (Resource) arguments[0];
if (LIVECOPY_PAGE.equals(resource.getPath())) {
LiveRelationship liveRelationship = mock(LiveRelationship.class);
LiveCopy liveCopy = mock(LiveCopy.class);
when(liveCopy.getPath()).thenReturn(LIVECOPY_ROOT);
when(liveRelationship.getLiveCopy()).thenReturn(liveCopy);
return liveRelationship;
}
return null;
});
context.registerService(LiveRelationshipManager.class, relationshipManager);
}
use of com.day.cq.wcm.msm.api.LiveRelationshipManager in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class SearchImplTest method setUp.
@BeforeEach
void setUp() {
context.load().json(TEST_BASE + CoreComponentTestContext.TEST_CONTENT_JSON, CONTENT_ROOT);
LiveRelationshipManager relationshipManager = mock(LiveRelationshipManager.class);
context.registerService(LiveRelationshipManager.class, relationshipManager);
}
Aggregations