@Test public void testIllegalStateIsCaught() throws IOException { SW360UpdaterImpl updaterImpl = mock(SW360UpdaterImpl.class); when(updaterImpl.artifactToReleaseInSW360(any(), any())) .thenReturn(SW360TestUtils.mkSW360Release("test")); String propertiesFilePath = Objects.requireNonNull(this.getClass().getClassLoader().getResource("compliancetool-updater.properties")).getPath(); final Map<String, String> properties = ComplianceFeatureUtils.mapPropertiesFile(new File(propertiesFilePath)); initConfiguration(properties); SW360ReleaseClientAdapter releaseClientAdapter = mock(SW360ReleaseClientAdapter.class); SW360Connection connection = mock(SW360Connection.class); when(connection.getReleaseAdapter()) .thenReturn(releaseClientAdapter); final ClearingReportGenerator clearingReportGenerator = mock(ClearingReportGenerator.class); when(clearingReportGenerator.createClearingDocument(any(), any())) .thenThrow(new SW360ClientException("Clearing doc generation error")); SW360Updater updater = new SW360Updater(updaterImpl, configurationMock, clearingReportGenerator); updater.execute(); verify(releaseClientAdapter, never()).uploadAttachments(any()); }
public void execute() { LOGGER.debug("{} has started.", SW360Updater.class.getName()); Collection<Artifact> artifacts = getArtifactsFromCsvFile(configuration); Map<Artifact, SW360ClientException> exceptions = new HashMap<>(); for (Artifact artifact : artifacts) { try { uploadReleaseWithClearingDocumentFromArtifact(artifact); } catch (SW360ClientException e) { exceptions.put(artifact, e); } } LOGGER.info("The SW360Updater was executed with the following configuration:"); configuration.logConfiguration(LOGGER); LOGGER.info("Path for clearing documents: {}", clearingDocDir); if (!exceptions.isEmpty()) { StringBuilder builder = new StringBuilder("There have been some errors during update:"); exceptions.forEach((key, value) -> { String packageURL = key.getMainCoordinate() .map(coordinate -> coordinate.getPackageURL().toString()) .orElse("UNKNOWN"); builder.append(System.lineSeparator()); builder.append(String.format("%s: %s", packageURL, value.getMessage())); }); LOGGER.error(builder.toString()); throw new SW360ClientException(builder.toString()); } }
SW360Updater { public void execute() { LOGGER.debug("{} has started.", SW360Updater.class.getName()); Collection<Artifact> artifacts = getArtifactsFromCsvFile(configuration); Map<Artifact, SW360ClientException> exceptions = new HashMap<>(); for (Artifact artifact : artifacts) { try { uploadReleaseWithClearingDocumentFromArtifact(artifact); } catch (SW360ClientException e) { exceptions.put(artifact, e); } } LOGGER.info("The SW360Updater was executed with the following configuration:"); configuration.logConfiguration(LOGGER); LOGGER.info("Path for clearing documents: {}", clearingDocDir); if (!exceptions.isEmpty()) { StringBuilder builder = new StringBuilder("There have been some errors during update:"); exceptions.forEach((key, value) -> { String packageURL = key.getMainCoordinate() .map(coordinate -> coordinate.getPackageURL().toString()) .orElse("UNKNOWN"); builder.append(System.lineSeparator()); builder.append(String.format("%s: %s", packageURL, value.getMessage())); }); LOGGER.error(builder.toString()); throw new SW360ClientException(builder.toString()); } } }
SW360Updater { public void execute() { LOGGER.debug("{} has started.", SW360Updater.class.getName()); Collection<Artifact> artifacts = getArtifactsFromCsvFile(configuration); Map<Artifact, SW360ClientException> exceptions = new HashMap<>(); for (Artifact artifact : artifacts) { try { uploadReleaseWithClearingDocumentFromArtifact(artifact); } catch (SW360ClientException e) { exceptions.put(artifact, e); } } LOGGER.info("The SW360Updater was executed with the following configuration:"); configuration.logConfiguration(LOGGER); LOGGER.info("Path for clearing documents: {}", clearingDocDir); if (!exceptions.isEmpty()) { StringBuilder builder = new StringBuilder("There have been some errors during update:"); exceptions.forEach((key, value) -> { String packageURL = key.getMainCoordinate() .map(coordinate -> coordinate.getPackageURL().toString()) .orElse("UNKNOWN"); builder.append(System.lineSeparator()); builder.append(String.format("%s: %s", packageURL, value.getMessage())); }); LOGGER.error(builder.toString()); throw new SW360ClientException(builder.toString()); } } SW360Updater(SW360UpdaterImpl updater, SW360Configuration configuration,
                        ClearingReportGenerator generator); }
SW360Updater { public void execute() { LOGGER.debug("{} has started.", SW360Updater.class.getName()); Collection<Artifact> artifacts = getArtifactsFromCsvFile(configuration); Map<Artifact, SW360ClientException> exceptions = new HashMap<>(); for (Artifact artifact : artifacts) { try { uploadReleaseWithClearingDocumentFromArtifact(artifact); } catch (SW360ClientException e) { exceptions.put(artifact, e); } } LOGGER.info("The SW360Updater was executed with the following configuration:"); configuration.logConfiguration(LOGGER); LOGGER.info("Path for clearing documents: {}", clearingDocDir); if (!exceptions.isEmpty()) { StringBuilder builder = new StringBuilder("There have been some errors during update:"); exceptions.forEach((key, value) -> { String packageURL = key.getMainCoordinate() .map(coordinate -> coordinate.getPackageURL().toString()) .orElse("UNKNOWN"); builder.append(System.lineSeparator()); builder.append(String.format("%s: %s", packageURL, value.getMessage())); }); LOGGER.error(builder.toString()); throw new SW360ClientException(builder.toString()); } } SW360Updater(SW360UpdaterImpl updater, SW360Configuration configuration,
                        ClearingReportGenerator generator); void execute(); }
SW360Updater { public void execute() { LOGGER.debug("{} has started.", SW360Updater.class.getName()); Collection<Artifact> artifacts = getArtifactsFromCsvFile(configuration); Map<Artifact, SW360ClientException> exceptions = new HashMap<>(); for (Artifact artifact : artifacts) { try { uploadReleaseWithClearingDocumentFromArtifact(artifact); } catch (SW360ClientException e) { exceptions.put(artifact, e); } } LOGGER.info("The SW360Updater was executed with the following configuration:"); configuration.logConfiguration(LOGGER); LOGGER.info("Path for clearing documents: {}", clearingDocDir); if (!exceptions.isEmpty()) { StringBuilder builder = new StringBuilder("There have been some errors during update:"); exceptions.forEach((key, value) -> { String packageURL = key.getMainCoordinate() .map(coordinate -> coordinate.getPackageURL().toString()) .orElse("UNKNOWN"); builder.append(System.lineSeparator()); builder.append(String.format("%s: %s", packageURL, value.getMessage())); }); LOGGER.error(builder.toString()); throw new SW360ClientException(builder.toString()); } } SW360Updater(SW360UpdaterImpl updater, SW360Configuration configuration,
                        ClearingReportGenerator generator); void execute(); static final String PROP_REMOVE_CLEARED_SOURCES; static final String PROP_REMOVE_CLEARING_DOCS; static final String PROP_CLEARING_DOC_FOLDER; }