-
Notifications
You must be signed in to change notification settings - Fork 0
/
request_test.go
101 lines (89 loc) · 4.03 KB
/
request_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package gossamer
import (
"github.com/stretchr/testify/assert"
"net/url"
"testing"
)
func TestParseRequestUrl(t *testing.T) {
cases1 := []struct {
in string
}{
/*
EntityType
ID
Query Opt Values
expand
top
skip
count
filter
property
propertyValue
*/
{"http://example.org/v1.0/ObservedProperties"},
{"http://example.org/v1.0/Things(1)"},
{"http://example.org/v1.0/Things(1)/Locations"},
{"http://example.org/v1.0/Things?$expand=Datastreams"},
{"http://example.org/v1.0/Things?$top=5"},
{"http://example.org/v1.0/Things?$skip=5"},
{"http://example.org/v1.0/Things?$count=true"},
{"http://example.org/v1.0/Things?$filter=geo.distance(Locations/location,geography'POINT(-122, 43)') gt 1"},
{"http://example.org/v1.0/Things?$expand=Datastreams/Observations/FeatureOfInterest&$filter=Datastreams/Observations/FeatureOfInterest/id eq 'FOI_1' and Datastreams/Observations/resultTime ge 2010-06-01T00:00:00Z and Datastreams/Observations/resultTime le 2010-07-01T00:00:00Z"},
{"http://example.org/v1.0/Observations?$select=result,resultTime"},
{"http://example.org/v1.0/Observations?$orderby=result"},
{"http://example.org/v1.0/Observations?$expand=Datastream&$orderby=Datastreams/id desc, phenomenonTime"},
{"http://example.org/v1.0/Observations(1)/resultTime"},
{"http://example.org/v1.0/Observations(1)/resultTime/$value"},
{"http://example.org/v1.0/Datastreams(1)/Observations"},
{"http://example.org/v1.0/Datastreams(1)/Observations/$ref"},
{"http://example.org/v1.0/Datastreams(1)/Observations(1)"},
{"http://example.org/v1.0/Datastreams(1)/Observations(1)/resultTime"},
{"http://example.org/v1.0/Datastreams(1)/Observations(1)/FeatureOfInterest"},
{"http://example.org/v1.0/Datastreams(1)?$expand=Observations,ObservedProperty"},
{"http://example.org/v1.0/Datastreams(1)?$expand=Observations($filter=result eq 1)"},
{"http://example.org/v1.0/Datastreams(1)?$select=id,Observations&$expand=Observations/FeatureOfInterest"},
{"http://example.org/v1.0/Datastreams(1)?$expand=Observations($select=result)"},
{"http://example.org/v1.0/Observations?$top=5&$orderby=phenomenonTime desc"},
{"http://example.org/v1.0/Observations?$skip=2&$top=2&$orderby=resultTime"},
{"http://example.org/v1.0/Observations?$filter=result lt 10.00"},
{"http://example.org/v1.0/Observations?$filter=Datastream/id eq '1'"},
}
for _, c := range cases1 {
var err error
reqUrl, err := url.Parse(c.in)
assert.Nil(t, err)
assert.NotNil(t, reqUrl)
req, err := CreateIncomingRequest(reqUrl, HTTP)
assert.Nil(t, err, "Error occured parsing URL: "+c.in)
assert.NotNil(t, req)
}
var reqUrl *url.URL
var req Request
reqUrl, _ = url.Parse("http://example.org/v1.0/ObservedProperties")
req, _ = CreateIncomingRequest(reqUrl, HTTP)
assert.NotNil(t, req)
assert.NotNil(t, req.GetResourcePath())
assert.Equal(t, 1, len(req.GetResourcePath().All()))
assert.Equal(t, ENTITY_OBSERVEDPROPERTIES, req.GetResourcePath().First().GetEntity())
assert.Empty(t, req.GetResourcePath().First().GetId())
reqUrl, _ = url.Parse("http://example.org/v1.0/Things(1)")
req, _ = CreateIncomingRequest(reqUrl, HTTP)
assert.NotNil(t, req)
assert.NotNil(t, req.GetResourcePath())
assert.Equal(t, 1, len(req.GetResourcePath().All()))
assert.Equal(t, ENTITY_THINGS, req.GetResourcePath().First().GetEntity())
assert.Equal(t, "1", req.GetResourcePath().First().GetId())
reqUrl, _ = url.Parse("http://example.org/v1.0/Things?$expand=Datastreams")
req, _ = CreateIncomingRequest(reqUrl, HTTP)
assert.NotNil(t, req)
assert.NotNil(t, req.GetResourcePath())
assert.Equal(t, 1, len(req.GetResourcePath().All()))
assert.Equal(t, ENTITY_THINGS, req.GetResourcePath().First().GetEntity())
assert.Empty(t, req.GetResourcePath().First().GetId())
reqUrl, _ = url.Parse("http://example.org/v1.0/Things(1)/Observations")
req, _ = CreateIncomingRequest(reqUrl, HTTP)
assert.NotNil(t, req)
assert.NotNil(t, req.GetResourcePath())
assert.Equal(t, 2, len(req.GetResourcePath().All()))
assert.Equal(t, ENTITY_THINGS, req.GetResourcePath().First().GetEntity())
}