Skip to content

Commit

Permalink
test: use HttpClient::toBlocking (#207)
Browse files Browse the repository at this point in the history
  • Loading branch information
sdelamo authored Mar 17, 2022
1 parent 9efb413 commit 6cd7907
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 52 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package io.micronaut.acme


import io.micronaut.http.HttpRequest
import io.micronaut.http.HttpResponse
import io.micronaut.http.annotation.Controller
import io.micronaut.http.annotation.Get
import io.netty.handler.ssl.util.InsecureTrustManagerFactory
import io.reactivex.Flowable
import spock.lang.Stepwise
import spock.util.concurrent.PollingConditions

Expand Down Expand Up @@ -73,13 +71,10 @@ class AcmeCertRefresherMultiDomainsTaskSpec extends AcmeBaseSpec {

void "test send https request when the cert is in place"() {
when:
Flowable<HttpResponse<String>> flowable = Flowable.fromPublisher(client.exchange(
HttpRequest.GET("/ssl-multidomains"), String
))
HttpResponse<String> response = flowable.blockingFirst()
HttpResponse<String> response = client.toBlocking().exchange(HttpRequest.GET("/ssl-multidomains"), String)

then:
response.body() == "Hello There"
response.body() == "Hello There"
}

@Controller('/')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package io.micronaut.acme


import io.micronaut.http.HttpRequest
import io.micronaut.http.HttpResponse
import io.micronaut.http.annotation.Controller
import io.micronaut.http.annotation.Get
import io.netty.handler.ssl.util.InsecureTrustManagerFactory
import io.reactivex.Flowable
import spock.lang.Stepwise
import spock.util.concurrent.PollingConditions

Expand Down Expand Up @@ -71,13 +69,10 @@ class AcmeCertRefresherTaskSpec extends AcmeBaseSpec {

void "test send https request when the cert is in place"() {
when:
Flowable<HttpResponse<String>> flowable = Flowable.fromPublisher(client.exchange(
HttpRequest.GET("/ssl"), String
))
HttpResponse<String> response = flowable.blockingFirst()
HttpResponse<String> response = client.toBlocking().exchange(HttpRequest.GET("/ssl"), String)

then:
response.body() == "Hello SSL"
response.body() == "Hello SSL"
}

@Controller('/')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package io.micronaut.acme


import io.micronaut.http.HttpRequest
import io.micronaut.http.HttpResponse
import io.micronaut.http.annotation.Controller
import io.micronaut.http.annotation.Get
import io.netty.handler.ssl.util.InsecureTrustManagerFactory
import io.reactivex.Flowable
import org.shredzone.acme4j.util.KeyPairUtils
import spock.lang.Stepwise
import spock.util.concurrent.PollingConditions
Expand Down Expand Up @@ -86,13 +84,10 @@ class AcmeCertRefresherTaskWithClasspathKeysSpec extends AcmeBaseSpec {

void "test send https request when the cert is in place"() {
when:
Flowable<HttpResponse<String>> flowable = Flowable.fromPublisher(client.exchange(
HttpRequest.GET("/ssl-using-classpath-keys"), String
))
HttpResponse<String> response = flowable.blockingFirst()
HttpResponse<String> response = client.toBlocking().exchange(HttpRequest.GET("/ssl-using-classpath-keys"), String)

then:
response.body() == "Hello Classpath"
response.body() == "Hello Classpath"
}

@Controller('/')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package io.micronaut.acme


import io.micronaut.http.HttpRequest
import io.micronaut.http.HttpResponse
import io.micronaut.http.annotation.Controller
import io.micronaut.http.annotation.Get
import io.netty.handler.ssl.util.InsecureTrustManagerFactory
import io.reactivex.Flowable
import spock.lang.Stepwise
import spock.util.concurrent.PollingConditions

Expand Down Expand Up @@ -80,13 +78,10 @@ class AcmeCertRefresherTaskWithFileKeysSpec extends AcmeBaseSpec {

void "test send https request when the cert is in place"() {
when:
Flowable<HttpResponse<String>> flowable = Flowable.fromPublisher(client.exchange(
HttpRequest.GET("/ssl-using-file-keys"), String
))
HttpResponse<String> response = flowable.blockingFirst()
HttpResponse<String> response = client.toBlocking().exchange(HttpRequest.GET("/ssl-using-file-keys"), String)

then:
response.body() == "Hello File"
response.body() == "Hello File"
}

@Controller('/')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package io.micronaut.acme


import io.micronaut.http.HttpRequest
import io.micronaut.http.HttpResponse
import io.micronaut.http.annotation.Controller
import io.micronaut.http.annotation.Get
import io.netty.handler.ssl.util.InsecureTrustManagerFactory
import io.reactivex.Flowable
import spock.lang.Stepwise
import spock.util.concurrent.PollingConditions

Expand Down Expand Up @@ -78,13 +76,10 @@ class AcmeCertWildcardRefresherTaskSpec extends AcmeBaseSpec {

void "test send https request when the cert is in place"() {
when:
Flowable<HttpResponse<String>> flowable = Flowable.fromPublisher(client.exchange(
HttpRequest.GET("/wildcardssl"), String
))
HttpResponse<String> response = flowable.blockingFirst()
HttpResponse<String> response = client.toBlocking().exchange(HttpRequest.GET("/wildcardssl"), String)

then:
response.body() == "Hello Wildcard"
response.body() == "Hello Wildcard"
}

@Controller('/')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import io.micronaut.http.HttpRequest
import io.micronaut.http.HttpResponse
import io.micronaut.http.HttpStatus
import io.micronaut.http.client.exceptions.HttpClientResponseException
import io.reactivex.Flowable

import static org.testcontainers.shaded.org.apache.commons.lang.RandomStringUtils.randomAlphanumeric

Expand Down Expand Up @@ -52,9 +51,6 @@ class WellKnownTokenControllerSpec extends AcmeBaseSpec {
}

private HttpResponse<String> callWellKnownEndpoint(String randomToken) {
Flowable<HttpResponse<String>> flowable = Flowable.fromPublisher(client.exchange(
HttpRequest.GET("/.well-known/acme-challenge/$randomToken"), String
))
flowable.blockingFirst()
client.toBlocking().exchange(HttpRequest.GET("/.well-known/acme-challenge/$randomToken"), String)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import io.micronaut.http.HttpResponse
import io.micronaut.http.annotation.Controller
import io.micronaut.http.annotation.Get
import io.netty.handler.ssl.util.InsecureTrustManagerFactory
import io.reactivex.Flowable
import spock.lang.Stepwise
import spock.util.concurrent.PollingConditions

Expand Down Expand Up @@ -74,13 +73,10 @@ class AcmeCertRefresherTaskHttp01ChallengeSpec extends AcmeBaseSpec {

void "test send https request when the cert is in place"() {
when:
Flowable<HttpResponse<String>> flowable = Flowable.fromPublisher(client.exchange(
HttpRequest.GET("/httpchallenge"), String
))
HttpResponse<String> response = flowable.blockingFirst()
HttpResponse<String> response = client.toBlocking().exchange(HttpRequest.GET("/httpchallenge"), String)

then:
response.body() == "Hello HTTP"
response.body() == "Hello HTTP"
}

@Controller('/')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import io.micronaut.http.HttpResponse
import io.micronaut.http.annotation.Controller
import io.micronaut.http.annotation.Get
import io.netty.handler.ssl.util.InsecureTrustManagerFactory
import io.reactivex.Flowable
import spock.lang.Stepwise
import spock.util.concurrent.PollingConditions

Expand Down Expand Up @@ -72,13 +71,10 @@ class AcmeCertRefresherTaskTlsApln01ChallengeSpec extends AcmeBaseSpec {

void "test send https request when the cert is in place"() {
when:
Flowable<HttpResponse<String>> flowable = Flowable.fromPublisher(client.exchange(
HttpRequest.GET("/tlschallenge"), String
))
HttpResponse<String> response = flowable.blockingFirst()
HttpResponse<String> response = client.toBlocking().exchange(HttpRequest.GET("/tlschallenge"), String)

then:
response.body() == "Hello TLS"
response.body() == "Hello TLS"
}

@Controller('/')
Expand Down

0 comments on commit 6cd7907

Please sign in to comment.