mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 16:28:12 -07:00
Fix PomTest.
This commit is contained in:
parent
2b78c0765d
commit
b4c2594f39
3 changed files with 34 additions and 19 deletions
|
@ -10,42 +10,57 @@ import com.google.inject.Inject
|
|||
import org.testng.Assert
|
||||
import org.testng.annotations.Test
|
||||
import java.io.File
|
||||
import java.io.FileOutputStream
|
||||
import java.nio.file.Files
|
||||
|
||||
class PomTest @Inject constructor() : KobaltTest() {
|
||||
@Test
|
||||
fun importPom() {
|
||||
val pomSrc = File("src/test/resources/pom.xml")
|
||||
val pom = Pom("testing", pomSrc);
|
||||
resourceToFile("PomTest/pom.xml").let { pomSrc ->
|
||||
with(Pom("testing", pomSrc)) {
|
||||
Assert.assertEquals(groupId, "com.foo.bob")
|
||||
Assert.assertEquals(artifactId, "rawr")
|
||||
Assert.assertEquals(name, "rawr")
|
||||
Assert.assertEquals(version, "1.2.3")
|
||||
Assert.assertEquals(properties["commons.version"], "2.1.1")
|
||||
Assert.assertEquals(properties["guice.version"], "4.0")
|
||||
|
||||
Assert.assertEquals(pom.groupId, "com.foo.bob")
|
||||
Assert.assertEquals(pom.artifactId, "rawr")
|
||||
Assert.assertEquals(pom.name, "rawr")
|
||||
Assert.assertEquals(pom.version, "1.2.3")
|
||||
Assert.assertEquals(pom.properties.get("commons.version"), "2.1.1")
|
||||
Assert.assertEquals(pom.properties.get("guice.version"), "4.0")
|
||||
validateGeneratedFile(this, pomSrc)
|
||||
}
|
||||
|
||||
validateGeneratedFile(pom, pomSrc)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun importBasicPom() {
|
||||
val pomSrc = File("src/test/resources/pom-norepositories-properties.xml")
|
||||
val pom = Pom("testing", pomSrc);
|
||||
resourceToFile("PomTest/pom-norepositories-properties.xml").let { pomSrc ->
|
||||
with(Pom("testing", pomSrc)) {
|
||||
Assert.assertEquals(groupId, "com.foo.bob")
|
||||
Assert.assertEquals(artifactId, "rawr")
|
||||
Assert.assertEquals(name, "rawr")
|
||||
Assert.assertEquals(version, "1.2.3")
|
||||
Assert.assertTrue(properties.isEmpty())
|
||||
Assert.assertTrue(repositories.isEmpty())
|
||||
|
||||
Assert.assertEquals(pom.groupId, "com.foo.bob")
|
||||
Assert.assertEquals(pom.artifactId, "rawr")
|
||||
Assert.assertEquals(pom.name, "rawr")
|
||||
Assert.assertEquals(pom.version, "1.2.3")
|
||||
Assert.assertTrue(pom.properties.isEmpty())
|
||||
Assert.assertTrue(pom.repositories.isEmpty())
|
||||
validateGeneratedFile(this, pomSrc)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
validateGeneratedFile(pom, pomSrc)
|
||||
private fun resourceToFile(fileName: String) : File {
|
||||
val ins = javaClass.classLoader.getResourceAsStream(fileName)
|
||||
val result = Files.createTempFile("kobaltTest", "").toFile()
|
||||
FileOutputStream(result).use {
|
||||
ins.copyTo(it)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
private fun validateGeneratedFile(pom: Pom, pomSrc: File) {
|
||||
val temp = File(System.getProperty("java.io.tmpdir"))
|
||||
val original = System.getProperty("user.dir")
|
||||
System.setProperty("user.dir", temp.absolutePath)
|
||||
|
||||
val pomFile = File(temp, "pom.xml")
|
||||
pomFile.deleteOnExit()
|
||||
pomSrc.copyTo(pomFile, true)
|
||||
|
@ -60,7 +75,7 @@ class PomTest @Inject constructor() : KobaltTest() {
|
|||
|
||||
ProjectGenerator(Kobalt.INJECTOR.getInstance(PluginInfo::class.java)).run(args, javaClass.classLoader)
|
||||
|
||||
var contents = file.readText()
|
||||
val contents = file.readText()
|
||||
Assert.assertTrue(contents.contains("group = \"${pom.groupId}\""), "Should find the group defined")
|
||||
Assert.assertTrue(contents.contains("name = \"${pom.name}\""), "Should find the name defined")
|
||||
Assert.assertTrue(contents.contains("version = \"${pom.version}\""), "Should find the version defined")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue