Add module for end-to-end testing library

This commit is contained in:
Tommy Lillehagen 2018-02-01 16:06:12 +00:00
parent 258b562e16
commit f3d2a7674c
13 changed files with 234 additions and 1 deletions

3
.idea/compiler.xml generated
View File

@ -10,6 +10,9 @@
<module name="bank-of-corda-demo_integrationTest" target="1.8" />
<module name="bank-of-corda-demo_main" target="1.8" />
<module name="bank-of-corda-demo_test" target="1.8" />
<module name="behave_main" target="1.8" />
<module name="behave_scenario" target="1.8" />
<module name="behave_test" target="1.8" />
<module name="bootstrapper_main" target="1.8" />
<module name="bootstrapper_test" target="1.8" />
<module name="buildSrc_main" target="1.8" />

View File

@ -0,0 +1,107 @@
buildscript {
ext.kotlin_version = '1.2.21'
ext.commonsio_version = '2.6'
ext.cucumber_version = '1.2.5'
ext.crash_version = 'cce5a00f114343c1145c1d7756e1dd6df3ea984e'
ext.docker_client_version = '8.11.0'
repositories {
maven {
jcenter()
url 'https://jitpack.io'
}
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
group 'net.corda.behave'
apply plugin: 'java'
apply plugin: 'kotlin'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
sourceSets {
scenario {
java {
compileClasspath += main.output
runtimeClasspath += main.output
srcDir file('src/scenario/kotlin')
}
resources.srcDir file('src/scenario/resources')
}
}
configurations {
scenarioCompile.extendsFrom testCompile
scenarioRuntime.extendsFrom testRuntime
}
dependencies {
// Library
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
compile "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
compile("com.github.corda.crash:crash.shell:$crash_version") {
exclude group: "org.slf4j", module: "slf4j-jdk14"
exclude group: "org.bouncycastle"
}
compile("com.github.corda.crash:crash.connectors.ssh:$crash_version") {
exclude group: "org.slf4j", module: "slf4j-jdk14"
exclude group: "org.bouncycastle"
}
compile "com.spotify:docker-client:$docker_client_version"
// Unit Tests
testCompile "junit:junit:$junit_version"
// Scenarios / End-to-End Tests
scenarioCompile "info.cukes:cucumber-java8:$cucumber_version"
scenarioCompile "info.cukes:cucumber-junit:$cucumber_version"
scenarioCompile "info.cukes:cucumber-picocontainer:$cucumber_version"
scenarioCompile "org.assertj:assertj-core:$assertj_version"
scenarioCompile "org.slf4j:log4j-over-slf4j:$slf4j_version"
scenarioCompile "org.slf4j:jul-to-slf4j:$slf4j_version"
scenarioCompile "org.apache.logging.log4j:log4j-slf4j-impl:$log4j_version"
scenarioCompile "org.apache.logging.log4j:log4j-core:$log4j_version"
scenarioCompile "commons-io:commons-io:$commonsio_version"
}
compileKotlin {
kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
kotlinOptions.jvmTarget = "1.8"
}
compileScenarioKotlin {
kotlinOptions.jvmTarget = "1.8"
}
test {
testLogging.showStandardStreams = true
}
task scenarios(type: Test) {
setTestClassesDirs sourceSets.scenario.output.getClassesDirs()
classpath = sourceSets.scenario.runtimeClasspath
outputs.upToDateWhen { false }
}
scenarios.mustRunAfter test
scenarios.dependsOn test

View File

@ -0,0 +1,7 @@
package net.corda.behave
object Utility {
fun dummy() = true
}

View File

@ -0,0 +1,12 @@
import cucumber.api.CucumberOptions
import cucumber.api.junit.Cucumber
import org.junit.runner.RunWith
@RunWith(Cucumber::class)
@CucumberOptions(
features = arrayOf("src/scenario/resources/features"),
glue = arrayOf("net.corda.behave.scenarios"),
plugin = arrayOf("pretty")
)
@Suppress("KDocMissingDocumentation")
class CucumberTest

View File

@ -0,0 +1,17 @@
package net.corda.behave.scenarios
import cucumber.api.java.After
import cucumber.api.java.Before
@Suppress("KDocMissingDocumentation")
class ScenarioHooks(private val state: ScenarioState) {
@Before
fun beforeScenario() {
}
@After
fun afterScenario() {
}
}

View File

@ -0,0 +1,7 @@
package net.corda.behave.scenarios
class ScenarioState {
var count: Int = 0
}

View File

@ -0,0 +1,3 @@
package net.corda.behave.scenarios
typealias StepsBlock = (StepsContainer.() -> Unit) -> Unit

View File

@ -0,0 +1,25 @@
package net.corda.behave.scenarios
import cucumber.api.java8.En
import net.corda.behave.scenarios.steps.dummySteps
import org.slf4j.Logger
import org.slf4j.LoggerFactory
@Suppress("KDocMissingDocumentation")
class StepsContainer(val state: ScenarioState) : En {
val log: Logger = LoggerFactory.getLogger(StepsContainer::class.java)
private val stepDefinitions: List<(StepsBlock) -> Unit> = listOf(
::dummySteps
)
init {
stepDefinitions.forEach { it({ this.steps(it) }) }
}
private fun steps(action: (StepsContainer.() -> Unit)) {
action(this)
}
}

View File

@ -0,0 +1,18 @@
package net.corda.behave.scenarios.steps
import net.corda.behave.scenarios.StepsBlock
import org.assertj.core.api.Assertions.assertThat
fun dummySteps(steps: StepsBlock) = steps {
When<Int, String>("^(\\d+) dumm(y|ies) exists?$") { count, _ ->
state.count = count
log.info("Checking pre-condition $count")
}
Then("^there is a dummy$") {
assertThat(state.count).isGreaterThan(0)
log.info("Checking outcome ${state.count}")
}
}

View File

@ -0,0 +1,6 @@
Feature: Dummy
Lorem ipsum
Scenario: Noop
Given 15 dummies exist
Then there is a dummy

View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="info">
<ThresholdFilter level="info"/>
<Appenders>
<Console name="STDOUT" target="SYSTEM_OUT" ignoreExceptions="false">
<PatternLayout pattern="%m%n"/>
</Console>
</Appenders>
<Loggers>
<Root level="info">
<AppenderRef ref="STDOUT"/>
</Root>
</Loggers>
</Configuration>

View File

@ -0,0 +1,13 @@
package net.corda.behave
import org.junit.Assert
import org.junit.Test
class UtilityTests {
@Test
fun `dummy`() {
Assert.assertEquals(true, Utility.dummy())
}
}

View File

@ -16,6 +16,7 @@ include 'client:rpc'
include 'webserver'
include 'webserver:webcapsule'
include 'experimental'
include 'experimental:behave'
include 'experimental:sandbox'
include 'experimental:quasar-hook'
include 'experimental:kryo-hook'