-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathobservedproperty_test.go
107 lines (83 loc) · 2.59 KB
/
observedproperty_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
package core
import (
"fmt"
"github.com/stretchr/testify/assert"
"testing"
)
var jsonObservedProperty = `{
"name": "ObservedPropertyUp Tempomatic 2000",
"description": "http://schema.org/description",
"definition": "Calibration date: Jan 1, 2014"
}`
var jsonObservedPropertyError = `{
"name": "ObservedPropertyUp Tempomatic 2000",
}`
func TestMissingMandatoryParametersObservedProperty(t *testing.T) {
//arrange
op := &ObservedProperty{}
//act
_, err := op.ContainsMandatoryParams()
//assert
assert.NotNil(t, err, "ObservedProperty mandatory param description not filled in should have returned error")
if len(err) > 0 {
assert.Contains(t, fmt.Sprintf("%v", err[0]), "name")
}
}
func TestObservedPropertyGetPropertyNames(t *testing.T) {
// arrange
op := &ObservedProperty{}
// act
propertynames := op.GetPropertyNames()
// assert
assert.True(t, propertynames[0] == "id")
}
func TestMandatoryParametersExistObservedProperty(t *testing.T) {
//arrange
op := &ObservedProperty{
Name: "test",
Definition: "test",
Description: "test",
}
//act
_, err := op.ContainsMandatoryParams()
//assert
assert.Nil(t, err, "All mandatory params are filled in should not have returned an error")
}
func TestParseEntityResultOkObservedProperty(t *testing.T) {
//arrange
op := &ObservedProperty{}
//act
err := op.ParseEntity([]byte(jsonObservedProperty))
//assert
assert.Equal(t, err, nil, "Unable to parse json into ObservedProperty")
}
func TestParseEntityResultNotOkObservedProperty(t *testing.T) {
//arrange
op := &ObservedProperty{}
//act
err := op.ParseEntity([]byte(jsonObservedPropertyError))
//assert
assert.NotEqual(t, err, nil, "ObservedProperty parse from json should have failed")
}
func TestSetLinksSObservedProperty(t *testing.T) {
//arrange
op := &ObservedProperty{}
op.ID = id
ds1 := &Datastream{}
ds2 := &Datastream{}
datastreams := []*Datastream{ds1, ds2}
op.Datastreams = datastreams
//act
op.SetAllLinks(externalURL)
//assert
assert.Equal(t, op.NavSelf, fmt.Sprintf("%s/v1.0/%s(%s)", externalURL, EntityLinkObservedProperties.ToString(), id), "ObservedProperty navself incorrect")
// assert.Equal(t, op.NavDatastreams, fmt.Sprintf("%s/v1.0/%s(%s)/%s", externalURL, EntityLinkObservedProperties.ToString(), id, EntityLinkDatastreams.ToString()), "ObservedProperty NavDatastreams incorrect")
}
func TestGetSupportedEncodingObservedProperty(t *testing.T) {
//arrange
op := &ObservedProperty{}
// act
supportedEncoding := op.GetSupportedEncoding()
//assert
assert.Equal(t, 0, len(supportedEncoding), "ObservedProperty should not support any encoding")
}