From f24dfd693fdf44c8b18712ed90b73ebb166dd1f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20Dom=C3=ADnguez=20Dorado?= Date: Sun, 13 Feb 2022 18:56:48 +0100 Subject: [PATCH] mjson seems to be abandoned, so it has been replaced by everit-json-schema --- .../LicenseRiskAnalysisEngineTest.java | 343 ++++++++++++++++++ ...nsesMisalignedFromProjectLicensesTest.java | 170 +++++++++ ...esIncompatibleWithProjectLicensesTest.java | 171 +++++++++ ...erHeterogeneousComponentsLicensesTest.java | 176 +++++++++ ...dSetOfPotentialComponentsLicensesTest.java | 172 +++++++++ ...itedSetOfPotentialProjectLicensesTest.java | 170 +++++++++ ...nalyserObsoleteComponentsLicensesTest.java | 171 +++++++++ ...skAnalyserObsoleteProjectLicensesTest.java | 170 +++++++++ ...rScarcelySpreadComponentsLicensesTest.java | 171 +++++++++ ...yserScarcelySpreadProjectLicensesTest.java | 170 +++++++++ ...erUnfashionableComponentsLicensesTest.java | 171 +++++++++ ...lyserUnfashionableProjectLicensesTest.java | 171 +++++++++ .../reporting/ReportsFactoryTest.java | 201 ++++++++++ 13 files changed, 2427 insertions(+) create mode 100644 src/test/java/com/manolodominguez/openlrae/analysis/LicenseRiskAnalysisEngineTest.java create mode 100644 src/test/java/com/manolodominguez/openlrae/analysis/riskanalysers/RiskAnalyserComponentsLicensesMisalignedFromProjectLicensesTest.java create mode 100644 src/test/java/com/manolodominguez/openlrae/analysis/riskanalysers/RiskAnalyserHavingComponentsLicensesIncompatibleWithProjectLicensesTest.java create mode 100644 src/test/java/com/manolodominguez/openlrae/analysis/riskanalysers/RiskAnalyserHeterogeneousComponentsLicensesTest.java create mode 100644 src/test/java/com/manolodominguez/openlrae/analysis/riskanalysers/RiskAnalyserLimitedSetOfPotentialComponentsLicensesTest.java create mode 100644 src/test/java/com/manolodominguez/openlrae/analysis/riskanalysers/RiskAnalyserLimitedSetOfPotentialProjectLicensesTest.java create mode 100644 src/test/java/com/manolodominguez/openlrae/analysis/riskanalysers/RiskAnalyserObsoleteComponentsLicensesTest.java create mode 100644 src/test/java/com/manolodominguez/openlrae/analysis/riskanalysers/RiskAnalyserObsoleteProjectLicensesTest.java create mode 100644 src/test/java/com/manolodominguez/openlrae/analysis/riskanalysers/RiskAnalyserScarcelySpreadComponentsLicensesTest.java create mode 100644 src/test/java/com/manolodominguez/openlrae/analysis/riskanalysers/RiskAnalyserScarcelySpreadProjectLicensesTest.java create mode 100644 src/test/java/com/manolodominguez/openlrae/analysis/riskanalysers/RiskAnalyserUnfashionableComponentsLicensesTest.java create mode 100644 src/test/java/com/manolodominguez/openlrae/analysis/riskanalysers/RiskAnalyserUnfashionableProjectLicensesTest.java create mode 100644 src/test/java/com/manolodominguez/openlrae/reporting/ReportsFactoryTest.java diff --git a/src/test/java/com/manolodominguez/openlrae/analysis/LicenseRiskAnalysisEngineTest.java b/src/test/java/com/manolodominguez/openlrae/analysis/LicenseRiskAnalysisEngineTest.java new file mode 100644 index 0000000..48c091a --- /dev/null +++ b/src/test/java/com/manolodominguez/openlrae/analysis/LicenseRiskAnalysisEngineTest.java @@ -0,0 +1,343 @@ +/* + * 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.analysis; + +import com.manolodominguez.openlrae.analysis.riskanalysers.AbstractRiskAnalyser; +import com.manolodominguez.openlrae.analysis.riskanalysers.RiskAnalyserComponentsLicensesIncompatibleWithProjectLicenses; +import com.manolodominguez.openlrae.analysis.riskanalysers.RiskAnalyserHeterogeneousComponentsLicenses; +import com.manolodominguez.openlrae.analysis.riskanalysers.RiskAnalyserObsoleteComponentsLicenses; +import com.manolodominguez.openlrae.analysis.riskanalysers.RiskAnalyserLimitedSetOfPotentialComponentsLicenses; +import com.manolodominguez.openlrae.analysis.riskanalysers.RiskAnalyserLimitedSetOfPotentialProjectLicenses; +import com.manolodominguez.openlrae.analysis.riskanalysers.RiskAnalyserScarcelySpreadComponentsLicenses; +import com.manolodominguez.openlrae.analysis.riskanalysers.RiskAnalyserUnfashionableComponentsLicenses; +import com.manolodominguez.openlrae.arquitecture.ComponentBinding; +import com.manolodominguez.openlrae.arquitecture.Project; +import com.manolodominguez.openlrae.i18n.SupportedLanguages; +import com.manolodominguez.openlrae.reporting.ReportsFactory; +import com.manolodominguez.openlrae.resourceslocators.FilesPaths; +import java.net.URI; +import java.net.URISyntaxException; +import java.net.URL; +import java.util.Locale; +import org.everit.json.schema.Schema; +import org.everit.json.schema.ValidationException; +import org.everit.json.schema.loader.SchemaLoader; +import org.json.JSONArray; +import org.json.JSONObject; +import org.json.JSONTokener; +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 LicenseRiskAnalysisEngineTest { + + public LicenseRiskAnalysisEngineTest() { + } + + @BeforeAll + public static void setUpClass() { + } + + @AfterAll + public static void tearDownClass() { + } + + @BeforeEach + void setUp() { + } + + @AfterEach + void tearDown() { + } + + /** + * Test constructor of class LicenseRiskAnalysisEngine. + */ + @Test + void testConstructor() { + System.out.println("constructor"); + assertThrows(IllegalArgumentException.class, () -> { + new LicenseRiskAnalysisEngine(null); // Should throw an exception + }); + } + + /** + * Test of addRiskAnalyser method, of class LicenseRiskAnalysisEngine. + */ + @Test + void testAddRiskAnalyserNull() { + System.out.println("addRiskAnalyser"); + // 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); + + // Define some risk analysers we want to use for this project + RiskAnalyserLimitedSetOfPotentialProjectLicenses riskAnalyser1 = new RiskAnalyserLimitedSetOfPotentialProjectLicenses(project); + // Define a Risk analysis engine and add these risk analysers + LicenseRiskAnalysisEngine instance = new LicenseRiskAnalysisEngine(riskAnalyser1); + assertThrows(IllegalArgumentException.class, () -> { + instance.addRiskAnalyser(null); // Should throw an exception + }); + } + + /** + * Test of analyse method, of class LicenseRiskAnalysisEngine. + */ + @Test + void testAnalyse() { + System.out.println("analyse"); + boolean worksFine = true; + // 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); + RiskAnalyserObsoleteComponentsLicenses riskAnalyser2 = new RiskAnalyserObsoleteComponentsLicenses(project); + RiskAnalyserUnfashionableComponentsLicenses riskAnalyser3 = new RiskAnalyserUnfashionableComponentsLicenses(project); + RiskAnalyserScarcelySpreadComponentsLicenses riskAnalyser4 = new RiskAnalyserScarcelySpreadComponentsLicenses(project); + RiskAnalyserComponentsLicensesIncompatibleWithProjectLicenses riskAnalyser5 = new RiskAnalyserComponentsLicensesIncompatibleWithProjectLicenses(project); + RiskAnalyserLimitedSetOfPotentialComponentsLicenses riskAnalyser6 = new RiskAnalyserLimitedSetOfPotentialComponentsLicenses(project); + // Define a Risk analysis engine and add these risk analysers + LicenseRiskAnalysisEngine instance = new LicenseRiskAnalysisEngine(riskAnalyser1); + instance.addRiskAnalyser(riskAnalyser2); + instance.addRiskAnalyser(riskAnalyser3); + instance.addRiskAnalyser(riskAnalyser4); + instance.addRiskAnalyser(riskAnalyser5); + instance.addRiskAnalyser(riskAnalyser6); + + // Run the license risks analysis and collect results + RiskAnalysisResult[] resultSet = instance.analyse(); + ReportsFactory reportsFactory = ReportsFactory.getInstance(); + JSONArray report = reportsFactory.getReportAsJSONArray(project, resultSet); + try { + JSONObject rawSchema = new JSONObject(new JSONTokener(getClass().getResourceAsStream(FilesPaths.REPORT_SCHEMA.getFilePath()))); + Schema sch = SchemaLoader.load(rawSchema); + sch.validate(report); // throws a ValidationException if this object is invalid + worksFine = true; + } + catch (ValidationException ex) { + worksFine = false; + } + assertTrue(worksFine); + } + + /** + * Test of addRiskAnalyser method, of class LicenseRiskAnalysisEngine. + */ + @Test + void testAddRiskAnalyser() { + System.out.println("addRiskAnalyser"); + // 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); + RiskAnalyserObsoleteComponentsLicenses riskAnalyser2 = new RiskAnalyserObsoleteComponentsLicenses(project); + RiskAnalyserUnfashionableComponentsLicenses riskAnalyser3 = new RiskAnalyserUnfashionableComponentsLicenses(project); + RiskAnalyserScarcelySpreadComponentsLicenses riskAnalyser4 = new RiskAnalyserScarcelySpreadComponentsLicenses(project); + RiskAnalyserComponentsLicensesIncompatibleWithProjectLicenses riskAnalyser5 = new RiskAnalyserComponentsLicensesIncompatibleWithProjectLicenses(project); + RiskAnalyserLimitedSetOfPotentialComponentsLicenses riskAnalyser6 = new RiskAnalyserLimitedSetOfPotentialComponentsLicenses(project); + // Define a Risk analysis engine and add these risk analysers + LicenseRiskAnalysisEngine instance = new LicenseRiskAnalysisEngine(riskAnalyser1); + assertEquals(1, instance.getRisksAnalysers().size()); + instance.addRiskAnalyser(riskAnalyser2); + assertEquals(2, instance.getRisksAnalysers().size()); + instance.addRiskAnalyser(riskAnalyser3); + assertEquals(3, instance.getRisksAnalysers().size()); + instance.addRiskAnalyser(riskAnalyser4); + assertEquals(4, instance.getRisksAnalysers().size()); + instance.addRiskAnalyser(riskAnalyser5); + assertEquals(5, instance.getRisksAnalysers().size()); + instance.addRiskAnalyser(riskAnalyser6); + assertEquals(6, instance.getRisksAnalysers().size()); + } + + /** + * Test of setLanguage method, of class LicenseRiskAnalysisEngine. + */ + @Test + void testSetLanguage() { + System.out.println("setLanguage"); + // 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); + RiskAnalyserObsoleteComponentsLicenses riskAnalyser2 = new RiskAnalyserObsoleteComponentsLicenses(project); + RiskAnalyserUnfashionableComponentsLicenses riskAnalyser3 = new RiskAnalyserUnfashionableComponentsLicenses(project); + RiskAnalyserScarcelySpreadComponentsLicenses riskAnalyser4 = new RiskAnalyserScarcelySpreadComponentsLicenses(project); + RiskAnalyserComponentsLicensesIncompatibleWithProjectLicenses riskAnalyser5 = new RiskAnalyserComponentsLicensesIncompatibleWithProjectLicenses(project); + RiskAnalyserLimitedSetOfPotentialComponentsLicenses riskAnalyser6 = new RiskAnalyserLimitedSetOfPotentialComponentsLicenses(project); + // Define a Risk analysis engine and add these risk analysers + LicenseRiskAnalysisEngine instance = new LicenseRiskAnalysisEngine(riskAnalyser1); + instance.addRiskAnalyser(riskAnalyser2); + instance.addRiskAnalyser(riskAnalyser3); + instance.addRiskAnalyser(riskAnalyser4); + instance.addRiskAnalyser(riskAnalyser5); + instance.addRiskAnalyser(riskAnalyser6); + assertEquals(SupportedLanguages.DEFAULT_LANGUAGE, instance.getLanguage()); + for (AbstractRiskAnalyser riskAnalyser : instance.getRisksAnalysers()) { + assertEquals(SupportedLanguages.DEFAULT_LANGUAGE, riskAnalyser.getLanguage()); + assertEquals(SupportedLanguages.DEFAULT_LANGUAGE, riskAnalyser.getProject().getLanguage()); + for (ComponentBinding componentBinding: riskAnalyser.getProject().getBillOfComponentBindings()) { + assertEquals(SupportedLanguages.DEFAULT_LANGUAGE, componentBinding.getLanguage()); + } + } + instance.setLanguage(new Locale("es")); + assertEquals(SupportedLanguages.SPANISH, instance.getLanguage()); + for (AbstractRiskAnalyser riskAnalyser : instance.getRisksAnalysers()) { + assertEquals(SupportedLanguages.SPANISH, riskAnalyser.getLanguage()); + assertEquals(SupportedLanguages.SPANISH, riskAnalyser.getProject().getLanguage()); + for (ComponentBinding componentBinding: riskAnalyser.getProject().getBillOfComponentBindings()) { + assertEquals(SupportedLanguages.SPANISH, componentBinding.getLanguage()); + } + } + } + + + /** + * Test of onLanguageChange method, of class + * LicenseRiskAnalysisEngine. + */ + @Test + void testSetLanguageWhenLanguageIsNull() { + System.out.println("setLanguage"); + URL projectURL = getClass().getResource(FilesPaths.PROJECT_EXAMPLE.getFilePath()); + Project project = new Project(projectURL); + RiskAnalyserHeterogeneousComponentsLicenses riskAnalyser = new RiskAnalyserHeterogeneousComponentsLicenses(project); + LicenseRiskAnalysisEngine instance = new LicenseRiskAnalysisEngine(riskAnalyser); + assertThrows(IllegalArgumentException.class, () -> { + // Should throw an exception because language is null + instance.setLanguage(null); + }); + } + /** + * Test of setDefaultLanguage method, of class LicenseRiskAnalysisEngine. + */ + @Test + void testSetDefaultLanguage() { + System.out.println("setDefaultLanguage"); + // 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); + RiskAnalyserObsoleteComponentsLicenses riskAnalyser2 = new RiskAnalyserObsoleteComponentsLicenses(project); + RiskAnalyserUnfashionableComponentsLicenses riskAnalyser3 = new RiskAnalyserUnfashionableComponentsLicenses(project); + RiskAnalyserScarcelySpreadComponentsLicenses riskAnalyser4 = new RiskAnalyserScarcelySpreadComponentsLicenses(project); + RiskAnalyserComponentsLicensesIncompatibleWithProjectLicenses riskAnalyser5 = new RiskAnalyserComponentsLicensesIncompatibleWithProjectLicenses(project); + RiskAnalyserLimitedSetOfPotentialComponentsLicenses riskAnalyser6 = new RiskAnalyserLimitedSetOfPotentialComponentsLicenses(project); + // Define a Risk analysis engine and add these risk analysers + LicenseRiskAnalysisEngine instance = new LicenseRiskAnalysisEngine(riskAnalyser1); + instance.addRiskAnalyser(riskAnalyser2); + instance.addRiskAnalyser(riskAnalyser3); + instance.addRiskAnalyser(riskAnalyser4); + instance.addRiskAnalyser(riskAnalyser5); + instance.addRiskAnalyser(riskAnalyser6); + assertEquals(SupportedLanguages.DEFAULT_LANGUAGE, instance.getLanguage()); + for (AbstractRiskAnalyser riskAnalyser : instance.getRisksAnalysers()) { + assertEquals(SupportedLanguages.DEFAULT_LANGUAGE, riskAnalyser.getLanguage()); + assertEquals(SupportedLanguages.DEFAULT_LANGUAGE, riskAnalyser.getProject().getLanguage()); + for (ComponentBinding componentBinding: riskAnalyser.getProject().getBillOfComponentBindings()) { + assertEquals(SupportedLanguages.DEFAULT_LANGUAGE, componentBinding.getLanguage()); + } + } + instance.setLanguage(new Locale("es")); + assertEquals(SupportedLanguages.SPANISH, instance.getLanguage()); + for (AbstractRiskAnalyser riskAnalyser : instance.getRisksAnalysers()) { + assertEquals(SupportedLanguages.SPANISH, riskAnalyser.getLanguage()); + assertEquals(SupportedLanguages.SPANISH, riskAnalyser.getProject().getLanguage()); + for (ComponentBinding componentBinding: riskAnalyser.getProject().getBillOfComponentBindings()) { + assertEquals(SupportedLanguages.SPANISH, componentBinding.getLanguage()); + } + } + instance.setDefaultLanguage(); + assertEquals(SupportedLanguages.DEFAULT_LANGUAGE, instance.getLanguage()); + for (AbstractRiskAnalyser riskAnalyser : instance.getRisksAnalysers()) { + assertEquals(SupportedLanguages.DEFAULT_LANGUAGE, riskAnalyser.getLanguage()); + assertEquals(SupportedLanguages.DEFAULT_LANGUAGE, riskAnalyser.getProject().getLanguage()); + for (ComponentBinding componentBinding: riskAnalyser.getProject().getBillOfComponentBindings()) { + assertEquals(SupportedLanguages.DEFAULT_LANGUAGE, componentBinding.getLanguage()); + } + } + } + + /** + * Test of fireLanguageChangeEvent method, of class LicenseRiskAnalysisEngine. + */ + @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); + + RiskAnalyserLimitedSetOfPotentialProjectLicenses riskAnalyser1 = new RiskAnalyserLimitedSetOfPotentialProjectLicenses(project); + RiskAnalyserObsoleteComponentsLicenses riskAnalyser2 = new RiskAnalyserObsoleteComponentsLicenses(project); + RiskAnalyserUnfashionableComponentsLicenses riskAnalyser3 = new RiskAnalyserUnfashionableComponentsLicenses(project); + RiskAnalyserScarcelySpreadComponentsLicenses riskAnalyser4 = new RiskAnalyserScarcelySpreadComponentsLicenses(project); + RiskAnalyserComponentsLicensesIncompatibleWithProjectLicenses riskAnalyser5 = new RiskAnalyserComponentsLicensesIncompatibleWithProjectLicenses(project); + RiskAnalyserLimitedSetOfPotentialComponentsLicenses riskAnalyser6 = new RiskAnalyserLimitedSetOfPotentialComponentsLicenses(project); + // Define a Risk analysis engine and add these risk analysers + LicenseRiskAnalysisEngine instance = new LicenseRiskAnalysisEngine(riskAnalyser1); + instance.addRiskAnalyser(riskAnalyser2); + instance.addRiskAnalyser(riskAnalyser3); + instance.addRiskAnalyser(riskAnalyser4); + instance.addRiskAnalyser(riskAnalyser5); + instance.addRiskAnalyser(riskAnalyser6); + assertEquals(SupportedLanguages.DEFAULT_LANGUAGE, instance.getLanguage()); + for (AbstractRiskAnalyser riskAnalyser : instance.getRisksAnalysers()) { + assertEquals(SupportedLanguages.DEFAULT_LANGUAGE, riskAnalyser.getLanguage()); + assertEquals(SupportedLanguages.DEFAULT_LANGUAGE, riskAnalyser.getProject().getLanguage()); + for (ComponentBinding componentBinding: riskAnalyser.getProject().getBillOfComponentBindings()) { + assertEquals(SupportedLanguages.DEFAULT_LANGUAGE, componentBinding.getLanguage()); + } + } + instance.setLanguage(new Locale("es")); + assertEquals(SupportedLanguages.SPANISH, instance.getLanguage()); + for (AbstractRiskAnalyser riskAnalyser : instance.getRisksAnalysers()) { + assertEquals(SupportedLanguages.SPANISH, riskAnalyser.getLanguage()); + assertEquals(SupportedLanguages.SPANISH, riskAnalyser.getProject().getLanguage()); + for (ComponentBinding componentBinding: riskAnalyser.getProject().getBillOfComponentBindings()) { + assertEquals(SupportedLanguages.SPANISH, componentBinding.getLanguage()); + } + } + instance.setDefaultLanguage(); + assertEquals(SupportedLanguages.DEFAULT_LANGUAGE, instance.getLanguage()); + for (AbstractRiskAnalyser riskAnalyser : instance.getRisksAnalysers()) { + assertEquals(SupportedLanguages.DEFAULT_LANGUAGE, riskAnalyser.getLanguage()); + assertEquals(SupportedLanguages.DEFAULT_LANGUAGE, riskAnalyser.getProject().getLanguage()); + for (ComponentBinding componentBinding: riskAnalyser.getProject().getBillOfComponentBindings()) { + assertEquals(SupportedLanguages.DEFAULT_LANGUAGE, componentBinding.getLanguage()); + } + } + } + +} diff --git a/src/test/java/com/manolodominguez/openlrae/analysis/riskanalysers/RiskAnalyserComponentsLicensesMisalignedFromProjectLicensesTest.java b/src/test/java/com/manolodominguez/openlrae/analysis/riskanalysers/RiskAnalyserComponentsLicensesMisalignedFromProjectLicensesTest.java new file mode 100644 index 0000000..61c467c --- /dev/null +++ b/src/test/java/com/manolodominguez/openlrae/analysis/riskanalysers/RiskAnalyserComponentsLicensesMisalignedFromProjectLicensesTest.java @@ -0,0 +1,170 @@ +/* + * 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.analysis.riskanalysers; + +import com.manolodominguez.openlrae.analysis.RiskAnalysisResult; +import com.manolodominguez.openlrae.arquitecture.Project; +import com.manolodominguez.openlrae.baseofknowledge.basevalues.SupportedRisks; +import com.manolodominguez.openlrae.i18n.LanguageChangeEvent; +import com.manolodominguez.openlrae.i18n.SupportedLanguages; +import com.manolodominguez.openlrae.resourceslocators.FilesPaths; +import java.net.URL; +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 RiskAnalyserComponentsLicensesMisalignedFromProjectLicensesTest { + + public RiskAnalyserComponentsLicensesMisalignedFromProjectLicensesTest() { + } + + @BeforeAll + public static void setUpClass() { + } + + @AfterAll + public static void tearDownClass() { + } + + @BeforeEach + void setUp() { + } + + @AfterEach + void tearDown() { + } + + /** + * Test of constructor, of class RiskAnalyserComponentLicensesMisalignedFromProjectLicenses. + */ + @Test + void testConstructorWhenProjectIsNull() { + System.out.println("constructor"); + Project project = null; + // Should throw an exception because project is null + assertThrows(IllegalArgumentException.class, () -> { + new RiskAnalyserComponentsLicensesMisalignedFromProjectLicenses(project); + }); + } + + /** + * Test of getHandledRiskType method, of class RiskAnalyserComponentLicensesMisalignedFromProjectLicenses. + */ + @Test + void testGetHandledRiskType() { + System.out.println("getHandledRiskType"); + // 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); + RiskAnalyserComponentsLicensesMisalignedFromProjectLicenses instance = new RiskAnalyserComponentsLicensesMisalignedFromProjectLicenses(project); + assertEquals(SupportedRisks.HAVING_COMPONENTS_LICENSES_MISALIGNED_FROM_PROJECT_LICENSES, instance.handledRiskType); + } + + /** + * Test of getRiskAnalisysResult method, of class RiskAnalyserComponentLicensesMisalignedFromProjectLicenses. + */ + @Test + void testGetRiskAnalisysResult() { + System.out.println("getRiskAnalisysResult"); + // 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); + RiskAnalyserComponentsLicensesMisalignedFromProjectLicenses instance = new RiskAnalyserComponentsLicensesMisalignedFromProjectLicenses(project); + // This calls runAnalyser method of instance + RiskAnalysisResult result1 = instance.getRiskAnalisysResult(); + RiskAnalysisResult result2 = instance.getRiskAnalisysResult(); + assertNotNull(result1); + assertNotNull(result2); + // Result should be different objects in diferent calls to the method + assertTrue(result1 != result2); // We're comparing references here + } + + /** + * Test of runAnalyser method, of class RiskAnalyserComponentLicensesMisalignedFromProjectLicenses. + */ + @Test + void testRunAnalyser() { + System.out.println("runAnalyser"); + // 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); + RiskAnalyserComponentsLicensesMisalignedFromProjectLicenses instance = new RiskAnalyserComponentsLicensesMisalignedFromProjectLicenses(project); + // This calls runAnalyser method of instance + RiskAnalysisResult result = instance.getRiskAnalisysResult(); + assertNotNull(result); + // We already know risk values for the selected project + assertNotNull(result.getGoodThings()); + assertTrue(!result.getGoodThings().isEmpty()); + assertNotNull(result.getRootCauses()); + assertTrue(!result.getRootCauses().isEmpty()); + assertNotNull(result.getWarnings()); + assertTrue(result.getWarnings().isEmpty()); + assertNotNull(result.getTips()); + assertTrue(!result.getTips().isEmpty()); + assertTrue(result.getRiskExposure() >= 0.0f); + assertTrue(result.getRiskExposure() <= 1.0f); + assertEquals(0.75f, result.getRiskExposure()); + assertTrue(result.getRiskImpact() >= 0.0f); + assertTrue(result.getRiskImpact() <= 1.0f); + assertEquals(0.8322f, result.getRiskImpact()); + assertTrue(result.getRiskValue() >= 0.0f); + assertTrue(result.getRiskValue() <= 1.0f); + assertEquals(0.6242f, result.getRiskValue()); + } + + /** + * Test of onLanguageChange method, of class RiskAnalyserComponentLicensesMisalignedFromProjectLicenses. + */ + @Test + void testOnLanguageChange() { + // 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); + RiskAnalyserComponentsLicensesMisalignedFromProjectLicenses instance = new RiskAnalyserComponentsLicensesMisalignedFromProjectLicenses(project); + instance.onLanguageChange(new LanguageChangeEvent(project, SupportedLanguages.SPANISH)); + assertEquals(SupportedLanguages.SPANISH, instance.getLanguage()); + } + + /** + * Test of onLanguageChange method, of class + * RiskAnalyserComponentLicensesMisalignedFromProjectLicenses. + */ + @Test + void testOnLanguageChangeWhenEventIsNull() { + System.out.println("setLanguage"); + URL projectURL = getClass().getResource(FilesPaths.PROJECT_EXAMPLE.getFilePath()); + Project project = new Project(projectURL); + RiskAnalyserComponentsLicensesMisalignedFromProjectLicenses instance = new RiskAnalyserComponentsLicensesMisalignedFromProjectLicenses(project); + assertThrows(IllegalArgumentException.class, () -> { + // Should throw an exception because event is null + instance.onLanguageChange(null); + }); + } +} diff --git a/src/test/java/com/manolodominguez/openlrae/analysis/riskanalysers/RiskAnalyserHavingComponentsLicensesIncompatibleWithProjectLicensesTest.java b/src/test/java/com/manolodominguez/openlrae/analysis/riskanalysers/RiskAnalyserHavingComponentsLicensesIncompatibleWithProjectLicensesTest.java new file mode 100644 index 0000000..96e9251 --- /dev/null +++ b/src/test/java/com/manolodominguez/openlrae/analysis/riskanalysers/RiskAnalyserHavingComponentsLicensesIncompatibleWithProjectLicensesTest.java @@ -0,0 +1,171 @@ +/* + * 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.analysis.riskanalysers; + +import com.manolodominguez.openlrae.analysis.RiskAnalysisResult; +import com.manolodominguez.openlrae.arquitecture.Project; +import com.manolodominguez.openlrae.baseofknowledge.basevalues.SupportedRisks; +import com.manolodominguez.openlrae.i18n.LanguageChangeEvent; +import com.manolodominguez.openlrae.i18n.SupportedLanguages; +import com.manolodominguez.openlrae.resourceslocators.FilesPaths; +import java.net.URL; +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 RiskAnalyserHavingComponentsLicensesIncompatibleWithProjectLicensesTest { + + public RiskAnalyserHavingComponentsLicensesIncompatibleWithProjectLicensesTest() { + } + + @BeforeAll + public static void setUpClass() { + } + + @AfterAll + public static void tearDownClass() { + } + + @BeforeEach + void setUp() { + } + + @AfterEach + void tearDown() { + } + + /** + * Test of constructor, of class RiskAnalyserLicensesOfComponentsIncompatibleWithProjectLicense. + */ + @Test + void testConstructorWhenProjectIsNull() { + System.out.println("constructor"); + Project project = null; + // Should throw an exception because project is null + assertThrows(IllegalArgumentException.class, () -> { + new RiskAnalyserComponentsLicensesIncompatibleWithProjectLicenses(project); + }); + } + + /** + * Test of getHandledRiskType method, of class RiskAnalyserLicensesOfComponentsIncompatibleWithProjectLicense. + */ + @Test + void testGetHandledRiskType() { + System.out.println("getHandledRiskType"); + // 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); + RiskAnalyserComponentsLicensesIncompatibleWithProjectLicenses instance = new RiskAnalyserComponentsLicensesIncompatibleWithProjectLicenses(project); + assertEquals(SupportedRisks.HAVING_COMPONENTS_LICENSES_INCOMPATIBLE_WITH_PROJECT_LICENSES, instance.handledRiskType); + } + + /** + * Test of getRiskAnalisysResult method, of class RiskAnalyserLicensesOfComponentsIncompatibleWithProjectLicense. + */ + @Test + void testGetRiskAnalisysResultr() { + System.out.println("getRiskAnalisysResult"); + // 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); + RiskAnalyserComponentsLicensesIncompatibleWithProjectLicenses instance = new RiskAnalyserComponentsLicensesIncompatibleWithProjectLicenses(project); + // This calls runAnalyser method of instance + RiskAnalysisResult result1 = instance.getRiskAnalisysResult(); + RiskAnalysisResult result2 = instance.getRiskAnalisysResult(); + assertNotNull(result1); + assertNotNull(result2); + // Result should be different objects in diferent calls to the method + assertTrue(result1 != result2); // We're comparing references here + } + + /** + * Test of runAnalyser method, of class RiskAnalyserLicensesOfComponentsIncompatibleWithProjectLicense. + */ + @Test + void testRunAnalyser() { + System.out.println("runAnalyser"); + // 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); + RiskAnalyserComponentsLicensesIncompatibleWithProjectLicenses instance = new RiskAnalyserComponentsLicensesIncompatibleWithProjectLicenses(project); + // This calls runAnalyser method of instance + RiskAnalysisResult result = instance.getRiskAnalisysResult(); + assertNotNull(result); + // We already know risk values for the selected project + assertNotNull(result.getGoodThings()); + assertTrue(!result.getGoodThings().isEmpty()); + assertNotNull(result.getRootCauses()); + assertTrue(!result.getRootCauses().isEmpty()); + assertNotNull(result.getWarnings()); + assertTrue(!result.getWarnings().isEmpty()); + assertNotNull(result.getTips()); + assertTrue(!result.getTips().isEmpty()); + assertTrue(result.getRiskExposure() >= 0.0f); + assertTrue(result.getRiskExposure() <= 1.0f); + assertEquals(0.2500f, result.getRiskExposure()); + assertTrue(result.getRiskImpact() >= 0.0f); + assertTrue(result.getRiskImpact() <= 1.0f); + assertEquals(0.2500f, result.getRiskImpact()); + assertTrue(result.getRiskValue() >= 0.0f); + assertTrue(result.getRiskValue() <= 1.0f); + assertEquals(0.0625f, result.getRiskValue()); + } + + /** + * Test of onLanguageChange method, of class RiskAnalyserLicensesOfComponentsIncompatibleWithProjectLicense. + */ + @Test + void testOnLanguageChange() { + // 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); + RiskAnalyserComponentsLicensesIncompatibleWithProjectLicenses instance = new RiskAnalyserComponentsLicensesIncompatibleWithProjectLicenses(project); + instance.onLanguageChange(new LanguageChangeEvent(project, SupportedLanguages.SPANISH)); + assertEquals(SupportedLanguages.SPANISH, instance.getLanguage()); + } + + /** + * Test of onLanguageChange method, of class + * RiskAnalyserLicensesOfComponentsIncompatibleWithProjectLicense. + */ + @Test + void testOnLanguageChangeWhenEventIsNull() { + System.out.println("setLanguage"); + URL projectURL = getClass().getResource(FilesPaths.PROJECT_EXAMPLE.getFilePath()); + Project project = new Project(projectURL); + RiskAnalyserComponentsLicensesIncompatibleWithProjectLicenses instance = new RiskAnalyserComponentsLicensesIncompatibleWithProjectLicenses(project); + assertThrows(IllegalArgumentException.class, () -> { + // Should throw an exception because event is null + instance.onLanguageChange(null); + }); + } + +} diff --git a/src/test/java/com/manolodominguez/openlrae/analysis/riskanalysers/RiskAnalyserHeterogeneousComponentsLicensesTest.java b/src/test/java/com/manolodominguez/openlrae/analysis/riskanalysers/RiskAnalyserHeterogeneousComponentsLicensesTest.java new file mode 100644 index 0000000..d9e2464 --- /dev/null +++ b/src/test/java/com/manolodominguez/openlrae/analysis/riskanalysers/RiskAnalyserHeterogeneousComponentsLicensesTest.java @@ -0,0 +1,176 @@ +/* + * 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.analysis.riskanalysers; + +import com.manolodominguez.openlrae.analysis.RiskAnalysisResult; +import com.manolodominguez.openlrae.arquitecture.Project; +import com.manolodominguez.openlrae.baseofknowledge.basevalues.SupportedRisks; +import com.manolodominguez.openlrae.i18n.LanguageChangeEvent; +import com.manolodominguez.openlrae.i18n.SupportedLanguages; +import com.manolodominguez.openlrae.resourceslocators.FilesPaths; +import java.net.URL; +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 RiskAnalyserHeterogeneousComponentsLicensesTest { + + public RiskAnalyserHeterogeneousComponentsLicensesTest() { + } + + @BeforeAll + public static void setUpClass() { + } + + @AfterAll + public static void tearDownClass() { + } + + @BeforeEach + void setUp() { + } + + @AfterEach + void tearDown() { + } + + /** + * Test of constructor, of class + * RiskAnalyserHeterogeneousComponentsLicenses. + */ + @Test + void testConstructorWhenProjectIsNull() { + System.out.println("constructor"); + Project project = null; + // Should throw an exception because project is null + assertThrows(IllegalArgumentException.class, () -> { + new RiskAnalyserHeterogeneousComponentsLicenses(project); + }); + } + + /** + * Test of getHandledRiskType method, of class + * RiskAnalyserHeterogeneousComponentsLicenses. + */ + @Test + void testGetHandledRiskType() { + System.out.println("getHandledRiskType"); + // 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); + RiskAnalyserHeterogeneousComponentsLicenses instance = new RiskAnalyserHeterogeneousComponentsLicenses(project); + assertEquals(SupportedRisks.HAVING_HETEROGENEOUS_COMPONENTS_LICENSES, instance.handledRiskType); + } + + /** + * Test of getRiskAnalisysResult method, of class + * RiskAnalyserHeterogeneousComponentsLicenses. + */ + @Test + void testGetRiskAnalisysResult() { + System.out.println("getRiskAnalisysResult"); + // 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); + RiskAnalyserHeterogeneousComponentsLicenses instance = new RiskAnalyserHeterogeneousComponentsLicenses(project); + // This calls runAnalyser method of instance + RiskAnalysisResult result1 = instance.getRiskAnalisysResult(); + RiskAnalysisResult result2 = instance.getRiskAnalisysResult(); + assertNotNull(result1); + assertNotNull(result2); + // Result should be different objects in diferent calls to the method + assertTrue(result1 != result2); // We're comparing references here + } + + /** + * Test of runAnalyser method, of class + * RiskAnalyserHeterogeneousComponentsLicenses. + */ + @Test + void testRunAnalyser() { + System.out.println("runAnalyser"); + // 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); + RiskAnalyserHeterogeneousComponentsLicenses instance = new RiskAnalyserHeterogeneousComponentsLicenses(project); + // This calls runAnalyser method of instance + RiskAnalysisResult result = instance.getRiskAnalisysResult(); + assertNotNull(result); + // We already know risk values for the selected project + assertNotNull(result.getGoodThings()); + assertTrue(!result.getGoodThings().isEmpty()); + assertNotNull(result.getRootCauses()); + assertTrue(!result.getRootCauses().isEmpty()); + assertNotNull(result.getWarnings()); + assertTrue(!result.getWarnings().isEmpty()); + assertNotNull(result.getTips()); + assertTrue(!result.getTips().isEmpty()); + assertTrue(result.getRiskExposure() >= 0.0f); + assertTrue(result.getRiskExposure() <= 1.0f); + assertEquals(0.75f, result.getRiskExposure()); + assertTrue(result.getRiskImpact() >= 0.0f); + assertTrue(result.getRiskImpact() <= 1.0f); + assertEquals(0.6678f, result.getRiskImpact()); + assertTrue(result.getRiskValue() >= 0.0f); + assertTrue(result.getRiskValue() <= 1.0f); + assertEquals(0.5008f, result.getRiskValue()); + } + + /** + * Test of onLanguageChange method, of class + * RiskAnalyserHeterogeneousComponentsLicenses. + */ + @Test + void testOnLanguageChange() { + // 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); + RiskAnalyserHeterogeneousComponentsLicenses instance = new RiskAnalyserHeterogeneousComponentsLicenses(project); + instance.onLanguageChange(new LanguageChangeEvent(project, SupportedLanguages.SPANISH)); + assertEquals(SupportedLanguages.SPANISH, instance.getLanguage()); + } + + /** + * Test of onLanguageChange method, of class + * RiskAnalyserHeterogeneousComponentsLicenses. + */ + @Test + void testOnLanguageChangeWhenEventIsNull() { + System.out.println("setLanguage"); + URL projectURL = getClass().getResource(FilesPaths.PROJECT_EXAMPLE.getFilePath()); + Project project = new Project(projectURL); + RiskAnalyserHeterogeneousComponentsLicenses instance = new RiskAnalyserHeterogeneousComponentsLicenses(project); + assertThrows(IllegalArgumentException.class, () -> { + // Should throw an exception because event is null + instance.onLanguageChange(null); + }); + } + +} diff --git a/src/test/java/com/manolodominguez/openlrae/analysis/riskanalysers/RiskAnalyserLimitedSetOfPotentialComponentsLicensesTest.java b/src/test/java/com/manolodominguez/openlrae/analysis/riskanalysers/RiskAnalyserLimitedSetOfPotentialComponentsLicensesTest.java new file mode 100644 index 0000000..533532a --- /dev/null +++ b/src/test/java/com/manolodominguez/openlrae/analysis/riskanalysers/RiskAnalyserLimitedSetOfPotentialComponentsLicensesTest.java @@ -0,0 +1,172 @@ +/* + * 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.analysis.riskanalysers; + +import com.manolodominguez.openlrae.analysis.RiskAnalysisResult; +import com.manolodominguez.openlrae.arquitecture.Project; +import com.manolodominguez.openlrae.baseofknowledge.basevalues.SupportedRisks; +import com.manolodominguez.openlrae.i18n.LanguageChangeEvent; +import com.manolodominguez.openlrae.i18n.SupportedLanguages; +import com.manolodominguez.openlrae.resourceslocators.FilesPaths; +import java.net.URL; +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 RiskAnalyserLimitedSetOfPotentialComponentsLicensesTest { + + public RiskAnalyserLimitedSetOfPotentialComponentsLicensesTest() { + } + + @BeforeAll + public static void setUpClass() { + } + + @AfterAll + public static void tearDownClass() { + } + + @BeforeEach + void setUp() { + } + + @AfterEach + void tearDown() { + } + + /** + * Test of constructor, of class RiskAnalyserLimitedSetOfPotentialComponentsLicenses. + */ + @Test + void testConstructorWhenProjectIsNull() { + System.out.println("constructor"); + Project project = null; + // Should throw an exception because project is null + assertThrows(IllegalArgumentException.class, () -> { + new RiskAnalyserLimitedSetOfPotentialComponentsLicenses(project); + }); + } + + /** + * Test of getHandledRiskType method, of class RiskAnalyserLimitedSetOfPotentialComponentsLicenses. + */ + @Test + void testGetHandledRiskType() { + System.out.println("getHandledRiskType"); + // 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); + RiskAnalyserLimitedSetOfPotentialComponentsLicenses instance = new RiskAnalyserLimitedSetOfPotentialComponentsLicenses(project); + assertEquals(SupportedRisks.HAVING_A_LIMITED_SET_OF_POTENTIAL_COMPONENTS_LICENSES, instance.handledRiskType); + } + + /** + * Test of getRiskAnalisysResult method, of class RiskAnalyserLimitedSetOfPotentialComponentsLicenses. + */ + @Test + void testGetRiskAnalisysResultr() { + System.out.println("getRiskAnalisysResult"); + // 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); + RiskAnalyserLimitedSetOfPotentialComponentsLicenses instance = new RiskAnalyserLimitedSetOfPotentialComponentsLicenses(project); + // This calls runAnalyser method of instance + RiskAnalysisResult result1 = instance.getRiskAnalisysResult(); + RiskAnalysisResult result2 = instance.getRiskAnalisysResult(); + assertNotNull(result1); + assertNotNull(result2); + // Result should be different objects in diferent calls to the method + assertTrue(result1 != result2); // We're comparing references here + } + + /** + * Test of runAnalyser method, of class RiskAnalyserLimitedSetOfPotentialComponentsLicenses. + */ + @Test + void testRunAnalyser() { + System.out.println("runAnalyser"); + // 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); + RiskAnalyserLimitedSetOfPotentialComponentsLicenses instance = new RiskAnalyserLimitedSetOfPotentialComponentsLicenses(project); + // This calls runAnalyser method of instance + RiskAnalysisResult result = instance.getRiskAnalisysResult(); + assertNotNull(result); + // We already know risk values for the selected project + assertNotNull(result.getGoodThings()); + assertTrue(!result.getGoodThings().isEmpty()); + assertNotNull(result.getRootCauses()); + assertTrue(!result.getRootCauses().isEmpty()); + assertNotNull(result.getWarnings()); + assertTrue(!result.getWarnings().isEmpty()); + assertNotNull(result.getTips()); + assertTrue(!result.getTips().isEmpty()); + assertTrue(result.getRiskExposure() >= 0.0f); + assertTrue(result.getRiskExposure() <= 1.0f); + assertEquals(0.4833f, result.getRiskExposure()); + assertTrue(result.getRiskImpact() >= 0.0f); + assertTrue(result.getRiskImpact() <= 1.0f); + assertEquals(0.4833f, result.getRiskImpact()); + assertTrue(result.getRiskValue() >= 0.0f); + assertTrue(result.getRiskValue() <= 1.0f); + assertEquals(0.2336f, result.getRiskValue()); + } + + /** + * Test of onLanguageChange method, of class RiskAnalyserLimitedSetOfPotentialComponentsLicenses. + */ + @Test + void testOnLanguageChange() { + // 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); + RiskAnalyserLimitedSetOfPotentialComponentsLicenses instance = new RiskAnalyserLimitedSetOfPotentialComponentsLicenses(project); + instance.onLanguageChange(new LanguageChangeEvent(project, SupportedLanguages.SPANISH)); + assertEquals(SupportedLanguages.SPANISH, instance.getLanguage()); + } + + + /** + * Test of onLanguageChange method, of class + * RiskAnalyserLimitedSetOfPotentialComponentsLicenses. + */ + @Test + void testOnLanguageChangeWhenEventIsNull() { + System.out.println("setLanguage"); + URL projectURL = getClass().getResource(FilesPaths.PROJECT_EXAMPLE.getFilePath()); + Project project = new Project(projectURL); + RiskAnalyserLimitedSetOfPotentialComponentsLicenses instance = new RiskAnalyserLimitedSetOfPotentialComponentsLicenses(project); + assertThrows(IllegalArgumentException.class, () -> { + // Should throw an exception because event is null + instance.onLanguageChange(null); + }); + } + +} diff --git a/src/test/java/com/manolodominguez/openlrae/analysis/riskanalysers/RiskAnalyserLimitedSetOfPotentialProjectLicensesTest.java b/src/test/java/com/manolodominguez/openlrae/analysis/riskanalysers/RiskAnalyserLimitedSetOfPotentialProjectLicensesTest.java new file mode 100644 index 0000000..aa975c0 --- /dev/null +++ b/src/test/java/com/manolodominguez/openlrae/analysis/riskanalysers/RiskAnalyserLimitedSetOfPotentialProjectLicensesTest.java @@ -0,0 +1,170 @@ +/* + * 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.analysis.riskanalysers; + +import com.manolodominguez.openlrae.analysis.RiskAnalysisResult; +import com.manolodominguez.openlrae.arquitecture.Project; +import com.manolodominguez.openlrae.baseofknowledge.basevalues.SupportedRisks; +import com.manolodominguez.openlrae.i18n.LanguageChangeEvent; +import com.manolodominguez.openlrae.i18n.SupportedLanguages; +import com.manolodominguez.openlrae.resourceslocators.FilesPaths; +import java.net.URL; +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 RiskAnalyserLimitedSetOfPotentialProjectLicensesTest { + + public RiskAnalyserLimitedSetOfPotentialProjectLicensesTest() { + } + + @BeforeAll + public static void setUpClass() { + } + + @AfterAll + public static void tearDownClass() { + } + + @BeforeEach + void setUp() { + } + + @AfterEach + void tearDown() { + } + + /** + * Test of constructor, of class RiskAnalyserLimitedSetOfPotentialProjectLicenses. + */ + @Test + void testConstructorWhenProjectIsNull() { + System.out.println("constructor"); + Project project = null; + // Should throw an exception because project is null + assertThrows(IllegalArgumentException.class, () -> { + new RiskAnalyserLimitedSetOfPotentialProjectLicenses(project); + }); + } + + /** + * Test of getHandledRiskType method, of class RiskAnalyserLimitedSetOfPotentialProjectLicenses. + */ + @Test + void testGetHandledRiskType() { + System.out.println("getHandledRiskType"); + // 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 instance = new RiskAnalyserLimitedSetOfPotentialProjectLicenses(project); + assertEquals(SupportedRisks.HAVING_A_LIMITED_SET_OF_POTENTIAL_PROJECT_LICENSES, instance.handledRiskType); + } + + /** + * Test of getRiskAnalisysResult method, of class RiskAnalyserLimitedSetOfPotentialProjectLicenses. + */ + @Test + void testGetRiskAnalisysResultr() { + System.out.println("getRiskAnalisysResult"); + // 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 instance = new RiskAnalyserLimitedSetOfPotentialProjectLicenses(project); + // This calls runAnalyser method of instance + RiskAnalysisResult result1 = instance.getRiskAnalisysResult(); + RiskAnalysisResult result2 = instance.getRiskAnalisysResult(); + assertNotNull(result1); + assertNotNull(result2); + // Result should be different objects in diferent calls to the method + assertTrue(result1 != result2); // We're comparing references here + } + + /** + * Test of runAnalyser method, of class RiskAnalyserLimitedSetOfPotentialProjectLicenses. + */ + @Test + void testRunAnalyser() { + System.out.println("runAnalyser"); + // 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 instance = new RiskAnalyserLimitedSetOfPotentialProjectLicenses(project); + // This calls runAnalyser method of instance + RiskAnalysisResult result = instance.getRiskAnalisysResult(); + assertNotNull(result); + // We already know risk values for the selected project + assertNotNull(result.getGoodThings()); + assertTrue(!result.getGoodThings().isEmpty()); + assertNotNull(result.getRootCauses()); + assertTrue(!result.getRootCauses().isEmpty()); + assertNotNull(result.getWarnings()); + assertTrue(result.getWarnings().isEmpty()); + assertNotNull(result.getTips()); + assertTrue(!result.getTips().isEmpty()); + assertTrue(result.getRiskExposure() >= 0.0f); + assertTrue(result.getRiskExposure() <= 1.0f); + assertEquals(0.9259f, result.getRiskExposure()); + assertTrue(result.getRiskImpact() >= 0.0f); + assertTrue(result.getRiskImpact() <= 1.0f); + assertEquals(0.3577f, result.getRiskImpact()); + assertTrue(result.getRiskValue() >= 0.0f); + assertTrue(result.getRiskValue() <= 1.0f); + assertEquals(0.3312f, result.getRiskValue()); + } + + /** + * Test of onLanguageChange method, of class RiskAnalyserLimitedSetOfPotentialProjectLicenses. + */ + @Test + void testOnLanguageChange() { + // 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 instance = new RiskAnalyserLimitedSetOfPotentialProjectLicenses(project); + instance.onLanguageChange(new LanguageChangeEvent(project, SupportedLanguages.SPANISH)); + assertEquals(SupportedLanguages.SPANISH, instance.getLanguage()); + } + + /** + * Test of onLanguageChange method, of class + * RiskAnalyserLimitedSetOfPotentialProjectLicenses. + */ + @Test + void testOnLanguageChangeWhenEventIsNull() { + System.out.println("setLanguage"); + URL projectURL = getClass().getResource(FilesPaths.PROJECT_EXAMPLE.getFilePath()); + Project project = new Project(projectURL); + RiskAnalyserLimitedSetOfPotentialProjectLicenses instance = new RiskAnalyserLimitedSetOfPotentialProjectLicenses(project); + assertThrows(IllegalArgumentException.class, () -> { + // Should throw an exception because event is null + instance.onLanguageChange(null); + }); + } +} diff --git a/src/test/java/com/manolodominguez/openlrae/analysis/riskanalysers/RiskAnalyserObsoleteComponentsLicensesTest.java b/src/test/java/com/manolodominguez/openlrae/analysis/riskanalysers/RiskAnalyserObsoleteComponentsLicensesTest.java new file mode 100644 index 0000000..9808ad2 --- /dev/null +++ b/src/test/java/com/manolodominguez/openlrae/analysis/riskanalysers/RiskAnalyserObsoleteComponentsLicensesTest.java @@ -0,0 +1,171 @@ +/* + * 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.analysis.riskanalysers; + +import com.manolodominguez.openlrae.analysis.RiskAnalysisResult; +import com.manolodominguez.openlrae.arquitecture.Project; +import com.manolodominguez.openlrae.baseofknowledge.basevalues.SupportedRisks; +import com.manolodominguez.openlrae.i18n.LanguageChangeEvent; +import com.manolodominguez.openlrae.i18n.SupportedLanguages; +import com.manolodominguez.openlrae.resourceslocators.FilesPaths; +import java.net.URL; +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 RiskAnalyserObsoleteComponentsLicensesTest { + + public RiskAnalyserObsoleteComponentsLicensesTest() { + } + + @BeforeAll + public static void setUpClass() { + } + + @AfterAll + public static void tearDownClass() { + } + + @BeforeEach + void setUp() { + } + + @AfterEach + void tearDown() { + } + + /** + * Test of constructor, of class RiskAnalyserLicensesOfComponentsTooObsolete. + */ + @Test + void testConstructorWhenProjectIsNull() { + System.out.println("constructor"); + Project project = null; + // Should throw an exception because project is null + assertThrows(IllegalArgumentException.class, () -> { + new RiskAnalyserObsoleteComponentsLicenses(project); + }); + } + + /** + * Test of getHandledRiskType method, of class RiskAnalyserLicensesOfComponentsTooObsolete. + */ + @Test + void testGetHandledRiskType() { + System.out.println("getHandledRiskType"); + // 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); + RiskAnalyserObsoleteComponentsLicenses instance = new RiskAnalyserObsoleteComponentsLicenses(project); + assertEquals(SupportedRisks.HAVING_OBSOLETE_COMPONENTS_LICENSES, instance.handledRiskType); + } + + /** + * Test of getRiskAnalisysResult method, of class RiskAnalyserLicensesOfComponentsTooObsolete. + */ + @Test + void testGetRiskAnalisysResultr() { + System.out.println("getRiskAnalisysResult"); + // 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); + RiskAnalyserObsoleteComponentsLicenses instance = new RiskAnalyserObsoleteComponentsLicenses(project); + // This calls runAnalyser method of instance + RiskAnalysisResult result1 = instance.getRiskAnalisysResult(); + RiskAnalysisResult result2 = instance.getRiskAnalisysResult(); + assertNotNull(result1); + assertNotNull(result2); + // Result should be different objects in diferent calls to the method + assertTrue(result1 != result2); // We're comparing references here + } + + /** + * Test of runAnalyser method, of class RiskAnalyserLicensesOfComponentsTooObsolete. + */ + @Test + void testRunAnalyser() { + System.out.println("runAnalyser"); + // 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); + RiskAnalyserObsoleteComponentsLicenses instance = new RiskAnalyserObsoleteComponentsLicenses(project); + // This calls runAnalyser method of instance + RiskAnalysisResult result = instance.getRiskAnalisysResult(); + assertNotNull(result); + // We already know risk values for the selected project + assertNotNull(result.getGoodThings()); + assertTrue(!result.getGoodThings().isEmpty()); + assertNotNull(result.getRootCauses()); + assertTrue(!result.getRootCauses().isEmpty()); + assertNotNull(result.getWarnings()); + assertTrue(result.getWarnings().isEmpty()); + assertNotNull(result.getTips()); + assertTrue(!result.getTips().isEmpty()); + assertTrue(result.getRiskExposure() >= 0.0f); + assertTrue(result.getRiskExposure() <= 1.0f); + assertEquals(0.2525f, result.getRiskExposure()); + assertTrue(result.getRiskImpact() >= 0.0f); + assertTrue(result.getRiskImpact() <= 1.0f); + assertEquals(0.2508f, result.getRiskImpact()); + assertTrue(result.getRiskValue() >= 0.0f); + assertTrue(result.getRiskValue() <= 1.0f); + assertEquals(0.0633f, result.getRiskValue()); + } + + /** + * Test of onLanguageChange method, of class RiskAnalyserLicensesOfComponentsTooObsolete. + */ + @Test + void testOnLanguageChange() { + // 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); + RiskAnalyserObsoleteComponentsLicenses instance = new RiskAnalyserObsoleteComponentsLicenses(project); + instance.onLanguageChange(new LanguageChangeEvent(project, SupportedLanguages.SPANISH)); + assertEquals(SupportedLanguages.SPANISH, instance.getLanguage()); + } + + + /** + * Test of onLanguageChange method, of class + * RiskAnalyserLicensesOfComponentsTooObsolete. + */ + @Test + void testOnLanguageChangeWhenEventIsNull() { + System.out.println("setLanguage"); + URL projectURL = getClass().getResource(FilesPaths.PROJECT_EXAMPLE.getFilePath()); + Project project = new Project(projectURL); + RiskAnalyserObsoleteComponentsLicenses instance = new RiskAnalyserObsoleteComponentsLicenses(project); + assertThrows(IllegalArgumentException.class, () -> { + // Should throw an exception because event is null + instance.onLanguageChange(null); + }); + } +} diff --git a/src/test/java/com/manolodominguez/openlrae/analysis/riskanalysers/RiskAnalyserObsoleteProjectLicensesTest.java b/src/test/java/com/manolodominguez/openlrae/analysis/riskanalysers/RiskAnalyserObsoleteProjectLicensesTest.java new file mode 100644 index 0000000..d615c44 --- /dev/null +++ b/src/test/java/com/manolodominguez/openlrae/analysis/riskanalysers/RiskAnalyserObsoleteProjectLicensesTest.java @@ -0,0 +1,170 @@ +/* + * 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.analysis.riskanalysers; + +import com.manolodominguez.openlrae.analysis.RiskAnalysisResult; +import com.manolodominguez.openlrae.arquitecture.Project; +import com.manolodominguez.openlrae.baseofknowledge.basevalues.SupportedRisks; +import com.manolodominguez.openlrae.i18n.LanguageChangeEvent; +import com.manolodominguez.openlrae.i18n.SupportedLanguages; +import com.manolodominguez.openlrae.resourceslocators.FilesPaths; +import java.net.URL; +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 RiskAnalyserObsoleteProjectLicensesTest { + + public RiskAnalyserObsoleteProjectLicensesTest() { + } + + @BeforeAll + public static void setUpClass() { + } + + @AfterAll + public static void tearDownClass() { + } + + @BeforeEach + void setUp() { + } + + @AfterEach + void tearDown() { + } + + /** + * Test of constructor, of class RiskAnalyserProjectLicensesTooObsolete. + */ + @Test + void testConstructorWhenProjectIsNull() { + System.out.println("constructor"); + Project project = null; + // Should throw an exception because project is null + assertThrows(IllegalArgumentException.class, () -> { + new RiskAnalyserObsoleteProjectLicenses(project); + }); + } + + /** + * Test of getHandledRiskType method, of class RiskAnalyserProjectLicensesTooObsolete. + */ + @Test + void testGetHandledRiskType() { + System.out.println("getHandledRiskType"); + // 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); + RiskAnalyserObsoleteProjectLicenses instance = new RiskAnalyserObsoleteProjectLicenses(project); + assertEquals(SupportedRisks.HAVING_OBSOLETE_PROJECT_LICENSES, instance.handledRiskType); + } + + /** + * Test of getRiskAnalisysResult method, of class RiskAnalyserProjectLicensesTooObsolete. + */ + @Test + void testGetRiskAnalisysResultr() { + System.out.println("getRiskAnalisysResult"); + // 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); + RiskAnalyserObsoleteProjectLicenses instance = new RiskAnalyserObsoleteProjectLicenses(project); + // This calls runAnalyser method of instance + RiskAnalysisResult result1 = instance.getRiskAnalisysResult(); + RiskAnalysisResult result2 = instance.getRiskAnalisysResult(); + assertNotNull(result1); + assertNotNull(result2); + // Result should be different objects in diferent calls to the method + assertTrue(result1 != result2); // We're comparing references here + } + + /** + * Test of runAnalyser method, of class RiskAnalyserProjectLicensesTooObsolete. + */ + @Test + void testRunAnalyser() { + System.out.println("runAnalyser"); + // 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); + RiskAnalyserObsoleteProjectLicenses instance = new RiskAnalyserObsoleteProjectLicenses(project); + // This calls runAnalyser method of instance + RiskAnalysisResult result = instance.getRiskAnalisysResult(); + assertNotNull(result); + // We already know risk values for the selected project + assertNotNull(result.getGoodThings()); + assertTrue(!result.getGoodThings().isEmpty()); + assertNotNull(result.getRootCauses()); + assertTrue(!result.getRootCauses().isEmpty()); + assertNotNull(result.getWarnings()); + assertTrue(result.getWarnings().isEmpty()); + assertNotNull(result.getTips()); + assertTrue(!result.getTips().isEmpty()); + assertTrue(result.getRiskExposure() >= 0.0f); + assertTrue(result.getRiskExposure() <= 1.0f); + assertEquals(0.5f, result.getRiskExposure()); + assertTrue(result.getRiskImpact() >= 0.0f); + assertTrue(result.getRiskImpact() <= 1.0f); + assertEquals(0.165f, result.getRiskImpact()); + assertTrue(result.getRiskValue() >= 0.0f); + assertTrue(result.getRiskValue() <= 1.0f); + assertEquals(0.0825f, result.getRiskValue()); + } + + /** + * Test of onLanguageChange method, of class RiskAnalyserProjectLicensesTooObsolete. + */ + @Test + void testOnLanguageChange() { + // 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); + RiskAnalyserObsoleteProjectLicenses instance = new RiskAnalyserObsoleteProjectLicenses(project); + instance.onLanguageChange(new LanguageChangeEvent(project, SupportedLanguages.SPANISH)); + assertEquals(SupportedLanguages.SPANISH, instance.getLanguage()); + } + + /** + * Test of onLanguageChange method, of class + * RiskAnalyserProjectLicensesTooObsolete. + */ + @Test + void testOnLanguageChangeWhenEventIsNull() { + System.out.println("setLanguage"); + URL projectURL = getClass().getResource(FilesPaths.PROJECT_EXAMPLE.getFilePath()); + Project project = new Project(projectURL); + RiskAnalyserObsoleteProjectLicenses instance = new RiskAnalyserObsoleteProjectLicenses(project); + assertThrows(IllegalArgumentException.class, () -> { + // Should throw an exception because event is null + instance.onLanguageChange(null); + }); + } +} diff --git a/src/test/java/com/manolodominguez/openlrae/analysis/riskanalysers/RiskAnalyserScarcelySpreadComponentsLicensesTest.java b/src/test/java/com/manolodominguez/openlrae/analysis/riskanalysers/RiskAnalyserScarcelySpreadComponentsLicensesTest.java new file mode 100644 index 0000000..a40b905 --- /dev/null +++ b/src/test/java/com/manolodominguez/openlrae/analysis/riskanalysers/RiskAnalyserScarcelySpreadComponentsLicensesTest.java @@ -0,0 +1,171 @@ +/* + * 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.analysis.riskanalysers; + +import com.manolodominguez.openlrae.analysis.RiskAnalysisResult; +import com.manolodominguez.openlrae.arquitecture.Project; +import com.manolodominguez.openlrae.baseofknowledge.basevalues.SupportedRisks; +import com.manolodominguez.openlrae.i18n.LanguageChangeEvent; +import com.manolodominguez.openlrae.i18n.SupportedLanguages; +import com.manolodominguez.openlrae.resourceslocators.FilesPaths; +import java.net.URL; +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 RiskAnalyserScarcelySpreadComponentsLicensesTest { + + public RiskAnalyserScarcelySpreadComponentsLicensesTest() { + } + + @BeforeAll + public static void setUpClass() { + } + + @AfterAll + public static void tearDownClass() { + } + + @BeforeEach + void setUp() { + } + + @AfterEach + void tearDown() { + } + + /** + * Test of constructor, of class RiskAnalyserScarceDeploymentOfLicensesOfComponents. + */ + @Test + void testConstructorWhenProjectIsNull() { + System.out.println("constructor"); + Project project = null; + // Should throw an exception because project is null + assertThrows(IllegalArgumentException.class, () -> { + new RiskAnalyserScarcelySpreadComponentsLicenses(project); + }); + } + + /** + * Test of getHandledRiskType method, of class RiskAnalyserScarceDeploymentOfLicensesOfComponents. + */ + @Test + void testGetHandledRiskType() { + System.out.println("getHandledRiskType"); + // 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); + RiskAnalyserScarcelySpreadComponentsLicenses instance = new RiskAnalyserScarcelySpreadComponentsLicenses(project); + assertEquals(SupportedRisks.HAVING_SCARCELY_SPREAD_COMPONENTS_LICENSES, instance.handledRiskType); + } + + /** + * Test of getRiskAnalisysResult method, of class RiskAnalyserScarceDeploymentOfLicensesOfComponents. + */ + @Test + void testGetRiskAnalisysResultr() { + System.out.println("getRiskAnalisysResult"); + // 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); + RiskAnalyserScarcelySpreadComponentsLicenses instance = new RiskAnalyserScarcelySpreadComponentsLicenses(project); + // This calls runAnalyser method of instance + RiskAnalysisResult result1 = instance.getRiskAnalisysResult(); + RiskAnalysisResult result2 = instance.getRiskAnalisysResult(); + assertNotNull(result1); + assertNotNull(result2); + // Result should be different objects in diferent calls to the method + assertTrue(result1 != result2); // We're comparing references here + } + + /** + * Test of runAnalyser method, of class RiskAnalyserScarceDeploymentOfLicensesOfComponents. + */ + @Test + void testRunAnalyser() { + System.out.println("runAnalyser"); + // 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); + RiskAnalyserScarcelySpreadComponentsLicenses instance = new RiskAnalyserScarcelySpreadComponentsLicenses(project); + // This calls runAnalyser method of instance + RiskAnalysisResult result = instance.getRiskAnalisysResult(); + assertNotNull(result); + // We already know risk values for the selected project + assertNotNull(result.getGoodThings()); + assertTrue(!result.getGoodThings().isEmpty()); + assertNotNull(result.getRootCauses()); + assertTrue(!result.getRootCauses().isEmpty()); + assertNotNull(result.getWarnings()); + assertTrue(result.getWarnings().isEmpty()); + assertNotNull(result.getTips()); + assertTrue(!result.getTips().isEmpty()); + assertTrue(result.getRiskExposure() >= 0.0f); + assertTrue(result.getRiskExposure() <= 1.0f); + assertEquals(0.5025f, result.getRiskExposure()); + assertTrue(result.getRiskImpact() >= 0.0f); + assertTrue(result.getRiskImpact() <= 1.0f); + assertEquals(0.5017f, result.getRiskImpact()); + assertTrue(result.getRiskValue() >= 0.0f); + assertTrue(result.getRiskValue() <= 1.0f); + assertEquals(0.2521f, result.getRiskValue()); + } + + /** + * Test of onLanguageChange method, of class RiskAnalyserScarceDeploymentOfLicensesOfComponents. + */ + @Test + void testOnLanguageChange() { + // 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); + RiskAnalyserScarcelySpreadComponentsLicenses instance = new RiskAnalyserScarcelySpreadComponentsLicenses(project); + instance.onLanguageChange(new LanguageChangeEvent(project, SupportedLanguages.SPANISH)); + assertEquals(SupportedLanguages.SPANISH, instance.getLanguage()); + } + + /** + * Test of onLanguageChange method, of class + * RiskAnalyserScarcelySpreadComponentsLicenses. + */ + @Test + void testOnLanguageChangeWhenEventIsNull() { + System.out.println("setLanguage"); + URL projectURL = getClass().getResource(FilesPaths.PROJECT_EXAMPLE.getFilePath()); + Project project = new Project(projectURL); + RiskAnalyserScarcelySpreadComponentsLicenses instance = new RiskAnalyserScarcelySpreadComponentsLicenses(project); + assertThrows(IllegalArgumentException.class, () -> { + // Should throw an exception because event is null + instance.onLanguageChange(null); + }); + } + +} diff --git a/src/test/java/com/manolodominguez/openlrae/analysis/riskanalysers/RiskAnalyserScarcelySpreadProjectLicensesTest.java b/src/test/java/com/manolodominguez/openlrae/analysis/riskanalysers/RiskAnalyserScarcelySpreadProjectLicensesTest.java new file mode 100644 index 0000000..6a2d761 --- /dev/null +++ b/src/test/java/com/manolodominguez/openlrae/analysis/riskanalysers/RiskAnalyserScarcelySpreadProjectLicensesTest.java @@ -0,0 +1,170 @@ +/* + * 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.analysis.riskanalysers; + +import com.manolodominguez.openlrae.analysis.RiskAnalysisResult; +import com.manolodominguez.openlrae.arquitecture.Project; +import com.manolodominguez.openlrae.baseofknowledge.basevalues.SupportedRisks; +import com.manolodominguez.openlrae.i18n.LanguageChangeEvent; +import com.manolodominguez.openlrae.i18n.SupportedLanguages; +import com.manolodominguez.openlrae.resourceslocators.FilesPaths; +import java.net.URL; +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 RiskAnalyserScarcelySpreadProjectLicensesTest { + + public RiskAnalyserScarcelySpreadProjectLicensesTest() { + } + + @BeforeAll + public static void setUpClass() { + } + + @AfterAll + public static void tearDownClass() { + } + + @BeforeEach + void setUp() { + } + + @AfterEach + void tearDown() { + } + + /** + * Test of constructor, of class RiskAnalyserScarcelySpreadProjectLicenses. + */ + @Test + void testConstructorWhenProjectIsNull() { + System.out.println("constructor"); + Project project = null; + // Should throw an exception because project is null + assertThrows(IllegalArgumentException.class, () -> { + new RiskAnalyserScarcelySpreadProjectLicenses(project); + }); + } + + /** + * Test of getHandledRiskType method, of class RiskAnalyserScarcelySpreadProjectLicenses. + */ + @Test + void testGetHandledRiskType() { + System.out.println("getHandledRiskType"); + // 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); + RiskAnalyserScarcelySpreadProjectLicenses instance = new RiskAnalyserScarcelySpreadProjectLicenses(project); + assertEquals(SupportedRisks.HAVING_SCARCELY_SPREAD_PROJECT_LICENSES, instance.handledRiskType); + } + + /** + * Test of getRiskAnalisysResult method, of class RiskAnalyserScarcelySpreadProjectLicenses. + */ + @Test + void testGetRiskAnalisysResult() { + System.out.println("getRiskAnalisysResult"); + // 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); + RiskAnalyserScarcelySpreadProjectLicenses instance = new RiskAnalyserScarcelySpreadProjectLicenses(project); + // This calls runAnalyser method of instance + RiskAnalysisResult result1 = instance.getRiskAnalisysResult(); + RiskAnalysisResult result2 = instance.getRiskAnalisysResult(); + assertNotNull(result1); + assertNotNull(result2); + // Result should be different objects in diferent calls to the method + assertTrue(result1 != result2); // We're comparing references here + } + + /** + * Test of runAnalyser method, of class RiskAnalyserScarcelySpreadProjectLicenses. + */ + @Test + void testRunAnalyser() { + System.out.println("runAnalyser"); + // 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); + RiskAnalyserScarcelySpreadProjectLicenses instance = new RiskAnalyserScarcelySpreadProjectLicenses(project); + // This calls runAnalyser method of instance + RiskAnalysisResult result = instance.getRiskAnalisysResult(); + assertNotNull(result); + // We already know risk values for the selected project + assertNotNull(result.getGoodThings()); + assertTrue(!result.getGoodThings().isEmpty()); + assertNotNull(result.getRootCauses()); + assertTrue(!result.getRootCauses().isEmpty()); + assertNotNull(result.getWarnings()); + assertTrue(result.getWarnings().isEmpty()); + assertNotNull(result.getTips()); + assertTrue(!result.getTips().isEmpty()); + assertTrue(result.getRiskExposure() >= 0.0f); + assertTrue(result.getRiskExposure() <= 1.0f); + assertEquals(0.5f, result.getRiskExposure()); + assertTrue(result.getRiskImpact() >= 0.0f); + assertTrue(result.getRiskImpact() <= 1.0f); + assertEquals(0.335f, result.getRiskImpact()); + assertTrue(result.getRiskValue() >= 0.0f); + assertTrue(result.getRiskValue() <= 1.0f); + assertEquals(0.1675f, result.getRiskValue()); + } + + /** + * Test of onLanguageChange method, of class RiskAnalyserScarcelySpreadProjectLicenses. + */ + @Test + void testOnLanguageChange() { + // 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); + RiskAnalyserScarcelySpreadProjectLicenses instance = new RiskAnalyserScarcelySpreadProjectLicenses(project); + instance.onLanguageChange(new LanguageChangeEvent(project, SupportedLanguages.SPANISH)); + assertEquals(SupportedLanguages.SPANISH, instance.getLanguage()); + } + + /** + * Test of onLanguageChange method, of class + * RiskAnalyserScarcelySpreadProjectLicenses. + */ + @Test + void testOnLanguageChangeWhenEventIsNull() { + System.out.println("setLanguage"); + URL projectURL = getClass().getResource(FilesPaths.PROJECT_EXAMPLE.getFilePath()); + Project project = new Project(projectURL); + RiskAnalyserScarcelySpreadProjectLicenses instance = new RiskAnalyserScarcelySpreadProjectLicenses(project); + assertThrows(IllegalArgumentException.class, () -> { + // Should throw an exception because event is null + instance.onLanguageChange(null); + }); + } +} diff --git a/src/test/java/com/manolodominguez/openlrae/analysis/riskanalysers/RiskAnalyserUnfashionableComponentsLicensesTest.java b/src/test/java/com/manolodominguez/openlrae/analysis/riskanalysers/RiskAnalyserUnfashionableComponentsLicensesTest.java new file mode 100644 index 0000000..ddbe496 --- /dev/null +++ b/src/test/java/com/manolodominguez/openlrae/analysis/riskanalysers/RiskAnalyserUnfashionableComponentsLicensesTest.java @@ -0,0 +1,171 @@ +/* + * 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.analysis.riskanalysers; + +import com.manolodominguez.openlrae.analysis.RiskAnalysisResult; +import com.manolodominguez.openlrae.arquitecture.Project; +import com.manolodominguez.openlrae.baseofknowledge.basevalues.SupportedRisks; +import com.manolodominguez.openlrae.i18n.LanguageChangeEvent; +import com.manolodominguez.openlrae.i18n.SupportedLanguages; +import com.manolodominguez.openlrae.resourceslocators.FilesPaths; +import java.net.URL; +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 RiskAnalyserUnfashionableComponentsLicensesTest { + + public RiskAnalyserUnfashionableComponentsLicensesTest() { + } + + @BeforeAll + public static void setUpClass() { + } + + @AfterAll + public static void tearDownClass() { + } + + @BeforeEach + void setUp() { + } + + @AfterEach + void tearDown() { + } + + /** + * Test of constructor, of class RiskAnalyserUnfashionableLicensesOfComponents. + */ + @Test + void testConstructorWhenProjectIsNull() { + System.out.println("constructor"); + Project project = null; + // Should throw an exception because project is null + assertThrows(IllegalArgumentException.class, () -> { + new RiskAnalyserUnfashionableComponentsLicenses(project); + }); + } + + /** + * Test of getHandledRiskType method, of class RiskAnalyserUnfashionableLicensesOfComponents. + */ + @Test + void testGetHandledRiskType() { + System.out.println("getHandledRiskType"); + // 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); + RiskAnalyserUnfashionableComponentsLicenses instance = new RiskAnalyserUnfashionableComponentsLicenses(project); + assertEquals(SupportedRisks.HAVING_UNFASHIONABLE_COMPONENTS_LICENSES, instance.handledRiskType); + } + + /** + * Test of getRiskAnalisysResult method, of class RiskAnalyserUnfashionableLicensesOfComponents. + */ + @Test + void testGetRiskAnalisysResultr() { + System.out.println("getRiskAnalisysResult"); + // 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); + RiskAnalyserUnfashionableComponentsLicenses instance = new RiskAnalyserUnfashionableComponentsLicenses(project); + // This calls runAnalyser method of instance + RiskAnalysisResult result1 = instance.getRiskAnalisysResult(); + RiskAnalysisResult result2 = instance.getRiskAnalisysResult(); + assertNotNull(result1); + assertNotNull(result2); + // Result should be different objects in diferent calls to the method + assertTrue(result1 != result2); // We're comparing references here + } + + /** + * Test of runAnalyser method, of class RiskAnalyserUnfashionableLicensesOfComponents. + */ + @Test + void testRunAnalyser() { + System.out.println("runAnalyser"); + // 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); + RiskAnalyserUnfashionableComponentsLicenses instance = new RiskAnalyserUnfashionableComponentsLicenses(project); + // This calls runAnalyser method of instance + RiskAnalysisResult result = instance.getRiskAnalisysResult(); + assertNotNull(result); + // We already know risk values for the selected project + assertNotNull(result.getGoodThings()); + assertTrue(!result.getGoodThings().isEmpty()); + assertNotNull(result.getRootCauses()); + assertTrue(!result.getRootCauses().isEmpty()); + assertNotNull(result.getWarnings()); + assertTrue(result.getWarnings().isEmpty()); + assertNotNull(result.getTips()); + assertTrue(!result.getTips().isEmpty()); + assertTrue(result.getRiskExposure() >= 0.0f); + assertTrue(result.getRiskExposure() <= 1.0f); + assertEquals(0.5025f, result.getRiskExposure()); + assertTrue(result.getRiskImpact() >= 0.0f); + assertTrue(result.getRiskImpact() <= 1.0f); + assertEquals(0.4200f, result.getRiskImpact()); + assertTrue(result.getRiskValue() >= 0.0f); + assertTrue(result.getRiskValue() <= 1.0f); + assertEquals(0.2111f, result.getRiskValue()); + } + + /** + * Test of onLanguageChange method, of class RiskAnalyserUnfashionableLicensesOfComponents. + */ + @Test + void testOnLanguageChange() { + // 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); + RiskAnalyserUnfashionableComponentsLicenses instance = new RiskAnalyserUnfashionableComponentsLicenses(project); + instance.onLanguageChange(new LanguageChangeEvent(project, SupportedLanguages.SPANISH)); + assertEquals(SupportedLanguages.SPANISH, instance.getLanguage()); + } + + /** + * Test of onLanguageChange method, of class + * RiskAnalyserUnfashionableLicensesOfComponents. + */ + @Test + void testOnLanguageChangeWhenEventIsNull() { + System.out.println("setLanguage"); + URL projectURL = getClass().getResource(FilesPaths.PROJECT_EXAMPLE.getFilePath()); + Project project = new Project(projectURL); + RiskAnalyserUnfashionableComponentsLicenses instance = new RiskAnalyserUnfashionableComponentsLicenses(project); + assertThrows(IllegalArgumentException.class, () -> { + // Should throw an exception because event is null + instance.onLanguageChange(null); + }); + } + +} diff --git a/src/test/java/com/manolodominguez/openlrae/analysis/riskanalysers/RiskAnalyserUnfashionableProjectLicensesTest.java b/src/test/java/com/manolodominguez/openlrae/analysis/riskanalysers/RiskAnalyserUnfashionableProjectLicensesTest.java new file mode 100644 index 0000000..fbea2d3 --- /dev/null +++ b/src/test/java/com/manolodominguez/openlrae/analysis/riskanalysers/RiskAnalyserUnfashionableProjectLicensesTest.java @@ -0,0 +1,171 @@ +/* + * 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.analysis.riskanalysers; + +import com.manolodominguez.openlrae.analysis.RiskAnalysisResult; +import com.manolodominguez.openlrae.arquitecture.Project; +import com.manolodominguez.openlrae.baseofknowledge.basevalues.SupportedRisks; +import com.manolodominguez.openlrae.i18n.LanguageChangeEvent; +import com.manolodominguez.openlrae.i18n.SupportedLanguages; +import com.manolodominguez.openlrae.resourceslocators.FilesPaths; +import java.net.URL; +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 RiskAnalyserUnfashionableProjectLicensesTest { + + public RiskAnalyserUnfashionableProjectLicensesTest() { + } + + @BeforeAll + public static void setUpClass() { + } + + @AfterAll + public static void tearDownClass() { + } + + @BeforeEach + void setUp() { + } + + @AfterEach + void tearDown() { + } + + /** + * Test of constructor, of class RiskAnalyserUnfashionableProjectLicenses. + */ + @Test + void testConstructorWhenProjectIsNull() { + System.out.println("constructor"); + Project project = null; + // Should throw an exception because project is null + assertThrows(IllegalArgumentException.class, () -> { + new RiskAnalyserUnfashionableProjectLicenses(project); + }); + } + + /** + * Test of getHandledRiskType method, of class RiskAnalyserUnfashionableProjectLicenses. + */ + @Test + void testGetHandledRiskType() { + System.out.println("getHandledRiskType"); + // 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); + RiskAnalyserUnfashionableProjectLicenses instance = new RiskAnalyserUnfashionableProjectLicenses(project); + assertEquals(SupportedRisks.HAVING_UNFASHIONABLE_PROJECT_LICENSES, instance.handledRiskType); + } + + /** + * Test of getRiskAnalisysResult method, of class RiskAnalyserUnfashionableProjectLicenses. + */ + @Test + void testGetRiskAnalisysResult() { + System.out.println("getRiskAnalisysResult"); + // 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); + RiskAnalyserUnfashionableProjectLicenses instance = new RiskAnalyserUnfashionableProjectLicenses(project); + // This calls runAnalyser method of instance + RiskAnalysisResult result1 = instance.getRiskAnalisysResult(); + RiskAnalysisResult result2 = instance.getRiskAnalisysResult(); + assertNotNull(result1); + assertNotNull(result2); + // Result should be different objects in diferent calls to the method + assertTrue(result1 != result2); // We're comparing references here + } + + /** + * Test of runAnalyser method, of class RiskAnalyserUnfashionableProjectLicenses. + */ + @Test + void testRunAnalyser() { + System.out.println("runAnalyser"); + // 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); + RiskAnalyserUnfashionableProjectLicenses instance = new RiskAnalyserUnfashionableProjectLicenses(project); + // This calls runAnalyser method of instance + RiskAnalysisResult result = instance.getRiskAnalisysResult(); + assertNotNull(result); + // We already know risk values for the selected project + assertNotNull(result.getGoodThings()); + assertTrue(!result.getGoodThings().isEmpty()); + assertNotNull(result.getRootCauses()); + assertTrue(!result.getRootCauses().isEmpty()); + assertNotNull(result.getWarnings()); + assertTrue(result.getWarnings().isEmpty()); + assertNotNull(result.getTips()); + assertTrue(!result.getTips().isEmpty()); + assertTrue(result.getRiskExposure() >= 0.0f); + assertTrue(result.getRiskExposure() <= 1.0f); + assertEquals(0.5f, result.getRiskExposure()); + assertTrue(result.getRiskImpact() >= 0.0f); + assertTrue(result.getRiskImpact() <= 1.0f); + assertEquals(0.5f, result.getRiskImpact()); + assertTrue(result.getRiskValue() >= 0.0f); + assertTrue(result.getRiskValue() <= 1.0f); + assertEquals(0.25f, result.getRiskValue()); + } + + /** + * Test of onLanguageChange method, of class RiskAnalyserUnfashionableProjectLicenses. + */ + @Test + void testOnLanguageChange() { + // 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); + RiskAnalyserUnfashionableProjectLicenses instance = new RiskAnalyserUnfashionableProjectLicenses(project); + instance.onLanguageChange(new LanguageChangeEvent(project, SupportedLanguages.SPANISH)); + assertEquals(SupportedLanguages.SPANISH, instance.getLanguage()); + } + + /** + * Test of onLanguageChange method, of class + * RiskAnalyserUnfashionableProjectLicenses. + */ + @Test + void testOnLanguageChangeWhenEventIsNull() { + System.out.println("setLanguage"); + URL projectURL = getClass().getResource(FilesPaths.PROJECT_EXAMPLE.getFilePath()); + Project project = new Project(projectURL); + RiskAnalyserUnfashionableProjectLicenses instance = new RiskAnalyserUnfashionableProjectLicenses(project); + assertThrows(IllegalArgumentException.class, () -> { + // Should throw an exception because event is null + instance.onLanguageChange(null); + }); + } + +} diff --git a/src/test/java/com/manolodominguez/openlrae/reporting/ReportsFactoryTest.java b/src/test/java/com/manolodominguez/openlrae/reporting/ReportsFactoryTest.java new file mode 100644 index 0000000..c419a03 --- /dev/null +++ b/src/test/java/com/manolodominguez/openlrae/reporting/ReportsFactoryTest.java @@ -0,0 +1,201 @@ +/* + * 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.reporting; + +import com.manolodominguez.openlrae.analysis.LicenseRiskAnalysisEngine; +import com.manolodominguez.openlrae.analysis.RiskAnalysisResult; +import com.manolodominguez.openlrae.analysis.riskanalysers.RiskAnalyserComponentsLicensesIncompatibleWithProjectLicenses; +import com.manolodominguez.openlrae.analysis.riskanalysers.RiskAnalyserObsoleteComponentsLicenses; +import com.manolodominguez.openlrae.analysis.riskanalysers.RiskAnalyserLimitedSetOfPotentialComponentsLicenses; +import com.manolodominguez.openlrae.analysis.riskanalysers.RiskAnalyserLimitedSetOfPotentialProjectLicenses; +import com.manolodominguez.openlrae.analysis.riskanalysers.RiskAnalyserScarcelySpreadComponentsLicenses; +import com.manolodominguez.openlrae.analysis.riskanalysers.RiskAnalyserUnfashionableComponentsLicenses; +import com.manolodominguez.openlrae.arquitecture.Project; +import com.manolodominguez.openlrae.resourceslocators.FilesPaths; +import java.net.URL; +import org.everit.json.schema.Schema; +import org.everit.json.schema.ValidationException; +import org.everit.json.schema.loader.SchemaLoader; +import org.json.JSONArray; +import org.json.JSONObject; +import org.json.JSONTokener; +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 ReportsFactoryTest { + + public ReportsFactoryTest() { + } + + @BeforeAll + public static void setUpClass() { + } + + @AfterAll + public static void tearDownClass() { + } + + @BeforeEach + void setUp() { + } + + @AfterEach + void tearDown() { + } + + /** + * Test of getInstance method, of class ReportsFactory. + */ + @Test + void testGetInstance_SupportedVerbosityLevel_WhenVerbosityIsNull() { + System.out.println("getInstance"); + SupportedVerbosityLevel verbosity = null; + assertThrows(IllegalArgumentException.class, () -> { + // Should throw an exception because verbosity is null + ReportsFactory.getInstance(verbosity); + }); + } + + /** + * Test of getReportAsBeautifiedJSONString method, of class ReportsFactory. + */ + @Test + void testGetReportAsBeautifiedJSONString() { + System.out.println("getReportAsBeautifiedJSONString"); + // 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); + + // Define desired risk analysers we want to use for this project + RiskAnalyserLimitedSetOfPotentialProjectLicenses riskAnalyser1 = new RiskAnalyserLimitedSetOfPotentialProjectLicenses(project); + RiskAnalyserObsoleteComponentsLicenses riskAnalyser2 = new RiskAnalyserObsoleteComponentsLicenses(project); + RiskAnalyserUnfashionableComponentsLicenses riskAnalyser3 = new RiskAnalyserUnfashionableComponentsLicenses(project); + RiskAnalyserScarcelySpreadComponentsLicenses riskAnalyser4 = new RiskAnalyserScarcelySpreadComponentsLicenses(project); + RiskAnalyserComponentsLicensesIncompatibleWithProjectLicenses riskAnalyser5 = new RiskAnalyserComponentsLicensesIncompatibleWithProjectLicenses(project); + RiskAnalyserLimitedSetOfPotentialComponentsLicenses riskAnalyser6 = new RiskAnalyserLimitedSetOfPotentialComponentsLicenses(project); + // Define a Risk analysis engine and add these risk analysers + LicenseRiskAnalysisEngine riskAnalysisEngine = new LicenseRiskAnalysisEngine(riskAnalyser1); + riskAnalysisEngine.addRiskAnalyser(riskAnalyser2); + riskAnalysisEngine.addRiskAnalyser(riskAnalyser3); + riskAnalysisEngine.addRiskAnalyser(riskAnalyser4); + riskAnalysisEngine.addRiskAnalyser(riskAnalyser5); + riskAnalysisEngine.addRiskAnalyser(riskAnalyser6); + + // Run the license risks analysis and collect results + RiskAnalysisResult[] resultSet = riskAnalysisEngine.analyse(); + String reportAsBeautifiedJSONString = ReportsFactory.getInstance().getReportAsBeautifiedJSONString(project, resultSet); + boolean isValidReport = true; + try { + JSONObject rawSchema = new JSONObject(new JSONTokener(getClass().getResourceAsStream(FilesPaths.REPORT_SCHEMA.getFilePath()))); + Schema sch = SchemaLoader.load(rawSchema); + sch.validate(new JSONArray(reportAsBeautifiedJSONString)); // throws a ValidationException if this object is invalid + isValidReport = true; + } + catch (ValidationException ex) { + isValidReport = false; + } + assertTrue(isValidReport); + } + + /** + * Test of getReportAsJSON method, of class ReportsFactory. + */ + @Test + void testGetReportAsJSON() { + System.out.println("getReportAsJSON"); + // 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); + + // Define desired risk analysers we want to use for this project + RiskAnalyserLimitedSetOfPotentialProjectLicenses riskAnalyser1 = new RiskAnalyserLimitedSetOfPotentialProjectLicenses(project); + RiskAnalyserObsoleteComponentsLicenses riskAnalyser2 = new RiskAnalyserObsoleteComponentsLicenses(project); + RiskAnalyserUnfashionableComponentsLicenses riskAnalyser3 = new RiskAnalyserUnfashionableComponentsLicenses(project); + RiskAnalyserScarcelySpreadComponentsLicenses riskAnalyser4 = new RiskAnalyserScarcelySpreadComponentsLicenses(project); + RiskAnalyserComponentsLicensesIncompatibleWithProjectLicenses riskAnalyser5 = new RiskAnalyserComponentsLicensesIncompatibleWithProjectLicenses(project); + RiskAnalyserLimitedSetOfPotentialComponentsLicenses riskAnalyser6 = new RiskAnalyserLimitedSetOfPotentialComponentsLicenses(project); + // Define a Risk analysis engine and add these risk analysers + LicenseRiskAnalysisEngine riskAnalysisEngine = new LicenseRiskAnalysisEngine(riskAnalyser1); + riskAnalysisEngine.addRiskAnalyser(riskAnalyser2); + riskAnalysisEngine.addRiskAnalyser(riskAnalyser3); + riskAnalysisEngine.addRiskAnalyser(riskAnalyser4); + riskAnalysisEngine.addRiskAnalyser(riskAnalyser5); + riskAnalysisEngine.addRiskAnalyser(riskAnalyser6); + + // Run the license risks analysis and collect results + RiskAnalysisResult[] resultSet = riskAnalysisEngine.analyse(); + JSONArray reportAsJSONArray = ReportsFactory.getInstance().getReportAsJSONArray(project, resultSet); + boolean isValidReport = true; + try { + JSONObject rawSchema = new JSONObject(new JSONTokener(getClass().getResourceAsStream(FilesPaths.REPORT_SCHEMA.getFilePath()))); + Schema sch = SchemaLoader.load(rawSchema); + sch.validate(reportAsJSONArray); // throws a ValidationException if this object is invalid + isValidReport = true; + } + catch (ValidationException ex) { + isValidReport = false; + } + assertTrue(isValidReport); + } + + /** + * Test of getReportAsPlainText method, of class ReportsFactory. + */ + @Test + void testGetReportAsPlainText() { + System.out.println("getReportAsPlainText"); + // 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); + + // Define desired risk analysers we want to use for this project + RiskAnalyserLimitedSetOfPotentialProjectLicenses riskAnalyser1 = new RiskAnalyserLimitedSetOfPotentialProjectLicenses(project); + RiskAnalyserObsoleteComponentsLicenses riskAnalyser2 = new RiskAnalyserObsoleteComponentsLicenses(project); + RiskAnalyserUnfashionableComponentsLicenses riskAnalyser3 = new RiskAnalyserUnfashionableComponentsLicenses(project); + RiskAnalyserScarcelySpreadComponentsLicenses riskAnalyser4 = new RiskAnalyserScarcelySpreadComponentsLicenses(project); + RiskAnalyserComponentsLicensesIncompatibleWithProjectLicenses riskAnalyser5 = new RiskAnalyserComponentsLicensesIncompatibleWithProjectLicenses(project); + RiskAnalyserLimitedSetOfPotentialComponentsLicenses riskAnalyser6 = new RiskAnalyserLimitedSetOfPotentialComponentsLicenses(project); + // Define a Risk analysis engine and add these risk analysers + LicenseRiskAnalysisEngine riskAnalysisEngine = new LicenseRiskAnalysisEngine(riskAnalyser1); + riskAnalysisEngine.addRiskAnalyser(riskAnalyser2); + riskAnalysisEngine.addRiskAnalyser(riskAnalyser3); + riskAnalysisEngine.addRiskAnalyser(riskAnalyser4); + riskAnalysisEngine.addRiskAnalyser(riskAnalyser5); + riskAnalysisEngine.addRiskAnalyser(riskAnalyser6); + + // Run the license risks analysis and collect results + RiskAnalysisResult[] resultSet = riskAnalysisEngine.analyse(); + String reportAsPlainText = ReportsFactory.getInstance().getReportAsPlainText(project, resultSet); + assertNotNull(reportAsPlainText); + assertFalse(reportAsPlainText.isEmpty()); + } + +}