RemoveArtifactsProcessor implements Processor { @Override @SuppressWarnings("unchecked") public void process(Exchange exchange) throws Exception { final CleanerContext cleanerContext = exchange.getIn() .getHeader(CleanerContext.KEY_NAME, CleanerContext.class); final ReferencedArtifactsMessageBody messageBody = exchange.getIn() .getBody(ReferencedArtifactsMessageBody.class); Set<String> artifactsToRemove = getArtifactsIdsToRemove(artifactsDAO, messageBody); LOGGER.debug("Artifacts that will be removed: {}", artifactsToRemove); if (!cleanerContext.isDryRun()) { LOGGER.info("{} unreferenced artifacts will be removed from {} after cleaning suite `{}`", artifactsToRemove.size(), messageBody.getDbKey(), messageBody.getData()); artifactsDAO.removeArtifacts(messageBody.getDbKey(), artifactsToRemove); LOGGER.info("{} artifacts removed successfully!", artifactsToRemove.size()); } else { LOGGER.info( "Dry run completed! {} unreferenced artifacts should be removed from {} after cleaning suite `{}`", artifactsToRemove.size(), messageBody.getDbKey(), messageBody.getData()); } } RemoveArtifactsProcessor();  RemoveArtifactsProcessor(ArtifactsDAO artifactsDAO); @Override @SuppressWarnings("unchecked") void process(Exchange exchange);  }
@Test public void checkIfRemoveArtifactsWasCalled_whenDryRunIsFalse_expectTrue() throws Exception { when(artifactDAO.getArtifactsIds(any(DBKey.class))) .thenReturn(new HashSet<>(ONE_TO_SEVEN_ARTIFACTS_ID_SET)); setArtifactsIdToKeep(ONE_TO_FIVE_ARTIFACTS_ID_SET); removeArtifactsProcessor = new RemoveArtifactsProcessor(artifactDAO); removeArtifactsProcessor.process(exchange); verify(artifactDAO, times(1)).removeArtifacts(any(DBKey.class), any(Set.class)); verify(artifactDAO, times(1)).getArtifactsIds(any(DBKey.class)); }
@Test public void checkIfRemoveArtifactsWasCalled_whenDryRunIsTrue_expectFalse() throws Exception { when(cleanerContext.isDryRun()).thenReturn(true); when(artifactDAO.getArtifactsIds(any(DBKey.class))) .thenReturn(new HashSet<>(ONE_TO_SEVEN_ARTIFACTS_ID_SET)); setArtifactsIdToKeep(ONE_TO_FIVE_ARTIFACTS_ID_SET); removeArtifactsProcessor = new RemoveArtifactsProcessor(artifactDAO); removeArtifactsProcessor.process(exchange); verify(artifactDAO, times(0)).removeArtifacts(any(DBKey.class), any(Set.class)); verify(artifactDAO, times(1)).getArtifactsIds(any(DBKey.class)); }