-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhistoricallocation_test.go
123 lines (95 loc) · 3.19 KB
/
historicallocation_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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
package core
import (
"testing"
"github.com/stretchr/testify/assert"
)
var historicalLocationJSON = `{
"@iot.id": 89,
"@iot.selfLink": "http://gost.geodan.nl/v1.0/HistoricalLocations(89)",
"time": "2017-05-04T14:22:04.646Z",
"[email protected]": "http://gost.geodan.nl/v1.0/HistoricalLocations(89)/Thing",
"[email protected]": "http://gost.geodan.nl/v1.0/HistoricalLocations(89)/Locations"
}`
func TestHistoricalLocationWithMandatoryParameters(t *testing.T) {
//arrange
historicalLocation := &HistoricalLocation{}
historicalLocation.Time = "testtime"
historicalLocation.Locations = []*Location{}
thing := Thing{}
thing.ID = 1
historicalLocation.Thing = &thing
location := &Location{}
location.ID = 1
historicalLocation.Locations = append(historicalLocation.Locations, location)
//act
res, err := historicalLocation.ContainsMandatoryParams()
//assert
assert.True(t, res, "HistoricalLocation result should be true")
assert.Nil(t, err, "HistoricalLocation mandatory param description not filled in should have returned error")
}
func TestHistoricalLocationWithoutMandatoryParameters(t *testing.T) {
//arrange
historicalLocation := &HistoricalLocation{}
//act
res, err := historicalLocation.ContainsMandatoryParams()
//assert
assert.False(t, res, "HistoricalLocation result should be false")
assert.NotNil(t, err, "HistoricalLocation mandatory param description not filled in should have returned error")
}
func TestGetHistoricalLocationsPropertyNames(t *testing.T) {
// arrange
historicalLocation := &HistoricalLocation{}
// act
props := historicalLocation.GetPropertyNames()
// assert
assert.True(t, len(props) > 0)
}
func TestSetAllLinks(t *testing.T) {
//arrange
historicalLocation := &HistoricalLocation{}
historicalLocation.Time = "testtime"
thing := Thing{}
thing.Description = "testdescription"
historicalLocation.Thing = &thing
obs1 := &Location{}
obs2 := &Location{}
locations := []*Location{obs1, obs2}
historicalLocation.Locations = locations
//act
historicalLocation.SetAllLinks("http://www.test.com")
//assert
assert.NotNil(t, historicalLocation.NavSelf)
assert.NotNil(t, historicalLocation.NavThing)
}
func TestParseHistoricalLocationShouldFail(t *testing.T) {
//arrange
historicalLocation := &HistoricalLocation{}
//act
err := historicalLocation.ParseEntity([]byte("hallo"))
//assert
assert.NotNil(t, err, "Historical parse from json should have failed")
}
func TestParseHistoricalLocationShouldSucceed(t *testing.T) {
//arrange
historicalLocation := &HistoricalLocation{}
//act
err := historicalLocation.ParseEntity([]byte(historicalLocationJSON))
//assert
assert.Equal(t, err, nil, "Historical parse from json should have succeeded")
}
func TestGetSupportedEncoding(t *testing.T) {
//arrange
historicalLocation := &HistoricalLocation{}
// act
enc := historicalLocation.GetSupportedEncoding()
// assert
assert.True(t, enc != nil)
}
func TestHistoricalLocationContainsMandatoryParameters(t *testing.T) {
// arrange
historicalLocation := &HistoricalLocation{}
// act
contains, _ := historicalLocation.ContainsMandatoryParams()
// assert
assert.False(t, contains, "HistoricalLocation is expected not to have mandatory parameters")
}