Skip to content

Commit d20ebb8

Browse files
committed
tests/qg-xxx: тесты переведены на новый RestTestClient
Так как он проще в отладке и чуть быстрее
1 parent c6c34af commit d20ebb8

13 files changed

Lines changed: 83 additions & 84 deletions

File tree

app/src/test/kotlin/pro/qyoga/tests/cases/app/publc/surveys/SubmitSurveyTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import pro.qyoga.tests.fixture.object_mothers.survey_forms.SurveyFormsSettingsOb
1919
import pro.qyoga.tests.fixture.object_mothers.therapists.THE_ADMIN_LOGIN
2020
import pro.qyoga.tests.fixture.object_mothers.therapists.THE_THERAPIST_REF
2121
import pro.qyoga.tests.infra.web.QYogaAppIntegrationBaseKoTest
22-
import pro.qyoga.tests.infra.web.mainWebTestClient
22+
import pro.qyoga.tests.infra.web.mainRestTestClient
2323
import tools.jackson.databind.JsonNode
2424
import tools.jackson.databind.node.ObjectNode
2525
import tools.jackson.module.kotlin.jacksonObjectMapper
@@ -28,7 +28,7 @@ import tools.jackson.module.kotlin.jacksonObjectMapper
2828
@DisplayName("Операция создания анкеты")
2929
class SubmitSurveyTest : QYogaAppIntegrationBaseKoTest({
3030

31-
val yandexFormsClient by lazy { YandexFormsClient(mainWebTestClient) }
31+
val yandexFormsClient by lazy { YandexFormsClient(mainRestTestClient) }
3232

3333
"при отправке новым клиентом корректного запроса со всеми значениями карточки должна" - {
3434
// Сетап

app/src/test/kotlin/pro/qyoga/tests/cases/app/therapist/calendars/google/GoogleAuthorizationIntegrationTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import pro.qyoga.tests.fixture.wiremocks.MockGoogleOAuthServer
2020
import pro.qyoga.tests.infra.test_config.spring.context
2121
import pro.qyoga.tests.infra.web.QYogaAppIntegrationBaseKoTest
2222
import pro.qyoga.tests.infra.wiremock.WireMock
23-
import pro.qyoga.tests.platform.spring.web_test_client.redirectLocation
23+
import pro.qyoga.tests.platform.spring.rest_test_client.redirectLocation
2424

2525

2626
@DisplayName("Интеграция с Google OAuth")

app/src/test/kotlin/pro/qyoga/tests/clients/TherapistClient.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,21 @@ import io.restassured.module.kotlin.extensions.When
88
import org.jsoup.Jsoup
99
import org.jsoup.nodes.Document
1010
import org.springframework.http.HttpStatus
11-
import org.springframework.test.web.reactive.server.WebTestClient
11+
import org.springframework.test.web.servlet.client.RestTestClient
1212
import pro.qyoga.tests.clients.api.*
1313
import pro.qyoga.tests.fixture.object_mothers.therapists.THE_THERAPIST_LOGIN
1414
import pro.qyoga.tests.fixture.object_mothers.therapists.THE_THERAPIST_PASSWORD
15-
import pro.qyoga.tests.infra.web.mainWebTestClient
15+
import pro.qyoga.tests.infra.web.mainRestTestClient
1616

1717

1818
class TherapistClient(
1919
val authCookie: Cookie,
20-
webTestClient: WebTestClient = mainWebTestClient
20+
restTestClient: RestTestClient = mainRestTestClient
2121
) {
2222

2323
// Work
2424
val appointments = TherapistAppointmentsApi(authCookie)
25-
val googleCalendarIntegration = TherapistGoogleCalendarIntegrationApi(authCookie, webTestClient)
25+
val googleCalendarIntegration = TherapistGoogleCalendarIntegrationApi(authCookie, restTestClient)
2626
val clients = TherapistClientsApi(authCookie)
2727
val clientJournal = TherapistClientJournalApi(authCookie)
2828
val clientFiles = TherapistClientFilesApi(authCookie)

app/src/test/kotlin/pro/qyoga/tests/clients/YandexFormsClient.kt

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ package pro.qyoga.tests.clients
33
import org.springframework.http.HttpStatus
44
import org.springframework.http.HttpStatusCode
55
import org.springframework.http.ResponseEntity
6-
import org.springframework.test.web.reactive.server.WebTestClient
7-
import org.springframework.test.web.reactive.server.returnResult
6+
import org.springframework.test.web.servlet.client.RestTestClient
7+
import org.springframework.test.web.servlet.client.returnResult
88
import pro.azhidkov.platform.spring.http.ErrorResponse
99
import pro.qyoga.app.publc.surverys.SurveysController
1010

1111

1212
class YandexFormsClient(
13-
private val client: WebTestClient
13+
private val client: RestTestClient
1414
) {
1515

1616
fun createSurvey(surveyJsonStr: String): HttpStatusCode {
@@ -26,16 +26,15 @@ class YandexFormsClient(
2626
return createSurveyForResponse(entranceSurveyJsonStr)
2727
.expectStatus().isEqualTo(expectedStatus)
2828
.returnResult(ErrorResponse::class.java)
29-
.responseBody
30-
.blockFirst()!!
29+
.responseBody!!
3130
}
3231

33-
fun createSurveyForResponse(entranceSurveyJsonStr: String): WebTestClient.ResponseSpec {
32+
fun createSurveyForResponse(entranceSurveyJsonStr: String): RestTestClient.ResponseSpec {
3433
return client
3534
.post()
3635
.uri(SurveysController.PATH)
37-
.bodyValue(entranceSurveyJsonStr)
36+
.body(entranceSurveyJsonStr)
3837
.exchange()
3938
}
4039

41-
}
40+
}

app/src/test/kotlin/pro/qyoga/tests/clients/api/AuthorizedApi.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package pro.qyoga.tests.clients.api
22

33
import io.restassured.http.Cookie
44
import io.restassured.specification.RequestSpecification
5-
import org.springframework.test.web.reactive.server.WebTestClient
5+
import org.springframework.test.web.servlet.client.RestTestClient
66

77

88
interface AuthorizedApi {
@@ -13,8 +13,8 @@ interface AuthorizedApi {
1313
return cookie(authCookie)
1414
}
1515

16-
fun WebTestClient.RequestHeadersSpec<*>.authorized(): WebTestClient.RequestHeadersSpec<*> {
16+
fun RestTestClient.RequestHeadersSpec<*>.authorized(): RestTestClient.RequestHeadersSpec<*> {
1717
return cookie(authCookie.name, authCookie.value)
1818
}
1919

20-
}
20+
}

app/src/test/kotlin/pro/qyoga/tests/clients/api/NotificationsApi.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@ package pro.qyoga.tests.clients.api
33
import io.restassured.http.Cookie
44
import org.jsoup.Jsoup
55
import org.jsoup.nodes.Document
6-
import org.springframework.test.web.reactive.server.WebTestClient
6+
import org.springframework.test.web.servlet.client.RestTestClient
77
import pro.qyoga.app.therapist.appointments.core.schedule.settings.NotificationsSettingsController
8-
import pro.qyoga.tests.infra.web.mainWebTestClient
9-
import pro.qyoga.tests.platform.spring.web_test_client.getBodyAsString
8+
import pro.qyoga.tests.infra.web.mainRestTestClient
9+
import pro.qyoga.tests.platform.spring.rest_test_client.getBodyAsString
1010

1111
object NotificationsApiFactory {
1212

1313
fun therapistApi(
1414
principal: Cookie,
15-
) = NotificationsTherapistApi(principal, mainWebTestClient)
15+
) = NotificationsTherapistApi(principal, mainRestTestClient)
1616

1717
}
1818

@@ -22,11 +22,11 @@ val TrainerAdvisorApis.Notifications
2222

2323
class NotificationsTherapistApi(
2424
override val authCookie: Cookie,
25-
private val webTestClient: WebTestClient
25+
private val restTestClient: RestTestClient
2626
) : AuthorizedApi {
2727

2828
fun getNotificationsSettings(): Document {
29-
return webTestClient.get()
29+
return restTestClient.get()
3030
.uri(NotificationsSettingsController.PATH)
3131
.authorized()
3232
.exchange()

app/src/test/kotlin/pro/qyoga/tests/clients/api/TherapistGoogleCalendarIntegrationApi.kt

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,20 @@ import io.restassured.http.Cookie
44
import org.jsoup.Jsoup
55
import org.jsoup.nodes.Document
66
import org.springframework.security.oauth2.core.endpoint.OAuth2AuthorizationResponse
7-
import org.springframework.test.web.reactive.server.WebTestClient
8-
import org.springframework.web.reactive.function.BodyInserters.fromValue
7+
import org.springframework.test.web.servlet.client.RestTestClient
98
import pro.qyoga.app.therapist.appointments.core.schedule.settings.GoogleCalendarSettingsController
109
import pro.qyoga.i9ns.calendars.google.model.GoogleAccountRef
11-
import pro.qyoga.tests.platform.spring.web_test_client.getBodyAsString
12-
import pro.qyoga.tests.platform.spring.web_test_client.redirectLocation
10+
import pro.qyoga.tests.platform.spring.rest_test_client.getBodyAsString
11+
import pro.qyoga.tests.platform.spring.rest_test_client.redirectLocation
1312
import java.net.URI
1413

1514
class TherapistGoogleCalendarIntegrationApi(
1615
override val authCookie: Cookie,
17-
private val webTestClient: WebTestClient
16+
private val restTestClient: RestTestClient
1817
) : AuthorizedApi {
1918

2019
fun authorizeInGoogle(): URI {
21-
val response = webTestClient.get()
20+
val response = restTestClient.get()
2221
.uri("/oauth2/authorization/google")
2322
.authorized()
2423
.exchange()
@@ -33,8 +32,8 @@ class TherapistGoogleCalendarIntegrationApi(
3332
// scope=https://www.googleapis.com/auth/calendar.readonly' \
3433
fun handleOAuthCallbackForResponse(
3534
authResponse: OAuth2AuthorizationResponse
36-
): WebTestClient.ResponseSpec {
37-
return webTestClient.get()
35+
): RestTestClient.ResponseSpec {
36+
return restTestClient.get()
3837
.uri {
3938
it.path("/therapist/oauth2/google/callback")
4039
.queryParam("state", authResponse.state)
@@ -45,15 +44,15 @@ class TherapistGoogleCalendarIntegrationApi(
4544
.exchange()
4645
}
4746

48-
fun finalizeOAuthCallbackForResponse(): WebTestClient.ResponseSpec {
49-
return webTestClient.get()
47+
fun finalizeOAuthCallbackForResponse(): RestTestClient.ResponseSpec {
48+
return restTestClient.get()
5049
.uri("/therapist/oauth2/google/callback")
5150
.authorized()
5251
.exchange()
5352
}
5453

5554
fun getGoogleCalendarComponent(): Document {
56-
return webTestClient.get()
55+
return restTestClient.get()
5756
.uri(GoogleCalendarSettingsController.PATH)
5857
.authorized()
5958
.exchange()
@@ -67,9 +66,9 @@ class TherapistGoogleCalendarIntegrationApi(
6766
"shouldBeShown" to shouldBeShown
6867
)
6968

70-
webTestClient.patch()
69+
restTestClient.patch()
7170
.uri(GoogleCalendarSettingsController.updateCalendarSettingsPath(googleAccount, calendarId))
72-
.body(fromValue(body))
71+
.body(body)
7372
.authorized()
7473
.exchange()
7574
.expectStatus().isNoContent
Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
package pro.qyoga.tests.clients.api
22

33
import io.restassured.http.Cookie
4-
import org.springframework.test.web.reactive.server.WebTestClient
5-
import org.springframework.test.web.reactive.server.returnResult
4+
import org.springframework.test.web.servlet.client.RestTestClient
5+
import org.springframework.test.web.servlet.client.returnResult
66
import pro.qyoga.app.publc.pushes.web.PushesPublicKeyController
7-
import pro.qyoga.tests.infra.web.mainWebTestClient
7+
import pro.qyoga.tests.infra.web.mainRestTestClient
88

99

1010
object WebPushesApiFactory {
1111

12-
val publicApi = WebPushesPublicApi(mainWebTestClient)
12+
val publicApi = WebPushesPublicApi(mainRestTestClient)
1313

1414
fun therapistApi(
1515
principal: Cookie,
16-
) = WebPushesTherapistApi(principal, mainWebTestClient)
16+
) = WebPushesTherapistApi(principal, mainRestTestClient)
1717

1818
}
1919

@@ -22,7 +22,7 @@ val TrainerAdvisorApis.WebPushes
2222
get() = WebPushesApiFactory
2323

2424
class WebPushesPublicApi(
25-
private val client: WebTestClient
25+
private val client: RestTestClient
2626
) {
2727

2828
fun getPublicKey(): String {
@@ -31,8 +31,7 @@ class WebPushesPublicApi(
3131
.exchange()
3232
.expectStatus().isOk
3333
.returnResult<String>()
34-
.responseBody
35-
.blockFirst() ?: ""
34+
.responseBody ?: ""
3635
}
3736

3837
}

app/src/test/kotlin/pro/qyoga/tests/clients/api/WebPushesTherapistApi.kt

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,26 @@
11
package pro.qyoga.tests.clients.api
22

33
import io.restassured.http.Cookie
4-
import org.springframework.test.web.reactive.server.WebTestClient
5-
import org.springframework.web.reactive.function.BodyInserters.fromValue
4+
import org.springframework.test.web.servlet.client.RestTestClient
65
import pro.qyoga.app.pushes.web.WebPushesController
76
import pro.qyoga.i9ns.pushes.web.model.WebPushSubscription
87

98
class WebPushesTherapistApi(
109
override val authCookie: Cookie,
11-
private val webTestClient: WebTestClient
10+
private val restTestClient: RestTestClient
1211
) : AuthorizedApi {
1312

1413
fun createSubscription(subscription: WebPushSubscription) {
15-
webTestClient.post()
14+
restTestClient.post()
1615
.uri(WebPushesController.PATH)
17-
.body(fromValue(subscription))
16+
.body(subscription)
1817
.authorized()
1918
.exchange()
2019
.expectStatus().isNoContent
2120
}
2221

2322
fun deleteSubscription(p256dh: String) {
24-
webTestClient.delete()
23+
restTestClient.delete()
2524
.uri(WebPushesController.DELETE_SUBSCRIPTION_PATH, p256dh)
2625
.authorized()
2726
.exchange()
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package pro.qyoga.tests.infra.web
2+
3+
import org.apache.hc.client5.http.impl.classic.HttpClients
4+
import org.springframework.context.ConfigurableApplicationContext
5+
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory
6+
import org.springframework.test.web.servlet.client.RestTestClient
7+
import pro.qyoga.tests.infra.test_config.spring.baseUrl
8+
9+
10+
val mainRestTestClient: RestTestClient by lazy { createRestTestClient() }
11+
12+
fun createRestTestClient(context: ConfigurableApplicationContext = pro.qyoga.tests.infra.test_config.spring.context): RestTestClient =
13+
RestTestClient.bindToServer(
14+
HttpComponentsClientHttpRequestFactory(
15+
HttpClients.custom()
16+
.disableRedirectHandling()
17+
.build()
18+
)
19+
)
20+
.baseUrl(context.baseUrl)
21+
.defaultHeader("Content-Type", "application/json;charset=UTF-8")
22+
.build()

0 commit comments

Comments
 (0)