This is an automated email from the ASF dual-hosted git repository.
nfilotto pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new 3fc4736bc47 CAMEL-17945: Fix the unstable test
HazelcastSedaTransferExchangeTest (#7418)
3fc4736bc47 is described below
commit 3fc4736bc47b893ffea49687e2aa493470560354
Author: Nicolas Filotto <[email protected]>
AuthorDate: Tue Apr 12 18:10:38 2022 +0200
CAMEL-17945: Fix the unstable test HazelcastSedaTransferExchangeTest (#7418)
## Motivation
While working on
[CAMEL-17921](https://issues.apache.org/jira/browse/CAMEL-17921), I noticed
that the test `HazelcastSedaTransferExchangeTest` was unstable and should be
fixed.
## Modifications
* Rewrite the test `testExchangeTransferDisabled` to use the new method
`expectedNoHeaderReceived` instead of asserting for an `AssertionError`
* Cleanup the test class by renaming properly the methods annotated with
`@BeforeAll` and `@AfterAll` (not related to the issue)
* Cleanup the test class by resetting the mock endpoint in a method
annotated with `@AfterEach` (not related to the issue)
* Cleanup the test class by removing exception in the throw declaration
when not needed (not related to the issue)
---
.../HazelcastSedaTransferExchangeTest.java | 25 +++++++++++-----------
1 file changed, 12 insertions(+), 13 deletions(-)
diff --git
a/components/camel-hazelcast/src/test/java/org/apache/camel/component/hazelcast/HazelcastSedaTransferExchangeTest.java
b/components/camel-hazelcast/src/test/java/org/apache/camel/component/hazelcast/HazelcastSedaTransferExchangeTest.java
index ba7baed70c6..bcb32683bbc 100644
---
a/components/camel-hazelcast/src/test/java/org/apache/camel/component/hazelcast/HazelcastSedaTransferExchangeTest.java
+++
b/components/camel-hazelcast/src/test/java/org/apache/camel/component/hazelcast/HazelcastSedaTransferExchangeTest.java
@@ -26,12 +26,11 @@ import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.test.junit5.CamelTestSupport;
import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
-import static org.junit.jupiter.api.Assertions.assertThrows;
-
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class HazelcastSedaTransferExchangeTest extends CamelTestSupport {
@@ -41,14 +40,19 @@ public class HazelcastSedaTransferExchangeTest extends
CamelTestSupport {
private HazelcastInstance hazelcastInstance;
@BeforeAll
- public void beforeEach() {
+ public void beforeAll() {
Config config = new Config();
config.getNetworkConfig().getJoin().getAutoDetectionConfig().setEnabled(false);
hazelcastInstance = Hazelcast.newHazelcastInstance(config);
}
- @AfterAll
+ @AfterEach
public void afterEach() {
+ mock.reset();
+ }
+
+ @AfterAll
+ public void afterAll() {
if (hazelcastInstance != null) {
hazelcastInstance.shutdown();
}
@@ -68,24 +72,20 @@ public class HazelcastSedaTransferExchangeTest extends
CamelTestSupport {
template.send("direct:foobar", exchange);
assertMockEndpointsSatisfied();
- mock.reset();
}
@Test
public void testExchangeTransferDisabled() throws InterruptedException {
mock.expectedMessageCount(1);
mock.expectedBodiesReceived("test");
- mock.expectedHeaderReceived("test", "");
+ mock.expectedNoHeaderReceived();
Exchange exchange = createExchangeWithBody("test");
- exchange.getIn().setHeader("test", "fail...");
+ exchange.getIn().setHeader("test", "Not propagated");
template.send("direct:foo", exchange);
- assertThrows(AssertionError.class,
- () -> assertMockEndpointsSatisfied());
-
- mock.reset();
+ assertMockEndpointsSatisfied();
}
@Override
@@ -100,7 +100,7 @@ public class HazelcastSedaTransferExchangeTest extends
CamelTestSupport {
return new RouteBuilder() {
@Override
- public void configure() throws Exception {
+ public void configure() {
from("direct:foo").to("hazelcast-seda:foo");
from("direct:foobar").to("hazelcast-seda:foo?transferExchange=true");
@@ -109,5 +109,4 @@ public class HazelcastSedaTransferExchangeTest extends
CamelTestSupport {
}
};
}
-
}