├── src
├── test
│ └── java
│ │ ├── FeatureRuleOverrideTests.approved
│ │ └── com
│ │ └── oneeyedmen
│ │ └── konsent
│ │ ├── InjectsRecorderTest.approved
│ │ ├── RendersPreambleTest.approved
│ │ ├── TestRunnerAddsRuleTests.approved
│ │ ├── TestRunnerNamingTests.approved
│ │ ├── TestRunnerOrderingTests.approved
│ │ ├── Test Runner Renaming Tests.approved
│ │ ├── RendersPreambleTest.kt
│ │ ├── TestRunnerOrderingTests.kt
│ │ ├── TestRunnerAddsRuleTests.kt
│ │ ├── TestRunnerNamingTests.kt
│ │ ├── InjectsRecorderTest.kt
│ │ ├── FeatureRuleOverrideTests.kt
│ │ ├── KonsentExampleTests.approved
│ │ ├── BetterEnglishTests.approved
│ │ ├── KonsentExampleTests.kt
│ │ └── BetterEnglishTests.kt
└── main
│ └── java
│ └── com
│ └── oneeyedmen
│ └── konsent
│ ├── TestName.kt
│ ├── Preamble.kt
│ ├── AcceptanceTest.kt
│ ├── Scenario.kt
│ ├── FeatureRecorder.kt
│ ├── webdriver
│ ├── ChromeAcceptanceTest.kt
│ ├── web-actions.kt
│ ├── WebAcceptanceTest.kt
│ ├── web-selectors.kt
│ └── web-matchers.kt
│ ├── util
│ └── DelegateRunner.kt
│ ├── Selector.kt
│ ├── ScenarioRule.kt
│ ├── matchers.kt
│ ├── Actor.kt
│ ├── Konsent.kt
│ ├── FeatureRule.kt
│ ├── acceptance-testing.kt
│ └── okeydoke
│ └── TranscriptFeatureRecorder.kt
├── .idea
├── encodings.xml
├── vcs.xml
├── kotlinc.xml
├── modules.xml
├── compiler.xml
└── misc.xml
├── create_readme.sh
├── .gitignore
├── README.md
├── konsent.iml
├── pom.xml
└── LICENSE
/src/test/java/FeatureRuleOverrideTests.approved:
--------------------------------------------------------------------------------
1 | Feature: Feature Rule Override Tests
2 |
3 | Scenario: first
4 |
--------------------------------------------------------------------------------
/src/main/java/com/oneeyedmen/konsent/TestName.kt:
--------------------------------------------------------------------------------
1 | package com.oneeyedmen.konsent
2 |
3 | annotation class TestName(val name: String)
--------------------------------------------------------------------------------
/src/test/java/com/oneeyedmen/konsent/InjectsRecorderTest.approved:
--------------------------------------------------------------------------------
1 | Feature: Injects Recorder Test
2 |
3 | Scenario: first
4 |
--------------------------------------------------------------------------------
/src/main/java/com/oneeyedmen/konsent/Preamble.kt:
--------------------------------------------------------------------------------
1 | package com.oneeyedmen.konsent
2 |
3 | annotation class Preamble(val p1: String = "", val p2: String = "", val p3: String = "")
--------------------------------------------------------------------------------
/src/test/java/com/oneeyedmen/konsent/RendersPreambleTest.approved:
--------------------------------------------------------------------------------
1 | Feature: Renders Preamble Test
2 | As a developer named Duncan
3 | I want there to be a preamble in the output
4 |
5 | Scenario: first
6 |
--------------------------------------------------------------------------------
/src/test/java/com/oneeyedmen/konsent/TestRunnerAddsRuleTests.approved:
--------------------------------------------------------------------------------
1 | Feature: Test Runner Adds Rule Tests
2 |
3 | Scenario: first
4 |
5 | Scenario: second
6 |
7 | Scenario: third
8 |
9 | Scenario: aaa
10 |
--------------------------------------------------------------------------------
/src/test/java/com/oneeyedmen/konsent/TestRunnerNamingTests.approved:
--------------------------------------------------------------------------------
1 | Feature: Test Runner Naming Tests
2 |
3 | Scenario: 1
4 |
5 | Scenario: number 2
6 |
7 | Scenario: erm, 3
8 |
9 | Scenario: the fouth
10 |
--------------------------------------------------------------------------------
/src/test/java/com/oneeyedmen/konsent/TestRunnerOrderingTests.approved:
--------------------------------------------------------------------------------
1 | Feature: Test Runner Ordering Tests
2 |
3 | Scenario: first
4 |
5 | Scenario: second
6 |
7 | Scenario: third
8 |
9 | Scenario: aaa
10 |
--------------------------------------------------------------------------------
/src/test/java/com/oneeyedmen/konsent/Test Runner Renaming Tests.approved:
--------------------------------------------------------------------------------
1 | Feature: Test Runner Renaming Tests
2 |
3 | Scenario: 1
4 |
5 | Scenario: number 2
6 |
7 | Scenario: erm, 3
8 |
9 | Scenario: the fouth
10 |
--------------------------------------------------------------------------------
/src/main/java/com/oneeyedmen/konsent/AcceptanceTest.kt:
--------------------------------------------------------------------------------
1 | package com.oneeyedmen.konsent
2 |
3 | open class AcceptanceTest {
4 |
5 | companion object {
6 | lateinit var recorder: FeatureRecorder // initialised by Konsent
7 | }
8 |
9 | }
--------------------------------------------------------------------------------
/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/.idea/kotlinc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/src/main/java/com/oneeyedmen/konsent/Scenario.kt:
--------------------------------------------------------------------------------
1 | package com.oneeyedmen.konsent
2 |
3 | @Retention(AnnotationRetention.RUNTIME)
4 | @Target(AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY_GETTER, AnnotationTarget.PROPERTY_SETTER)
5 | annotation class Scenario(
6 | val index: Int,
7 | val name: String = ""
8 | )
--------------------------------------------------------------------------------
/src/main/java/com/oneeyedmen/konsent/FeatureRecorder.kt:
--------------------------------------------------------------------------------
1 | package com.oneeyedmen.konsent
2 |
3 |
4 | interface FeatureRecorder {
5 | fun featureStart(name: String, vararg preamble: String): Unit
6 | fun scenarioStart(name: String): Unit
7 | fun term(termName: String?, actor: Actor<*>, operation: String, vararg items: Any): Unit
8 | }
9 |
10 |
--------------------------------------------------------------------------------
/src/test/java/com/oneeyedmen/konsent/RendersPreambleTest.kt:
--------------------------------------------------------------------------------
1 | package com.oneeyedmen.konsent
2 |
3 | import org.junit.runner.RunWith
4 |
5 |
6 | @RunWith(Konsent::class)
7 | @Preamble("As a developer named Duncan",
8 | "I want there to be a preamble in the output")
9 | class RendersPreambleTest {
10 |
11 | @Scenario(index = 0) fun first() { }
12 |
13 | }
14 |
15 |
--------------------------------------------------------------------------------
/src/main/java/com/oneeyedmen/konsent/webdriver/ChromeAcceptanceTest.kt:
--------------------------------------------------------------------------------
1 | package com.oneeyedmen.konsent.webdriver
2 |
3 | import org.junit.BeforeClass
4 | import org.openqa.selenium.chrome.ChromeDriver
5 |
6 | open class ChromeAcceptanceTest : WebAcceptanceTest() {
7 |
8 | companion object {
9 | @BeforeClass @JvmStatic fun createDriver() {
10 | driver = ChromeDriver()
11 | }
12 | }
13 | }
--------------------------------------------------------------------------------
/src/test/java/com/oneeyedmen/konsent/TestRunnerOrderingTests.kt:
--------------------------------------------------------------------------------
1 | package com.oneeyedmen.konsent
2 |
3 | import org.junit.runner.RunWith
4 |
5 |
6 | @RunWith(Konsent::class)
7 | class TestRunnerOrderingTests : AcceptanceTest() {
8 |
9 | @Scenario(1) fun second() { }
10 |
11 | @Scenario(0) fun first() { }
12 |
13 | @Scenario(2) fun third() { }
14 |
15 | @Scenario(4) fun aaa() { }
16 |
17 | }
18 |
19 |
--------------------------------------------------------------------------------
/src/test/java/com/oneeyedmen/konsent/TestRunnerAddsRuleTests.kt:
--------------------------------------------------------------------------------
1 | package com.oneeyedmen.konsent
2 |
3 | import org.junit.runner.RunWith
4 |
5 |
6 | @RunWith(Konsent::class)
7 | class TestRunnerAddsRuleTests {
8 |
9 | @Scenario(index = 1) fun second() { }
10 |
11 | @Scenario(index = 0) fun first() { }
12 |
13 | @Scenario(index = 2) fun third() { }
14 |
15 | @Scenario(index = 4) fun aaa() { }
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/src/main/java/com/oneeyedmen/konsent/util/DelegateRunner.kt:
--------------------------------------------------------------------------------
1 | package com.oneeyedmen.konsent.util
2 |
3 | import org.junit.runner.Description
4 | import org.junit.runner.Runner
5 | import org.junit.runner.notification.RunNotifier
6 |
7 | open class DelegateRunner(private val delegate: Runner) : Runner() {
8 |
9 | override fun getDescription(): Description = delegate.description
10 |
11 | override fun run(notifier: RunNotifier) = delegate.run(notifier)
12 |
13 | }
--------------------------------------------------------------------------------
/src/main/java/com/oneeyedmen/konsent/Selector.kt:
--------------------------------------------------------------------------------
1 | package com.oneeyedmen.konsent
2 |
3 | interface Selector {
4 | fun select(actor: Actor): ResultT
5 | val description: String
6 | }
7 |
8 | fun selector(description: String, block: Actor.() -> ResultT) =
9 | object: Selector {
10 | override val description = description
11 | override fun select(actor: Actor) = block(actor)
12 | }
--------------------------------------------------------------------------------
/src/main/java/com/oneeyedmen/konsent/ScenarioRule.kt:
--------------------------------------------------------------------------------
1 | package com.oneeyedmen.konsent
2 |
3 | import org.junit.rules.TestWatcher
4 | import org.junit.runner.Description
5 |
6 | class ScenarioRule(
7 | private val target: Any,
8 | private val recorder: FeatureRecorder
9 | ) : TestWatcher() {
10 |
11 | override fun starting(description: Description) {
12 | injectRecorder(target.javaClass, target, recorder)
13 | recorder.scenarioStart(description.methodName)
14 | }
15 | }
--------------------------------------------------------------------------------
/src/main/java/com/oneeyedmen/konsent/matchers.kt:
--------------------------------------------------------------------------------
1 | package com.oneeyedmen.konsent
2 |
3 | import com.natpryce.hamkrest.MatchResult
4 | import com.natpryce.hamkrest.Matcher
5 | import com.natpryce.hamkrest.describe
6 |
7 | fun matcherOf(description: String, predicate: (T) -> Boolean) = object: Matcher.Primitive() {
8 | override val description = description
9 | override fun invoke(actual: T): MatchResult = if (predicate(actual)) MatchResult.Match
10 | else MatchResult.Mismatch("was ${describe(actual)}")
11 | }
12 |
--------------------------------------------------------------------------------
/src/test/java/com/oneeyedmen/konsent/TestRunnerNamingTests.kt:
--------------------------------------------------------------------------------
1 | package com.oneeyedmen.konsent
2 |
3 | import com.oneeyedmen.okeydoke.Name
4 | import org.junit.runner.RunWith
5 |
6 |
7 | @RunWith(Konsent::class)
8 | @Name("Test Runner Renaming Tests")
9 | class TestRunnerNamingTests : AcceptanceTest() {
10 |
11 | @Scenario(0, "1") fun first() {}
12 |
13 | @Scenario(1, "number 2") fun second() {}
14 |
15 | @Scenario(2, "erm, 3") fun third() {}
16 |
17 | @Scenario(3, "the fouth") fun aaa() {}
18 |
19 | }
20 |
21 |
--------------------------------------------------------------------------------
/src/main/java/com/oneeyedmen/konsent/webdriver/web-actions.kt:
--------------------------------------------------------------------------------
1 | package com.oneeyedmen.konsent.webdriver
2 |
3 | import com.oneeyedmen.konsent.Steps
4 | import org.openqa.selenium.remote.RemoteWebDriver
5 |
6 | fun Steps.loadsThePageAt(url: String) = describedBy("""loads the page at "$url"""") {
7 | driver.get(url)
8 | }
9 |
10 | fun Steps.followsTheLink(text: String, href: String) = describedBy("""follows the link [$text]($href)""") {
11 | driver.findElementByXPath("//a[@href='$href'][text()='$text']").click()
12 | }
13 |
14 |
--------------------------------------------------------------------------------
/src/test/java/com/oneeyedmen/konsent/InjectsRecorderTest.kt:
--------------------------------------------------------------------------------
1 | package com.oneeyedmen.konsent
2 |
3 | import org.junit.Assert.assertNotNull
4 | import org.junit.runner.RunWith
5 |
6 |
7 | @RunWith(Konsent::class)
8 | class InjectsRecorderTest {
9 |
10 | companion object {
11 | lateinit var recorder: FeatureRecorder
12 | }
13 |
14 | private val recorderDuringConstruction = recorder
15 |
16 | @Scenario(index = 0) fun first() {
17 | assertNotNull(recorder)
18 | assertNotNull(recorderDuringConstruction)
19 | }
20 | }
21 |
22 |
--------------------------------------------------------------------------------
/src/main/java/com/oneeyedmen/konsent/Actor.kt:
--------------------------------------------------------------------------------
1 | package com.oneeyedmen.konsent
2 |
3 |
4 | open class Actor(val name: String, val pronoun:String, val driver: DriverT, val recorder: FeatureRecorder) {
5 |
6 | companion object {
7 | fun with(name: String, driver: DriverT, recorder: FeatureRecorder) = Actor.with(name, "(s)he", driver, recorder)
8 | fun with(name: String, pronoun: String, driver: DriverT, recorder: FeatureRecorder) = Actor(name, pronoun, driver, recorder)
9 | }
10 |
11 | operator fun invoke(function: Steps.() -> Unit) = anonymousSteps(this).function()
12 |
13 | val he = anonymousSteps(this)
14 | val she = anonymousSteps(this)
15 |
16 | }
--------------------------------------------------------------------------------
/src/main/java/com/oneeyedmen/konsent/webdriver/WebAcceptanceTest.kt:
--------------------------------------------------------------------------------
1 | package com.oneeyedmen.konsent.webdriver
2 |
3 | import com.oneeyedmen.konsent.AcceptanceTest
4 | import com.oneeyedmen.konsent.Actor
5 | import org.junit.AfterClass
6 | import org.openqa.selenium.remote.RemoteWebDriver
7 |
8 | open class WebAcceptanceTest : AcceptanceTest() {
9 |
10 | companion object {
11 |
12 | // subclasses should create driver in @BeforeClass
13 | lateinit var driver: RemoteWebDriver
14 |
15 | @AfterClass @JvmStatic fun shutdown() {
16 | driver.close()
17 | }
18 | }
19 |
20 | fun actorNamed(name: String, pronoun: String = "he") = Actor.with(name, pronoun, driver, recorder)
21 | }
22 |
23 |
--------------------------------------------------------------------------------
/create_readme.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | set -e
3 |
4 | function write_file_contents {
5 | echo '```kotlin'
6 | sed -e '1,/README_TEXT/d' -e '/README_TEXT/,$d' $1
7 | echo '```'
8 | }
9 |
10 | echo "
11 | Konsent
12 | =========
13 |
14 | An acceptance testing library for Kotlin.
15 |
16 | [KonsentExampleTests](src/test/java/com/oneeyedmen/konsent/KonsentExampleTests.kt)
17 | shows how to write a test.
18 | " > README.md
19 |
20 | write_file_contents src/test/java/com/oneeyedmen/konsent/KonsentExampleTests.kt >> README.md
21 |
22 | echo "
23 | This writes an approved file
24 |
25 | \`\`\`gherkin
26 | " >> README.md
27 |
28 | cat src/test/java/com/oneeyedmen/konsent/KonsentExampleTests.approved >> README.md
29 |
30 | echo "
31 | \`\`\`
32 |
33 | Konsent is available at Maven central.
34 | " >> README.md
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Created by .ignore support plugin (hsz.mobi)
2 | ### Maven template
3 | target/
4 | pom.xml.tag
5 | pom.xml.releaseBackup
6 | pom.xml.versionsBackup
7 | pom.xml.next
8 | release.properties
9 | dependency-reduced-pom.xml
10 | buildNumber.properties
11 | .mvn/timing.properties
12 | ### JetBrains template
13 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
14 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
15 |
16 | # User-specific stuff:
17 | .idea/workspace.xml
18 | .idea/tasks.xml
19 | .idea/dictionaries
20 | .idea/vcs.xml
21 | .idea/jsLibraryMappings.xml
22 |
23 | # Sensitive or high-churn files:
24 | .idea/dataSources.ids
25 | .idea/dataSources.xml
26 | .idea/dataSources.local.xml
27 | .idea/sqlDataSources.xml
28 | .idea/dynamic.xml
29 | .idea/uiDesigner.xml
30 | .idea/libraries
31 |
32 |
33 |
34 | ## Plugin-specific files:
35 |
36 |
37 |
--------------------------------------------------------------------------------
/src/test/java/com/oneeyedmen/konsent/FeatureRuleOverrideTests.kt:
--------------------------------------------------------------------------------
1 | package com.oneeyedmen.konsent
2 |
3 | import com.oneeyedmen.konsent.util.DelegateRunner
4 | import com.oneeyedmen.okeydoke.Approver
5 | import com.oneeyedmen.okeydoke.ApproverFactory
6 | import com.oneeyedmen.okeydoke.Sources
7 | import com.oneeyedmen.okeydoke.junit.ApprovalsRule
8 | import org.junit.runner.RunWith
9 | import java.io.File
10 |
11 | // Shows that we can fall back to creating a custom test runner to override configuration
12 | @RunWith(MySpecialRunner::class)
13 | class FeatureRuleOverrideTests : AcceptanceTest() {
14 |
15 | @Scenario(0) fun first() {}
16 |
17 | }
18 |
19 | class MySpecialRunner(klass: Class<*>) : DelegateRunner(
20 | Konsent(klass) {
21 | singleApprovedDirFeatureRule(File("src/test/java"))
22 | })
23 |
24 |
25 | private fun singleApprovedDirFeatureRule(dir: File) = FeatureRule(ApprovalsRule(singleDirApproverFactor(dir)))
26 |
27 | private fun singleDirApproverFactor(sourceRoot: File) = ApproverFactory { testName, _ ->
28 | Approver(testName, Sources.`in`(sourceRoot))
29 | }
30 |
--------------------------------------------------------------------------------
/src/test/java/com/oneeyedmen/konsent/KonsentExampleTests.approved:
--------------------------------------------------------------------------------
1 | Feature: Konsent Example Tests
2 | As a developer named Duncan
3 | I want to know that example.com is up and running
4 |
5 | Scenario: Example_dot_com loads
6 | Given Duncan loads the page at "http://example.com"
7 | Then he sees the page location "location contains "example.com"
8 | and the page title is equal to "Example Domain"
9 | and the page content contains a link [More information...](http://www.iana.org/domains/example)
10 |
11 | Scenario: Following a link from example.com
12 | Given Duncan loads the page at "http://example.com"
13 | When he follows the link [More information...](http://www.iana.org/domains/example)
14 | Then he sees the page location is equal to http://www.iana.org/domains/reserved
15 |
16 | Scenario: Dispensing with the given when then
17 | Duncan loads the page at "http://example.com"
18 | he follows the link [More information...](http://www.iana.org/domains/example)
19 | he sees the page location is equal to http://www.iana.org/domains/reserved
20 |
--------------------------------------------------------------------------------
/src/main/java/com/oneeyedmen/konsent/webdriver/web-selectors.kt:
--------------------------------------------------------------------------------
1 | package com.oneeyedmen.konsent.webdriver
2 |
3 | import com.oneeyedmen.konsent.Actor
4 | import com.oneeyedmen.konsent.selector
5 | import org.openqa.selenium.remote.RemoteWebDriver
6 | import org.openqa.selenium.remote.RemoteWebElement
7 | import java.net.URI
8 |
9 | fun webSelector(description: String, block: Actor.() -> ResultT) = selector(description, block)
10 |
11 |
12 | val thePageLocation = webSelector("the page location") {
13 | URI.create(driver.currentUrl)
14 | }
15 |
16 | val thePageContent = webSelector("the page content") {
17 | driver.findElementByTagName("body") as RemoteWebElement?
18 | }
19 |
20 | val thePageTitle = webSelector("the page title") {
21 | driver.title
22 | }
23 |
24 | @Deprecated("too cutesy", replaceWith = ReplaceWith("thePageLocation")) val `the page location` = thePageLocation
25 | @Deprecated("too cutesy", replaceWith = ReplaceWith("thePageContent")) val `the page content` = thePageContent
26 | @Deprecated("too cutesy", replaceWith = ReplaceWith("thePageTitle")) val `the page title` = thePageTitle
27 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/src/test/java/com/oneeyedmen/konsent/BetterEnglishTests.approved:
--------------------------------------------------------------------------------
1 | Feature: Better English Tests
2 |
3 | Scenario: uses 'and' instead of repeating clause
4 | Given Duncan does a thing named "Duncan's thing"
5 | and Alice does a thing named "Alice's thing"
6 | Then she sees the last thing happened is equal to "Alice's thing happened"
7 | and Duncan sees the last thing happened is equal to "Alice's thing happened"
8 |
9 | Scenario: uses 'and' instead of repeating name and operation
10 | Given Duncan does a thing named "Duncan's thing"
11 | Then he sees the last thing happened is equal to "Duncan's thing happened"
12 | and the last thing happened is not equal to "Alice's thing happened"
13 | and Alice sees the last thing happened is equal to "Duncan's thing happened"
14 |
15 | Scenario: uses 'he' instead of repeating name
16 | Then Duncan does a thing named "Duncan's thing"
17 | and he sees the last thing happened is equal to "Duncan's thing happened"
18 |
19 | Scenario: uses 'he' instead of repeating name with anonymous term
20 | Duncan does a thing named "Duncan's thing"
21 | he sees the last thing happened is equal to "Duncan's thing happened"
22 |
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 | 1.8
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
--------------------------------------------------------------------------------
/src/main/java/com/oneeyedmen/konsent/Konsent.kt:
--------------------------------------------------------------------------------
1 | package com.oneeyedmen.konsent
2 |
3 | import com.oneeyedmen.okeydoke.junit.ApprovalsRule
4 | import org.junit.rules.TestRule
5 | import org.junit.runners.BlockJUnit4ClassRunner
6 | import org.junit.runners.model.FrameworkMethod
7 |
8 | class Konsent(
9 | klass: Class<*>,
10 | featureRuleFactory: (Class<*>) -> FeatureRule
11 | ) : BlockJUnit4ClassRunner(klass) {
12 |
13 | constructor(klass: Class<*>) : this(klass, ::usualFeatureRuleFor)
14 |
15 | private val featureRule = featureRuleFactory(klass)
16 |
17 | override fun computeTestMethods() = testClass.getAnnotatedMethods(Scenario::class.java)
18 | .map { it.butNamed(it.getAnnotation(Scenario::class.java).name)}
19 | .sortedBy { it.getAnnotation(Scenario::class.java).index }
20 |
21 | // we fake a FeatureRule attached to the class
22 | override fun classRules(): List = super.classRules().apply {
23 | add(featureRule)
24 | }
25 |
26 | // and a ScenarioRule attached to the instance
27 | override fun getTestRules(target: Any): List = super.getTestRules(target).apply {
28 | add(ScenarioRule(target, featureRule.recorder))
29 | }
30 |
31 | private fun FrameworkMethod.butNamed(newName: String) = if (newName == "") this
32 | else object: FrameworkMethod(method) {
33 | override fun getName(): String = newName
34 | }
35 | }
36 |
37 | @Suppress("UNUSED_PARAMETER")
38 | fun usualFeatureRuleFor(klass: Class<*>) = FeatureRule(ApprovalsRule.usualRule())
39 |
40 |
--------------------------------------------------------------------------------
/src/main/java/com/oneeyedmen/konsent/webdriver/web-matchers.kt:
--------------------------------------------------------------------------------
1 | package com.oneeyedmen.konsent.webdriver
2 |
3 | import com.natpryce.hamkrest.MatchResult
4 | import com.natpryce.hamkrest.Matcher
5 | import com.oneeyedmen.konsent.matcherOf
6 | import org.openqa.selenium.WebElement
7 | import org.openqa.selenium.remote.RemoteWebElement
8 | import java.net.URI
9 |
10 | fun elementMatcher(description: String, predicate: (T) -> Boolean) = object: Matcher.Primitive() {
11 | override val description = description
12 | override fun invoke(actual: T): MatchResult = if (predicate(actual)) MatchResult.Match
13 | else MatchResult.Mismatch("was ${describeWebElement(actual)}")
14 |
15 | private fun describeWebElement(actual: T): String {
16 | if (actual == null)
17 | return "[No such element]"
18 | else
19 | return "<${actual.tagName}>${actual.text}>"
20 | }
21 | }
22 |
23 | fun containsALink(text: String, href: String) = elementMatcher("contains a link [$text]($href)") { element ->
24 | element != null && element.findElementsByXPath("//a[@href='$href'][text()='$text']").isNotEmpty()
25 | }
26 |
27 | val isntThere = elementMatcher("isn't there") { it == null }
28 |
29 | val hasSomeContent = elementMatcher("has some content") {
30 | it != null && it.isDisplayed
31 | }
32 |
33 | fun pathContains(pathElement: String) = matcherOf(""""location contains "$pathElement"""") { uri ->
34 | uri.toString().contains(pathElement)
35 | }
36 |
37 |
--------------------------------------------------------------------------------
/src/test/java/com/oneeyedmen/konsent/KonsentExampleTests.kt:
--------------------------------------------------------------------------------
1 | package com.oneeyedmen.konsent
2 |
3 | import com.natpryce.hamkrest.equalTo
4 | import com.oneeyedmen.konsent.webdriver.*
5 | import org.junit.Ignore
6 | import org.junit.runner.RunWith
7 | import java.net.URI
8 |
9 | @Ignore("ChromeDriver not working for me ATM")
10 | //README_TEXT
11 | @RunWith(Konsent::class)
12 | @Preamble(
13 | "As a developer named Duncan",
14 | "I want to know that example.com is up and running")
15 | class KonsentExampleTests : ChromeAcceptanceTest() {
16 |
17 | val duncan = actorNamed("Duncan")
18 |
19 | @Scenario(1) fun `Example_dot_com loads`() {
20 | Given(duncan).loadsThePageAt("http://example.com")
21 | Then(duncan) {
22 | shouldSee(thePageLocation, pathContains("example.com"))
23 | shouldSee(thePageTitle, equalTo("Example Domain"))
24 | shouldSee(thePageContent, containsALink("More information...", "http://www.iana.org/domains/example"))
25 | }
26 | }
27 |
28 | @Scenario(2, "Following a link from example.com") fun cant_have_dots_in_quoted_method_names() {
29 | Given(duncan).loadsThePageAt("http://example.com")
30 | When(duncan).followsTheLink("More information...", "http://www.iana.org/domains/example")
31 | Then(duncan).shouldSee(thePageLocation, equalTo(URI("http://www.iana.org/domains/reserved")))
32 | }
33 |
34 | @Scenario(3) fun `Dispensing with the given when then`() {
35 | duncan.he.loadsThePageAt("http://example.com")
36 | duncan.he.followsTheLink("More information...", "http://www.iana.org/domains/example")
37 | duncan.he.shouldSee(thePageLocation, equalTo(URI("http://www.iana.org/domains/reserved")))
38 | }
39 | }
40 | //README_TEXT
--------------------------------------------------------------------------------
/src/main/java/com/oneeyedmen/konsent/FeatureRule.kt:
--------------------------------------------------------------------------------
1 | package com.oneeyedmen.konsent
2 |
3 | import com.oneeyedmen.konsent.okeydoke.TranscriptFeatureRecorder
4 | import com.oneeyedmen.okeydoke.Name
5 | import com.oneeyedmen.okeydoke.junit.ApprovalsRule
6 | import org.junit.rules.TestWatcher
7 | import org.junit.runner.Description
8 |
9 | class FeatureRule(private val approvalsRule: ApprovalsRule) : TestWatcher() {
10 |
11 | lateinit var recorder: FeatureRecorder
12 |
13 | override fun starting(description: Description) {
14 | approvalsRule.starting(description)
15 | recorder = TranscriptFeatureRecorder(approvalsRule.transcript())
16 | recorder.featureStart(featureNameFrom(description), *preambleFor(description.testClass))
17 | injectRecorder(description.testClass, null, recorder)
18 | }
19 |
20 | private fun preambleFor(testClass: Class<*>): Array {
21 | val preamble = testClass.getAnnotation(Preamble::class.java)
22 | return if (preamble != null) listOf(preamble.p1, preamble.p2, preamble.p3).filter { it.isNotBlank() }.toTypedArray()
23 | else emptyArray()
24 | }
25 |
26 | override fun succeeded(description: Description) {
27 | approvalsRule.succeeded(description)
28 | }
29 |
30 | }
31 |
32 | internal fun injectRecorder(clazz: Class, target: T?, recorder: FeatureRecorder) {
33 | clazz.fields.filter { it.type == FeatureRecorder::class.java }.forEach { it.set(target, recorder) }
34 | }
35 |
36 | private val spaceOutCamelCase = Regex("(\\p{Ll})(\\p{Lu})")
37 | private fun String.`space Out Camel Case`() = this.replace(spaceOutCamelCase, "$1 $2")
38 | private fun featureNameFrom(description: Description) =
39 | nameFromClassAnnotation(description) ?: description.testClass.simpleName.`space Out Camel Case`()
40 |
41 | private fun nameFromClassAnnotation(description: Description): String? =
42 | description.testClass?.getAnnotation(Name::class.java)?.value
--------------------------------------------------------------------------------
/src/main/java/com/oneeyedmen/konsent/acceptance-testing.kt:
--------------------------------------------------------------------------------
1 | package com.oneeyedmen.konsent
2 |
3 | import com.natpryce.hamkrest.MatchResult
4 | import com.natpryce.hamkrest.Matcher
5 |
6 | fun Given(actor: Actor, function: Steps.() -> Unit) = function.invoke(givenSteps(actor))
7 | fun Given(actor: Actor) = givenSteps(actor)
8 |
9 | fun When(actor: Actor, function: Steps.() -> Unit) = function.invoke(whenSteps(actor))
10 | fun When(actor: Actor) = whenSteps(actor)
11 |
12 | fun Then(actor: Actor, function: Steps.() -> Unit) = function.invoke(thenSteps(actor))
13 | fun Then(actor: Actor) = thenSteps(actor)
14 |
15 | fun Steps.shouldSee(selector: Selector, matcher: Matcher) {
16 | val matchResult = matcher.invoke(selector.select(actor))
17 | val resultString = when(matchResult) {
18 | is MatchResult.Mismatch -> "[expected ${matcher.description}, ${matchResult.description}]"
19 | else -> matcher.description
20 | }
21 | record("sees", selector.description, resultString)
22 | }
23 |
24 | class Steps(val actor: Actor, val driver: DriverT, val recorder: FeatureRecorder, private val term: String?) {
25 | fun describedBy(stepName: String, block: Steps.() -> Unit) {
26 | record(stepName)
27 | block()
28 | }
29 | fun record(operation: String, vararg args: Any) = recorder.term(term, actor, operation, *args)
30 |
31 | }
32 |
33 | fun anonymousSteps(actor: Actor) = Steps(actor, actor.driver, actor.recorder, null)
34 | fun givenSteps(actor: Actor) = Steps(actor, actor.driver, actor.recorder, "Given")
35 | fun whenSteps(actor: Actor) = Steps(actor, actor.driver, actor.recorder, "When")
36 | fun thenSteps(actor: Actor) = Steps(actor, actor.driver, actor.recorder, "Then")
37 |
38 |
--------------------------------------------------------------------------------
/src/test/java/com/oneeyedmen/konsent/BetterEnglishTests.kt:
--------------------------------------------------------------------------------
1 | package com.oneeyedmen.konsent
2 |
3 | import com.natpryce.hamkrest.equalTo
4 | import org.junit.runner.RunWith
5 |
6 | @RunWith(Konsent::class)
7 | class BetterEnglishTests : AcceptanceTest() {
8 |
9 | val driver = DummyDriver()
10 | val duncan = Actor.with("Duncan", "he", driver, recorder)
11 | val alice = Actor.with("Alice", "she", driver, recorder)
12 |
13 | @Scenario(1) fun `uses 'and' instead of repeating clause`() {
14 | Given(duncan).doesAThing("Duncan's thing")
15 | Given(alice).doesAThing("Alice's thing")
16 | Then(alice).shouldSee(theLastThingHappened, equalTo("Alice's thing happened"))
17 | Then(duncan).shouldSee(theLastThingHappened, equalTo("Alice's thing happened"))
18 | }
19 |
20 | @Scenario(2) fun `uses 'and' instead of repeating name and operation`() {
21 | Given(duncan).doesAThing("Duncan's thing")
22 | Then(duncan).shouldSee(theLastThingHappened, equalTo("Duncan's thing happened"))
23 | Then(duncan).shouldSee(theLastThingHappened, equalTo("Alice's thing happened").not())
24 | Then(alice).shouldSee(theLastThingHappened, equalTo("Duncan's thing happened"))
25 | }
26 |
27 | @Scenario(3) fun `uses 'he' instead of repeating name`() {
28 | Then(duncan).doesAThing("Duncan's thing")
29 | Then(duncan).shouldSee(theLastThingHappened, equalTo("Duncan's thing happened"))
30 | }
31 |
32 | @Scenario(4) fun `uses 'he' instead of repeating name with anonymous term`() {
33 | duncan.he.doesAThing("Duncan's thing")
34 | duncan.he.shouldSee(theLastThingHappened, equalTo("Duncan's thing happened"))
35 | }
36 |
37 | }
38 |
39 | val theLastThingHappened = selector("the last thing happened") {
40 | driver.state
41 | }
42 |
43 | private fun Steps.doesAThing(s: String) = describedBy("""does a thing named "$s"""") {
44 | driver.doThing(s)
45 | }
46 |
47 | class DummyDriver {
48 | var state: String? = null
49 |
50 | fun doThing(s: String) {
51 | state = "$s happened"
52 | }
53 |
54 | }
55 |
--------------------------------------------------------------------------------
/src/main/java/com/oneeyedmen/konsent/okeydoke/TranscriptFeatureRecorder.kt:
--------------------------------------------------------------------------------
1 | package com.oneeyedmen.konsent.okeydoke
2 |
3 | import com.oneeyedmen.konsent.Actor
4 | import com.oneeyedmen.konsent.FeatureRecorder
5 | import com.oneeyedmen.okeydoke.Transcript
6 |
7 | class TranscriptFeatureRecorder(val transcript: Transcript, val indent: Int = 4) : FeatureRecorder {
8 |
9 | private var lastTermName: String? = null
10 | private var lastActor: Actor<*>? = null
11 | private var lastOperation: String? = null
12 |
13 | override fun featureStart(name: String, vararg preamble: String) {
14 | transcript.append("Feature: ").appendLine(name)
15 | preamble.forEach {
16 | indent(1).appendLine(it)
17 | }
18 | }
19 |
20 | override fun scenarioStart(name: String) {
21 | reset()
22 | transcript.endl()
23 | indent(1).append("Scenario: ").appendLine(name)
24 | }
25 |
26 | override fun term(termName: String?, actor: Actor<*>, operation: String, vararg items: Any) {
27 | indent(2).appendLine(collectTerms(termName, actor, operation, *items).joinToString(" "))
28 | lastActor = actor
29 | lastTermName = termName
30 | lastOperation = operation
31 | }
32 |
33 |
34 | private fun indent(level: Int): Transcript {
35 | if (transcript.isStartOfLine)
36 | transcript.space(indent * level)
37 | return transcript
38 | }
39 |
40 | private fun collectTerms(termName: String?, actor: Actor<*>, operation: String, vararg items: Any) : List =
41 | listOf(prefixOrAnd(termName.orEmpty(), actor, operation)).plus(items)
42 |
43 | private fun prefixOrAnd(termName: String, actor: Actor<*>, operation: String): String {
44 | val actorName = if (actor == lastActor) actor.pronoun else actor.name
45 | val termNameAndSeparator = if (termName.isEmpty()) "" else termName + " "
46 | return when {
47 | termName == lastTermName && actor == lastActor && operation == lastOperation-> "and"
48 | termName == lastTermName -> "and $actorName $operation"
49 | else -> "$termNameAndSeparator${actorName} $operation"
50 | }
51 | }
52 |
53 | private fun reset() {
54 | lastTermName = null
55 | lastActor = null
56 | lastOperation = null
57 | }
58 | }
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 | Konsent
3 | =========
4 |
5 | An acceptance testing library for Kotlin.
6 |
7 | [KonsentExampleTests](src/test/java/com/oneeyedmen/konsent/KonsentExampleTests.kt)
8 | shows how to write a test.
9 |
10 | ```kotlin
11 | @RunWith(Konsent::class)
12 | @Preamble(
13 | "As a developer named Duncan",
14 | "I want to know that example.com is up and running")
15 | class KonsentExampleTests : ChromeAcceptanceTest() {
16 |
17 | val duncan = actorNamed("Duncan")
18 |
19 | @Scenario(1) fun `Example_dot_com loads`() {
20 | Given(duncan).loadsThePageAt("http://example.com")
21 | Then(duncan) {
22 | shouldSee(thePageLocation, pathContains("example.com"))
23 | shouldSee(thePageTitle, equalTo("Example Domain"))
24 | shouldSee(thePageContent, containsALink("More information...", "http://www.iana.org/domains/example"))
25 | }
26 | }
27 |
28 | @Scenario(2, "Following a link from example.com") fun cant_have_dots_in_quoted_method_names() {
29 | Given(duncan).loadsThePageAt("http://example.com")
30 | When(duncan).followsTheLink("More information...", "http://www.iana.org/domains/example")
31 | Then(duncan).shouldSee(thePageLocation, equalTo(URI("http://www.iana.org/domains/reserved")))
32 | }
33 |
34 | @Scenario(3) fun `Dispensing with the given when then`() {
35 | duncan.he.loadsThePageAt("http://example.com")
36 | duncan.he.followsTheLink("More information...", "http://www.iana.org/domains/example")
37 | duncan.he.shouldSee(thePageLocation, equalTo(URI("http://www.iana.org/domains/reserved")))
38 | }
39 | }
40 | ```
41 |
42 | This writes an approved file
43 |
44 | ```gherkin
45 |
46 | Feature: Konsent Example Tests
47 | As a developer named Duncan
48 | I want to know that example.com is up and running
49 |
50 | Scenario: Example_dot_com loads
51 | Given Duncan loads the page at "http://example.com"
52 | Then he sees the page location "location contains "example.com"
53 | and the page title is equal to "Example Domain"
54 | and the page content contains a link [More information...](http://www.iana.org/domains/example)
55 |
56 | Scenario: Following a link from example.com
57 | Given Duncan loads the page at "http://example.com"
58 | When he follows the link [More information...](http://www.iana.org/domains/example)
59 | Then he sees the page location is equal to http://www.iana.org/domains/reserved
60 |
61 | Scenario: Dispensing with the given when then
62 | Duncan loads the page at "http://example.com"
63 | he follows the link [More information...](http://www.iana.org/domains/example)
64 | he sees the page location is equal to http://www.iana.org/domains/reserved
65 |
66 | ```
67 |
68 | Konsent is available at Maven central.
69 |
70 |
--------------------------------------------------------------------------------
/konsent.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 | 4.0.0
3 |
4 | com.oneeyedmen
5 | konsent
6 | 1.0.8-SNAPSHOT
7 | jar
8 |
9 | kosent
10 | An acceptance testing library
11 | https://github.com/dmcg/konsent
12 |
13 |
14 | Apache License, Version 2.0
15 | http://www.apache.org/licenses/LICENSE-2.0.txt
16 | repo
17 |
18 |
19 |
20 |
21 | dmcg
22 | Duncan McGregor
23 |
24 |
25 |
26 |
27 | 1.2.41
28 | UTF-8
29 | UTF-8
30 |
31 |
32 |
33 | scm:git:git@github.com:dmcg/konsent.git
34 | scm:git:git@github.com:dmcg/konsent.git
35 | https://github.com/dmcg/konsent
36 | HEAD
37 |
38 |
39 |
40 |
41 | org.jetbrains.kotlin
42 | kotlin-stdlib
43 | ${kotlin.version}
44 |
45 |
46 | com.natpryce
47 | hamkrest
48 | 1.4.2.2
49 |
50 |
51 | com.oneeyedmen
52 | okeydoke
53 | 1.1.0
54 |
55 |
56 | junit
57 | junit
58 | 4.12
59 |
60 |
61 | org.seleniumhq.selenium
62 | selenium-java
63 | 2.53.0
64 | provided
65 |
66 |
67 | org.jetbrains.kotlin
68 | kotlin-test
69 | ${kotlin.version}
70 | test
71 |
72 |
73 |
74 |
75 |
76 |
77 | true
78 | org.apache.maven.plugins
79 | maven-compiler-plugin
80 | 3.7.0
81 |
82 | 1.6
83 | 1.6
84 | true
85 | true
86 |
87 |
88 |
89 | org.apache.maven.plugins
90 | maven-source-plugin
91 | 3.0.1
92 |
93 |
94 | attach-sources
95 |
96 | jar
97 |
98 |
99 |
100 |
101 |
102 | kotlin-maven-plugin
103 |
104 | 1.8
105 |
106 | org.jetbrains.kotlin
107 | ${kotlin.version}
108 |
109 |
110 | compile
111 | compile
112 |
113 | compile
114 |
115 |
116 |
117 | test-compile
118 | test-compile
119 |
120 | test-compile
121 |
122 |
123 |
124 |
125 |
126 | org.jetbrains.dokka
127 | dokka-maven-plugin
128 | 0.9.7
129 |
130 |
131 | prepare-package
132 |
133 | dokka
134 |
135 |
136 |
137 |
138 | ${project.build.directory}/apidocs
139 |
140 |
141 | ${project.basedir}/src/main/kotlin
142 | http://github.com/dmcg/konsent
143 |
144 |
145 |
146 |
147 |
148 | org.apache.maven.plugins
149 | maven-javadoc-plugin
150 | 2.10.4
151 |
152 |
153 | attach-javadocs
154 |
155 | jar
156 |
157 |
158 |
159 |
160 |
161 | org.apache.maven.plugins
162 | maven-gpg-plugin
163 | 1.6
164 |
165 |
166 | sign-artifacts
167 | verify
168 |
169 | sign
170 |
171 |
172 |
173 |
174 |
175 | org.apache.maven.plugins
176 | maven-release-plugin
177 | 2.5.3
178 |
179 |
180 | maven-antrun-plugin
181 |
182 |
183 | update-readme
184 | prepare-package
185 |
186 | run
187 |
188 |
189 |
190 |
191 |
192 |
193 |
194 |
195 |
196 |
197 |
198 |
199 |
200 |
201 |
202 | bintray
203 | https://api.bintray.com/maven/dmcg/oneeyedmen-mvn/konsent/;publish=1
204 |
205 |
206 |
207 |
208 |
209 | jcenter
210 | JCenter
211 | https://jcenter.bintray.com/
212 |
213 |
214 |
215 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "{}"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright {yyyy} {name of copyright owner}
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------