Skip to content

Commit

Permalink
SonarQube fixes for release 6.2.0 (#151)
Browse files Browse the repository at this point in the history
* sonar qube fixed and adding UT
---------

Co-authored-by: Aditya Narayan <[email protected]>
  • Loading branch information
adityanarayanp and Aditya Narayan authored Apr 17, 2024
1 parent a6d7da1 commit b5ca02d
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 20 deletions.
2 changes: 0 additions & 2 deletions src/ArtifactoryUploader/ArtifactoryValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ namespace LCT.ArtifactoryUploader
{
public class ArtifactoryValidator
{
static readonly ILog Logger = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);

private readonly NpmJfrogApiCommunication JfrogApiCommunication;

public ArtifactoryValidator(NpmJfrogApiCommunication jfrogApiCommunication)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// --------------------------------------------------------------------------------------------------------------------
// SPDX-FileCopyrightText: 2024 Siemens AG
//
// SPDX-License-Identifier: MIT
// --------------------------------------------------------------------------------------------------------------------


using LCT.APICommunications.Model;

namespace LCT.APICommunications.UTest
{
public class DebainJfrogAPICommunicationUTest
{
[SetUp]
public void Setup()
{
// Method intentionally left empty.
}

[Test]
public void DebainJfrogApiCommunication_CopyFromRemoteRepo_ReturnsInvalidOperationException()
{
//Arrange
ArtifactoryCredentials repoCredentials = new ArtifactoryCredentials();

//Act
JfrogApicommunication jfrogApicommunication = new DebianJfrogAPICommunication("", "", repoCredentials,100);

//Assert
Assert.ThrowsAsync<InvalidOperationException>(async () => await jfrogApicommunication.CopyFromRemoteRepo(new ComponentsToArtifactory()));
}

[Test]
public void DebainJfrogApiCommunication_UpdatePackagePropertiesInJfrog_ReturnsInvalidOperationException()
{
//Arrange
ArtifactoryCredentials repoCredentials = new ArtifactoryCredentials();

//Act
JfrogApicommunication jfrogApicommunication = new DebianJfrogAPICommunication("", "", repoCredentials, 100);

//Assert
Assert.ThrowsAsync<InvalidOperationException>(() => { jfrogApicommunication.UpdatePackagePropertiesInJfrog("", "", new UploadArgs()); return Task.CompletedTask; });
}

[Test]
public void DebainJfrogApiCommunication_GetPackageInfo_ReturnsInvalidOperationException()
{
//Arrange
ArtifactoryCredentials repoCredentials = new ArtifactoryCredentials();

//Act
JfrogApicommunication jfrogApicommunication = new DebianJfrogAPICommunication("", "", repoCredentials, 100);

//Assert
Assert.ThrowsAsync<InvalidOperationException>(async () => await jfrogApicommunication.GetPackageInfo(new ComponentsToArtifactory()));
}
}
}
2 changes: 1 addition & 1 deletion src/LCT.PackageIdentifier/NpmProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ private static void CheckAndAddToBundleComponents(List<BundledComponents> bundle
}


private void GetComponentsForBom(string filepath, CommonAppSettings appSettings,
private static void GetComponentsForBom(string filepath, CommonAppSettings appSettings,
ref List<BundledComponents> bundledComponents, ref List<Component> lstComponentForBOM,
ref int noOfDevDependent, IEnumerable<JProperty> depencyComponentList)
{
Expand Down
5 changes: 2 additions & 3 deletions src/LCT.PackageIdentifier/NugetProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ public Bom ParsePackageFile(CommonAppSettings appSettings)
List<Component> listComponentForBOM = new List<Component>();
Bom bom = new Bom();
int totalComponentsIdentified = 0;
int noOfExcludedComponents = 0;

ParsingInputFileForBOM(appSettings, ref listComponentForBOM, ref bom);
totalComponentsIdentified = listComponentForBOM.Count;
Expand All @@ -59,7 +58,7 @@ public Bom ParsePackageFile(CommonAppSettings appSettings)
var componentsWithMultipleVersions = listComponentForBOM.GroupBy(s => s.Name)
.Where(g => g.Count() > 1).SelectMany(g => g).ToList();

CheckForMultipleVersions(appSettings, ref listComponentForBOM, ref noOfExcludedComponents, componentsWithMultipleVersions);
CheckForMultipleVersions(appSettings, componentsWithMultipleVersions);

Logger.Debug($"ParsePackageFile():End");
bom.Components = listComponentForBOM;
Expand Down Expand Up @@ -511,7 +510,7 @@ private static void ParseInputFiles(CommonAppSettings appSettings, string filepa
}


private static void CheckForMultipleVersions(CommonAppSettings appSettings, ref List<Component> listComponentForBOM, ref int noOfExcludedComponents, List<Component> componentsWithMultipleVersions)
private static void CheckForMultipleVersions(CommonAppSettings appSettings, List<Component> componentsWithMultipleVersions)
{

if (componentsWithMultipleVersions.Count != 0)
Expand Down
2 changes: 1 addition & 1 deletion src/LCT.SW360PackageCreator/ComponentCreator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ private static async Task<List<ReleaseLinked>> GetManuallyLinkedReleasesFromProj
return manuallyLinkedReleases;
}

private async Task<List<ReleaseLinked>> GetAlreadyLinkedReleasesByProjectId(string projectId, ISw360ProjectService sw360ProjectService)
private static async Task<List<ReleaseLinked>> GetAlreadyLinkedReleasesByProjectId(string projectId, ISw360ProjectService sw360ProjectService)
{
List<ReleaseLinked> alreadyLinkedReleases = await sw360ProjectService.GetAlreadyLinkedReleasesByProjectId(projectId);
return alreadyLinkedReleases;
Expand Down
13 changes: 0 additions & 13 deletions src/LCT.Services/Sw360CreatorService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -350,19 +350,6 @@ public async Task<string> GetReleaseIdByName(string componentName, string compon
return releaseid ?? string.Empty;
}

private async Task UpdateLinkedReleaseComment(string projectId, List<string> releaseIDList)
{
UpdateLinkedRelease updateLinkedRelease = new UpdateLinkedRelease() { Comment = Dataconstant.LinkedByCATool };
foreach (string releaseId in releaseIDList)
{
var updateResponse = await m_SW360ApiCommunicationFacade.UpdateLinkedRelease(projectId, releaseId, updateLinkedRelease);
if (!updateResponse.IsSuccessStatusCode)
{
Logger.Debug($"UpdateLinkedReleaseComment() : Updating comment to linked release id -{releaseId} of preoject - {projectId} is failed.");
}
}
}

private static string GetReleaseIdFromResponse(string componentName, string componentVersion, string releaseid, string responseBody)
{
var responseData = JsonConvert.DeserializeObject<ReleaseIdOfComponent>(responseBody);
Expand Down

0 comments on commit b5ca02d

Please sign in to comment.