Skip to content

Commit

Permalink
Updated as per review comments and fix test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
ragavareddychalapala committed Jan 3, 2025
1 parent 15ffb9d commit 5d05078
Show file tree
Hide file tree
Showing 5 changed files with 211 additions and 59 deletions.
14 changes: 13 additions & 1 deletion src/AritfactoryUploader.UTest/PackageUploadHelperTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,18 @@ public async Task GetSrcRepoDetailsForPyPiOrConanPackages_WhenPypiRepoExists_Ret
Name = "pypi component",
Version = "1.0.0"
};
AqlProperty property1 = new AqlProperty
{
key = "pypi.normalized.name",
value = "pypi component"
};

AqlProperty property2 = new AqlProperty
{
key = "pypi.version",
value = "1.0.0"
};
List<AqlProperty> propertys = new List<AqlProperty> { property1, property2 };
//GetInternalComponentDataByRepo
var aqlResultList = new List<AqlResult>
{
Expand All @@ -428,10 +439,11 @@ public async Task GetSrcRepoDetailsForPyPiOrConanPackages_WhenPypiRepoExists_Ret
Repo = "pypi-repo",
Path = "path/to/package",
Name = "pypi component-1.0.0",
properties=propertys,
}
};
var jFrogServiceMock = new Mock<IJFrogService>();
jFrogServiceMock.Setup(x => x.GetInternalComponentDataByRepo(It.IsAny<string>())).ReturnsAsync(aqlResultList);
jFrogServiceMock.Setup(x => x.GetPypiComponentDataByRepo(It.IsAny<string>())).ReturnsAsync(aqlResultList);
PackageUploadHelper.jFrogService = jFrogServiceMock.Object;

// Act
Expand Down
142 changes: 127 additions & 15 deletions src/LCT.PackageIdentifier.UTest/NpmProcessorUTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,38 @@ public void GetJfrogArtifactoryRepoDetials_RepoPathFound_ReturnsAqlResultWithRep
{
// Arrange
Mock<ICycloneDXBomParser> cycloneDXBomParser = new Mock<ICycloneDXBomParser>();
AqlProperty property1 = new AqlProperty
{
key = "npm.name",
value = "component"
};

AqlProperty property2 = new AqlProperty
{
key = "npm.version",
value = "1.0.0"
};
AqlProperty prop1 = new AqlProperty
{
key = "npm.name",
value = "component"
};

AqlProperty prop2 = new AqlProperty
{
key = "npm.version",
value = "2.0.0"
};
List<AqlProperty> propertys = new List<AqlProperty> { property1, property2 };
List<AqlProperty> property = new List<AqlProperty> { prop1, prop2 };
var aqlResultList = new List<AqlResult>
{
new AqlResult { Name = "component-1.0.0.tgz", Repo = "repo1", Path="path/to" },
new AqlResult { Name = "component-2.0.0.tgz", Repo = "repo2", Path="path/to" }
new AqlResult { Name = "component-1.0.0.tgz", Repo = "repo1", Path="path/to",properties=propertys },
new AqlResult { Name = "component-2.0.0.tgz", Repo = "repo2", Path="path/to",properties = property }
};
var component = new Component { Name = "component", Version = "1.0.0" };
var bomHelperMock = new Mock<IBomHelper>();
var component = new Component { Name = "component", Version = "1.0.0" };
bomHelperMock.Setup(b => b.GetFullNameOfComponent(component)).Returns("component");
var expectedRepoPath = "repo1/path/to/component-1.0.0.tgz";

var npmProcessor = new NpmProcessor(cycloneDXBomParser.Object);
Expand All @@ -52,13 +77,38 @@ public void GetJfrogArtifactoryRepoDetials_RepoPathNotFound_ReturnsAqlResultWith
{
// Arrange
Mock<ICycloneDXBomParser> cycloneDXBomParser = new Mock<ICycloneDXBomParser>();
AqlProperty property1 = new AqlProperty
{
key = "npm.name",
value = "component"
};

AqlProperty property2 = new AqlProperty
{
key = "npm.version",
value = "1.0.0"
};
AqlProperty prop1 = new AqlProperty
{
key = "npm.name",
value = "component"
};

AqlProperty prop2 = new AqlProperty
{
key = "npm.version",
value = "2.0.0"
};
List<AqlProperty> propertys = new List<AqlProperty> { property1, property2 };
List<AqlProperty> property = new List<AqlProperty> { prop1, prop2 };
var aqlResultList = new List<AqlResult>
{
new AqlResult { Name = "component-1.0.0.tgz", Repo = "repo1" },
new AqlResult { Name = "component-2.0.0.tgz", Repo = "repo2" }
new AqlResult { Name = "component-1.0.0.tgz", Repo = "repo1",properties=propertys },
new AqlResult { Name = "component-2.0.0.tgz", Repo = "repo2",properties=property }
};
var component = new Component { Name = "component", Version = "3.0.0" };
var bomHelperMock = new Mock<IBomHelper>();
bomHelperMock.Setup(b => b.GetFullNameOfComponent(component)).Returns("component");

var npmProcessor = new NpmProcessor(cycloneDXBomParser.Object);

Expand All @@ -84,18 +134,30 @@ public async Task IdentificationOfInternalComponents_ReturnsComponentData_Succes
ComponentIdentification component = new() { comparisonBOMData = components };
string[] reooListArr = { "internalrepo1", "internalrepo2" };
CommonAppSettings appSettings = new() { InternalRepoList = reooListArr };
AqlProperty prop1 = new AqlProperty
{
key = "npm.name",
value = "animations"
};

AqlProperty prop2 = new AqlProperty
{
key = "npm.version",
value = "1.0.0"
};
List<AqlProperty> propertys = new List<AqlProperty> { prop1, prop2 };
AqlResult aqlResult = new()
{
Name = "animations-1.0.0.tgz",
Path = "@testfolder/-/folder",
Repo = "internalrepo1"
Repo = "internalrepo1",
properties = propertys
};

List<AqlResult> results = new List<AqlResult>() { aqlResult };
Mock<IJFrogService> mockJfrogService = new Mock<IJFrogService>();
Mock<IBomHelper> mockBomHelper = new Mock<IBomHelper>();
mockBomHelper.Setup(m => m.GetListOfComponentsFromRepo(It.IsAny<string[]>(), It.IsAny<IJFrogService>()))
mockBomHelper.Setup(m => m.GetNpmListOfComponentsFromRepo(It.IsAny<string[]>(), It.IsAny<IJFrogService>()))
.ReturnsAsync(results);
mockBomHelper.Setup(m => m.GetFullNameOfComponent(It.IsAny<Component>())).Returns("animations");
Mock<ICycloneDXBomParser> cycloneDXBomParser = new Mock<ICycloneDXBomParser>();
Expand All @@ -121,18 +183,30 @@ public async Task IdentificationOfInternalComponents_ReturnsComponentData2_Succe
ComponentIdentification component = new() { comparisonBOMData = components };
string[] reooListArr = { "internalrepo1", "internalrepo2" };
CommonAppSettings appSettings = new() { InternalRepoList = reooListArr };
AqlProperty prop1 = new AqlProperty
{
key = "npm.name",
value = "animations"
};

AqlProperty prop2 = new AqlProperty
{
key = "npm.version",
value = "1.0.0"
};
List<AqlProperty> propertys = new List<AqlProperty> { prop1, prop2 };
AqlResult aqlResult = new()
{
Name = "animations-common_license-1.0.0.tgz",
Path = "@testfolder/-/folder",
Repo = "internalrepo1"
Repo = "internalrepo1",
properties = propertys
};

List<AqlResult> results = new List<AqlResult>() { aqlResult };
Mock<IJFrogService> mockJfrogService = new Mock<IJFrogService>();
Mock<IBomHelper> mockBomHelper = new Mock<IBomHelper>();
mockBomHelper.Setup(m => m.GetListOfComponentsFromRepo(It.IsAny<string[]>(), It.IsAny<IJFrogService>()))
mockBomHelper.Setup(m => m.GetNpmListOfComponentsFromRepo(It.IsAny<string[]>(), It.IsAny<IJFrogService>()))
.ReturnsAsync(results);
mockBomHelper.Setup(m => m.GetFullNameOfComponent(It.IsAny<Component>())).Returns("animations");
Mock<ICycloneDXBomParser> cycloneDXBomParser = new Mock<ICycloneDXBomParser>();
Expand Down Expand Up @@ -160,18 +234,30 @@ public async Task IdentificationOfInternalComponents_ReturnsComponentData3_Succe
ComponentIdentification componentIdentification = new() { comparisonBOMData = components };
string[] reooListArr = { "internalrepo1", "internalrepo1" };
CommonAppSettings appSettings = new() { InternalRepoList = reooListArr };
AqlProperty prop1 = new AqlProperty
{
key = "npm.name",
value = "animations"
};

AqlProperty prop2 = new AqlProperty
{
key = "npm.version",
value = "1.0.0"
};
List<AqlProperty> propertys = new List<AqlProperty> { prop1, prop2 };
AqlResult aqlResult = new()
{
Name = "animations-common-1.0.0.tgz",
Path = "@testfolder/-/folder",
Repo = "internalrepo1"
Repo = "internalrepo1",
properties = propertys
};

List<AqlResult> results = new List<AqlResult>() { aqlResult };
Mock<IJFrogService> mockJfrogService = new Mock<IJFrogService>();
Mock<IBomHelper> mockBomHelper = new Mock<IBomHelper>();
mockBomHelper.Setup(m => m.GetListOfComponentsFromRepo(It.IsAny<string[]>(), It.IsAny<IJFrogService>()))
mockBomHelper.Setup(m => m.GetNpmListOfComponentsFromRepo(It.IsAny<string[]>(), It.IsAny<IJFrogService>()))
.ReturnsAsync(results);
mockBomHelper.Setup(m => m.GetFullNameOfComponent(It.IsAny<Component>())).Returns("animations/common");
Mock<ICycloneDXBomParser> cycloneDXBomParser = new Mock<ICycloneDXBomParser>();
Expand Down Expand Up @@ -200,18 +286,31 @@ public async Task GetJfrogRepoDetailsOfAComponent_ReturnsWithData_SuccessFully()
string[] reooListArr = { "internalrepo1", "internalrepo1" };
CommonAppSettings appSettings = new();
appSettings.Npm = new Common.Model.Config() { JfrogNpmRepoList = reooListArr };
AqlProperty prop1 = new AqlProperty
{
key = "npm.name",
value = "animations"
};

AqlProperty prop2 = new AqlProperty
{
key = "npm.version",
value = "1.0.0"
};
List<AqlProperty> propertys = new List<AqlProperty> { prop1, prop2 };
AqlResult aqlResult = new()
{
Name = "animations-common-1.0.0.tgz",
Path = "@testfolder/-/folder",
Repo = "internalrepo1"
Repo = "internalrepo1",
properties = propertys
};

List<AqlResult> results = new List<AqlResult>() { aqlResult };

Mock<IJFrogService> mockJfrogService = new Mock<IJFrogService>();
Mock<IBomHelper> mockBomHelper = new Mock<IBomHelper>();
mockBomHelper.Setup(m => m.GetListOfComponentsFromRepo(It.IsAny<string[]>(), It.IsAny<IJFrogService>()))
mockBomHelper.Setup(m => m.GetNpmListOfComponentsFromRepo(It.IsAny<string[]>(), It.IsAny<IJFrogService>()))
.ReturnsAsync(results);
mockBomHelper.Setup(m => m.GetFullNameOfComponent(It.IsAny<Component>())).Returns("animations/common");
Mock<ICycloneDXBomParser> cycloneDXBomParser = new Mock<ICycloneDXBomParser>();
Expand Down Expand Up @@ -240,18 +339,31 @@ public async Task GetJfrogRepoDetailsOfAComponent_ReturnsWithData2_SuccessFully(
string[] reooListArr = { "internalrepo1", "internalrepo2" };
CommonAppSettings appSettings = new();
appSettings.Npm = new Common.Model.Config() { JfrogNpmRepoList = reooListArr };
AqlProperty prop1 = new AqlProperty
{
key = "npm.name",
value = "animations"
};

AqlProperty prop2 = new AqlProperty
{
key = "npm.version",
value = "1.0.0"
};
List<AqlProperty> propertys = new List<AqlProperty> { prop1, prop2 };
AqlResult aqlResult = new()
{
Name = "animations-common-1.0.0.tgz",
Path = "@testfolder/-/folder",
Repo = "internalrepo1"
Repo = "internalrepo1",
properties = propertys
};

List<AqlResult> results = new List<AqlResult>() { aqlResult };

Mock<IJFrogService> mockJfrogService = new Mock<IJFrogService>();
Mock<IBomHelper> mockBomHelper = new Mock<IBomHelper>();
mockBomHelper.Setup(m => m.GetListOfComponentsFromRepo(It.IsAny<string[]>(), It.IsAny<IJFrogService>()))
mockBomHelper.Setup(m => m.GetNpmListOfComponentsFromRepo(It.IsAny<string[]>(), It.IsAny<IJFrogService>()))
.ReturnsAsync(results);
mockBomHelper.Setup(m => m.GetFullNameOfComponent(It.IsAny<Component>())).Returns("animations");
Mock<ICycloneDXBomParser> cycloneDXBomParser = new Mock<ICycloneDXBomParser>();
Expand Down
Loading

0 comments on commit 5d05078

Please sign in to comment.