|
@@ -9,7 +9,10 @@
|
|
|
|
|
|
package org.elasticsearch.common.xcontent.json;
|
|
|
|
|
|
+import org.elasticsearch.common.bytes.BytesReference;
|
|
|
import org.elasticsearch.common.xcontent.BaseXContentTestCase;
|
|
|
+import org.elasticsearch.xcontent.Text;
|
|
|
+import org.elasticsearch.xcontent.XContentBuilder;
|
|
|
import org.elasticsearch.xcontent.XContentGenerator;
|
|
|
import org.elasticsearch.xcontent.XContentParseException;
|
|
|
import org.elasticsearch.xcontent.XContentParser;
|
|
@@ -18,6 +21,9 @@ import org.elasticsearch.xcontent.XContentType;
|
|
|
import org.elasticsearch.xcontent.json.JsonXContent;
|
|
|
|
|
|
import java.io.ByteArrayOutputStream;
|
|
|
+import java.util.Set;
|
|
|
+
|
|
|
+import static org.hamcrest.Matchers.equalTo;
|
|
|
|
|
|
public class JsonXContentTests extends BaseXContentTestCase {
|
|
|
|
|
@@ -41,4 +47,21 @@ public class JsonXContentTests extends BaseXContentTestCase {
|
|
|
assertThrows(XContentParseException.class, () -> parser.text());
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ public void testOptimizedTextHasBytes() throws Exception {
|
|
|
+ XContentBuilder builder = builder().startObject().field("text", new Text("foo")).endObject();
|
|
|
+ XContentParserConfiguration parserConfig = parserConfig();
|
|
|
+ if (randomBoolean()) {
|
|
|
+ parserConfig = parserConfig.withFiltering(null, Set.of("*"), null, true);
|
|
|
+ }
|
|
|
+ try (XContentParser parser = createParser(parserConfig, xcontentType().xContent(), BytesReference.bytes(builder))) {
|
|
|
+ assertSame(XContentParser.Token.START_OBJECT, parser.nextToken());
|
|
|
+ assertSame(XContentParser.Token.FIELD_NAME, parser.nextToken());
|
|
|
+ assertTrue(parser.nextToken().isValue());
|
|
|
+ Text text = (Text) parser.optimizedText();
|
|
|
+ // TODO: uncomment after utf8 optimized parsing has been enabled again:
|
|
|
+ // assertTrue(text.hasBytes());
|
|
|
+ assertThat(text.string(), equalTo("foo"));
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|