Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
Search
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
OSDU
OSDU Data Platform
System
Search
Commits
28355b28
Commit
28355b28
authored
2 years ago
by
Neelesh Thakur
Browse files
Options
Downloads
Patches
Plain Diff
add test
parent
1e766240
No related branches found
No related tags found
1 merge request
!474
optimize geo queries: remove redundant call
Pipeline
#175388
failed
2 years ago
Stage: review
Stage: build
Stage: containerize
Stage: scan
Stage: deploy
Stage: integration
Changes
1
Pipelines
3
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
provider/search-azure/src/test/java/org/opengroup/osdu/search/provider/azure/provider.impl/GeoQueryBuilderTest.java
+95
-3
95 additions, 3 deletions
...rch/provider/azure/provider.impl/GeoQueryBuilderTest.java
with
95 additions
and
3 deletions
provider/search-azure/src/test/java/org/opengroup/osdu/search/provider/azure/provider.impl/GeoQueryBuilderTest.java
+
95
−
3
View file @
28355b28
...
...
@@ -14,6 +14,8 @@
package
org.opengroup.osdu.search.provider.azure.provider.impl
;
import
org.elasticsearch.geometry.Circle
;
import
org.elasticsearch.geometry.Rectangle
;
import
org.elasticsearch.index.query.GeoShapeQueryBuilder
;
import
org.elasticsearch.index.query.QueryBuilder
;
import
org.junit.Test
;
...
...
@@ -28,19 +30,103 @@ import java.io.IOException;
import
java.util.ArrayList
;
import
java.util.List
;
import
static
org
.
junit
.
Assert
.
assertArrayEquals
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
@RunWith
(
MockitoJUnitRunner
.
class
)
public
class
GeoQueryBuilderTest
{
private
static
final
String
GEO_FIELD
=
"data.SpatialLocation.Wgs84Coordinates"
;
@InjectMocks
private
GeoQueryBuilder
sut
;
@Test
public
void
should_provide_valid_distanceQuery
()
throws
IOException
{
SpatialFilter
spatialFilter
=
new
SpatialFilter
();
spatialFilter
.
setField
(
GEO_FIELD
);
SpatialFilter
.
ByDistance
circl
=
new
SpatialFilter
.
ByDistance
();
Point
center
=
new
Point
(
1.02
,
-
8.61
);
circl
.
setDistance
(
1000
);
circl
.
setPoint
(
center
);
spatialFilter
.
setByDistance
(
circl
);
QueryBuilder
queryBuilder
=
this
.
sut
.
getGeoQuery
(
spatialFilter
);
assertNotNull
(
queryBuilder
);
GeoShapeQueryBuilder
shapeQueryBuilder
=
(
GeoShapeQueryBuilder
)
queryBuilder
;
assertEquals
(
GEO_FIELD
,
shapeQueryBuilder
.
fieldName
());
assertEquals
(
true
,
shapeQueryBuilder
.
ignoreUnmapped
());
assertTrue
(
shapeQueryBuilder
.
shape
()
instanceof
Circle
);
assertEquals
(
"WITHIN"
,
shapeQueryBuilder
.
relation
().
name
());
Circle
circle
=
(
Circle
)
shapeQueryBuilder
.
shape
();
assertEquals
(-
8.61
,
circle
.
getX
(),
0.000001
);
assertEquals
(
1.02
,
circle
.
getY
(),
0.000001
);
}
@Test
public
void
should_provide_valid_boundingBoxQuery
()
throws
IOException
{
SpatialFilter
spatialFilter
=
new
SpatialFilter
();
spatialFilter
.
setField
(
GEO_FIELD
);
SpatialFilter
.
ByBoundingBox
boundingBox
=
new
SpatialFilter
.
ByBoundingBox
();
Point
topLeft
=
new
Point
(
90
,
-
180
);
Point
bottomRight
=
new
Point
(-
90
,
180
);
boundingBox
.
setTopLeft
(
topLeft
);
boundingBox
.
setBottomRight
(
bottomRight
);
spatialFilter
.
setByBoundingBox
(
boundingBox
);
QueryBuilder
queryBuilder
=
this
.
sut
.
getGeoQuery
(
spatialFilter
);
assertNotNull
(
queryBuilder
);
GeoShapeQueryBuilder
shapeQueryBuilder
=
(
GeoShapeQueryBuilder
)
queryBuilder
;
assertEquals
(
GEO_FIELD
,
shapeQueryBuilder
.
fieldName
());
assertEquals
(
true
,
shapeQueryBuilder
.
ignoreUnmapped
());
assertTrue
(
shapeQueryBuilder
.
shape
()
instanceof
Rectangle
);
assertEquals
(
"WITHIN"
,
shapeQueryBuilder
.
relation
().
name
());
Rectangle
rectangle
=
(
Rectangle
)
shapeQueryBuilder
.
shape
();
assertEquals
(
90
,
rectangle
.
getMaxLat
(),
0.01
);
assertEquals
(
180
,
rectangle
.
getMaxLon
(),
0.01
);
assertEquals
(-
90
,
rectangle
.
getMinLat
(),
0.01
);
assertEquals
(-
180
,
rectangle
.
getMinLon
(),
0.01
);
}
@Test
public
void
should_provide_valid_polygonQuery
()
throws
IOException
{
SpatialFilter
spatialFilter
=
new
SpatialFilter
();
spatialFilter
.
setField
(
GEO_FIELD
);
SpatialFilter
.
ByGeoPolygon
geoPolygon
=
new
SpatialFilter
.
ByGeoPolygon
();
Point
point
=
new
Point
(
1.02
,
-
8.61
);
Point
point1
=
new
Point
(
1.02
,
-
2.48
);
Point
point2
=
new
Point
(
10.74
,
-
2.48
);
Point
point3
=
new
Point
(
10.74
,
-
8.61
);
Point
point4
=
new
Point
(
1.02
,
-
8.61
);
List
<
Point
>
points
=
new
ArrayList
<>();
points
.
add
(
point
);
points
.
add
(
point1
);
points
.
add
(
point2
);
points
.
add
(
point3
);
points
.
add
(
point4
);
geoPolygon
.
setPoints
(
points
);
spatialFilter
.
setByGeoPolygon
(
geoPolygon
);
QueryBuilder
queryBuilder
=
this
.
sut
.
getGeoQuery
(
spatialFilter
);
assertNotNull
(
queryBuilder
);
GeoShapeQueryBuilder
shapeQueryBuilder
=
(
GeoShapeQueryBuilder
)
queryBuilder
;
assertEquals
(
GEO_FIELD
,
shapeQueryBuilder
.
fieldName
());
assertEquals
(
true
,
shapeQueryBuilder
.
ignoreUnmapped
());
assertTrue
(
shapeQueryBuilder
.
shape
()
instanceof
org
.
elasticsearch
.
geometry
.
Polygon
);
assertEquals
(
"WITHIN"
,
shapeQueryBuilder
.
relation
().
name
());
org
.
elasticsearch
.
geometry
.
Polygon
expectedPolygon
=
(
org
.
elasticsearch
.
geometry
.
Polygon
)
shapeQueryBuilder
.
shape
();
assertArrayEquals
(
new
double
[]{
1.02
,
1.02
,
10.74
,
10.74
,
1.02
},
expectedPolygon
.
getPolygon
().
getLats
(),
0.01
);
assertArrayEquals
(
new
double
[]{-
8.61
,
-
2.48
,
-
2.48
,
-
8.61
,
-
8.61
},
expectedPolygon
.
getPolygon
().
getLons
(),
0.01
);
}
@Test
public
void
should_provide_valid_intersectionQuery
()
throws
IOException
{
SpatialFilter
spatialFilter
=
new
SpatialFilter
();
spatialFilter
.
setField
(
"data.Wgs84Coordinates"
);
spatialFilter
.
setField
(
GEO_FIELD
);
SpatialFilter
.
ByIntersection
byIntersection
=
new
SpatialFilter
.
ByIntersection
();
Polygon
polygon
=
new
Polygon
();
Point
point
=
new
Point
(
1.02
,
-
8.61
);
...
...
@@ -61,10 +147,16 @@ public class GeoQueryBuilderTest {
spatialFilter
.
setByIntersection
(
byIntersection
);
QueryBuilder
queryBuilder
=
this
.
sut
.
getGeoQuery
(
spatialFilter
);
assertNotNull
(
queryBuilder
);
assertNotNull
(
queryBuilder
);
GeoShapeQueryBuilder
shapeQueryBuilder
=
(
GeoShapeQueryBuilder
)
queryBuilder
;
assertEquals
(
"data.Wgs84Coordinates"
,
shapeQueryBuilder
.
fieldName
());
assertEquals
(
GEO_FIELD
,
shapeQueryBuilder
.
fieldName
());
assertEquals
(
true
,
shapeQueryBuilder
.
ignoreUnmapped
());
assertEquals
(
"INTERSECTS"
,
shapeQueryBuilder
.
relation
().
name
());
assertTrue
(
shapeQueryBuilder
.
shape
()
instanceof
org
.
elasticsearch
.
geometry
.
GeometryCollection
);
org
.
elasticsearch
.
geometry
.
GeometryCollection
geometryCollection
=
(
org
.
elasticsearch
.
geometry
.
GeometryCollection
)
shapeQueryBuilder
.
shape
();
org
.
elasticsearch
.
geometry
.
MultiPolygon
multiPolygon
=
(
org
.
elasticsearch
.
geometry
.
MultiPolygon
)
geometryCollection
.
get
(
0
);
assertArrayEquals
(
new
double
[]{
1.02
,
1.02
,
10.74
,
10.74
,
1.02
},
multiPolygon
.
get
(
0
).
getPolygon
().
getLats
(),
0.01
);
assertArrayEquals
(
new
double
[]{-
8.61
,
-
2.48
,
-
2.48
,
-
8.61
,
-
8.61
},
multiPolygon
.
get
(
0
).
getPolygon
().
getLons
(),
0.01
);
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment