@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); }
@Test public void testPackageAdditionWithSucceedingItemDeliveryOnPriorityPath() 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[] {"/content/sample1"}); ReplicationQueueProvider queueProvider = mock(ReplicationQueueProvider.class); ReplicationQueue queue = mock(ReplicationQueue.class); when(queueProvider.getQueue("agentName", "/content")).thenReturn(queue); when(queue.add(replicationPackage)).thenReturn(true); ReplicationQueueItemState state = mock(ReplicationQueueItemState.class); when(state.isSuccessful()).thenReturn(true); when(queue.getStatus(replicationPackage)).thenReturn(state); ReplicationQueueItemState returnedState = priorityPathDistributionStrategy.add("agentName", replicationPackage, queueProvider); assertNotNull(returnedState); assertTrue(returnedState.isSuccessful()); }