Skip to content

Commit

Permalink
Add integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mtdowling committed May 20, 2019
1 parent 5509ccc commit 7fd2762
Show file tree
Hide file tree
Showing 39 changed files with 642 additions and 23 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,15 @@ buildscript {
```


## Testing the plugin

The plugin is tested using integration tests that exercise example packages
in the `examples` directory. Failure cases are placed in `examples/failure-cases`.
Integration tests are executed with Gradle using the `it` task. Note that this
task requires publishing the Smithy Gradle plugin to your Maven local
repository.


## License

This library is licensed under the Apache 2.0 License.
25 changes: 23 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ dependencies {
testRuntime("org.junit.jupiter:junit-jupiter-engine:5.4.0")
testImplementation("org.junit.jupiter:junit-jupiter-params:5.4.0")
testImplementation("org.hamcrest:hamcrest:2.1")
testImplementation("commons-io:commons-io:2.6")
}

/*
Expand Down Expand Up @@ -78,8 +79,26 @@ tasks.jar {
}
}

// Always run javadoc after build.
tasks["build"].finalizedBy(tasks["javadoc"])
sourceSets {
create("it") {
java.srcDir("src/it/java")
resources.srcDir("src/it/resources")
compileClasspath += sourceSets["main"].output + configurations["testRuntimeClasspath"]
runtimeClasspath += output + compileClasspath + sourceSets["test"].runtimeClasspath
}
}

tasks.register<Test>("it") {
useJUnitPlatform()
testClassesDirs = sourceSets["it"].output.classesDirs
classpath = sourceSets["it"].compileClasspath + sourceSets["it"].runtimeClasspath
maxParallelForks = Runtime.getRuntime().availableProcessors() / 2
}

tasks["it"].dependsOn("publishToMavenLocal")

// Always run javadoc and integration tests after build.
tasks["build"].finalizedBy(tasks["javadoc"]).finalizedBy(tasks["it"])

/*
* Maven
Expand Down Expand Up @@ -115,6 +134,7 @@ publishing {
*/

tasks["checkstyleTest"].enabled = false
tasks["checkstyleIt"].enabled = false

/*
* Code coverage
Expand Down Expand Up @@ -144,6 +164,7 @@ tasks.jacocoTestReport {

// We don't need to lint tests.
tasks["spotbugsTest"].enabled = false
tasks["spotbugsIt"].enabled = false

// Configure the bug filter for spotbugs.
tasks.withType(com.github.spotbugs.SpotBugsTask::class) {
Expand Down
27 changes: 27 additions & 0 deletions examples/disable-jar/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// This example builds Smithy models but does not create a JAR.

plugins {
java
}

buildscript {
repositories {
mavenLocal()
}
dependencies {
classpath("software.amazon.smithy:smithy-gradle-plugin:0.0.1")
}
}

apply(plugin = "software.amazon.smithy")

repositories {
mavenLocal()
mavenCentral()
}

dependencies {
implementation("software.amazon.smithy:smithy-model:0.4.1")
}

tasks["jar"].enabled = false
5 changes: 5 additions & 0 deletions examples/disable-jar/model/main.smithy
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
namespace smithy.example

structure Example {
foo: String
}
7 changes: 7 additions & 0 deletions examples/disable-jar/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
rootProject.name = "disable-jar"

pluginManagement {
repositories {
mavenLocal()
}
}
3 changes: 3 additions & 0 deletions examples/disable-jar/smithy-build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"version": "1.0"
}
29 changes: 29 additions & 0 deletions examples/failure-cases/invalid-projection/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// This example attempts to use an invalid projection. The build will fail.

plugins {
java
}

buildscript {
repositories {
mavenLocal()
}
dependencies {
classpath("software.amazon.smithy:smithy-gradle-plugin:0.0.1")
}
}

apply(plugin = "software.amazon.smithy")

repositories {
mavenLocal()
mavenCentral()
}

dependencies {
implementation("software.amazon.smithy:smithy-model:0.4.1")
}

configure<software.amazon.smithy.gradle.SmithyExtension> {
projection = "invalid"
}
5 changes: 5 additions & 0 deletions examples/failure-cases/invalid-projection/model/main.smithy
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
namespace smithy.example

structure Foo {
foo: String
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
rootProject.name = "test"
rootProject.name = "projection"

pluginManagement {
repositories {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"version": "1.0",
"projections": {
"trimmed": {}
"foo": {}
}
}
39 changes: 39 additions & 0 deletions examples/failure-cases/missing-runtime-dependency/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// This example creates a projected version of the model, but because the
// projected model references traits from another package and that package
// is not part of the runtime dependencies, the build will fail when the
// plugin validates the JAR with Smithy model discovery.

plugins {
java
}

buildscript {
repositories {
mavenLocal()
}
dependencies {
classpath("software.amazon.smithy:smithy-gradle-plugin:0.0.1")

// This dependency is required to build the model.
classpath("software.amazon.smithy:smithy-aws-traits:0.4.1")
}
}

apply(plugin = "software.amazon.smithy")

repositories {
mavenLocal()
mavenCentral()
}

dependencies {
implementation("software.amazon.smithy:smithy-model:0.4.1")

// This dependency is used in the projected model, so it's required here too.
// This should fail to build since this is missing.
//implementation("software.amazon.smithy:smithy-aws-traits:0.4.1")
}

configure<software.amazon.smithy.gradle.SmithyExtension> {
projection = "foo"
}
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
rootProject.name = "projection"

pluginManagement {
repositories {
mavenLocal()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"version": "1.0",
"projections": {
"foo": {}
}
}
28 changes: 28 additions & 0 deletions examples/multiple-sources/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// This example pulls Smithy models from the following locations:
// - model/
// - src/main/smithy/
// - src/main/resources/META-INF/smithy

plugins {
java
}

buildscript {
repositories {
mavenLocal()
}
dependencies {
classpath("software.amazon.smithy:smithy-gradle-plugin:0.0.1")
}
}

apply(plugin = "software.amazon.smithy")

repositories {
mavenLocal()
mavenCentral()
}

dependencies {
implementation("software.amazon.smithy:smithy-model:0.4.1")
}
3 changes: 3 additions & 0 deletions examples/multiple-sources/model/a.smithy
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
namespace smithy.example

structure A {}
7 changes: 7 additions & 0 deletions examples/multiple-sources/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
rootProject.name = "multiple-sources"

pluginManagement {
repositories {
mavenLocal()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
namespace smithy.example

structure C {
foo: String
}
5 changes: 5 additions & 0 deletions examples/multiple-sources/src/main/smithy/b.smithy
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
namespace smithy.example

structure B {
foo: String
}
35 changes: 35 additions & 0 deletions examples/projection/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// This example places a projected version of the model into the JAR.

plugins {
java
}

buildscript {
repositories {
mavenLocal()
}
dependencies {
classpath("software.amazon.smithy:smithy-gradle-plugin:0.0.1")

// This dependency is required to build the model.
classpath("software.amazon.smithy:smithy-aws-traits:0.4.1")
}
}

apply(plugin = "software.amazon.smithy")

repositories {
mavenLocal()
mavenCentral()
}

dependencies {
implementation("software.amazon.smithy:smithy-model:0.4.1")

// This dependency is used in the projected model, so it's requird here too.
implementation("software.amazon.smithy:smithy-aws-traits:0.4.1")
}

configure<software.amazon.smithy.gradle.SmithyExtension> {
projection = "foo"
}
8 changes: 8 additions & 0 deletions examples/projection/model/main.smithy
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace smithy.example

structure Baz {
foo: String
}

@aws.api#unsignedPayload
operation Foo()
7 changes: 7 additions & 0 deletions examples/projection/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
rootProject.name = "projection"

pluginManagement {
repositories {
mavenLocal()
}
}
6 changes: 6 additions & 0 deletions examples/projection/smithy-build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"version": "1.0",
"projections": {
"foo": {}
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// This example builds the model and places it in the JAR.

plugins {
java
}
Expand All @@ -8,14 +10,14 @@ buildscript {
}
dependencies {
classpath("software.amazon.smithy:smithy-gradle-plugin:0.0.1")
//classpath("software.amazon.smithy:smithy-aws-traits:0.4.1")
}
}

apply(plugin = "software.amazon.smithy")

repositories {
mavenLocal()
mavenCentral()
}

dependencies {
Expand All @@ -25,7 +27,7 @@ dependencies {

configure<software.amazon.smithy.gradle.SmithyExtension> {
// Uncomment this to use a custom projection when building the JAR.
// projection = "trimmed"
// projection = "foo"
}

// Uncomment to disable creating a JAR.
Expand Down
8 changes: 8 additions & 0 deletions examples/source-projection/model/main.smithy
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace smithy.example

structure Baz {
foo: String
}

@aws.api#unsignedPayload
operation Foo()
7 changes: 7 additions & 0 deletions examples/source-projection/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
rootProject.name = "source-projection"

pluginManagement {
repositories {
mavenLocal()
}
}
6 changes: 6 additions & 0 deletions examples/source-projection/smithy-build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"version": "1.0",
"projections": {
"foo": {}
}
}
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
org.gradle.parallel=true
Loading

0 comments on commit 7fd2762

Please sign in to comment.