Skip to content

Commit

Permalink
Updated Unit test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
ragavareddychalapala committed Jan 9, 2025
1 parent 9c53c9f commit be6f263
Show file tree
Hide file tree
Showing 17 changed files with 940 additions and 334 deletions.
92 changes: 62 additions & 30 deletions src/LCT.PackageIdentifier.UTest/AlpineParserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using LCT.Common.Constants;
using Moq;
using System.Collections.Generic;
using LCT.Common.Interface;

namespace LCT.PackageIdentifier.UTest
{
Expand Down Expand Up @@ -41,13 +42,19 @@ public void ParsePackageConfig_GivenAMultipleInputFilePath_ReturnsCounts()
string exePath = System.Reflection.Assembly.GetExecutingAssembly().Location;
string OutFolder = Path.GetDirectoryName(exePath);

string[] Includes = { "*_Alpine.cdx.json" };
CommonAppSettings appSettings = new CommonAppSettings()
string[] Includes = { "*_Alpine.cdx.json" };

IFolderAction folderAction = new FolderAction();
IFileOperations fileOperations = new FileOperations();
CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations)
{
ProjectType = "ALPINE",
RemoveDevDependency = true,
Alpine = new Config() { Include = Includes },
PackageFilePath = OutFolder + @"\PackageIdentifierUTTestFiles"
SW360 = new SW360() { IgnoreDevDependency = true },
Directory = new LCT.Common.Directory(folderAction, fileOperations)
{
InputFolder = OutFolder + @"\PackageIdentifierUTTestFiles"
}
};

//Act
Expand All @@ -67,13 +74,18 @@ public void ParsePackageConfig_GivenAInputFilePath_ReturnsCounts()
string exePath = System.Reflection.Assembly.GetExecutingAssembly().Location;
string OutFolder = Path.GetDirectoryName(exePath);
string[] Includes = { "CycloneDX_Alpine.cdx.json" };
CommonAppSettings appSettings = new CommonAppSettings()
IFolderAction folderAction = new FolderAction();
IFileOperations fileOperations=new FileOperations();
CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations)
{
PackageFilePath = OutFolder + @"\PackageIdentifierUTTestFiles",
ProjectType = "ALPINE",
RemoveDevDependency = true,
Alpine = new Config() { Include = Includes }
};
Alpine = new Config() { Include = Includes },
SW360=new SW360() { IgnoreDevDependency = true },
Directory = new LCT.Common.Directory(folderAction, fileOperations)
{
InputFolder = OutFolder + @"\PackageIdentifierUTTestFiles"
}
};

//Act
Bom listofcomponents = _alpineProcessor.ParsePackageFile(appSettings);
Expand All @@ -90,17 +102,22 @@ public void ParsePackageConfig_GivenMultipleInputFiles_ReturnsCountOfDuplicates(
int duplicateComponents = 2;
string exePath = System.Reflection.Assembly.GetExecutingAssembly().Location;
string OutFolder = Path.GetDirectoryName(exePath);

string[] Includes = { "*_Alpine.cdx.json" };

CommonAppSettings appSettings = new CommonAppSettings()
string[] Includes = { "*_Alpine.cdx.json" };
IFolderAction folderAction = new FolderAction();
IFileOperations fileOperations = new FileOperations();
CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations)
{
PackageFilePath = OutFolder + @"\PackageIdentifierUTTestFiles",
ProjectType = "ALPINE",
RemoveDevDependency = true,
Alpine = new Config() { Include = Includes }
Alpine = new Config() { Include = Includes },
SW360 = new SW360() { IgnoreDevDependency = true },
Directory = new LCT.Common.Directory(folderAction, fileOperations)
{
InputFolder = OutFolder + @"\PackageIdentifierUTTestFiles"
}
};


//Act
_alpineProcessor.ParsePackageFile(appSettings);

Expand All @@ -118,14 +135,19 @@ public void ParsePackageConfig_GivenAInputFilePath_ReturnsSourceDetails()
string OutFolder = Path.GetDirectoryName(exePath);
string[] Includes = { "AlpineSourceDetails_Cyclonedx.cdx.json" };

CommonAppSettings appSettings = new CommonAppSettings()
IFolderAction folderAction = new FolderAction();
IFileOperations fileOperations = new FileOperations();
CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations)
{
PackageFilePath = OutFolder + @"\PackageIdentifierUTTestFiles",
ProjectType = "ALPINE",
RemoveDevDependency = true,
Alpine = new Config() { Include = Includes }
Alpine = new Config() { Include = Includes },
SW360 = new SW360() { IgnoreDevDependency = true },
Directory = new LCT.Common.Directory(folderAction, fileOperations)
{
InputFolder = OutFolder + @"\PackageIdentifierUTTestFiles"
}
};

//Act
Bom listofcomponents = _alpineProcessor.ParsePackageFile(appSettings);

Expand All @@ -144,14 +166,19 @@ public void ParsePackageConfig_GivenAInputFilePathAlongWithSBOMTemplate_ReturnTo
string[] Includes = { "CycloneDX_Alpine.cdx.json", "SBOMTemplate_Alpine.cdx.json" };
string packagefilepath = OutFolder + @"\PackageIdentifierUTTestFiles";

CommonAppSettings appSettings = new CommonAppSettings()
IFolderAction folderAction = new FolderAction();
IFileOperations fileOperations = new FileOperations();
CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations)
{
PackageFilePath = packagefilepath,
ProjectType = "ALPINE",
RemoveDevDependency = true,
Alpine = new Config() { Include = Includes },
CycloneDxSBomTemplatePath = packagefilepath + "\\SBOMTemplates\\SBOM_AlpineCATemplate.cdx.json"
};
SW360 = new SW360() { IgnoreDevDependency = true },
Directory = new LCT.Common.Directory(folderAction, fileOperations)
{
InputFolder = OutFolder + @"\PackageIdentifierUTTestFiles",
CycloneDxSBomTemplatePath = packagefilepath + "\\SBOMTemplates\\SBOM_AlpineCATemplate.cdx.json"
}
};

//Act
Bom listofcomponents = _alpineProcessor.ParsePackageFile(appSettings);
Expand All @@ -170,15 +197,20 @@ public void ParsePackageConfig_GivenAInputFilePathAlongWithSBOMTemplate_ReturnUp
string[] Includes = { "CycloneDX_Alpine.cdx.json", "SBOMTemplate_Alpine.cdx.json" };
string packagefilepath = OutFolder + @"\PackageIdentifierUTTestFiles";

CommonAppSettings appSettings = new CommonAppSettings()
IFolderAction folderAction = new FolderAction();
IFileOperations fileOperations = new FileOperations();
CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations)
{
PackageFilePath = packagefilepath,
ProjectType = "ALPINE",
RemoveDevDependency = true,
Alpine = new Config() { Include = Includes },
CycloneDxSBomTemplatePath = packagefilepath + "\\SBOMTemplates\\SBOMTemplate_Alpine.cdx.json",
SW360 = new SW360() { IgnoreDevDependency = true },
Directory = new LCT.Common.Directory(folderAction, fileOperations)
{
InputFolder = packagefilepath,
CycloneDxSBomTemplatePath = packagefilepath + "\\SBOMTemplates\\SBOMTemplate_Alpine.cdx.json"
}
};

//Act
Bom listofcomponents = _alpineProcessor.ParsePackageFile(appSettings);
bool isUpdated = listofcomponents.Components.Exists(x => x.Properties != null
Expand Down
126 changes: 89 additions & 37 deletions src/LCT.PackageIdentifier.UTest/BomHelperUnitTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
using LCT.Common.Model;
using LCT.Services.Interface;
using LCT.APICommunications.Model.AQL;
using LCT.Common.Interface;

namespace LCT.PackageIdentifier.UTest
{
Expand Down Expand Up @@ -176,16 +177,25 @@ public async Task GetRepoDetails_GivenProjectTypeAsDebian_ReturnsListOFComponent
Version="1",
}
};


CommonAppSettings appSettings = new CommonAppSettings()
IFolderAction folderAction = new FolderAction();
IFileOperations fileOperations = new FileOperations();
CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations)
{
ArtifactoryUploadApiKey = "testvalue",
ProjectType = "DEBIAN",
Debian = new Config()
Debian = new Config
{
JfrogDebianRepoList = new string[] { "here" }
Artifactory = new Artifactory
{
RemoteRepos = new string[] { "here" }
}
},
JFrogApi = "https://jfrogapi"
Jfrog = new Jfrog
{
Token = "testvalue",
URL = "https://jfrogapi"
}
};
List<AqlResult> aqlResultList = new()
{
Expand Down Expand Up @@ -227,15 +237,24 @@ public async Task GetRepoDetails_GivenProjectTypeAsNpm_ReturnsListOFComponents()
}
};

CommonAppSettings appSettings = new CommonAppSettings()

IFolderAction folderAction = new FolderAction();
IFileOperations fileOperations = new FileOperations();
CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations)
{
ArtifactoryUploadApiKey = "testvalue",
ProjectType = "NPM",
Debian = new Config()
Npm = new Config
{
JfrogDebianRepoList = new string[] { "here" }
Artifactory = new Artifactory
{
RemoteRepos = new string[] { "here" }
}
},
JFrogApi = "https://jfrogapi"
Jfrog = new Jfrog
{
Token = "testvalue",
URL = "https://jfrogapi"
}
};
List<AqlResult> aqlResultList = new()
{
Expand All @@ -252,7 +271,7 @@ public async Task GetRepoDetails_GivenProjectTypeAsNpm_ReturnsListOFComponents()
mockIProcessor.Setup(x => x.GetJfrogArtifactoryRepoInfo(It.IsAny<CommonAppSettings>(), It.IsAny<ArtifactoryCredentials>(), It.IsAny<Component>(), It.IsAny<string>())).ReturnsAsync(lstComponentForBOM);
Mock<ICycloneDXBomParser> cycloneDXBomParser = new Mock<ICycloneDXBomParser>();

IParser parser = new DebianProcessor(cycloneDXBomParser.Object);
IParser parser = new NpmProcessor(cycloneDXBomParser.Object);
Mock<IJFrogService> jFrogService = new Mock<IJFrogService>();
Mock<IBomHelper> bomHelper = new Mock<IBomHelper>();
bomHelper.Setup(x => x.GetListOfComponentsFromRepo(It.IsAny<string[]>(), It.IsAny<IJFrogService>())).ReturnsAsync(aqlResultList);
Expand All @@ -277,16 +296,25 @@ public async Task GetRepoDetails_GivenProjectTypeAsNuget_ReturnsListOFComponents
}
};

CommonAppSettings appSettings = new CommonAppSettings()
IFolderAction folderAction = new FolderAction();
IFileOperations fileOperations = new FileOperations();
CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations)
{
ArtifactoryUploadApiKey = "testvalue",
ProjectType = "NUGET",
Debian = new Config()
ProjectType = "Nuget",
Nuget = new Config
{
JfrogDebianRepoList = new string[] { "here" }
Artifactory = new Artifactory
{
RemoteRepos = new string[] { "here" }
}
},
JFrogApi = "https://jfrogapi"
Jfrog = new Jfrog
{
Token = "testvalue",
URL = "https://jfrogapi"
}
};

List<AqlResult> aqlResultList = new()
{
new()
Expand All @@ -302,7 +330,7 @@ public async Task GetRepoDetails_GivenProjectTypeAsNuget_ReturnsListOFComponents
mockIProcessor.Setup(x => x.GetJfrogArtifactoryRepoInfo(It.IsAny<CommonAppSettings>(), It.IsAny<ArtifactoryCredentials>(), It.IsAny<Component>(), It.IsAny<string>())).ReturnsAsync(lstComponentForBOM);
Mock<ICycloneDXBomParser> cycloneDXBomParser = new Mock<ICycloneDXBomParser>();

IParser parser = new DebianProcessor(cycloneDXBomParser.Object);
IParser parser = new NugetProcessor(cycloneDXBomParser.Object);
Mock<IJFrogService> jFrogService = new Mock<IJFrogService>();
Mock<IBomHelper> bomHelper = new Mock<IBomHelper>();
bomHelper.Setup(x => x.GetListOfComponentsFromRepo(It.IsAny<string[]>(), It.IsAny<IJFrogService>())).ReturnsAsync(aqlResultList);
Expand All @@ -327,15 +355,23 @@ public async Task GetRepoDetails_GivenProjectTypeAsPython_ReturnsListOFComponent
}
};

CommonAppSettings appSettings = new CommonAppSettings()
IFolderAction folderAction = new FolderAction();
IFileOperations fileOperations = new FileOperations();
CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations)
{
ArtifactoryUploadApiKey = "testvalue",
ProjectType = "PYTHON",
Debian = new Config()
ProjectType = "Python",
Poetry = new Config
{
JfrogDebianRepoList = new string[] { "here" }
Artifactory = new Artifactory
{
RemoteRepos = new string[] { "here" }
}
},
JFrogApi = "https://jfrogapi"
Jfrog = new Jfrog
{
Token = "testvalue",
URL = "https://jfrogapi"
}
};
List<AqlResult> aqlResultList = new()
{
Expand All @@ -352,7 +388,7 @@ public async Task GetRepoDetails_GivenProjectTypeAsPython_ReturnsListOFComponent
mockIProcessor.Setup(x => x.GetJfrogArtifactoryRepoInfo(It.IsAny<CommonAppSettings>(), It.IsAny<ArtifactoryCredentials>(), It.IsAny<Component>(), It.IsAny<string>())).ReturnsAsync(lstComponentForBOM);
Mock<ICycloneDXBomParser> cycloneDXBomParser = new Mock<ICycloneDXBomParser>();

IParser parser = new DebianProcessor(cycloneDXBomParser.Object);
IParser parser = new PythonProcessor(cycloneDXBomParser.Object);
Mock<IJFrogService> jFrogService = new Mock<IJFrogService>();
Mock<IBomHelper> bomHelper = new Mock<IBomHelper>();
bomHelper.Setup(x => x.GetListOfComponentsFromRepo(It.IsAny<string[]>(), It.IsAny<IJFrogService>())).ReturnsAsync(aqlResultList);
Expand All @@ -377,15 +413,23 @@ public async Task GetRepoDetails_GivenProjectTypeAsConan_ReturnsListOFComponents
}
};

CommonAppSettings appSettings = new CommonAppSettings()
IFolderAction folderAction = new FolderAction();
IFileOperations fileOperations = new FileOperations();
CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations)
{
ArtifactoryUploadApiKey = "testvalue",
ProjectType = "Conan",
Debian = new Config()
Conan = new Config
{
JfrogDebianRepoList = new string[] { "here" }
Artifactory = new Artifactory
{
RemoteRepos = new string[] { "here" }
}
},
JFrogApi = "https://jfrogapi"
Jfrog = new Jfrog
{
Token = "testvalue",
URL = "https://jfrogapi"
}
};
List<AqlResult> aqlResultList = new()
{
Expand All @@ -402,7 +446,7 @@ public async Task GetRepoDetails_GivenProjectTypeAsConan_ReturnsListOFComponents
mockIProcessor.Setup(x => x.GetJfrogArtifactoryRepoInfo(It.IsAny<CommonAppSettings>(), It.IsAny<ArtifactoryCredentials>(), It.IsAny<Component>(), It.IsAny<string>())).ReturnsAsync(lstComponentForBOM);
Mock<ICycloneDXBomParser> cycloneDXBomParser = new Mock<ICycloneDXBomParser>();

IParser parser = new DebianProcessor(cycloneDXBomParser.Object);
IParser parser = new ConanProcessor(cycloneDXBomParser.Object);
Mock<IJFrogService> jFrogService = new Mock<IJFrogService>();
Mock<IBomHelper> bomHelper = new Mock<IBomHelper>();
bomHelper.Setup(x => x.GetListOfComponentsFromRepo(It.IsAny<string[]>(), It.IsAny<IJFrogService>())).ReturnsAsync(aqlResultList);
Expand All @@ -427,15 +471,23 @@ public async Task GetRepoDetails_GivenProjectTypeAsMaven_ReturnsListOFComponents
}
};

CommonAppSettings appSettings = new CommonAppSettings()
IFolderAction folderAction = new FolderAction();
IFileOperations fileOperations = new FileOperations();
CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations)
{
ArtifactoryUploadApiKey = "testvalue",
ProjectType = "MAVEN",
Debian = new Config()
Maven = new Config
{
JfrogDebianRepoList = new string[] { "here" }
Artifactory = new Artifactory
{
RemoteRepos = new string[] { "here" }
}
},
JFrogApi = "https://jfrogapi"
Jfrog = new Jfrog
{
Token = "testvalue",
URL = "https://jfrogapi"
}
};
List<AqlResult> aqlResultList = new()
{
Expand All @@ -452,7 +504,7 @@ public async Task GetRepoDetails_GivenProjectTypeAsMaven_ReturnsListOFComponents
mockIProcessor.Setup(x => x.GetJfrogArtifactoryRepoInfo(It.IsAny<CommonAppSettings>(), It.IsAny<ArtifactoryCredentials>(), It.IsAny<Component>(), It.IsAny<string>())).ReturnsAsync(lstComponentForBOM);
Mock<ICycloneDXBomParser> cycloneDXBomParser = new Mock<ICycloneDXBomParser>();

IParser parser = new DebianProcessor(cycloneDXBomParser.Object);
IParser parser = new MavenProcessor(cycloneDXBomParser.Object);
Mock<IJFrogService> jFrogService = new Mock<IJFrogService>();
Mock<IBomHelper> bomHelper = new Mock<IBomHelper>();
bomHelper.Setup(x => x.GetListOfComponentsFromRepo(It.IsAny<string[]>(), It.IsAny<IJFrogService>())).ReturnsAsync(aqlResultList);
Expand Down
Loading

0 comments on commit be6f263

Please sign in to comment.