Search in sources :

Example 1 with ProcessInstanceImpl

use of com.adobe.acs.commons.mcp.impl.ProcessInstanceImpl in project acs-aem-commons by Adobe-Consulting-Services.

the class FolderRelocatorTest method testRequiredFields.

@Test
public void testRequiredFields() throws LoginException, DeserializeException, RepositoryException {
    ResourceResolver rr = getEnhancedMockResolver();
    FolderRelocator tool = new FolderRelocatorFactory().createProcessDefinition();
    ProcessInstance instance = new ProcessInstanceImpl(getControlledProcessManager(), tool, "relocator test");
    assertEquals("Folder Relocator: relocator test", instance.getName());
    try {
        instance.init(rr, Collections.EMPTY_MAP);
        fail("That should have thrown an error");
    } catch (DeserializeException ex) {
    // Expected
    }
}
Also used : ProcessInstanceImpl(com.adobe.acs.commons.mcp.impl.ProcessInstanceImpl) ResourceResolver(org.apache.sling.api.resource.ResourceResolver) ProcessInstance(com.adobe.acs.commons.mcp.ProcessInstance) DeserializeException(com.adobe.acs.commons.mcp.util.DeserializeException) Test(org.junit.Test) ActionManagerTest(com.adobe.acs.commons.fam.impl.ActionManagerTest)

Example 2 with ProcessInstanceImpl

use of com.adobe.acs.commons.mcp.impl.ProcessInstanceImpl in project acs-aem-commons by Adobe-Consulting-Services.

the class PageRelocatorTest method aclFail.

@Test
public void aclFail() throws LoginException, DeserializeException, RepositoryException, PersistenceException {
    ResourceResolver rr = getEnhancedMockResolver(false);
    ProcessInstance instance = new ProcessInstanceImpl(getControlledProcessManager(), tool, "relocator test");
    assertEquals("Page Relocator: relocator test", instance.getName());
    initInstance(instance, rr);
    instance.run(rr);
    assertFalse("ACL issues should have been tracked", instance.getInfo().getReportedErrors().isEmpty());
    assertEquals("Aborted", instance.getInfo().getStatus());
}
Also used : ProcessInstanceImpl(com.adobe.acs.commons.mcp.impl.ProcessInstanceImpl) ResourceResolver(org.apache.sling.api.resource.ResourceResolver) ProcessInstance(com.adobe.acs.commons.mcp.ProcessInstance) Test(org.junit.Test) ActionManagerTest(com.adobe.acs.commons.fam.impl.ActionManagerTest)

Example 3 with ProcessInstanceImpl

use of com.adobe.acs.commons.mcp.impl.ProcessInstanceImpl 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"));
}
Also used : ProcessInstanceImpl(com.adobe.acs.commons.mcp.impl.ProcessInstanceImpl) AbstractResourceImpl(com.adobe.acs.commons.mcp.impl.AbstractResourceImpl) Test(org.junit.Test) ActionManagerTest(com.adobe.acs.commons.fam.impl.ActionManagerTest)

Example 4 with ProcessInstanceImpl

use of com.adobe.acs.commons.mcp.impl.ProcessInstanceImpl in project acs-aem-commons by Adobe-Consulting-Services.

the class FolderRelocatorTest method barebonesRun.

@Test
public void barebonesRun() throws LoginException, DeserializeException, RepositoryException, PersistenceException {
    ResourceResolver rr = getEnhancedMockResolver();
    FolderRelocator tool = new FolderRelocatorFactory().createProcessDefinition();
    ProcessInstance instance = new ProcessInstanceImpl(getControlledProcessManager(), tool, "relocator test");
    assertEquals("Folder Relocator: relocator test", instance.getName());
    Map<String, Object> values = new HashMap<>();
    values.put("sourcePaths", "/content/folderA");
    values.put("destinationPath", "/content/folderB");
    values.put("mode", FolderRelocator.Mode.MOVE.toString());
    instance.init(rr, values);
    assertEquals(0.0, instance.updateProgress(), 0.00001);
    instance.run(rr);
    assertEquals(1.0, instance.updateProgress(), 0.00001);
    verify(rr, atLeast(3)).commit();
}
Also used : HashMap(java.util.HashMap) ProcessInstanceImpl(com.adobe.acs.commons.mcp.impl.ProcessInstanceImpl) ResourceResolver(org.apache.sling.api.resource.ResourceResolver) ProcessInstance(com.adobe.acs.commons.mcp.ProcessInstance) Test(org.junit.Test) ActionManagerTest(com.adobe.acs.commons.fam.impl.ActionManagerTest)

Example 5 with ProcessInstanceImpl

use of com.adobe.acs.commons.mcp.impl.ProcessInstanceImpl in project acs-aem-commons by Adobe-Consulting-Services.

the class FolderRelocatorTest method testHaltingScenario.

@Test
public void testHaltingScenario() throws DeserializeException, LoginException, RepositoryException, InterruptedException, ExecutionException, PersistenceException {
    ResourceResolver rr = getEnhancedMockResolver();
    FolderRelocator tool = new FolderRelocatorFactory().createProcessDefinition();
    ProcessInstance instance = new ProcessInstanceImpl(getControlledProcessManager(), tool, "relocator test");
    assertEquals("Folder Relocator: relocator test", instance.getName());
    Map<String, Object> values = new HashMap<>();
    values.put("sourcePaths", "/content/folderA");
    values.put("destinationPath", "/content/folderB");
    values.put("mode", FolderRelocator.Mode.MOVE.toString());
    instance.init(rr, values);
    CompletableFuture<Boolean> f = new CompletableFuture<>();
    instance.defineAction("Halt", rr, am -> {
        instance.halt();
        try {
            assertTrue(instance.updateProgress() < 1.0);
            assertFalse(instance.getInfo().isIsRunning());
            f.complete(true);
        } catch (Throwable t) {
            f.completeExceptionally(t);
        }
    });
    instance.run(rr);
    assertTrue(f.get());
    verify(rr, atLeastOnce()).commit();
}
Also used : HashMap(java.util.HashMap) ProcessInstanceImpl(com.adobe.acs.commons.mcp.impl.ProcessInstanceImpl) CompletableFuture(java.util.concurrent.CompletableFuture) ResourceResolver(org.apache.sling.api.resource.ResourceResolver) ProcessInstance(com.adobe.acs.commons.mcp.ProcessInstance) Test(org.junit.Test) ActionManagerTest(com.adobe.acs.commons.fam.impl.ActionManagerTest)

Aggregations

ActionManagerTest (com.adobe.acs.commons.fam.impl.ActionManagerTest)7 ProcessInstanceImpl (com.adobe.acs.commons.mcp.impl.ProcessInstanceImpl)7 Test (org.junit.Test)7 ProcessInstance (com.adobe.acs.commons.mcp.ProcessInstance)6 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)6 HashMap (java.util.HashMap)2 ActionManager (com.adobe.acs.commons.fam.ActionManager)1 AbstractResourceImpl (com.adobe.acs.commons.mcp.impl.AbstractResourceImpl)1 DeserializeException (com.adobe.acs.commons.mcp.util.DeserializeException)1 CompletableFuture (java.util.concurrent.CompletableFuture)1