Skip to content
Open
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
5 changes: 5 additions & 0 deletions components/camel-aws/camel-aws2-mq/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,10 @@
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ public class MQ2Producer extends DefaultProducer {

private static final Logger LOG = LoggerFactory.getLogger(MQ2Producer.class);
public static final String MISSING_BROKER_NAME = "Broker Name must be specified";
public static final String MISSING_BROKER_ID = "Broker Id must be specified";
public static final String MISSING_CONFIGURATION_ID = "Configuration Id must be specified";

private transient String mqProducerToString;
private HealthCheck producerHealthCheck;
Expand Down Expand Up @@ -247,7 +249,7 @@ private void deleteBroker(MqClient mqClient, Exchange exchange) throws InvalidPa
brokerId = exchange.getIn().getHeader(MQ2Constants.BROKER_ID, String.class);
builder.brokerId(brokerId);
} else {
throw new IllegalArgumentException(MISSING_BROKER_NAME);
throw new IllegalArgumentException(MISSING_BROKER_ID);
}
DeleteBrokerResponse result;
try {
Expand Down Expand Up @@ -282,7 +284,7 @@ private void rebootBroker(MqClient mqClient, Exchange exchange) throws InvalidPa
brokerId = exchange.getIn().getHeader(MQ2Constants.BROKER_ID, String.class);
builder.brokerId(brokerId);
} else {
throw new IllegalArgumentException(MISSING_BROKER_NAME);
throw new IllegalArgumentException(MISSING_BROKER_ID);
}
RebootBrokerResponse result;
try {
Expand Down Expand Up @@ -318,13 +320,13 @@ private void updateBroker(MqClient mqClient, Exchange exchange) throws InvalidPa
brokerId = exchange.getIn().getHeader(MQ2Constants.BROKER_ID, String.class);
builder.brokerId(brokerId);
} else {
throw new IllegalArgumentException(MISSING_BROKER_NAME);
throw new IllegalArgumentException(MISSING_BROKER_ID);
}
if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(MQ2Constants.CONFIGURATION_ID))) {
configurationId = exchange.getIn().getHeader(MQ2Constants.CONFIGURATION_ID, ConfigurationId.class);
builder.configuration(configurationId);
} else {
throw new IllegalArgumentException(MISSING_BROKER_NAME);
throw new IllegalArgumentException(MISSING_CONFIGURATION_ID);
}
UpdateBrokerResponse result;
try {
Expand Down Expand Up @@ -359,7 +361,7 @@ private void describeBroker(MqClient mqClient, Exchange exchange) throws Invalid
brokerId = exchange.getIn().getHeader(MQ2Constants.BROKER_ID, String.class);
builder.brokerId(brokerId);
} else {
throw new IllegalArgumentException(MISSING_BROKER_NAME);
throw new IllegalArgumentException(MISSING_BROKER_ID);
}
DescribeBrokerResponse result;
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import software.amazon.awssdk.services.mq.model.UpdateBrokerResponse;
import software.amazon.awssdk.services.mq.model.User;

import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.jupiter.api.Assertions.assertEquals;

public class MQProducerTest extends CamelTestSupport {
Expand Down Expand Up @@ -172,6 +173,22 @@ public void process(Exchange exchange) {
assertEquals("1", resultGet.brokerId());
}

@Test
void mqUpdateBrokerWithoutBrokerIdReportsThatParameter() {
assertThatThrownBy(() -> template.requestBody("direct:updateBroker", "body"))
.hasRootCauseInstanceOf(IllegalArgumentException.class)
.hasRootCauseMessage("Broker Id must be specified");
}

@Test
void mqUpdateBrokerWithoutConfigurationIdReportsThatParameter() {
// the broker id IS supplied, so the error must name the missing configuration id
assertThatThrownBy(() -> template.requestBodyAndHeader("direct:updateBroker", "body",
MQ2Constants.BROKER_ID, "1"))
.hasRootCauseInstanceOf(IllegalArgumentException.class)
.hasRootCauseMessage("Configuration Id must be specified");
}

@Test
public void mqDescribeBrokerTest() throws Exception {

Expand Down
5 changes: 5 additions & 0 deletions components/camel-aws/camel-aws2-msk/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,10 @@
<artifactId>camel-test-spring-junit5</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ private void createCluster(KafkaClient mskClient, Exchange exchange) throws Inva
Integer nodesNumber = exchange.getIn().getHeader(MSK2Constants.BROKER_NODES_NUMBER, Integer.class);
builder.numberOfBrokerNodes(nodesNumber);
} else {
throw new IllegalArgumentException("Kafka Version must be specified");
throw new IllegalArgumentException("Number of Broker Nodes must be specified");
}
if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(MSK2Constants.BROKER_NODES_GROUP_INFO))) {
BrokerNodeGroupInfo brokerNodesGroupInfo
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*/
package org.apache.camel.component.aws2.msk;

import java.util.Map;

import org.apache.camel.BindToRegistry;
import org.apache.camel.EndpointInject;
import org.apache.camel.Exchange;
Expand All @@ -32,6 +34,7 @@
import software.amazon.awssdk.services.kafka.model.ListClustersRequest;
import software.amazon.awssdk.services.kafka.model.ListClustersResponse;

import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.jupiter.api.Assertions.assertEquals;

public class MSKProducerTest extends CamelTestSupport {
Expand Down Expand Up @@ -99,6 +102,17 @@ public void process(Exchange exchange) {
assertEquals(ClusterState.CREATING.name(), resultGet.state().toString());
}

@Test
void mskCreateClusterWithoutBrokerNodesNumberReportsThatParameter() {
// the Kafka version IS supplied, so the error must name the missing broker-nodes count
assertThatThrownBy(() -> template.requestBodyAndHeaders("direct:createCluster", "body",
Map.of(
MSK2Constants.CLUSTER_NAME, "test-kafka",
MSK2Constants.CLUSTER_KAFKA_VERSION, "2.1.1")))
.hasRootCauseInstanceOf(IllegalArgumentException.class)
.hasRootCauseMessage("Number of Broker Nodes must be specified");
}

@Test
public void mskDeleteClusterTest() throws Exception {

Expand Down
5 changes: 5 additions & 0 deletions components/camel-aws/camel-aws2-sts/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,10 @@
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ private void getFederationToken(StsClient stsClient, Exchange exchange) throws I
String federatedName = exchange.getIn().getHeader(STS2Constants.FEDERATED_NAME, String.class);
builder.name(federatedName);
} else {
throw new IllegalArgumentException("Federated name needs to be specified for assumeRole operation");
throw new IllegalArgumentException("Federated name needs to be specified for getFederationToken operation");
}
try {
result = stsClient.getFederationToken(builder.build());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import software.amazon.awssdk.services.sts.model.GetFederationTokenResponse;
import software.amazon.awssdk.services.sts.model.GetSessionTokenResponse;

import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.jupiter.api.Assertions.assertEquals;

public class STS2ProducerTest extends CamelTestSupport {
Expand Down Expand Up @@ -92,6 +93,13 @@ public void process(Exchange exchange) {
assertEquals("xxx", resultGet.credentials().accessKeyId());
}

@Test
void stsGetFederationTokenWithoutFederatedNameReportsTheCorrectOperation() {
assertThatThrownBy(() -> template.requestBody("direct:getFederationToken", "body"))
.hasRootCauseInstanceOf(IllegalArgumentException.class)
.hasRootCauseMessage("Federated name needs to be specified for getFederationToken operation");
}

@Override
protected RouteBuilder createRouteBuilder() {
return new RouteBuilder() {
Expand Down
Loading