-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
226 additions
and
467 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
275 changes: 44 additions & 231 deletions
275
modules/client/js/src/test/scala/com/azavea/stac4s/api/client/StacClientSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,259 +1,72 @@ | ||
package com.azavea.stac4s.api.client | ||
|
||
import com.azavea.stac4s.testing.JsInstances | ||
|
||
import cats.syntax.either._ | ||
import eu.timepit.refined.types.all.NonEmptyString | ||
import io.circe.parser._ | ||
import io.circe.JsonObject | ||
import io.circe.syntax._ | ||
import org.scalatest.funspec.AnyFunSpec | ||
import org.scalatest.matchers.should.Matchers | ||
import sttp.client3.testing.SttpBackendStub | ||
import sttp.client3.{Response, UriContext} | ||
import sttp.model.StatusCode | ||
import sttp.monad.EitherMonad | ||
|
||
class StacClientSpec extends AnyFunSpec with Matchers { | ||
class StacClientSpec extends AnyFunSpec with Matchers with JsInstances { | ||
|
||
lazy val backend: SttpBackendStub[Either[Throwable, *], Nothing] = | ||
lazy val backend = | ||
SttpBackendStub(EitherMonad) | ||
.whenRequestMatches(_.uri.path == Seq("search")) | ||
.thenRespondF { _ => | ||
Response | ||
.ok(arbItemCollectionShort.arbitrary.sample.asJson.asRight) | ||
.asRight | ||
} | ||
.whenRequestMatches(_.uri.path == Seq("collections")) | ||
.thenRespondF { _ => | ||
Right( | ||
Response( | ||
Right(parse(""" | ||
|{ | ||
| "collections":[ | ||
| { | ||
| "stac_version":"1.0.0-beta.2", | ||
| "stac_extensions":[ | ||
| | ||
| ], | ||
| "id":"aviris_2006", | ||
| "title":null, | ||
| "description":"aviris_2006", | ||
| "keywords":[ | ||
| | ||
| ], | ||
| "license":"proprietary", | ||
| "providers":[ | ||
| | ||
| ], | ||
| "extent":{ | ||
| "spatial":{ | ||
| "bbox":[ | ||
| [ | ||
| -122.857491, | ||
| 32.093266, | ||
| -76.55229, | ||
| 48.142484 | ||
| ] | ||
| ] | ||
| }, | ||
| "temporal":{ | ||
| "interval":[ | ||
| [ | ||
| "2006-04-26T17:52:00Z", | ||
| "2006-11-15T19:42:00Z" | ||
| ] | ||
| ] | ||
| } | ||
| }, | ||
| "summaries":{ | ||
| | ||
| }, | ||
| "properties":{ | ||
| | ||
| }, | ||
| "links":[ | ||
| { | ||
| "href":"http://localhost:9090/collections/aviris_2006/items", | ||
| "rel":"items", | ||
| "type":"application/json", | ||
| "title":null | ||
| }, | ||
| { | ||
| "href":"http://localhost:9090/collections/aviris_2006", | ||
| "rel":"self", | ||
| "type":"application/json", | ||
| "title":null | ||
| } | ||
| ] | ||
| } | ||
| ] | ||
|} | ||
|""".stripMargin).valueOr(throw _)), | ||
StatusCode.Ok, | ||
"" | ||
) | ||
) | ||
Response | ||
.ok(JsonObject("collections" -> arbCollectionShort.arbitrary.sample.toList.asJson).asJson.asRight) | ||
.asRight | ||
} | ||
.whenRequestMatches(_.uri.path == Seq("collections", "aviris_2006", "items")) | ||
.whenRequestMatches(_.uri.path == Seq("collections", "collection_id", "items")) | ||
.thenRespondF { _ => | ||
Right( | ||
Response( | ||
Right(parse(""" | ||
|{ | ||
| "type":"FeatureCollection", | ||
| "features":[ | ||
| { | ||
| "id":"aviris_f060426t01p00r03_sc01", | ||
| "stac_version":"1.0.0-beta.2", | ||
| "stac_extensions":[ | ||
| | ||
| ], | ||
| "type":"Feature", | ||
| "geometry":{ | ||
| "type":"Polygon", | ||
| "coordinates":[ | ||
| [ | ||
| [ | ||
| -107.771817, | ||
| 37.913396 | ||
| ], | ||
| [ | ||
| -107.739984, | ||
| 37.914142 | ||
| ], | ||
| [ | ||
| -107.744691, | ||
| 38.040563 | ||
| ], | ||
| [ | ||
| -107.776579, | ||
| 38.039814 | ||
| ], | ||
| [ | ||
| -107.771817, | ||
| 37.913396 | ||
| ] | ||
| ] | ||
| ] | ||
| }, | ||
| "bbox":[ | ||
| -107.776579, | ||
| 37.913396, | ||
| -107.739984, | ||
| 38.040563 | ||
| ], | ||
| "links":[ | ||
| { | ||
| "href":"http://localhost:9090/collections/aviris_2006_60426", | ||
| "rel":"collection", | ||
| "type":"application/json", | ||
| "title":null | ||
| }, | ||
| { | ||
| "href":"http://localhost:9090/collections/aviris_2006_60426/items/aviris_f060426t01p00r03_sc01", | ||
| "rel":"self", | ||
| "type":"application/json", | ||
| "title":null | ||
| } | ||
| ], | ||
| "assets":{ | ||
| "ftp":{ | ||
| "href":"ftp://avoil:Gulf0il$pill@popo.jpl.nasa.gov/y06_data/f060426t01p00r03.tar.gz", | ||
| "title":"ftp", | ||
| "description":"AVIRIS data archive. The file size is described by the 'Gzip File Size' property.", | ||
| "roles":[ | ||
| | ||
| ], | ||
| "type":"application/gzip" | ||
| }, | ||
| "rgb":{ | ||
| "href":"http://aviris.jpl.nasa.gov/aviris_locator/y06_RGB/f060426t01p00r03_sc01_RGB.jpeg", | ||
| "title":"rgb", | ||
| "description":"Full resolution RGB image captured by the flight", | ||
| "roles":[ | ||
| | ||
| ], | ||
| "type":"image/jpeg" | ||
| }, | ||
| "kml_overlay":{ | ||
| "href":"http://aviris.jpl.nasa.gov/aviris_locator/y06_KML/f060426t01p00r03_sc01_overlay_KML.kml", | ||
| "title":"kml_overlay", | ||
| "description":"KML file describing the bounding box of the flight", | ||
| "roles":[ | ||
| | ||
| ], | ||
| "type":"application/vnd.google-earth.kml+xml" | ||
| }, | ||
| "rgb_small":{ | ||
| "href":"http://aviris.jpl.nasa.gov/aviris_locator/y06_RGB/f060426t01p00r03_sc01_RGB-W200.jpg", | ||
| "title":"rgb_small", | ||
| "description":"A lower resolution thumbnail of the same image as the 'rgb' asset.", | ||
| "roles":[ | ||
| | ||
| ], | ||
| "type":"image/jpeg" | ||
| }, | ||
| "flight_log":{ | ||
| "href":"http://aviris.jpl.nasa.gov/cgi/flights_06.cgi?step=view_flightlog&flight_id=f060426t01", | ||
| "title":"flight_log", | ||
| "description":"HTML page with table listing the runs for this flight.", | ||
| "roles":[ | ||
| | ||
| ], | ||
| "type":"text/html" | ||
| }, | ||
| "kml_outline":{ | ||
| "href":"http://aviris.jpl.nasa.gov/aviris_locator/y06_KML/f060426t01p00r03_sc01_outline_KML.kml", | ||
| "title":"kml_outline", | ||
| "description":"KML file describing the flight outline", | ||
| "roles":[ | ||
| | ||
| ], | ||
| "type":"application/vnd.google-earth.kml+xml" | ||
| } | ||
| }, | ||
| "collection":"aviris_2006_60426", | ||
| "properties":{ | ||
| "YY":6, | ||
| "Run":3, | ||
| "Tape":"t01", | ||
| "Year":2006, | ||
| "Scene":"sc01", | ||
| "Flight":60426, | ||
| "GEO Ver":"ort", | ||
| "RDN Ver":"c", | ||
| "Comments":"Alt = 21Kft<br>SOG = 103 kts<br>CLEAR !!", | ||
| "NASA Log":"6T010", | ||
| "Rotation":0, | ||
| "datetime":"2006-04-26T17:52:00Z", | ||
| "Flight ID":"f060426t01", | ||
| "Site Name":"Red Mtn Pass 1, CO", | ||
| "Pixel Size":2.1, | ||
| "Flight Scene":"f060426t01p00r03_sc01", | ||
| "Investigator":"Thomas Painter", | ||
| "Solar Azimuth":139.9, | ||
| "Number of Lines":6688, | ||
| "Solar Elevation":60.21, | ||
| "File Size (Bytes)":7475366912, | ||
| "Number of Samples":1335, | ||
| "Max Scene Elevation":4097.59, | ||
| "Min Scene Elevation":3163.91, | ||
| "Mean Scene Elevation":3680.71, | ||
| "Gzip File Size (Bytes)":2673260903 | ||
| } | ||
| } | ||
| ] | ||
|} | ||
|""".stripMargin).valueOr(throw _)), | ||
StatusCode.Ok, | ||
"" | ||
) | ||
) | ||
Response | ||
.ok(arbItemCollectionShort.arbitrary.sample.asJson.asRight) | ||
.asRight | ||
} | ||
.whenRequestMatches(_.uri.path == Seq("collections", "collection_id", "items", "item_id")) | ||
.thenRespondF { _ => | ||
Response | ||
.ok(arbItemShort.arbitrary.sample.asRight) | ||
.asRight | ||
} | ||
|
||
describe("StacClientSpec") { | ||
it("SttpBackendStub collections") { | ||
it("search") { | ||
SttpStacClient(backend, uri"http://localhost:9090") | ||
.search() | ||
.valueOr(throw _) | ||
.size should be > 0 | ||
} | ||
|
||
it("collections") { | ||
SttpStacClient(backend, uri"http://localhost:9090").collections | ||
.valueOr(throw _) | ||
.map(_.id) shouldBe "aviris_2006" :: Nil | ||
.size should be > 0 | ||
} | ||
|
||
it("items") { | ||
SttpStacClient(backend, uri"http://localhost:9090") | ||
.items(NonEmptyString.unsafeFrom("collection_id")) | ||
.valueOr(throw _) | ||
.size should be > 0 | ||
} | ||
|
||
it("SttpBackendStub items") { | ||
it("item") { | ||
SttpStacClient(backend, uri"http://localhost:9090") | ||
.items(NonEmptyString.unsafeFrom("aviris_2006")) | ||
.item(NonEmptyString.unsafeFrom("collection_id"), NonEmptyString.unsafeFrom("item_id")) | ||
.valueOr(throw _) | ||
.map(_.id) shouldBe "aviris_f060426t01p00r03_sc01" :: Nil | ||
.size should be > 0 | ||
} | ||
} | ||
} |
Oops, something went wrong.