forked from elastic/elasticsearch
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improve FetchSourceContext and add unit tests (elastic#77346) (elasti…
…c#77521) Co-authored-by: Elastic Machine <[email protected]> Co-authored-by: weizijun <[email protected]> Co-authored-by: Elastic Machine <[email protected]>
- Loading branch information
1 parent
7da3b15
commit c6180cf
Showing
3 changed files
with
78 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
server/src/test/java/org/elasticsearch/search/fetch/subphase/FetchSourceContextTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
package org.elasticsearch.search.fetch.subphase; | ||
|
||
import org.elasticsearch.common.ParsingException; | ||
import org.elasticsearch.common.io.stream.Writeable; | ||
import org.elasticsearch.common.xcontent.XContentBuilder; | ||
import org.elasticsearch.common.xcontent.XContentFactory; | ||
import org.elasticsearch.common.xcontent.XContentParser; | ||
import org.elasticsearch.test.AbstractSerializingTestCase; | ||
|
||
import java.io.IOException; | ||
|
||
import static org.hamcrest.Matchers.containsString; | ||
|
||
public class FetchSourceContextTests extends AbstractSerializingTestCase<FetchSourceContext> { | ||
@Override | ||
protected FetchSourceContext doParseInstance(XContentParser parser) throws IOException { | ||
return FetchSourceContext.fromXContent(parser); | ||
} | ||
|
||
@Override | ||
protected Writeable.Reader<FetchSourceContext> instanceReader() { | ||
return FetchSourceContext::new; | ||
} | ||
|
||
@Override | ||
protected FetchSourceContext createTestInstance() { | ||
return new FetchSourceContext( | ||
true, | ||
randomArray(0, 5, String[]::new, () -> randomAlphaOfLength(5)), | ||
randomArray(0, 5, String[]::new, () -> randomAlphaOfLength(5)) | ||
); | ||
} | ||
|
||
public void testFromXContentException() throws IOException { | ||
XContentBuilder builder = XContentFactory.jsonBuilder(); | ||
int value = randomInt(); | ||
builder.value(value); | ||
XContentParser parser = createParser(builder); | ||
ParsingException exception = expectThrows(ParsingException.class, () -> FetchSourceContext.fromXContent(parser)); | ||
assertThat( | ||
exception.getMessage(), | ||
containsString("Expected one of [VALUE_BOOLEAN, VALUE_STRING, START_ARRAY, START_OBJECT] but found [VALUE_NUMBER]") | ||
); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters