-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rewrite Transformations tests (#234)
- Loading branch information
1 parent
07f350b
commit f274368
Showing
7 changed files
with
202 additions
and
117 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
plugins { | ||
id("org.gradle.java") | ||
id("org.gradle.java-test-fixtures") | ||
} | ||
|
||
java { | ||
sourceCompatibility = JavaVersion.VERSION_1_7 | ||
targetCompatibility = JavaVersion.VERSION_1_7 | ||
registerFeature("sharedIntegrationTests") { | ||
usingSourceSet(sourceSets.create("integrationTest")) | ||
@Suppress("UnstableApiUsage") | ||
disablePublication() | ||
} | ||
} | ||
|
||
dependencies { | ||
integrationTestImplementation(project) | ||
integrationTestImplementation(testFixtures(project)) | ||
integrationTestImplementation(libs.test.junit4) | ||
} | ||
|
||
// TODO Not using `org.gradle.test-report-aggregation`, because https://github.com/gradle/gradle/issues/24272. | ||
val integrationTestAggregateTestReport by tasks.registering(TestReport::class) { | ||
group = LifecycleBasePlugin.VERIFICATION_GROUP | ||
description = "Generates aggregated test report for all integration tests." | ||
// testResults.from(testing.suites*.targets*.testTask) added later when configuring the test suites. | ||
destinationDirectory.convention(java.testReportDir.dir("integration-tests/aggregated-results")) | ||
} | ||
|
||
val integrationTests by tasks.registering { | ||
// dependsOn("integration*Test") added later when configuring the test suites. | ||
finalizedBy(integrationTestAggregateTestReport) | ||
} | ||
|
||
tasks.check.configure { | ||
dependsOn(integrationTests) | ||
dependsOn(integrationTestAggregateTestReport) | ||
} | ||
|
||
@Suppress("UnstableApiUsage") | ||
testing.suites { | ||
named<JvmTestSuite>("test").configure { | ||
// Keep defaults. | ||
} | ||
registerIntegrationTest("java") { | ||
dependencies { | ||
// None, use default from JRE bootclasspath. | ||
} | ||
} | ||
registerIntegrationTest("xalan") { | ||
dependencies { | ||
implementation(libs.xml.xalan) | ||
} | ||
} | ||
registerIntegrationTest("saxon") { | ||
dependencies { | ||
implementation(libs.xml.saxon) | ||
} | ||
} | ||
} | ||
|
||
@Suppress("UnstableApiUsage") | ||
fun NamedDomainObjectContainerScope<TestSuite>.registerIntegrationTest( | ||
name: String, | ||
configure: JvmTestSuite.() -> Unit | ||
) { | ||
register<JvmTestSuite>("${name}IntegrationTest") { | ||
testType.set("${TestSuiteType.INTEGRATION_TEST}-${name}") | ||
useJUnit(libs.versions.test.junit4) | ||
dependencies { | ||
implementation(project()) | ||
implementation(testFixtures(project())) | ||
runtimeOnly(sharedIntegrationTests(project())) | ||
} | ||
targets.configureEach { | ||
integrationTests.configure { dependsOn(testTask) } | ||
integrationTestAggregateTestReport.configure { testResults.from(testTask) } | ||
testTask.configure { | ||
enableAssertions = true | ||
//val dataXml = file("${rootDir}/../temp/test/data.xml") | ||
systemProperty("net.twisterrob.inventory.transform.name", name) | ||
fun Test.inputFile(prop: String, file: File) { | ||
inputs.file(file) | ||
.withPropertyName(prop) | ||
.withPathSensitivity(PathSensitivity.RELATIVE) | ||
systemProperty(prop, file) | ||
} | ||
inputFile( | ||
"net.twisterrob.inventory.transform.xml", | ||
project(":android:backup").file("src/main/assets/demo.xml") | ||
) | ||
inputFile( | ||
"net.twisterrob.inventory.transform.xsd", | ||
project(":android:backup").file("src/main/assets/data.xml.xsd") | ||
) | ||
inputFile( | ||
"net.twisterrob.inventory.transform.xslt.html", | ||
project(":android:backup").file("src/main/assets/data.html.xslt") | ||
) | ||
inputFile( | ||
"net.twisterrob.inventory.transform.xslt.csv", | ||
project(":android:backup").file("src/main/assets/data.csv.xslt") | ||
) | ||
val transformDir = layout.buildDirectory.file("transformed") | ||
outputs.dir(transformDir).withPropertyName("transformDir") | ||
systemProperty( | ||
"net.twisterrob.inventory.transform.output", | ||
transformDir.get().asFile | ||
) | ||
testClassesDirs = files( | ||
testClassesDirs, // Keep original. | ||
sourceSets["integrationTest"].output.classesDirs, | ||
) | ||
} | ||
} | ||
configure() | ||
} | ||
} | ||
|
||
fun DependencyHandler.integrationTestImplementation(dependencyNotation: Any): Dependency? = | ||
add("integrationTestImplementation", dependencyNotation) | ||
|
||
fun sharedIntegrationTests(dependency: ProjectDependency): ProjectDependency { | ||
dependency.capabilities { | ||
// See org.gradle.internal.component.external.model.ProjectDerivedCapability | ||
val project = dependency.dependencyProject | ||
requireCapability("${project.group}:${project.name}-shared-integration-tests") | ||
} | ||
return dependency | ||
} |
This file was deleted.
Oops, something went wrong.
33 changes: 33 additions & 0 deletions
33
tools/transform/src/integrationTest/java/net/twisterrob/build/TransformTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package net.twisterrob.build; | ||
|
||
import java.io.IOException; | ||
|
||
import javax.xml.transform.TransformerException; | ||
|
||
import org.junit.Test; | ||
import org.xml.sax.SAXException; | ||
|
||
public class TransformTest { | ||
|
||
@Test | ||
public void transformHtml() throws IOException, TransformerException, SAXException { | ||
TransformTestProperties props = new TransformTestProperties(); | ||
Transform.main( | ||
props.getInputXml().getAbsolutePath(), | ||
props.getXsd().getAbsolutePath(), | ||
props.getXsltHtml().getAbsolutePath(), | ||
props.getOutputHtml().getAbsolutePath() | ||
); | ||
} | ||
|
||
@Test | ||
public void transformCsv() throws IOException, TransformerException, SAXException { | ||
TransformTestProperties props = new TransformTestProperties(); | ||
Transform.main( | ||
props.getInputXml().getAbsolutePath(), | ||
props.getXsd().getAbsolutePath(), | ||
props.getXsltCsv().getAbsolutePath(), | ||
props.getOutputCsv().getAbsolutePath() | ||
); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
tools/transform/src/testFixtures/java/net/twisterrob/build/TransformTestProperties.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package net.twisterrob.build; | ||
|
||
import java.io.File; | ||
|
||
public class TransformTestProperties { | ||
File getInputXml() { | ||
return new File(System.getProperty("net.twisterrob.inventory.transform.xml")); | ||
} | ||
File getXsd() { | ||
return new File(System.getProperty("net.twisterrob.inventory.transform.xsd")); | ||
} | ||
|
||
File getName() { | ||
return new File(System.getProperty("net.twisterrob.inventory.transform.name")); | ||
} | ||
File getOutputDir() { | ||
return new File(System.getProperty("net.twisterrob.inventory.transform.output")); | ||
} | ||
|
||
File getXsltHtml() { | ||
return new File(System.getProperty("net.twisterrob.inventory.transform.xslt.html")); | ||
} | ||
File getOutputHtml() { | ||
return new File(getOutputDir(), "data-" + getName() + ".csv"); | ||
} | ||
|
||
File getXsltCsv() { | ||
return new File(System.getProperty("net.twisterrob.inventory.transform.xslt.csv")); | ||
} | ||
File getOutputCsv() { | ||
return new File(getOutputDir(), "data-" + getName() + ".csv"); | ||
} | ||
} |