Skip to content
This repository has been archived by the owner on Aug 10, 2024. It is now read-only.

Commit

Permalink
checkpoint while debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
sanity committed Mar 18, 2018
1 parent 4671a0e commit 83387ea
Show file tree
Hide file tree
Showing 8 changed files with 198 additions and 128 deletions.
49 changes: 35 additions & 14 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,29 @@ buildscript {
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'org.junit.platform:junit-platform-gradle-plugin:1.0.0'
classpath "org.jetbrains.dokka:dokka-gradle-plugin:$dokka_version"
classpath 'info.solidsoft.gradle.pitest:gradle-pitest-plugin:1.1.10'
}
}

group 'io.kweb'
version '0.2.14'
version '0.3.0'

apply plugin: 'java'
apply plugin: 'kotlin'
apply plugin: 'maven'
apply plugin: 'org.jetbrains.dokka'
apply plugin: "info.solidsoft.pitest"
apply plugin: 'org.junit.platform.gradle.plugin'

junitPlatform {
filters {
engines {
include 'spek'
}
}
}

sourceCompatibility = 1.8
targetCompatibility = 1.8
Expand All @@ -46,12 +56,10 @@ repositories {
maven {
url "http://dl.bintray.com/kotlin/ktor"
}
/* maven {
url "http://dl.bintray.com/cy6ergn0m/maven"
} */
maven {
url 'https://jitpack.io'
}
maven { url "http://dl.bintray.com/jetbrains/spek" }
jcenter()
}

Expand All @@ -73,19 +81,27 @@ sourceSets {


dependencies {
// Temp for development
compile project(":renegade")

compile 'com.github.salomonbrys.kotson:kotson:2.3.0'
compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.0'
compile group: 'commons-io', name: 'commons-io', version: '2.5'


//////////////////////////////
// Kotlin library dependencies
//////////////////////////////
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
compile "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
compile 'org.jetbrains.kotlinx:kotlinx-coroutines-core:0.21-alpha-2'
compile 'org.jetbrains.kotlinx:kotlinx-coroutines-jdk8:0.21-alpha-2'

// TODO: This should be testCompile
compile group: 'ch.qos.logback', name: 'logback-classic', version: '1.+'
// Should be compileOnly
compile group: 'org.hotswapagent', name: 'hotswap-agent-core', version: '1.1.0'

////////////////////
// Ktor dependencies
////////////////////
compile ("io.ktor:ktor-server-core:$ktor_version") {
exclude group : 'ch.qos.logback', module : 'logback-classic'
}
Expand All @@ -104,15 +120,20 @@ dependencies {

compile 'com.github.kwebio:shoebox:0.2.13'

///////////////////////////
// Dependencies for testing
///////////////////////////
compile group: 'net.sourceforge.htmlunit', name: 'htmlunit', version: '2.29'
testCompile 'io.kotlintest:kotlintest:2.0.3'
testCompile ('org.jetbrains.spek:spek-api:1.1.5') {
exclude group: 'org.jetbrains.kotlin'
}
testRuntime ('org.jetbrains.spek:spek-junit-platform-engine:1.1.5') {
exclude group: 'org.junit.platform'
exclude group: 'org.jetbrains.kotlin'
}
testImplementation 'org.amshove.kluent:kluent:1.35'
testCompile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.+'

// TODO: This should be testCompile
compile group: 'ch.qos.logback', name: 'logback-classic', version: '1.+'

// Should be compileOnly
compile group: 'org.hotswapagent', name: 'hotswap-agent-core', version: '1.1.0'

}

Expand Down
1 change: 1 addition & 0 deletions src/main/kotlin/io/kweb/Kweb.kt
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@ class Kweb(val port: Int,
}

override fun close() {
logger.info("Shutting down Kweb")
server.stop(0, 0, TimeUnit.SECONDS)
}

Expand Down
16 changes: 2 additions & 14 deletions src/test/kotlin/io/kweb/BasicBrowserInteropSpec.kt
Original file line number Diff line number Diff line change
@@ -1,21 +1,10 @@
package io.kweb

import com.gargoylesoftware.htmlunit.AjaxController
import com.gargoylesoftware.htmlunit.BrowserVersion
import com.gargoylesoftware.htmlunit.WebClient
import com.gargoylesoftware.htmlunit.WebRequest
import com.gargoylesoftware.htmlunit.html.HtmlPage
import io.kotlintest.matchers.shouldBe
import io.kotlintest.specs.FreeSpec
import io.kweb.dom.element.creation.tags.h1
import io.kweb.dom.element.new
import java.io.Closeable



/**
* Created by ian on 4/30/17.
*/
class BasicBrowserInteropSpec : FreeSpec() {
val webClient : WebClient = autoClose(ACWebClient().apply {
options.apply {
Expand Down Expand Up @@ -52,5 +41,4 @@ class BasicBrowserInteropSpec : FreeSpec() {
}
}
}

class ACWebClient : WebClient(BrowserVersion.BEST_SUPPORTED), Closeable
*/
42 changes: 42 additions & 0 deletions src/test/kotlin/io/kweb/KwebSpec.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package io.kweb

import com.gargoylesoftware.htmlunit.html.HtmlPage
import io.kweb.dom.element.creation.tags.h1
import io.kweb.dom.element.new
import org.amshove.kluent.shouldEqual
import org.jetbrains.spek.api.Spek
import org.jetbrains.spek.api.dsl.*

object KwebSpec : Spek({
given("a Kweb instance listening on port 12243") {
on("creating a kweb server") {
val kweb = Kweb(port = 12243) {
doc.body.new {
h1().text("Lorum Ipsum")
}
}


useWebClient { webClient ->


val page = webClient.getPage<HtmlPage>("http://localhost:12243/")

webClient.waitForBackgroundJavaScript(10000)

page.getElementsByTagName("h1").let { h1Elements ->
it("should contain one H1 element containing the appropriate text") {
h1Elements.size shouldEqual 1
h1Elements.first().let { h1Element ->
h1Element.textContent shouldEqual "Lorum Ipsum"
}
}
}

}

kweb.close()
}

}
})
22 changes: 5 additions & 17 deletions src/test/kotlin/io/kweb/routing/RoutingSpec.kt
Original file line number Diff line number Diff line change
@@ -1,25 +1,12 @@
package io.kweb.routing

import com.gargoylesoftware.htmlunit.WebClient
import com.gargoylesoftware.htmlunit.html.HtmlPage
import io.kotlintest.*
import io.kotlintest.matchers.*
import io.kotlintest.specs.FreeSpec
import io.kweb.*
import io.kweb.dom.attributes.*
import io.kweb.dom.element.creation.tags.h1
import io.kweb.dom.element.events.on
import io.kweb.dom.element.new
import io.kweb.state.persistent.render
import mu.KotlinLogging
import java.lang.Thread.sleep

/**
* Created by ian on 4/30/17.
*/
class RoutingSpec : FreeSpec() {
/*
object RoutingSpec : Spek({
private val logger = KotlinLogging.logger {}
val logger = KotlinLogging.logger {}
val webClient: WebClient = autoClose(ACWebClient())
Expand Down Expand Up @@ -65,7 +52,7 @@ class RoutingSpec : FreeSpec() {
}
}
}
}
})
val Duration.millis get() = this.timeUnit.toMillis(amount)
Expand All @@ -85,3 +72,4 @@ fun <T> pollFor(maximumTime: io.kotlintest.Duration, pollEvery : Duration = 300.
}
throw AssertionError("Test failed after ${maximumTime.amount} ${maximumTime.timeUnit}; attempted $times times", lastException!!)
}
*/
118 changes: 68 additions & 50 deletions src/test/kotlin/io/kweb/state/BindableSpec.kt
Original file line number Diff line number Diff line change
@@ -1,68 +1,86 @@
package io.kweb.state

import io.kotlintest.matchers.shouldBe
import io.kotlintest.specs.FreeSpec
import org.amshove.kluent.shouldEqual
import org.jetbrains.spek.api.Spek
import org.jetbrains.spek.api.dsl.*

/**
* Created by ian on 6/18/17.
*/
class BindableSpec : FreeSpec() {
init {
"A Bindable should initialize correctly" {
val sw = ReadOnlyBindable("Test")
sw.value shouldBe "Test"
object BindableSpec : Spek({
describe("ReadOnlyBindable") {
val readOnlyBindable = ReadOnlyBindable("Test")
on("retrieving its value") {
val value = readOnlyBindable.value
it("should match the value it was initialized with") {
readOnlyBindable.value shouldEqual "Test"
}
}
}

"A Bindable should notify a listener of a change" {
val sw = Bindable("Foo")
var old : String? = null
var new : String? = null
sw.addListener { o, n ->
old shouldBe null
new shouldBe null
describe("A simple string bindable") {
val bindable = Bindable("Foo")
context("adding a listener that modifies two vars") {
var old: String? = null
var new: String? = null
val handle = bindable.addListener { o, n ->
old shouldEqual null
new shouldEqual null
old = o
new = n
}
sw.value = "Bar"
old shouldBe "Foo"
new shouldBe "Bar"
}
"A removed listener shouldn't be called" {
val sw = Bindable("Foo")
var old : String? = null
var new : String? = null
val listenerHandler = sw.addListener { o, n ->
old shouldBe null
new shouldBe null
old = o
new = n
on("modifying the value") {
bindable.value = "Bar"
it("should call the listener, modifying the vars accordingly") {
old shouldEqual "Foo"
new shouldEqual "Bar"
}
}
on("removing the listener and modifying the value again") {
bindable.removeListener(handle)
bindable.value = "FooBar"
it("shouldn't call the listener again") {
old shouldEqual "Foo"
new shouldEqual "Bar"
}

}
sw.removeListener(listenerHandler)
sw.value = "Bar"
old shouldBe null
new shouldBe null
}
context("creating a one-way mapping") {
val mappedBindable = bindable.map { it.length }
on("modifying the original bindable") {
bindable.value = "elephant"
it("should be mapped correctly") {
mappedBindable.value shouldEqual 8
}

"A read-only mapped watcher should work" {
val sw = Bindable("Foo")
val mapped = sw.map {it -> it.length}
mapped.value shouldBe 3
sw.value = "Hello"
mapped.value shouldBe 5
}
}
/*
"A bi-directional mapped watcher should work" {
data class Foo(var bar : Int)
val sw = Bindable(Foo(12))
val mapped = sw.map(
object : ReversableFunction<>

{it.bar.toString()}, {n, o -> n.copy(bar = o.toInt())}
}
describe("a string bindable") {
val lowerCaseBindable = Bindable("foo")
context("creating a two-way mapping") {
val upperCaseBindable = lowerCaseBindable.map(object : ReversableFunction<String, String> {
override fun map(from: String) = from.toUpperCase()

override fun unmap(original: String, change: String) = change.toLowerCase()

)
sw.value shouldBe Foo(12)
mapped.value = "143"
sw.value shouldBe Foo(143)
} */
})
on("modifying the original bindable") {
lowerCaseBindable.value = "one"
it("should be mapped correctly") {
val value = upperCaseBindable.value
value shouldEqual "ONE"
}
}
on("modifying the mappedBindable") {
upperCaseBindable.value = "TWO"
it("should be unmapped correctly") {
val value = lowerCaseBindable.value
value shouldEqual "two"
}
}
}
}
}
})
Loading

0 comments on commit 83387ea

Please sign in to comment.