Skip to content

Commit c489487

Browse files
committed
fix: fix UploadLicenses data structure
1 parent 632e318 commit c489487

File tree

3 files changed

+103
-24
lines changed

3 files changed

+103
-24
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// ---------------------------------------------------------------------------
2+
// <copyright file="Findings.cs" company="Tethys">
3+
// Copyright (C) 2022 T. Graf
4+
// </copyright>
5+
//
6+
// Licensed under the MIT License.
7+
// SPDX-License-Identifier: MIT
8+
//
9+
// Unless required by applicable law or agreed to in writing,
10+
// software distributed under the License is distributed on an
11+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
12+
// either express or implied.
13+
// ---------------------------------------------------------------------------
14+
15+
namespace Fossology.Rest.Dotnet.Model
16+
{
17+
using System.Collections.Generic;
18+
using Newtonsoft.Json;
19+
20+
/// <summary>
21+
/// Information about the licenses of the uploaded files.
22+
/// </summary>
23+
public class Findings
24+
{
25+
/// <summary>
26+
/// Gets the short names of the licenses found by the scanner.
27+
/// </summary>
28+
[JsonProperty("scanner")]
29+
public List<string> Scanner { get; }
30+
31+
/// <summary>
32+
/// Gets the conclusions, i.e. license(s) decided by user.
33+
/// </summary>
34+
[JsonProperty("conclusions")]
35+
public List<string> Conclusions { get; }
36+
37+
/// <summary>
38+
/// Gets the copyrights.
39+
/// </summary>
40+
[JsonProperty("copyright")]
41+
public List<string> Copyrights { get; }
42+
43+
/// <summary>
44+
/// Initializes a new instance of the <see cref="Findings"/> class.
45+
/// </summary>
46+
public Findings()
47+
{
48+
this.Scanner = new List<string>();
49+
this.Conclusions = new List<string>();
50+
this.Copyrights = new List<string>();
51+
} // UploadLicenses()
52+
53+
/// <inheritdoc />
54+
public override string ToString()
55+
{
56+
return $"S={Support.ListToString(this.Scanner)}, C={Support.ListToString(this.Conclusions)}: Copy={Support.ListToString(this.Copyrights)}";
57+
} // ToString()
58+
} // Findings
59+
}
Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// ---------------------------------------------------------------------------
22
// <copyright file="UploadLicenses.cs" company="Tethys">
3-
// Copyright (C) 2020 T. Graf
3+
// Copyright (C) 2020-2022 T. Graf
44
// </copyright>
55
//
66
// Licensed under the MIT License.
@@ -14,7 +14,6 @@
1414

1515
namespace Fossology.Rest.Dotnet.Model
1616
{
17-
using System.Collections.Generic;
1817
using Newtonsoft.Json;
1918

2019
/// <summary>
@@ -29,30 +28,23 @@ public class UploadLicenses
2928
public string FilePath { get; set; }
3029

3130
/// <summary>
32-
/// Gets the short names of the found licenses.
31+
/// Gets the findings for this file.
3332
/// </summary>
34-
[JsonProperty("agentFindings")]
35-
public List<string> AgentFindings { get; }
36-
37-
/// <summary>
38-
/// Gets the conclusions, i.e. license(s) decided by user.
39-
/// </summary>
40-
[JsonProperty("conclusions")]
41-
public List<string> Conclusions { get; }
33+
[JsonProperty("findings")]
34+
public Findings Findings { get; }
4235

4336
/// <summary>
4437
/// Initializes a new instance of the <see cref="UploadLicenses"/> class.
4538
/// </summary>
4639
public UploadLicenses()
4740
{
48-
this.AgentFindings = new List<string>();
49-
this.Conclusions = new List<string>();
41+
this.Findings = new Findings();
5042
} // UploadLicenses()
5143

5244
/// <inheritdoc />
5345
public override string ToString()
5446
{
55-
return $"{this.FilePath}: C={Support.ListToString(this.Conclusions)}: F={Support.ListToString(this.AgentFindings)}";
47+
return $"{this.FilePath}: {this.Findings}";
5648
} // ToString()
5749
} // UploadLicenses
5850
}

Fossology.Rest.Dotnet.Test/DeserializationTest.cs

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -88,21 +88,49 @@ public void TestSerializeStringList()
8888
/// Unit test.
8989
/// </summary>
9090
[TestMethod]
91-
public void TestDeserializeComplex1()
91+
public void TestDeserializeFindings()
9292
{
9393
const string JsonText =
94-
"{"
95-
+ "\"filePath\":\"fetch-retry-master.zip/fetch-retry-master/package.json\","
96-
+ "\"agentFindings\":[\"MIT\"],"
97-
+ "\"conclusions\":null"
98-
+ "}";
94+
"{" +
95+
"\"scanner\":[" +
96+
"\"No_license_found\"" +
97+
"]," +
98+
"\"conclusion\":null," +
99+
"\"copyright\":null" +
100+
"}";
99101

100-
var actual = JsonConvert.DeserializeObject<UploadLicenses>(JsonText);
102+
var actual = JsonConvert.DeserializeObject<Findings>(JsonText);
101103
Assert.IsNotNull(actual);
102-
Assert.IsNotNull(actual.AgentFindings);
103-
Assert.AreEqual(1, actual.AgentFindings.Count);
104+
Assert.AreEqual(1, actual.Scanner.Count);
105+
Assert.AreEqual("No_license_found", actual.Scanner[0]);
106+
Assert.AreEqual(0, actual.Copyrights.Count);
107+
Assert.AreEqual(0, actual.Copyrights.Count);
108+
}
104109

105-
// ==> no correct deserialization without constructor...
110+
/// <summary>
111+
/// Unit test.
112+
/// </summary>
113+
[TestMethod]
114+
public void TestDeserializeUploadLicenses()
115+
{
116+
const string JsonText =
117+
"[" +
118+
"{" +
119+
"\"filePath\":\"Tethys.xml_v1.0.0.zip/Tethys.Xml-1.0.0/Tethys.Xml.sln\"," +
120+
"\"findings\":" +
121+
"{" +
122+
"\"scanner\":[" +
123+
"\"No_license_found\"" +
124+
"]," +
125+
"\"conclusion\":null," +
126+
"\"copyright\":null" +
127+
"}" +
128+
"}" +
129+
"]";
130+
131+
var actual = JsonConvert.DeserializeObject<List<UploadLicenses>>(JsonText);
132+
Assert.IsNotNull(actual);
133+
Assert.AreEqual(1, actual.Count);
106134
}
107135
}
108136
}

0 commit comments

Comments
 (0)