Skip to content

Commit 7a275a2

Browse files
committed
Generate STAC Client specs
1 parent 739912d commit 7a275a2

File tree

6 files changed

+226
-467
lines changed

6 files changed

+226
-467
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
55

66
## [Unreleased]
7+
### Added
8+
- Add a client module [#140](https://github.com/azavea/stac4s/pull/140)
9+
710
### Fixed
811
- Repaired build.sbt configuration to get sonatype publication to cooperate [#186](https://github.com/azavea/stac4s/pull/186)
912

build.sbt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,11 @@ lazy val testing = crossProject(JSPlatform, JVMPlatform)
170170
)
171171
)
172172
.jvmSettings(libraryDependencies ++= testingDependenciesJVM)
173+
.jsSettings(
174+
libraryDependencies ++= Seq(
175+
"io.github.cquiroz" %%% "scala-java-time" % "2.1.0" % Test
176+
)
177+
)
173178

174179
lazy val testingJVM = testing.jvm
175180
lazy val testingJS = testing.js
@@ -198,7 +203,7 @@ lazy val coreTestRef = LocalProject("modules/core-test")
198203

199204
lazy val client = crossProject(JSPlatform, JVMPlatform)
200205
.in(file("modules/client"))
201-
.dependsOn(core)
206+
.dependsOn(core, testing % Test)
202207
.settings(commonSettings)
203208
.settings(publishSettings)
204209
.settings(
Lines changed: 44 additions & 231 deletions
Original file line numberDiff line numberDiff line change
@@ -1,259 +1,72 @@
11
package com.azavea.stac4s.api.client
22

3+
import com.azavea.stac4s.testing.JsInstances
4+
35
import cats.syntax.either._
46
import eu.timepit.refined.types.all.NonEmptyString
5-
import io.circe.parser._
7+
import io.circe.JsonObject
8+
import io.circe.syntax._
69
import org.scalatest.funspec.AnyFunSpec
710
import org.scalatest.matchers.should.Matchers
811
import sttp.client3.testing.SttpBackendStub
912
import sttp.client3.{Response, UriContext}
10-
import sttp.model.StatusCode
1113
import sttp.monad.EitherMonad
1214

13-
class StacClientSpec extends AnyFunSpec with Matchers {
15+
class StacClientSpec extends AnyFunSpec with Matchers with JsInstances {
1416

15-
lazy val backend: SttpBackendStub[Either[Throwable, *], Nothing] =
17+
lazy val backend =
1618
SttpBackendStub(EitherMonad)
19+
.whenRequestMatches(_.uri.path == Seq("search"))
20+
.thenRespondF { _ =>
21+
Response
22+
.ok(arbItemCollectionShort.arbitrary.sample.asJson.asRight)
23+
.asRight
24+
}
1725
.whenRequestMatches(_.uri.path == Seq("collections"))
1826
.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
8730
}
88-
.whenRequestMatches(_.uri.path == Seq("collections", "aviris_2006", "items"))
31+
.whenRequestMatches(_.uri.path == Seq("collections", "collection_id", "items"))
8932
.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
24342
}
24443

24544
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") {
24753
SttpStacClient(backend, uri"http://localhost:9090").collections
24854
.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
25063
}
25164

252-
it("SttpBackendStub items") {
65+
it("item") {
25366
SttpStacClient(backend, uri"http://localhost:9090")
254-
.items(NonEmptyString.unsafeFrom("aviris_2006"))
67+
.item(NonEmptyString.unsafeFrom("collection_id"), NonEmptyString.unsafeFrom("item_id"))
25568
.valueOr(throw _)
256-
.map(_.id) shouldBe "aviris_f060426t01p00r03_sc01" :: Nil
69+
.size should be > 0
25770
}
25871
}
25972
}

0 commit comments

Comments
 (0)