oscerd commented on code in PR #26746:
URL: https://github.com/apache/camel/pull/26746#discussion_r4072060373
##########
components/camel-aws/camel-aws2-s3/src/test/java/org/apache/camel/component/aws2/s3/utils/AWS2S3UtilsTest.java:
##########
@@ -84,4 +86,74 @@ void suffixNullOrEmptyReturnsEmptyString() {
assertEquals("", AWS2S3Utils.evaluateDestinationBucketSuffix(exchange,
config));
}
+
+ // ---- determineKey ----
+
+ @Test
+ void keyFromHeaderIsUsedLiterallyAndNotEvaluated() {
+ Exchange exchange = createExchangeWithBody("body");
+ // a key coming from the header (e.g. inherited from a consumed object
name) must be used as-is
+ exchange.getIn().setHeader(AWS2S3Constants.KEY,
"${sys.user.name}.txt");
+ AWS2S3Configuration config = new AWS2S3Configuration();
+
+ assertEquals("${sys.user.name}.txt",
AWS2S3Utils.determineKey(exchange, config));
+ }
+
+ @Test
+ void keyFromConfigurationIsEvaluatedAsSimpleExpression() {
+ Exchange exchange = createExchangeWithBody("body");
+ exchange.getIn().setHeader("name", "report");
+ AWS2S3Configuration config = new AWS2S3Configuration();
+ config.setKeyName("${header.name}.txt");
+
+ assertEquals("report.txt", AWS2S3Utils.determineKey(exchange, config));
+ }
+
+ @Test
+ void keyFromHeaderTakesPrecedenceOverConfiguration() {
+ Exchange exchange = createExchangeWithBody("body");
+ exchange.getIn().setHeader(AWS2S3Constants.KEY, "literal-key");
+ AWS2S3Configuration config = new AWS2S3Configuration();
+ config.setKeyName("${header.name}.txt");
+
+ assertEquals("literal-key", AWS2S3Utils.determineKey(exchange,
config));
+ }
+
+ @Test
+ void keyMissingFromHeaderAndConfigurationThrows() {
+ Exchange exchange = createExchangeWithBody("body");
+ AWS2S3Configuration config = new AWS2S3Configuration();
+
+ assertThrows(IllegalArgumentException.class, () ->
AWS2S3Utils.determineKey(exchange, config));
+ }
+
+ // ---- determineBucketName ----
+
+ @Test
+ void bucketFromOverrideHeaderIsUsedLiterallyAndNotEvaluated() {
+ Exchange exchange = createExchangeWithBody("body");
+ exchange.getIn().setHeader(AWS2S3Constants.OVERRIDE_BUCKET_NAME,
"${sys.user.name}-bucket");
+ AWS2S3Configuration config = new AWS2S3Configuration();
+ config.setBucketName("configured-bucket");
+
+ assertEquals("${sys.user.name}-bucket",
AWS2S3Utils.determineBucketName(exchange, config));
+ }
+
+ @Test
+ void bucketFromConfigurationIsEvaluatedAsSimpleExpression() {
+ Exchange exchange = createExchangeWithBody("body");
+ exchange.getIn().setHeader("env", "prod");
+ AWS2S3Configuration config = new AWS2S3Configuration();
+ config.setBucketName("bucket-${header.env}");
+
+ assertEquals("bucket-prod", AWS2S3Utils.determineBucketName(exchange,
config));
+ }
+
+ @Test
+ void bucketMissingFromHeaderAndConfigurationThrows() {
+ Exchange exchange = createExchangeWithBody("body");
+ AWS2S3Configuration config = new AWS2S3Configuration();
+
+ assertThrows(IllegalArgumentException.class, () ->
AWS2S3Utils.determineBucketName(exchange, config));
Review Comment:
Added `bucketOverrideHeaderTakesPrecedenceOverConfiguration` in 4c488bf,
mirroring the key precedence test. Thanks for the catch.
_Claude Code on behalf of Andrea Cosentino_
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]