From 1b16c275c293aeb0b6aeb7e21b9c6e7cd64279cc Mon Sep 17 00:00:00 2001 From: Topin2001 Date: Mon, 3 Jun 2024 13:25:23 +0200 Subject: [PATCH] Implement ReportTest for SQ compliance --- .../cnes/sonar/report/model/ReportTest.java | 119 ++++++++++++++++++ 1 file changed, 119 insertions(+) create mode 100644 src/test/ut/java/fr/cnes/sonar/report/model/ReportTest.java diff --git a/src/test/ut/java/fr/cnes/sonar/report/model/ReportTest.java b/src/test/ut/java/fr/cnes/sonar/report/model/ReportTest.java new file mode 100644 index 00000000..fed5db00 --- /dev/null +++ b/src/test/ut/java/fr/cnes/sonar/report/model/ReportTest.java @@ -0,0 +1,119 @@ +package fr.cnes.sonar.report.model; + +import fr.cnes.sonar.report.CommonTest; + +import org.junit.Assert; +import org.junit.Test; + +import java.util.*; + +public class ReportTest extends CommonTest{ + + @Test + public void getComplianceTest() { + Report report = new Report(); + Assert.assertEquals("0.0", report.getCompliance()); + } + + @Test + public void MetricsStatsTest() { + Report report = new Report(); + Map metrics = new HashMap<>(); + metrics.put("metric1", 1.0); + metrics.put("metric2", 2.0); + report.setMetricsStats(metrics); + Assert.assertEquals((Double) 1.0, report.getMetricsStats().get("metric1")); + Assert.assertEquals((Double) 2.0, report.getMetricsStats().get("metric2")); + } + + @Test + public void ComponentsTest() { + Report report = new Report(); + List> components = new ArrayList<>(); + Map component = new HashMap<>(); + component.put("id", "1"); + component.put("name", "test"); + component.put("path", "path/to/test"); + components.add(component); + report.setComponents(components); + Assert.assertEquals("1", report.getComponents().get(0).get("id")); + Assert.assertEquals("test", report.getComponents().get(0).get("name")); + Assert.assertEquals("path/to/test", report.getComponents().get(0).get("path")); + } + + @Test + public void IssuesTest() { + Report report = new Report(); + List issues = new ArrayList<>(); + Issue issue = new Issue(); + issue.setKey("1"); + issue.setRule("rule"); + issue.setSeverity("severity"); + issues.add(issue); + report.setIssues(issues); + Assert.assertEquals("1", report.getIssues().getIssuesList().get(0).getKey()); + Assert.assertEquals("rule", report.getIssues().getIssuesList().get(0).getRule()); + Assert.assertEquals("severity", report.getIssues().getIssuesList().get(0).getSeverity()); + } + + @Test + public void toReviewSecurityHotspotsTest(){ + Report report = new Report(); + List securityHotspots = new ArrayList<>(); + SecurityHotspot securityHotspot = new SecurityHotspot(); + securityHotspot.setKey("1"); + securityHotspot.setRule("rule"); + securityHotspot.setSeverity("severity"); + securityHotspots.add(securityHotspot); + report.setToReviewSecurityHotspots(securityHotspots); + Assert.assertEquals("1", report.getToReviewSecurityHotspots().get(0).getKey()); + Assert.assertEquals("rule", report.getToReviewSecurityHotspots().get(0).getRule()); + Assert.assertEquals("severity", report.getToReviewSecurityHotspots().get(0).getSeverity()); + } + + @Test + public void reviewedSecurityHotspotsTest(){ + Report report = new Report(); + List securityHotspots = new ArrayList<>(); + SecurityHotspot securityHotspot = new SecurityHotspot(); + securityHotspot.setKey("1"); + securityHotspot.setRule("rule"); + securityHotspot.setSeverity("severity"); + securityHotspots.add(securityHotspot); + report.setReviewedSecurityHotspots(securityHotspots); + Assert.assertEquals("1", report.getReviewedSecurityHotspots().get(0).getKey()); + Assert.assertEquals("rule", report.getReviewedSecurityHotspots().get(0).getRule()); + Assert.assertEquals("severity", report.getReviewedSecurityHotspots().get(0).getSeverity()); + } + + @Test + public void projetNameTest() { + Report report = new Report(); + report.setProjectName("projectName"); + Assert.assertEquals("projectName", report.getProjectName()); + } + + @Test + public void projectBranchTest() { + Report report = new Report(); + report.setProjectBranch("projectBranch"); + Assert.assertEquals("projectBranch", report.getProjectBranch()); + } + + @Test + public void projectAuthorTest() { + Report report = new Report(); + report.setProjectAuthor("projectAuthor"); + Assert.assertEquals("projectAuthor", report.getProjectAuthor()); + } + + @Test + public void projectDateTest() { + Report report = new Report(); + report.setProjectDate("projectDate"); + Assert.assertEquals("projectDate", report.getProjectDate()); + } + + + +}