|
25 | 25 | import java.util.Map;
|
26 | 26 | import java.util.Set;
|
27 | 27 |
|
| 28 | +import static org.hamcrest.Matchers.arrayContainingInAnyOrder; |
28 | 29 | import static org.hamcrest.Matchers.equalTo;
|
29 | 30 |
|
30 | 31 | public class SetProcessorTests extends ESTestCase {
|
@@ -135,19 +136,47 @@ public void testSetMetadataIfPrimaryTerm() throws Exception {
|
135 | 136 | assertThat(ingestDocument.getFieldValue(Metadata.IF_PRIMARY_TERM.getFieldName(), Long.class), Matchers.equalTo(ifPrimaryTerm));
|
136 | 137 | }
|
137 | 138 |
|
138 |
| - @AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/69876") |
139 | 139 | public void testCopyFromOtherField() throws Exception {
|
140 | 140 | Map<String, Object> document = new HashMap<>();
|
141 | 141 | Object fieldValue = RandomDocumentPicks.randomFieldValue(random());
|
142 | 142 | document.put("field", fieldValue);
|
143 | 143 |
|
144 | 144 | IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), document);
|
145 |
| - String fieldName = RandomDocumentPicks.randomExistingFieldName(random(), ingestDocument); |
| 145 | + String fieldName; |
| 146 | + if (document.size() > 1) { |
| 147 | + // select an existing field as target if one exists other than the copy_from field |
| 148 | + do { |
| 149 | + fieldName = RandomDocumentPicks.randomExistingFieldName(random(), ingestDocument); |
| 150 | + } while (fieldName.equals("field") || fieldName.startsWith("field.")); |
| 151 | + } else { |
| 152 | + // otherwise make up a new target field |
| 153 | + fieldName = randomAlphaOfLength(6); |
| 154 | + } |
146 | 155 |
|
147 | 156 | Processor processor = createSetProcessor(fieldName, null, "field", true, false);
|
148 | 157 | processor.execute(ingestDocument);
|
149 | 158 | assertThat(ingestDocument.hasField(fieldName), equalTo(true));
|
150 |
| - assertThat(ingestDocument.getFieldValue(fieldName, Object.class), equalTo(fieldValue)); |
| 159 | + Object copiedValue = ingestDocument.getFieldValue(fieldName, Object.class); |
| 160 | + if (fieldValue instanceof Map) { |
| 161 | + assertMapEquals(copiedValue, fieldValue); |
| 162 | + } else { |
| 163 | + assertThat(copiedValue, equalTo(fieldValue)); |
| 164 | + } |
| 165 | + } |
| 166 | + |
| 167 | + private static void assertMapEquals(Object actual, Object expected) { |
| 168 | + if (expected instanceof Map) { |
| 169 | + Map<?, ?> expectedMap = (Map<?, ?>) expected; |
| 170 | + Map<?, ?> actualMap = (Map<?, ?>) actual; |
| 171 | + assertThat(actualMap.keySet().toArray(), arrayContainingInAnyOrder(expectedMap.keySet().toArray())); |
| 172 | + for (Map.Entry<?, ?> entry : actualMap.entrySet()) { |
| 173 | + if (entry.getValue() instanceof Map) { |
| 174 | + assertMapEquals(entry.getValue(), expectedMap.get(entry.getKey())); |
| 175 | + } else { |
| 176 | + assertThat(entry.getValue(), equalTo(expectedMap.get(entry.getKey()))); |
| 177 | + } |
| 178 | + } |
| 179 | + } |
151 | 180 | }
|
152 | 181 |
|
153 | 182 | public void testCopyFromDeepCopiesNonPrimitiveMutableTypes() throws Exception {
|
|
0 commit comments