diff --git a/src/test/kotlin/com/beust/kobalt/BaseTest.kt b/src/test/kotlin/com/beust/kobalt/BaseTest.kt index 6340d36c..a7b4d82c 100644 --- a/src/test/kotlin/com/beust/kobalt/BaseTest.kt +++ b/src/test/kotlin/com/beust/kobalt/BaseTest.kt @@ -1,15 +1,25 @@ package com.beust.kobalt import com.beust.kobalt.api.Kobalt +import com.beust.kobalt.api.KobaltContext import com.beust.kobalt.app.BuildFileCompiler import com.beust.kobalt.internal.JvmCompilerPlugin import com.beust.kobalt.internal.KobaltPluginXml import com.beust.kobalt.internal.PluginInfo import com.beust.kobalt.internal.build.BuildFile +import com.beust.kobalt.maven.aether.KobaltAether +import org.testng.annotations.BeforeSuite import java.io.File import java.nio.file.Paths -interface BaseTest { +open class BaseTest(open val aether: KobaltAether) { + val context = KobaltContext(Args()) + + @BeforeSuite + fun bs() { + context.aether = aether + } + fun compileBuildFile(buildFileText: String, args: Args, compilerFactory: BuildFileCompiler.IFactory) : BuildFileCompiler.FindProjectResult { val tmpBuildFile = File.createTempFile("kobaltTest", "").apply { diff --git a/src/test/kotlin/com/beust/kobalt/ContextTest.kt b/src/test/kotlin/com/beust/kobalt/ContextTest.kt new file mode 100644 index 00000000..108872fc --- /dev/null +++ b/src/test/kotlin/com/beust/kobalt/ContextTest.kt @@ -0,0 +1,49 @@ +package com.beust.kobalt + +import com.beust.kobalt.api.KobaltContext +import com.beust.kobalt.maven.aether.KobaltAether +import com.google.inject.Inject +import org.assertj.core.api.Assertions.assertThat +import org.testng.annotations.DataProvider +import org.testng.annotations.Guice +import org.testng.annotations.Test +import java.io.File + +@Guice(modules = arrayOf(TestModule::class)) +class ContextTest @Inject constructor(override val aether: KobaltAether): BaseTest(aether) { + + val GROUP = "org.testng" + val ARTIFACT = "testng" + val VERSION = "6.9.11" + val REPO_PATH = TEST_KOBALT_SETTINGS.localCache + val id = "$GROUP:$ARTIFACT:$VERSION" + + @DataProvider + fun dp() : Array> { + return arrayOf( + arrayOf(KobaltContext.FileType.JAR, ARTIFACT + "-" + VERSION + ".jar"), + arrayOf(KobaltContext.FileType.POM, ARTIFACT + "-" + VERSION + ".pom"), + arrayOf(KobaltContext.FileType.JAVADOC, ARTIFACT + "-" + VERSION + "-javadoc.jar"), + arrayOf(KobaltContext.FileType.SOURCES, ARTIFACT + "-" + VERSION + "-sources.jar") + ) + } + + fun normalize(path: String) = path.replace('.', File.separatorChar) + + @Test(dataProvider = "dp") + fun fileForIdShouldWork(fileType: KobaltContext.FileType, expectedFileName: String) { + val expected = listOf(REPO_PATH, normalize(GROUP), ARTIFACT, VERSION, + ARTIFACT + "-" + VERSION + ".jar").joinToString(File.separator) + val file = context.fileFor(id, KobaltContext.FileType.JAR) + assertThat(file.absolutePath).isEqualTo(expected) + } + + @Test + fun fileForIdOther() { + val expected = listOf(REPO_PATH, "io/reactivex/rxandroid/1.0.1/rxandroid-1.0.1.aar") + .joinToString(File.separator) + val file = context.fileFor("io.reactivex:rxandroid:aar:1.0.1", KobaltContext.FileType.OTHER) + assertThat(file.absolutePath).isEqualTo(expected) + + } +} diff --git a/src/test/kotlin/com/beust/kobalt/internal/ProfileTest.kt b/src/test/kotlin/com/beust/kobalt/internal/ProfileTest.kt index 4bb722d7..2ea7d714 100644 --- a/src/test/kotlin/com/beust/kobalt/internal/ProfileTest.kt +++ b/src/test/kotlin/com/beust/kobalt/internal/ProfileTest.kt @@ -6,16 +6,15 @@ import com.beust.kobalt.TestModule import com.beust.kobalt.api.Kobalt import com.beust.kobalt.api.Project import com.beust.kobalt.app.BuildFileCompiler +import com.beust.kobalt.maven.aether.KobaltAether import com.google.inject.Inject import org.assertj.core.api.Assertions.assertThat import org.testng.annotations.Guice import org.testng.annotations.Test @Guice(modules = arrayOf(TestModule::class)) -class ProfileTest @Inject constructor(val compilerFactory: BuildFileCompiler.IFactory -// val jvmCompilerPlugin: JvmCompilerPlugin -// val buildScriptUtil: BuildScriptUtil -) : BaseTest { +class ProfileTest @Inject constructor(val compilerFactory: BuildFileCompiler.IFactory, + override val aether: KobaltAether): BaseTest(aether) { private fun runTestWithProfile(enabled: Boolean) : Project { val buildFileString = """ | import com.beust.kobalt.*