|
12 | 12 | import org.elasticsearch.ElasticsearchParseException; |
13 | 13 | import org.elasticsearch.test.ESTestCase; |
14 | 14 |
|
| 15 | +import java.util.Arrays; |
15 | 16 | import java.util.HashMap; |
16 | 17 | import java.util.Map; |
17 | 18 |
|
@@ -93,6 +94,32 @@ private XmlProcessor createProcessor(Map<String, Object> config) throws Exceptio |
93 | 94 | return createProcessor(createFactory(), config); |
94 | 95 | } |
95 | 96 |
|
| 97 | + /** |
| 98 | + * Creates a processor mimicking the production pipeline validation. |
| 99 | + * This simulates what ConfigurationUtils.readProcessor() does. |
| 100 | + */ |
| 101 | + private XmlProcessor createProcessorWithValidation(Map<String, Object> config) throws Exception { |
| 102 | + XmlProcessor.Factory factory = createFactory(); |
| 103 | + String processorTag = randomAlphaOfLength(10); |
| 104 | + |
| 105 | + // Make a copy of the config to avoid modifying the original |
| 106 | + Map<String, Object> configCopy = new HashMap<>(config); |
| 107 | + |
| 108 | + // Create the processor (this should consume config parameters) |
| 109 | + XmlProcessor processor = factory.create(null, processorTag, null, configCopy, null); |
| 110 | + |
| 111 | + // Simulate the validation check from ConfigurationUtils.readProcessor() |
| 112 | + if (configCopy.isEmpty() == false) { |
| 113 | + throw new ElasticsearchParseException( |
| 114 | + "processor [{}] doesn't support one or more provided configuration parameters {}", |
| 115 | + "xml", |
| 116 | + Arrays.toString(configCopy.keySet().toArray()) |
| 117 | + ); |
| 118 | + } |
| 119 | + |
| 120 | + return processor; |
| 121 | + } |
| 122 | + |
96 | 123 | /** |
97 | 124 | * Helper method to create XPath configuration map. |
98 | 125 | */ |
@@ -235,7 +262,7 @@ public void testCreateWithInvalidXPathConfig() throws Exception { |
235 | 262 | Map<String, Object> config = createBaseConfig(); |
236 | 263 | config.put("xpath", "invalid_string"); // Should be a map |
237 | 264 |
|
238 | | - expectCreationFailure(config, IllegalArgumentException.class, "XPath configuration must be a map of expressions to target fields"); |
| 265 | + expectCreationFailure(config, ElasticsearchParseException.class, "[xpath] property isn't a map, but of type [java.lang.String]"); |
239 | 266 | } |
240 | 267 |
|
241 | 268 | public void testCreateWithInvalidXPathTargetField() throws Exception { |
@@ -271,7 +298,7 @@ public void testCreateWithInvalidNamespacesConfig() throws Exception { |
271 | 298 | Map<String, Object> config = createBaseConfig(); |
272 | 299 | config.put("namespaces", "invalid_string"); // Should be a map |
273 | 300 |
|
274 | | - expectCreationFailure(config, IllegalArgumentException.class, "Namespaces configuration must be a map of prefixes to URIs"); |
| 301 | + expectCreationFailure(config, ElasticsearchParseException.class, "[namespaces] property isn't a map, but of type [java.lang.String]"); |
275 | 302 | } |
276 | 303 |
|
277 | 304 | public void testCreateWithInvalidNamespaceURI() throws Exception { |
@@ -384,4 +411,25 @@ public void testCreateWithXPathUsingNamespacesWithoutConfiguration() throws Exce |
384 | 411 | "Invalid XPath expression [//book:title/text()]: contains namespace prefixes but no namespace configuration provided" |
385 | 412 | ); |
386 | 413 | } |
| 414 | + |
| 415 | + public void testConfigurationParametersAreProperlyRemoved() throws Exception { |
| 416 | + // Test that demonstrates configuration validation works when using production-like validation |
| 417 | + // This test verifies that ConfigurationUtils.readOptionalMap() properly removes parameters from config |
| 418 | + // If any are left, the processor factory should throw an exception about unknown parameters |
| 419 | + |
| 420 | + Map<String, String> xpathConfig = createXPathConfig("//test", "test_field"); |
| 421 | + Map<String, Object> config = createConfigWithXPath(DEFAULT_FIELD, xpathConfig); |
| 422 | + |
| 423 | + // Add an intentionally unknown parameter to trigger the validation |
| 424 | + config.put("unknown_parameter", "should_fail"); |
| 425 | + |
| 426 | + // This should fail because "unknown_parameter" should remain in config after all valid params are removed |
| 427 | + ElasticsearchParseException exception = expectThrows( |
| 428 | + ElasticsearchParseException.class, |
| 429 | + () -> createProcessorWithValidation(config) |
| 430 | + ); |
| 431 | + |
| 432 | + assertThat(exception.getMessage(), containsString("doesn't support one or more provided configuration parameters")); |
| 433 | + assertThat(exception.getMessage(), containsString("unknown_parameter")); |
| 434 | + } |
387 | 435 | } |
0 commit comments