mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-02-17 10:25:15 +00:00
exclude{Filters}, filters => filters, exclude
This commit is contained in:
parent
db4c6c96a3
commit
0dfb55d72c
@ -84,7 +84,7 @@ public final class XContentBuilder implements BytesStream, Releasable {
|
||||
}
|
||||
|
||||
public static XContentBuilder builder(XContent xContent, String[] filters, boolean inclusive) throws IOException {
|
||||
return new XContentBuilder(xContent, new BytesStreamOutput(), inclusive, filters);
|
||||
return new XContentBuilder(xContent, new BytesStreamOutput(), filters, inclusive);
|
||||
}
|
||||
|
||||
private XContentGenerator generator;
|
||||
@ -112,7 +112,7 @@ public final class XContentBuilder implements BytesStream, Releasable {
|
||||
* {@link #close()} when the builder is done with.
|
||||
*/
|
||||
public XContentBuilder(XContent xContent, OutputStream bos, String[] filters) throws IOException {
|
||||
this(xContent, bos, true, filters);
|
||||
this(xContent, bos, filters, true);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -122,9 +122,9 @@ public final class XContentBuilder implements BytesStream, Releasable {
|
||||
* inclusiveFilters is false, those matching will be excluded. Make sure to
|
||||
* call {@link #close()} when the builder is done with.
|
||||
*/
|
||||
public XContentBuilder(XContent xContent, OutputStream bos, boolean inclusiveFilters, String[] filters) throws IOException {
|
||||
public XContentBuilder(XContent xContent, OutputStream bos, String[] filters, boolean inclusive) throws IOException {
|
||||
this.bos = bos;
|
||||
this.generator = xContent.createGenerator(bos, filters, inclusiveFilters);
|
||||
this.generator = xContent.createGenerator(bos, filters, inclusive);
|
||||
}
|
||||
|
||||
public XContentBuilder fieldCaseConversion(FieldCaseConversion fieldCaseConversion) {
|
||||
|
@ -67,8 +67,8 @@ public class CborXContent implements XContent {
|
||||
}
|
||||
|
||||
@Override
|
||||
public XContentGenerator createGenerator(OutputStream os, String[] filters, boolean inclusiveFilters) throws IOException {
|
||||
return new CborXContentGenerator(cborFactory.createGenerator(os, JsonEncoding.UTF8), os, inclusiveFilters, filters);
|
||||
public XContentGenerator createGenerator(OutputStream os, String[] filters, boolean inclusive) throws IOException {
|
||||
return new CborXContentGenerator(cborFactory.createGenerator(os, JsonEncoding.UTF8), os, filters, inclusive);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -32,11 +32,11 @@ import java.io.OutputStream;
|
||||
public class CborXContentGenerator extends JsonXContentGenerator {
|
||||
|
||||
public CborXContentGenerator(JsonGenerator jsonGenerator, OutputStream os, String... filters) {
|
||||
this(jsonGenerator, os, true, filters);
|
||||
this(jsonGenerator, os, filters, true);
|
||||
}
|
||||
|
||||
public CborXContentGenerator(JsonGenerator jsonGenerator, OutputStream os, boolean inclusive, String[] filters) {
|
||||
super(jsonGenerator, os, inclusive, filters);
|
||||
public CborXContentGenerator(JsonGenerator jsonGenerator, OutputStream os, String[] filters, boolean inclusive) {
|
||||
super(jsonGenerator, os, filters, inclusive);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -72,7 +72,7 @@ public class JsonXContent implements XContent {
|
||||
|
||||
@Override
|
||||
public XContentGenerator createGenerator(OutputStream os, String[] filters, boolean inclusive) throws IOException {
|
||||
return new JsonXContentGenerator(jsonFactory.createGenerator(os, JsonEncoding.UTF8), os, inclusive, filters);
|
||||
return new JsonXContentGenerator(jsonFactory.createGenerator(os, JsonEncoding.UTF8), os, filters, inclusive);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -72,10 +72,10 @@ public class JsonXContentGenerator implements XContentGenerator {
|
||||
private boolean prettyPrint = false;
|
||||
|
||||
public JsonXContentGenerator(JsonGenerator jsonGenerator, OutputStream os, String... filters) {
|
||||
this(jsonGenerator, os, true, filters);
|
||||
this(jsonGenerator, os, filters, true);
|
||||
}
|
||||
|
||||
public JsonXContentGenerator(JsonGenerator jsonGenerator, OutputStream os, boolean inclusive, String... filters) {
|
||||
public JsonXContentGenerator(JsonGenerator jsonGenerator, OutputStream os, String[] filters, boolean inclusive) {
|
||||
if (jsonGenerator instanceof GeneratorBase) {
|
||||
this.base = (GeneratorBase) jsonGenerator;
|
||||
} else {
|
||||
|
@ -69,7 +69,7 @@ public class SmileXContent implements XContent {
|
||||
|
||||
@Override
|
||||
public XContentGenerator createGenerator(OutputStream os, String[] filters, boolean inclusive) throws IOException {
|
||||
return new SmileXContentGenerator(smileFactory.createGenerator(os, JsonEncoding.UTF8), os, inclusive, filters);
|
||||
return new SmileXContentGenerator(smileFactory.createGenerator(os, JsonEncoding.UTF8), os, filters, inclusive);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -32,11 +32,11 @@ import java.io.OutputStream;
|
||||
public class SmileXContentGenerator extends JsonXContentGenerator {
|
||||
|
||||
public SmileXContentGenerator(JsonGenerator jsonGenerator, OutputStream os, String... filters) {
|
||||
this(jsonGenerator, os, true, filters);
|
||||
this(jsonGenerator, os, filters, true);
|
||||
}
|
||||
|
||||
public SmileXContentGenerator(JsonGenerator jsonGenerator, OutputStream os, boolean inclusive, String[] filters) {
|
||||
super(jsonGenerator, os, inclusive, filters);
|
||||
public SmileXContentGenerator(JsonGenerator jsonGenerator, OutputStream os, String[] filters, boolean inclusive) {
|
||||
super(jsonGenerator, os, filters, inclusive);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -45,7 +45,7 @@ public class FilterPathBasedFilter extends TokenFilter {
|
||||
|
||||
private final boolean inclusive;
|
||||
|
||||
public FilterPathBasedFilter(boolean inclusive, FilterPath[] filters) {
|
||||
public FilterPathBasedFilter(FilterPath[] filters, boolean inclusive) {
|
||||
if (CollectionUtils.isEmpty(filters)) {
|
||||
throw new IllegalArgumentException("filters cannot be null or empty");
|
||||
}
|
||||
@ -54,7 +54,7 @@ public class FilterPathBasedFilter extends TokenFilter {
|
||||
}
|
||||
|
||||
public FilterPathBasedFilter(boolean inclusive, String[] filters) {
|
||||
this(inclusive, FilterPath.compile(filters));
|
||||
this(FilterPath.compile(filters), inclusive);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -82,7 +82,7 @@ public class FilterPathBasedFilter extends TokenFilter {
|
||||
}
|
||||
|
||||
if ((nextFilters != null) && (nextFilters.isEmpty() == false)) {
|
||||
return new FilterPathBasedFilter(inclusive, nextFilters.toArray(new FilterPath[nextFilters.size()]));
|
||||
return new FilterPathBasedFilter(nextFilters.toArray(new FilterPath[nextFilters.size()]), inclusive);
|
||||
}
|
||||
}
|
||||
return NO_MATCHING;
|
||||
|
@ -66,8 +66,8 @@ public class YamlXContent implements XContent {
|
||||
}
|
||||
|
||||
@Override
|
||||
public XContentGenerator createGenerator(OutputStream os, String[] filters, boolean inclusiveFilters) throws IOException {
|
||||
return new YamlXContentGenerator(yamlFactory.createGenerator(os, JsonEncoding.UTF8), os, inclusiveFilters, filters);
|
||||
public XContentGenerator createGenerator(OutputStream os, String[] filters, boolean inclusive) throws IOException {
|
||||
return new YamlXContentGenerator(yamlFactory.createGenerator(os, JsonEncoding.UTF8), os, filters, inclusive);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -32,11 +32,11 @@ import java.io.OutputStream;
|
||||
public class YamlXContentGenerator extends JsonXContentGenerator {
|
||||
|
||||
public YamlXContentGenerator(JsonGenerator jsonGenerator, OutputStream os, String... filters) {
|
||||
this(jsonGenerator, os, true, filters);
|
||||
this(jsonGenerator, os, filters, true);
|
||||
}
|
||||
|
||||
public YamlXContentGenerator(JsonGenerator jsonGenerator, OutputStream os, boolean inclusive, String[] filters) {
|
||||
super(jsonGenerator, os, inclusive, filters);
|
||||
public YamlXContentGenerator(JsonGenerator jsonGenerator, OutputStream os, String[] filters, boolean inclusive) {
|
||||
super(jsonGenerator, os, filters, inclusive);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -83,7 +83,15 @@ public abstract class AbstractFilteringJsonGeneratorTestCase extends ESTestCase
|
||||
}
|
||||
}
|
||||
|
||||
private XContentBuilder newXContentBuilder(boolean inclusive, String... filters) throws IOException {
|
||||
private XContentBuilder newXContentBuilder() throws IOException {
|
||||
return XContentBuilder.builder(getXContentType().xContent());
|
||||
}
|
||||
|
||||
private XContentBuilder newXContentBuilder(String filter, boolean inclusive) throws IOException {
|
||||
return XContentBuilder.builder(getXContentType().xContent(), new String[] { filter }, inclusive);
|
||||
}
|
||||
|
||||
private XContentBuilder newXContentBuilder(String[] filters, boolean inclusive) throws IOException {
|
||||
return XContentBuilder.builder(getXContentType().xContent(), filters, inclusive);
|
||||
}
|
||||
|
||||
@ -169,39 +177,46 @@ public abstract class AbstractFilteringJsonGeneratorTestCase extends ESTestCase
|
||||
/**
|
||||
* Instanciates a new XContentBuilder with the given filters and builds a
|
||||
* sample with it.
|
||||
*
|
||||
* @param inclusive
|
||||
* Specifies if filters are inclusive or exclusive
|
||||
*/
|
||||
private XContentBuilder sample(boolean inclusive, String... filters) throws IOException {
|
||||
return sample(newXContentBuilder(inclusive, filters));
|
||||
private XContentBuilder sample(String filter, boolean inclusive) throws IOException {
|
||||
return sample(newXContentBuilder(filter, inclusive));
|
||||
}
|
||||
|
||||
private XContentBuilder sample(String[] filters, boolean inclusive) throws IOException {
|
||||
return sample(newXContentBuilder(filters, inclusive));
|
||||
}
|
||||
|
||||
private XContentBuilder sample() throws IOException {
|
||||
return sample(newXContentBuilder());
|
||||
}
|
||||
|
||||
public void testNoFiltering() throws Exception {
|
||||
XContentBuilder expected = sample(true);
|
||||
XContentBuilder expected = sample();
|
||||
|
||||
assertXContentBuilder(expected, sample(true));
|
||||
assertXContentBuilder(expected, sample(true, "*"));
|
||||
assertXContentBuilder(expected, sample(true, "**"));
|
||||
assertXContentBuilder(expected, sample(false, "xyz"));
|
||||
assertXContentBuilder(expected, sample());
|
||||
assertXContentBuilder(expected, sample("*", true));
|
||||
assertXContentBuilder(expected, sample("**", true));
|
||||
assertXContentBuilder(expected, sample("xyz", false));
|
||||
}
|
||||
|
||||
public void testNoMatch() throws Exception {
|
||||
XContentBuilder expected = newXContentBuilder(true).startObject().endObject();
|
||||
XContentBuilder expected = newXContentBuilder().startObject().endObject();
|
||||
|
||||
assertXContentBuilder(expected, sample(true, "xyz"));
|
||||
assertXContentBuilder(expected, sample(false, "*"));
|
||||
assertXContentBuilder(expected, sample(false, "**"));
|
||||
assertXContentBuilder(expected, sample("xyz", true));
|
||||
assertXContentBuilder(expected, sample("*", false));
|
||||
assertXContentBuilder(expected, sample("**", false));
|
||||
}
|
||||
|
||||
public void testSimpleFieldInclusive() throws Exception {
|
||||
XContentBuilder expected = newXContentBuilder(true).startObject().field("title", "My awesome book").endObject();
|
||||
XContentBuilder expected = newXContentBuilder().startObject().field("title", "My awesome book").endObject();
|
||||
|
||||
assertXContentBuilder(expected, sample(true, "title"));
|
||||
assertXContentBuilder(expected, sample("title", true));
|
||||
}
|
||||
|
||||
public void testSimpleFieldExclusive() throws Exception {
|
||||
XContentBuilder expected = newXContentBuilder(true).startObject()
|
||||
XContentBuilder expected = newXContentBuilder().startObject()
|
||||
.field("pages", 456)
|
||||
.field("price", 27.99)
|
||||
.field("timestamp", 1428582942867L)
|
||||
@ -272,12 +287,12 @@ public abstract class AbstractFilteringJsonGeneratorTestCase extends ESTestCase
|
||||
.endObject()
|
||||
.endObject();
|
||||
|
||||
assertXContentBuilder(expected, sample(false, "title"));
|
||||
assertXContentBuilder(expected, sample("title", false));
|
||||
}
|
||||
|
||||
|
||||
public void testSimpleFieldWithWildcardInclusive() throws Exception {
|
||||
XContentBuilder expected = newXContentBuilder(true).startObject()
|
||||
XContentBuilder expected = newXContentBuilder().startObject()
|
||||
.field("price", 27.99)
|
||||
.startObject("properties")
|
||||
.field("weight", 0.8d)
|
||||
@ -329,11 +344,11 @@ public abstract class AbstractFilteringJsonGeneratorTestCase extends ESTestCase
|
||||
.endObject()
|
||||
.endObject();
|
||||
|
||||
assertXContentBuilder(expected, sample(true, "pr*"));
|
||||
assertXContentBuilder(expected, sample("pr*", true));
|
||||
}
|
||||
|
||||
public void testSimpleFieldWithWildcardExclusive() throws Exception {
|
||||
XContentBuilder expected = newXContentBuilder(true).startObject()
|
||||
XContentBuilder expected = newXContentBuilder().startObject()
|
||||
.field("title", "My awesome book")
|
||||
.field("pages", 456)
|
||||
.field("timestamp", 1428582942867L)
|
||||
@ -356,20 +371,20 @@ public abstract class AbstractFilteringJsonGeneratorTestCase extends ESTestCase
|
||||
.endArray()
|
||||
.endObject();
|
||||
|
||||
assertXContentBuilder(expected, sample(false, "pr*"));
|
||||
assertXContentBuilder(expected, sample("pr*", false));
|
||||
}
|
||||
|
||||
public void testMultipleFieldsInclusive() throws Exception {
|
||||
XContentBuilder expected = newXContentBuilder(true).startObject()
|
||||
XContentBuilder expected = newXContentBuilder().startObject()
|
||||
.field("title", "My awesome book")
|
||||
.field("pages", 456)
|
||||
.endObject();
|
||||
|
||||
assertXContentBuilder(expected, sample(true, "title", "pages"));
|
||||
assertXContentBuilder(expected, sample(new String[] { "title", "pages" }, true));
|
||||
}
|
||||
|
||||
public void testMultipleFieldsExclusive() throws Exception {
|
||||
XContentBuilder expected = newXContentBuilder(true).startObject()
|
||||
XContentBuilder expected = newXContentBuilder().startObject()
|
||||
.field("price", 27.99)
|
||||
.field("timestamp", 1428582942867L)
|
||||
.nullField("default")
|
||||
@ -439,23 +454,23 @@ public abstract class AbstractFilteringJsonGeneratorTestCase extends ESTestCase
|
||||
.endObject()
|
||||
.endObject();
|
||||
|
||||
assertXContentBuilder(expected, sample(false, "title", "pages"));
|
||||
assertXContentBuilder(expected, sample(new String[] { "title", "pages" }, false));
|
||||
}
|
||||
|
||||
|
||||
public void testSimpleArrayInclusive() throws Exception {
|
||||
XContentBuilder expected = newXContentBuilder(true).startObject()
|
||||
XContentBuilder expected = newXContentBuilder().startObject()
|
||||
.startArray("tags")
|
||||
.value("elasticsearch")
|
||||
.value("java")
|
||||
.endArray()
|
||||
.endObject();
|
||||
|
||||
assertXContentBuilder(expected, sample(true, "tags"));
|
||||
assertXContentBuilder(expected, sample("tags", true));
|
||||
}
|
||||
|
||||
public void testSimpleArrayExclusive() throws Exception {
|
||||
XContentBuilder expected = newXContentBuilder(true).startObject()
|
||||
XContentBuilder expected = newXContentBuilder().startObject()
|
||||
.field("title", "My awesome book")
|
||||
.field("pages", 456)
|
||||
.field("price", 27.99)
|
||||
@ -523,12 +538,12 @@ public abstract class AbstractFilteringJsonGeneratorTestCase extends ESTestCase
|
||||
.endObject()
|
||||
.endObject();
|
||||
|
||||
assertXContentBuilder(expected, sample(false, "tags"));
|
||||
assertXContentBuilder(expected, sample("tags", false));
|
||||
}
|
||||
|
||||
|
||||
public void testSimpleArrayOfObjectsInclusive() throws Exception {
|
||||
XContentBuilder expected = newXContentBuilder(true).startObject()
|
||||
XContentBuilder expected = newXContentBuilder().startObject()
|
||||
.startArray("authors")
|
||||
.startObject()
|
||||
.field("name", "John Doe")
|
||||
@ -543,13 +558,13 @@ public abstract class AbstractFilteringJsonGeneratorTestCase extends ESTestCase
|
||||
.endArray()
|
||||
.endObject();
|
||||
|
||||
assertXContentBuilder(expected, sample(true, "authors"));
|
||||
assertXContentBuilder(expected, sample(true, "authors.*"));
|
||||
assertXContentBuilder(expected, sample(true, "authors.*name"));
|
||||
assertXContentBuilder(expected, sample("authors", true));
|
||||
assertXContentBuilder(expected, sample("authors.*", true));
|
||||
assertXContentBuilder(expected, sample("authors.*name", true));
|
||||
}
|
||||
|
||||
public void testSimpleArrayOfObjectsExclusive() throws Exception {
|
||||
XContentBuilder expected = newXContentBuilder(true).startObject()
|
||||
XContentBuilder expected = newXContentBuilder().startObject()
|
||||
.field("title", "My awesome book")
|
||||
.field("pages", 456)
|
||||
.field("price", 27.99)
|
||||
@ -609,13 +624,13 @@ public abstract class AbstractFilteringJsonGeneratorTestCase extends ESTestCase
|
||||
.endObject()
|
||||
.endObject();
|
||||
|
||||
assertXContentBuilder(expected, sample(false, "authors"));
|
||||
assertXContentBuilder(expected, sample(false, "authors.*"));
|
||||
assertXContentBuilder(expected, sample(false, "authors.*name"));
|
||||
assertXContentBuilder(expected, sample("authors", false));
|
||||
assertXContentBuilder(expected, sample("authors.*", false));
|
||||
assertXContentBuilder(expected, sample("authors.*name", false));
|
||||
}
|
||||
|
||||
public void testSimpleArrayOfObjectsPropertyInclusive() throws Exception {
|
||||
XContentBuilder expected = newXContentBuilder(true).startObject()
|
||||
XContentBuilder expected = newXContentBuilder().startObject()
|
||||
.startArray("authors")
|
||||
.startObject()
|
||||
.field("lastname", "John")
|
||||
@ -626,12 +641,12 @@ public abstract class AbstractFilteringJsonGeneratorTestCase extends ESTestCase
|
||||
.endArray()
|
||||
.endObject();
|
||||
|
||||
assertXContentBuilder(expected, sample(true, "authors.lastname"));
|
||||
assertXContentBuilder(expected, sample(true, "authors.l*"));
|
||||
assertXContentBuilder(expected, sample("authors.lastname", true));
|
||||
assertXContentBuilder(expected, sample("authors.l*", true));
|
||||
}
|
||||
|
||||
public void testSimpleArrayOfObjectsPropertyExclusive() throws Exception {
|
||||
XContentBuilder expected = newXContentBuilder(true).startObject()
|
||||
XContentBuilder expected = newXContentBuilder().startObject()
|
||||
.field("title", "My awesome book")
|
||||
.field("pages", 456)
|
||||
.field("price", 27.99)
|
||||
@ -701,12 +716,12 @@ public abstract class AbstractFilteringJsonGeneratorTestCase extends ESTestCase
|
||||
.endObject()
|
||||
.endObject();
|
||||
|
||||
assertXContentBuilder(expected, sample(false, "authors.lastname"));
|
||||
assertXContentBuilder(expected, sample(false, "authors.l*"));
|
||||
assertXContentBuilder(expected, sample("authors.lastname", false));
|
||||
assertXContentBuilder(expected, sample("authors.l*", false));
|
||||
}
|
||||
|
||||
public void testRecurseField1Inclusive() throws Exception {
|
||||
XContentBuilder expected = newXContentBuilder(true).startObject()
|
||||
XContentBuilder expected = newXContentBuilder().startObject()
|
||||
.startArray("authors")
|
||||
.startObject()
|
||||
.field("name", "John Doe")
|
||||
@ -754,11 +769,11 @@ public abstract class AbstractFilteringJsonGeneratorTestCase extends ESTestCase
|
||||
.endObject()
|
||||
.endObject();
|
||||
|
||||
assertXContentBuilder(expected, sample(true, "**.name"));
|
||||
assertXContentBuilder(expected, sample("**.name", true));
|
||||
}
|
||||
|
||||
public void testRecurseField1Exclusive() throws Exception {
|
||||
XContentBuilder expected = newXContentBuilder(true).startObject()
|
||||
XContentBuilder expected = newXContentBuilder().startObject()
|
||||
.field("title", "My awesome book")
|
||||
.field("pages", 456)
|
||||
.field("price", 27.99)
|
||||
@ -817,11 +832,11 @@ public abstract class AbstractFilteringJsonGeneratorTestCase extends ESTestCase
|
||||
.endObject()
|
||||
.endObject();
|
||||
|
||||
assertXContentBuilder(expected, sample(false, "**.name"));
|
||||
assertXContentBuilder(expected, sample("**.name", false));
|
||||
}
|
||||
|
||||
public void testRecurseField2Inclusive() throws Exception {
|
||||
XContentBuilder expected = newXContentBuilder(true).startObject()
|
||||
XContentBuilder expected = newXContentBuilder().startObject()
|
||||
.startObject("properties")
|
||||
.startObject("language")
|
||||
.startObject("en")
|
||||
@ -861,11 +876,11 @@ public abstract class AbstractFilteringJsonGeneratorTestCase extends ESTestCase
|
||||
.endObject()
|
||||
.endObject();
|
||||
|
||||
assertXContentBuilder(expected, sample(true, "properties.**.name"));
|
||||
assertXContentBuilder(expected, sample("properties.**.name", true));
|
||||
}
|
||||
|
||||
public void testRecurseField2Exclusive() throws Exception {
|
||||
XContentBuilder expected = newXContentBuilder(true).startObject()
|
||||
XContentBuilder expected = newXContentBuilder().startObject()
|
||||
.field("title", "My awesome book")
|
||||
.field("pages", 456)
|
||||
.field("price", 27.99)
|
||||
@ -926,12 +941,12 @@ public abstract class AbstractFilteringJsonGeneratorTestCase extends ESTestCase
|
||||
.endObject()
|
||||
.endObject();
|
||||
|
||||
assertXContentBuilder(expected, sample(false, "properties.**.name"));
|
||||
assertXContentBuilder(expected, sample("properties.**.name", false));
|
||||
}
|
||||
|
||||
|
||||
public void testRecurseField3Inclusive() throws Exception {
|
||||
XContentBuilder expected = newXContentBuilder(true).startObject()
|
||||
XContentBuilder expected = newXContentBuilder().startObject()
|
||||
.startObject("properties")
|
||||
.startObject("language")
|
||||
.startObject("en")
|
||||
@ -956,11 +971,11 @@ public abstract class AbstractFilteringJsonGeneratorTestCase extends ESTestCase
|
||||
.endObject()
|
||||
.endObject();
|
||||
|
||||
assertXContentBuilder(expected, sample(true, "properties.*.en.**.name"));
|
||||
assertXContentBuilder(expected, sample("properties.*.en.**.name", true));
|
||||
}
|
||||
|
||||
public void testRecurseField3Exclusive() throws Exception {
|
||||
XContentBuilder expected = newXContentBuilder(true).startObject()
|
||||
XContentBuilder expected = newXContentBuilder().startObject()
|
||||
.field("title", "My awesome book")
|
||||
.field("pages", 456)
|
||||
.field("price", 27.99)
|
||||
@ -1026,12 +1041,12 @@ public abstract class AbstractFilteringJsonGeneratorTestCase extends ESTestCase
|
||||
.endObject()
|
||||
.endObject();
|
||||
|
||||
assertXContentBuilder(expected, sample(false, "properties.*.en.**.name"));
|
||||
assertXContentBuilder(expected, sample("properties.*.en.**.name", false));
|
||||
}
|
||||
|
||||
|
||||
public void testRecurseField4Inclusive() throws Exception {
|
||||
XContentBuilder expected = newXContentBuilder(true).startObject()
|
||||
XContentBuilder expected = newXContentBuilder().startObject()
|
||||
.startObject("properties")
|
||||
.startObject("language")
|
||||
.startObject("en")
|
||||
@ -1058,11 +1073,11 @@ public abstract class AbstractFilteringJsonGeneratorTestCase extends ESTestCase
|
||||
.endObject()
|
||||
.endObject();
|
||||
|
||||
assertXContentBuilder(expected, sample(true, "properties.**.distributors.name"));
|
||||
assertXContentBuilder(expected, sample("properties.**.distributors.name", true));
|
||||
}
|
||||
|
||||
public void testRecurseField4Exclusive() throws Exception {
|
||||
XContentBuilder expected = newXContentBuilder(true).startObject()
|
||||
XContentBuilder expected = newXContentBuilder().startObject()
|
||||
.field("title", "My awesome book")
|
||||
.field("pages", 456)
|
||||
.field("price", 27.99)
|
||||
@ -1126,59 +1141,88 @@ public abstract class AbstractFilteringJsonGeneratorTestCase extends ESTestCase
|
||||
.endObject()
|
||||
.endObject();
|
||||
|
||||
assertXContentBuilder(expected, sample(false, "properties.**.distributors.name"));
|
||||
assertXContentBuilder(expected, sample("properties.**.distributors.name", false));
|
||||
}
|
||||
|
||||
public void testRawField() throws Exception {
|
||||
XContentBuilder expectedRawField = newXContentBuilder().startObject().field("foo", 0).startObject("raw")
|
||||
.field("content", "hello world!").endObject().endObject();
|
||||
XContentBuilder expectedRawFieldFiltered = newXContentBuilder().startObject().field("foo", 0).endObject();
|
||||
XContentBuilder expectedRawFieldNotFiltered = newXContentBuilder().startObject().startObject("raw").field("content", "hello world!")
|
||||
.endObject().endObject();
|
||||
|
||||
XContentBuilder expectedRawField = newXContentBuilder(true).startObject().field("foo", 0).startObject("raw").field("content", "hello world!").endObject().endObject();
|
||||
XContentBuilder expectedRawFieldFiltered = newXContentBuilder(true).startObject().field("foo", 0).endObject();
|
||||
XContentBuilder expectedRawFieldNotFiltered = newXContentBuilder(true).startObject().startObject("raw").field("content", "hello world!").endObject().endObject();
|
||||
|
||||
BytesReference raw = newXContentBuilder(true).startObject().field("content", "hello world!").endObject().bytes();
|
||||
BytesReference raw = newXContentBuilder().startObject().field("content", "hello world!").endObject().bytes();
|
||||
|
||||
// Test method: rawField(String fieldName, BytesReference content)
|
||||
assertXContentBuilder(expectedRawField, newXContentBuilder(true).startObject().field("foo", 0).rawField("raw", raw).endObject());
|
||||
assertXContentBuilder(expectedRawFieldFiltered, newXContentBuilder(true, "f*").startObject().field("foo", 0).rawField("raw", raw).endObject());
|
||||
assertXContentBuilder(expectedRawFieldFiltered, newXContentBuilder(false, "r*").startObject().field("foo", 0).rawField("raw", raw).endObject());
|
||||
assertXContentBuilder(expectedRawFieldNotFiltered, newXContentBuilder(true, "r*").startObject().field("foo", 0).rawField("raw", raw).endObject());
|
||||
assertXContentBuilder(expectedRawFieldNotFiltered, newXContentBuilder(false, "f*").startObject().field("foo", 0).rawField("raw", raw).endObject());
|
||||
assertXContentBuilder(expectedRawField, newXContentBuilder().startObject().field("foo", 0).rawField("raw", raw).endObject());
|
||||
assertXContentBuilder(expectedRawFieldFiltered,
|
||||
newXContentBuilder("f*", true).startObject().field("foo", 0).rawField("raw", raw).endObject());
|
||||
assertXContentBuilder(expectedRawFieldFiltered,
|
||||
newXContentBuilder("r*", false).startObject().field("foo", 0).rawField("raw", raw).endObject());
|
||||
assertXContentBuilder(expectedRawFieldNotFiltered,
|
||||
newXContentBuilder("r*", true).startObject().field("foo", 0).rawField("raw", raw).endObject());
|
||||
assertXContentBuilder(expectedRawFieldNotFiltered,
|
||||
newXContentBuilder("f*", false).startObject().field("foo", 0).rawField("raw", raw).endObject());
|
||||
|
||||
// Test method: rawField(String fieldName, InputStream content)
|
||||
assertXContentBuilder(expectedRawField, newXContentBuilder(true).startObject().field("foo", 0).rawField("raw", new ByteArrayInputStream(raw.toBytes())).endObject());
|
||||
assertXContentBuilder(expectedRawFieldFiltered, newXContentBuilder(true, "f*").startObject().field("foo", 0).rawField("raw", new ByteArrayInputStream(raw.toBytes())).endObject());
|
||||
assertXContentBuilder(expectedRawFieldFiltered, newXContentBuilder(false, "r*").startObject().field("foo", 0).rawField("raw", new ByteArrayInputStream(raw.toBytes())).endObject());
|
||||
assertXContentBuilder(expectedRawFieldNotFiltered, newXContentBuilder(true, "r*").startObject().field("foo", 0).rawField("raw", new ByteArrayInputStream(raw.toBytes())).endObject());
|
||||
assertXContentBuilder(expectedRawFieldNotFiltered, newXContentBuilder(false, "f*").startObject().field("foo", 0).rawField("raw", new ByteArrayInputStream(raw.toBytes())).endObject());
|
||||
assertXContentBuilder(expectedRawField,
|
||||
newXContentBuilder().startObject().field("foo", 0).rawField("raw", new ByteArrayInputStream(raw.toBytes())).endObject());
|
||||
assertXContentBuilder(expectedRawFieldFiltered, newXContentBuilder("f*", true).startObject().field("foo", 0)
|
||||
.rawField("raw", new ByteArrayInputStream(raw.toBytes())).endObject());
|
||||
assertXContentBuilder(expectedRawFieldFiltered, newXContentBuilder("r*", false).startObject().field("foo", 0)
|
||||
.rawField("raw", new ByteArrayInputStream(raw.toBytes())).endObject());
|
||||
assertXContentBuilder(expectedRawFieldNotFiltered, newXContentBuilder("r*", true).startObject().field("foo", 0)
|
||||
.rawField("raw", new ByteArrayInputStream(raw.toBytes())).endObject());
|
||||
assertXContentBuilder(expectedRawFieldNotFiltered, newXContentBuilder("f*", false).startObject().field("foo", 0)
|
||||
.rawField("raw", new ByteArrayInputStream(raw.toBytes())).endObject());
|
||||
}
|
||||
|
||||
|
||||
public void testArrays() throws Exception {
|
||||
// Test: Array of values (no filtering)
|
||||
XContentBuilder expected = newXContentBuilder(true).startObject().startArray("tags").value("lorem").value("ipsum").value("dolor").endArray().endObject();
|
||||
assertXContentBuilder(expected, newXContentBuilder(true, "t*").startObject().startArray("tags").value("lorem").value("ipsum").value("dolor").endArray().endObject());
|
||||
assertXContentBuilder(expected, newXContentBuilder(true, "tags").startObject().startArray("tags").value("lorem").value("ipsum").value("dolor").endArray().endObject());
|
||||
assertXContentBuilder(expected, newXContentBuilder(false, "a").startObject().startArray("tags").value("lorem").value("ipsum").value("dolor").endArray().endObject());
|
||||
XContentBuilder expected = newXContentBuilder().startObject().startArray("tags").value("lorem").value("ipsum").value("dolor")
|
||||
.endArray().endObject();
|
||||
assertXContentBuilder(expected, newXContentBuilder("t*", true).startObject().startArray("tags").value("lorem").value("ipsum")
|
||||
.value("dolor").endArray().endObject());
|
||||
assertXContentBuilder(expected, newXContentBuilder("tags", true).startObject().startArray("tags").value("lorem").value("ipsum")
|
||||
.value("dolor").endArray().endObject());
|
||||
assertXContentBuilder(expected, newXContentBuilder("a", false).startObject().startArray("tags").value("lorem").value("ipsum")
|
||||
.value("dolor").endArray().endObject());
|
||||
|
||||
// Test: Array of values (with filtering)
|
||||
assertXContentBuilder(newXContentBuilder(true).startObject().endObject(), newXContentBuilder(true, "foo").startObject().startArray("tags").value("lorem").value("ipsum").value("dolor").endArray().endObject());
|
||||
assertXContentBuilder(newXContentBuilder(true).startObject().endObject(), newXContentBuilder(false, "t*").startObject().startArray("tags").value("lorem").value("ipsum").value("dolor").endArray().endObject());
|
||||
assertXContentBuilder(newXContentBuilder(true).startObject().endObject(), newXContentBuilder(false, "tags").startObject().startArray("tags").value("lorem").value("ipsum").value("dolor").endArray().endObject());
|
||||
assertXContentBuilder(newXContentBuilder().startObject().endObject(), newXContentBuilder("foo", true).startObject()
|
||||
.startArray("tags").value("lorem").value("ipsum").value("dolor").endArray().endObject());
|
||||
assertXContentBuilder(newXContentBuilder().startObject().endObject(), newXContentBuilder("t*", false).startObject()
|
||||
.startArray("tags").value("lorem").value("ipsum").value("dolor").endArray().endObject());
|
||||
assertXContentBuilder(newXContentBuilder().startObject().endObject(), newXContentBuilder("tags", false).startObject()
|
||||
.startArray("tags").value("lorem").value("ipsum").value("dolor").endArray().endObject());
|
||||
|
||||
// Test: Array of objects (no filtering)
|
||||
expected = newXContentBuilder(true).startObject().startArray("tags").startObject().field("lastname", "lorem").endObject().startObject().field("firstname", "ipsum").endObject().endArray().endObject();
|
||||
assertXContentBuilder(expected, newXContentBuilder(true, "t*").startObject().startArray("tags").startObject().field("lastname", "lorem").endObject().startObject().field("firstname", "ipsum").endObject().endArray().endObject());
|
||||
assertXContentBuilder(expected, newXContentBuilder(true, "tags").startObject().startArray("tags").startObject().field("lastname", "lorem").endObject().startObject().field("firstname", "ipsum").endObject().endArray().endObject());
|
||||
assertXContentBuilder(expected, newXContentBuilder(false, "a").startObject().startArray("tags").startObject().field("lastname", "lorem").endObject().startObject().field("firstname", "ipsum").endObject().endArray().endObject());
|
||||
expected = newXContentBuilder().startObject().startArray("tags").startObject().field("lastname", "lorem").endObject().startObject()
|
||||
.field("firstname", "ipsum").endObject().endArray().endObject();
|
||||
assertXContentBuilder(expected, newXContentBuilder("t*", true).startObject().startArray("tags").startObject()
|
||||
.field("lastname", "lorem").endObject().startObject().field("firstname", "ipsum").endObject().endArray().endObject());
|
||||
assertXContentBuilder(expected, newXContentBuilder("tags", true).startObject().startArray("tags").startObject()
|
||||
.field("lastname", "lorem").endObject().startObject().field("firstname", "ipsum").endObject().endArray().endObject());
|
||||
assertXContentBuilder(expected, newXContentBuilder("a", false).startObject().startArray("tags").startObject()
|
||||
.field("lastname", "lorem").endObject().startObject().field("firstname", "ipsum").endObject().endArray().endObject());
|
||||
|
||||
// Test: Array of objects (with filtering)
|
||||
assertXContentBuilder(newXContentBuilder(true).startObject().endObject(), newXContentBuilder(true, "foo").startObject().startArray("tags").startObject().field("lastname", "lorem").endObject().startObject().field("firstname", "ipsum").endObject().endArray().endObject());
|
||||
assertXContentBuilder(newXContentBuilder(true).startObject().endObject(), newXContentBuilder(false, "t*").startObject().startArray("tags").startObject().field("lastname", "lorem").endObject().startObject().field("firstname", "ipsum").endObject().endArray().endObject());
|
||||
assertXContentBuilder(newXContentBuilder(true).startObject().endObject(), newXContentBuilder(false, "tags").startObject().startArray("tags").startObject().field("lastname", "lorem").endObject().startObject().field("firstname", "ipsum").endObject().endArray().endObject());
|
||||
assertXContentBuilder(newXContentBuilder().startObject().endObject(),
|
||||
newXContentBuilder("foo", true).startObject().startArray("tags").startObject().field("lastname", "lorem").endObject()
|
||||
.startObject().field("firstname", "ipsum").endObject().endArray().endObject());
|
||||
assertXContentBuilder(newXContentBuilder().startObject().endObject(),
|
||||
newXContentBuilder("t*", false).startObject().startArray("tags").startObject().field("lastname", "lorem").endObject()
|
||||
.startObject().field("firstname", "ipsum").endObject().endArray().endObject());
|
||||
assertXContentBuilder(newXContentBuilder().startObject().endObject(),
|
||||
newXContentBuilder("tags", false).startObject().startArray("tags").startObject().field("lastname", "lorem").endObject()
|
||||
.startObject().field("firstname", "ipsum").endObject().endArray().endObject());
|
||||
|
||||
// Test: Array of objects (with partial filtering)
|
||||
expected = newXContentBuilder(true).startObject().startArray("tags").startObject().field("firstname", "ipsum").endObject().endArray().endObject();
|
||||
assertXContentBuilder(expected, newXContentBuilder(true, "t*.firstname").startObject().startArray("tags").startObject().field("lastname", "lorem").endObject().startObject().field("firstname", "ipsum").endObject().endArray().endObject());
|
||||
assertXContentBuilder(expected, newXContentBuilder(false, "t*.lastname").startObject().startArray("tags").startObject().field("lastname", "lorem").endObject().startObject().field("firstname", "ipsum").endObject().endArray().endObject());
|
||||
expected = newXContentBuilder().startObject().startArray("tags").startObject().field("firstname", "ipsum").endObject().endArray()
|
||||
.endObject();
|
||||
assertXContentBuilder(expected, newXContentBuilder("t*.firstname", true).startObject().startArray("tags").startObject()
|
||||
.field("lastname", "lorem").endObject().startObject().field("firstname", "ipsum").endObject().endArray().endObject());
|
||||
assertXContentBuilder(expected, newXContentBuilder("t*.lastname", false).startObject().startArray("tags").startObject()
|
||||
.field("lastname", "lorem").endObject().startObject().field("firstname", "ipsum").endObject().endArray().endObject());
|
||||
}
|
||||
}
|
||||
|
@ -34,105 +34,105 @@ public class FilterPathGeneratorFilteringTests extends ESTestCase {
|
||||
public void testInclusiveFilters() throws Exception {
|
||||
final String SAMPLE = "{'a':0,'b':true,'c':'c_value','d':[0,1,2],'e':[{'f1':'f1_value','f2':'f2_value'},{'g1':'g1_value','g2':'g2_value'}],'h':{'i':{'j':{'k':{'l':'l_value'}}}}}";
|
||||
|
||||
assertResult(SAMPLE, true, "a", "{'a':0}");
|
||||
assertResult(SAMPLE, true, "b", "{'b':true}");
|
||||
assertResult(SAMPLE, true, "c", "{'c':'c_value'}");
|
||||
assertResult(SAMPLE, true, "d", "{'d':[0,1,2]}");
|
||||
assertResult(SAMPLE, true, "e", "{'e':[{'f1':'f1_value','f2':'f2_value'},{'g1':'g1_value','g2':'g2_value'}]}");
|
||||
assertResult(SAMPLE, true, "h", "{'h':{'i':{'j':{'k':{'l':'l_value'}}}}}");
|
||||
assertResult(SAMPLE, true, "z", "");
|
||||
assertResult(SAMPLE, "a", true, "{'a':0}");
|
||||
assertResult(SAMPLE, "b", true, "{'b':true}");
|
||||
assertResult(SAMPLE, "c", true, "{'c':'c_value'}");
|
||||
assertResult(SAMPLE, "d", true, "{'d':[0,1,2]}");
|
||||
assertResult(SAMPLE, "e", true, "{'e':[{'f1':'f1_value','f2':'f2_value'},{'g1':'g1_value','g2':'g2_value'}]}");
|
||||
assertResult(SAMPLE, "h", true, "{'h':{'i':{'j':{'k':{'l':'l_value'}}}}}");
|
||||
assertResult(SAMPLE, "z", true, "");
|
||||
|
||||
assertResult(SAMPLE, true, "e.f1", "{'e':[{'f1':'f1_value'}]}");
|
||||
assertResult(SAMPLE, true, "e.f2", "{'e':[{'f2':'f2_value'}]}");
|
||||
assertResult(SAMPLE, true, "e.f*", "{'e':[{'f1':'f1_value','f2':'f2_value'}]}");
|
||||
assertResult(SAMPLE, true, "e.*2", "{'e':[{'f2':'f2_value'},{'g2':'g2_value'}]}");
|
||||
assertResult(SAMPLE, "e.f1", true, "{'e':[{'f1':'f1_value'}]}");
|
||||
assertResult(SAMPLE, "e.f2", true, "{'e':[{'f2':'f2_value'}]}");
|
||||
assertResult(SAMPLE, "e.f*", true, "{'e':[{'f1':'f1_value','f2':'f2_value'}]}");
|
||||
assertResult(SAMPLE, "e.*2", true, "{'e':[{'f2':'f2_value'},{'g2':'g2_value'}]}");
|
||||
|
||||
assertResult(SAMPLE, true, "h.i", "{'h':{'i':{'j':{'k':{'l':'l_value'}}}}}");
|
||||
assertResult(SAMPLE, true, "h.i.j", "{'h':{'i':{'j':{'k':{'l':'l_value'}}}}}");
|
||||
assertResult(SAMPLE, true, "h.i.j.k", "{'h':{'i':{'j':{'k':{'l':'l_value'}}}}}");
|
||||
assertResult(SAMPLE, true, "h.i.j.k.l", "{'h':{'i':{'j':{'k':{'l':'l_value'}}}}}");
|
||||
assertResult(SAMPLE, "h.i", true, "{'h':{'i':{'j':{'k':{'l':'l_value'}}}}}");
|
||||
assertResult(SAMPLE, "h.i.j", true, "{'h':{'i':{'j':{'k':{'l':'l_value'}}}}}");
|
||||
assertResult(SAMPLE, "h.i.j.k", true, "{'h':{'i':{'j':{'k':{'l':'l_value'}}}}}");
|
||||
assertResult(SAMPLE, "h.i.j.k.l", true, "{'h':{'i':{'j':{'k':{'l':'l_value'}}}}}");
|
||||
|
||||
assertResult(SAMPLE, true, "h.*", "{'h':{'i':{'j':{'k':{'l':'l_value'}}}}}");
|
||||
assertResult(SAMPLE, true, "*.i", "{'h':{'i':{'j':{'k':{'l':'l_value'}}}}}");
|
||||
assertResult(SAMPLE, "h.*", true, "{'h':{'i':{'j':{'k':{'l':'l_value'}}}}}");
|
||||
assertResult(SAMPLE, "*.i", true, "{'h':{'i':{'j':{'k':{'l':'l_value'}}}}}");
|
||||
|
||||
assertResult(SAMPLE, true, "*.i.j", "{'h':{'i':{'j':{'k':{'l':'l_value'}}}}}");
|
||||
assertResult(SAMPLE, true, "h.*.j", "{'h':{'i':{'j':{'k':{'l':'l_value'}}}}}");
|
||||
assertResult(SAMPLE, true, "h.i.*", "{'h':{'i':{'j':{'k':{'l':'l_value'}}}}}");
|
||||
assertResult(SAMPLE, "*.i.j", true, "{'h':{'i':{'j':{'k':{'l':'l_value'}}}}}");
|
||||
assertResult(SAMPLE, "h.*.j", true, "{'h':{'i':{'j':{'k':{'l':'l_value'}}}}}");
|
||||
assertResult(SAMPLE, "h.i.*", true, "{'h':{'i':{'j':{'k':{'l':'l_value'}}}}}");
|
||||
|
||||
assertResult(SAMPLE, true, "*.i.j.k", "{'h':{'i':{'j':{'k':{'l':'l_value'}}}}}");
|
||||
assertResult(SAMPLE, true, "h.*.j.k", "{'h':{'i':{'j':{'k':{'l':'l_value'}}}}}");
|
||||
assertResult(SAMPLE, true, "h.i.*.k", "{'h':{'i':{'j':{'k':{'l':'l_value'}}}}}");
|
||||
assertResult(SAMPLE, true, "h.i.j.*", "{'h':{'i':{'j':{'k':{'l':'l_value'}}}}}");
|
||||
assertResult(SAMPLE, "*.i.j.k", true, "{'h':{'i':{'j':{'k':{'l':'l_value'}}}}}");
|
||||
assertResult(SAMPLE, "h.*.j.k", true, "{'h':{'i':{'j':{'k':{'l':'l_value'}}}}}");
|
||||
assertResult(SAMPLE, "h.i.*.k", true, "{'h':{'i':{'j':{'k':{'l':'l_value'}}}}}");
|
||||
assertResult(SAMPLE, "h.i.j.*", true, "{'h':{'i':{'j':{'k':{'l':'l_value'}}}}}");
|
||||
|
||||
assertResult(SAMPLE, true, "*.i.j.k.l", "{'h':{'i':{'j':{'k':{'l':'l_value'}}}}}");
|
||||
assertResult(SAMPLE, true, "h.*.j.k.l", "{'h':{'i':{'j':{'k':{'l':'l_value'}}}}}");
|
||||
assertResult(SAMPLE, true, "h.i.*.k.l", "{'h':{'i':{'j':{'k':{'l':'l_value'}}}}}");
|
||||
assertResult(SAMPLE, true, "h.i.j.*.l", "{'h':{'i':{'j':{'k':{'l':'l_value'}}}}}");
|
||||
assertResult(SAMPLE, true, "h.i.j.k.*", "{'h':{'i':{'j':{'k':{'l':'l_value'}}}}}");
|
||||
assertResult(SAMPLE, "*.i.j.k.l", true, "{'h':{'i':{'j':{'k':{'l':'l_value'}}}}}");
|
||||
assertResult(SAMPLE, "h.*.j.k.l", true, "{'h':{'i':{'j':{'k':{'l':'l_value'}}}}}");
|
||||
assertResult(SAMPLE, "h.i.*.k.l", true, "{'h':{'i':{'j':{'k':{'l':'l_value'}}}}}");
|
||||
assertResult(SAMPLE, "h.i.j.*.l", true, "{'h':{'i':{'j':{'k':{'l':'l_value'}}}}}");
|
||||
assertResult(SAMPLE, "h.i.j.k.*", true, "{'h':{'i':{'j':{'k':{'l':'l_value'}}}}}");
|
||||
|
||||
assertResult(SAMPLE, true, "h.*.j.*.l", "{'h':{'i':{'j':{'k':{'l':'l_value'}}}}}");
|
||||
assertResult(SAMPLE, true, "**.l", "{'h':{'i':{'j':{'k':{'l':'l_value'}}}}}");
|
||||
assertResult(SAMPLE, "h.*.j.*.l", true, "{'h':{'i':{'j':{'k':{'l':'l_value'}}}}}");
|
||||
assertResult(SAMPLE, "**.l", true, "{'h':{'i':{'j':{'k':{'l':'l_value'}}}}}");
|
||||
|
||||
assertResult(SAMPLE, true, "**.*2", "{'e':[{'f2':'f2_value'},{'g2':'g2_value'}]}");
|
||||
assertResult(SAMPLE, "**.*2", true, "{'e':[{'f2':'f2_value'},{'g2':'g2_value'}]}");
|
||||
}
|
||||
|
||||
public void testExclusiveFilters() throws Exception {
|
||||
final String SAMPLE = "{'a':0,'b':true,'c':'c_value','d':[0,1,2],'e':[{'f1':'f1_value','f2':'f2_value'},{'g1':'g1_value','g2':'g2_value'}],'h':{'i':{'j':{'k':{'l':'l_value'}}}}}";
|
||||
|
||||
assertResult(SAMPLE, false, "a", "{'b':true,'c':'c_value','d':[0,1,2],'e':[{'f1':'f1_value','f2':'f2_value'},{'g1':'g1_value','g2':'g2_value'}],'h':{'i':{'j':{'k':{'l':'l_value'}}}}}");
|
||||
assertResult(SAMPLE, false, "b", "{'a':0,'c':'c_value','d':[0,1,2],'e':[{'f1':'f1_value','f2':'f2_value'},{'g1':'g1_value','g2':'g2_value'}],'h':{'i':{'j':{'k':{'l':'l_value'}}}}}");
|
||||
assertResult(SAMPLE, false, "c", "{'a':0,'b':true,'d':[0,1,2],'e':[{'f1':'f1_value','f2':'f2_value'},{'g1':'g1_value','g2':'g2_value'}],'h':{'i':{'j':{'k':{'l':'l_value'}}}}}");
|
||||
assertResult(SAMPLE, false, "d", "{'a':0,'b':true,'c':'c_value','e':[{'f1':'f1_value','f2':'f2_value'},{'g1':'g1_value','g2':'g2_value'}],'h':{'i':{'j':{'k':{'l':'l_value'}}}}}");
|
||||
assertResult(SAMPLE, false, "e", "{'a':0,'b':true,'c':'c_value','d':[0,1,2],'h':{'i':{'j':{'k':{'l':'l_value'}}}}}");
|
||||
assertResult(SAMPLE, false, "h", "{'a':0,'b':true,'c':'c_value','d':[0,1,2],'e':[{'f1':'f1_value','f2':'f2_value'},{'g1':'g1_value','g2':'g2_value'}]}");
|
||||
assertResult(SAMPLE, false, "z", "{'a':0,'b':true,'c':'c_value','d':[0,1,2],'e':[{'f1':'f1_value','f2':'f2_value'},{'g1':'g1_value','g2':'g2_value'}],'h':{'i':{'j':{'k':{'l':'l_value'}}}}}");
|
||||
assertResult(SAMPLE, "a", false, "{'b':true,'c':'c_value','d':[0,1,2],'e':[{'f1':'f1_value','f2':'f2_value'},{'g1':'g1_value','g2':'g2_value'}],'h':{'i':{'j':{'k':{'l':'l_value'}}}}}");
|
||||
assertResult(SAMPLE, "b", false, "{'a':0,'c':'c_value','d':[0,1,2],'e':[{'f1':'f1_value','f2':'f2_value'},{'g1':'g1_value','g2':'g2_value'}],'h':{'i':{'j':{'k':{'l':'l_value'}}}}}");
|
||||
assertResult(SAMPLE, "c", false, "{'a':0,'b':true,'d':[0,1,2],'e':[{'f1':'f1_value','f2':'f2_value'},{'g1':'g1_value','g2':'g2_value'}],'h':{'i':{'j':{'k':{'l':'l_value'}}}}}");
|
||||
assertResult(SAMPLE, "d", false, "{'a':0,'b':true,'c':'c_value','e':[{'f1':'f1_value','f2':'f2_value'},{'g1':'g1_value','g2':'g2_value'}],'h':{'i':{'j':{'k':{'l':'l_value'}}}}}");
|
||||
assertResult(SAMPLE, "e", false, "{'a':0,'b':true,'c':'c_value','d':[0,1,2],'h':{'i':{'j':{'k':{'l':'l_value'}}}}}");
|
||||
assertResult(SAMPLE, "h", false, "{'a':0,'b':true,'c':'c_value','d':[0,1,2],'e':[{'f1':'f1_value','f2':'f2_value'},{'g1':'g1_value','g2':'g2_value'}]}");
|
||||
assertResult(SAMPLE, "z", false, "{'a':0,'b':true,'c':'c_value','d':[0,1,2],'e':[{'f1':'f1_value','f2':'f2_value'},{'g1':'g1_value','g2':'g2_value'}],'h':{'i':{'j':{'k':{'l':'l_value'}}}}}");
|
||||
|
||||
assertResult(SAMPLE, false, "e.f1", "{'a':0,'b':true,'c':'c_value','d':[0,1,2],'e':[{'f2':'f2_value'},{'g1':'g1_value','g2':'g2_value'}],'h':{'i':{'j':{'k':{'l':'l_value'}}}}}");
|
||||
assertResult(SAMPLE, false, "e.f2", "{'a':0,'b':true,'c':'c_value','d':[0,1,2],'e':[{'f1':'f1_value'},{'g1':'g1_value','g2':'g2_value'}],'h':{'i':{'j':{'k':{'l':'l_value'}}}}}");
|
||||
assertResult(SAMPLE, false, "e.f*", "{'a':0,'b':true,'c':'c_value','d':[0,1,2],'e':[{'g1':'g1_value','g2':'g2_value'}],'h':{'i':{'j':{'k':{'l':'l_value'}}}}}");
|
||||
assertResult(SAMPLE, false, "e.*2", "{'a':0,'b':true,'c':'c_value','d':[0,1,2],'e':[{'f1':'f1_value'},{'g1':'g1_value'}],'h':{'i':{'j':{'k':{'l':'l_value'}}}}}");
|
||||
assertResult(SAMPLE, "e.f1", false, "{'a':0,'b':true,'c':'c_value','d':[0,1,2],'e':[{'f2':'f2_value'},{'g1':'g1_value','g2':'g2_value'}],'h':{'i':{'j':{'k':{'l':'l_value'}}}}}");
|
||||
assertResult(SAMPLE, "e.f2", false, "{'a':0,'b':true,'c':'c_value','d':[0,1,2],'e':[{'f1':'f1_value'},{'g1':'g1_value','g2':'g2_value'}],'h':{'i':{'j':{'k':{'l':'l_value'}}}}}");
|
||||
assertResult(SAMPLE, "e.f*", false, "{'a':0,'b':true,'c':'c_value','d':[0,1,2],'e':[{'g1':'g1_value','g2':'g2_value'}],'h':{'i':{'j':{'k':{'l':'l_value'}}}}}");
|
||||
assertResult(SAMPLE, "e.*2", false, "{'a':0,'b':true,'c':'c_value','d':[0,1,2],'e':[{'f1':'f1_value'},{'g1':'g1_value'}],'h':{'i':{'j':{'k':{'l':'l_value'}}}}}");
|
||||
|
||||
assertResult(SAMPLE, false, "h.i", "{'a':0,'b':true,'c':'c_value','d':[0,1,2],'e':[{'f1':'f1_value','f2':'f2_value'},{'g1':'g1_value','g2':'g2_value'}]}");
|
||||
assertResult(SAMPLE, false, "h.i.j", "{'a':0,'b':true,'c':'c_value','d':[0,1,2],'e':[{'f1':'f1_value','f2':'f2_value'},{'g1':'g1_value','g2':'g2_value'}]}");
|
||||
assertResult(SAMPLE, false, "h.i.j.k", "{'a':0,'b':true,'c':'c_value','d':[0,1,2],'e':[{'f1':'f1_value','f2':'f2_value'},{'g1':'g1_value','g2':'g2_value'}]}");
|
||||
assertResult(SAMPLE, false, "h.i.j.k.l", "{'a':0,'b':true,'c':'c_value','d':[0,1,2],'e':[{'f1':'f1_value','f2':'f2_value'},{'g1':'g1_value','g2':'g2_value'}]}");
|
||||
assertResult(SAMPLE, "h.i", false, "{'a':0,'b':true,'c':'c_value','d':[0,1,2],'e':[{'f1':'f1_value','f2':'f2_value'},{'g1':'g1_value','g2':'g2_value'}]}");
|
||||
assertResult(SAMPLE, "h.i.j", false, "{'a':0,'b':true,'c':'c_value','d':[0,1,2],'e':[{'f1':'f1_value','f2':'f2_value'},{'g1':'g1_value','g2':'g2_value'}]}");
|
||||
assertResult(SAMPLE, "h.i.j.k", false, "{'a':0,'b':true,'c':'c_value','d':[0,1,2],'e':[{'f1':'f1_value','f2':'f2_value'},{'g1':'g1_value','g2':'g2_value'}]}");
|
||||
assertResult(SAMPLE, "h.i.j.k.l", false, "{'a':0,'b':true,'c':'c_value','d':[0,1,2],'e':[{'f1':'f1_value','f2':'f2_value'},{'g1':'g1_value','g2':'g2_value'}]}");
|
||||
|
||||
assertResult(SAMPLE, false, "h.*", "{'a':0,'b':true,'c':'c_value','d':[0,1,2],'e':[{'f1':'f1_value','f2':'f2_value'},{'g1':'g1_value','g2':'g2_value'}]}");
|
||||
assertResult(SAMPLE, false, "*.i", "{'a':0,'b':true,'c':'c_value','d':[0,1,2],'e':[{'f1':'f1_value','f2':'f2_value'},{'g1':'g1_value','g2':'g2_value'}]}");
|
||||
assertResult(SAMPLE, "h.*", false, "{'a':0,'b':true,'c':'c_value','d':[0,1,2],'e':[{'f1':'f1_value','f2':'f2_value'},{'g1':'g1_value','g2':'g2_value'}]}");
|
||||
assertResult(SAMPLE, "*.i", false, "{'a':0,'b':true,'c':'c_value','d':[0,1,2],'e':[{'f1':'f1_value','f2':'f2_value'},{'g1':'g1_value','g2':'g2_value'}]}");
|
||||
|
||||
assertResult(SAMPLE, false, "*.i.j", "{'a':0,'b':true,'c':'c_value','d':[0,1,2],'e':[{'f1':'f1_value','f2':'f2_value'},{'g1':'g1_value','g2':'g2_value'}]}");
|
||||
assertResult(SAMPLE, false, "h.*.j", "{'a':0,'b':true,'c':'c_value','d':[0,1,2],'e':[{'f1':'f1_value','f2':'f2_value'},{'g1':'g1_value','g2':'g2_value'}]}");
|
||||
assertResult(SAMPLE, false, "h.i.*", "{'a':0,'b':true,'c':'c_value','d':[0,1,2],'e':[{'f1':'f1_value','f2':'f2_value'},{'g1':'g1_value','g2':'g2_value'}]}");
|
||||
assertResult(SAMPLE, "*.i.j", false, "{'a':0,'b':true,'c':'c_value','d':[0,1,2],'e':[{'f1':'f1_value','f2':'f2_value'},{'g1':'g1_value','g2':'g2_value'}]}");
|
||||
assertResult(SAMPLE, "h.*.j", false, "{'a':0,'b':true,'c':'c_value','d':[0,1,2],'e':[{'f1':'f1_value','f2':'f2_value'},{'g1':'g1_value','g2':'g2_value'}]}");
|
||||
assertResult(SAMPLE, "h.i.*", false, "{'a':0,'b':true,'c':'c_value','d':[0,1,2],'e':[{'f1':'f1_value','f2':'f2_value'},{'g1':'g1_value','g2':'g2_value'}]}");
|
||||
|
||||
assertResult(SAMPLE, false, "*.i.j.k", "{'a':0,'b':true,'c':'c_value','d':[0,1,2],'e':[{'f1':'f1_value','f2':'f2_value'},{'g1':'g1_value','g2':'g2_value'}]}");
|
||||
assertResult(SAMPLE, false, "h.*.j.k", "{'a':0,'b':true,'c':'c_value','d':[0,1,2],'e':[{'f1':'f1_value','f2':'f2_value'},{'g1':'g1_value','g2':'g2_value'}]}");
|
||||
assertResult(SAMPLE, false, "h.i.*.k", "{'a':0,'b':true,'c':'c_value','d':[0,1,2],'e':[{'f1':'f1_value','f2':'f2_value'},{'g1':'g1_value','g2':'g2_value'}]}");
|
||||
assertResult(SAMPLE, false, "h.i.j.*", "{'a':0,'b':true,'c':'c_value','d':[0,1,2],'e':[{'f1':'f1_value','f2':'f2_value'},{'g1':'g1_value','g2':'g2_value'}]}");
|
||||
assertResult(SAMPLE, "*.i.j.k", false, "{'a':0,'b':true,'c':'c_value','d':[0,1,2],'e':[{'f1':'f1_value','f2':'f2_value'},{'g1':'g1_value','g2':'g2_value'}]}");
|
||||
assertResult(SAMPLE, "h.*.j.k", false, "{'a':0,'b':true,'c':'c_value','d':[0,1,2],'e':[{'f1':'f1_value','f2':'f2_value'},{'g1':'g1_value','g2':'g2_value'}]}");
|
||||
assertResult(SAMPLE, "h.i.*.k", false, "{'a':0,'b':true,'c':'c_value','d':[0,1,2],'e':[{'f1':'f1_value','f2':'f2_value'},{'g1':'g1_value','g2':'g2_value'}]}");
|
||||
assertResult(SAMPLE, "h.i.j.*", false, "{'a':0,'b':true,'c':'c_value','d':[0,1,2],'e':[{'f1':'f1_value','f2':'f2_value'},{'g1':'g1_value','g2':'g2_value'}]}");
|
||||
|
||||
assertResult(SAMPLE, false, "*.i.j.k.l", "{'a':0,'b':true,'c':'c_value','d':[0,1,2],'e':[{'f1':'f1_value','f2':'f2_value'},{'g1':'g1_value','g2':'g2_value'}]}");
|
||||
assertResult(SAMPLE, false, "h.*.j.k.l", "{'a':0,'b':true,'c':'c_value','d':[0,1,2],'e':[{'f1':'f1_value','f2':'f2_value'},{'g1':'g1_value','g2':'g2_value'}]}");
|
||||
assertResult(SAMPLE, false, "h.i.*.k.l", "{'a':0,'b':true,'c':'c_value','d':[0,1,2],'e':[{'f1':'f1_value','f2':'f2_value'},{'g1':'g1_value','g2':'g2_value'}]}");
|
||||
assertResult(SAMPLE, false, "h.i.j.*.l", "{'a':0,'b':true,'c':'c_value','d':[0,1,2],'e':[{'f1':'f1_value','f2':'f2_value'},{'g1':'g1_value','g2':'g2_value'}]}");
|
||||
assertResult(SAMPLE, false, "h.i.j.k.*", "{'a':0,'b':true,'c':'c_value','d':[0,1,2],'e':[{'f1':'f1_value','f2':'f2_value'},{'g1':'g1_value','g2':'g2_value'}]}");
|
||||
assertResult(SAMPLE, "*.i.j.k.l", false, "{'a':0,'b':true,'c':'c_value','d':[0,1,2],'e':[{'f1':'f1_value','f2':'f2_value'},{'g1':'g1_value','g2':'g2_value'}]}");
|
||||
assertResult(SAMPLE, "h.*.j.k.l", false, "{'a':0,'b':true,'c':'c_value','d':[0,1,2],'e':[{'f1':'f1_value','f2':'f2_value'},{'g1':'g1_value','g2':'g2_value'}]}");
|
||||
assertResult(SAMPLE, "h.i.*.k.l", false, "{'a':0,'b':true,'c':'c_value','d':[0,1,2],'e':[{'f1':'f1_value','f2':'f2_value'},{'g1':'g1_value','g2':'g2_value'}]}");
|
||||
assertResult(SAMPLE, "h.i.j.*.l", false, "{'a':0,'b':true,'c':'c_value','d':[0,1,2],'e':[{'f1':'f1_value','f2':'f2_value'},{'g1':'g1_value','g2':'g2_value'}]}");
|
||||
assertResult(SAMPLE, "h.i.j.k.*", false, "{'a':0,'b':true,'c':'c_value','d':[0,1,2],'e':[{'f1':'f1_value','f2':'f2_value'},{'g1':'g1_value','g2':'g2_value'}]}");
|
||||
|
||||
assertResult(SAMPLE, false, "h.*.j.*.l", "{'a':0,'b':true,'c':'c_value','d':[0,1,2],'e':[{'f1':'f1_value','f2':'f2_value'},{'g1':'g1_value','g2':'g2_value'}]}");
|
||||
assertResult(SAMPLE, false, "**.l", "{'a':0,'b':true,'c':'c_value','d':[0,1,2],'e':[{'f1':'f1_value','f2':'f2_value'},{'g1':'g1_value','g2':'g2_value'}]}");
|
||||
assertResult(SAMPLE, "h.*.j.*.l", false, "{'a':0,'b':true,'c':'c_value','d':[0,1,2],'e':[{'f1':'f1_value','f2':'f2_value'},{'g1':'g1_value','g2':'g2_value'}]}");
|
||||
assertResult(SAMPLE, "**.l", false, "{'a':0,'b':true,'c':'c_value','d':[0,1,2],'e':[{'f1':'f1_value','f2':'f2_value'},{'g1':'g1_value','g2':'g2_value'}]}");
|
||||
|
||||
assertResult(SAMPLE, false, "**.*2", "{'a':0,'b':true,'c':'c_value','d':[0,1,2],'e':[{'f1':'f1_value'},{'g1':'g1_value'}],'h':{'i':{'j':{'k':{'l':'l_value'}}}}}");
|
||||
assertResult(SAMPLE, "**.*2", false, "{'a':0,'b':true,'c':'c_value','d':[0,1,2],'e':[{'f1':'f1_value'},{'g1':'g1_value'}],'h':{'i':{'j':{'k':{'l':'l_value'}}}}}");
|
||||
|
||||
}
|
||||
|
||||
public void testInclusiveFiltersWithDots() throws Exception {
|
||||
assertResult("{'a':0,'b.c':'value','b':{'c':'c_value'}}", true, "b.c", "{'b':{'c':'c_value'}}");
|
||||
assertResult("{'a':0,'b.c':'value','b':{'c':'c_value'}}", true, "b\\.c", "{'b.c':'value'}");
|
||||
assertResult("{'a':0,'b.c':'value','b':{'c':'c_value'}}", "b.c", true, "{'b':{'c':'c_value'}}");
|
||||
assertResult("{'a':0,'b.c':'value','b':{'c':'c_value'}}", "b\\.c", true, "{'b.c':'value'}");
|
||||
}
|
||||
|
||||
public void testExclusiveFiltersWithDots() throws Exception {
|
||||
assertResult("{'a':0,'b.c':'value','b':{'c':'c_value'}}", false, "b.c", "{'a':0,'b.c':'value'}");
|
||||
assertResult("{'a':0,'b.c':'value','b':{'c':'c_value'}}", false, "b\\.c", "{'a':0,'b':{'c':'c_value'}}");
|
||||
assertResult("{'a':0,'b.c':'value','b':{'c':'c_value'}}", "b.c", false, "{'a':0,'b.c':'value'}");
|
||||
assertResult("{'a':0,'b.c':'value','b':{'c':'c_value'}}", "b\\.c", false, "{'a':0,'b':{'c':'c_value'}}");
|
||||
}
|
||||
|
||||
private void assertResult(String input, boolean inclusive, String filter, String expected) throws Exception {
|
||||
private void assertResult(String input, String filter, boolean inclusive, String expected) throws Exception {
|
||||
try (BytesStreamOutput os = new BytesStreamOutput()) {
|
||||
try (FilteringGeneratorDelegate generator = new FilteringGeneratorDelegate(JSON_FACTORY.createGenerator(os),
|
||||
new FilterPathBasedFilter(inclusive, new String[] { filter }), true, true)) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user