Search in sources :

Example 1 with WorkItem

use of com.day.cq.workflow.exec.WorkItem in project acs-aem-commons by Adobe-Consulting-Services.

the class RenditionModifyingProcessTest method test_with_null_rendition_arg_is_noop.

@Test
public void test_with_null_rendition_arg_is_noop() throws Exception {
    WorkItem workItem = mock(WorkItem.class);
    MetaDataMap metaData = new SimpleMetaDataMap();
    process.execute(workItem, workflowSession, metaData, workflowHelper);
    verifyZeroInteractions(harness);
}
Also used : SimpleMetaDataMap(com.day.cq.workflow.metadata.SimpleMetaDataMap) MetaDataMap(com.day.cq.workflow.metadata.MetaDataMap) SimpleMetaDataMap(com.day.cq.workflow.metadata.SimpleMetaDataMap) WorkItem(com.day.cq.workflow.exec.WorkItem) Test(org.junit.Test)

Example 2 with WorkItem

use of com.day.cq.workflow.exec.WorkItem in project acs-aem-commons by Adobe-Consulting-Services.

the class RenditionModifyingProcessTest method test_with_blank_rendition_arg_is_noop.

@Test
public void test_with_blank_rendition_arg_is_noop() throws Exception {
    WorkItem workItem = mock(WorkItem.class);
    MetaDataMap metaData = new SimpleMetaDataMap();
    metaData.put("PROCESS_ARGS", "");
    process.execute(workItem, workflowSession, metaData, workflowHelper);
    verifyZeroInteractions(harness);
}
Also used : SimpleMetaDataMap(com.day.cq.workflow.metadata.SimpleMetaDataMap) MetaDataMap(com.day.cq.workflow.metadata.MetaDataMap) SimpleMetaDataMap(com.day.cq.workflow.metadata.SimpleMetaDataMap) WorkItem(com.day.cq.workflow.exec.WorkItem) Test(org.junit.Test)

Example 3 with WorkItem

use of com.day.cq.workflow.exec.WorkItem in project acs-aem-commons by Adobe-Consulting-Services.

the class RenditionModifyingProcessTest method test_with_rendition_arg_getting_no_rendition_is_noop.

@Test
public void test_with_rendition_arg_getting_no_rendition_is_noop() throws Exception {
    String path = "/content/dam/some/path.ext";
    WorkItem workItem = mock(WorkItem.class);
    WorkflowData data = mock(WorkflowData.class);
    when(workItem.getWorkflowData()).thenReturn(data);
    when(data.getPayloadType()).thenReturn(WorkflowHelper.TYPE_JCR_PATH);
    when(data.getPayload()).thenReturn(path);
    Resource resource = mock(Resource.class);
    Asset asset = mock(Asset.class);
    when(resource.adaptTo(Asset.class)).thenReturn(asset);
    when(resource.getResourceType()).thenReturn(DamConstants.NT_DAM_ASSET);
    when(resourceResolver.getResource(path)).thenReturn(resource);
    MetaDataMap metaData = new SimpleMetaDataMap();
    metaData.put("PROCESS_ARGS", "renditionName:test");
    process.execute(workItem, workflowSession, metaData, workflowHelper);
    verifyZeroInteractions(harness);
}
Also used : SimpleMetaDataMap(com.day.cq.workflow.metadata.SimpleMetaDataMap) Resource(org.apache.sling.api.resource.Resource) MetaDataMap(com.day.cq.workflow.metadata.MetaDataMap) SimpleMetaDataMap(com.day.cq.workflow.metadata.SimpleMetaDataMap) Asset(com.day.cq.dam.api.Asset) WorkItem(com.day.cq.workflow.exec.WorkItem) WorkflowData(com.day.cq.workflow.exec.WorkflowData) Test(org.junit.Test)

Example 4 with WorkItem

use of com.day.cq.workflow.exec.WorkItem in project acs-aem-commons by Adobe-Consulting-Services.

the class RenditionModifyingProcessTest method test_with_rendition_arg_getting_real_rendition.

@Test
public void test_with_rendition_arg_getting_real_rendition() throws Exception {
    String path = "/content/dam/some/path.ext";
    WorkItem workItem = mock(WorkItem.class);
    WorkflowData data = mock(WorkflowData.class);
    when(workItem.getWorkflowData()).thenReturn(data);
    when(data.getPayloadType()).thenReturn(WorkflowHelper.TYPE_JCR_PATH);
    when(data.getPayload()).thenReturn(path);
    Resource resource = mock(Resource.class);
    Asset asset = mock(Asset.class);
    Rendition rendition = mock(Rendition.class);
    when(resource.adaptTo(Asset.class)).thenReturn(asset);
    when(resource.getResourceType()).thenReturn(DamConstants.NT_DAM_ASSET);
    when(resourceResolver.getResource(path)).thenReturn(resource);
    when(asset.getRendition(isA(RenditionPicker.class))).thenReturn(rendition);
    when(rendition.getStream()).then(new Answer<InputStream>() {

        @Override
        public InputStream answer(InvocationOnMock invocation) throws Throwable {
            return getClass().getResourceAsStream("/img/test.png");
        }
    });
    when(harness.processLayer(any(Layer.class), eq(rendition), eq(workflowSession), any(String[].class))).thenAnswer(new Answer<Layer>() {

        @Override
        public Layer answer(InvocationOnMock invocation) throws Throwable {
            return (Layer) invocation.getArguments()[0];
        }
    });
    MetaDataMap metaData = new SimpleMetaDataMap();
    metaData.put("PROCESS_ARGS", "renditionName:test");
    process.execute(workItem, workflowSession, metaData, workflowHelper);
    verify(harness, times(1)).processLayer(any(Layer.class), eq(rendition), eq(workflowSession), any(String[].class));
    verify(harness, times(1)).saveImage(eq(asset), eq(rendition), any(Layer.class), eq("image/png"), eq(0.6));
}
Also used : Rendition(com.day.cq.dam.api.Rendition) InputStream(java.io.InputStream) Resource(org.apache.sling.api.resource.Resource) RenditionPicker(com.day.cq.dam.api.RenditionPicker) WorkItem(com.day.cq.workflow.exec.WorkItem) Layer(com.day.image.Layer) WorkflowData(com.day.cq.workflow.exec.WorkflowData) InvocationOnMock(org.mockito.invocation.InvocationOnMock) SimpleMetaDataMap(com.day.cq.workflow.metadata.SimpleMetaDataMap) MetaDataMap(com.day.cq.workflow.metadata.MetaDataMap) SimpleMetaDataMap(com.day.cq.workflow.metadata.SimpleMetaDataMap) Asset(com.day.cq.dam.api.Asset) Test(org.junit.Test)

Aggregations

WorkItem (com.day.cq.workflow.exec.WorkItem)4 MetaDataMap (com.day.cq.workflow.metadata.MetaDataMap)4 SimpleMetaDataMap (com.day.cq.workflow.metadata.SimpleMetaDataMap)4 Test (org.junit.Test)4 Asset (com.day.cq.dam.api.Asset)2 WorkflowData (com.day.cq.workflow.exec.WorkflowData)2 Resource (org.apache.sling.api.resource.Resource)2 Rendition (com.day.cq.dam.api.Rendition)1 RenditionPicker (com.day.cq.dam.api.RenditionPicker)1 Layer (com.day.image.Layer)1 InputStream (java.io.InputStream)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1