Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,11 @@ private void putRule(EventBridgeClient eventbridgeClient, Exchange exchange) thr
Message message = getMessageForResponse(exchange);
message.setBody(result);
message.setHeader(EventbridgeConstants.RULE_ARN, result.ruleArn());
} else {
throw new IllegalArgumentException(
Comment thread
oscerd marked this conversation as resolved.
String.format("Expected body of type %s but was %s",
PutRuleRequest.class.getName(),
ObjectHelper.isNotEmpty(payload) ? payload.getClass().getName() : "null"));
}
} else {
PutRuleRequest.Builder builder = PutRuleRequest.builder();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* 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.eventbridge;

import org.apache.camel.Exchange;
import org.apache.camel.impl.DefaultCamelContext;
import org.apache.camel.support.DefaultExchange;
import org.junit.jupiter.api.Test;
import software.amazon.awssdk.services.eventbridge.EventBridgeClient;

import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

/**
* When {@code pojoRequest=true}, the producer must fail fast if the body is not the expected request type, rather than
* silently doing nothing (see CAMEL-24261).
*/
class EventbridgeProducerPojoRequestTest {

@Test
void putRuleWithPojoRequestAndWrongBodyTypeThrows() {
EventbridgeConfiguration configuration = new EventbridgeConfiguration();
configuration.setPojoRequest(true);
configuration.setOperation(EventbridgeOperations.putRule);

EventbridgeEndpoint endpoint = mock(EventbridgeEndpoint.class);
when(endpoint.getConfiguration()).thenReturn(configuration);
when(endpoint.getEventbridgeClient()).thenReturn(mock(EventBridgeClient.class));

EventbridgeProducer producer = new EventbridgeProducer(endpoint);

Exchange exchange = new DefaultExchange(new DefaultCamelContext());
exchange.getIn().setBody("not a PutRuleRequest");

assertThatThrownBy(() -> producer.process(exchange))
.isInstanceOf(IllegalArgumentException.class)
.hasMessageContaining("Expected body of type")
.hasMessageContaining("PutRuleRequest")
.hasMessageContaining("java.lang.String");
}
}