|
| 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 | +} |
0 commit comments