Skip to content

Commit

Permalink
Make test cases in ElasticsearchManagerTests more concise
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesChenX committed Apr 29, 2024
1 parent eeaa184 commit 5905009
Showing 1 changed file with 13 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package integration.im.turms.service.storage.elasticsearch;

import java.text.MessageFormat;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
Expand Down Expand Up @@ -63,40 +64,22 @@
class ElasticsearchManagerTests extends SpringAwareIntegrationTest {

private static final List<String> NAMES = List.of("hello world", "你好,世界", "こんにちは、世界");
private static final List<TestCase> TEST_CASES = List.of(
new TestCase(
"world",
List.of(new ExpectedHit(
"hello world",
"hello %sworld%s".formatted(ElasticsearchManager.PRE_TAG,
ElasticsearchManager.POST_TAG)))),
private static final List<TestCase> TEST_CASES = List.of(new TestCase(
"world",
List.of(new ExpectedHit("hello world", formatExpectedHighlight("hello {0}world{1}")))),
new TestCase(
"世界",
List.of(new ExpectedHit(
"你好,世界",
"你好,%s世界%s".formatted(ElasticsearchManager.PRE_TAG,
ElasticsearchManager.POST_TAG)),
List.of(new ExpectedHit("你好,世界", formatExpectedHighlight("你好,{0}世界{1}")),
new ExpectedHit(
"こんにちは、世界",
"こんにちは、%s世界%s".formatted(ElasticsearchManager.PRE_TAG,
ElasticsearchManager.POST_TAG)))),
formatExpectedHighlight("こんにちは、{0}世界{1}")))),
new TestCase(
"こんにちは",
List.of(new ExpectedHit(
"こんにちは、世界",
// TODO: The expected result should be:
// "%sこんにちは%s、世界".formatted(ElasticsearchManager.PRE_TAG,
// ElasticsearchManager.POST_TAG)
"%sこ%s%sん%s%sに%s%sち%s%sは%s、世界".formatted(ElasticsearchManager.PRE_TAG,
ElasticsearchManager.POST_TAG,
ElasticsearchManager.PRE_TAG,
ElasticsearchManager.POST_TAG,
ElasticsearchManager.PRE_TAG,
ElasticsearchManager.POST_TAG,
ElasticsearchManager.PRE_TAG,
ElasticsearchManager.POST_TAG,
ElasticsearchManager.PRE_TAG,
ElasticsearchManager.POST_TAG)))));
// "{0}こんにちは{1}、世界"
formatExpectedHighlight("{0}こ{1}{0}ん{1}{0}に{1}{0}ち{1}{0}は{1}、世界")))));

@BeforeAll
static void setup() {
Expand Down Expand Up @@ -248,6 +231,11 @@ private static Group buildGroup(long id, String name) {
null);
}

private static String formatExpectedHighlight(String pattern) {
return MessageFormat
.format(pattern, ElasticsearchManager.PRE_TAG, ElasticsearchManager.POST_TAG);
}

private static void waitForElasticsearch() throws InterruptedException {
Thread.sleep(1000);
}
Expand Down

0 comments on commit 5905009

Please sign in to comment.