-
Notifications
You must be signed in to change notification settings - Fork 165
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CAMEL-17938 Add tests in camel-aws2-cw-starter
- Loading branch information
1 parent
3498fca
commit 2086d85
Showing
3 changed files
with
160 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
...tarter/camel-aws2-cw-starter/src/test/java/org/apache/camel/component/aws2/cw/BaseCw.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* 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.cw; | ||
|
||
import org.apache.camel.CamelContext; | ||
import org.apache.camel.Configuration; | ||
import org.apache.camel.ProducerTemplate; | ||
import org.apache.camel.component.mock.MockEndpoint; | ||
import org.apache.camel.test.infra.aws2.clients.AWSSDKClientUtils; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
import org.apache.camel.test.infra.aws.common.services.AWSService; | ||
import org.apache.camel.test.infra.aws2.services.AWSServiceFactory; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.context.annotation.Bean; | ||
import software.amazon.awssdk.services.cloudwatch.CloudWatchClient; | ||
|
||
public class BaseCw { | ||
|
||
@Autowired | ||
protected CamelContext context; | ||
|
||
@Autowired | ||
protected ProducerTemplate template; | ||
|
||
@RegisterExtension | ||
public static AWSService service = AWSServiceFactory.createCloudWatchService(); | ||
|
||
protected void assertMockEndpointsSatisfied() throws InterruptedException { | ||
MockEndpoint.assertIsSatisfied(this.context); | ||
} | ||
|
||
// ************************************* | ||
// Config | ||
// ************************************* | ||
|
||
@Configuration | ||
public static class TestConfiguration { | ||
|
||
@Bean | ||
public CloudWatchClient cloudWatchClient() { | ||
return AWSSDKClientUtils.newCloudWatchClient(); | ||
} | ||
} | ||
} |
95 changes: 95 additions & 0 deletions
95
...mel-aws2-cw-starter/src/test/java/org/apache/camel/component/aws2/cw/CwComponentTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
/* | ||
* 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.cw; | ||
|
||
import org.apache.camel.Configuration; | ||
import org.apache.camel.EndpointInject; | ||
import org.apache.camel.Exchange; | ||
import org.apache.camel.ExchangePattern; | ||
import org.apache.camel.Processor; | ||
import org.apache.camel.builder.RouteBuilder; | ||
import org.apache.camel.component.mock.MockEndpoint; | ||
import org.apache.camel.spring.boot.CamelAutoConfiguration; | ||
import org.apache.camel.test.infra.aws2.clients.AWSSDKClientUtils; | ||
import org.apache.camel.test.spring.junit5.CamelSpringBootTest; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.test.annotation.DirtiesContext; | ||
import software.amazon.awssdk.services.cloudwatch.CloudWatchClient; | ||
import software.amazon.awssdk.services.cloudwatch.model.GetMetricDataRequest; | ||
import software.amazon.awssdk.services.cloudwatch.model.ListMetricsRequest; | ||
import software.amazon.awssdk.services.cloudwatch.model.ListMetricsResponse; | ||
|
||
import java.time.Instant; | ||
|
||
//Based on CwComponentIT | ||
@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_CLASS) | ||
@CamelSpringBootTest | ||
@SpringBootTest( | ||
classes = { | ||
CamelAutoConfiguration.class, | ||
CwComponentTest.class, | ||
CwComponentTest.TestConfiguration.class | ||
} | ||
) | ||
public class CwComponentTest extends BaseCw { | ||
|
||
@EndpointInject("mock:result") | ||
private MockEndpoint mock; | ||
|
||
@Test | ||
public void sendInOnly() throws Exception { | ||
mock.expectedMessageCount(1); | ||
|
||
Exchange e = template.send("direct:start", ExchangePattern.InOnly, new Processor() { | ||
public void process(Exchange exchange) { | ||
exchange.getIn().setHeader(Cw2Constants.METRIC_NAME, "ExchangesCompleted"); | ||
exchange.getIn().setHeader(Cw2Constants.METRIC_DIMENSION_NAME, "dimension"); | ||
exchange.getIn().setHeader(Cw2Constants.METRIC_VALUE, "2.0"); | ||
exchange.getIn().setHeader(Cw2Constants.METRIC_UNIT, "Count"); | ||
} | ||
}); | ||
|
||
assertMockEndpointsSatisfied(); | ||
|
||
CloudWatchClient client = AWSSDKClientUtils.newCloudWatchClient(); | ||
ListMetricsResponse resp = client.listMetrics( ListMetricsRequest.builder().namespace("http://camel.apache.org/aws-cw").build()); | ||
|
||
Assertions.assertEquals(1, resp.metrics().size()); | ||
Assertions.assertEquals("ExchangesCompleted", resp.metrics().get(0).metricName()); | ||
} | ||
|
||
// ************************************* | ||
// Config | ||
// ************************************* | ||
|
||
@Configuration | ||
public class TestConfiguration extends BaseCw.TestConfiguration { | ||
@Bean | ||
public RouteBuilder routeBuilder() { | ||
return new RouteBuilder() { | ||
@Override | ||
public void configure() { | ||
from("direct:start").to("aws2-cw://http://camel.apache.org/aws-cw") | ||
.to("mock:result"); | ||
} | ||
}; | ||
} | ||
} | ||
} |