Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kotlin samples #401

Merged
merged 5 commits into from Aug 13, 2019

Conversation

@tsiq-karold
Copy link
Collaborator

commented Aug 7, 2019

Kotlin equivalent of CustomerCrudSeparatedJavaTest. This shows the basics of using webtau from Kotlin, I will add some of this to docs in a later PR. It also shows at least one thing which is slightly less than ideal from Kotlin and that's the SAM conversion required when returning from a validation block. The assertions could also do with some Kotlinisation. I will at some point provide some Kotlin helpers/wrappers to help with some of this.

@tsiq-karold tsiq-karold requested a review from MykolaGolubyev Aug 7, 2019

pom.xml Outdated
@@ -116,6 +116,7 @@
<module>webtau-junit5</module>
<module>webtau-junit5-groovy</module>
<module>webtau-junit5-examples</module>
<module>webtau-junit5-examples-kotlin</module>

This comment has been minimized.

Copy link
@MykolaGolubyev

MykolaGolubyev Aug 7, 2019

Collaborator

junit5-examples has both groovy and java ones. Is there an issue to put Kotlin there as well?

This comment has been minimized.

Copy link
@tsiq-karold

tsiq-karold Aug 7, 2019

Author Collaborator

I had a hard time getting Maven to build all three but I've found an SO article that suggests it's possible so happy to give it another go.

This comment has been minimized.

Copy link
@MykolaGolubyev

MykolaGolubyev Aug 7, 2019

Collaborator

That would help. If not possible, probably should make a parent pom to avoid repetition

This comment has been minimized.

Copy link
@tsiq-karold

tsiq-karold Aug 7, 2019

Author Collaborator

Yeah, makes sense.

This comment has been minimized.

Copy link
@tsiq-karold

tsiq-karold Aug 13, 2019

Author Collaborator

I figured it out.

}
}

companion object {

This comment has been minimized.

Copy link
@MykolaGolubyev

MykolaGolubyev Aug 7, 2019

Collaborator

oh interesting, I need to learn me more Kotlin

This comment has been minimized.

Copy link
@tsiq-karold

tsiq-karold Aug 7, 2019

Author Collaborator

This is sort of creating a singleton object of the same name as its containing class. It's the only way to get to something similar to statics in java.

"lastName" to "NLN"
)
private val id by lazy {
val id: Int = http.post("/customers", customerPayload, HttpResponseValidatorWithReturn { _, body ->

This comment has been minimized.

Copy link
@MykolaGolubyev

MykolaGolubyev Aug 7, 2019

Collaborator

yeah, this looks a bit weird.

This comment has been minimized.

Copy link
@tsiq-karold

tsiq-karold Aug 7, 2019

Author Collaborator

It's not uncommon in Kotlin code which uses java libs sadly but we can provide Kotlin specific versions of the http methods which won't need this.

This comment has been minimized.

Copy link
@MykolaGolubyev

MykolaGolubyev Aug 7, 2019

Collaborator

will Kotlin specific versions need to provide all the overrides? or is there some smart extension mechanism?

This comment has been minimized.

Copy link
@tsiq-karold

tsiq-karold Aug 7, 2019

Author Collaborator

It has an extension mechanism. This is something I've been playing with for should:

infix fun Any.shouldNot(valueMatcher: ValueMatcher) = actual(this).shouldNot(valueMatcher))

Which would allow me to do:

val id: Int = http.post("/customers", customerPayload, HttpResponseValidatorWithReturn { _, body ->
                body.get("id")
            })

id shouldNot equal(0)

I'm pretty sure I can make the http methods work nicely and feel Kotlin native without tonnes of work but that'll be for a separate PR.

This comment has been minimized.

Copy link
@MykolaGolubyev

MykolaGolubyev Aug 7, 2019

Collaborator

oh neat. separate PR sounds good.

@Test
@Order(1)
fun `read customer record`() {
http.get("/customers/$id") { _, body ->

This comment has been minimized.

Copy link
@MykolaGolubyev

MykolaGolubyev Aug 7, 2019

Collaborator

this looks pretty good!

This comment has been minimized.

Copy link
@tsiq-karold

tsiq-karold Aug 7, 2019

Author Collaborator

Yeah, better than I initially feared 😄

@MykolaGolubyev
Copy link
Collaborator

left a comment

Nice!

@tsiq-karold tsiq-karold merged commit c6bbd8c into master Aug 13, 2019

4 checks passed

Travis CI - Branch Build Passed
Details
Travis CI - Pull Request Build Passed
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
continuous-integration/travis-ci/push The Travis CI build passed
Details

@tsiq-karold tsiq-karold deleted the kotlin-samples branch Aug 13, 2019

<execution>
<id>java-compile</id>
<phase>compile</phase>
<goals> <goal>compile</goal> </goals>

This comment has been minimized.

Copy link
@tsiq-clemens

tsiq-clemens Aug 13, 2019

Collaborator

weird formatting...

<execution>
<id>java-test-compile</id>
<phase>test-compile</phase>
<goals> <goal>testCompile</goal> </goals>

This comment has been minimized.

Copy link
@tsiq-clemens

tsiq-clemens Aug 13, 2019

Collaborator

weird formatting...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.