#71 Use response object for route FindArticles

This commit is contained in:
2021-03-05 00:39:49 +01:00
parent 9fc21f5459
commit bb637dd96a
19 changed files with 175 additions and 58 deletions

View File

@@ -1,18 +1,21 @@
package integration
import integration.steps.`And have property`
import integration.steps.`And the response should not be null`
import integration.steps.`Then the response should be`
import integration.steps.then.`And have property`
import integration.steps.then.`And the response should contain pattern`
import integration.steps.then.`And the response should not be null`
import integration.steps.then.`Then the response should be`
import integration.steps.`when`.`When I send a GET request`
import integration.steps.`when`.`When I send a POST request`
import integration.steps.`whish contains`
import integration.steps.and
import integration.steps.then.`whish contains`
import integration.steps.then.and
import integration.steps.given.`Given I have article created by workgroup`
import integration.steps.given.`Given I have article`
import integration.steps.given.`Given I have articles`
import integration.steps.given.`Given I have citizen`
import integration.steps.given.`Given I have workgroup`
import integration.steps.given.`authenticated as`
import integration.steps.then.`And the response should contain list`
import integration.steps.then.`And the response should not contain`
import io.ktor.http.HttpStatusCode.Companion.OK
import org.junit.jupiter.api.Tag
import org.junit.jupiter.api.Tags
@@ -28,6 +31,11 @@ class `Article routes` : BaseTest() {
`Given I have articles`(3)
`When I send a GET request`("/articles") `Then the response should be` OK and {
`And the response should not be null`()
`And the response should contain pattern`("$.result[0].created_by.name.first_name", "firstName.+")
`And the response should contain pattern`("$.result[1].created_by.name.first_name", "firstName.+")
`And the response should contain pattern`("$.result[2].created_by.name.first_name", "firstName.+")
`And the response should not contain`("$.result[3]")
`And the response should contain list`("$.result", 3, 3)
}
}
}

View File

@@ -1,12 +1,12 @@
package integration
import integration.steps.`And have property`
import integration.steps.`And the response should not be null`
import integration.steps.`Then the response should be`
import integration.steps.then.`And have property`
import integration.steps.then.`And the response should not be null`
import integration.steps.then.`Then the response should be`
import integration.steps.`when`.`When I send a GET request`
import integration.steps.`when`.`When I send a PUT request`
import integration.steps.`whish contains`
import integration.steps.and
import integration.steps.then.`whish contains`
import integration.steps.then.and
import integration.steps.given.`Given I have citizen`
import integration.steps.given.`authenticated as`
import io.ktor.http.HttpStatusCode.Companion.BadRequest

View File

@@ -1,13 +1,13 @@
package integration
import fr.dcproject.component.citizen.database.CitizenI.Name
import integration.steps.`And the response should contain`
import integration.steps.`And the response should not be null`
import integration.steps.`Then the response should be`
import integration.steps.then.`And the response should contain`
import integration.steps.then.`And the response should not be null`
import integration.steps.then.`Then the response should be`
import integration.steps.`when`.`When I send a GET request`
import integration.steps.`when`.`When I send a POST request`
import integration.steps.`when`.`When I send a PUT request`
import integration.steps.and
import integration.steps.then.and
import integration.steps.given.`Given I have article`
import integration.steps.given.`Given I have citizen`
import integration.steps.given.`Given I have comment on article`

View File

@@ -1,13 +1,13 @@
package integration
import fr.dcproject.component.citizen.database.CitizenI.Name
import integration.steps.`And the response should contain list`
import integration.steps.`And the response should contain`
import integration.steps.`And the response should not be null`
import integration.steps.`Then the response should be`
import integration.steps.then.`And the response should contain list`
import integration.steps.then.`And the response should contain`
import integration.steps.then.`And the response should not be null`
import integration.steps.then.`Then the response should be`
import integration.steps.`when`.`When I send a GET request`
import integration.steps.`when`.`When I send a POST request`
import integration.steps.and
import integration.steps.then.and
import integration.steps.given.`Given I have citizen`
import integration.steps.given.`Given I have comment on constitution`
import integration.steps.given.`Given I have constitution`

View File

@@ -1,9 +1,9 @@
package integration
import integration.steps.`And the response should not be null`
import integration.steps.`Then the response should be`
import integration.steps.then.`And the response should not be null`
import integration.steps.then.`Then the response should be`
import integration.steps.`when`.`When I send a GET request`
import integration.steps.and
import integration.steps.then.and
import integration.steps.given.`Given I have article`
import integration.steps.given.`Given I have citizen`
import integration.steps.given.`Given I have comment on article`

View File

@@ -1,12 +1,12 @@
package integration
import integration.steps.`And have property`
import integration.steps.`And the response should not be null`
import integration.steps.`Then the response should be`
import integration.steps.then.`And have property`
import integration.steps.then.`And the response should not be null`
import integration.steps.then.`Then the response should be`
import integration.steps.`when`.`When I send a GET request`
import integration.steps.`when`.`When I send a POST request`
import integration.steps.`whish contains`
import integration.steps.and
import integration.steps.then.`whish contains`
import integration.steps.then.and
import integration.steps.given.`Given I have citizen`
import integration.steps.given.`Given I have constitution`
import integration.steps.given.`Given I have constitutions`

View File

@@ -1,13 +1,13 @@
package integration
import integration.steps.`And the response should be null`
import integration.steps.`And the response should contain`
import integration.steps.`And the response should not be null`
import integration.steps.`Then the response should be`
import integration.steps.then.`And the response should be null`
import integration.steps.then.`And the response should contain`
import integration.steps.then.`And the response should not be null`
import integration.steps.then.`Then the response should be`
import integration.steps.`when`.`When I send a DELETE request`
import integration.steps.`when`.`When I send a GET request`
import integration.steps.`when`.`When I send a POST request`
import integration.steps.and
import integration.steps.then.and
import integration.steps.given.`And follow article`
import integration.steps.given.`Given I have article`
import integration.steps.given.`Given I have citizen`

View File

@@ -1,13 +1,13 @@
package integration
import integration.steps.`And the response should be null`
import integration.steps.`And the response should contain`
import integration.steps.`And the response should not be null`
import integration.steps.`Then the response should be`
import integration.steps.then.`And the response should be null`
import integration.steps.then.`And the response should contain`
import integration.steps.then.`And the response should not be null`
import integration.steps.then.`Then the response should be`
import integration.steps.`when`.`When I send a DELETE request`
import integration.steps.`when`.`When I send a GET request`
import integration.steps.`when`.`When I send a POST request`
import integration.steps.and
import integration.steps.then.and
import integration.steps.given.`And follow constitution`
import integration.steps.given.`Given I have citizen`
import integration.steps.given.`Given I have constitution`

View File

@@ -1,8 +1,8 @@
package integration
import integration.steps.`And the response should not be null`
import integration.steps.`Then the response should be`
import integration.steps.`and should contains`
import integration.steps.then.`And the response should not be null`
import integration.steps.then.`Then the response should be`
import integration.steps.then.`and should contains`
import integration.steps.`when`.`When I send a POST request`
import integration.steps.given.`Given I have citizen`
import integration.steps.given.`authenticated as`

View File

@@ -1,12 +1,12 @@
package integration
import fr.dcproject.component.citizen.database.CitizenI.Name
import integration.steps.`And the response should contain list`
import integration.steps.`And the response should contain`
import integration.steps.`Then the response should be`
import integration.steps.then.`And the response should contain list`
import integration.steps.then.`And the response should contain`
import integration.steps.then.`Then the response should be`
import integration.steps.`when`.`When I send a GET request`
import integration.steps.`when`.`When I send a PUT request`
import integration.steps.and
import integration.steps.then.and
import integration.steps.given.`Given I have an opinion choice`
import integration.steps.given.`Given I have article`
import integration.steps.given.`Given I have citizen`

View File

@@ -1,6 +1,6 @@
package integration
import integration.steps.`Then the response should be`
import integration.steps.then.`Then the response should be`
import integration.steps.`when`.`When I send a POST request`
import io.ktor.http.HttpStatusCode
import org.amshove.kluent.`should be null`

View File

@@ -1,11 +1,11 @@
package integration
import fr.dcproject.component.citizen.database.CitizenI.Name
import integration.steps.`And the response should contain`
import integration.steps.`Then the response should be`
import integration.steps.then.`And the response should contain`
import integration.steps.then.`Then the response should be`
import integration.steps.`when`.`When I send a GET request`
import integration.steps.`when`.`When I send a PUT request`
import integration.steps.and
import integration.steps.then.and
import integration.steps.given.`Given I have article`
import integration.steps.given.`Given I have citizen`
import integration.steps.given.`Given I have comment on article`

View File

@@ -1,15 +1,15 @@
package integration
import fr.dcproject.component.citizen.database.CitizenI.Name
import integration.steps.`And the response should be null`
import integration.steps.`And the response should contain list`
import integration.steps.`And the response should contain`
import integration.steps.`Then the response should be`
import integration.steps.then.`And the response should be null`
import integration.steps.then.`And the response should contain list`
import integration.steps.then.`And the response should contain`
import integration.steps.then.`Then the response should be`
import integration.steps.`when`.`When I send a DELETE request`
import integration.steps.`when`.`When I send a GET request`
import integration.steps.`when`.`When I send a POST request`
import integration.steps.`when`.`When I send a PUT request`
import integration.steps.and
import integration.steps.then.and
import integration.steps.given.`Given I have citizen`
import integration.steps.given.`Given I have workgroup`
import integration.steps.given.`With members`

View File

@@ -1,8 +1,9 @@
package integration.steps
package integration.steps.then
import assert.assertGreaterThan
import assert.assertLessThan
import com.jayway.jsonpath.JsonPath
import com.jayway.jsonpath.PathNotFoundException
import io.ktor.http.HttpStatusCode
import io.ktor.server.testing.TestApplicationCall
import io.ktor.server.testing.TestApplicationResponse
@@ -12,8 +13,10 @@ import org.amshove.kluent.`should be null`
import org.amshove.kluent.`should be`
import org.amshove.kluent.`should not be null`
import org.amshove.kluent.shouldContain
import org.junit.jupiter.api.assertThrows
import kotlin.test.assertEquals
import kotlin.test.assertNotNull
import kotlin.test.assertTrue
fun TestApplicationCall.`Then the response should be`(status: HttpStatusCode? = null, block: TestApplicationResponse.() -> Unit): TestApplicationCall = this.apply {
if (status != null) {
@@ -62,6 +65,26 @@ inline fun <reified T> TestApplicationResponse.`And the response should contain`
}
}
fun TestApplicationResponse.`And the response should not contain`(path: String) {
assertThrows<PathNotFoundException> {
JsonPath.read(content, path)
}
}
fun TestApplicationResponse.`And the response should contain pattern`(path: String, expectedRegex: String): Any {
return JsonPath.read<Any?>(content, path).also {
it.let {
if (it is JSONArray && it.count() == 1) {
it.first()
} else {
it
}
}?.let {
assertTrue(expectedRegex.toRegex().containsMatchIn(it.toString()))
} ?: throw AssertionError("\"$path -> element not found on json response")
}
}
fun TestApplicationResponse.`And the response should contain list`(path: String, min: Int? = null, max: Int? = null) {
JsonPath.read<JSONArray?>(content, path).also {
assertNotNull(it)