Skip to content

Commit

Permalink
mjson seems to be abandoned, so it has been replaced by
Browse files Browse the repository at this point in the history
everit-json-schema
  • Loading branch information
Manuel Domínguez Dorado committed Feb 13, 2022
1 parent 13e2478 commit f24dfd6
Show file tree
Hide file tree
Showing 13 changed files with 2,427 additions and 0 deletions.

Large diffs are not rendered by default.

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);
});
}
}
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);
});
}

}
Loading

0 comments on commit f24dfd6

Please sign in to comment.