55package play .libs .ws .ahc
66
77import akka .http .scaladsl .server .Route
8- import org .specs2 .concurrent .ExecutionEnv
9- import org .specs2 .concurrent .FutureAwait
10- import org .specs2 .mutable .Specification
8+ import org .scalatest .concurrent .ScalaFutures
9+ import org .scalatest .wordspec .AnyWordSpec
1110import play .AkkaServerProvider
1211import play .libs .ws .DefaultBodyWritables
1312import play .libs .ws .DefaultWSCookie
@@ -20,11 +19,11 @@ import uk.org.lidalia.slf4jtest.TestLoggerFactory
2019import scala .jdk .CollectionConverters ._
2120import scala .jdk .FutureConverters ._
2221
23- class AhcCurlRequestLoggerSpec ( implicit val executionEnv : ExecutionEnv )
24- extends Specification
22+ class AhcCurlRequestLoggerSpec
23+ extends AnyWordSpec
2524 with AkkaServerProvider
2625 with StandaloneWSClientSupport
27- with FutureAwait
26+ with ScalaFutures
2827 with DefaultBodyWritables {
2928
3029 override def routes : Route = {
@@ -53,9 +52,9 @@ class AhcCurlRequestLoggerSpec(implicit val executionEnv: ExecutionEnv)
5352 .setRequestFilter(curlRequestLogger)
5453 .get()
5554 .asScala
56- .awaitFor(defaultTimeout)
55+ .futureValue
5756
58- testLogger.getLoggingEvents.asScala.map(_.getMessage) must containMatch( " --verbose" )
57+ assert( testLogger.getLoggingEvents.asScala.map(_.getMessage).exists(_.contains( " --verbose" )) )
5958 }
6059
6160 " add all headers" in withClient() { client =>
@@ -68,11 +67,11 @@ class AhcCurlRequestLoggerSpec(implicit val executionEnv: ExecutionEnv)
6867 .setRequestFilter(curlRequestLogger)
6968 .get()
7069 .asScala
71- .awaitFor(defaultTimeout)
70+ .futureValue
7271
7372 val messages = testLogger.getLoggingEvents.asScala.map(_.getMessage)
7473
75- messages must containMatch( " --header 'My-Header: My-Header-Value'" )
74+ assert( messages.exists(_.contains( " --header 'My-Header: My-Header-Value'" )) )
7675 }
7776
7877 " add all cookies" in withClient() { client =>
@@ -85,11 +84,11 @@ class AhcCurlRequestLoggerSpec(implicit val executionEnv: ExecutionEnv)
8584 .setRequestFilter(curlRequestLogger)
8685 .get()
8786 .asScala
88- .awaitFor(defaultTimeout)
87+ .futureValue
8988
9089 val messages = testLogger.getLoggingEvents.asScala.map(_.getMessage)
9190
92- messages must containMatch( """ --cookie 'cookie1=value1'""" )
91+ assert( messages.exists(_.contains( """ --cookie 'cookie1=value1'""" )) )
9392 }
9493
9594 " add method" in withClient() { client =>
@@ -101,9 +100,11 @@ class AhcCurlRequestLoggerSpec(implicit val executionEnv: ExecutionEnv)
101100 .setRequestFilter(curlRequestLogger)
102101 .get()
103102 .asScala
104- .awaitFor(defaultTimeout)
103+ .futureValue
105104
106- testLogger.getLoggingEvents.asScala.map(_.getMessage) must containMatch(" --request GET" )
105+ assert(
106+ testLogger.getLoggingEvents.asScala.map(_.getMessage).exists(_.contains(" --request GET" ))
107+ )
107108 }
108109
109110 " add authorization header" in withClient() { client =>
@@ -116,14 +117,20 @@ class AhcCurlRequestLoggerSpec(implicit val executionEnv: ExecutionEnv)
116117 .setRequestFilter(curlRequestLogger)
117118 .get()
118119 .asScala
119- .awaitFor(defaultTimeout)
120-
121- testLogger.getLoggingEvents.asScala.map(_.getMessage) must containMatch(
122- """ --header 'Authorization: Basic dXNlcm5hbWU6cGFzc3dvcmQ='"""
120+ .futureValue
121+
122+ assert(
123+ testLogger.getLoggingEvents.asScala
124+ .map(_.getMessage)
125+ .exists(
126+ _.contains(
127+ """ --header 'Authorization: Basic dXNlcm5hbWU6cGFzc3dvcmQ='"""
128+ )
129+ )
123130 )
124131 }
125132
126- " handle body" in {
133+ " handle body" should {
127134
128135 " add when in memory" in withClient() { client =>
129136 val testLogger = createTestLogger
@@ -135,9 +142,9 @@ class AhcCurlRequestLoggerSpec(implicit val executionEnv: ExecutionEnv)
135142 .setRequestFilter(curlRequestLogger)
136143 .get()
137144 .asScala
138- .awaitFor(defaultTimeout)
145+ .futureValue
139146
140- testLogger.getLoggingEvents.asScala.map(_.getMessage) must containMatch( " the-body" )
147+ assert( testLogger.getLoggingEvents.asScala.map(_.getMessage).exists(_.contains( " the-body" )) )
141148 }
142149
143150 " do nothing for empty bodies" in withClient() { client =>
@@ -150,9 +157,9 @@ class AhcCurlRequestLoggerSpec(implicit val executionEnv: ExecutionEnv)
150157 .setRequestFilter(curlRequestLogger)
151158 .get()
152159 .asScala
153- .awaitFor(defaultTimeout)
160+ .futureValue
154161
155- testLogger.getLoggingEvents.asScala.map(_.getMessage) must not containMatch " --data"
162+ assert( testLogger.getLoggingEvents.asScala.map(_.getMessage).forall( ! _.contains( " --data" )))
156163 }
157164 }
158165
@@ -168,18 +175,19 @@ class AhcCurlRequestLoggerSpec(implicit val executionEnv: ExecutionEnv)
168175 .setRequestFilter(curlRequestLogger)
169176 .get()
170177 .asScala
171- .awaitFor(defaultTimeout)
172-
173- testLogger.getLoggingEvents.get(0 ).getMessage must beEqualTo(
174- s """
175- |curl \\
176- | --verbose \\
177- | --request GET \\
178- | --header 'Authorization: Basic dXNlcm5hbWU6cGFzc3dvcmQ=' \\
179- | --header 'content-type: text/plain' \\
180- | --header 'My-Header: My-Header-Value' \\
181- | --data 'the-body' \\
182- | 'http://localhost: $testServerPort/'
178+ .futureValue
179+
180+ assert(
181+ testLogger.getLoggingEvents.get(0 ).getMessage ==
182+ s """
183+ |curl \\
184+ | --verbose \\
185+ | --request GET \\
186+ | --header 'Authorization: Basic dXNlcm5hbWU6cGFzc3dvcmQ=' \\
187+ | --header 'content-type: text/plain' \\
188+ | --header 'My-Header: My-Header-Value' \\
189+ | --data 'the-body' \\
190+ | 'http://localhost: $testServerPort/'
183191 """ .stripMargin.trim
184192 )
185193 }
0 commit comments