Search in sources :

Example 6 with ReplicationOptions

use of com.day.cq.replication.ReplicationOptions in project acs-aem-commons by Adobe-Consulting-Services.

the class DispatcherFlushRulesImplTest method testPreprocess_success_resourceOnly.

@Test
public void testPreprocess_success_resourceOnly() throws Exception {
    resourceOnlyFlushRules.put(Pattern.compile("/content/acs-aem-commons/.*"), new String[] { "/content/target" });
    final ReplicationAction replicationAction = mock(ReplicationAction.class);
    when(replicationAction.getPath()).thenReturn("/content/acs-aem-commons/page");
    when(replicationAction.getType()).thenReturn(ReplicationActionType.ACTIVATE);
    final ReplicationOptions replicationOptions = new ReplicationOptions();
    replicationOptions.setSynchronous(false);
    final ArgumentCaptor<DispatcherFlushFilter> agentFilterCaptor = ArgumentCaptor.forClass(DispatcherFlushFilter.class);
    dispatcherFlushRules.preprocess(replicationAction, replicationOptions);
    verify(dispatcherFlusher, times(1)).flush(any(ResourceResolver.class), eq(ReplicationActionType.ACTIVATE), eq(false), agentFilterCaptor.capture(), eq("/content/target"));
    assertEquals(DispatcherFlushFilter.FlushType.ResourceOnly, agentFilterCaptor.getValue().getFlushType());
    // Private impl class; no access to test for instanceof
    assertEquals("DispatcherFlushRulesFilter", agentFilterCaptor.getValue().getClass().getSimpleName());
    verifyNoMoreInteractions(dispatcherFlusher);
}
Also used : ReplicationOptions(com.day.cq.replication.ReplicationOptions) ReplicationAction(com.day.cq.replication.ReplicationAction) ResourceResolver(org.apache.sling.api.resource.ResourceResolver) DispatcherFlushFilter(com.adobe.acs.commons.replication.dispatcher.DispatcherFlushFilter) Test(org.junit.Test)

Example 7 with ReplicationOptions

use of com.day.cq.replication.ReplicationOptions in project acs-aem-commons by Adobe-Consulting-Services.

the class DispatcherFlushRulesImplTest method testPreprocess_notAccepts_ReplicationActionNoFlushRules.

@Test
public void testPreprocess_notAccepts_ReplicationActionNoFlushRules() throws Exception {
    when(this.hierarchicalFlushRules.size()).thenReturn(0);
    when(this.resourceOnlyFlushRules.size()).thenReturn(0);
    final ReplicationAction replicationAction = mock(ReplicationAction.class);
    when(replicationAction.getPath()).thenReturn("/content/acs-aem-commons");
    dispatcherFlushRules.preprocess(replicationAction, new ReplicationOptions());
    verifyZeroInteractions(dispatcherFlusher);
}
Also used : ReplicationOptions(com.day.cq.replication.ReplicationOptions) ReplicationAction(com.day.cq.replication.ReplicationAction) Test(org.junit.Test)

Example 8 with ReplicationOptions

use of com.day.cq.replication.ReplicationOptions in project acs-aem-commons by Adobe-Consulting-Services.

the class PageRelocator method init.

@Override
public void init() throws RepositoryException {
    if (mode == Mode.MOVE) {
        String nodeName = sourcePath.substring(sourcePath.lastIndexOf('/'));
        destinationPath += nodeName;
    }
    replicationOptions = new ReplicationOptions();
    switch(publishMethod) {
        case SELF_MANAGED:
            replicationOptions.setSynchronous(true);
            break;
        default:
            replicationOptions.setSynchronous(false);
            break;
    }
    replicationOptions.setSuppressVersions(!createVerionsOnReplicate);
    replicationOptions.setSuppressStatusUpdate(!updateStatus);
    if (referenceSearchRoot == null || referenceSearchRoot.trim().isEmpty()) {
        referenceSearchRoot = "/";
    }
}
Also used : ReplicationOptions(com.day.cq.replication.ReplicationOptions)

Example 9 with ReplicationOptions

use of com.day.cq.replication.ReplicationOptions in project acs-aem-commons by Adobe-Consulting-Services.

the class DispatcherFlusherImpl method flush.

/**
 * {@inheritDoc}
 */
@Override
public final Map<Agent, ReplicationResult> flush(final ResourceResolver resourceResolver, final ReplicationActionType actionType, final boolean synchronous, final AgentFilter agentFilter, final String... paths) throws ReplicationException {
    final ReplicationOptions options = new ReplicationOptions();
    final ReplicationResultListener listener = new ReplicationResultListener();
    options.setFilter(agentFilter);
    options.setSynchronous(synchronous);
    options.setSuppressStatusUpdate(true);
    options.setSuppressVersions(true);
    options.setListener(listener);
    for (final String path : paths) {
        if (log.isDebugEnabled()) {
            log.debug("--------------------------------------------------------------------------------");
            log.debug("Issuing Dispatcher Flush (via AEM Replication API) request for: {}", path);
            log.debug(" > Synchronous: {}", options.isSynchronous());
            log.debug(" > Replication Action Type: {}", actionType.name());
        }
        replicator.replicate(resourceResolver.adaptTo(Session.class), actionType, path, options);
    }
    return listener.getResults();
}
Also used : ReplicationOptions(com.day.cq.replication.ReplicationOptions) Session(javax.jcr.Session)

Example 10 with ReplicationOptions

use of com.day.cq.replication.ReplicationOptions in project acs-aem-commons by Adobe-Consulting-Services.

the class DispatcherFlushRulesImplTest method testPreprocess_success_hierarchicalAndResourceOnly.

@Test
public void testPreprocess_success_hierarchicalAndResourceOnly() throws Exception {
    hierarchicalFlushRules.put(Pattern.compile("/content/.*"), new String[] { "/content/hierarchical" });
    resourceOnlyFlushRules.put(Pattern.compile("/content/.*"), new String[] { "/content/resource-only" });
    final ReplicationAction replicationAction = mock(ReplicationAction.class);
    when(replicationAction.getPath()).thenReturn("/content/acs-aem-commons/page");
    when(replicationAction.getType()).thenReturn(ReplicationActionType.ACTIVATE);
    final ReplicationOptions replicationOptions = new ReplicationOptions();
    replicationOptions.setSynchronous(false);
    replicationOptions.setFilter(new DispatcherFlushFilter());
    final ArgumentCaptor<DispatcherFlushFilter> agentFilterCaptor = ArgumentCaptor.forClass(DispatcherFlushFilter.class);
    dispatcherFlushRules.preprocess(replicationAction, replicationOptions);
    verify(dispatcherFlusher, times(1)).flush(any(ResourceResolver.class), eq(ReplicationActionType.ACTIVATE), eq(false), agentFilterCaptor.capture(), eq("/content/hierarchical"));
    assertEquals(DispatcherFlushFilter.FlushType.Hierarchical, agentFilterCaptor.getValue().getFlushType());
    // Private impl class; no access to test for instanceof
    assertEquals("DispatcherFlushRulesFilter", agentFilterCaptor.getValue().getClass().getSimpleName());
    verify(dispatcherFlusher, times(1)).flush(any(ResourceResolver.class), eq(ReplicationActionType.ACTIVATE), eq(false), agentFilterCaptor.capture(), eq("/content/resource-only"));
    assertEquals(DispatcherFlushFilter.FlushType.ResourceOnly, agentFilterCaptor.getValue().getFlushType());
    // Private impl class; no access to test for instanceof
    assertEquals("DispatcherFlushRulesFilter", agentFilterCaptor.getValue().getClass().getSimpleName());
    verifyNoMoreInteractions(dispatcherFlusher);
}
Also used : ReplicationOptions(com.day.cq.replication.ReplicationOptions) ReplicationAction(com.day.cq.replication.ReplicationAction) ResourceResolver(org.apache.sling.api.resource.ResourceResolver) DispatcherFlushFilter(com.adobe.acs.commons.replication.dispatcher.DispatcherFlushFilter) Test(org.junit.Test)

Aggregations

ReplicationOptions (com.day.cq.replication.ReplicationOptions)17 Test (org.junit.Test)13 ReplicationAction (com.day.cq.replication.ReplicationAction)12 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)7 DispatcherFlushFilter (com.adobe.acs.commons.replication.dispatcher.DispatcherFlushFilter)6 Session (javax.jcr.Session)2 RoundRobin (com.adobe.acs.commons.functions.RoundRobin)1 ReplicateVersion (com.adobe.acs.commons.replication.ReplicateVersion)1 ReplicationResult (com.adobe.acs.commons.replication.ReplicationResult)1 AgentIdFilter (com.day.cq.replication.AgentIdFilter)1 ReplicationException (com.day.cq.replication.ReplicationException)1 ArrayList (java.util.ArrayList)1 RepositoryException (javax.jcr.RepositoryException)1 Version (javax.jcr.version.Version)1 Resource (org.apache.sling.api.resource.Resource)1