@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 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()); }