-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalidation_test.go
249 lines (188 loc) · 8 KB
/
validation_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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
package gossamer
import (
"github.com/stretchr/testify/assert"
"testing"
"time"
)
func TestValidateMandatoryPropertiesForThing(t *testing.T) {
var err error
thingEntity := NewThingEntity()
err = ValidateMandatoryProperties(thingEntity)
assert.NotNil(t, err)
assert.Equal(t, "Missing mandatory property for Thing entity: 'description'", err.Error())
thingEntity.Description = "XXXXXX"
err = ValidateMandatoryProperties(thingEntity)
assert.Nil(t, err)
}
func TestValidateMandatoryPropertiesForLocation(t *testing.T) {
var err error
locationEntity := NewLocationEntity()
err = ValidateMandatoryProperties(locationEntity)
assert.NotNil(t, err)
assert.Equal(t, "Missing mandatory property for Location entity: 'description'", err.Error())
locationEntity.Description = "XXXXXXX"
err = ValidateMandatoryProperties(locationEntity)
assert.NotNil(t, err)
assert.Equal(t, "Missing mandatory property for Location entity: 'encodingType'", err.Error())
locationEntity.EncodingType = "XXXXXXX"
err = ValidateMandatoryProperties(locationEntity)
assert.NotNil(t, err)
assert.Equal(t, "Missing mandatory property for Location entity: 'location'", err.Error())
locationEntity.Location = "XXXXXXX"
err = ValidateMandatoryProperties(locationEntity)
assert.Nil(t, err)
}
func TestValidateMandatoryPropertiesForHistoricalLocation(t *testing.T) {
var err error
historicalLocation := NewHistoricalLocationEntity()
err = ValidateMandatoryProperties(historicalLocation)
assert.NotNil(t, err)
assert.Equal(t, "Missing mandatory property for HistoricalLocation entity: 'time'", err.Error())
historicalLocation.Time = NewTimeInstant(time.Now())
err = ValidateMandatoryProperties(historicalLocation)
assert.Nil(t, err)
}
func TestValidateMandatoryPropertiesForDatastream(t *testing.T) {
var err error
datastreamEntity := NewDatastreamEntity()
err = ValidateMandatoryProperties(datastreamEntity)
assert.NotNil(t, err)
assert.Equal(t, "Missing mandatory property for Datastream entity: 'description'", err.Error())
datastreamEntity.Description = "XXXXXXX"
err = ValidateMandatoryProperties(datastreamEntity)
assert.NotNil(t, err)
assert.Equal(t, "Missing mandatory property for Datastream entity: 'unitOfMeasurement'", err.Error())
datastreamEntity.UnitOfMeasurement = "XXXXXXX"
err = ValidateMandatoryProperties(datastreamEntity)
assert.NotNil(t, err)
assert.Equal(t, "Missing mandatory property for Datastream entity: 'observationType'", err.Error())
datastreamEntity.ObservationType = "XXXXXXX"
err = ValidateMandatoryProperties(datastreamEntity)
assert.Nil(t, err)
}
func TestValidateMandatoryPropertiesForSensor(t *testing.T) {
var err error
sensorEntity := NewSensorEntity()
err = ValidateMandatoryProperties(sensorEntity)
assert.NotNil(t, err)
assert.Equal(t, "Missing mandatory property for Sensor entity: 'description'", err.Error())
sensorEntity.Description = "XXXXXXX"
err = ValidateMandatoryProperties(sensorEntity)
assert.NotNil(t, err)
assert.Equal(t, "Missing mandatory property for Sensor entity: 'encodingType'", err.Error())
sensorEntity.EncodingType = "XXXXXXX"
err = ValidateMandatoryProperties(sensorEntity)
assert.Equal(t, "Missing mandatory property for Sensor entity: 'metadata'", err.Error())
sensorEntity.Metadata = "XXXXXXX"
err = ValidateMandatoryProperties(sensorEntity)
assert.Nil(t, err)
}
func TestValidateMandatoryPropertiesForObservedProperty(t *testing.T) {
var err error
observedPropertyEntity := NewObservedPropertyEntity()
err = ValidateMandatoryProperties(observedPropertyEntity)
assert.NotNil(t, err)
assert.Equal(t, "Missing mandatory property for ObservedProperty entity: 'name'", err.Error())
observedPropertyEntity.Name = "XXXXXXX"
err = ValidateMandatoryProperties(observedPropertyEntity)
assert.NotNil(t, err)
assert.Equal(t, "Missing mandatory property for ObservedProperty entity: 'definition'", err.Error())
observedPropertyEntity.Definition = "XXXXXXX"
err = ValidateMandatoryProperties(observedPropertyEntity)
assert.NotNil(t, err)
assert.Equal(t, "Missing mandatory property for ObservedProperty entity: 'description'", err.Error())
observedPropertyEntity.Description = "XXXXXXX"
err = ValidateMandatoryProperties(observedPropertyEntity)
assert.Nil(t, err)
}
func TestValidateMandatoryPropertiesForObservation(t *testing.T) {
var err error
observationEntity := NewObservationEntity()
err = ValidateMandatoryProperties(observationEntity)
assert.NotNil(t, err)
assert.Equal(t, "Missing mandatory property for Observation entity: 'phenomenonTime'", err.Error())
observationEntity.PhenomenonTime = NewTimePeriod(time.Now(), time.Now())
err = ValidateMandatoryProperties(observationEntity)
assert.NotNil(t, err)
assert.Equal(t, "Missing mandatory property for Observation entity: 'resultTime'", err.Error())
ti := TimeInstant(time.Now())
observationEntity.ResultTime = &ti
err = ValidateMandatoryProperties(observationEntity)
assert.NotNil(t, err)
assert.Equal(t, "Missing mandatory property for Observation entity: 'result'", err.Error())
observationEntity.Result = "XXXXXXX"
err = ValidateMandatoryProperties(observationEntity)
assert.Nil(t, err)
}
func TestValidateMandatoryPropertiesForFeatureOfInterest(t *testing.T) {
var err error
featureOfInterestEntity := NewFeatureOfInterestEntity()
err = ValidateMandatoryProperties(featureOfInterestEntity)
assert.NotNil(t, err)
assert.Equal(t, "Missing mandatory property for FeaturesOfInterest entity: 'description'", err.Error())
featureOfInterestEntity.Description = "XXXXXXX"
err = ValidateMandatoryProperties(featureOfInterestEntity)
assert.NotNil(t, err)
assert.Equal(t, "Missing mandatory property for FeaturesOfInterest entity: 'encodingType'", err.Error())
featureOfInterestEntity.EncodingType = "XXXXXXX"
err = ValidateMandatoryProperties(featureOfInterestEntity)
assert.NotNil(t, err)
assert.Equal(t, "Missing mandatory property for FeaturesOfInterest entity: 'feature'", err.Error())
featureOfInterestEntity.Feature = "XXXXXXX"
err = ValidateMandatoryProperties(featureOfInterestEntity)
assert.Nil(t, err)
}
func TestValidateIntegrityConstraintsForThings(t *testing.T) {
var err error
thingEntity := NewThingEntity()
err = ValidateIntegrityConstraints(thingEntity)
assert.Nil(t, err)
}
func TestValidateIntegrityConstraintsForLocations(t *testing.T) {
var err error
locationEntity := NewLocationEntity()
err = ValidateIntegrityConstraints(locationEntity)
assert.Nil(t, err)
}
func TestValidateIntegrityConstraintsForDatastreams(t *testing.T) {
var err error
var datastream *DatastreamEntity
datastream = NewDatastreamEntity()
err = ValidateIntegrityConstraints(datastream)
assert.NotNil(t, err)
assert.Equal(t, "Missing constrains for Datastream Entity: 'Thing'", err.Error())
datastream.IdThing = "12345"
err = ValidateIntegrityConstraints(datastream)
assert.Equal(t, "Missing constrains for Datastream Entity: 'Sensor'", err.Error())
datastream.IdSensor = "12345"
err = ValidateIntegrityConstraints(datastream)
assert.Equal(t, "Missing constrains for Datastream Entity: 'ObservedProperty'", err.Error())
datastream.IdObservedProperty = "12345"
err = ValidateIntegrityConstraints(datastream)
assert.Nil(t, err)
}
func TestValidateIntegrityConstraintsForSensors(t *testing.T) {
var err error
sensorEntity := NewSensorEntity()
err = ValidateIntegrityConstraints(sensorEntity)
assert.Nil(t, err)
}
func TestValidateIntegrityConstraintsForObservedProperties(t *testing.T) {
var err error
observedProperty := NewObservedPropertyEntity()
err = ValidateIntegrityConstraints(observedProperty)
assert.Nil(t, err)
}
func TestValidateIntegrityConstraintsForObservations(t *testing.T) {
var err error
observation := NewObservationEntity()
err = ValidateIntegrityConstraints(observation)
assert.NotNil(t, err)
assert.Equal(t, "Missing constrains for Observation Entity: 'Datastream'", err.Error())
}
func TestValidateIntegrityConstraintsForFeaturesOfInterest(t *testing.T) {
var err error
featuresOfInterest := NewFeatureOfInterestEntity()
err = ValidateIntegrityConstraints(featuresOfInterest)
assert.Nil(t, err)
}