Skip to content

Commit c7faab5

Browse files
Updated code changes for test cases
1 parent d09abc9 commit c7faab5

17 files changed

+620
-10
lines changed

src/LCT.Common/appSettings.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66

77
{
88
"TimeOut": 400,
9-
"BasicSBOM": true,
9+
"BasicSBOM": false,
1010
"ProjectType": "<Insert ProjectType>",
1111
"MultipleProjectType": false,
1212
"Telemetry": {
13-
"Enable": true,
13+
"Enable": false,
1414
"ApplicationInsightInstrumentKey": "" //From Application Insight to enable Telemetry
1515
},
1616
"SW360": {

src/LCT.PackageIdentifier/BomCreator.cs

+4-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,10 @@ public async Task GenerateBom(CommonAppSettings appSettings,
7575
Logger.Logger.Log(null, Level.Notice, $"Writing CycloneDX BOM..", null);
7676
WritecontentsToBOM(appSettings, bomKpiData, listOfComponentsToBom, defaultProjectName);
7777
Logger.Logger.Log(null, Level.Notice, $"Writing CycloneDX BOM completed", null);
78-
78+
if (appSettings.BasicSBOM)
79+
{
80+
Logger.Logger.Log(null, Level.Warn, $"Basic SBOM generated.", null);
81+
}
7982
// Writes Kpi data
8083
Program.BomStopWatch?.Stop();
8184
bomKpiData.TimeTakenByBomCreator = Program.BomStopWatch == null ? 0 :

src/LCT.PackageIdentifier/Program.cs

+2-6
Original file line numberDiff line numberDiff line change
@@ -100,15 +100,11 @@ static async Task Main(string[] args)
100100
caToolInformation);
101101
}
102102

103-
if (appSettings.Telemetry.Enable == true)
103+
if (appSettings?.Telemetry?.Enable == true)
104104
{
105105
TelemetryHelper telemetryHelper = new TelemetryHelper(appSettings);
106106
telemetryHelper.StartTelemetry(caToolInformation.CatoolVersion, BomCreator.bomKpiData, TelemetryConstant.IdentifierKpiData);
107-
}
108-
if (appSettings.BasicSBOM)
109-
{
110-
Logger.Logger.Log(null, Level.Warn, $"Basic SBOM generated.\n", null);
111-
}
107+
}
112108
Logger.Logger.Log(null, Level.Notice, $"End of Package Identifier execution : {DateTime.Now}\n", null);
113109
// publish logs and bom file to pipeline artifact
114110
PipelineArtifactUploader.UploadArtifacts();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
using NUnit.Framework;
2+
using TestUtilities;
3+
using System.IO;
4+
using CycloneDX.Models;
5+
6+
namespace SW360IntegrationTest.Alpine
7+
{
8+
[TestFixture, Order(29)]
9+
public class PackageIdentifierBasicSBOMAlpine
10+
{
11+
private string CCTLocalBomTestFile { get; set; }
12+
private string OutFolder { get; set; }
13+
TestParamAlpine testParameters;
14+
15+
[SetUp]
16+
public void Setup()
17+
{
18+
OutFolder = TestHelper.OutFolder;
19+
20+
CCTLocalBomTestFile = OutFolder + @"..\..\..\src\SW360IntegrationTest\PackageIdentifierTestFiles\Alpine\CCTLocalBOMAlpineInitial.json";
21+
22+
if (!Directory.Exists(OutFolder + @"\..\BOMs"))
23+
{
24+
Directory.CreateDirectory(OutFolder + @"\..\BOMs");
25+
}
26+
testParameters = new TestParamAlpine();
27+
}
28+
29+
[Test, Order(1)]
30+
public void RunBOMCreatorexe_ProvidedPackageJsonFilePath_ReturnsSuccess()
31+
{
32+
string packagejsonPath = OutFolder + @"\..\..\TestFiles\IntegrationTestFiles\SystemTest1stIterationData\Alpine";
33+
string bomPath = OutFolder + @"\..\BOMs";
34+
35+
// Test BOM Creator ran with exit code 0
36+
Assert.AreEqual(0, TestHelper.RunBOMCreatorExe(new string[]{
37+
TestConstant.PackageFilePath, packagejsonPath,
38+
TestConstant.BomFolderPath, bomPath,
39+
TestConstant.BasicSBOM, testParameters.BasicSBOMEnable,
40+
TestConstant.ProjectType,"ALPINE",
41+
TestConstant.Mode,""}),
42+
"Test to run Package Identifier EXE execution");
43+
}
44+
45+
[Test, Order(2)]
46+
public void LocalBOMCreation_AfterSuccessfulExeRun_ReturnsSuccess()
47+
{
48+
bool fileExist = false;
49+
50+
// Expected
51+
ComponentJsonParsor expected = new ComponentJsonParsor();
52+
expected.Read(CCTLocalBomTestFile);
53+
54+
// Actual
55+
string generatedBOM = OutFolder + $"\\..\\BOMs\\CycloneDX_Bom.cdx.json";
56+
if (File.Exists(generatedBOM))
57+
{
58+
fileExist = true;
59+
60+
ComponentJsonParsor actual = new ComponentJsonParsor();
61+
actual.Read(generatedBOM);
62+
63+
foreach (var item in expected.Components)
64+
{
65+
66+
foreach (var i in actual.Components)
67+
{
68+
if ((i.Name == item.Name) && (i.Version == item.Version))
69+
{
70+
Component component = i;
71+
Assert.AreEqual(item.Name, component.Name);
72+
Assert.AreEqual(item.Version, component.Version);
73+
Assert.AreEqual(item.Purl, component.Purl);
74+
Assert.AreEqual(item.BomRef, component.BomRef);
75+
}
76+
}
77+
78+
}
79+
}
80+
81+
Assert.IsTrue(fileExist, "Test to BOM file present");
82+
}
83+
}
84+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
using NUnit.Framework;
2+
using TestUtilities;
3+
using CycloneDX.Models;
4+
using System.IO;
5+
6+
namespace SW360IntegrationTest.Conan
7+
{
8+
[TestFixture, Order(30)]
9+
public class PackageIdentifierBasicSBOMConan
10+
{
11+
private string CCTLocalBomTestFile { get; set; }
12+
private string OutFolder { get; set; }
13+
TestParamConan testParameters;
14+
15+
[SetUp]
16+
public void Setup()
17+
{
18+
OutFolder = TestHelper.OutFolder;
19+
20+
CCTLocalBomTestFile = OutFolder + @"..\..\..\src\SW360IntegrationTest\PackageIdentifierTestFiles\Conan\CCTLocalBOMConanInitial.json";
21+
22+
if (!Directory.Exists(OutFolder + @"\..\BOMs"))
23+
{
24+
Directory.CreateDirectory(OutFolder + @"\..\BOMs");
25+
}
26+
testParameters = new TestParamConan();
27+
}
28+
[Test, Order(1)]
29+
public void RunBOMCreatorexe_ProvidedPackageJsonFilePath_ReturnsSuccess()
30+
{
31+
string packagejsonPath = OutFolder + @"\..\..\TestFiles\IntegrationTestFiles\SystemTest1stIterationData\Conan";
32+
string bomPath = OutFolder + @"\..\BOMs";
33+
34+
// Test BOM Creator ran with exit code 0
35+
Assert.AreEqual(0, TestHelper.RunBOMCreatorExe(new string[]{
36+
TestConstant.PackageFilePath, packagejsonPath,
37+
TestConstant.BomFolderPath, bomPath,
38+
TestConstant.BasicSBOM, testParameters.BasicSBOMEnable,
39+
TestConstant.ProjectType,"Conan",
40+
TestConstant.Mode,""}),
41+
"Test to run Package Identifier EXE execution");
42+
}
43+
44+
45+
[Test, Order(2)]
46+
public void LocalBOMCreation_AfterSuccessfulExeRun_ReturnsSuccess()
47+
{
48+
bool fileExist = false;
49+
50+
// Expected
51+
ComponentJsonParsor expected = new ComponentJsonParsor();
52+
expected.Read(CCTLocalBomTestFile);
53+
54+
// Actual
55+
string generatedBOM = OutFolder + $"\\..\\BOMs\\CycloneDX_Bom.cdx.json";
56+
if (File.Exists(generatedBOM))
57+
{
58+
fileExist = true;
59+
60+
ComponentJsonParsor actual = new ComponentJsonParsor();
61+
actual.Read(generatedBOM);
62+
63+
foreach (var item in expected.Components)
64+
{
65+
66+
foreach (var i in actual.Components)
67+
{
68+
if ((i.Name == item.Name) && (i.Version == item.Version))
69+
{
70+
Component component = i;
71+
Assert.AreEqual(item.Name, component.Name);
72+
Assert.AreEqual(item.Version, component.Version);
73+
Assert.AreEqual(item.Purl, component.Purl);
74+
Assert.AreEqual(item.BomRef, component.BomRef);
75+
}
76+
}
77+
78+
}
79+
}
80+
81+
Assert.IsTrue(fileExist, "Test to BOM file present");
82+
}
83+
}
84+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using CycloneDX.Models;
7+
using System.IO;
8+
using NUnit.Framework;
9+
using TestUtilities;
10+
11+
namespace SW360IntegrationTest.Debian
12+
{
13+
[TestFixture, Order(31)]
14+
public class PackageIdentifierBasicSBOMDebian
15+
{
16+
private string CCTLocalBomTestFile { get; set; }
17+
private string OutFolder { get; set; }
18+
TestParamDebian testParameters;
19+
20+
[SetUp]
21+
public void Setup()
22+
{
23+
OutFolder = TestHelper.OutFolder;
24+
25+
CCTLocalBomTestFile = OutFolder + @"..\..\..\src\SW360IntegrationTest\PackageIdentifierTestFiles\Debian\CCTLocalBOMDebianInitial.json";
26+
27+
if (!Directory.Exists(OutFolder + @"\..\BOMs"))
28+
{
29+
Directory.CreateDirectory(OutFolder + @"\..\BOMs");
30+
}
31+
testParameters = new TestParamDebian();
32+
}
33+
34+
[Test, Order(1)]
35+
public void RunBOMCreatorexe_ProvidedPackageJsonFilePath_ReturnsSuccess()
36+
{
37+
string packagejsonPath = OutFolder + @"\..\..\TestFiles\IntegrationTestFiles\SystemTest1stIterationData\Debian";
38+
string bomPath = OutFolder + @"\..\BOMs";
39+
40+
// Test BOM Creator ran with exit code 0
41+
Assert.AreEqual(0, TestHelper.RunBOMCreatorExe(new string[]{
42+
TestConstant.PackageFilePath, packagejsonPath,
43+
TestConstant.BomFolderPath, bomPath,
44+
TestConstant.BasicSBOM, testParameters.BasicSBOMEnable,
45+
TestConstant.ProjectType,"Debian",
46+
TestConstant.Mode,""}),
47+
"Test to run Package Identifier EXE execution");
48+
}
49+
50+
51+
52+
[Test, Order(2)]
53+
public void LocalBOMCreation_AfterSuccessfulExeRun_ReturnsSuccess()
54+
{
55+
bool fileExist = false;
56+
57+
// Expected
58+
ComponentJsonParsor expected = new ComponentJsonParsor();
59+
expected.Read(CCTLocalBomTestFile);
60+
61+
// Actual
62+
string generatedBOM = OutFolder + $"\\..\\BOMs\\CycloneDX_Bom.cdx.json";
63+
if (File.Exists(generatedBOM))
64+
{
65+
fileExist = true;
66+
67+
ComponentJsonParsor actual = new ComponentJsonParsor();
68+
actual.Read(generatedBOM);
69+
70+
foreach (var item in expected.Components)
71+
{
72+
73+
foreach (var i in actual.Components)
74+
{
75+
if ((i.Name == item.Name) && (i.Version == item.Version))
76+
{
77+
Component component = i;
78+
Assert.AreEqual(item.Name, component.Name);
79+
Assert.AreEqual(item.Version, component.Version);
80+
Assert.AreEqual(item.Purl, component.Purl);
81+
Assert.AreEqual(item.BomRef, component.BomRef);
82+
}
83+
}
84+
85+
}
86+
}
87+
88+
Assert.IsTrue(fileExist, "Test to BOM file present");
89+
}
90+
}
91+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using CycloneDX.Models;
7+
using System.IO;
8+
using NUnit.Framework;
9+
using TestUtilities;
10+
11+
namespace SW360IntegrationTest.Maven
12+
{
13+
[TestFixture, Order(32)]
14+
public class PackageIdentifierBasicSBOMMaven
15+
{
16+
private string CCTLocalBomTestFile { get; set; }
17+
private string OutFolder { get; set; }
18+
TestParamNuget testParameters;
19+
20+
[SetUp]
21+
public void Setup()
22+
{
23+
OutFolder = TestHelper.OutFolder;
24+
25+
CCTLocalBomTestFile = OutFolder + @"..\..\..\src\SW360IntegrationTest\PackageIdentifierTestFiles\Maven\CCTLocalBOMMavenInitial.json";
26+
27+
if (!Directory.Exists(OutFolder + @"\..\BOMs"))
28+
{
29+
Directory.CreateDirectory(OutFolder + @"\..\BOMs");
30+
}
31+
testParameters = new TestParamNuget();
32+
}
33+
34+
[Test, Order(1)]
35+
public void RunBOMCreatorexe_ProvidedPackageJsonFilePath_ReturnsSuccess()
36+
{
37+
string packagejsonPath = OutFolder + @"\..\..\TestFiles\IntegrationTestFiles\SystemTest1stIterationData\Maven";
38+
string bomPath = OutFolder + @"\..\BOMs";
39+
40+
// Test BOM Creator ran with exit code 0
41+
Assert.AreEqual(0, TestHelper.RunBOMCreatorExe(new string[]{
42+
TestConstant.PackageFilePath, packagejsonPath,
43+
TestConstant.BomFolderPath, bomPath,
44+
TestConstant.BasicSBOM, testParameters.BasicSBOMEnable,
45+
TestConstant.ProjectType,"Maven",
46+
TestConstant.Mode,""}),
47+
"Test to run Package Identifier EXE execution");
48+
}
49+
50+
51+
52+
[Test, Order(2)]
53+
public void LocalBOMCreation_AfterSuccessfulExeRun_ReturnsSuccess()
54+
{
55+
bool fileExist = false;
56+
57+
// Expected
58+
ComponentJsonParsor expected = new ComponentJsonParsor();
59+
expected.Read(CCTLocalBomTestFile);
60+
61+
// Actual
62+
string generatedBOM = OutFolder + $"\\..\\BOMs\\CycloneDX_Bom.cdx.json";
63+
if (File.Exists(generatedBOM))
64+
{
65+
fileExist = true;
66+
67+
ComponentJsonParsor actual = new ComponentJsonParsor();
68+
actual.Read(generatedBOM);
69+
70+
foreach (var item in expected.Components)
71+
{
72+
73+
foreach (var i in actual.Components)
74+
{
75+
if ((i.Name == item.Name) && (i.Version == item.Version))
76+
{
77+
Component component = i;
78+
Assert.AreEqual(item.Name, component.Name);
79+
Assert.AreEqual(item.Version, component.Version);
80+
Assert.AreEqual(item.Purl, component.Purl);
81+
Assert.AreEqual(item.BomRef, component.BomRef);
82+
}
83+
}
84+
85+
}
86+
}
87+
88+
Assert.IsTrue(fileExist, "Test to BOM file present");
89+
}
90+
}
91+
}

0 commit comments

Comments
 (0)