|
1 | 1 | package com.azavea.stac4s.api.client |
2 | 2 |
|
| 3 | +import com.azavea.stac4s.testing.JsInstances |
| 4 | + |
3 | 5 | import cats.syntax.either._ |
4 | 6 | import eu.timepit.refined.types.all.NonEmptyString |
5 | | -import io.circe.parser._ |
| 7 | +import io.circe.JsonObject |
| 8 | +import io.circe.syntax._ |
6 | 9 | import org.scalatest.funspec.AnyFunSpec |
7 | 10 | import org.scalatest.matchers.should.Matchers |
8 | 11 | import sttp.client3.testing.SttpBackendStub |
9 | 12 | import sttp.client3.{Response, UriContext} |
10 | | -import sttp.model.StatusCode |
11 | 13 | import sttp.monad.EitherMonad |
12 | 14 |
|
13 | | -class StacClientSpec extends AnyFunSpec with Matchers { |
| 15 | +class StacClientSpec extends AnyFunSpec with Matchers with JsInstances { |
14 | 16 |
|
15 | | - lazy val backend: SttpBackendStub[Either[Throwable, *], Nothing] = |
| 17 | + lazy val backend = |
16 | 18 | SttpBackendStub(EitherMonad) |
| 19 | + .whenRequestMatches(_.uri.path == Seq("search")) |
| 20 | + .thenRespondF { _ => |
| 21 | + Response |
| 22 | + .ok(arbItemCollectionShort.arbitrary.sample.asJson.asRight) |
| 23 | + .asRight |
| 24 | + } |
17 | 25 | .whenRequestMatches(_.uri.path == Seq("collections")) |
18 | 26 | .thenRespondF { _ => |
19 | | - Right( |
20 | | - Response( |
21 | | - Right(parse(""" |
22 | | - |{ |
23 | | - | "collections":[ |
24 | | - | { |
25 | | - | "stac_version":"1.0.0-beta.2", |
26 | | - | "stac_extensions":[ |
27 | | - | |
28 | | - | ], |
29 | | - | "id":"aviris_2006", |
30 | | - | "title":null, |
31 | | - | "description":"aviris_2006", |
32 | | - | "keywords":[ |
33 | | - | |
34 | | - | ], |
35 | | - | "license":"proprietary", |
36 | | - | "providers":[ |
37 | | - | |
38 | | - | ], |
39 | | - | "extent":{ |
40 | | - | "spatial":{ |
41 | | - | "bbox":[ |
42 | | - | [ |
43 | | - | -122.857491, |
44 | | - | 32.093266, |
45 | | - | -76.55229, |
46 | | - | 48.142484 |
47 | | - | ] |
48 | | - | ] |
49 | | - | }, |
50 | | - | "temporal":{ |
51 | | - | "interval":[ |
52 | | - | [ |
53 | | - | "2006-04-26T17:52:00Z", |
54 | | - | "2006-11-15T19:42:00Z" |
55 | | - | ] |
56 | | - | ] |
57 | | - | } |
58 | | - | }, |
59 | | - | "summaries":{ |
60 | | - | |
61 | | - | }, |
62 | | - | "properties":{ |
63 | | - | |
64 | | - | }, |
65 | | - | "links":[ |
66 | | - | { |
67 | | - | "href":"http://localhost:9090/collections/aviris_2006/items", |
68 | | - | "rel":"items", |
69 | | - | "type":"application/json", |
70 | | - | "title":null |
71 | | - | }, |
72 | | - | { |
73 | | - | "href":"http://localhost:9090/collections/aviris_2006", |
74 | | - | "rel":"self", |
75 | | - | "type":"application/json", |
76 | | - | "title":null |
77 | | - | } |
78 | | - | ] |
79 | | - | } |
80 | | - | ] |
81 | | - |} |
82 | | - |""".stripMargin).valueOr(throw _)), |
83 | | - StatusCode.Ok, |
84 | | - "" |
85 | | - ) |
86 | | - ) |
| 27 | + Response |
| 28 | + .ok(JsonObject("collections" -> arbCollectionShort.arbitrary.sample.toList.asJson).asJson.asRight) |
| 29 | + .asRight |
87 | 30 | } |
88 | | - .whenRequestMatches(_.uri.path == Seq("collections", "aviris_2006", "items")) |
| 31 | + .whenRequestMatches(_.uri.path == Seq("collections", "collection_id", "items")) |
89 | 32 | .thenRespondF { _ => |
90 | | - Right( |
91 | | - Response( |
92 | | - Right(parse(""" |
93 | | - |{ |
94 | | - | "type":"FeatureCollection", |
95 | | - | "features":[ |
96 | | - | { |
97 | | - | "id":"aviris_f060426t01p00r03_sc01", |
98 | | - | "stac_version":"1.0.0-beta.2", |
99 | | - | "stac_extensions":[ |
100 | | - | |
101 | | - | ], |
102 | | - | "type":"Feature", |
103 | | - | "geometry":{ |
104 | | - | "type":"Polygon", |
105 | | - | "coordinates":[ |
106 | | - | [ |
107 | | - | [ |
108 | | - | -107.771817, |
109 | | - | 37.913396 |
110 | | - | ], |
111 | | - | [ |
112 | | - | -107.739984, |
113 | | - | 37.914142 |
114 | | - | ], |
115 | | - | [ |
116 | | - | -107.744691, |
117 | | - | 38.040563 |
118 | | - | ], |
119 | | - | [ |
120 | | - | -107.776579, |
121 | | - | 38.039814 |
122 | | - | ], |
123 | | - | [ |
124 | | - | -107.771817, |
125 | | - | 37.913396 |
126 | | - | ] |
127 | | - | ] |
128 | | - | ] |
129 | | - | }, |
130 | | - | "bbox":[ |
131 | | - | -107.776579, |
132 | | - | 37.913396, |
133 | | - | -107.739984, |
134 | | - | 38.040563 |
135 | | - | ], |
136 | | - | "links":[ |
137 | | - | { |
138 | | - | "href":"http://localhost:9090/collections/aviris_2006_60426", |
139 | | - | "rel":"collection", |
140 | | - | "type":"application/json", |
141 | | - | "title":null |
142 | | - | }, |
143 | | - | { |
144 | | - | "href":"http://localhost:9090/collections/aviris_2006_60426/items/aviris_f060426t01p00r03_sc01", |
145 | | - | "rel":"self", |
146 | | - | "type":"application/json", |
147 | | - | "title":null |
148 | | - | } |
149 | | - | ], |
150 | | - | "assets":{ |
151 | | - | "ftp":{ |
152 | | - | "href":"ftp://avoil:[email protected]/y06_data/f060426t01p00r03.tar.gz", |
153 | | - | "title":"ftp", |
154 | | - | "description":"AVIRIS data archive. The file size is described by the 'Gzip File Size' property.", |
155 | | - | "roles":[ |
156 | | - | |
157 | | - | ], |
158 | | - | "type":"application/gzip" |
159 | | - | }, |
160 | | - | "rgb":{ |
161 | | - | "href":"http://aviris.jpl.nasa.gov/aviris_locator/y06_RGB/f060426t01p00r03_sc01_RGB.jpeg", |
162 | | - | "title":"rgb", |
163 | | - | "description":"Full resolution RGB image captured by the flight", |
164 | | - | "roles":[ |
165 | | - | |
166 | | - | ], |
167 | | - | "type":"image/jpeg" |
168 | | - | }, |
169 | | - | "kml_overlay":{ |
170 | | - | "href":"http://aviris.jpl.nasa.gov/aviris_locator/y06_KML/f060426t01p00r03_sc01_overlay_KML.kml", |
171 | | - | "title":"kml_overlay", |
172 | | - | "description":"KML file describing the bounding box of the flight", |
173 | | - | "roles":[ |
174 | | - | |
175 | | - | ], |
176 | | - | "type":"application/vnd.google-earth.kml+xml" |
177 | | - | }, |
178 | | - | "rgb_small":{ |
179 | | - | "href":"http://aviris.jpl.nasa.gov/aviris_locator/y06_RGB/f060426t01p00r03_sc01_RGB-W200.jpg", |
180 | | - | "title":"rgb_small", |
181 | | - | "description":"A lower resolution thumbnail of the same image as the 'rgb' asset.", |
182 | | - | "roles":[ |
183 | | - | |
184 | | - | ], |
185 | | - | "type":"image/jpeg" |
186 | | - | }, |
187 | | - | "flight_log":{ |
188 | | - | "href":"http://aviris.jpl.nasa.gov/cgi/flights_06.cgi?step=view_flightlog&flight_id=f060426t01", |
189 | | - | "title":"flight_log", |
190 | | - | "description":"HTML page with table listing the runs for this flight.", |
191 | | - | "roles":[ |
192 | | - | |
193 | | - | ], |
194 | | - | "type":"text/html" |
195 | | - | }, |
196 | | - | "kml_outline":{ |
197 | | - | "href":"http://aviris.jpl.nasa.gov/aviris_locator/y06_KML/f060426t01p00r03_sc01_outline_KML.kml", |
198 | | - | "title":"kml_outline", |
199 | | - | "description":"KML file describing the flight outline", |
200 | | - | "roles":[ |
201 | | - | |
202 | | - | ], |
203 | | - | "type":"application/vnd.google-earth.kml+xml" |
204 | | - | } |
205 | | - | }, |
206 | | - | "collection":"aviris_2006_60426", |
207 | | - | "properties":{ |
208 | | - | "YY":6, |
209 | | - | "Run":3, |
210 | | - | "Tape":"t01", |
211 | | - | "Year":2006, |
212 | | - | "Scene":"sc01", |
213 | | - | "Flight":60426, |
214 | | - | "GEO Ver":"ort", |
215 | | - | "RDN Ver":"c", |
216 | | - | "Comments":"Alt = 21Kft<br>SOG = 103 kts<br>CLEAR !!", |
217 | | - | "NASA Log":"6T010", |
218 | | - | "Rotation":0, |
219 | | - | "datetime":"2006-04-26T17:52:00Z", |
220 | | - | "Flight ID":"f060426t01", |
221 | | - | "Site Name":"Red Mtn Pass 1, CO", |
222 | | - | "Pixel Size":2.1, |
223 | | - | "Flight Scene":"f060426t01p00r03_sc01", |
224 | | - | "Investigator":"Thomas Painter", |
225 | | - | "Solar Azimuth":139.9, |
226 | | - | "Number of Lines":6688, |
227 | | - | "Solar Elevation":60.21, |
228 | | - | "File Size (Bytes)":7475366912, |
229 | | - | "Number of Samples":1335, |
230 | | - | "Max Scene Elevation":4097.59, |
231 | | - | "Min Scene Elevation":3163.91, |
232 | | - | "Mean Scene Elevation":3680.71, |
233 | | - | "Gzip File Size (Bytes)":2673260903 |
234 | | - | } |
235 | | - | } |
236 | | - | ] |
237 | | - |} |
238 | | - |""".stripMargin).valueOr(throw _)), |
239 | | - StatusCode.Ok, |
240 | | - "" |
241 | | - ) |
242 | | - ) |
| 33 | + Response |
| 34 | + .ok(arbItemCollectionShort.arbitrary.sample.asJson.asRight) |
| 35 | + .asRight |
| 36 | + } |
| 37 | + .whenRequestMatches(_.uri.path == Seq("collections", "collection_id", "items", "item_id")) |
| 38 | + .thenRespondF { _ => |
| 39 | + Response |
| 40 | + .ok(arbItemShort.arbitrary.sample.asRight) |
| 41 | + .asRight |
243 | 42 | } |
244 | 43 |
|
245 | 44 | describe("StacClientSpec") { |
246 | | - it("SttpBackendStub collections") { |
| 45 | + it("search") { |
| 46 | + SttpStacClient(backend, uri"http://localhost:9090") |
| 47 | + .search() |
| 48 | + .valueOr(throw _) |
| 49 | + .size should be > 0 |
| 50 | + } |
| 51 | + |
| 52 | + it("collections") { |
247 | 53 | SttpStacClient(backend, uri"http://localhost:9090").collections |
248 | 54 | .valueOr(throw _) |
249 | | - .map(_.id) shouldBe "aviris_2006" :: Nil |
| 55 | + .size should be > 0 |
| 56 | + } |
| 57 | + |
| 58 | + it("items") { |
| 59 | + SttpStacClient(backend, uri"http://localhost:9090") |
| 60 | + .items(NonEmptyString.unsafeFrom("collection_id")) |
| 61 | + .valueOr(throw _) |
| 62 | + .size should be > 0 |
250 | 63 | } |
251 | 64 |
|
252 | | - it("SttpBackendStub items") { |
| 65 | + it("item") { |
253 | 66 | SttpStacClient(backend, uri"http://localhost:9090") |
254 | | - .items(NonEmptyString.unsafeFrom("aviris_2006")) |
| 67 | + .item(NonEmptyString.unsafeFrom("collection_id"), NonEmptyString.unsafeFrom("item_id")) |
255 | 68 | .valueOr(throw _) |
256 | | - .map(_.id) shouldBe "aviris_f060426t01p00r03_sc01" :: Nil |
| 69 | + .size should be > 0 |
257 | 70 | } |
258 | 71 | } |
259 | 72 | } |
0 commit comments