-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #210 from siemens/feat/codecoverage_sep10
Feat/codecoverage sep10
- Loading branch information
Showing
71 changed files
with
3,028 additions
and
360 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,11 +7,9 @@ | |
using LCT.APICommunications.Interfaces; | ||
using LCT.APICommunications.Model; | ||
using Moq; | ||
using Newtonsoft.Json; | ||
using System.Net; | ||
using LCT.ArtifactoryUploader; | ||
using System.Net.Http; | ||
using System; | ||
using NUnit.Framework; | ||
using System.Threading.Tasks; | ||
using LCT.APICommunications; | ||
|
@@ -22,9 +20,12 @@ | |
using LCT.Services; | ||
using UnitTestUtilities; | ||
using LCT.ArtifactoryUploader.Model; | ||
using LCT.APICommunications.Model.AQL; | ||
using System; | ||
|
||
namespace AritfactoryUploader.UTest | ||
{ | ||
[TestFixture] | ||
public class ArtifactoryUploader | ||
{ | ||
[SetUp] | ||
|
@@ -97,5 +98,175 @@ private static IJFrogService GetJfrogService(CommonAppSettings appSettings) | |
IJFrogService jFrogService = new JFrogService(jFrogApiCommunicationFacade); | ||
return jFrogService; | ||
} | ||
|
||
[Test] | ||
public async Task UploadPackageToRepo_WhenPackageInfoIsNull_ReturnsNotFoundResponse() | ||
{ | ||
// Arrange | ||
var component = new ComponentsToArtifactory(); | ||
component.SrcRepoName = ""; | ||
component.DestRepoName = ""; | ||
component.JfrogPackageName = ""; | ||
component.Path = ""; | ||
var timeout = 10000; | ||
var displayPackagesInfo = new DisplayPackagesInfo(); | ||
var jFrogServiceMock = new Mock<IJFrogService>(); | ||
jFrogServiceMock.Setup(x => x.GetPackageInfo(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>())) | ||
.ReturnsAsync((AqlResult)null); | ||
ArtfactoryUploader.jFrogService = jFrogServiceMock.Object; | ||
// Act | ||
var response = await ArtfactoryUploader.UploadPackageToRepo(component, timeout, displayPackagesInfo); | ||
|
||
// Assert | ||
Assert.AreEqual(HttpStatusCode.NotFound, response.StatusCode); | ||
Assert.AreEqual(ApiConstant.PackageNotFound, response.ReasonPhrase); | ||
} | ||
|
||
[Test] | ||
public async Task UploadPackageToRepo_WhenPackageTypeIsClearedThirdPartyOrDevelopment_CallsCopyFromRemoteRepo() | ||
{ | ||
// Arrange | ||
var component = new ComponentsToArtifactory | ||
{ | ||
PackageType = PackageType.ClearedThirdParty, | ||
ApiKey = "apiKey", | ||
Email = "[email protected]" | ||
}; | ||
component.SrcRepoName = ""; | ||
component.DestRepoName = ""; | ||
component.JfrogPackageName = ""; | ||
component.Path = ""; | ||
var timeout = 10000; | ||
var displayPackagesInfo = new DisplayPackagesInfo(); | ||
var jFrogServiceMock = new Mock<IJFrogService>(); | ||
var jfrogApicommunicationMock = new Mock<IJFrogApiCommunication>(); | ||
jFrogServiceMock.Setup(x => x.GetPackageInfo(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>())) | ||
.ReturnsAsync(new AqlResult()); | ||
jfrogApicommunicationMock.Setup(x => x.CopyFromRemoteRepo(It.IsAny<ComponentsToArtifactory>())) | ||
.ReturnsAsync(new HttpResponseMessage(HttpStatusCode.OK)); | ||
ArtfactoryUploader.jFrogService = jFrogServiceMock.Object; | ||
ArtfactoryUploader.JFrogApiCommInstance = jfrogApicommunicationMock.Object; | ||
// Act | ||
_= await ArtfactoryUploader.UploadPackageToRepo(component, timeout, displayPackagesInfo); | ||
|
||
// Assert | ||
jfrogApicommunicationMock.Verify(x => x.CopyFromRemoteRepo(component), Times.Once); | ||
} | ||
|
||
[Test] | ||
public async Task UploadPackageToRepo_WhenPackageTypeIsInternal_CallsMoveFromRepo() | ||
{ | ||
// Arrange | ||
var component = new ComponentsToArtifactory | ||
{ | ||
PackageType = PackageType.Internal, | ||
ApiKey = "apiKey", | ||
Email = "[email protected]" | ||
}; | ||
component.SrcRepoName = ""; | ||
component.DestRepoName = ""; | ||
component.JfrogPackageName = ""; | ||
component.Path = ""; | ||
var timeout = 10000; | ||
var displayPackagesInfo = new DisplayPackagesInfo(); | ||
var jFrogServiceMock = new Mock<IJFrogService>(); | ||
var jfrogApicommunicationMock = new Mock<IJFrogApiCommunication>(); | ||
jFrogServiceMock.Setup(x => x.GetPackageInfo(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>())) | ||
.ReturnsAsync(new AqlResult()); | ||
jfrogApicommunicationMock.Setup(x => x.MoveFromRepo(It.IsAny<ComponentsToArtifactory>())) | ||
.ReturnsAsync(new HttpResponseMessage(HttpStatusCode.OK)); | ||
ArtfactoryUploader.jFrogService = jFrogServiceMock.Object; | ||
ArtfactoryUploader.JFrogApiCommInstance = jfrogApicommunicationMock.Object; | ||
// Act | ||
var response = await ArtfactoryUploader.UploadPackageToRepo(component, timeout, displayPackagesInfo); | ||
|
||
// Assert | ||
jfrogApicommunicationMock.Verify(x => x.MoveFromRepo(component), Times.Once); | ||
Assert.AreEqual(HttpStatusCode.OK, response.StatusCode); | ||
} | ||
|
||
[Test] | ||
public async Task UploadPackageToRepo_WhenPackageTypeIsNotSupported_ReturnsNotFoundResponse() | ||
{ | ||
// Arrange | ||
var component = new ComponentsToArtifactory | ||
{ | ||
PackageType = PackageType.Unknown, | ||
ApiKey = "apiKey", | ||
Email = "[email protected]" | ||
}; | ||
component.SrcRepoName = ""; | ||
component.DestRepoName = ""; | ||
component.JfrogPackageName = ""; | ||
component.Path = ""; | ||
var timeout = 10000; | ||
var displayPackagesInfo = new DisplayPackagesInfo(); | ||
var jFrogServiceMock = new Mock<IJFrogService>(); | ||
ArtfactoryUploader.jFrogService = jFrogServiceMock.Object; | ||
// Act | ||
var response = await ArtfactoryUploader.UploadPackageToRepo(component, timeout, displayPackagesInfo); | ||
|
||
// Assert | ||
Assert.AreEqual(HttpStatusCode.NotFound, response.StatusCode); | ||
} | ||
[Test] | ||
public async Task UploadPackageToRepo_WhenHttpRequestExceptionOccurs_ReturnsErrorResponse() | ||
{ | ||
// Arrange | ||
var component = new ComponentsToArtifactory | ||
{ | ||
PackageType = PackageType.Unknown, | ||
ApiKey = "apiKey", | ||
Email = "[email protected]" | ||
}; | ||
component.SrcRepoName = ""; | ||
component.DestRepoName = ""; | ||
component.JfrogPackageName = ""; | ||
component.Path = ""; | ||
var timeout = 10000; | ||
var displayPackagesInfo = new DisplayPackagesInfo(); | ||
var jFrogServiceMock = new Mock<IJFrogService>(); | ||
var jfrogApicommunicationMock = new Mock<IJFrogApiCommunication>(); | ||
jFrogServiceMock.Setup(x => x.GetPackageInfo(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>())) | ||
.ThrowsAsync(new HttpRequestException()); | ||
ArtfactoryUploader.jFrogService = jFrogServiceMock.Object; | ||
ArtfactoryUploader.JFrogApiCommInstance = jfrogApicommunicationMock.Object; | ||
|
||
// Act | ||
var response = await ArtfactoryUploader.UploadPackageToRepo(component, timeout, displayPackagesInfo); | ||
|
||
// Assert | ||
Assert.AreEqual(ApiConstant.ErrorInUpload, response.ReasonPhrase); | ||
} | ||
|
||
[Test] | ||
public async Task UploadPackageToRepo_WhenInvalidOperationExceptionOccurs_ReturnsErrorResponse() | ||
{ | ||
// Arrange | ||
var component = new ComponentsToArtifactory | ||
{ | ||
PackageType = PackageType.Unknown, | ||
ApiKey = "apiKey", | ||
Email = "[email protected]" | ||
}; | ||
component.SrcRepoName = ""; | ||
component.DestRepoName = ""; | ||
component.JfrogPackageName = ""; | ||
component.Path = ""; | ||
var timeout = 10000; | ||
var displayPackagesInfo = new DisplayPackagesInfo(); | ||
var jFrogServiceMock = new Mock<IJFrogService>(); | ||
var jfrogApicommunicationMock = new Mock<IJFrogApiCommunication>(); | ||
jFrogServiceMock.Setup(x => x.GetPackageInfo(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>())) | ||
.ThrowsAsync(new InvalidOperationException()); | ||
ArtfactoryUploader.jFrogService = jFrogServiceMock.Object; | ||
ArtfactoryUploader.JFrogApiCommInstance = jfrogApicommunicationMock.Object; | ||
|
||
// Act | ||
var response = await ArtfactoryUploader.UploadPackageToRepo(component, timeout, displayPackagesInfo); | ||
|
||
// Assert | ||
Assert.AreEqual(ApiConstant.ErrorInUpload, response.ReasonPhrase); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -83,5 +83,29 @@ public void ValidateArtifactoryCredentials_InputAppsettings_ThrowsInvalidDataExc | |
// assert will not pass always | ||
// Assert.ThrowsAsync<InvalidDataException>(async () => await artifactoryValidator.ValidateArtifactoryCredentials(appSettings)) | ||
} | ||
|
||
[Test] | ||
public async Task ValidateArtifactoryCredentials_InputAppsettings_ThrowsHttpRequestException() | ||
{ | ||
// Arrange | ||
CommonAppSettings appSettings = new CommonAppSettings() | ||
{ | ||
ArtifactoryUploadApiKey = "tyyteye", | ||
ArtifactoryUploadUser = "[email protected]" | ||
}; | ||
ArtifactoryCredentials artifactoryCredentials = new ArtifactoryCredentials() | ||
{ | ||
ApiKey = "tyyteye", | ||
Email = "[email protected]" | ||
}; | ||
Mock<NpmJfrogApiCommunication> jfrogCommunicationMck = new Mock<NpmJfrogApiCommunication>(UTParams.JFrogURL, "test", artifactoryCredentials, 100); | ||
ArtifactoryValidator artifactoryValidator = new ArtifactoryValidator(jfrogCommunicationMck.Object); | ||
jfrogCommunicationMck.Setup(x => x.GetApiKey()).ThrowsAsync(new HttpRequestException()); | ||
|
||
// Act and Assert | ||
var isvalid= await artifactoryValidator.ValidateArtifactoryCredentials(appSettings); | ||
Assert.AreEqual(-1, isvalid); | ||
|
||
} | ||
} | ||
} |
Oops, something went wrong.