-
Notifications
You must be signed in to change notification settings - Fork 4
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 #63 from leanix/feature/CID-2058/enhance-test-suite
CID-2058 Enhance test suite
- Loading branch information
Showing
14 changed files
with
508 additions
and
7 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
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
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
43 changes: 42 additions & 1 deletion
43
src/test/kotlin/net/leanix/vsm/sbomBooster/VsmSbomBoosterApplicationTests.kt
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 |
---|---|---|
@@ -1,6 +1,47 @@ | ||
package net.leanix.vsm.sbomBooster | ||
|
||
import com.ninjasquad.springmockk.MockkBean | ||
import net.leanix.vsm.sbomBooster.service.BitBucketApiService | ||
import net.leanix.vsm.sbomBooster.service.ExitScheduler | ||
import net.leanix.vsm.sbomBooster.service.GitHubApiService | ||
import net.leanix.vsm.sbomBooster.service.GitLabApiService | ||
import net.leanix.vsm.sbomBooster.service.MtMService | ||
import net.leanix.vsm.sbomBooster.service.OrtService | ||
import net.leanix.vsm.sbomBooster.service.SummaryReportService | ||
import net.leanix.vsm.sbomBooster.service.VsmDiscoveryService | ||
import org.springframework.beans.factory.annotation.Autowired | ||
import org.springframework.boot.test.context.SpringBootTest | ||
import java.util.concurrent.ThreadPoolExecutor | ||
|
||
@SpringBootTest | ||
class VsmSbomBoosterApplicationTests | ||
class VsmSbomBoosterApplicationTests { | ||
@MockkBean | ||
internal lateinit var threadPoolExecutor: ThreadPoolExecutor | ||
|
||
@MockkBean(name = "taskExecutor") | ||
internal lateinit var taskExecutor: ThreadPoolExecutor | ||
|
||
@MockkBean | ||
internal lateinit var exitScheduler: ExitScheduler | ||
|
||
@MockkBean(relaxed = true) | ||
internal lateinit var summaryReportService: SummaryReportService | ||
|
||
@MockkBean | ||
internal lateinit var vsmDiscoveryService: VsmDiscoveryService | ||
|
||
@MockkBean(relaxed = true) | ||
internal lateinit var mtMService: MtMService | ||
|
||
@Autowired | ||
internal lateinit var bitBucketApiService: BitBucketApiService | ||
|
||
@Autowired | ||
internal lateinit var gitHubApiService: GitHubApiService | ||
|
||
@Autowired | ||
internal lateinit var gitLabApiService: GitLabApiService | ||
|
||
@Autowired | ||
internal lateinit var ortService: OrtService | ||
} |
52 changes: 52 additions & 0 deletions
52
src/test/kotlin/net/leanix/vsm/sbomBooster/VsmSbomBoosterBitBucketApplicationTests.kt
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 |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package net.leanix.vsm.sbomBooster | ||
|
||
import io.mockk.verify | ||
import net.leanix.vsm.sbomBooster.configuration.BitBucketTestConfiguration | ||
import org.junit.jupiter.api.Test | ||
import org.springframework.context.annotation.Import | ||
|
||
@Import(BitBucketTestConfiguration::class) | ||
class VsmSbomBoosterBitBucketApplicationTests : VsmSbomBoosterApplicationTests() { | ||
|
||
@Test | ||
fun `test BitBucket integration`() { | ||
verify(exactly = 1) { | ||
summaryReportService.appendRecord( | ||
"BITBUCKET_WORKSPACE: bitbucketWorkspace\n" | ||
) | ||
} | ||
verify(exactly = 1) { bitBucketApiService.getUsername("") } | ||
verify(exactly = 1) { | ||
bitBucketApiService | ||
.getRepositories("bitbucketKey:bitbucketSecret", "bitbucketWorkspace") | ||
} | ||
verify(exactly = 1) { | ||
ortService.downloadProject( | ||
"cloneUrl1", | ||
"bitbucketUsername", | ||
"bitbucketToken", | ||
) | ||
} | ||
verify(exactly = 1) { | ||
ortService.downloadProject( | ||
"cloneUrl2", | ||
"bitbucketUsername", | ||
"bitbucketToken", | ||
) | ||
} | ||
verify(exactly = 1) { | ||
ortService.analyzeProject( | ||
"cloneUrl1", | ||
"downloadedFolder", | ||
) | ||
} | ||
verify(exactly = 1) { | ||
ortService.analyzeProject( | ||
"cloneUrl2", | ||
"downloadedFolder", | ||
) | ||
} | ||
verify(exactly = 1) { ortService.generateSbom("cloneUrl1") } | ||
verify(exactly = 1) { ortService.generateSbom("cloneUrl2") } | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
src/test/kotlin/net/leanix/vsm/sbomBooster/VsmSbomBoosterGitHubApplicationTests.kt
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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package net.leanix.vsm.sbomBooster | ||
|
||
import io.mockk.verify | ||
import net.leanix.vsm.sbomBooster.configuration.GitHubTestConfiguration | ||
import org.junit.jupiter.api.Test | ||
import org.springframework.context.annotation.Import | ||
|
||
@Import(GitHubTestConfiguration::class) | ||
class VsmSbomBoosterGitHubApplicationTests : VsmSbomBoosterApplicationTests() { | ||
@Test | ||
fun `test GitHub integration`() { | ||
verify(exactly = 1) { | ||
summaryReportService.appendRecord( | ||
"GITHUB_ORGANIZATION: githubOrganization\n" | ||
) | ||
} | ||
verify(exactly = 1) { gitHubApiService.getUsername("githubToken") } | ||
verify(exactly = 1) { gitHubApiService.getRepositories("githubToken", "githubOrganization") } | ||
verify(exactly = 1) { | ||
ortService.downloadProject( | ||
"cloneUrl1", | ||
"githubUsername", | ||
"githubToken", | ||
) | ||
} | ||
verify(exactly = 1) { | ||
ortService.downloadProject( | ||
"cloneUrl2", | ||
"githubUsername", | ||
"githubToken", | ||
) | ||
} | ||
verify(exactly = 1) { | ||
ortService.analyzeProject( | ||
"cloneUrl1", | ||
"downloadedFolder" | ||
) | ||
} | ||
verify(exactly = 1) { | ||
ortService.analyzeProject( | ||
"cloneUrl2", | ||
"downloadedFolder" | ||
) | ||
} | ||
verify(exactly = 1) { ortService.generateSbom("cloneUrl1") } | ||
verify(exactly = 1) { ortService.generateSbom("cloneUrl2") } | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
src/test/kotlin/net/leanix/vsm/sbomBooster/VsmSbomBoosterGitLabApplicationTests.kt
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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package net.leanix.vsm.sbomBooster | ||
|
||
import io.mockk.verify | ||
import net.leanix.vsm.sbomBooster.configuration.GitLabTestConfiguration | ||
import org.junit.jupiter.api.Test | ||
import org.springframework.context.annotation.Import | ||
|
||
@Import(GitLabTestConfiguration::class) | ||
class VsmSbomBoosterGitLabApplicationTests : VsmSbomBoosterApplicationTests() { | ||
@Test | ||
fun `test GitLab integration`() { | ||
verify(exactly = 1) { | ||
summaryReportService.appendRecord( | ||
"GITLAB_GROUP: gitlabGroup\n" | ||
) | ||
} | ||
verify(exactly = 1) { gitLabApiService.getUsername("gitlabToken") } | ||
verify(exactly = 1) { gitLabApiService.getRepositories("gitlabToken", "gitlabGroup") } | ||
verify(exactly = 1) { | ||
ortService.downloadProject( | ||
"cloneUrl1", | ||
"gitlabUsername", | ||
"gitlabToken", | ||
) | ||
} | ||
verify(exactly = 1) { | ||
ortService.downloadProject( | ||
"cloneUrl2", | ||
"gitlabUsername", | ||
"gitlabToken", | ||
) | ||
} | ||
verify(exactly = 1) { | ||
ortService.analyzeProject( | ||
"cloneUrl1", | ||
"downloadedFolder" | ||
) | ||
} | ||
verify(exactly = 1) { | ||
ortService.analyzeProject( | ||
"cloneUrl2", | ||
"downloadedFolder" | ||
) | ||
} | ||
verify(exactly = 1) { ortService.generateSbom("cloneUrl1") } | ||
verify(exactly = 1) { ortService.generateSbom("cloneUrl2") } | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
src/test/kotlin/net/leanix/vsm/sbomBooster/configuration/BitBucketTestConfiguration.kt
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 |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package net.leanix.vsm.sbomBooster.configuration | ||
|
||
import com.ninjasquad.springmockk.MockkBean | ||
import io.mockk.every | ||
import jakarta.annotation.PostConstruct | ||
import net.leanix.vsm.sbomBooster.domain.Repository | ||
import net.leanix.vsm.sbomBooster.service.BitBucketApiService | ||
import org.springframework.boot.test.context.TestConfiguration | ||
|
||
@TestConfiguration | ||
class BitBucketTestConfiguration : GenericTestConfiguration() { | ||
|
||
@MockkBean | ||
private lateinit var bitBucketApiService: BitBucketApiService | ||
|
||
@PostConstruct | ||
fun prepare() { | ||
every { propertiesConfiguration.bitbucketKey } returns "bitbucketKey" | ||
every { propertiesConfiguration.gitProvider } returns "bitbucket" | ||
every { propertiesConfiguration.bitbucketSecret } returns "bitbucketSecret" | ||
every { propertiesConfiguration.bitbucketWorkspace } returns "bitbucketWorkspace" | ||
every { propertiesConfiguration.bitbucketKey } returns "bitbucketKey" | ||
|
||
every { bitBucketApiService.getUsername("") } returns "bitbucketUsername" | ||
every { bitBucketApiService.authenticate("bitbucketKey:bitbucketSecret") } returns "bitbucketToken" | ||
every { | ||
bitBucketApiService | ||
.getRepositories("bitbucketKey:bitbucketSecret", "bitbucketWorkspace") | ||
} returns listOf( | ||
Repository( | ||
"cloneUrl1", | ||
"sourceType", | ||
"sourceInstance", | ||
"repositoryName1", | ||
"repositoryId1" | ||
), | ||
Repository( | ||
"cloneUrl2", | ||
"sourceType", | ||
"sourceInstance", | ||
"repositoryName2", | ||
"repositoryId2" | ||
) | ||
) | ||
|
||
every { | ||
ortService.downloadProject( | ||
any(), | ||
"bitbucketUsername", | ||
"bitbucketToken" | ||
) | ||
} returns "downloadedFolder" | ||
every { ortService.analyzeProject(any(), "downloadedFolder") } returns "ortFolder" | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
src/test/kotlin/net/leanix/vsm/sbomBooster/configuration/GenericTestConfiguration.kt
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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package net.leanix.vsm.sbomBooster.configuration | ||
|
||
import com.ninjasquad.springmockk.MockkBean | ||
import io.mockk.every | ||
import jakarta.annotation.PostConstruct | ||
import net.leanix.vsm.sbomBooster.service.OrtService | ||
|
||
open class GenericTestConfiguration { | ||
@MockkBean(relaxed = true) | ||
protected lateinit var ortService: OrtService | ||
|
||
@MockkBean | ||
protected lateinit var propertiesConfiguration: PropertiesConfiguration | ||
|
||
@PostConstruct | ||
fun setUp() { | ||
every { propertiesConfiguration.concurrencyFactor } returns 2 | ||
every { propertiesConfiguration.mountedVolume } returns "mountedVolume" | ||
every { propertiesConfiguration.allowNoComponentSboms } returns false | ||
every { propertiesConfiguration.devMode } returns false | ||
every { propertiesConfiguration.leanIxHost } returns "de" | ||
every { propertiesConfiguration.leanIxToken } returns "dummyLeanIxToken" | ||
every { propertiesConfiguration.sourceInstance } returns "sourceInstance" | ||
every { propertiesConfiguration.sourceType } returns "sourceType" | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
src/test/kotlin/net/leanix/vsm/sbomBooster/configuration/GitHubTestConfiguration.kt
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 |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package net.leanix.vsm.sbomBooster.configuration | ||
|
||
import com.ninjasquad.springmockk.MockkBean | ||
import io.mockk.every | ||
import jakarta.annotation.PostConstruct | ||
import net.leanix.vsm.sbomBooster.domain.Repository | ||
import net.leanix.vsm.sbomBooster.service.GitHubApiService | ||
import org.springframework.boot.test.context.TestConfiguration | ||
|
||
@TestConfiguration | ||
class GitHubTestConfiguration : GenericTestConfiguration() { | ||
@MockkBean | ||
private lateinit var gitHubApiService: GitHubApiService | ||
|
||
@PostConstruct | ||
fun prepare() { | ||
every { propertiesConfiguration.githubApiHost } returns "https://api.github.com" | ||
every { propertiesConfiguration.gitProvider } returns "github" | ||
every { propertiesConfiguration.githubGraphqlApiUrl } returns "https://api.github.com/graphql" | ||
every { propertiesConfiguration.githubOrganization } returns "githubOrganization" | ||
every { propertiesConfiguration.githubToken } returns "githubToken" | ||
|
||
every { gitHubApiService.getUsername("githubToken") } returns "githubUsername" | ||
every { gitHubApiService.getRepositories("githubToken", "githubOrganization") } returns listOf( | ||
Repository( | ||
"cloneUrl1", | ||
"sourceType", | ||
"sourceInstance", | ||
"repositoryName1", | ||
"repositoryId1" | ||
), | ||
Repository( | ||
"cloneUrl2", | ||
"sourceType", | ||
"sourceInstance", | ||
"repositoryName2", | ||
"repositoryId2" | ||
) | ||
) | ||
|
||
every { | ||
ortService.downloadProject( | ||
any(), | ||
"githubUsername", | ||
"githubToken" | ||
) | ||
} returns "downloadedFolder" | ||
every { ortService.analyzeProject(any(), "downloadedFolder") } returns "ortFolder" | ||
} | ||
} |
Oops, something went wrong.