mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-30 09:58:12 -07:00
First commit
This commit is contained in:
commit
c061e7df85
102 changed files with 6717 additions and 0 deletions
21
src/test/kotlin/com/beust/kobalt/ResourceTest.kt
Normal file
21
src/test/kotlin/com/beust/kobalt/ResourceTest.kt
Normal file
|
@ -0,0 +1,21 @@
|
|||
package com.beust.kobalt
|
||||
|
||||
import org.testng.Assert
|
||||
import org.testng.annotations.Test
|
||||
import java.util.Properties
|
||||
|
||||
@Test
|
||||
public class ResourceTest {
|
||||
val fileName = "kobalt.properties"
|
||||
|
||||
fun shouldLoadResources() {
|
||||
val properties = Properties()
|
||||
val res = ClassLoader.getSystemResource(fileName)
|
||||
if (res != null) {
|
||||
properties.load(res.openStream())
|
||||
Assert.assertTrue(properties.get("foo") == "bar")
|
||||
} else {
|
||||
Assert.fail("Couldn't load ${fileName}")
|
||||
}
|
||||
}
|
||||
}
|
15
src/test/kotlin/com/beust/kobalt/TestModule.kt
Normal file
15
src/test/kotlin/com/beust/kobalt/TestModule.kt
Normal file
|
@ -0,0 +1,15 @@
|
|||
package com.beust.kobalt
|
||||
|
||||
import com.beust.kobalt.maven.LocalRepo
|
||||
import com.beust.kobalt.plugin.java.SystemProperties
|
||||
import com.google.inject.Scopes
|
||||
import java.io.File
|
||||
|
||||
class TestLocalRepo: LocalRepo(localRepo = SystemProperties.homeDir + File.separatorChar + ".kobalt-test")
|
||||
|
||||
public class TestModule : com.beust.kobalt.misc.MainModule() {
|
||||
override fun configureTest() {
|
||||
bind(LocalRepo::class.java).to(TestLocalRepo::class.java).`in`(Scopes.SINGLETON)
|
||||
}
|
||||
|
||||
}
|
138
src/test/kotlin/com/beust/kobalt/internal/DynamicGraphTest.kt
Normal file
138
src/test/kotlin/com/beust/kobalt/internal/DynamicGraphTest.kt
Normal file
|
@ -0,0 +1,138 @@
|
|||
package com.beust.kobalt.internal
|
||||
|
||||
import com.beust.kobalt.maven.KobaltException
|
||||
import com.beust.kobalt.misc.KobaltLogger
|
||||
import com.beust.kobalt.misc.Topological
|
||||
import javafx.concurrent.Worker
|
||||
import org.testng.Assert
|
||||
import org.testng.annotations.Test
|
||||
import java.util.ArrayList
|
||||
import java.util.HashSet
|
||||
import java.util.concurrent.LinkedBlockingQueue
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
public class DynamicGraphTest {
|
||||
|
||||
private fun <T> assertFreeNodesEquals(graph: DynamicGraph<T>, expected: Array<T>) {
|
||||
val h = HashSet(graph.freeNodes)
|
||||
val e = HashSet(expected.toList())
|
||||
Assert.assertEquals(h, e)
|
||||
}
|
||||
|
||||
private fun <T> createFactory(runNodes: ArrayList<T>, errorFunction: (T) -> Boolean) : IThreadWorkerFactory<T> {
|
||||
return object: IThreadWorkerFactory<T> {
|
||||
override fun createWorkers(nodes: List<T>): List<IWorker<T>> {
|
||||
val result = arrayListOf<IWorker<T>>()
|
||||
nodes.forEach { result.add(Worker(runNodes, it, errorFunction)) }
|
||||
return result
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class Worker<T>(val runNodes: ArrayList<T>, val n: T,
|
||||
val errorFunction: (T) -> Boolean) : IWorker<T>, KobaltLogger {
|
||||
override val priority = 0
|
||||
|
||||
override fun call() : TaskResult2<T> {
|
||||
log(2, "Running node $n")
|
||||
runNodes.add(n)
|
||||
return TaskResult2(errorFunction(n), n)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public fun testExecutor() {
|
||||
val dg = DynamicGraph<String>();
|
||||
dg.addEdge("compile", "runApt")
|
||||
dg.addEdge("compile", "generateVersion")
|
||||
|
||||
val runNodes = arrayListOf<String>()
|
||||
val factory = createFactory(runNodes, { true })
|
||||
|
||||
DynamicGraphExecutor(dg, factory).run()
|
||||
Assert.assertEquals(runNodes.size(), 3)
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
private fun testExecutorWithSkip() {
|
||||
|
||||
val g = DynamicGraph<Int>()
|
||||
// 2 and 3 depend on 1, 4 depend on 3, 10 depends on 4
|
||||
// 3 will blow up, which should make 4 and 10 skipped
|
||||
g.addEdge(2, 1)
|
||||
g.addEdge(3, 1)
|
||||
g.addEdge(4, 3)
|
||||
g.addEdge(10, 4)
|
||||
g.addEdge(5, 2)
|
||||
val runNodes = arrayListOf<Int>()
|
||||
val factory = createFactory(runNodes, { n -> n != 3 })
|
||||
val ex = DynamicGraphExecutor(g, factory)
|
||||
ex.run()
|
||||
Thread.yield()
|
||||
Assert.assertEquals(runNodes, listOf(1, 2, 3, 5))
|
||||
}
|
||||
|
||||
@Test
|
||||
public fun test8() {
|
||||
val dg = DynamicGraph<String>();
|
||||
dg.addEdge("b1", "a1")
|
||||
dg.addEdge("b1", "a2")
|
||||
dg.addEdge("b2", "a1")
|
||||
dg.addEdge("b2", "a2")
|
||||
dg.addEdge("c1", "b1")
|
||||
dg.addEdge("c1", "b2")
|
||||
dg.addNode("x")
|
||||
dg.addNode("y")
|
||||
val freeNodes = dg.freeNodes
|
||||
assertFreeNodesEquals(dg, arrayOf("a1", "a2", "y", "x"))
|
||||
|
||||
dg.setStatus(freeNodes, DynamicGraph.Status.RUNNING)
|
||||
dg.setStatus("a1", DynamicGraph.Status.FINISHED)
|
||||
assertFreeNodesEquals(dg, arrayOf<String>())
|
||||
|
||||
dg.setStatus("a2", DynamicGraph.Status.FINISHED)
|
||||
assertFreeNodesEquals(dg, arrayOf("b1", "b2"))
|
||||
|
||||
dg.setStatus("b2", DynamicGraph.Status.RUNNING)
|
||||
dg.setStatus("b1", DynamicGraph.Status.FINISHED)
|
||||
assertFreeNodesEquals(dg, arrayOf<String>())
|
||||
|
||||
dg.setStatus("b2", DynamicGraph.Status.FINISHED)
|
||||
assertFreeNodesEquals(dg, arrayOf("c1"))
|
||||
}
|
||||
|
||||
@Test
|
||||
public fun test2() {
|
||||
val dg = DynamicGraph<String>()
|
||||
dg.addEdge("b1", "a1")
|
||||
dg.addEdge("b1", "a2")
|
||||
dg.addNode("x")
|
||||
val freeNodes = dg.freeNodes
|
||||
assertFreeNodesEquals(dg, arrayOf("a1", "a2", "x" ))
|
||||
|
||||
dg.setStatus(freeNodes, DynamicGraph.Status.RUNNING)
|
||||
dg.setStatus("a1", DynamicGraph.Status.FINISHED)
|
||||
assertFreeNodesEquals(dg, arrayOf<String>())
|
||||
|
||||
dg.setStatus("a2", DynamicGraph.Status.FINISHED)
|
||||
assertFreeNodesEquals(dg, arrayOf("b1"))
|
||||
|
||||
dg.setStatus("b2", DynamicGraph.Status.RUNNING)
|
||||
dg.setStatus("b1", DynamicGraph.Status.FINISHED)
|
||||
assertFreeNodesEquals(dg, arrayOf<String>())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun topologicalSort() {
|
||||
val dg = Topological<String>()
|
||||
dg.addEdge("b1", "a1")
|
||||
dg.addEdge("b1", "a2")
|
||||
dg.addEdge("b2", "a1")
|
||||
dg.addEdge("b2", "a2")
|
||||
dg.addEdge("c1", "b1")
|
||||
dg.addEdge("c1", "b2")
|
||||
val sorted = dg.sort(arrayListOf("a1", "a2", "b1", "b2", "c1", "x", "y"))
|
||||
Assert.assertEquals(sorted, arrayListOf("a1", "a2", "x", "y", "b1", "b2", "c1"))
|
||||
}
|
||||
}
|
48
src/test/kotlin/com/beust/kobalt/maven/DependencyTest.kt
Normal file
48
src/test/kotlin/com/beust/kobalt/maven/DependencyTest.kt
Normal file
|
@ -0,0 +1,48 @@
|
|||
package com.beust.kobalt.maven
|
||||
|
||||
import com.beust.kobalt.TestModule
|
||||
import com.beust.kobalt.misc.KobaltExecutors
|
||||
import com.beust.kobalt.misc.Versions
|
||||
import org.testng.Assert
|
||||
import org.testng.annotations.*
|
||||
import java.util.concurrent.ExecutorService
|
||||
import javax.inject.Inject
|
||||
import kotlin.properties.Delegates
|
||||
|
||||
@Guice(modules = arrayOf(TestModule::class))
|
||||
public class DependencyTest @Inject constructor(val depFactory: DepFactory,
|
||||
val executors: KobaltExecutors) {
|
||||
|
||||
@DataProvider
|
||||
fun dpVersions(): Array<Array<out Any>> {
|
||||
return arrayOf(
|
||||
arrayOf("6.9.4", "6.9.5"),
|
||||
arrayOf("1.7", "1.38"),
|
||||
arrayOf("1.70", "1.380"),
|
||||
arrayOf("3.8.1", "4.5"),
|
||||
arrayOf("18.0-rc1", "19.0"),
|
||||
arrayOf("3.0.5.RELEASE", "3.0.6")
|
||||
)
|
||||
}
|
||||
|
||||
private var executor: ExecutorService by Delegates.notNull()
|
||||
|
||||
@BeforeClass
|
||||
public fun bc() {
|
||||
executor = executors.newExecutor("DependencyTest", 5)
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public fun ac() {
|
||||
executor.shutdown()
|
||||
}
|
||||
|
||||
@Test(dataProvider = "dpVersions")
|
||||
public fun versionSorting(k: String, v: String) {
|
||||
val dep1 = Versions.toLongVersion(k)
|
||||
val dep2 = Versions.toLongVersion(v)
|
||||
Assert.assertTrue(dep1.compareTo(dep2) < 0)
|
||||
Assert.assertTrue(dep2.compareTo(dep1) > 0)
|
||||
}
|
||||
}
|
||||
|
80
src/test/kotlin/com/beust/kobalt/maven/DownloadTest.kt
Normal file
80
src/test/kotlin/com/beust/kobalt/maven/DownloadTest.kt
Normal file
|
@ -0,0 +1,80 @@
|
|||
package com.beust.kobalt.maven
|
||||
|
||||
import com.beust.kobalt.maven.CompletedFuture
|
||||
import com.beust.kobalt.maven.DepFactory
|
||||
import com.beust.kobalt.maven.LocalRepo
|
||||
import com.beust.kobalt.misc.KobaltExecutors
|
||||
import com.beust.kobalt.misc.MainModule
|
||||
import com.beust.kobalt.TestModule
|
||||
import com.google.inject.Module
|
||||
import com.google.inject.util.Modules
|
||||
import org.testng.Assert
|
||||
import org.testng.IModuleFactory
|
||||
import org.testng.ITestContext
|
||||
import org.testng.annotations.BeforeClass
|
||||
import org.testng.annotations.Guice
|
||||
import org.testng.annotations.Test
|
||||
import java.io.File
|
||||
import java.util.concurrent.ExecutorService
|
||||
import javax.inject.Inject
|
||||
import kotlin.properties.Delegates
|
||||
|
||||
/**
|
||||
* TODO: test snapshots https://repository.jboss.org/nexus/content/repositories/root_repository//commons-lang/commons-lang/2.7-SNAPSHOT/commons-lang-2.7-SNAPSHOT.jar
|
||||
*/
|
||||
@Guice(modules = arrayOf(TestModule::class))
|
||||
public class DownloadTest @Inject constructor(
|
||||
val depFactory: DepFactory,
|
||||
val localRepo: LocalRepo,
|
||||
val executors: KobaltExecutors) {
|
||||
var executor: ExecutorService by Delegates.notNull()
|
||||
|
||||
@BeforeClass
|
||||
public fun bc() {
|
||||
executor = executors.newExecutor("DependentTest", 5)
|
||||
}
|
||||
|
||||
@Test
|
||||
public fun shouldDownloadWithVersion() {
|
||||
File(localRepo.toFullPath("org/testng/testng")).deleteRecursively()
|
||||
|
||||
arrayListOf("org.testng:testng:6.9.4", "org.testng:testng:6.9.5").forEach {
|
||||
val dep = depFactory.create(it, executor)
|
||||
val future = dep.jarFile
|
||||
Assert.assertFalse(future is CompletedFuture)
|
||||
val file = future.get()
|
||||
Assert.assertTrue(file.exists())
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public fun shouldDownloadNoVersion() {
|
||||
File(localRepo.toFullPath("org/testng/testng")).deleteRecursively()
|
||||
|
||||
val dep = depFactory.create("org.testng:testng:", executor)
|
||||
|
||||
val future = dep.jarFile
|
||||
val file = future.get()
|
||||
Assert.assertFalse(future is CompletedFuture)
|
||||
Assert.assertEquals(file.getName(), "testng-6.9.6.jar")
|
||||
Assert.assertTrue(file.exists())
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = arrayOf("shouldDownloadWithVersion"))
|
||||
public fun shouldFindLocalJar() {
|
||||
val dep = depFactory.create("org.testng:testng:6.9.6", executor)
|
||||
val future = dep.jarFile
|
||||
Assert.assertTrue(future is CompletedFuture)
|
||||
val file = future.get()
|
||||
Assert.assertTrue(file.exists())
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = arrayOf("shouldDownloadWithVersion"))
|
||||
public fun shouldFindLocalJarNoVersion() {
|
||||
val dep = depFactory.create("org.testng:testng:", executor)
|
||||
val future = dep.jarFile
|
||||
val file = future.get()
|
||||
Assert.assertEquals(file.getName(), "testng-6.9.6.jar")
|
||||
Assert.assertTrue(file.exists())
|
||||
}
|
||||
}
|
10
src/test/kotlin/com/beust/kobalt/maven/JUnitTest.kt
Normal file
10
src/test/kotlin/com/beust/kobalt/maven/JUnitTest.kt
Normal file
|
@ -0,0 +1,10 @@
|
|||
package com.beust.kobalt.maven
|
||||
|
||||
//import org.junit.Test
|
||||
//
|
||||
//public class JUnitTest {
|
||||
// @Test
|
||||
// public fun simpleTestForJUnit() {
|
||||
// println("Works")
|
||||
// }
|
||||
//}
|
30
src/test/kotlin/com/beust/kobalt/maven/RemoteRepoTest.kt
Normal file
30
src/test/kotlin/com/beust/kobalt/maven/RemoteRepoTest.kt
Normal file
|
@ -0,0 +1,30 @@
|
|||
package com.beust.kobalt.maven
|
||||
|
||||
import com.beust.kobalt.TestModule
|
||||
import com.beust.kobalt.misc.DependencyExecutor
|
||||
import com.beust.kobalt.misc.MainModule
|
||||
import com.google.inject.Guice
|
||||
import org.testng.Assert
|
||||
import org.testng.annotations.Test
|
||||
import java.util.concurrent.ExecutorService
|
||||
import javax.inject.Inject
|
||||
|
||||
@org.testng.annotations.Guice(modules = arrayOf(TestModule::class))
|
||||
public class RemoteRepoTest @Inject constructor(val repoFinder: RepoFinder,
|
||||
@DependencyExecutor val executor: ExecutorService){
|
||||
|
||||
val INJECTOR = Guice.createInjector(MainModule())
|
||||
|
||||
@Test
|
||||
public fun mavenMetadata() {
|
||||
val dep = MavenDependency.create("org.codehaus.groovy:groovy-all:")
|
||||
Assert.assertEquals(dep.id.split(":")[2], "2.4.4")
|
||||
}
|
||||
|
||||
@Test
|
||||
public fun metadataForSnapshots() {
|
||||
val jar = MavenDependency.create("org.apache.maven.wagon:wagon-provider-test:2.10-SNAPSHOT", executor)
|
||||
.jarFile
|
||||
Assert.assertTrue(jar.get().exists())
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue