use of com.adobe.acs.commons.mcp.impl.AbstractResourceImpl in project acs-aem-commons by Adobe-Consulting-Services.
the class BrokenLinksTest method getEnhancedMockResolver.
private ResourceResolver getEnhancedMockResolver() throws RepositoryException, LoginException {
ResourceResolver rr = getFreshMockResolver();
AbstractResourceImpl processes = new AbstractResourceImpl(ProcessInstanceImpl.BASE_PATH, null, null, new ResourceMetadata());
when(rr.getResource(ProcessInstanceImpl.BASE_PATH)).thenReturn(processes);
Session ses = mock(Session.class);
when(rr.adaptTo(Session.class)).thenReturn(ses);
AccessControlManager acm = mock(AccessControlManager.class);
when(ses.getAccessControlManager()).thenReturn(acm);
when(acm.privilegeFromName(any())).thenReturn(mock(Privilege.class));
when(acm.hasPrivileges(any(), any())).thenReturn(true);
return rr;
}
use of com.adobe.acs.commons.mcp.impl.AbstractResourceImpl in project acs-aem-commons by Adobe-Consulting-Services.
the class SelectComponent method buildComponentResource.
@Override
public Resource buildComponentResource() {
AbstractResourceImpl component = (AbstractResourceImpl) super.buildComponentResource();
AbstractResourceImpl options = new AbstractResourceImpl("items", null, null, new ResourceMetadata());
component.addChild(options);
String defaultValue = getOption("default").orElse(null);
getOptions().forEach((value, name) -> {
final ResourceMetadata meta = new ResourceMetadata();
final String nodeName = JcrUtil.escapeIllegalJcrChars(value);
if (value.equals(defaultValue)) {
meta.put("selected", true);
}
meta.put("value", value);
meta.put("text", name);
AbstractResourceImpl option = new AbstractResourceImpl("option_" + nodeName, null, null, meta);
options.addChild(option);
});
return component;
}
use of com.adobe.acs.commons.mcp.impl.AbstractResourceImpl in project acs-aem-commons by Adobe-Consulting-Services.
the class BrokenLinksTest method reportBrokenReferences.
@Test
public void reportBrokenReferences() throws Exception {
ResourceResolver rr = getEnhancedMockResolver();
AbstractResourceImpl content = new AbstractResourceImpl("/content", "cq:Page", "cq:Page", new ResourceMetadata());
AbstractResourceImpl pageA = new AbstractResourceImpl("/content/pageA", "cq:Page", "cq:Page", new ResourceMetadata());
content.addChild(pageA);
AbstractResourceImpl pageAcontent = new AbstractResourceImpl("/content/pageA/jcr:content", "cq:PageContent", "cq:PageContent", new ResourceMetadata() {
{
put("ref1", "/content/pageA");
put("ref2", "/content/pageB");
put("ref3", "/content/pageC");
}
});
pageA.addChild(pageAcontent);
AbstractResourceImpl pageB = new AbstractResourceImpl("/content/pageB", "cq:Page", "cq:Page", new ResourceMetadata());
content.addChild(pageB);
AbstractResourceImpl pageBcontent = new AbstractResourceImpl("/content/pageB/jcr:content", "cq:PageContent", "cq:PageContent", new ResourceMetadata() {
{
put("ignoredRef", "/content/pageC");
put("ref2", "/content/pageD");
put("ref3", "/content/pageE");
}
});
pageB.addChild(pageBcontent);
when(rr.getResource("/content")).thenReturn(content);
pageA.setResourceResolver(rr);
pageAcontent.setResourceResolver(rr);
pageB.setResourceResolver(rr);
pageBcontent.setResourceResolver(rr);
when(rr.resolve("/content/pageA")).thenReturn(pageA);
when(rr.resolve("/content/pageB")).thenReturn(pageB);
when(rr.resolve("/content/pageC")).thenReturn(new NonExistingResource(rr, "/content/pageC"));
when(rr.resolve("/content/pageD")).thenReturn(new NonExistingResource(rr, "/content/pageD"));
when(rr.resolve("/content/pageE")).thenReturn(new NonExistingResource(rr, "/content/pageE"));
Map<String, Object> values = new HashMap<>();
values.put("sourcePath", "/content");
values.put("propertyRegex", "^/(etc|content)/.+");
values.put("excludeProperties", "ignoredRef");
ProcessInstanceImpl instance = new ProcessInstanceImpl(getControlledProcessManager(), tool, "broken references");
instance.init(rr, values);
instance.run(rr);
Map<String, EnumMap<Report, Object>> reportData = tool.getReportData();
assertEquals(3, reportData.size());
assertEquals("/content/pageC", reportData.get("/content/pageA/jcr:content/ref3").get(Report.reference));
assertEquals("/content/pageD", reportData.get("/content/pageB/jcr:content/ref2").get(Report.reference));
assertEquals("/content/pageE", reportData.get("/content/pageB/jcr:content/ref3").get(Report.reference));
assertFalse("ignoredRef is in the exclude list", reportData.containsKey("/content/pageB/jcr:content/ignoredRef"));
}
use of com.adobe.acs.commons.mcp.impl.AbstractResourceImpl in project acs-aem-commons by Adobe-Consulting-Services.
the class FieldComponent method buildComponentResource.
/**
* If your component needs child nodes then override this method, call the superclass implementation, and then use addChildren
* to add additional nodes to it.
* @return
*/
public Resource buildComponentResource() {
AbstractResourceImpl res = new AbstractResourceImpl("/fake/path", resourceType, resourceSuperType, componentMetadata);
res.setResourceResolver(sling.getRequest().getResourceResolver());
return res;
}
use of com.adobe.acs.commons.mcp.impl.AbstractResourceImpl in project acs-aem-commons by Adobe-Consulting-Services.
the class RadioComponent method buildComponentResource.
@Override
public Resource buildComponentResource() {
AbstractResourceImpl component = (AbstractResourceImpl) super.buildComponentResource();
AbstractResourceImpl options = new AbstractResourceImpl("items", null, null, new ResourceMetadata());
component.addChild(options);
String defaultValue = getOption("default").orElse(null);
getOptions().forEach((value, name) -> {
final ResourceMetadata meta = new ResourceMetadata();
final String nodeName = JcrUtil.escapeIllegalJcrChars(value);
if (value.equals(defaultValue)) {
meta.put("checked", true);
}
meta.put("name", getName());
meta.put("value", value);
meta.put("text", name);
AbstractResourceImpl option = new AbstractResourceImpl("option_" + nodeName, "granite/ui/components/foundation/form/radio", "granite/ui/components/foundation/form/field", meta);
options.addChild(option);
});
return component;
}
Aggregations