Ejemplo n.º 1
0
//## Single Region
//
// **GET /region/(regionID)**
//
// Get a single region.
//
//### Example request:
//
// `/region/wellington`
//
func TestRegionV1(t *testing.T) {
	setup()
	defer teardown()

	c := webtest.Content{
		Accept: web.V1GeoJSON,
		URI:    "/region/wellington",
	}

	b, err := c.Get(ts)
	if err != nil {
		t.Fatal(err)
	}

	var f RegionFeatures

	err = json.Unmarshal(b, &f)
	if err != nil {
		log.Fatal(err)
	}

	if !(len(f.Features) == 1) {
		t.Error("Found wrong number of features")
	}

	if f.Features[0].Properties.RegionID != "wellington" {
		t.Errorf("wrong region: %s", f.Features[0].Properties.RegionID)
	}
}
Ejemplo n.º 2
0
//## Quake Regions
//
// **GET /region?type=quake**
//
// Get all quake regions.
//
//### Example request:
//
// `/region?type=quake`
//
func TestRegionsV1(t *testing.T) {
	setup()
	defer teardown()

	c := webtest.Content{
		Accept: web.V1GeoJSON,
		URI:    "/region?type=quake",
	}

	b, err := c.Get(ts)
	if err != nil {
		t.Fatal(err)
	}

	var f RegionFeatures

	err = json.Unmarshal(b, &f)
	if err != nil {
		log.Fatal(err)
	}

	if !(len(f.Features) >= 1) {
		t.Error("Found wrong number of features")
	}

	for _, feat := range f.Features {
		var g = feat.Properties.Group
		if !(g == "region" || g == "north" || g == "south") {
			t.Error("Found non quake region")
		}
	}
}
Ejemplo n.º 3
0
//## Quakes Possibly Felt in a Region
//
// **GET /quake?regionID=(region)&regionIntensity=(intensity)&number=(n)&quality=(quality)**
//
// Get quake information from the last 365 days.
// If no quakes are found for the query parameters then a null features array is returned.
//
//### Parameters
//
// * `regionID` - a valid quake region identifier e.g., `newzealand`.
// * `regionIntensity` - the minimum intensity in the region e.g., `weak`.  Must be one of `unnoticeable`, `weak`, `light`, `moderate`, `strong`, `severe`.
// * `number` - the maximum number of quakes to return.  Must be one of  `3`, `30`, `100`, `500`, `1000`, `1500`.
// * `quality` - a comma separated list of quality values to be included in the response; `best`, `caution`, `deleted`, `good`.
//
// *The `number` of quakes that can be returned is restricted to a range of options to improve caching.*
//
//### Example request:
//
// `/quake?regionID=newzealand&regionIntensity=weak&number=30`
//
func TestQuakesRegionV1(t *testing.T) {
	setup()
	defer teardown()

	c := webtest.Content{
		Accept: web.V1GeoJSON,
		URI:    "/quake?regionID=newzealand&regionIntensity=severe&number=30&quality=best,caution,good",
	}

	b, err := c.Get(ts)
	if err != nil {
		t.Fatal(err)
	}

	var f QuakeFeatures

	err = json.Unmarshal(b, &f)
	if err != nil {
		log.Fatal(err)
	}

	if len(f.Features) != 2 {
		t.Errorf("Found wrong number of features: %d", len(f.Features))
	}

	// Check that deleted quakes are included in the response.
	// This is a change from the existing GeoNet services.
	c = webtest.Content{
		Accept: web.V1GeoJSON,
		URI:    "/quake?regionID=newzealand&regionIntensity=unnoticeable&number=1000&quality=best,caution,good,deleted",
	}

	b, err = c.Get(ts)
	if err != nil {
		t.Fatal(err)
	}

	err = json.Unmarshal(b, &f)
	if err != nil {
		log.Fatal(err)
	}

	var count = 0
	for _, q := range f.Features {
		if q.Properties.Quality == "deleted" {
			count++
		}
	}
	if count == 0 {
		t.Error("found no deleted quakes in the JSON.")
	}
}
Ejemplo n.º 4
0
//## Single Quake
//
//  **GET /quake/(publicID)**
//
// Get information for a single quake.
//
//### Parameters
//
// * `publicID` - a valid quake ID e.g., `2014p715167`.
//
//### Example request:
//
// `/quake/2013p407387`
//
func TestQuakeV1(t *testing.T) {
	setup()
	defer teardown()

	c := webtest.Content{
		Accept: web.V1GeoJSON,
		URI:    "/quake/2013p407387",
	}

	b, err := c.Get(ts)
	if err != nil {
		t.Fatal(err)
	}

	var f QuakeFeatures
	err = json.Unmarshal(b, &f)
	if err != nil {
		log.Fatal(err)
	}

	if f.Features[0].Geometry.Type != "Point" {
		t.Error("wrong type")
	}

	if f.Features[0].Geometry.Coordinates[0] != 172.28223 {
		t.Error("wrong longitude")
	}

	if f.Features[0].Geometry.Coordinates[1] != -43.397461 {
		t.Error("wrong latitude")
	}

	if f.Features[0].Properties.Publicid != "2013p407387" {
		t.Error("incorrect publicid")
	}

	if f.Features[0].Properties.Time != "2013-05-30T15:15:37.812Z" {
		t.Error("incorrect time")
	}

	if f.Features[0].Properties.Modificationtime != "2013-06-13T23:47:04.344Z" {
		t.Error("incorrect updatetime")
	}

	if f.Features[0].Properties.Type != "earthquake" {
		t.Error("incorrect type")
	}

	if f.Features[0].Properties.Quality != "good" {
		t.Error("incorrect quality")
	}

	if f.Features[0].Properties.Intensity != "moderate" {
		t.Error("incorrect intensity")
	}

	if f.Features[0].Properties.Regionintensity != "moderate" {
		t.Error("incorrect region intensity")
	}

	if f.Features[0].Properties.Agency != "WEL(Avalon)" {
		t.Error("incorrect agency")
	}

	if f.Features[0].Properties.Locality != "15 km south-east of Oxford" {
		t.Error("incorrect locality")
	}

	if f.Features[0].Properties.Depth != 20.141276 {
		t.Error("incorrect depth")
	}

	if f.Features[0].Properties.Magnitude != 4.0252561 {
		t.Error("incorrect magnitude")
	}
}
Ejemplo n.º 5
0
//## Quakes in a Region
//
// **GET /quake?regionID=(region)&intensity=(intensity)&number=(n)&quality=(quality)**
//
// Get quake information from the last 365 days.
// If no quakes are found for the query parameters then a null features array is returned.
//
//### Parameters
//
// * `regionID` - a valid quake region identifier e.g., `newzealand`.
// * `intensity` - the minimum intensity at the epicenter e.g., `weak`.  Must be one of `unnoticeable`, `weak`, `light`, `moderate`, `strong`, `severe`.
// * `number` - the maximum number of quakes to return.  Must be one of `30`, `100`, `500`, `1000`, `1500`.
// * `quality` - a comma separated list of quality values to be included in the response; `best`, `caution`, `deleted`, `good`.
//
// *The `number` of quakes that can be returned is restricted to a range of options to improve caching.*
//
//### Example request:
//
// `/quake?regionID=newzealand&intensity=weak&number=30`
//
func TestQuakesV1(t *testing.T) {
	setup()
	defer teardown()

	c := webtest.Content{
		Accept: web.V1GeoJSON,
		URI:    "/quake?regionID=wellington&intensity=weak&number=30&quality=best,caution,good",
	}

	b, err := c.Get(ts)
	if err != nil {
		t.Fatal(err)
	}

	var f QuakeFeatures

	err = json.Unmarshal(b, &f)
	if err != nil {
		log.Fatal(err)
	}

	if len(f.Features) != 0 {
		t.Errorf("Found wrong number of features: %d", len(f.Features))
	}

	c = webtest.Content{
		Accept: web.V1GeoJSON,
		URI:    "/quake?regionID=wellington&regionIntensity=weak&number=30&quality=best,caution,good",
	}

	b, err = c.Get(ts)
	if err != nil {
		t.Fatal(err)
	}

	err = json.Unmarshal(b, &f)
	if err != nil {
		log.Fatal(err)
	}

	if len(f.Features) != 2 {
		t.Errorf("Found wrong number of features: %d", len(f.Features))
	}

	// There should be 7 quakes weak and above in the Canterbury region.
	c = webtest.Content{
		Accept: web.V1GeoJSON,
		URI:    "/quake?regionID=canterbury&intensity=weak&number=30&quality=best,caution,good",
	}

	b, err = c.Get(ts)
	if err != nil {
		t.Fatal(err)
	}

	err = json.Unmarshal(b, &f)
	if err != nil {
		log.Fatal(err)
	}

	if len(f.Features) != 7 {
		t.Errorf("Found wrong number of features: %d", len(f.Features))
	}
}