Search in sources :

Example 6 with ReplicationAction

use of com.day.cq.replication.ReplicationAction 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 7 with ReplicationAction

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

the class JcrPackageReplicationStatusEventHandler method getInfoFromEvent.

/**
 * Extracts relevant event information from a Granite Replication Event OR a Day CQ Replication event.
 * @param event the Osgi Event
 * @return a Map containing the relevant data points.
 */
protected final Map<String, Object> getInfoFromEvent(Event event) {
    final Map<String, Object> eventConfig = new HashMap<>();
    final ReplicationEvent replicationEvent = ReplicationEvent.fromEvent(event);
    if (replicationEvent != null) {
        // Granite event
        final ReplicationAction replicationAction = replicationEvent.getReplicationAction();
        eventConfig.put(PROPERTY_PATHS, replicationAction.getPaths());
        eventConfig.put(PROPERTY_REPLICATED_BY, replicationAction.getUserId());
    } else {
        // CQ event
        String[] paths = (String[]) event.getProperty(ReplicationAction.PROPERTY_PATHS);
        if (paths == null) {
            paths = ArrayUtils.EMPTY_STRING_ARRAY;
        }
        String userId = (String) event.getProperty(ReplicationAction.PROPERTY_USER_ID);
        if (StringUtils.isBlank(userId)) {
            userId = StringUtils.defaultIfEmpty(this.replicatedByOverride, FALLBACK_REPLICATION_USER_ID);
        }
        eventConfig.put(PROPERTY_PATHS, paths);
        eventConfig.put(PROPERTY_REPLICATED_BY, userId);
    }
    return eventConfig;
}
Also used : HashMap(java.util.HashMap) ReplicationAction(com.day.cq.replication.ReplicationAction) ReplicationEvent(com.day.cq.replication.ReplicationEvent)

Example 8 with ReplicationAction

use of com.day.cq.replication.ReplicationAction 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)

Example 9 with ReplicationAction

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

the class DispatcherFlushRulesImplTest method testPreprocess_notAccepts_ReplicationActionTypeInternalPoll.

@Test
public void testPreprocess_notAccepts_ReplicationActionTypeInternalPoll() throws Exception {
    when(this.hierarchicalFlushRules.size()).thenReturn(9);
    when(this.resourceOnlyFlushRules.size()).thenReturn(9);
    final ReplicationAction replicationAction = mock(ReplicationAction.class);
    when(replicationAction.getPath()).thenReturn("/content/acs-aem-commons");
    when(replicationAction.getType()).thenReturn(ReplicationActionType.INTERNAL_POLL);
    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 10 with ReplicationAction

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

the class DispatcherFlushRulesImplTest method testPreprocess_success_translation2.

@Test
public void testPreprocess_success_translation2() throws Exception {
    hierarchicalFlushRules.put(Pattern.compile("/content/acs-aem-commons/(.*)/(.*)"), new String[] { "/content/target/$1/acs-aem-commons/$2" });
    final ReplicationAction replicationAction = mock(ReplicationAction.class);
    when(replicationAction.getPath()).thenReturn("/content/acs-aem-commons/en/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/en/acs-aem-commons/page"));
    assertEquals(DispatcherFlushFilter.FlushType.Hierarchical, 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

ReplicationAction (com.day.cq.replication.ReplicationAction)14 Test (org.junit.Test)13 ReplicationOptions (com.day.cq.replication.ReplicationOptions)12 DispatcherFlushFilter (com.adobe.acs.commons.replication.dispatcher.DispatcherFlushFilter)6 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)6 ReplicationEvent (com.day.cq.replication.ReplicationEvent)1 HashMap (java.util.HashMap)1