-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlocation_test.go
115 lines (93 loc) · 3.37 KB
/
location_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
package core
import (
"fmt"
"testing"
"github.com/stretchr/testify/assert"
)
var jsonLocation = `{
"name": "somewhere",
"description": "my backyard",
"encodingType": "application/vnd.geo+json",
"location": {
"type": "Point",
"coordinates": [-117.123,
54.123]
}
}`
var jsonLocationError = `{
"description": "my backyard",
"encodingType": "application/vnd.geo+json",
"location": 10
}`
func TestMissingMandatoryParametersLocation(t *testing.T) {
//arrange
location := &Location{}
//act
_, err := location.ContainsMandatoryParams()
//assert
assert.NotNil(t, err, "Location mandatory param description not filled in should have returned error")
if len(err) > 0 {
assert.Contains(t, fmt.Sprintf("%v", err[0]), "name")
}
}
func TestMandatoryParametersExistLocation(t *testing.T) {
//arrange
location := &Location{
Name: "test",
Description: "test",
EncodingType: "test",
Location: map[string]interface{}{"test": "test"},
}
//act
_, err := location.ContainsMandatoryParams()
//assert
assert.Nil(t, err, "All mandatory params are filled in shoud not have returned an error")
}
func TestParseEntityResultOkLocation(t *testing.T) {
//arrange
location := &Location{}
//act
err := location.ParseEntity([]byte(jsonLocation))
//assert
assert.Equal(t, err, nil, "Unable to parse json into Location")
}
func TestParseEntityResultNotOkLocation(t *testing.T) {
//arrange
location := &Location{}
//act
err := location.ParseEntity([]byte(jsonLocationError))
//assert
assert.NotEqual(t, err, nil, "Location parse from json should have failed")
}
func TestSetLinksLocation(t *testing.T) {
//arrange
location := &Location{}
location.ID = id
//act
location.SetAllLinks(externalURL)
propertynames := location.GetPropertyNames()
//assert
assert.True(t, len(propertynames) > 0)
assert.Equal(t, location.NavSelf, fmt.Sprintf("%s/v1.0/%s(%s)", externalURL, EntityLinkLocations.ToString(), id), "Location navself incorrect")
assert.Equal(t, location.NavThings, fmt.Sprintf("%s/v1.0/%s(%s)/%s", externalURL, EntityLinkLocations.ToString(), id, EntityLinkThings.ToString()), "Location NavThings incorrect")
assert.Equal(t, location.NavHistoricalLocations, fmt.Sprintf("%s/v1.0/%s(%s)/%s", externalURL, EntityLinkLocations.ToString(), id, EntityLinkHistoricalLocations.ToString()), "Location NavHistoricalLocations incorrect")
}
func TestSetLinksLocationExpanded(t *testing.T) {
//arrange
location := &Location{}
location.ID = id
thing := &Thing{}
thing.ID = 66
location.Things = []*Thing{thing}
historicallocation := &HistoricalLocation{}
historicallocation.ID = 77
location.HistoricalLocations = []*HistoricalLocation{historicallocation}
//act
location.SetAllLinks(externalURL)
propertynames := location.GetPropertyNames()
//assert
assert.True(t, len(propertynames) > 0)
assert.Equal(t, location.NavSelf, fmt.Sprintf("%s/v1.0/%s(%s)", externalURL, EntityLinkLocations.ToString(), id), "Location navself incorrect")
//assert.Equal(t, location.NavThings, fmt.Sprintf("%s/v1.0/%s(%s)/%s", externalURL, EntityLinkLocations.ToString(), id, EntityLinkThings.ToString()), "Location NavThings incorrect")
//assert.Equal(t, location.NavHistoricalLocations, fmt.Sprintf("%s/v1.0/%s(%s)/%s", externalURL, EntityLinkLocations.ToString(), id, EntityLinkHistoricalLocations.ToString()), "Location NavHistoricalLocations incorrect")
}