@Test
 public void testPackageAdditionWithNullItemStateFromTheQueueOnPriorityPath() throws Exception {
   PriorityPathDistributionStrategy priorityPathDistributionStrategy =
       new PriorityPathDistributionStrategy();
   ComponentContext context = mock(ComponentContext.class);
   Dictionary properties = mock(Dictionary.class);
   when(properties.get("priority.paths")).thenReturn(new String[] {"/content", "/apps"});
   when(context.getProperties()).thenReturn(properties);
   priorityPathDistributionStrategy.activate(context);
   ReplicationQueueItem replicationPackage = mock(ReplicationQueueItem.class);
   when(replicationPackage.getPaths()).thenReturn(new String[] {"/apps/some/stuff"});
   ReplicationQueueProvider queueProvider = mock(ReplicationQueueProvider.class);
   ReplicationQueue queue = mock(ReplicationQueue.class);
   when(queueProvider.getQueue("agentName", "/apps")).thenReturn(queue);
   when(queue.add(replicationPackage)).thenReturn(true);
   ReplicationQueueItemState returnedState =
       priorityPathDistributionStrategy.add("agentName", replicationPackage, queueProvider);
   assertNull(returnedState);
 }
  public List<ReplicationPackage> exportPackage(ReplicationRequest replicationRequest) {

    List<ReplicationPackage> result = new ArrayList<ReplicationPackage>();
    try {
      log.info("getting item from queue {}", queueName);

      ReplicationQueue queue = agent.getQueue(queueName);
      ReplicationQueueItem info = queue.getHead();
      ReplicationPackage replicationPackage = null;
      if (info != null) {
        queue.removeHead();
        replicationPackage = replicationPackageBuilder.getPackage(info.getId());
        if (replicationPackage != null) {
          result.add(replicationPackage);
        }
      }

    } catch (Exception ex) {
      log.error("Error exporting package", ex);
    }

    return result;
  }
 @Test
 public void testPackageAdditionWithFailingItemDelivery() throws Exception {
   PriorityPathDistributionStrategy priorityPathDistributionStrategy =
       new PriorityPathDistributionStrategy();
   ComponentContext context = mock(ComponentContext.class);
   Dictionary properties = mock(Dictionary.class);
   when(properties.get("priority.paths")).thenReturn(new String[] {"/content", "/apps"});
   when(context.getProperties()).thenReturn(properties);
   priorityPathDistributionStrategy.activate(context);
   ReplicationQueueItem replicationPackage = mock(ReplicationQueueItem.class);
   when(replicationPackage.getPaths()).thenReturn(new String[] {"/etc"});
   ReplicationQueueProvider queueProvider = mock(ReplicationQueueProvider.class);
   ReplicationQueue queue = mock(ReplicationQueue.class);
   when(queueProvider.getDefaultQueue("agentName")).thenReturn(queue);
   when(queue.add(replicationPackage)).thenReturn(true);
   ReplicationQueueItemState state = mock(ReplicationQueueItemState.class);
   when(state.isSuccessful()).thenReturn(false);
   when(queue.getStatus(replicationPackage)).thenReturn(state);
   ReplicationQueueItemState returnedState =
       priorityPathDistributionStrategy.add("agentName", replicationPackage, queueProvider);
   assertNotNull(returnedState);
   assertFalse(returnedState.isSuccessful());
 }