44
55package play .libs .ws .ahc
66
7- import org .specs2 .concurrent .ExecutionEnv
8- import org .specs2 .concurrent .FutureAwait
9- import org .specs2 .mutable .Specification
7+ import org .scalatest .concurrent .ScalaFutures
8+ import org .scalatest .wordspec .AnyWordSpec
109import play .NettyServerProvider
1110import play .api .BuiltInComponents
1211import play .api .mvc .Results
@@ -22,11 +21,11 @@ import scala.jdk.CollectionConverters._
2221import scala .jdk .FutureConverters ._
2322import play .api .routing .sird ._
2423
25- class AhcCurlRequestLoggerSpec ( implicit val executionEnv : ExecutionEnv )
26- extends Specification
24+ class AhcCurlRequestLoggerSpec
25+ extends AnyWordSpec
2726 with NettyServerProvider
2827 with StandaloneWSClientSupport
29- with FutureAwait
28+ with ScalaFutures
3029 with DefaultBodyWritables {
3130
3231 override def routes (components : BuiltInComponents ) = {
@@ -56,9 +55,9 @@ class AhcCurlRequestLoggerSpec(implicit val executionEnv: ExecutionEnv)
5655 .setRequestFilter(curlRequestLogger)
5756 .get()
5857 .asScala
59- .awaitFor(defaultTimeout)
58+ .futureValue
6059
61- testLogger.getLoggingEvents.asScala.map(_.getMessage) must containMatch( " --verbose" )
60+ assert( testLogger.getLoggingEvents.asScala.map(_.getMessage).exists(_.contains( " --verbose" )) )
6261 }
6362
6463 " add all headers" in withClient() { client =>
@@ -71,11 +70,11 @@ class AhcCurlRequestLoggerSpec(implicit val executionEnv: ExecutionEnv)
7170 .setRequestFilter(curlRequestLogger)
7271 .get()
7372 .asScala
74- .awaitFor(defaultTimeout)
73+ .futureValue
7574
7675 val messages = testLogger.getLoggingEvents.asScala.map(_.getMessage)
7776
78- messages must containMatch( " --header 'My-Header: My-Header-Value'" )
77+ assert( messages.exists(_.contains( " --header 'My-Header: My-Header-Value'" )) )
7978 }
8079
8180 " add all cookies" in withClient() { client =>
@@ -88,11 +87,11 @@ class AhcCurlRequestLoggerSpec(implicit val executionEnv: ExecutionEnv)
8887 .setRequestFilter(curlRequestLogger)
8988 .get()
9089 .asScala
91- .awaitFor(defaultTimeout)
90+ .futureValue
9291
9392 val messages = testLogger.getLoggingEvents.asScala.map(_.getMessage)
9493
95- messages must containMatch( """ --cookie 'cookie1=value1'""" )
94+ assert( messages.exists(_.contains( """ --cookie 'cookie1=value1'""" )) )
9695 }
9796
9897 " add method" in withClient() { client =>
@@ -104,9 +103,11 @@ class AhcCurlRequestLoggerSpec(implicit val executionEnv: ExecutionEnv)
104103 .setRequestFilter(curlRequestLogger)
105104 .get()
106105 .asScala
107- .awaitFor(defaultTimeout)
106+ .futureValue
108107
109- testLogger.getLoggingEvents.asScala.map(_.getMessage) must containMatch(" --request GET" )
108+ assert(
109+ testLogger.getLoggingEvents.asScala.map(_.getMessage).exists(_.contains(" --request GET" ))
110+ )
110111 }
111112
112113 " add authorization header" in withClient() { client =>
@@ -119,14 +120,20 @@ class AhcCurlRequestLoggerSpec(implicit val executionEnv: ExecutionEnv)
119120 .setRequestFilter(curlRequestLogger)
120121 .get()
121122 .asScala
122- .awaitFor(defaultTimeout)
123-
124- testLogger.getLoggingEvents.asScala.map(_.getMessage) must containMatch(
125- """ --header 'Authorization: Basic dXNlcm5hbWU6cGFzc3dvcmQ='"""
123+ .futureValue
124+
125+ assert(
126+ testLogger.getLoggingEvents.asScala
127+ .map(_.getMessage)
128+ .exists(
129+ _.contains(
130+ """ --header 'Authorization: Basic dXNlcm5hbWU6cGFzc3dvcmQ='"""
131+ )
132+ )
126133 )
127134 }
128135
129- " handle body" in {
136+ " handle body" should {
130137
131138 " add when in memory" in withClient() { client =>
132139 val testLogger = createTestLogger
@@ -138,9 +145,9 @@ class AhcCurlRequestLoggerSpec(implicit val executionEnv: ExecutionEnv)
138145 .setRequestFilter(curlRequestLogger)
139146 .get()
140147 .asScala
141- .awaitFor(defaultTimeout)
148+ .futureValue
142149
143- testLogger.getLoggingEvents.asScala.map(_.getMessage) must containMatch( " the-body" )
150+ assert( testLogger.getLoggingEvents.asScala.map(_.getMessage).exists(_.contains( " the-body" )) )
144151 }
145152
146153 " do nothing for empty bodies" in withClient() { client =>
@@ -153,9 +160,9 @@ class AhcCurlRequestLoggerSpec(implicit val executionEnv: ExecutionEnv)
153160 .setRequestFilter(curlRequestLogger)
154161 .get()
155162 .asScala
156- .awaitFor(defaultTimeout)
163+ .futureValue
157164
158- testLogger.getLoggingEvents.asScala.map(_.getMessage) must not containMatch " --data"
165+ assert( testLogger.getLoggingEvents.asScala.map(_.getMessage).forall( ! _.contains( " --data" )))
159166 }
160167 }
161168
@@ -171,18 +178,19 @@ class AhcCurlRequestLoggerSpec(implicit val executionEnv: ExecutionEnv)
171178 .setRequestFilter(curlRequestLogger)
172179 .get()
173180 .asScala
174- .awaitFor(defaultTimeout)
175-
176- testLogger.getLoggingEvents.get(0 ).getMessage must beEqualTo(
177- s """
178- |curl \\
179- | --verbose \\
180- | --request GET \\
181- | --header 'Authorization: Basic dXNlcm5hbWU6cGFzc3dvcmQ=' \\
182- | --header 'content-type: text/plain' \\
183- | --header 'My-Header: My-Header-Value' \\
184- | --data 'the-body' \\
185- | 'http://localhost: $testServerPort/'
181+ .futureValue
182+
183+ assert(
184+ testLogger.getLoggingEvents.get(0 ).getMessage ==
185+ s """
186+ |curl \\
187+ | --verbose \\
188+ | --request GET \\
189+ | --header 'Authorization: Basic dXNlcm5hbWU6cGFzc3dvcmQ=' \\
190+ | --header 'content-type: text/plain' \\
191+ | --header 'My-Header: My-Header-Value' \\
192+ | --data 'the-body' \\
193+ | 'http://localhost: $testServerPort/'
186194 """ .stripMargin.trim
187195 )
188196 }
0 commit comments