use of com.day.cq.wcm.msm.api.LiveCopy 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.LiveCopy in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class LocalizationUtils method getBlueprintPath.
/**
* Returns the path of the blueprint of the resource.
*
* @param resource the resource
* @param relationshipManager the live relationship manager service
* @return the path of the blueprint of the resource if it exists, {@code null} otherwise
*/
@Nullable
public static String getBlueprintPath(@NotNull Resource resource, @NotNull LiveRelationshipManager relationshipManager) {
try {
if (relationshipManager.isSource(resource)) {
// the resource is a blueprint
RangeIterator liveCopiesIterator = relationshipManager.getLiveRelationships(resource, null, null);
if (liveCopiesIterator != null) {
LiveRelationship relationship = (LiveRelationship) liveCopiesIterator.next();
LiveCopy liveCopy = relationship.getLiveCopy();
if (liveCopy != null) {
return liveCopy.getBlueprintPath();
}
}
}
} catch (WCMException e) {
LOGGER.error("Unable to get the blueprint: {}", e.getMessage());
}
return null;
}
Aggregations