Search in sources :

Example 1 with ProcessInstance

use of com.adobe.acs.commons.mcp.ProcessInstance 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 ProcessInstance

use of com.adobe.acs.commons.mcp.ProcessInstance 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 ProcessInstance

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

the class ControlledProcessManagerServlet method doStartProcess.

private ProcessInstance doStartProcess(SlingHttpServletRequest request) throws RepositoryException, ReflectiveOperationException, DeserializeException {
    String def = request.getParameter("definition");
    String description = request.getParameter("description");
    ProcessDefinition definition = manager.findDefinitionByNameOrPath(def);
    ProcessInstance instance = manager.createManagedProcessInstance(definition, description);
    instance.init(request.getResourceResolver(), convertRequestMap(request.getRequestParameterMap()));
    instance.run(request.getResourceResolver());
    return instance;
}
Also used : ProcessDefinition(com.adobe.acs.commons.mcp.ProcessDefinition) ProcessInstance(com.adobe.acs.commons.mcp.ProcessInstance)

Example 4 with ProcessInstance

use of com.adobe.acs.commons.mcp.ProcessInstance 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 ProcessInstance

use of com.adobe.acs.commons.mcp.ProcessInstance 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

ProcessInstance (com.adobe.acs.commons.mcp.ProcessInstance)9 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)7 ActionManagerTest (com.adobe.acs.commons.fam.impl.ActionManagerTest)6 ProcessInstanceImpl (com.adobe.acs.commons.mcp.impl.ProcessInstanceImpl)6 Test (org.junit.Test)6 ArchivedProcessInstance (com.adobe.acs.commons.mcp.model.impl.ArchivedProcessInstance)2 HashMap (java.util.HashMap)2 ActionManager (com.adobe.acs.commons.fam.ActionManager)1 ProcessDefinition (com.adobe.acs.commons.mcp.ProcessDefinition)1 DeserializeException (com.adobe.acs.commons.mcp.util.DeserializeException)1 TreeFilteringResourceVisitor (com.adobe.acs.commons.util.visitors.TreeFilteringResourceVisitor)1 ArrayList (java.util.ArrayList)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 LoginException (org.apache.sling.api.resource.LoginException)1 Resource (org.apache.sling.api.resource.Resource)1