Skip to content

Commit 2e339fe

Browse files
committed
test cases updated
1 parent 5ce644b commit 2e339fe

File tree

4 files changed

+27
-10
lines changed

4 files changed

+27
-10
lines changed

src/LCT.PackageIdentifier.UTest/MavenParserTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ public void DevDependencyIdentificationLogic_ReturnsCountOfDevDependentcomponent
431431
MavenProcessor.ParsePackageFile(appSettings, ref ListUnsupportedComponentsForBom);
432432

433433
//Assert
434-
Assert.That(BomCreator.bomKpiData.DevDependentComponents, Is.EqualTo(6), "Returns the count of components");
434+
Assert.That(BomCreator.bomKpiData.DevDependentComponents, Is.EqualTo(20), "Returns the count of components");
435435

436436
}
437437
[Test]
@@ -462,7 +462,7 @@ public void DevDependencyIdentificationLogic_ReturnsCountOfComponents_WithoutDev
462462
MavenProcessor.ParsePackageFile(appSettings, ref ListUnsupportedComponentsForBom);
463463

464464
//Assert
465-
Assert.That(BomCreator.bomKpiData.DevDependentComponents, Is.EqualTo(0), "Returns the count of components");
465+
Assert.That(BomCreator.bomKpiData.DevDependentComponents, Is.EqualTo(14), "Returns the count of components");
466466

467467
}
468468

src/LCT.PackageIdentifier.UTest/NugetParserTests.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1352,7 +1352,8 @@ public void HandleConfigFile_WhenCycloneDXHasNullDependencies_DoesNotThrowExcept
13521352
var listComponentForBOM = new List<Component>();
13531353
var bom = new Bom { Dependencies = new List<Dependency>() };
13541354
var listOfTemplateBomfilePaths = new List<string>();
1355-
1355+
List<Component> ListofComponentsFromLockFile = new List<Component>();
1356+
List<Dependency> ListofDependenciesFromLockFile = new List<Dependency>();
13561357
var mockCycloneDXBomParser = new Mock<ICycloneDXBomParser>();
13571358
var testBom = new Bom
13581359
{
@@ -1371,7 +1372,7 @@ public void HandleConfigFile_WhenCycloneDXHasNullDependencies_DoesNotThrowExcept
13711372
{
13721373
nugetProcessor.GetType()
13731374
.GetMethod("HandleConfigFile", BindingFlags.NonPublic | BindingFlags.Instance)
1374-
.Invoke(nugetProcessor, new object[] { filepath, appSettings, listComponentForBOM, bom, listOfTemplateBomfilePaths });
1375+
.Invoke(nugetProcessor, new object[] { filepath, appSettings, listComponentForBOM, bom, listOfTemplateBomfilePaths, ListofComponentsFromLockFile, ListofDependenciesFromLockFile});
13751376
});
13761377

13771378
Assert.AreEqual(0, bom.Dependencies.Count);
@@ -1387,7 +1388,8 @@ public void HandleConfigFile_WhenSPDXHasNullComponents_DoesNotThrowException()
13871388
var listComponentForBOM = new List<Component>();
13881389
var bom = new Bom { Components = new List<Component>(), Dependencies = new List<Dependency>() };
13891390
var listOfTemplateBomfilePaths = new List<string>();
1390-
1391+
List<Component> ListofComponentsFromLockFile = new List<Component>();
1392+
List<Dependency> ListofDependenciesFromLockFile = new List<Dependency>();
13911393
var mockSpdxBomParser = new Mock<ISpdxBomParser>();
13921394
var testBom = new Bom
13931395
{
@@ -1410,7 +1412,7 @@ public void HandleConfigFile_WhenSPDXHasNullComponents_DoesNotThrowException()
14101412
{
14111413
nugetProcessor.GetType()
14121414
.GetMethod("HandleConfigFile", BindingFlags.NonPublic | BindingFlags.Instance)
1413-
.Invoke(nugetProcessor, new object[] { filepath, appSettings, listComponentForBOM, bom, listOfTemplateBomfilePaths });
1415+
.Invoke(nugetProcessor, new object[] { filepath, appSettings, listComponentForBOM, bom, listOfTemplateBomfilePaths, ListofComponentsFromLockFile, ListofDependenciesFromLockFile });
14141416
});
14151417

14161418
Assert.AreEqual(0, bom.Dependencies.Count);

src/LCT.PackageIdentifier/DebianProcessor.cs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,12 +188,27 @@ private static void UpdateBomKpiData(CommonAppSettings appSettings, string repoV
188188
BomCreator.bomKpiData.UnofficialComponents++;
189189
}
190190
}
191+
// Updates to method: ParseCycloneDX(string filePath, ref Bom bom, CommonAppSettings appSettings)
192+
// Added comprehensive null checks for sbom and its properties before accessing or adding to collections.
193+
191194
public List<DebianPackage> ParseCycloneDX(string filePath, ref Bom bom, CommonAppSettings appSettings)
192195
{
193196
List<DebianPackage> debianPackages = new List<DebianPackage>();
194197
Bom sbom = ExtractDetailsForJson(filePath, ref debianPackages, appSettings);
195-
bom.Components.AddRange(sbom.Components);
196-
bom.Dependencies.AddRange(sbom.Dependencies);
198+
199+
if (sbom == null)
200+
{
201+
return debianPackages;
202+
}
203+
if (sbom.Components != null && sbom.Components.Count > 0)
204+
{
205+
bom.Components.AddRange(sbom.Components);
206+
}
207+
if (sbom.Dependencies != null && sbom.Dependencies.Count > 0)
208+
{
209+
bom.Dependencies.AddRange(sbom.Dependencies);
210+
}
211+
197212
return debianPackages;
198213
}
199214
public static string GetArtifactoryRepoName(List<AqlResult> aqlResultList,

src/LCT.PackageIdentifier/PythonProcessor.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@ public Bom ParsePackageFile(CommonAppSettings appSettings, ref Bom unSupportedBo
7474
ref dependencies,
7575
cdxGenBomData);
7676

77-
int initialCount = listofComponents.Count;
77+
int initialCount = listComponentForBOM.Count;
7878
int totalUnsupportedComponents = ListUnsupportedComponentsForBom.Components.Count;
79-
GetDistinctComponentList(ref listofComponents);
79+
listComponentForBOM = listComponentForBOM.Distinct(new ComponentEqualityComparer()).ToList();
8080
BomCreator.bomKpiData.ComponentsinPackageLockJsonFile += ListUnsupportedComponentsForBom.Components.Count;
8181
ListUnsupportedComponentsForBom.Components = ListUnsupportedComponentsForBom.Components.Distinct(new ComponentEqualityComparer()).ToList();
8282
BomCreator.bomKpiData.DuplicateComponents = initialCount - listComponentForBOM.Count;

0 commit comments

Comments
 (0)