Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
memoriav
Memobase 2020
services
Elasticsearch Services
Search Doc Service
Commits
d1f6f3ab
Commit
d1f6f3ab
authored
Jan 18, 2021
by
Jonas Waeber
Browse files
Fix elasticwrapper real test.
parent
8792c5df
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/test/kotlin/TestElasticSearchWrapper.kt
View file @
d1f6f3ab
package
org.memobase
import
java.net.ConnectException
import
java.net.SocketTimeoutException
import
java.util.Properties
import
kotlin.system.exitProcess
import
org.apache.http.HttpHost
import
org.apache.logging.log4j.LogManager
import
org.assertj.core.api.Assertions.assertThat
import
org.elasticsearch.ElasticsearchException
import
org.elasticsearch.action.admin.indices.alias.get.GetAliasesRequest
import
org.elasticsearch.client.RequestOptions
import
org.elasticsearch.client.RestClient
import
org.elasticsearch.client.RestHighLevelClient
import
org.elasticsearch.client.indices.GetIndexRequest
import
org.junit.jupiter.api.Disabled
import
org.junit.jupiter.api.Test
import
org.junit.jupiter.api.TestInstance
import
org.junit.jupiter.api.assertAll
import
org.memobase.helpers.ElasticSearchWrapper
import
org.memobase.model.FacetContainer
import
org.memobase.model.LanguageContainer
@TestInstance
(
TestInstance
.
Lifecycle
.
PER_CLASS
)
class
TestElasticSearchWrapper
{
private
val
log
=
LogManager
.
getLogger
(
TestElasticSearchWrapper
::
class
.
java
)
private
val
host
=
"localhost"
private
val
port
=
8080
private
val
documentsIndex
=
"documents-v17"
private
val
client
:
RestHighLevelClient
=
connect
()
private
fun
connect
():
RestHighLevelClient
{
return
try
{
val
c
=
RestHighLevelClient
(
RestClient
.
builder
(
HttpHost
(
host
,
port
)
)
)
val
indexExists
=
c
.
indices
().
exists
(
GetIndexRequest
(
documentsIndex
),
RequestOptions
.
DEFAULT
)
val
aliasExists
=
c
.
indices
().
existsAlias
(
GetAliasesRequest
(
documentsIndex
),
RequestOptions
.
DEFAULT
)
if
(!
indexExists
&&
!
aliasExists
)
{
log
.
error
(
"Could not find the index or alias defined in the configuration: $documentsIndex."
)
exitProcess
(
1
)
}
else
{
log
.
info
(
"Successfully connected to index $documentsIndex. Ready to query."
)
c
}
}
catch
(
ex
:
ElasticsearchException
)
{
log
.
error
(
ex
.
detailedMessage
)
exitProcess
(
1
)
}
catch
(
ex
:
SocketTimeoutException
)
{
log
.
error
(
ex
.
localizedMessage
)
exitProcess
(
1
)
}
catch
(
ex
:
ConnectException
)
{
log
.
error
(
ex
.
localizedMessage
)
exitProcess
(
1
)
}
}
/**
* This test can only be run locally. Create a tunnel to
...
...
@@ -20,17 +67,28 @@ class TestElasticSearchWrapper {
@Disabled
fun
`test
getDocumentTypesFromRecords`
()
{
val
props
=
Properties
()
props
.
setProperty
(
"elastic.host"
,
"localhost"
)
props
.
setProperty
(
"elastic.port"
,
"8080"
)
props
.
setProperty
(
"elastic.index"
,
"documents-v16"
)
props
.
setProperty
(
"elastic.index"
,
"documents-v17"
)
val
wrapper
=
ElasticSearchWrapper
(
props
,
TestUtilities
.
elasticSearchC
lient
,
TestUtilities
.
translationMappers
)
val
wrapper
=
ElasticSearchWrapper
(
props
,
c
lient
,
TestUtilities
.
translationMappers
)
val
results
=
wrapper
.
getDocumentTypesFromRecords
(
"
rti
-00
2
"
,
"recordSet.facet"
)
val
results
=
wrapper
.
getDocumentTypesFromRecords
(
"
aag
-00
1
"
,
"recordSet.facet"
)
assertAll
(
""
,
{
assertThat
(
results
)
.
hasSize
(
1
)
},
{
assertThat
(
results
[
0
])
.
isEqualTo
(
FacetContainer
(
LanguageContainer
(
listOf
(
"Fotografie"
),
listOf
(
"Photographie"
),
listOf
(
"Fotografia"
),
emptyList
()
),
"Foto"
,
emptyList
()
))
}
)
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment