forked from ravendb/ravendb-go-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathravendb_8328_test.go
133 lines (102 loc) · 3.47 KB
/
ravendb_8328_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
package tests
import (
"reflect"
"testing"
ravendb "github.com/ravendb/ravendb-go-client"
"github.com/stretchr/testify/assert"
)
// Note: renamed to Item2 to avoid conflicts
type Item2 struct {
ID string
Name string `json:"name"`
Latitude float64 `json:"latitude"`
Longitude float64 `json:"longitude"`
Latitude2 float64 `json:"latitude2"`
Longitude2 float64 `json:"longitude2"`
ShapeWkt string `json:"shapeWkt"`
}
func ravenDB8328_spatialOnAutoIndex(t *testing.T, driver *RavenTestDriver) {
var err error
store := driver.getDocumentStoreMust(t)
defer store.Close()
{
session := openSessionMust(t, store)
item := &Item2{
Latitude: 10,
Longitude: 20,
Latitude2: 10,
Longitude2: 20,
ShapeWkt: "POINT(20 10)",
Name: "Name1",
}
err = session.Store(item)
assert.NoError(t, err)
err = session.SaveChanges()
assert.NoError(t, err)
session.Close()
}
{
session := openSessionMust(t, store)
clazz := reflect.TypeOf(&Item2{})
q := session.QueryCollectionForType(clazz)
fieldName := ravendb.NewPointField("latitude", "longitude")
clause := func(f *ravendb.SpatialCriteriaFactory) ravendb.SpatialCriteria {
return f.WithinRadius(10, 10, 20)
}
q = q.Spatial2(fieldName, clause)
iq, err := q.GetIndexQuery()
assert.NoError(t, err)
assert.Equal(t, iq.GetQuery(), "from Item2s where spatial.within(spatial.point(latitude, longitude), spatial.circle($p0, $p1, $p2))")
q = session.QueryCollectionForType(clazz)
fieldName2 := ravendb.NewWktField("shapeWkt")
q = q.Spatial2(fieldName2, clause)
iq, err = q.GetIndexQuery()
assert.NoError(t, err)
assert.Equal(t, iq.GetQuery(), "from Item2s where spatial.within(spatial.wkt(shapeWkt), spatial.circle($p0, $p1, $p2))")
session.Close()
}
{
session := openSessionMust(t, store)
var statsRef *ravendb.QueryStatistics
var results []*Item2
q := session.QueryCollectionForType(reflect.TypeOf(&Item2{}))
q = q.Statistics(&statsRef)
fieldName := ravendb.NewPointField("latitude", "longitude")
clause := func(f *ravendb.SpatialCriteriaFactory) ravendb.SpatialCriteria {
return f.WithinRadius(10, 10, 20)
}
q = q.Spatial2(fieldName, clause)
err = q.GetResults(&results)
assert.NoError(t, err)
assert.Equal(t, len(results), 1)
assert.Equal(t, statsRef.IndexName, "Auto/Item2s/BySpatial.point(latitude|longitude)")
session.Close()
statsRef = nil
results = nil
q = session.QueryCollectionForType(reflect.TypeOf(&Item2{}))
q = q.Statistics(&statsRef)
fieldName = ravendb.NewPointField("latitude2", "longitude2")
q = q.Spatial2(fieldName, clause)
err = q.GetResults(&results)
assert.NoError(t, err)
assert.Equal(t, len(results), 1)
assert.Equal(t, statsRef.IndexName, "Auto/Item2s/BySpatial.point(latitude|longitude)AndSpatial.point(latitude2|longitude2)")
statsRef = nil
results = nil
q = session.QueryCollectionForType(reflect.TypeOf(&Item2{}))
q = q.Statistics(&statsRef)
fieldName2 := ravendb.NewWktField("shapeWkt")
q = q.Spatial2(fieldName2, clause)
err = q.GetResults(&results)
assert.NoError(t, err)
assert.Equal(t, len(results), 1)
assert.Equal(t, statsRef.IndexName, "Auto/Item2s/BySpatial.point(latitude|longitude)AndSpatial.point(latitude2|longitude2)AndSpatial.wkt(shapeWkt)")
}
}
func TestRavenDB8328(t *testing.T) {
driver := createTestDriver(t)
destroy := func() { destroyDriver(t, driver) }
defer recoverTest(t, destroy)
// matches order of Java tests
ravenDB8328_spatialOnAutoIndex(t, driver)
}