@Test
public void testReplicationWithFailingDistributionStrategy() throws Exception {
String name = "sample-agent";
ReplicationPackageImporter packageImporter = mock(ReplicationPackageImporter.class);
ReplicationPackageExporter packageExporter = mock(ReplicationPackageExporter.class);
ReplicationRequestAuthorizationStrategy packageExporterStrategy = mock(ReplicationRequestAuthorizationStrategy.class);
ReplicationQueueProvider queueProvider = mock(ReplicationQueueProvider.class);
ReplicationQueueDistributionStrategy distributionHandler = mock(ReplicationQueueDistributionStrategy.class);
when(distributionHandler.add(any(String.class), any(ReplicationPackage.class), any(ReplicationQueueProvider.class))).thenReturn(false);
ReplicationEventFactory replicationEventFactory = mock(ReplicationEventFactory.class);
ResourceResolverFactory resolverFactory = mock(ResourceResolverFactory.class);
SimpleReplicationAgent agent = new SimpleReplicationAgent(name,
false, "serviceName", packageImporter,
packageExporter, packageExporterStrategy,
queueProvider, distributionHandler,
replicationEventFactory, resolverFactory, null);
ReplicationRequest request = new ReplicationRequest(System.nanoTime(),
ReplicationActionType.ADD, "/");
ReplicationPackage replicationPackage = mock(ReplicationPackage.class);
ResourceResolver resourceResolver = mock(ResourceResolver.class);
when(replicationPackage.getPaths()).thenReturn(new String[]{"/"});
when(packageExporter.exportPackages(any(ResourceResolver.class), any(ReplicationRequest.class)))
.thenReturn(Arrays.asList(replicationPackage));
when(queueProvider.getDefaultQueue(name)).thenReturn(
new SimpleReplicationQueue(name, "name"));
ReplicationResponse response = agent.execute(resourceResolver, request);
assertNotNull(response);