davsclaus commented on code in PR #30438: URL: https://github.com/apache/camel/pull/30438#discussion_r4632451668
########## components/camel-aws/camel-aws2-lambda/src/test/java/org/apache/camel/component/aws2/lambda/LambdaProducerInvocationTypeTest.java: ########## @@ -0,0 +1,125 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.component.aws2.lambda; + +import java.nio.charset.StandardCharsets; +import java.util.Base64; +import java.util.Map; + +import org.apache.camel.BindToRegistry; +import org.apache.camel.Exchange; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.test.junit6.CamelTestSupport; +import org.junit.jupiter.api.Test; +import software.amazon.awssdk.core.SdkBytes; +import software.amazon.awssdk.services.lambda.model.InvocationType; +import software.amazon.awssdk.services.lambda.model.InvokeRequest; +import software.amazon.awssdk.services.lambda.model.InvokeResponse; +import software.amazon.awssdk.services.lambda.model.LogType; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; + +/** + * The invocation type and the log type of invokeFunction come from the headers, else from the endpoint options. + */ +public class LambdaProducerInvocationTypeTest extends CamelTestSupport { + + private static final String LOG = Base64.getEncoder().encodeToString("START RequestId: 1".getBytes(StandardCharsets.UTF_8)); + + @BindToRegistry("awsLambdaClient") + AmazonLambdaClientMock clientMock = new AmazonLambdaClientMock() { + @Override + public InvokeResponse invoke(InvokeRequest invokeRequest) { + this.invokeRequest = invokeRequest; + InvokeResponse.Builder response = InvokeResponse.builder(); + if (invokeRequest.invocationType() == InvocationType.EVENT) { + // Lambda queues the event and answers at once without a payload + return response.statusCode(202).payload(SdkBytes.fromUtf8String("")).build(); + } + response.statusCode(200).payload(SdkBytes.fromUtf8String("{\"Hello\":\"Camel\"}")); + if (invokeRequest.logType() == LogType.TAIL) { + response.logResult(LOG); + } + return response.build(); + } + }; + + @Test + public void defaultIsRequestResponseWithoutLog() { Review Comment: Done in 401a61d6a0d: the mock answers a DryRun invocation with status code 204 and an empty payload. _Claude Code on behalf of Claus Ibsen_ ########## components/camel-aws/camel-aws2-lambda/src/test/java/org/apache/camel/component/aws2/lambda/LambdaProducerInvocationTypeTest.java: ########## @@ -0,0 +1,125 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.component.aws2.lambda; + +import java.nio.charset.StandardCharsets; +import java.util.Base64; +import java.util.Map; + +import org.apache.camel.BindToRegistry; +import org.apache.camel.Exchange; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.test.junit6.CamelTestSupport; +import org.junit.jupiter.api.Test; +import software.amazon.awssdk.core.SdkBytes; +import software.amazon.awssdk.services.lambda.model.InvocationType; +import software.amazon.awssdk.services.lambda.model.InvokeRequest; +import software.amazon.awssdk.services.lambda.model.InvokeResponse; +import software.amazon.awssdk.services.lambda.model.LogType; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; + +/** + * The invocation type and the log type of invokeFunction come from the headers, else from the endpoint options. + */ +public class LambdaProducerInvocationTypeTest extends CamelTestSupport { + + private static final String LOG = Base64.getEncoder().encodeToString("START RequestId: 1".getBytes(StandardCharsets.UTF_8)); + + @BindToRegistry("awsLambdaClient") + AmazonLambdaClientMock clientMock = new AmazonLambdaClientMock() { + @Override + public InvokeResponse invoke(InvokeRequest invokeRequest) { + this.invokeRequest = invokeRequest; + InvokeResponse.Builder response = InvokeResponse.builder(); + if (invokeRequest.invocationType() == InvocationType.EVENT) { + // Lambda queues the event and answers at once without a payload + return response.statusCode(202).payload(SdkBytes.fromUtf8String("")).build(); + } + response.statusCode(200).payload(SdkBytes.fromUtf8String("{\"Hello\":\"Camel\"}")); + if (invokeRequest.logType() == LogType.TAIL) { + response.logResult(LOG); + } + return response.build(); + } + }; + + @Test + public void defaultIsRequestResponseWithoutLog() { + Exchange exchange = template.request("direct:default", e -> e.getIn().setBody("{\"name\":\"Camel\"}")); + + assertEquals(InvocationType.REQUEST_RESPONSE, clientMock.invokeRequest.invocationType()); + assertEquals(LogType.NONE, clientMock.invokeRequest.logType()); + assertEquals("{\"Hello\":\"Camel\"}", exchange.getMessage().getBody(String.class)); + assertEquals(200, exchange.getMessage().getHeader(Lambda2Constants.STATUS_CODE)); + assertNull(exchange.getMessage().getHeader(Lambda2Constants.LOG_RESULT)); + } + + @Test + public void eventFromTheOption() { + Exchange exchange = template.request("direct:event", e -> e.getIn().setBody("{\"name\":\"Camel\"}")); + + assertEquals(InvocationType.EVENT, clientMock.invokeRequest.invocationType()); + assertEquals(202, exchange.getMessage().getHeader(Lambda2Constants.STATUS_CODE)); + assertEquals("", exchange.getMessage().getBody(String.class)); + } + + @Test + public void headerOverridesTheOption() { + template.sendBodyAndHeader("direct:event", "{\"name\":\"Camel\"}", Lambda2Constants.INVOCATION_TYPE, + "DryRun"); + + assertEquals(InvocationType.DRY_RUN, clientMock.invokeRequest.invocationType()); + } + + @Test + public void tailFromTheOptionFillsTheLogResult() { + Exchange exchange = template.request("direct:tail", e -> e.getIn().setBody("{\"name\":\"Camel\"}")); + Review Comment: Done in 401a61d6a0d: the test now uses `template.request` and checks the 204 status code and the empty body. _Claude Code on behalf of Claus Ibsen_ -- 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]
