-
Notifications
You must be signed in to change notification settings - Fork 0
/
WithGeoLocationServiceTest.kt
64 lines (48 loc) · 2.13 KB
/
WithGeoLocationServiceTest.kt
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
package kern.elasticsearchplayground
import io.kotest.matchers.collections.shouldContainExactlyInAnyOrder
import io.kotest.matchers.collections.shouldHaveSize
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.data.elasticsearch.client.elc.ElasticsearchAggregations
import org.springframework.test.context.ActiveProfiles
import org.testcontainers.junit.jupiter.Testcontainers
@SpringBootTest(classes = [TestElasticsearchPlaygroundApplication::class])
@Testcontainers
@ActiveProfiles("test")
class WithGeoLocationServiceTest {
@Autowired
private lateinit var withGeoLocationRepository: WithGeoLocationRepository
@Autowired
private lateinit var withGeoLocationService: WithGeoLocationService
@BeforeEach
fun setUp() {
withGeoLocationRepository.deleteAll()
}
@Test
fun searchOnlyWithNativeQuery() {
withGeoLocationService.seedSampleData()
val result = withGeoLocationService.searchOnlyWithNativeQuery()
result shouldHaveSize 3
}
@Test
fun searchWithNativeQueryMixedWithCriteriaQueryAndGeoLocation() {
withGeoLocationService.seedSampleData()
val result = withGeoLocationService.searchWithNativeQueryMixedWithCriteriaQueryAndGeoLocation()
result shouldHaveSize 3
}
@Test
fun searchWithNativeQueryMixedWithCriteriaQueryAndGeoLocationAndAggregation() {
withGeoLocationService.seedSampleData()
val result = withGeoLocationService.searchWithNativeQueryMixedWithCriteriaQueryAndGeoLocationAndAggregation()
result shouldHaveSize 3 //works with spring-data-elasticsearch 5.3.0-M2
val foundAggregationIds = (result.aggregations as ElasticsearchAggregations)
.aggregationsAsMap()["exampleAggregation"]
?.aggregation()
?.aggregate?.lterms()
?.buckets()?.array()
?.map { it.key() }?.toSet() ?: emptySet()
foundAggregationIds shouldContainExactlyInAnyOrder listOf(1L, 2L)
}
}