-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatastream_test.go
136 lines (112 loc) · 3.56 KB
/
datastream_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
129
130
131
132
133
134
135
136
package core
import (
"encoding/json"
"github.com/stretchr/testify/assert"
"testing"
)
func TestSetLinksReturnsVariousLinks(t *testing.T) {
// arrange
datastream := &Datastream{}
datastream.ID = "0"
// todo: what happens if there is no ID?
// act
datastream.SetAllLinks("http://www.nu.nl")
propertynames := datastream.GetPropertyNames()
supportedencoding := datastream.GetSupportedEncoding()
// assert
assert.NotNil(t, datastream.NavSelf, "NavSelf should be filled in")
assert.NotNil(t, datastream.NavThing, "NavThing should be filled in")
assert.NotNil(t, datastream.NavSensor, "NavSensor should be filled in")
assert.NotNil(t, datastream.NavObservations, "NavObservations should be filled in")
assert.NotNil(t, datastream.NavObservedProperty, "NavObservedProperty should be filled in")
assert.True(t, len(propertynames) > 0)
assert.True(t, len(supportedencoding) == 0)
}
func TestSetLinksAdvanced(t *testing.T) {
// arrange
thing := &Thing{}
sensor := &Sensor{}
datastream := &Datastream{}
observedproperty := &ObservedProperty{}
obs1 := &Observation{}
obs2 := &Observation{}
obs := []*Observation{obs1, obs2}
datastream.Observations = obs
datastream.ID = "0"
datastream.Thing = thing
datastream.Sensor = sensor
datastream.ObservedProperty = observedproperty
// act
datastream.SetAllLinks("http://www.nu.nl")
// assert
assert.NotNil(t, datastream.NavSelf, "NavSelf should be filled in")
assert.NotNil(t, datastream.NavThing, "NavThing should be filled in")
assert.NotNil(t, datastream.NavSensor, "NavSensor should be filled in")
assert.NotNil(t, datastream.NavObservations, "NavObservations should be filled in")
assert.NotNil(t, datastream.NavObservedProperty, "NavObservedProperty should be filled in")
}
func TestParseEntity(t *testing.T) {
// arrange
datastream := &Datastream{}
datastream.ID = "0"
dsjson, _ := json.Marshal(datastream)
// act
datastream.ParseEntity(dsjson)
// assert
assert.True(t, datastream.ID == "0")
}
func TestParseEntityFails(t *testing.T) {
// arrange
dsjson, _ := json.Marshal("hoho")
// act
datastream := &Datastream{}
err := datastream.ParseEntity(dsjson)
// assert
assert.True(t, err != nil)
}
func TestGetEntityType(t *testing.T) {
// arrange
datastream := &Datastream{}
// act
entityType := datastream.GetEntityType()
// assert
assert.Equal(t, EntityTypeDatastream, entityType, "GetEntityType should be Datastream")
}
func TestContainsMandatoryParametersFails(t *testing.T) {
// arrange
datastream := &Datastream{}
// act
contains, _ := datastream.ContainsMandatoryParams()
// assert
assert.False(t, contains, "Datastream is expected not to have mandatory parameters")
}
func TestContainsMandatoryParametersSucceeds(t *testing.T) {
// arrange
datastream := &Datastream{}
datastream.Name = "name"
datastream.Description = "desc"
unitofmeasurement := map[string]interface{}{"definition": "http://www.qudt.org/qudt/owl/1.0.0/unit/Instances.html/Lumen", "name": "Centigrade", "symbol": "C"}
datastream.UnitOfMeasurement = unitofmeasurement
datastream.ObservationType = "OMCategoryUnknown"
thing := &Thing{}
thing.Name = "name"
thing.Description = "desc"
datastream.Thing = thing
sensor := &Sensor{
Name: "test",
Description: "test",
EncodingType: "test",
Metadata: "test",
}
datastream.Sensor = sensor
op := &ObservedProperty{
Name: "test",
Definition: "test",
Description: "test",
}
datastream.ObservedProperty = op
// act
contains, _ := datastream.ContainsMandatoryParams()
// assert
assert.True(t, contains, "Datastream is expected to have mandatory parameters")
}