Skip to content

Commit f16fa00

Browse files
committed
feat: tests improved
1 parent 4be425d commit f16fa00

File tree

1 file changed

+32
-8
lines changed

1 file changed

+32
-8
lines changed

Fossology.Rest.Dotnet.Test/FossologyClientTest.cs

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@ public class FossologyClientTest
4343
/// <summary>
4444
/// The access token.
4545
/// </summary>
46-
private const string Token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE1OTM1NjE1OTksIm5iZiI6MTU5MjI2NTYwMCwianRpIjoiTWk0eiIsInNjb3BlIjoid3JpdGUifQ.h9oNRGV_N-GkEJGNZPp2qQCgOkb1rDv0_bnEnWjCnkg";
46+
private const string Token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE1OTM2NDc5OTksIm5iZiI6MTU5MzA0MzIwMCwianRpIjoiTWk0eiIsInNjb3BlIjoid3JpdGUifQ.YsZLPym6rRUdBsEtEderJS2Xlj09DOG0J3z0Ygbv8MI";
4747

4848
/// <summary>
4949
/// The filename of a test package.
5050
/// </summary>
51-
private const string Filename = @"..\..\..\TestData\fetch-retry-master.zip";
51+
private const string Filename = @"..\..\..\..\TestData\fetch-retry-master.zip";
5252

5353
/// <summary>
5454
/// The test folder name.
@@ -335,7 +335,7 @@ public void TestGetUploadList()
335335
[TestMethod]
336336
public void TestGetUploadLicenses()
337337
{
338-
const int Id = 5;
338+
const int Id = 2;
339339

340340
var client = new FossologyClient(LocalUrl, Token);
341341
var licenses = client.GetUploadLicenses(Id, "nomos", true);
@@ -547,22 +547,24 @@ public void MyIntegrationTestLikeUnitTest()
547547
{
548548
const string ReportFilename = "Report.spdx2.rdf";
549549

550-
var client = new FossologyClient(LocalUrl, Token);
550+
var client = new FossologyClient(LocalUrl, string.Empty);
551551

552552
var version = client.GetVersion();
553553
Assert.IsNotNull(version);
554554
Debug.WriteLine($"Version = {version}");
555555

556556
var request = new TokenRequest();
557+
var guid = Guid.NewGuid();
557558
request.Username = "fossy";
558559
request.Password = "fossy";
559-
request.TokenName = "TestToken1";
560+
request.TokenName = guid.ToString();
560561
request.TokenScope = "write";
561562
request.TokenExpire = DateTime.Today.AddDays(3).ToString("yyyy-MM-dd");
562563
var tokenResult = client.GetToken(request);
563564
Assert.IsNotNull(tokenResult);
564565
Assert.IsTrue(tokenResult.Length > 20);
565566

567+
client = new FossologyClient(LocalUrl, tokenResult);
566568
var folderlist = client.GetFolderList();
567569
Assert.IsNotNull(folderlist);
568570
if ((folderlist.Count != 1) && (folderlist.Count != 2))
@@ -646,11 +648,13 @@ public void MyIntegrationTestLikeUnitTest()
646648
var job = client.GetJob(jobId);
647649
Assert.IsNotNull(job);
648650
Assert.AreEqual(jobId, job.Id);
651+
WaitUntilJobIsDone(client, jobId);
649652

650653
// PHP Fatal error: Uncaught Exception: cannot find uploadId = 14 in /usr/local/share/fossology/lib/php/Dao/UploadDao.php:201
651-
////var summary = client.GetUploadSummary(uploadId);
652-
////Assert.IsNotNull(summary);
653-
////Assert.AreEqual(uploadId, summary.Id);
654+
var summary = client.GetUploadSummary(uploadId);
655+
Assert.IsNotNull(summary);
656+
Assert.AreEqual(uploadId, summary.Id);
657+
654658
var licensesFound = client.GetUploadLicenses(
655659
uploadId, "nomos", true);
656660
Assert.IsNotNull(licensesFound);
@@ -694,6 +698,26 @@ private static void WaitUntilUploadIsDone(FossologyClient client, int id)
694698
} // while
695699
}
696700

701+
/// <summary>
702+
/// Waits the until the given job is done.
703+
/// </summary>
704+
/// <param name="client">The client.</param>
705+
/// <param name="id">The job identifier.</param>
706+
private static void WaitUntilJobIsDone(FossologyClient client, int id)
707+
{
708+
while (true)
709+
{
710+
var job = client.GetJob(id);
711+
if (job.Status == "Completed")
712+
{
713+
return;
714+
} // if
715+
716+
Debug.WriteLine($"Waiting for job {id} to complete...");
717+
Thread.Sleep(500);
718+
} // while
719+
}
720+
697721
/// <summary>
698722
/// Finds the folder with the given name.
699723
/// </summary>

0 commit comments

Comments
 (0)