@@ -41,6 +41,8 @@ import org.ossreviewtoolkit.clients.fossid.PolymorphicList
4141import org.ossreviewtoolkit.clients.fossid.PolymorphicResponseBody
4242import org.ossreviewtoolkit.clients.fossid.addComponentIdentification
4343import org.ossreviewtoolkit.clients.fossid.addFileComment
44+ import org.ossreviewtoolkit.clients.fossid.createScan
45+ import org.ossreviewtoolkit.clients.fossid.extractArchives
4446import org.ossreviewtoolkit.clients.fossid.listIdentifiedFiles
4547import org.ossreviewtoolkit.clients.fossid.listIgnoredFiles
4648import org.ossreviewtoolkit.clients.fossid.listMarkedAsIdentifiedFiles
@@ -53,7 +55,9 @@ import org.ossreviewtoolkit.clients.fossid.model.result.MatchType
5355import org.ossreviewtoolkit.clients.fossid.model.result.MatchedLines
5456import org.ossreviewtoolkit.clients.fossid.model.result.Snippet
5557import org.ossreviewtoolkit.clients.fossid.model.status.ScanStatus
58+ import org.ossreviewtoolkit.clients.fossid.removeUploadedContent
5659import org.ossreviewtoolkit.clients.fossid.unmarkAsIdentified
60+ import org.ossreviewtoolkit.clients.fossid.uploadFile
5761import org.ossreviewtoolkit.downloader.VersionControlSystem
5862import org.ossreviewtoolkit.model.Severity
5963import org.ossreviewtoolkit.model.TextLocation
@@ -70,6 +74,7 @@ import org.ossreviewtoolkit.utils.spdx.toSpdx
7074/* * Sample files in the results. **/
7175private const val FILE_1 = " a.java"
7276private const val FILE_2 = " b.java"
77+ private const val FILE_1_ARCHIVE_MODE = " fossid-source-archive832364312005325574.zip/a.java"
7378
7479/* * A sample purl in the results. **/
7580private const val PURL_1 = " pkg:github/fakeuser/[email protected] " @@ -312,6 +317,89 @@ class FossIdSnippetChoiceTest : WordSpec({
312317 }
313318 }
314319
320+ " mark a file with all snippets chosen as identified when the scan has been created in archive mode" {
321+ val branchName = " aTestBranch"
322+ val projectCode = PROJECT
323+ val scanCode = scanCode(PROJECT , null)
324+ val config = createConfig(deltaScans = false, fetchSnippetMatchedLines = true, isArchiveMode = true)
325+ val vcsInfo = createVcsInfo()
326+ val scan = createScan(vcsInfo.url, "${vcsInfo.revision}_other ", scanCode)
327+ val pkgId = createIdentifier(index = 42)
328+
329+ val service = FossIdRestService .create(config.serverUrl)
330+ .expectProjectRequest(projectCode)
331+ .expectListScans(projectCode, listOf(scan))
332+ .expectCheckScanStatus(scanCode, ScanStatus .FINISHED )
333+ .expectCreateScan(projectCode, scanCode, vcsInfo, branchName, isArchiveMode = true)
334+ .expectRemoveUploadedContent(scanCode)
335+ .expectUploadFile(scanCode)
336+ .expectExtractArchives(scanCode)
337+ .mockFiles(
338+ scanCode,
339+ pendingFiles = listOf(FILE_1_ARCHIVE_MODE ),
340+ snippets = listOf(
341+ createSnippet(0, FILE_1 , PURL_1 )
342+ ),
343+ matchedLines = mapOf(
344+ 0 to MatchedLines .create((10..20).toList(), (10..20).toList())
345+ )
346+ )
347+ // The mark as identified call is made on the real snippet path.
348+ .expectMarkAsIdentified(scanCode, FILE_1_ARCHIVE_MODE )
349+
350+ // The snippet choice is make on the truncated snippet path.
351+ val choiceLocation = TextLocation (FILE_1 , 10, 20)
352+ val snippetChoices = createSnippetChoices(
353+ vcsInfo.url,
354+ createSnippetChoice(choiceLocation, PURL_1 , comment = "")
355+ )
356+ val fossId = createFossId(config)
357+
358+ val comment = createOrtScanComment(vcsInfo.url, vcsInfo.revision, branchName).asJsonString()
359+ val summary = fossId.scan(
360+ createPackage(pkgId, vcsInfo),
361+ snippetChoices = snippetChoices,
362+ labels = mapOf(FossId .PROJECT_REVISION_LABEL to branchName)
363+ ).summary
364+
365+ summary.snippetFindings should beEmpty()
366+ coVerify {
367+ service.createScan(USER , API_KEY , projectCode, scanCode, null, null, comment)
368+ service.removeUploadedContent(USER , API_KEY , scanCode)
369+ service.uploadFile(USER , API_KEY , scanCode, any())
370+ service.extractArchives(USER , API_KEY , scanCode, any())
371+ service.markAsIdentified(USER , API_KEY , scanCode, FILE_1_ARCHIVE_MODE , any())
372+ service.addComponentIdentification(
373+ user = USER ,
374+ apiKey = API_KEY ,
375+ scanCode = scanCode,
376+ path = FILE_1_ARCHIVE_MODE ,
377+ componentName = "fakepackage1",
378+ componentVersion = "1.0.0",
379+ isDirectory = false,
380+ preserveExistingIdentifications = true
381+ )
382+
383+ val payload = OrtCommentPayload (mapOf("MIT " to listOf(choiceLocation)), 1, 0)
384+ val jsonComment = jsonMapper.writeValueAsString(OrtComment (payload))
385+
386+ service.addFileComment(
387+ user = USER ,
388+ apiKey = API_KEY ,
389+ scanCode = scanCode,
390+ path = FILE_1_ARCHIVE_MODE ,
391+ comment = jsonComment,
392+ isImportant = false,
393+ includeInReport = false
394+ )
395+ }
396+
397+ summary.issues.forAtLeastOne {
398+ it.message shouldBe " This scan has 0 file(s) pending identification in FossID. " +
399+ " Please review and resolve them at: https://www.example.org/fossid/index.html?action=scanview&sid=1"
400+ }
401+ }
402+
315403 " mark a file with only non relevant snippets for a given snippet location as identified" {
316404 val projectCode = PROJECT
317405 val scanCode = scanCode(PROJECT , null)
@@ -952,7 +1040,7 @@ private fun createSnippetChoice(location: TextLocation, purl: String? = null, co
9521040 )
9531041 )
9541042
955- fun FossIdServiceWithVersion.mockFiles (
1043+ internal fun FossIdServiceWithVersion.mockFiles (
9561044 scanCode : String ,
9571045 markedFiles : List <MarkedAsIdentifiedFile > = emptyList(),
9581046 pendingFiles : List <String > = emptyList(),
0 commit comments