Skip to content

Commit dd017ea

Browse files
committed
fix test
1 parent 1bb7c4d commit dd017ea

File tree

2 files changed

+23
-14
lines changed

2 files changed

+23
-14
lines changed

server/src/test/java/org/elasticsearch/index/mapper/PatchSourceMapperTests.java

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
/*
22
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3-
* or more contributor license agreements. Licensed under the Elastic License
4-
* 2.0 and the Server Side Public License, v 1; you may not use this file except
5-
* in compliance with, at your election, the Elastic License 2.0 or the Server
6-
* Side Public License, v 1.
3+
* or more contributor license agreements. Licensed under the "Elastic License
4+
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
5+
* Public License v 1"; you may not use this file except in compliance with, at
6+
* your election, the "Elastic License 2.0", the "GNU Affero General Public
7+
* License v3.0 only", or the "Server Side Public License, v 1".
78
*/
89

910
package org.elasticsearch.index.mapper;
@@ -65,6 +66,11 @@ public void testPatchSourceFlatWithCopyTo() throws IOException {
6566
b.startObject("another_field");
6667
b.field("type", "keyword");
6768
b.endObject();
69+
70+
// another_field
71+
b.startObject("extra_field");
72+
b.field("type", "keyword");
73+
b.endObject();
6874
}));
6975
assertSourcePatch(mapperService, Map.of("field", "key1"));
7076
}
@@ -94,7 +100,7 @@ public void testPatchSourceFlatMulti() throws IOException {
94100
)
95101
);
96102
assertThat(exc.status(), equalTo(RestStatus.BAD_REQUEST));
97-
assertThat(exc.getDetailedMessage(), containsString("doesn't support patching multiple values"));
103+
assertThat(exc.getDetailedMessage(), containsString("[field] does not support patching multiple values"));
98104
}
99105

100106
public void testPatchSourceObject() throws IOException {
@@ -394,7 +400,9 @@ protected BinaryPatchSourceFieldMapper(String simpleName, BinaryFieldMapper dele
394400

395401
@Override
396402
protected void parseCreateField(DocumentParserContext context) throws IOException {
397-
context.addSourceFieldPatch(this, context.parser().getTokenLocation());
403+
if (context.isWithinCopyTo() == false) {
404+
context.addSourceFieldPatch(this, context.parser().getTokenLocation());
405+
}
398406
XContentBuilder b = XContentBuilder.builder(context.parser().contentType().xContent());
399407
b.copyCurrentStructure(context.parser());
400408
context.doc().add(new BinaryDocValuesField(fullPath(), BytesReference.bytes(b).toBytesRef()));
@@ -426,7 +434,7 @@ protected void writeValue(XContentBuilder b, BytesRef value) throws IOException
426434

427435
@Override
428436
protected SourceLoader.PatchFieldLoader patchFieldLoader() {
429-
return new SourceLoader.SyntheticPatchFieldLoader(syntheticFieldLoader());
437+
return new SourceLoader.SyntheticPatchFieldLoader(syntheticSourceSupport().loader());
430438
}
431439
}
432440
}

server/src/test/java/org/elasticsearch/index/mapper/SourceFieldMapperTests.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ public void testWrongLocationPatchSourceInPostParse() throws Exception {
567567
XContentType.JSON
568568
)
569569
) {
570-
DocumentParserContext context = new TestDocumentParserContext(MappingLookup.EMPTY, sourceToParse) {
570+
DocumentParserContext context = new TestDocumentParserContext(mapperService.mappingLookup(), sourceToParse) {
571571
@Override
572572
public XContentParser parser() {
573573
return parser;
@@ -576,7 +576,7 @@ public XContentParser parser() {
576576
var xContentLocation = new XContentLocation(0, 3);
577577
context.addSourceFieldPatch(fieldMapper, xContentLocation);
578578
var exc = expectThrows(IllegalArgumentException.class, () -> mapper.postParse(context));
579-
assertThat(exc.getMessage(), containsString("Cannot find patch"));
579+
assertThat(exc.getMessage(), containsString("Registered patch not found"));
580580
}
581581
}
582582

@@ -594,15 +594,16 @@ public void testRemainingPatchSourceInPostParse() throws Exception {
594594
XContentBuilder builder = JsonXContent.contentBuilder();
595595
builder.value(Map.of("another_field", 45));
596596
var sourceToParse = new SourceToParse("0", BytesReference.bytes(builder), builder.contentType());
597-
FieldMapper fieldMapper = (FieldMapper) mapperService.mappingLookup().getMapper("field");
597+
var fieldMapper = (FieldMapper) mapperService.mappingLookup().getMapper("field");
598+
var anotherFieldMapper = (FieldMapper) mapperService.mappingLookup().getMapper("another_field");
598599
try (
599600
var parser = XContentHelper.createParserNotCompressed(
600601
XContentParserConfiguration.EMPTY,
601602
sourceToParse.source(),
602603
XContentType.JSON
603604
)
604605
) {
605-
DocumentParserContext context = new TestDocumentParserContext(MappingLookup.EMPTY, sourceToParse) {
606+
DocumentParserContext context = new TestDocumentParserContext(mapperService.mappingLookup(), sourceToParse) {
606607
@Override
607608
public XContentParser parser() {
608609
return parser;
@@ -612,13 +613,13 @@ public XContentParser parser() {
612613
context.addSourceFieldPatch(fieldMapper, xContentLocation1);
613614
{
614615
var exc = expectThrows(IllegalArgumentException.class, () -> context.addSourceFieldPatch(fieldMapper, xContentLocation1));
615-
assertThat(exc.getMessage(), containsString(xContentLocation1.toString()));
616+
assertThat(exc.getMessage(), containsString("Field [field] does not support patching the same location "));
616617
}
617618
var xContentLocation2 = new XContentLocation(2, 6);
618-
context.addSourceFieldPatch(fieldMapper, xContentLocation2);
619+
context.addSourceFieldPatch(anotherFieldMapper, xContentLocation2);
619620

620621
var exc = expectThrows(IllegalArgumentException.class, () -> mapper.postParse(context));
621-
assertThat(exc.getMessage(), allOf(containsString(xContentLocation2.toString()), containsString(xContentLocation1.toString())));
622+
assertThat(exc.getMessage(), containsString("Registered patch not found"));
622623
}
623624
}
624625
}

0 commit comments

Comments
 (0)