-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
mjson seems to be abandoned, so it has been replaced by
everit-json-schema
- Loading branch information
Manuel Domínguez Dorado
committed
Feb 13, 2022
1 parent
13e2478
commit f24dfd6
Showing
13 changed files
with
2,427 additions
and
0 deletions.
There are no files selected for viewing
343 changes: 343 additions & 0 deletions
343
src/test/java/com/manolodominguez/openlrae/analysis/LicenseRiskAnalysisEngineTest.java
Large diffs are not rendered by default.
Oops, something went wrong.
170 changes: 170 additions & 0 deletions
170
...alysis/riskanalysers/RiskAnalyserComponentsLicensesMisalignedFromProjectLicensesTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 - [email protected]. | ||
* | ||
* 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); | ||
}); | ||
} | ||
} |
171 changes: 171 additions & 0 deletions
171
...iskanalysers/RiskAnalyserHavingComponentsLicensesIncompatibleWithProjectLicensesTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 - [email protected]. | ||
* | ||
* 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); | ||
}); | ||
} | ||
|
||
} |
Oops, something went wrong.