From 13e24782cf12ca0ebc26bee80187276a0f7e0202 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20Dom=C3=ADnguez=20Dorado?= Date: Sun, 13 Feb 2022 17:31:11 +0100 Subject: [PATCH] mjson seems to be abandoned, so it has been replaced by everit-json-schema --- .../riskanalysers/AbstractRiskAnalyser.java | 8 +- ...censesIncompatibleWithProjectLicenses.java | 4 +- ...LicensesMisalignedFromProjectLicenses.java | 4 +- ...alyserHeterogeneousComponentsLicenses.java | 4 +- ...mitedSetOfPotentialComponentsLicenses.java | 4 +- ...rLimitedSetOfPotentialProjectLicenses.java | 4 +- ...iskAnalyserObsoleteComponentsLicenses.java | 4 +- .../RiskAnalyserObsoleteProjectLicenses.java | 4 +- ...lyserScarcelySpreadComponentsLicenses.java | 4 +- ...AnalyserScarcelySpreadProjectLicenses.java | 4 +- ...alyserUnfashionableComponentsLicenses.java | 4 +- ...kAnalyserUnfashionableProjectLicenses.java | 4 +- .../{SwProject.java => Project.java} | 10 +- .../openlrae/cli/CLIHandler.java | 6 +- .../openlrae/reporting/ReportsFactory.java | 10 +- .../arquitecture/ComponentBindingTest.java | 6 +- .../openlrae/arquitecture/ProjectTest.java | 609 ++++++++++++++++++ .../i18n/LanguageChangeEventTest.java | 8 +- 18 files changed, 655 insertions(+), 46 deletions(-) rename src/main/java/com/manolodominguez/openlrae/arquitecture/{SwProject.java => Project.java} (97%) create mode 100644 src/test/java/com/manolodominguez/openlrae/arquitecture/ProjectTest.java diff --git a/src/main/java/com/manolodominguez/openlrae/analysis/riskanalysers/AbstractRiskAnalyser.java b/src/main/java/com/manolodominguez/openlrae/analysis/riskanalysers/AbstractRiskAnalyser.java index 3e65a7c..ea0acd7 100644 --- a/src/main/java/com/manolodominguez/openlrae/analysis/riskanalysers/AbstractRiskAnalyser.java +++ b/src/main/java/com/manolodominguez/openlrae/analysis/riskanalysers/AbstractRiskAnalyser.java @@ -24,7 +24,7 @@ import com.manolodominguez.openlrae.analysis.RiskAnalysisResult; import com.manolodominguez.openlrae.baseofknowledge.basevalues.SupportedRisks; -import com.manolodominguez.openlrae.arquitecture.SwProject; +import com.manolodominguez.openlrae.arquitecture.Project; import com.manolodominguez.openlrae.i18n.ILanguageChangeEventEmitter; import com.manolodominguez.openlrae.i18n.ILanguageChangeListener; import com.manolodominguez.openlrae.i18n.LanguageChangeEvent; @@ -46,7 +46,7 @@ public abstract class AbstractRiskAnalyser implements ILanguageChangeEventEmitter, ILanguageChangeListener { protected Logger logger; - protected SwProject project = null; + protected Project project = null; protected SupportedRisks handledRiskType; protected float riskExposure; protected float riskImpact; @@ -64,7 +64,7 @@ public abstract class AbstractRiskAnalyser implements ILanguageChangeEventEmitte * @param project The software project to be analised. * @param handledRiskType The type of risk the subclass addresses. */ - protected AbstractRiskAnalyser(SwProject project, SupportedRisks handledRiskType) { + protected AbstractRiskAnalyser(Project project, SupportedRisks handledRiskType) { logger = LoggerFactory.getLogger(AbstractRiskAnalyser.class); if (project == null) { logger.error("Project cannot be null"); @@ -103,7 +103,7 @@ private void reset() { * * @return the project on wich the risk analysis is going to be done. */ - public SwProject getProject() { + public Project getProject() { return project; } diff --git a/src/main/java/com/manolodominguez/openlrae/analysis/riskanalysers/RiskAnalyserComponentsLicensesIncompatibleWithProjectLicenses.java b/src/main/java/com/manolodominguez/openlrae/analysis/riskanalysers/RiskAnalyserComponentsLicensesIncompatibleWithProjectLicenses.java index f4e7a20..6b01748 100644 --- a/src/main/java/com/manolodominguez/openlrae/analysis/riskanalysers/RiskAnalyserComponentsLicensesIncompatibleWithProjectLicenses.java +++ b/src/main/java/com/manolodominguez/openlrae/analysis/riskanalysers/RiskAnalyserComponentsLicensesIncompatibleWithProjectLicenses.java @@ -25,7 +25,7 @@ import com.manolodominguez.openlrae.baseofknowledge.basevalues.SupportedCompatibilities; import com.manolodominguez.openlrae.baseofknowledge.basevalues.SupportedRisks; import com.manolodominguez.openlrae.baseofknowledge.licenseproperties.LicensesCompatibilityFactory; -import com.manolodominguez.openlrae.arquitecture.SwProject; +import com.manolodominguez.openlrae.arquitecture.Project; import com.manolodominguez.openlrae.arquitecture.ComponentBinding; import com.manolodominguez.openlrae.baseofknowledge.basevalues.SupportedLicenses; import com.manolodominguez.openlrae.i18n.LanguageChangeEvent; @@ -75,7 +75,7 @@ public class RiskAnalyserComponentsLicensesIncompatibleWithProjectLicenses exten * * @param project. The software project to be analised. */ - public RiskAnalyserComponentsLicensesIncompatibleWithProjectLicenses(SwProject project) { + public RiskAnalyserComponentsLicensesIncompatibleWithProjectLicenses(Project project) { // Project is checked at superclass super(project, SupportedRisks.HAVING_COMPONENTS_LICENSES_INCOMPATIBLE_WITH_PROJECT_LICENSES); logger = LoggerFactory.getLogger(RiskAnalyserComponentsLicensesIncompatibleWithProjectLicenses.class); diff --git a/src/main/java/com/manolodominguez/openlrae/analysis/riskanalysers/RiskAnalyserComponentsLicensesMisalignedFromProjectLicenses.java b/src/main/java/com/manolodominguez/openlrae/analysis/riskanalysers/RiskAnalyserComponentsLicensesMisalignedFromProjectLicenses.java index 966020f..1881ec0 100644 --- a/src/main/java/com/manolodominguez/openlrae/analysis/riskanalysers/RiskAnalyserComponentsLicensesMisalignedFromProjectLicenses.java +++ b/src/main/java/com/manolodominguez/openlrae/analysis/riskanalysers/RiskAnalyserComponentsLicensesMisalignedFromProjectLicenses.java @@ -23,7 +23,7 @@ package com.manolodominguez.openlrae.analysis.riskanalysers; import com.manolodominguez.openlrae.baseofknowledge.basevalues.SupportedRisks; -import com.manolodominguez.openlrae.arquitecture.SwProject; +import com.manolodominguez.openlrae.arquitecture.Project; import com.manolodominguez.openlrae.arquitecture.ComponentBinding; import com.manolodominguez.openlrae.baseofknowledge.basevalues.SupportedLicenses; import com.manolodominguez.openlrae.i18n.LanguageChangeEvent; @@ -71,7 +71,7 @@ public class RiskAnalyserComponentsLicensesMisalignedFromProjectLicenses extends * * @param project. The software project to be analised. */ - public RiskAnalyserComponentsLicensesMisalignedFromProjectLicenses(SwProject project) { + public RiskAnalyserComponentsLicensesMisalignedFromProjectLicenses(Project project) { // Project is ckecked at superclass super(project, SupportedRisks.HAVING_COMPONENTS_LICENSES_MISALIGNED_FROM_PROJECT_LICENSES); logger = LoggerFactory.getLogger(RiskAnalyserComponentsLicensesMisalignedFromProjectLicenses.class); diff --git a/src/main/java/com/manolodominguez/openlrae/analysis/riskanalysers/RiskAnalyserHeterogeneousComponentsLicenses.java b/src/main/java/com/manolodominguez/openlrae/analysis/riskanalysers/RiskAnalyserHeterogeneousComponentsLicenses.java index e166229..65960c9 100644 --- a/src/main/java/com/manolodominguez/openlrae/analysis/riskanalysers/RiskAnalyserHeterogeneousComponentsLicenses.java +++ b/src/main/java/com/manolodominguez/openlrae/analysis/riskanalysers/RiskAnalyserHeterogeneousComponentsLicenses.java @@ -23,7 +23,7 @@ package com.manolodominguez.openlrae.analysis.riskanalysers; import com.manolodominguez.openlrae.baseofknowledge.basevalues.SupportedRisks; -import com.manolodominguez.openlrae.arquitecture.SwProject; +import com.manolodominguez.openlrae.arquitecture.Project; import com.manolodominguez.openlrae.arquitecture.ComponentBinding; import com.manolodominguez.openlrae.baseofknowledge.basevalues.SupportedLicenses; import com.manolodominguez.openlrae.i18n.LanguageChangeEvent; @@ -82,7 +82,7 @@ public class RiskAnalyserHeterogeneousComponentsLicenses extends AbstractRiskAna * * @param project. The software project to be analised. */ - public RiskAnalyserHeterogeneousComponentsLicenses(SwProject project) { + public RiskAnalyserHeterogeneousComponentsLicenses(Project project) { // Project is ckecked at superclass super(project, SupportedRisks.HAVING_HETEROGENEOUS_COMPONENTS_LICENSES); logger = LoggerFactory.getLogger(RiskAnalyserHeterogeneousComponentsLicenses.class); diff --git a/src/main/java/com/manolodominguez/openlrae/analysis/riskanalysers/RiskAnalyserLimitedSetOfPotentialComponentsLicenses.java b/src/main/java/com/manolodominguez/openlrae/analysis/riskanalysers/RiskAnalyserLimitedSetOfPotentialComponentsLicenses.java index 8851c5c..fcc0c21 100644 --- a/src/main/java/com/manolodominguez/openlrae/analysis/riskanalysers/RiskAnalyserLimitedSetOfPotentialComponentsLicenses.java +++ b/src/main/java/com/manolodominguez/openlrae/analysis/riskanalysers/RiskAnalyserLimitedSetOfPotentialComponentsLicenses.java @@ -28,7 +28,7 @@ import com.manolodominguez.openlrae.baseofknowledge.basevalues.SupportedLicenses; import com.manolodominguez.openlrae.baseofknowledge.basevalues.SupportedRisks; import com.manolodominguez.openlrae.baseofknowledge.licenseproperties.LicensesCompatibilityFactory; -import com.manolodominguez.openlrae.arquitecture.SwProject; +import com.manolodominguez.openlrae.arquitecture.Project; import com.manolodominguez.openlrae.baseofknowledge.basevalues.SupportedComponentWeights; import com.manolodominguez.openlrae.baseofknowledge.basevalues.SupportedLinks; import com.manolodominguez.openlrae.i18n.LanguageChangeEvent; @@ -81,7 +81,7 @@ public class RiskAnalyserLimitedSetOfPotentialComponentsLicenses extends Abstrac * * @param project. The software project to be analised. */ - public RiskAnalyserLimitedSetOfPotentialComponentsLicenses(SwProject project) { + public RiskAnalyserLimitedSetOfPotentialComponentsLicenses(Project project) { // Project is ckecked at superclass super(project, SupportedRisks.HAVING_A_LIMITED_SET_OF_POTENTIAL_COMPONENTS_LICENSES); logger = LoggerFactory.getLogger(RiskAnalyserLimitedSetOfPotentialComponentsLicenses.class); diff --git a/src/main/java/com/manolodominguez/openlrae/analysis/riskanalysers/RiskAnalyserLimitedSetOfPotentialProjectLicenses.java b/src/main/java/com/manolodominguez/openlrae/analysis/riskanalysers/RiskAnalyserLimitedSetOfPotentialProjectLicenses.java index 46e5680..987cd92 100644 --- a/src/main/java/com/manolodominguez/openlrae/analysis/riskanalysers/RiskAnalyserLimitedSetOfPotentialProjectLicenses.java +++ b/src/main/java/com/manolodominguez/openlrae/analysis/riskanalysers/RiskAnalyserLimitedSetOfPotentialProjectLicenses.java @@ -26,7 +26,7 @@ import com.manolodominguez.openlrae.baseofknowledge.basevalues.SupportedLicenses; import com.manolodominguez.openlrae.baseofknowledge.basevalues.SupportedRisks; import com.manolodominguez.openlrae.baseofknowledge.licenseproperties.LicensesCompatibilityFactory; -import com.manolodominguez.openlrae.arquitecture.SwProject; +import com.manolodominguez.openlrae.arquitecture.Project; import com.manolodominguez.openlrae.arquitecture.ComponentBinding; import com.manolodominguez.openlrae.i18n.LanguageChangeEvent; import com.manolodominguez.openlrae.i18n.Translations; @@ -76,7 +76,7 @@ public class RiskAnalyserLimitedSetOfPotentialProjectLicenses extends AbstractRi * * @param project. The software project to be analised. */ - public RiskAnalyserLimitedSetOfPotentialProjectLicenses(SwProject project) { + public RiskAnalyserLimitedSetOfPotentialProjectLicenses(Project project) { // Project is ckecked at superclass super(project, SupportedRisks.HAVING_A_LIMITED_SET_OF_POTENTIAL_PROJECT_LICENSES); logger = LoggerFactory.getLogger(RiskAnalyserLimitedSetOfPotentialProjectLicenses.class); diff --git a/src/main/java/com/manolodominguez/openlrae/analysis/riskanalysers/RiskAnalyserObsoleteComponentsLicenses.java b/src/main/java/com/manolodominguez/openlrae/analysis/riskanalysers/RiskAnalyserObsoleteComponentsLicenses.java index 887b94a..7161f16 100644 --- a/src/main/java/com/manolodominguez/openlrae/analysis/riskanalysers/RiskAnalyserObsoleteComponentsLicenses.java +++ b/src/main/java/com/manolodominguez/openlrae/analysis/riskanalysers/RiskAnalyserObsoleteComponentsLicenses.java @@ -25,7 +25,7 @@ import com.manolodominguez.openlrae.baseofknowledge.basevalues.SupportedObsolescences; import com.manolodominguez.openlrae.baseofknowledge.basevalues.SupportedRisks; import com.manolodominguez.openlrae.baseofknowledge.licenseproperties.LicensesObsolescencesFactory; -import com.manolodominguez.openlrae.arquitecture.SwProject; +import com.manolodominguez.openlrae.arquitecture.Project; import com.manolodominguez.openlrae.arquitecture.ComponentBinding; import com.manolodominguez.openlrae.i18n.LanguageChangeEvent; import com.manolodominguez.openlrae.i18n.Translations; @@ -71,7 +71,7 @@ public class RiskAnalyserObsoleteComponentsLicenses extends AbstractRiskAnalyser * * @param project. The software project to be analised. */ - public RiskAnalyserObsoleteComponentsLicenses(SwProject project) { + public RiskAnalyserObsoleteComponentsLicenses(Project project) { // Project is ckecked at superclass super(project, SupportedRisks.HAVING_OBSOLETE_COMPONENTS_LICENSES); logger = LoggerFactory.getLogger(RiskAnalyserObsoleteComponentsLicenses.class); diff --git a/src/main/java/com/manolodominguez/openlrae/analysis/riskanalysers/RiskAnalyserObsoleteProjectLicenses.java b/src/main/java/com/manolodominguez/openlrae/analysis/riskanalysers/RiskAnalyserObsoleteProjectLicenses.java index 3c0fc73..9744f88 100644 --- a/src/main/java/com/manolodominguez/openlrae/analysis/riskanalysers/RiskAnalyserObsoleteProjectLicenses.java +++ b/src/main/java/com/manolodominguez/openlrae/analysis/riskanalysers/RiskAnalyserObsoleteProjectLicenses.java @@ -25,7 +25,7 @@ import com.manolodominguez.openlrae.baseofknowledge.basevalues.SupportedObsolescences; import com.manolodominguez.openlrae.baseofknowledge.basevalues.SupportedRisks; import com.manolodominguez.openlrae.baseofknowledge.licenseproperties.LicensesObsolescencesFactory; -import com.manolodominguez.openlrae.arquitecture.SwProject; +import com.manolodominguez.openlrae.arquitecture.Project; import com.manolodominguez.openlrae.baseofknowledge.basevalues.SupportedLicenses; import com.manolodominguez.openlrae.i18n.LanguageChangeEvent; import com.manolodominguez.openlrae.i18n.Translations; @@ -69,7 +69,7 @@ public class RiskAnalyserObsoleteProjectLicenses extends AbstractRiskAnalyser { * * @param project. The software project to be analised. */ - public RiskAnalyserObsoleteProjectLicenses(SwProject project) { + public RiskAnalyserObsoleteProjectLicenses(Project project) { // Project is ckecked at superclass super(project, SupportedRisks.HAVING_OBSOLETE_PROJECT_LICENSES); logger = LoggerFactory.getLogger(RiskAnalyserObsoleteProjectLicenses.class); diff --git a/src/main/java/com/manolodominguez/openlrae/analysis/riskanalysers/RiskAnalyserScarcelySpreadComponentsLicenses.java b/src/main/java/com/manolodominguez/openlrae/analysis/riskanalysers/RiskAnalyserScarcelySpreadComponentsLicenses.java index 036f801..90db16b 100644 --- a/src/main/java/com/manolodominguez/openlrae/analysis/riskanalysers/RiskAnalyserScarcelySpreadComponentsLicenses.java +++ b/src/main/java/com/manolodominguez/openlrae/analysis/riskanalysers/RiskAnalyserScarcelySpreadComponentsLicenses.java @@ -25,7 +25,7 @@ import com.manolodominguez.openlrae.baseofknowledge.basevalues.SupportedRisks; import com.manolodominguez.openlrae.baseofknowledge.basevalues.SupportedSpreadings; import com.manolodominguez.openlrae.baseofknowledge.licenseproperties.LicensesSpreadingFactory; -import com.manolodominguez.openlrae.arquitecture.SwProject; +import com.manolodominguez.openlrae.arquitecture.Project; import com.manolodominguez.openlrae.arquitecture.ComponentBinding; import com.manolodominguez.openlrae.i18n.LanguageChangeEvent; import com.manolodominguez.openlrae.i18n.Translations; @@ -72,7 +72,7 @@ public class RiskAnalyserScarcelySpreadComponentsLicenses extends AbstractRiskAn * * @param project. The software project to be analised. */ - public RiskAnalyserScarcelySpreadComponentsLicenses(SwProject project) { + public RiskAnalyserScarcelySpreadComponentsLicenses(Project project) { // Project is ckecked at superclass super(project, SupportedRisks.HAVING_SCARCELY_SPREAD_COMPONENTS_LICENSES); logger = LoggerFactory.getLogger(RiskAnalyserScarcelySpreadComponentsLicenses.class); diff --git a/src/main/java/com/manolodominguez/openlrae/analysis/riskanalysers/RiskAnalyserScarcelySpreadProjectLicenses.java b/src/main/java/com/manolodominguez/openlrae/analysis/riskanalysers/RiskAnalyserScarcelySpreadProjectLicenses.java index c5cfa08..30bf739 100644 --- a/src/main/java/com/manolodominguez/openlrae/analysis/riskanalysers/RiskAnalyserScarcelySpreadProjectLicenses.java +++ b/src/main/java/com/manolodominguez/openlrae/analysis/riskanalysers/RiskAnalyserScarcelySpreadProjectLicenses.java @@ -23,7 +23,7 @@ package com.manolodominguez.openlrae.analysis.riskanalysers; import com.manolodominguez.openlrae.baseofknowledge.basevalues.SupportedRisks; -import com.manolodominguez.openlrae.arquitecture.SwProject; +import com.manolodominguez.openlrae.arquitecture.Project; import com.manolodominguez.openlrae.baseofknowledge.basevalues.SupportedLicenses; import com.manolodominguez.openlrae.baseofknowledge.basevalues.SupportedSpreadings; import com.manolodominguez.openlrae.baseofknowledge.licenseproperties.LicensesSpreadingFactory; @@ -69,7 +69,7 @@ public class RiskAnalyserScarcelySpreadProjectLicenses extends AbstractRiskAnaly * * @param project. The software project to be analised. */ - public RiskAnalyserScarcelySpreadProjectLicenses(SwProject project) { + public RiskAnalyserScarcelySpreadProjectLicenses(Project project) { // Project is ckecked at superclass super(project, SupportedRisks.HAVING_SCARCELY_SPREAD_PROJECT_LICENSES); logger = LoggerFactory.getLogger(RiskAnalyserScarcelySpreadProjectLicenses.class); diff --git a/src/main/java/com/manolodominguez/openlrae/analysis/riskanalysers/RiskAnalyserUnfashionableComponentsLicenses.java b/src/main/java/com/manolodominguez/openlrae/analysis/riskanalysers/RiskAnalyserUnfashionableComponentsLicenses.java index 7605a87..7294795 100644 --- a/src/main/java/com/manolodominguez/openlrae/analysis/riskanalysers/RiskAnalyserUnfashionableComponentsLicenses.java +++ b/src/main/java/com/manolodominguez/openlrae/analysis/riskanalysers/RiskAnalyserUnfashionableComponentsLicenses.java @@ -25,7 +25,7 @@ import com.manolodominguez.openlrae.baseofknowledge.basevalues.SupportedRisks; import com.manolodominguez.openlrae.baseofknowledge.basevalues.SupportedTrends; import com.manolodominguez.openlrae.baseofknowledge.licenseproperties.LicensesTrendFactory; -import com.manolodominguez.openlrae.arquitecture.SwProject; +import com.manolodominguez.openlrae.arquitecture.Project; import com.manolodominguez.openlrae.arquitecture.ComponentBinding; import com.manolodominguez.openlrae.i18n.LanguageChangeEvent; import com.manolodominguez.openlrae.i18n.Translations; @@ -71,7 +71,7 @@ public class RiskAnalyserUnfashionableComponentsLicenses extends AbstractRiskAna * * @param project. The software project to be analised. */ - public RiskAnalyserUnfashionableComponentsLicenses(SwProject project) { + public RiskAnalyserUnfashionableComponentsLicenses(Project project) { // Project is ckecked at superclass super(project, SupportedRisks.HAVING_UNFASHIONABLE_COMPONENTS_LICENSES); logger = LoggerFactory.getLogger(RiskAnalyserUnfashionableComponentsLicenses.class); diff --git a/src/main/java/com/manolodominguez/openlrae/analysis/riskanalysers/RiskAnalyserUnfashionableProjectLicenses.java b/src/main/java/com/manolodominguez/openlrae/analysis/riskanalysers/RiskAnalyserUnfashionableProjectLicenses.java index 2b37a01..b7a6b78 100644 --- a/src/main/java/com/manolodominguez/openlrae/analysis/riskanalysers/RiskAnalyserUnfashionableProjectLicenses.java +++ b/src/main/java/com/manolodominguez/openlrae/analysis/riskanalysers/RiskAnalyserUnfashionableProjectLicenses.java @@ -23,7 +23,7 @@ package com.manolodominguez.openlrae.analysis.riskanalysers; import com.manolodominguez.openlrae.baseofknowledge.basevalues.SupportedRisks; -import com.manolodominguez.openlrae.arquitecture.SwProject; +import com.manolodominguez.openlrae.arquitecture.Project; import com.manolodominguez.openlrae.baseofknowledge.basevalues.SupportedLicenses; import com.manolodominguez.openlrae.baseofknowledge.basevalues.SupportedTrends; import com.manolodominguez.openlrae.baseofknowledge.licenseproperties.LicensesTrendFactory; @@ -68,7 +68,7 @@ public class RiskAnalyserUnfashionableProjectLicenses extends AbstractRiskAnalys * * @param project. The software project to be analised. */ - public RiskAnalyserUnfashionableProjectLicenses(SwProject project) { + public RiskAnalyserUnfashionableProjectLicenses(Project project) { // Project is ckecked at superclass super(project, SupportedRisks.HAVING_UNFASHIONABLE_PROJECT_LICENSES); logger = LoggerFactory.getLogger(RiskAnalyserUnfashionableProjectLicenses.class); diff --git a/src/main/java/com/manolodominguez/openlrae/arquitecture/SwProject.java b/src/main/java/com/manolodominguez/openlrae/arquitecture/Project.java similarity index 97% rename from src/main/java/com/manolodominguez/openlrae/arquitecture/SwProject.java rename to src/main/java/com/manolodominguez/openlrae/arquitecture/Project.java index 3f3f70f..e120c0d 100644 --- a/src/main/java/com/manolodominguez/openlrae/arquitecture/SwProject.java +++ b/src/main/java/com/manolodominguez/openlrae/arquitecture/Project.java @@ -57,9 +57,9 @@ * * @author Manuel Domínguez Dorado - ingeniero@ManoloDominguez.com */ -public class SwProject implements ILanguageChangeEventEmitter, ILanguageChangeListener { +public class Project implements ILanguageChangeEventEmitter, ILanguageChangeListener { - private Logger logger = LoggerFactory.getLogger(SwProject.class); + private Logger logger = LoggerFactory.getLogger(Project.class); private String name; private String version; @@ -93,7 +93,7 @@ public class SwProject implements ILanguageChangeEventEmitter, ILanguageChangeLi * add additional component bindings, you have to use * addComponentBinding(...) method. */ - public SwProject(String name, String version, SupportedLicenses firstLicense, SupportedRedistributions redistribution, ComponentBinding firstComponentBinding) { + public Project(String name, String version, SupportedLicenses firstLicense, SupportedRedistributions redistribution, ComponentBinding firstComponentBinding) { if (name == null) { logger.error("name cannot be null"); throw new IllegalArgumentException("name cannot be null"); @@ -151,7 +151,7 @@ public SwProject(String name, String version, SupportedLicenses firstLicense, Su * @param projectDefinitionAsJSONString a JSON project definition as a * String. */ - public SwProject(String projectDefinitionAsJSONString) { + public Project(String projectDefinitionAsJSONString) { if (projectDefinitionAsJSONString == null) { logger.error("projectDefinitionAsJSONString cannot be null"); throw new IllegalArgumentException("projectDefinitionAsJSONString cannot be null"); @@ -184,7 +184,7 @@ public SwProject(String projectDefinitionAsJSONString) { * * @param projectDefinitionURL a URL containing a JSON project definition. */ - public SwProject(URL projectDefinitionURL) { + public Project(URL projectDefinitionURL) { if (projectDefinitionURL == null) { logger.error("projectDefinition URL cannot be null"); throw new IllegalArgumentException("projectDefinition URL cannot be null"); diff --git a/src/main/java/com/manolodominguez/openlrae/cli/CLIHandler.java b/src/main/java/com/manolodominguez/openlrae/cli/CLIHandler.java index 9688c0f..edffa56 100644 --- a/src/main/java/com/manolodominguez/openlrae/cli/CLIHandler.java +++ b/src/main/java/com/manolodominguez/openlrae/cli/CLIHandler.java @@ -36,7 +36,7 @@ import com.manolodominguez.openlrae.analysis.riskanalysers.RiskAnalyserUnfashionableProjectLicenses; import com.manolodominguez.openlrae.analysis.riskanalysers.RiskAnalyserComponentsLicensesMisalignedFromProjectLicenses; import com.manolodominguez.openlrae.analysis.riskanalysers.RiskAnalyserHeterogeneousComponentsLicenses; -import com.manolodominguez.openlrae.arquitecture.SwProject; +import com.manolodominguez.openlrae.arquitecture.Project; import com.manolodominguez.openlrae.baseofknowledge.basevalues.SupportedCompatibilities; import com.manolodominguez.openlrae.baseofknowledge.basevalues.SupportedComponentWeights; import com.manolodominguez.openlrae.baseofknowledge.basevalues.SupportedLicenses; @@ -134,7 +134,7 @@ public void runAnalysis(String fileName) { } else { try { - SwProject project = new SwProject(file.toURI().toURL()); + Project project = new Project(file.toURI().toURL()); // Define desired risk analysers we want to use for this project RiskAnalyserLimitedSetOfPotentialProjectLicenses riskAnalyser1 = new RiskAnalyserLimitedSetOfPotentialProjectLicenses(project); RiskAnalyserObsoleteComponentsLicenses riskAnalyser2 = new RiskAnalyserObsoleteComponentsLicenses(project); @@ -206,7 +206,7 @@ public void runExample() { } // Define the project. In this case, it is defined from a JSON file. URL projectURL = getClass().getResource(FilesPaths.PROJECT_EXAMPLE.getFilePath()); - SwProject project = new SwProject(projectURL); + Project project = new Project(projectURL); // Define desired risk analysers we want to use for this project RiskAnalyserLimitedSetOfPotentialProjectLicenses riskAnalyser1 = new RiskAnalyserLimitedSetOfPotentialProjectLicenses(project); diff --git a/src/main/java/com/manolodominguez/openlrae/reporting/ReportsFactory.java b/src/main/java/com/manolodominguez/openlrae/reporting/ReportsFactory.java index 2336720..30d64e4 100644 --- a/src/main/java/com/manolodominguez/openlrae/reporting/ReportsFactory.java +++ b/src/main/java/com/manolodominguez/openlrae/reporting/ReportsFactory.java @@ -23,7 +23,7 @@ package com.manolodominguez.openlrae.reporting; import com.manolodominguez.openlrae.analysis.RiskAnalysisResult; -import com.manolodominguez.openlrae.arquitecture.SwProject; +import com.manolodominguez.openlrae.arquitecture.Project; import org.json.JSONArray; import org.json.JSONObject; import org.slf4j.Logger; @@ -123,7 +123,7 @@ public static ReportsFactory getInstance() { * @return a licensing risk analysis report as a beautified (well indented) * JSON string. */ - public String getReportAsBeautifiedJSONString(SwProject project, RiskAnalysisResult[] resultSet) { + public String getReportAsBeautifiedJSONString(Project project, RiskAnalysisResult[] resultSet) { if (project == null) { logger.error("project cannot be null"); throw new IllegalArgumentException("project cannot be null"); @@ -145,7 +145,7 @@ public String getReportAsBeautifiedJSONString(SwProject project, RiskAnalysisRes * @return a licensing risk analysis report as a beautified (well indented) * JSON string. */ - public String getReportAsCompactJSONString(SwProject project, RiskAnalysisResult[] resultSet) { + public String getReportAsCompactJSONString(Project project, RiskAnalysisResult[] resultSet) { if (project == null) { logger.error("project cannot be null"); throw new IllegalArgumentException("project cannot be null"); @@ -165,7 +165,7 @@ public String getReportAsCompactJSONString(SwProject project, RiskAnalysisResult * analysis execution, related to the project. * @return a licensing risk analysis report as a JSON object. */ - public JSONArray getReportAsJSONArray(SwProject project, RiskAnalysisResult[] resultSet) { + public JSONArray getReportAsJSONArray(Project project, RiskAnalysisResult[] resultSet) { if (project == null) { logger.error("project cannot be null"); throw new IllegalArgumentException("project cannot be null"); @@ -219,7 +219,7 @@ public JSONArray getReportAsJSONArray(SwProject project, RiskAnalysisResult[] re * analysis execution, related to the project. * @return a licensing risk analysis report as a plain text. */ - public String getReportAsPlainText(SwProject project, RiskAnalysisResult[] resultSet) { + public String getReportAsPlainText(Project project, RiskAnalysisResult[] resultSet) { if (project == null) { logger.error("project cannot be null"); throw new IllegalArgumentException("project cannot be null"); diff --git a/src/test/java/com/manolodominguez/openlrae/arquitecture/ComponentBindingTest.java b/src/test/java/com/manolodominguez/openlrae/arquitecture/ComponentBindingTest.java index 88fa92f..8409db6 100644 --- a/src/test/java/com/manolodominguez/openlrae/arquitecture/ComponentBindingTest.java +++ b/src/test/java/com/manolodominguez/openlrae/arquitecture/ComponentBindingTest.java @@ -190,7 +190,7 @@ void testGetLanguage() { // See /com/manolodominguez/openlrae/json/ExampleProject.json to know // the content of that project. URL projectURL = getClass().getResource(FilesPaths.PROJECT_EXAMPLE.getFilePath()); - SwProject project = new SwProject(projectURL); + Project project = new Project(projectURL); ComponentBinding firstComponentBinding = project.getBillOfComponentBindings().get(0); assertEquals(SupportedLanguages.DEFAULT_LANGUAGE, firstComponentBinding.getLanguage()); firstComponentBinding.onLanguageChange(new LanguageChangeEvent(project, SupportedLanguages.SPANISH)); @@ -208,7 +208,7 @@ void testOnLanguageChange() { // See /com/manolodominguez/openlrae/json/ExampleProject.json to know // the content of that project. URL projectURL = getClass().getResource(FilesPaths.PROJECT_EXAMPLE.getFilePath()); - SwProject project = new SwProject(projectURL); + Project project = new Project(projectURL); ComponentBinding firstComponentBinding = project.getBillOfComponentBindings().get(0); assertEquals(SupportedLanguages.DEFAULT_LANGUAGE, firstComponentBinding.getLanguage()); firstComponentBinding.onLanguageChange(new LanguageChangeEvent(project, SupportedLanguages.SPANISH)); @@ -227,7 +227,7 @@ void testOnLanguageChangeWhenEventIsNull() { // See /com/manolodominguez/openlrae/json/ExampleProject.json to know // the content of that project. URL projectURL = getClass().getResource(FilesPaths.PROJECT_EXAMPLE.getFilePath()); - SwProject project = new SwProject(projectURL); + Project project = new Project(projectURL); ComponentBinding firstComponentBinding = project.getBillOfComponentBindings().get(0); assertThrows(IllegalArgumentException.class, () -> { // Should throw an exception because event is null diff --git a/src/test/java/com/manolodominguez/openlrae/arquitecture/ProjectTest.java b/src/test/java/com/manolodominguez/openlrae/arquitecture/ProjectTest.java new file mode 100644 index 0000000..3d7943c --- /dev/null +++ b/src/test/java/com/manolodominguez/openlrae/arquitecture/ProjectTest.java @@ -0,0 +1,609 @@ +/* + * Open Licensing Risk Analysis Engine (Open LRAE) is a licensing risk analysis + * engine in the form of Java library that allow the detection of risks related + * to licensing from the set of components (and their respective licenses) you + * are using in a given project. + * + * Copyright (C) Manuel Domínguez Dorado - ingeniero@ManoloDominguez.com. + * + * This program is free software: you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the Free + * Software Foundation, either version 3 of the License, or (at your option) any + * later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see + * https://www.gnu.org/licenses/lgpl-3.0.en.html. + */ +package com.manolodominguez.openlrae.arquitecture; + +import com.manolodominguez.openlrae.analysis.LicenseRiskAnalysisEngine; +import com.manolodominguez.openlrae.analysis.riskanalysers.RiskAnalyserLimitedSetOfPotentialProjectLicenses; +import com.manolodominguez.openlrae.baseofknowledge.basevalues.SupportedComponentWeights; +import com.manolodominguez.openlrae.baseofknowledge.basevalues.SupportedLicenses; +import com.manolodominguez.openlrae.baseofknowledge.basevalues.SupportedLinks; +import com.manolodominguez.openlrae.baseofknowledge.basevalues.SupportedRedistributions; +import com.manolodominguez.openlrae.i18n.LanguageChangeEvent; +import com.manolodominguez.openlrae.i18n.SupportedLanguages; +import com.manolodominguez.openlrae.resourceslocators.FilesPaths; +import java.io.BufferedReader; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.net.URL; +import java.util.Locale; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.*; + +/** + * + * @author manolodd + */ +class ProjectTest { + + public ProjectTest() { + } + + @BeforeAll + public static void setUpClass() { + } + + @AfterAll + public static void tearDownClass() { + } + + @BeforeEach + void setUp() { + } + + @AfterEach + void tearDown() { + } + + /** + * Test constructor of class Project. + */ + @Test + void testConstructor3() { + System.out.println("Constructor"); + // Define the project. In this case, it is defined from a JSON file. + // but could be come in by a call to a rest service or other methods. + // See /com/manolodominguez/openlrae/json/ExampleProject.json to know + // the content of that project. + URL projectURL = getClass().getResource(FilesPaths.PROJECT_EXAMPLE.getFilePath()); + Project project = new Project(projectURL); + assertEquals("MyProject", project.getName()); + assertEquals("1.0", project.getVersion()); + assertEquals(2, project.getLicenses().size()); + assertEquals(SupportedLicenses.APACHE_1_1, project.getLicenses().get(0)); + assertEquals(SupportedLicenses.MIT, project.getLicenses().get(1)); + assertEquals(SupportedRedistributions.SOFTWARE_PACKAGE_OR_SAAS, project.getRedistribution()); + assertEquals(4, project.getBillOfComponentBindings().size()); + } + + /** + * Test constructor of class Project. + */ + @Test + void testConstructor2() { + System.out.println("Constructor"); + // Define the project. In this case, it is defined from a JSON file. + // but could be come in by a call to a rest service or other methods. + // See /com/manolodominguez/openlrae/json/ExampleProject.json to know + // the content of that project. + URL projectURL = getClass().getResource(FilesPaths.PROJECT_EXAMPLE.getFilePath()); + Project project = new Project(projectURL); + assertEquals("MyProject", project.getName()); + assertEquals("1.0", project.getVersion()); + assertEquals(2, project.getLicenses().size()); + assertEquals(SupportedLicenses.APACHE_1_1, project.getLicenses().get(0)); + assertEquals(SupportedLicenses.MIT, project.getLicenses().get(1)); + assertEquals(SupportedRedistributions.SOFTWARE_PACKAGE_OR_SAAS, project.getRedistribution()); + assertEquals(4, project.getBillOfComponentBindings().size()); + } + + /** + * Test constructor of class Project. + */ + @Test + void testConstructor2WhenJSONStringIsNotValid() { + System.out.println("Constructor"); + // Define the project. In this case, it is defined from a JSON file. + // but could be come in by a call to a rest service or other methods. + // See /com/manolodominguez/openlrae/json/InvalidExampleProject.json + // to know the content of that project. + // Here we have the definition of a project as JSON string + assertThrows(IllegalArgumentException.class, () -> { + String projectDefinitionAsJSONString = ""; + InputStream inputStream = getClass().getResourceAsStream(FilesPaths.INVALID_PROJECT_EXAMPLE.getFilePath()); + BufferedReader bufferedReader; + bufferedReader = new BufferedReader(new InputStreamReader(inputStream)); + String string; + while ((string = bufferedReader.readLine()) != null) { + projectDefinitionAsJSONString += string; + } // Should throw an exception because project definition string does + // not follow the corresponding schema + new Project(projectDefinitionAsJSONString); + }); + } + + /** + * Test constructor of class Project. + */ + @Test + void testConstructor2WhenJSONStringIsNull() { + System.out.println("Constructor"); + String projectDefinitionAsJSONString = null; + assertThrows(IllegalArgumentException.class, () -> { + // Should throw an exception because the JSON string that defines the + // project is null + new Project(projectDefinitionAsJSONString); + }); + } + + /** + * Test constructor of class Project. + */ + @Test + void testConstructor2WhenJSONStringIsEmpty() { + System.out.println("Constructor"); + String projectDefinitionAsJSONString = ""; + assertThrows(IllegalArgumentException.class, () -> { + // Should throw an exception because the JSON string that defines the + // project is empty + new Project(projectDefinitionAsJSONString); + }); + } + + /** + * Test constructor of class Project. + */ + @Test + void testConstructor2WhenJSONStringIsNotJSON() { + System.out.println("Constructor"); + String projectDefinitionAsJSONString = "This is not a JSON string"; + assertThrows(IllegalArgumentException.class, () -> { + // Should throw an exception because the JSON string that defines the + // project is not a JSON string + new Project(projectDefinitionAsJSONString); + }); + } + + /** + * Test constructor of class Project. + */ + @Test + void testConstructor1() { + System.out.println("Constructor"); + Component firstComponent = new Component("ComponentName1", "ComponentVersion1", SupportedLicenses.ARTISTIC_2_0); + ComponentBinding firstComponentBinding = new ComponentBinding(firstComponent, SupportedLinks.DYNAMIC, SupportedComponentWeights.HIGH); + String projectName = "MyProject"; + String projectVersion = "MyProjectVersion"; + SupportedLicenses firstProjectLicense = SupportedLicenses.ARTISTIC_2_0; + SupportedRedistributions projectRedistribution = SupportedRedistributions.SOFTWARE_PACKAGE_OR_SAAS; + Project project = new Project(projectName, projectVersion, firstProjectLicense, projectRedistribution, firstComponentBinding); + assertEquals(projectName, project.getName()); + assertEquals(projectVersion, project.getVersion()); + assertEquals(1, project.getLicenses().size()); + assertEquals(firstProjectLicense, project.getLicenses().get(0)); + assertEquals(projectRedistribution, project.getRedistribution()); + assertEquals(1, project.getBillOfComponentBindings().size()); + // We're comparing object references here + assertEquals(firstComponentBinding, project.getBillOfComponentBindings().get(0)); + } + + /** + * Test constructor of class Project. + */ + @Test + void testConstructorWhenFirstComponentBindingIsNull() { + System.out.println("Constructor"); + ComponentBinding firstComponentBinding = null; + String projectName = "MyProject"; + String projectVersion = "MyProjectVersion"; + SupportedLicenses firstProjectLicense = SupportedLicenses.APACHE_2_0; + SupportedRedistributions projectRedistribution = SupportedRedistributions.SOFTWARE_PACKAGE_OR_SAAS; + assertThrows(IllegalArgumentException.class, () -> { + // Should throw an exception because first component binding is null + new Project(projectName, projectVersion, firstProjectLicense, projectRedistribution, firstComponentBinding); + }); + } + + /** + * Test constructor of class Project. + */ + @Test + void testConstructorWhenRedistributionIsNull() { + System.out.println("Constructor"); + Component firstComponent = new Component("ComponentName1", "ComponentVersion1", SupportedLicenses.ARTISTIC_2_0); + ComponentBinding firstComponentBinding = new ComponentBinding(firstComponent, SupportedLinks.DYNAMIC, SupportedComponentWeights.HIGH); + String projectName = "MyProject"; + String projectVersion = "MyProjectVersion"; + SupportedLicenses firstProjectLicense = SupportedLicenses.APACHE_2_0; + SupportedRedistributions projectRedistribution = null; + assertThrows(IllegalArgumentException.class, () -> { + // Should throw an exception because project redistribution is null + new Project(projectName, projectVersion, firstProjectLicense, projectRedistribution, firstComponentBinding); + }); + } + + /** + * Test constructor of class Project. + */ + @Test + void testConstructorWhenFirstProjectLicenseIsInvalid() { + System.out.println("Constructor"); + Component firstComponent = new Component("ComponentName1", "ComponentVersion1", SupportedLicenses.ARTISTIC_2_0); + ComponentBinding firstComponentBinding = new ComponentBinding(firstComponent, SupportedLinks.DYNAMIC, SupportedComponentWeights.HIGH); + String projectName = "MyProject"; + String projectVersion = "MyProjectVersion"; + SupportedLicenses firstProjectLicense = SupportedLicenses.UNSUPPORTED; + SupportedRedistributions projectRedistribution = SupportedRedistributions.SOFTWARE_PACKAGE_OR_SAAS; + assertThrows(IllegalArgumentException.class, () -> { + // Should throw an exception because first project license version is invalid + new Project(projectName, projectVersion, firstProjectLicense, projectRedistribution, firstComponentBinding); + }); + } + + /** + * Test constructor of class Project. + */ + @Test + void testConstructorWhenFirstProjectLicenseIsNull() { + System.out.println("Constructor"); + Component firstComponent = new Component("ComponentName1", "ComponentVersion1", SupportedLicenses.ARTISTIC_2_0); + ComponentBinding firstComponentBinding = new ComponentBinding(firstComponent, SupportedLinks.DYNAMIC, SupportedComponentWeights.HIGH); + String projectName = "MyProject"; + String projectVersion = "MyProjectVersion"; + SupportedLicenses firstProjectLicense = null; + SupportedRedistributions projectRedistribution = SupportedRedistributions.SOFTWARE_PACKAGE_OR_SAAS; + assertThrows(IllegalArgumentException.class, () -> { + // Should throw an exception because first project license version is null + new Project(projectName, projectVersion, firstProjectLicense, projectRedistribution, firstComponentBinding); + }); + } + + /** + * Test constructor of class Project. + */ + @Test + void testConstructorWhenVersionIsEmpty() { + System.out.println("Constructor"); + Component firstComponent = new Component("ComponentName1", "ComponentVersion1", SupportedLicenses.ARTISTIC_2_0); + ComponentBinding firstComponentBinding = new ComponentBinding(firstComponent, SupportedLinks.DYNAMIC, SupportedComponentWeights.HIGH); + String projectName = "MyProject"; + String projectVersion = ""; + SupportedLicenses firstProjectLicense = SupportedLicenses.ARTISTIC_2_0; + SupportedRedistributions projectRedistribution = SupportedRedistributions.SOFTWARE_PACKAGE_OR_SAAS; + assertThrows(IllegalArgumentException.class, () -> { + // Should throw an exception because project version is empty + new Project(projectName, projectVersion, firstProjectLicense, projectRedistribution, firstComponentBinding); + }); + } + + /** + * Test constructor of class Project. + */ + @Test + void testConstructorWhenVersionIsNull() { + System.out.println("Constructor"); + Component firstComponent = new Component("ComponentName1", "ComponentVersion1", SupportedLicenses.ARTISTIC_2_0); + ComponentBinding firstComponentBinding = new ComponentBinding(firstComponent, SupportedLinks.DYNAMIC, SupportedComponentWeights.HIGH); + String projectName = "MyProject"; + String projectVersion = null; + SupportedLicenses firstProjectLicense = SupportedLicenses.ARTISTIC_2_0; + SupportedRedistributions projectRedistribution = SupportedRedistributions.SOFTWARE_PACKAGE_OR_SAAS; + assertThrows(IllegalArgumentException.class, () -> { + // Should throw an exception because project version is null + new Project(projectName, projectVersion, firstProjectLicense, projectRedistribution, firstComponentBinding); + }); + } + + /** + * Test constructor of class Project. + */ + @Test + void testConstructorWhenNameIsEmpty() { + System.out.println("Constructor"); + Component firstComponent = new Component("ComponentName1", "ComponentVersion1", SupportedLicenses.ARTISTIC_2_0); + ComponentBinding firstComponentBinding = new ComponentBinding(firstComponent, SupportedLinks.DYNAMIC, SupportedComponentWeights.HIGH); + String projectName = ""; + String projectVersion = "MyProjectVersion"; + SupportedLicenses firstProjectLicense = SupportedLicenses.ARTISTIC_2_0; + SupportedRedistributions projectRedistribution = SupportedRedistributions.SOFTWARE_PACKAGE_OR_SAAS; + assertThrows(IllegalArgumentException.class, () -> { + // Should throw an exception because project name is empty + new Project(projectName, projectVersion, firstProjectLicense, projectRedistribution, firstComponentBinding); + }); + } + + /** + * Test constructor of class Project. + */ + @Test + void testConstructorWhenNameIsNull() { + System.out.println("Constructor"); + Component firstComponent = new Component("ComponentName1", "ComponentVersion1", SupportedLicenses.ARTISTIC_2_0); + ComponentBinding firstComponentBinding = new ComponentBinding(firstComponent, SupportedLinks.DYNAMIC, SupportedComponentWeights.HIGH); + String projectName = null; + String projectVersion = "MyProjectVersion"; + SupportedLicenses firstProjectLicense = SupportedLicenses.ARTISTIC_2_0; + SupportedRedistributions projectRedistribution = SupportedRedistributions.SOFTWARE_PACKAGE_OR_SAAS; + assertThrows(IllegalArgumentException.class, () -> { + // Should throw an exception because project name is null + new Project(projectName, projectVersion, firstProjectLicense, projectRedistribution, firstComponentBinding); + }); + } + + /** + * Test of addComponentBinding method, of class Project. + */ + @Test + void testAddComponentBindingWhenNull() { + System.out.println("addComponentBinding"); + Component firstComponent = new Component("ComponentName1", "ComponentVersion1", SupportedLicenses.ARTISTIC_2_0); + ComponentBinding firstComponentBinding = new ComponentBinding(firstComponent, SupportedLinks.DYNAMIC, SupportedComponentWeights.HIGH); + String projectName = "MyProject"; + String projectVersion = "MyProjectVersion"; + SupportedLicenses firstProjectLicense = SupportedLicenses.ARTISTIC_2_0; + SupportedRedistributions projectRedistribution = SupportedRedistributions.SOFTWARE_PACKAGE_OR_SAAS; + Project project = new Project(projectName, projectVersion, firstProjectLicense, projectRedistribution, firstComponentBinding); + assertThrows(IllegalArgumentException.class, () -> { + // Should throw an exception because the argument is null + project.addComponentBinding(null); + }); + } + + /** + * Test of addComponentBinding method, of class Project. + */ + @Test + void testAddComponentBinding() { + System.out.println("addComponentBinding"); + Component firstComponent = new Component("ComponentName1", "ComponentVersion1", SupportedLicenses.ARTISTIC_2_0); + Component secondComponent = new Component("ComponentName1", "ComponentVersion2", SupportedLicenses.MIT); + ComponentBinding firstComponentBinding = new ComponentBinding(firstComponent, SupportedLinks.DYNAMIC, SupportedComponentWeights.HIGH); + ComponentBinding secondComponentBinding = new ComponentBinding(secondComponent, SupportedLinks.DYNAMIC, SupportedComponentWeights.NEAR_HIGH); + String projectName = "MyProject"; + String projectVersion = "MyProjectVersion"; + SupportedLicenses firstProjectLicense = SupportedLicenses.ARTISTIC_2_0; + SupportedRedistributions projectRedistribution = SupportedRedistributions.SOFTWARE_PACKAGE_OR_SAAS; + Project project = new Project(projectName, projectVersion, firstProjectLicense, projectRedistribution, firstComponentBinding); + assertEquals(1, project.getBillOfComponentBindings().size()); + project.addComponentBinding(secondComponentBinding); + assertEquals(2, project.getBillOfComponentBindings().size()); + assertEquals(secondComponentBinding, project.getBillOfComponentBindings().get(1)); // We're comparing objects references here + } + + /** + * Test of getName method, of class Project. + */ + @Test + void testGetName() { + System.out.println("getName"); + Component firstComponent = new Component("ComponentName1", "ComponentVersion1", SupportedLicenses.ARTISTIC_2_0); + ComponentBinding firstComponentBinding = new ComponentBinding(firstComponent, SupportedLinks.DYNAMIC, SupportedComponentWeights.HIGH); + String projectName = "MyProject"; + String projectVersion = "MyProjectVersion"; + SupportedLicenses firstProjectLicense = SupportedLicenses.ARTISTIC_2_0; + SupportedRedistributions projectRedistribution = SupportedRedistributions.SOFTWARE_PACKAGE_OR_SAAS; + Project project = new Project(projectName, projectVersion, firstProjectLicense, projectRedistribution, firstComponentBinding); + assertEquals("MyProject", project.getName()); + } + + /** + * Test of getFullName method, of class Project. + */ + @Test + void testGetFullName() { + System.out.println("getFullName"); + Component firstComponent = new Component("ComponentName1", "ComponentVersion1", SupportedLicenses.ARTISTIC_2_0); + ComponentBinding firstComponentBinding = new ComponentBinding(firstComponent, SupportedLinks.DYNAMIC, SupportedComponentWeights.HIGH); + String projectName = "MyProject"; + String projectVersion = "MyProjectVersion"; + SupportedLicenses firstProjectLicense = SupportedLicenses.ARTISTIC_2_0; + SupportedLicenses secondProjectLicense = SupportedLicenses.APACHE_2_0; + SupportedRedistributions projectRedistribution = SupportedRedistributions.SOFTWARE_PACKAGE_OR_SAAS; + Project project = new Project(projectName, projectVersion, firstProjectLicense, projectRedistribution, firstComponentBinding); + project.addLicense(secondProjectLicense); + assertEquals("MyProject-MyProjectVersion (Artistic-2.0, Apache-2.0), that is going to be redistributed", project.getFullName()); + } + + /** + * Test of getVersion method, of class Project. + */ + @Test + void testGetVersion() { + System.out.println("getVersion"); + Component firstComponent = new Component("ComponentName1", "ComponentVersion1", SupportedLicenses.ARTISTIC_2_0); + ComponentBinding firstComponentBinding = new ComponentBinding(firstComponent, SupportedLinks.DYNAMIC, SupportedComponentWeights.HIGH); + String projectName = "MyProject"; + String projectVersion = "MyProjectVersion"; + SupportedLicenses firstProjectLicense = SupportedLicenses.ARTISTIC_2_0; + SupportedRedistributions projectRedistribution = SupportedRedistributions.SOFTWARE_PACKAGE_OR_SAAS; + Project project = new Project(projectName, projectVersion, firstProjectLicense, projectRedistribution, firstComponentBinding); + assertEquals("MyProjectVersion", project.getVersion()); + } + + /** + * Test of addLicense method, of class Project. + */ + @Test + void testAddLicense() { + System.out.println("addLicense"); + Component firstComponent = new Component("ComponentName1", "ComponentVersion1", SupportedLicenses.ARTISTIC_2_0); + ComponentBinding firstComponentBinding = new ComponentBinding(firstComponent, SupportedLinks.DYNAMIC, SupportedComponentWeights.HIGH); + String projectName = "MyProject"; + String projectVersion = "MyProjectVersion"; + SupportedLicenses firstProjectLicense = SupportedLicenses.ARTISTIC_2_0; + SupportedLicenses secondProjectLicense = SupportedLicenses.APACHE_2_0; + SupportedRedistributions projectRedistribution = SupportedRedistributions.SOFTWARE_PACKAGE_OR_SAAS; + Project project = new Project(projectName, projectVersion, firstProjectLicense, projectRedistribution, firstComponentBinding); + assertEquals(firstProjectLicense, project.getLicenses().get(0)); + project.addLicense(secondProjectLicense); + assertEquals(secondProjectLicense, project.getLicenses().get(1)); + } + + /** + * Test of addLicense method, of class Project. + */ + @Test + void testAddLicenseWhenNull() { + System.out.println("addLicense"); + Component firstComponent = new Component("ComponentName1", "ComponentVersion1", SupportedLicenses.ARTISTIC_2_0); + ComponentBinding firstComponentBinding = new ComponentBinding(firstComponent, SupportedLinks.DYNAMIC, SupportedComponentWeights.HIGH); + String projectName = "MyProject"; + String projectVersion = "MyProjectVersion"; + SupportedLicenses firstProjectLicense = SupportedLicenses.ARTISTIC_2_0; + SupportedRedistributions projectRedistribution = SupportedRedistributions.SOFTWARE_PACKAGE_OR_SAAS; + Project project = new Project(projectName, projectVersion, firstProjectLicense, projectRedistribution, firstComponentBinding); + assertThrows(IllegalArgumentException.class, () -> { + // Should throw an exception because the argument is null + project.addLicense(null); + }); + } + + /** + * Test of getLicenses method, of class Project. + */ + @Test + void testGetLicenses() { + System.out.println("getLicenses"); + Component firstComponent = new Component("ComponentName1", "ComponentVersion1", SupportedLicenses.ARTISTIC_2_0); + ComponentBinding firstComponentBinding = new ComponentBinding(firstComponent, SupportedLinks.DYNAMIC, SupportedComponentWeights.HIGH); + String projectName = "MyProject"; + String projectVersion = "MyProjectVersion"; + SupportedLicenses firstProjectLicense = SupportedLicenses.ARTISTIC_2_0; + SupportedLicenses secondProjectLicense = SupportedLicenses.APACHE_2_0; + SupportedRedistributions projectRedistribution = SupportedRedistributions.SOFTWARE_PACKAGE_OR_SAAS; + Project project = new Project(projectName, projectVersion, firstProjectLicense, projectRedistribution, firstComponentBinding); + assertEquals(1, project.getLicenses().size()); + project.addLicense(secondProjectLicense); + assertEquals(2, project.getLicenses().size()); + assertNotNull(project.getLicenses()); + } + + /** + * Test of getRedistribution method, of class Project. + */ + @Test + void testGetRedistribution() { + System.out.println("getRedistribution"); + Component firstComponent = new Component("ComponentName1", "ComponentVersion1", SupportedLicenses.ARTISTIC_2_0); + ComponentBinding firstComponentBinding = new ComponentBinding(firstComponent, SupportedLinks.DYNAMIC, SupportedComponentWeights.HIGH); + String projectName = "MyProject"; + String projectVersion = "MyProjectVersion"; + SupportedLicenses firstProjectLicense = SupportedLicenses.ARTISTIC_2_0; + SupportedRedistributions projectRedistribution = SupportedRedistributions.SOFTWARE_PACKAGE_OR_SAAS; + Project project = new Project(projectName, projectVersion, firstProjectLicense, projectRedistribution, firstComponentBinding); + assertEquals(projectRedistribution, project.getRedistribution()); + } + + /** + * Test of getBillOfComponentBindings method, of class Project. + */ + @Test + void testGetBillOfComponentBindings() { + System.out.println("getBillOfComponentBindings"); + Component firstComponent = new Component("ComponentName1", "ComponentVersion1", SupportedLicenses.ARTISTIC_2_0); + Component secondComponent = new Component("ComponentName1", "ComponentVersion2", SupportedLicenses.MIT); + ComponentBinding firstComponentBinding = new ComponentBinding(firstComponent, SupportedLinks.DYNAMIC, SupportedComponentWeights.HIGH); + ComponentBinding secondComponentBinding = new ComponentBinding(secondComponent, SupportedLinks.DYNAMIC, SupportedComponentWeights.NEAR_HIGH); + String projectName = "MyProject"; + String projectVersion = "MyProjectVersion"; + SupportedLicenses firstProjectLicense = SupportedLicenses.ARTISTIC_2_0; + SupportedRedistributions projectRedistribution = SupportedRedistributions.SOFTWARE_PACKAGE_OR_SAAS; + Project project = new Project(projectName, projectVersion, firstProjectLicense, projectRedistribution, firstComponentBinding); + assertEquals(1, project.getBillOfComponentBindings().size()); + assertEquals(firstComponentBinding, project.getBillOfComponentBindings().get(0)); // We're comparing objects references here + project.addComponentBinding(secondComponentBinding); + assertEquals(2, project.getBillOfComponentBindings().size()); + assertEquals(secondComponentBinding, project.getBillOfComponentBindings().get(1)); // We're comparing objects references here + assertNotNull(project.getBillOfComponentBindings()); + } + + /** + * Test of getLanguage method, of class Project. + */ + @Test + void testGetLanguage() { + System.out.println("getLanguage"); + Component firstComponent = new Component("ComponentName1", "ComponentVersion1", SupportedLicenses.ARTISTIC_2_0); + Component secondComponent = new Component("ComponentName1", "ComponentVersion2", SupportedLicenses.MIT); + ComponentBinding firstComponentBinding = new ComponentBinding(firstComponent, SupportedLinks.DYNAMIC, SupportedComponentWeights.HIGH); + ComponentBinding secondComponentBinding = new ComponentBinding(secondComponent, SupportedLinks.DYNAMIC, SupportedComponentWeights.NEAR_HIGH); + String projectName = "MyProject"; + String projectVersion = "MyProjectVersion"; + SupportedLicenses firstProjectLicense = SupportedLicenses.ARTISTIC_2_0; + SupportedRedistributions projectRedistribution = SupportedRedistributions.SOFTWARE_PACKAGE_OR_SAAS; + Project project = new Project(projectName, projectVersion, firstProjectLicense, projectRedistribution, firstComponentBinding); + assertEquals(SupportedLanguages.DEFAULT_LANGUAGE, project.getLanguage()); + } + + /** + * Test of fireLanguageChangeEvent method, of class Project. + */ + @Test + void testFireLanguageChangeEvent() { + System.out.println("fireLanguageChangeEvent"); + // Define the project. In this case, it is defined from a JSON file. + URL projectURL = getClass().getResource(FilesPaths.PROJECT_EXAMPLE.getFilePath()); + Project project = new Project(projectURL); + + assertEquals(SupportedLanguages.DEFAULT_LANGUAGE, project.getLanguage()); + for (ComponentBinding componentBinding : project.getBillOfComponentBindings()) { + assertEquals(SupportedLanguages.DEFAULT_LANGUAGE, componentBinding.getLanguage()); + } + project.onLanguageChange(new LanguageChangeEvent(project, SupportedLanguages.SPANISH)); + assertEquals(SupportedLanguages.SPANISH, project.getLanguage()); + for (ComponentBinding componentBinding : project.getBillOfComponentBindings()) { + assertEquals(SupportedLanguages.SPANISH, componentBinding.getLanguage()); + } + } + + /** + * Test of onLanguageChange method, of class Project. + */ + @Test + void testOnLanguageChange() { + System.out.println("onLanguageChange"); + // Define the project. In this case, it is defined from a JSON file. + URL projectURL = getClass().getResource(FilesPaths.PROJECT_EXAMPLE.getFilePath()); + Project project = new Project(projectURL); + + RiskAnalyserLimitedSetOfPotentialProjectLicenses riskAnalyser1 = new RiskAnalyserLimitedSetOfPotentialProjectLicenses(project); + // Define a Risk analysis engine and add these risk analysers + LicenseRiskAnalysisEngine instance = new LicenseRiskAnalysisEngine(riskAnalyser1); + + assertEquals(SupportedLanguages.DEFAULT_LANGUAGE, project.getLanguage()); + instance.setLanguage(new Locale("es")); + assertEquals(SupportedLanguages.SPANISH, project.getLanguage()); + } + + /** + * Test of onLanguageChange method, of class Project. + */ + @Test + void testOnLanguageChangeWhenEventisNull() { + System.out.println("onLanguageChange"); + // Define the project. In this case, it is defined from a JSON file. + URL projectURL = getClass().getResource(FilesPaths.PROJECT_EXAMPLE.getFilePath()); + Project project = new Project(projectURL); + + assertThrows(IllegalArgumentException.class, () -> { + // Should throw an exception because the argument is null + project.onLanguageChange(null); + }); + } + +} diff --git a/src/test/java/com/manolodominguez/openlrae/i18n/LanguageChangeEventTest.java b/src/test/java/com/manolodominguez/openlrae/i18n/LanguageChangeEventTest.java index 33494b4..7d482cb 100644 --- a/src/test/java/com/manolodominguez/openlrae/i18n/LanguageChangeEventTest.java +++ b/src/test/java/com/manolodominguez/openlrae/i18n/LanguageChangeEventTest.java @@ -22,7 +22,7 @@ */ package com.manolodominguez.openlrae.i18n; -import com.manolodominguez.openlrae.arquitecture.SwProject; +import com.manolodominguez.openlrae.arquitecture.Project; import com.manolodominguez.openlrae.resourceslocators.FilesPaths; import java.net.URL; import org.junit.jupiter.api.AfterEach; @@ -66,7 +66,7 @@ void TestConstructor() { // Define a project. Just because we need a ILanguageChangeEventEmitter // and a Project is one. URL projectURL = getClass().getResource(FilesPaths.PROJECT_EXAMPLE.getFilePath()); - SwProject project = new SwProject(projectURL); + Project project = new Project(projectURL); LanguageChangeEvent event = new LanguageChangeEvent(project, SupportedLanguages.SPANISH); assertTrue(project == event.getSource()); //We're comparing object references here assertEquals(SupportedLanguages.SPANISH, event.getNewLanguage()); @@ -94,7 +94,7 @@ void TestConstructorWhenNewLanguageIsNull() { // Define a project. Just because we need a ILanguageChangeEventEmitter // and a Project is one. URL projectURL = getClass().getResource(FilesPaths.PROJECT_EXAMPLE.getFilePath()); - SwProject project = new SwProject(projectURL); + Project project = new Project(projectURL); assertThrows(IllegalArgumentException.class, () -> { // Should throw an exception because newLanguage is null new LanguageChangeEvent(project, null); @@ -110,7 +110,7 @@ void testGetNewLanguage() { // Define a project. Just because we need a ILanguageChangeEventEmitter // and a Project is one. URL projectURL = getClass().getResource(FilesPaths.PROJECT_EXAMPLE.getFilePath()); - SwProject project = new SwProject(projectURL); + Project project = new Project(projectURL); LanguageChangeEvent event = new LanguageChangeEvent(project, SupportedLanguages.SPANISH); assertEquals(SupportedLanguages.SPANISH, event.getNewLanguage()); }