In order to mitigate against the brute force attacks against Gitlab accounts, we are moving to all edu-ID Logins. We would like to remind you to link your account with your edu-id. Login will be possible only by edu-ID after November 30, 2021. Here you can find the instructions for linking your account.

If you don't have a SWITCH edu-ID, you can create one with this guide here

kind regards

Commit d1f6f3ab authored by Jonas Waeber's avatar Jonas Waeber
Browse files

Fix elasticwrapper real test.

parent 8792c5df
package org.memobase package org.memobase
import java.net.ConnectException
import java.net.SocketTimeoutException
import java.util.Properties 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.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.Disabled
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
import org.junit.jupiter.api.TestInstance import org.junit.jupiter.api.TestInstance
import org.junit.jupiter.api.assertAll import org.junit.jupiter.api.assertAll
import org.memobase.helpers.ElasticSearchWrapper import org.memobase.helpers.ElasticSearchWrapper
import org.memobase.model.FacetContainer
import org.memobase.model.LanguageContainer
@TestInstance(TestInstance.Lifecycle.PER_CLASS) @TestInstance(TestInstance.Lifecycle.PER_CLASS)
class TestElasticSearchWrapper { 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 * This test can only be run locally. Create a tunnel to
...@@ -20,17 +67,28 @@ class TestElasticSearchWrapper { ...@@ -20,17 +67,28 @@ class TestElasticSearchWrapper {
@Disabled @Disabled
fun `test getDocumentTypesFromRecords`() { fun `test getDocumentTypesFromRecords`() {
val props = Properties() val props = Properties()
props.setProperty("elastic.host", "localhost") props.setProperty("elastic.index", "documents-v17")
props.setProperty("elastic.port", "8080")
props.setProperty("elastic.index", "documents-v16")
val wrapper = ElasticSearchWrapper(props, TestUtilities.elasticSearchClient, TestUtilities.translationMappers) val wrapper = ElasticSearchWrapper(props, client, TestUtilities.translationMappers)
val results = wrapper.getDocumentTypesFromRecords("rti-002", "recordSet.facet") val results = wrapper.getDocumentTypesFromRecords("aag-001", "recordSet.facet")
assertAll("", assertAll("",
{ {
assertThat(results) assertThat(results)
.hasSize(1) .hasSize(1)
},
{
assertThat(results[0])
.isEqualTo(FacetContainer(
LanguageContainer(
listOf("Fotografie"),
listOf("Photographie"),
listOf("Fotografia"),
emptyList()
),
"Foto",
emptyList()
))
} }
) )
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment