mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 08:27:12 -07:00
add some more testing around pom importing
This commit is contained in:
parent
59e6776e03
commit
f2aa5435ed
4 changed files with 89 additions and 23 deletions
|
@ -1,5 +1,7 @@
|
|||
package com.beust.kobalt.maven
|
||||
|
||||
import com.beust.kobalt.Args
|
||||
import com.beust.kobalt.ProjectGenerator
|
||||
import org.testng.Assert
|
||||
import org.testng.annotations.Test
|
||||
import java.io.File
|
||||
|
@ -7,7 +9,8 @@ import java.io.File
|
|||
class PomTest {
|
||||
@Test
|
||||
fun importPom() {
|
||||
val pom = Pom("testing", File("src/test/resources/pom.xml"));
|
||||
val pomSrc = File("src/test/resources/pom.xml")
|
||||
val pom = Pom("testing", pomSrc);
|
||||
|
||||
Assert.assertEquals(pom.groupId, "com.foo.bob")
|
||||
Assert.assertEquals(pom.artifactId, "rawr")
|
||||
|
@ -15,5 +18,54 @@ class PomTest {
|
|||
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
|
||||
fun importBasicPom() {
|
||||
val pomSrc = File("src/test/resources/pom-norepositories-properties.xml")
|
||||
val pom = Pom("testing", pomSrc);
|
||||
|
||||
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(pom, pomSrc)
|
||||
}
|
||||
|
||||
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)
|
||||
try {
|
||||
val file = File(temp, "Build.kt")
|
||||
file.delete()
|
||||
|
||||
file.deleteOnExit()
|
||||
val args = Args()
|
||||
args.buildFile = file.absolutePath
|
||||
args.init = true
|
||||
ProjectGenerator().run(args)
|
||||
var 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")
|
||||
pom.properties.forEach {
|
||||
Assert.assertTrue(contents.contains("val ${ProjectGenerator.translate(it.key)} = \"${it.value}\""), "Should find the " +
|
||||
"property defined")
|
||||
}
|
||||
pom.repositories.forEach {
|
||||
Assert.assertTrue(contents.contains(it), "Should find the repository defined")
|
||||
}
|
||||
} finally {
|
||||
System.getProperty("user.dir", original)
|
||||
}
|
||||
}
|
||||
}
|
11
src/test/resources/pom-norepositories-properties.xml
Normal file
11
src/test/resources/pom-norepositories-properties.xml
Normal file
|
@ -0,0 +1,11 @@
|
|||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>com.foo.bob</groupId>
|
||||
<artifactId>rawr</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<version>1.2.3</version>
|
||||
|
||||
<name>rawr</name>
|
||||
</project>
|
Loading…
Add table
Add a link
Reference in a new issue