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.Assert
|
||||||
import org.testng.annotations.Test
|
import org.testng.annotations.Test
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
import java.io.FileOutputStream
|
||||||
|
import java.nio.file.Files
|
||||||
|
|
||||||
class PomTest @Inject constructor() : KobaltTest() {
|
class PomTest @Inject constructor() : KobaltTest() {
|
||||||
@Test
|
@Test
|
||||||
fun importPom() {
|
fun importPom() {
|
||||||
val pomSrc = File("src/test/resources/pom.xml")
|
resourceToFile("PomTest/pom.xml").let { pomSrc ->
|
||||||
val pom = Pom("testing", 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")
|
validateGeneratedFile(this, pomSrc)
|
||||||
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(pom, pomSrc)
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun importBasicPom() {
|
fun importBasicPom() {
|
||||||
val pomSrc = File("src/test/resources/pom-norepositories-properties.xml")
|
resourceToFile("PomTest/pom-norepositories-properties.xml").let { pomSrc ->
|
||||||
val pom = Pom("testing", 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")
|
validateGeneratedFile(this, pomSrc)
|
||||||
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(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) {
|
private fun validateGeneratedFile(pom: Pom, pomSrc: File) {
|
||||||
val temp = File(System.getProperty("java.io.tmpdir"))
|
val temp = File(System.getProperty("java.io.tmpdir"))
|
||||||
val original = System.getProperty("user.dir")
|
val original = System.getProperty("user.dir")
|
||||||
System.setProperty("user.dir", temp.absolutePath)
|
System.setProperty("user.dir", temp.absolutePath)
|
||||||
|
|
||||||
val pomFile = File(temp, "pom.xml")
|
val pomFile = File(temp, "pom.xml")
|
||||||
pomFile.deleteOnExit()
|
pomFile.deleteOnExit()
|
||||||
pomSrc.copyTo(pomFile, true)
|
pomSrc.copyTo(pomFile, true)
|
||||||
|
@ -60,7 +75,7 @@ class PomTest @Inject constructor() : KobaltTest() {
|
||||||
|
|
||||||
ProjectGenerator(Kobalt.INJECTOR.getInstance(PluginInfo::class.java)).run(args, javaClass.classLoader)
|
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("group = \"${pom.groupId}\""), "Should find the group defined")
|
||||||
Assert.assertTrue(contents.contains("name = \"${pom.name}\""), "Should find the name 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")
|
Assert.assertTrue(contents.contains("version = \"${pom.version}\""), "Should find the version defined")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue