use of com.day.cq.replication.ReplicationOptions in project acs-aem-commons by Adobe-Consulting-Services.
the class DispatcherFlushRulesImplTest method testPreprocess_success_hierarchical.
@Test
public void testPreprocess_success_hierarchical() throws Exception {
hierarchicalFlushRules.put(Pattern.compile("/content/acs-aem-commons/.*"), new String[] { "/content/target", "/content/target2" });
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.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/target2"));
assertEquals(DispatcherFlushFilter.FlushType.Hierarchical, agentFilterCaptor.getValue().getFlushType());
// Private impl class; no access to test for instanceof
assertEquals("DispatcherFlushRulesFilter", agentFilterCaptor.getValue().getClass().getSimpleName());
verifyNoMoreInteractions(dispatcherFlusher);
}
use of com.day.cq.replication.ReplicationOptions in project acs-aem-commons by Adobe-Consulting-Services.
the class ReplicateVersionImpl method replicateResource.
private List<ReplicationResult> replicateResource(ResourceResolver resolver, List<Resource> resources, String[] agents, Date date) {
List<ReplicationResult> results = new ArrayList<ReplicationResult>();
ReplicationOptions opts = new ReplicationOptions();
AgentIdFilter agentFilter = new AgentIdFilter(agents);
opts.setFilter(agentFilter);
Session session = resolver.adaptTo(Session.class);
for (Resource resource : resources) {
String path = resource.getPath();
try {
Version v = getAppropriateVersion(resource, date, session);
if (v == null) {
results.add(new ReplicationResult(path, Status.not_replicated));
continue;
}
String versionName = v.getName();
opts.setRevision(versionName);
replicator.replicate(session, ReplicationActionType.ACTIVATE, path, opts);
results.add(new ReplicationResult(path, Status.replicated, versionName));
} catch (RepositoryException e) {
results.add(new ReplicationResult(path, Status.error));
log.error("Exception while replicating version of " + path, e);
} catch (ReplicationException e) {
results.add(new ReplicationResult(path, Status.error));
log.error("Exception while replicating version of " + path, e);
}
}
return results;
}
Aggregations