Skip to content

Commit

Permalink
Update test
Browse files Browse the repository at this point in the history
  • Loading branch information
kderusso committed Dec 12, 2024
1 parent 1fc6125 commit f6f57bb
Showing 1 changed file with 7 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,23 @@ public void testRewrite() throws IOException {
QueryRewriteContext context = new QueryRewriteContext(null, client, null);
context.setQueryRewriteInterceptor(myMatchInterceptor);

// Queries that are not intercepted behave normally
TermQueryBuilder termQueryBuilder = new TermQueryBuilder("field", "value");
QueryBuilder rewritten = termQueryBuilder.rewrite(context);
assertTrue(rewritten instanceof TermQueryBuilder);

// Queries that should be intercepted are and the right thing happens
MatchQueryBuilder matchQueryBuilder = new MatchQueryBuilder("field", "value");
rewritten = matchQueryBuilder.rewrite(context);
assertTrue(rewritten instanceof InterceptedQueryBuilderWrapper);
assertTrue(((InterceptedQueryBuilderWrapper) rewritten).queryBuilder instanceof MatchQueryBuilder);
MatchQueryBuilder rewrittenMatchQueryBuilder = (MatchQueryBuilder) ((InterceptedQueryBuilderWrapper) rewritten).queryBuilder;
assertEquals("intercepted", rewrittenMatchQueryBuilder.value());

// An additional rewrite on an already intercepted query returns the same query
QueryBuilder rewrittenAgain = rewritten.rewrite(context);
assertTrue(rewrittenAgain instanceof InterceptedQueryBuilderWrapper);
assertEquals(rewritten, rewrittenAgain);
}

private final QueryRewriteInterceptor myMatchInterceptor = new QueryRewriteInterceptor() {
Expand Down

0 comments on commit f6f57bb

Please sign in to comment.