Skip to content

Commit

Permalink
Add module for end-to-end testing library
Browse files Browse the repository at this point in the history
  • Loading branch information
Tommy Lillehagen committed Feb 2, 2018
1 parent 258b562 commit f3d2a76
Show file tree
Hide file tree
Showing 13 changed files with 234 additions and 1 deletion.
5 changes: 4 additions & 1 deletion .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

107 changes: 107 additions & 0 deletions experimental/behave/build.gradle
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package net.corda.behave

object Utility {

fun dummy() = true

}
12 changes: 12 additions & 0 deletions experimental/behave/src/scenario/kotlin/Scenarios.kt
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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() {
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package net.corda.behave.scenarios

class ScenarioState {

var count: Int = 0

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package net.corda.behave.scenarios

typealias StepsBlock = (StepsContainer.() -> Unit) -> Unit
Original file line number Diff line number Diff line change
@@ -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)
}

}
Original file line number Diff line number Diff line change
@@ -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}")
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Feature: Dummy
Lorem ipsum

Scenario: Noop
Given 15 dummies exist
Then there is a dummy
14 changes: 14 additions & 0 deletions experimental/behave/src/scenario/resources/log4j2.xml
Original file line number Diff line number Diff line change
@@ -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>
Original file line number Diff line number Diff line change
@@ -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())
}

}
1 change: 1 addition & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit f3d2a76

Please sign in to comment.