@@ -19,6 +19,7 @@ import io.circe.syntax._
19
19
import org .http4s .circe .CirceEntityDecoder ._
20
20
import org .http4s .circe .CirceEntityEncoder ._
21
21
import org .http4s .{Method , Request , Uri }
22
+ import org .scalacheck .Prop
22
23
import org .specs2 .execute .Result
23
24
import org .specs2 .{ScalaCheck , Specification }
24
25
@@ -35,10 +36,11 @@ class CollectionsServiceSpec
35
36
This specification verifies that the collections service can run without crashing
36
37
37
38
The collections service should:
38
- - create and delete collections $createDeleteCollectionExpectation
39
- - list collections $listCollectionsExpectation
40
- - get collections by id $getCollectionsExpectation
41
- - create a mosaic definition $createMosaicDefinitionExpectation
39
+ - create and delete collections createDeleteCollectionExpectation
40
+ - list collections listCollectionsExpectation
41
+ - get collections by id getCollectionsExpectation
42
+ - create a mosaic definition createMosaicDefinitionExpectation
43
+ - get a mosaic by id $getMosaicExpectation
42
44
"""
43
45
44
46
val testServices : TestServices [IO ] = new TestServices [IO ](transactor)
@@ -167,4 +169,66 @@ class CollectionsServiceSpec
167
169
168
170
}
169
171
172
+ @ SuppressWarnings (Array (" TraversableHead" ))
173
+ def getMosaicExpectation = prop { (stacCollection : StacCollection , stacItem : StacItem ) =>
174
+ (! stacItem.assets.isEmpty) ==> {
175
+ val expectationIO = (testClient, testServices.collectionsService).tupled flatMap {
176
+ case (client, collectionsService) =>
177
+ client.getCollectionItemsResource(List (stacItem), stacCollection) use {
178
+ case (collection, items) =>
179
+ val encodedCollectionId =
180
+ URLEncoder .encode(collection.id, StandardCharsets .UTF_8 .toString)
181
+ val item = items.head
182
+ val name = item.assets.keys.head
183
+ val mosaicDefinition =
184
+ MosaicDefinition (
185
+ UUID .randomUUID,
186
+ Option (" Testing mosaic definition" ),
187
+ MapCenter .fromGeometry(item.geometry, 8 ),
188
+ NonEmptyList .of(ItemAsset (item.id, name)),
189
+ 2 ,
190
+ 30 ,
191
+ item.bbox
192
+ )
193
+
194
+ val createRequest =
195
+ Request [IO ](
196
+ method = Method .POST ,
197
+ Uri .unsafeFromString(s " /collections/ $encodedCollectionId/mosaic " )
198
+ ).withEntity(
199
+ mosaicDefinition
200
+ )
201
+
202
+ val getRequest =
203
+ Request [IO ](
204
+ method = Method .GET ,
205
+ Uri .unsafeFromString(
206
+ s " /collections/ $encodedCollectionId/mosaic/ ${mosaicDefinition.id}"
207
+ )
208
+ )
209
+
210
+ val deleteRequest =
211
+ Request [IO ](
212
+ method = Method .DELETE ,
213
+ Uri .unsafeFromString(
214
+ s " /collections/ $encodedCollectionId/mosaic/ ${mosaicDefinition.id}"
215
+ )
216
+ )
217
+
218
+ (for {
219
+ _ <- collectionsService.routes.run(createRequest)
220
+ resp <- collectionsService.routes.run(getRequest)
221
+ decoded <- OptionT .liftF { resp.as[MosaicDefinition ] }
222
+ deleteResp <- collectionsService.routes.run(deleteRequest)
223
+ } yield (decoded, deleteResp)).value map {
224
+ case Some ((respData, deleteResp)) =>
225
+ respData === mosaicDefinition && deleteResp.status.code === 204 : Prop
226
+ case None => false : Prop
227
+ }
228
+ }
229
+
230
+ }
231
+ expectationIO.unsafeRunSync
232
+ }
233
+ }
170
234
}
0 commit comments