-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(integrationTest): add CreateProjectTest
- Loading branch information
Patrick Mirwald
committed
Feb 1, 2024
1 parent
0ed4ee7
commit 65b2032
Showing
1 changed file
with
72 additions
and
0 deletions.
There are no files selected for viewing
72 changes: 72 additions & 0 deletions
72
src/integrationTest/kotlin/com/liftric/dtcp/CreateProjectTest.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,72 @@ | ||
package com.liftric.dtcp | ||
|
||
import com.liftric.dtcp.service.ApiService | ||
import org.gradle.testkit.runner.GradleRunner | ||
import org.junit.jupiter.api.Assertions.assertTrue | ||
import org.junit.jupiter.api.Test | ||
import java.io.File | ||
import kotlinx.coroutines.runBlocking | ||
import org.gradle.testkit.runner.UnexpectedBuildFailure | ||
|
||
class CreateProjectTest : IntegrationTestBase() { | ||
@Test | ||
fun testCreateProjectTest() { | ||
val projectName = "createProjectTest" | ||
val version = "1.0.0" | ||
|
||
val apiService = ApiService(dependencyTrackApiEndpoint) | ||
|
||
val dependencyTrackAccessKey = | ||
runBlocking { apiService.getDependencyTrackAccessKey() } | ||
|
||
assertTrue(dependencyTrackAccessKey.isNotEmpty()) | ||
|
||
val projectDir = File("build/createProjectTest") | ||
|
||
projectDir.mkdirs() | ||
projectDir.resolve("settings.gradle.kts").writeText("") | ||
projectDir.resolve("build.gradle.kts").writeText( | ||
""" | ||
import com.liftric.dtcp.extensions.* | ||
plugins { | ||
kotlin("jvm") version "1.8.21" | ||
id("com.liftric.dependency-track-companion-plugin") | ||
} | ||
repositories { | ||
mavenCentral() | ||
} | ||
group = "com.liftric.$projectName" | ||
version = "$version" | ||
dependencyTrackCompanion { | ||
url.set("$dependencyTrackApiEndpoint") | ||
apiKey.set("$dependencyTrackAccessKey") | ||
projectName.set("$projectName") | ||
projectVersion.set("$version") | ||
projectActive.set(false) | ||
} | ||
""" | ||
) | ||
|
||
/** | ||
* GradleRunner fails under the hood, but the Project is created successfully. | ||
* see [IgnoreErrorApiService] for more info. | ||
* */ | ||
try { | ||
GradleRunner | ||
.create() | ||
.withProjectDir(projectDir) | ||
.withArguments("build", "createProject") | ||
.withPluginClasspath().build() | ||
} catch (e: UnexpectedBuildFailure) { | ||
assertTrue(e.message!!.contains("/api/v1/project: 500 Server Error")) | ||
} | ||
|
||
runBlocking { | ||
assertTrue(apiService.verifyProjectCreation(dependencyTrackAccessKey, projectName, version)) | ||
} | ||
} | ||
} |