-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththing_test.go
128 lines (100 loc) · 3.7 KB
/
thing_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
124
125
126
127
128
package core
import (
"fmt"
"github.com/stretchr/testify/assert"
"testing"
)
var jsonThing = `{
"name": "thingy",
"description": "camping lantern",
"properties": {
"property1": "it’s waterproof"
}
}`
var jsonThingError = `{
"desc": "camping lantern",
}`
func TestMissingMandatoryParametersThing(t *testing.T) {
//arrange
thing := &Thing{}
//act
_, err := thing.ContainsMandatoryParams()
//assert
assert.NotNil(t, err, "Thing mandatory param description not filled in should have returned error")
if len(err) > 0 {
assert.Contains(t, fmt.Sprintf("%v", err[0]), "name")
}
}
func TestThingGetPropertyNames(t *testing.T) {
// arrange
thing := &Thing{}
// act
propertynames := thing.GetPropertyNames()
// assert
assert.True(t, propertynames[0] == "id")
}
func TestMandatoryParametersExistThing(t *testing.T) {
//arrange
thing := &Thing{Description: "test", Name: "thingy"}
//act
_, err := thing.ContainsMandatoryParams()
//assert
assert.Nil(t, err, "All mandatory params are filled in should not have return an error")
}
func TestParseEntityResultOkThing(t *testing.T) {
//arrange
thing := &Thing{}
//act
err := thing.ParseEntity([]byte(jsonThing))
//assert
assert.Equal(t, err, nil, "Unable to parse json into thing")
}
func TestParseEntityResultNotOkThing(t *testing.T) {
//arrange
thing := &Thing{}
//act
err := thing.ParseEntity([]byte(jsonThingError))
//assert
assert.NotEqual(t, err, nil, "Thing parse from json should have failed")
}
func TestSetLinksThing(t *testing.T) {
//arrange
thing := &Thing{}
thing.ID = id
ds1 := &Datastream{}
ds2 := &Datastream{}
datastreams := []*Datastream{ds1, ds2}
thing.Datastreams = datastreams
obs1 := &Location{}
obs2 := &Location{}
locations := []*Location{obs1, obs2}
thing.Locations = locations
historicallocation := &HistoricalLocation{}
historicallocation.ID = 77
thing.HistoricalLocations = []*HistoricalLocation{historicallocation}
//act
thing.SetAllLinks(externalURL)
//assert
assert.Equal(t, thing.NavSelf, fmt.Sprintf("%s/v1.0/%s(%s)", externalURL, EntityLinkThings.ToString(), id), "Thing navself incorrect")
//assert.Equal(t, thing.NavDatastreams, fmt.Sprintf("%s/v1.0/%s(%s)/%s", externalURL, EntityLinkThings.ToString(), id, EntityLinkDatastreams.ToString()), "Thing NavDatastreams incorrect")
//assert.Equal(t, thing.NavLocations, fmt.Sprintf("%s/v1.0/%s(%s)/%s", externalURL, EntityLinkThings.ToString(), id, EntityLinkLocations.ToString()), "Thing NavLocations incorrect")
//assert.Equal(t, thing.NavHistoricalLocations, fmt.Sprintf("%s/v1.0/%s(%s)/%s", externalURL, EntityLinkThings.ToString(), id, EntityLinkHistoricalLocations.ToString()), "Thing NavHistoricalLocations incorrect")
}
func TestSetLinksThingExpanded(t *testing.T) {
//arrange
thing := &Thing{}
thing.ID = id
//act
thing.SetAllLinks(externalURL)
//assert
assert.Equal(t, thing.NavSelf, fmt.Sprintf("%s/v1.0/%s(%s)", externalURL, EntityLinkThings.ToString(), id), "Thing navself incorrect")
assert.Equal(t, thing.NavDatastreams, fmt.Sprintf("%s/v1.0/%s(%s)/%s", externalURL, EntityLinkThings.ToString(), id, EntityLinkDatastreams.ToString()), "Thing NavDatastreams incorrect")
assert.Equal(t, thing.NavLocations, fmt.Sprintf("%s/v1.0/%s(%s)/%s", externalURL, EntityLinkThings.ToString(), id, EntityLinkLocations.ToString()), "Thing NavLocations incorrect")
assert.Equal(t, thing.NavHistoricalLocations, fmt.Sprintf("%s/v1.0/%s(%s)/%s", externalURL, EntityLinkThings.ToString(), id, EntityLinkHistoricalLocations.ToString()), "Thing NavHistoricalLocations incorrect")
}
func TestGetSupportedEncodingThing(t *testing.T) {
//arrange
thing := &Thing{}
//assert
assert.Equal(t, 0, len(thing.GetSupportedEncoding()), "Thing should not support any encoding")
}