diff --git a/core/camel-core/src/test/java/org/apache/camel/component/file/FileInvalidStartingPathTest.java b/core/camel-core/src/test/java/org/apache/camel/component/file/FileInvalidStartingPathTest.java index 506ecf0c4ef6e..e6f5ec17d18b0 100644 --- a/core/camel-core/src/test/java/org/apache/camel/component/file/FileInvalidStartingPathTest.java +++ b/core/camel-core/src/test/java/org/apache/camel/component/file/FileInvalidStartingPathTest.java @@ -17,13 +17,17 @@ package org.apache.camel.component.file; import org.apache.camel.ContextTestSupport; +import org.apache.camel.Endpoint; import org.apache.camel.ResolveEndpointFailedException; import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; +import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; -public class FileInvalidStartingPathTest extends ContextTestSupport { +class FileInvalidStartingPathTest extends ContextTestSupport { @Test public void testInvalidStartingPath() { @@ -35,9 +39,17 @@ public void testInvalidStartingPath() { } @Test - public void testValidStartingPath() { - context.getEndpoint( + void testValidStartingPath() { + Endpoint endpoint = context.getEndpoint( fileUri("?fileName=${date:now:yyyyMMdd}/${in.header.messageType}-${date:now:hhmmss}.txt")); + assertNotNull(endpoint, "Endpoint should be resolved for a valid starting path"); + FileEndpoint fileEndpoint = assertInstanceOf(FileEndpoint.class, endpoint); + assertNotNull(fileEndpoint.getFileName(), "FileEndpoint should have a fileName expression set"); + assertNotNull(fileEndpoint.getConfiguration().getDirectory(), + "FileEndpoint should have a directory configured"); + assertEquals("${date:now:yyyyMMdd}/${in.header.messageType}-${date:now:hhmmss}.txt", + fileEndpoint.getFileName().toString(), + "FileEndpoint fileName expression should match the configured value"); } } diff --git a/core/camel-core/src/test/java/org/apache/camel/component/file/FileProduceTempPrefixTest.java b/core/camel-core/src/test/java/org/apache/camel/component/file/FileProduceTempPrefixTest.java index 2ddf90bf71450..5345f4325fbbb 100644 --- a/core/camel-core/src/test/java/org/apache/camel/component/file/FileProduceTempPrefixTest.java +++ b/core/camel-core/src/test/java/org/apache/camel/component/file/FileProduceTempPrefixTest.java @@ -16,7 +16,11 @@ */ package org.apache.camel.component.file; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.List; import java.util.UUID; +import java.util.stream.Stream; import org.apache.camel.ContextTestSupport; import org.apache.camel.Endpoint; @@ -24,10 +28,13 @@ import org.apache.camel.builder.RouteBuilder; import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; + /** * Unit test for file producer option tempPrefix */ -public class FileProduceTempPrefixTest extends ContextTestSupport { +class FileProduceTempPrefixTest extends ContextTestSupport { private static final String TEST_FILE_NAME_1 = "hello" + UUID.randomUUID() + ".txt"; private static final String TEST_FILE_NAME_2 = "claus" + UUID.randomUUID() + ".txt"; @@ -74,8 +81,18 @@ public void testTempPrefix() { } @Test - public void testTempPrefixUUIDFilename() { + void testTempPrefixUUIDFilename() throws Exception { template.sendBody("direct:a", "Bye World"); + + // When no FILE_NAME header is set, the producer creates a file with an auto-generated UUID name + List files; + try (Stream stream = Files.list(testDirectory())) { + files = stream.toList(); + } + assertNotNull(files, "Test directory should contain files"); + assertEquals(1, files.size(), "exactly one file should have been created"); + String content = Files.readString(files.get(0)); + assertEquals("Bye World", content, "File content should match the body that was sent"); } @Override diff --git a/core/camel-core/src/test/java/org/apache/camel/component/validator/CustomSchemaFactoryFeatureTest.java b/core/camel-core/src/test/java/org/apache/camel/component/validator/CustomSchemaFactoryFeatureTest.java index 47f6e2713ac34..54065f95b350d 100644 --- a/core/camel-core/src/test/java/org/apache/camel/component/validator/CustomSchemaFactoryFeatureTest.java +++ b/core/camel-core/src/test/java/org/apache/camel/component/validator/CustomSchemaFactoryFeatureTest.java @@ -20,10 +20,16 @@ import javax.xml.validation.SchemaFactory; import org.apache.camel.ContextTestSupport; +import org.apache.camel.Endpoint; import org.apache.camel.spi.Registry; import org.junit.jupiter.api.Test; -public class CustomSchemaFactoryFeatureTest extends ContextTestSupport { +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertSame; + +class CustomSchemaFactoryFeatureTest extends ContextTestSupport { // Need to bind the CustomerSchemaFactory @Override protected Registry createCamelRegistry() throws Exception { @@ -36,11 +42,21 @@ protected Registry createCamelRegistry() throws Exception { // just inject the SchemaFactory as we want @Test - public void testCustomSchemaFactory() throws Exception { + void testCustomSchemaFactory() throws Exception { + SchemaFactory registeredFactory = (SchemaFactory) context.getRegistry().lookupByName("MySchemaFactory"); + ValidatorComponent v = new ValidatorComponent(); v.setCamelContext(context); v.init(); - v.createEndpoint("validator:org/apache/camel/component/validator/unsecuredSchema.xsd?schemaFactory=#MySchemaFactory"); + Endpoint endpoint = v.createEndpoint( + "validator:org/apache/camel/component/validator/unsecuredSchema.xsd?schemaFactory=#MySchemaFactory"); + assertNotNull(endpoint, "Endpoint should be created with a custom SchemaFactory"); + ValidatorEndpoint ve = assertInstanceOf(ValidatorEndpoint.class, endpoint); + assertNotNull(ve.getSchemaFactory(), "Endpoint should have the custom SchemaFactory configured"); + assertSame(registeredFactory, ve.getSchemaFactory(), + "Endpoint should use the same SchemaFactory instance that was registered"); + assertFalse(ve.getSchemaFactory().getFeature(XMLConstants.FEATURE_SECURE_PROCESSING), + "Custom SchemaFactory should have FEATURE_SECURE_PROCESSING set to false"); } } diff --git a/core/camel-core/src/test/java/org/apache/camel/converter/jaxp/XmlConverterTest.java b/core/camel-core/src/test/java/org/apache/camel/converter/jaxp/XmlConverterTest.java index c58f51dcd4024..16ccef50bd4bf 100644 --- a/core/camel-core/src/test/java/org/apache/camel/converter/jaxp/XmlConverterTest.java +++ b/core/camel-core/src/test/java/org/apache/camel/converter/jaxp/XmlConverterTest.java @@ -51,12 +51,15 @@ import static org.junit.jupiter.api.Assertions.assertSame; import static org.junit.jupiter.api.Assertions.assertTrue; -public class XmlConverterTest extends ContextTestSupport { +class XmlConverterTest extends ContextTestSupport { @Test - public void testToResultNoSource() throws Exception { + void testToResultNoSource() throws Exception { XmlConverter conv = new XmlConverter(); + // Should handle null source gracefully (returns immediately without transforming) conv.toResult(null, null); + // Verify the converter itself is still functional after handling null + assertNotNull(conv.createDocument()); } @Test diff --git a/core/camel-core/src/test/java/org/apache/camel/impl/ClassicUuidGeneratorTest.java b/core/camel-core/src/test/java/org/apache/camel/impl/ClassicUuidGeneratorTest.java index 1ed84b3378e5f..9a22ca949545b 100644 --- a/core/camel-core/src/test/java/org/apache/camel/impl/ClassicUuidGeneratorTest.java +++ b/core/camel-core/src/test/java/org/apache/camel/impl/ClassicUuidGeneratorTest.java @@ -16,6 +16,9 @@ */ package org.apache.camel.impl; +import java.util.HashSet; +import java.util.Set; + import org.apache.camel.support.ClassicUuidGenerator; import org.apache.camel.util.StopWatch; import org.apache.camel.util.TimeUtils; @@ -26,7 +29,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotSame; -public class ClassicUuidGeneratorTest { +class ClassicUuidGeneratorTest { private static final Logger LOG = LoggerFactory.getLogger(ClassicUuidGeneratorTest.class); @@ -41,17 +44,20 @@ public void testGenerateUUID() { } @Test - public void testPerformance() { + void testPerformance() { ClassicUuidGenerator uuidGenerator = new ClassicUuidGenerator(); StopWatch watch = new StopWatch(); + int count = 500000; + Set ids = new HashSet<>(count + 2); - LOG.info("First id: {}", uuidGenerator.generateUuid()); - for (int i = 0; i < 500000; i++) { - uuidGenerator.generateUuid(); + ids.add(uuidGenerator.generateUuid()); + for (int i = 0; i < count; i++) { + ids.add(uuidGenerator.generateUuid()); } - LOG.info("Last id: {}", uuidGenerator.generateUuid()); + ids.add(uuidGenerator.generateUuid()); LOG.info("Took {}", TimeUtils.printDuration(watch.taken(), true)); + assertEquals(count + 2, ids.size(), "All generated UUIDs should be unique"); } @Test diff --git a/core/camel-core/src/test/java/org/apache/camel/impl/DefaultProducerTemplateNonBlockingAsyncTest.java b/core/camel-core/src/test/java/org/apache/camel/impl/DefaultProducerTemplateNonBlockingAsyncTest.java index 787802898ccd5..8e714d027bb29 100644 --- a/core/camel-core/src/test/java/org/apache/camel/impl/DefaultProducerTemplateNonBlockingAsyncTest.java +++ b/core/camel-core/src/test/java/org/apache/camel/impl/DefaultProducerTemplateNonBlockingAsyncTest.java @@ -20,6 +20,7 @@ import org.apache.camel.Exchange; import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Timeout; @@ -27,7 +28,7 @@ import static org.junit.jupiter.api.Assertions.assertSame; @Timeout(20) -public class DefaultProducerTemplateNonBlockingAsyncTest extends DefaultProducerTemplateAsyncTest { +class DefaultProducerTemplateNonBlockingAsyncTest extends DefaultProducerTemplateAsyncTest { @Override @BeforeEach public void setUp() throws Exception { @@ -37,10 +38,10 @@ public void setUp() throws Exception { template.start(); } + @Disabled("Not applicable for non-blocking async mode") @Test @Override public void testSendAsyncProcessor() { - // noop } @Test diff --git a/core/camel-core/src/test/java/org/apache/camel/impl/DefaultUuidGeneratorTest.java b/core/camel-core/src/test/java/org/apache/camel/impl/DefaultUuidGeneratorTest.java index 78a314cd8dcfa..30b5f38fa3a5d 100644 --- a/core/camel-core/src/test/java/org/apache/camel/impl/DefaultUuidGeneratorTest.java +++ b/core/camel-core/src/test/java/org/apache/camel/impl/DefaultUuidGeneratorTest.java @@ -16,6 +16,9 @@ */ package org.apache.camel.impl; +import java.util.HashSet; +import java.util.Set; + import org.apache.camel.spi.UuidGenerator; import org.apache.camel.support.DefaultUuidGenerator; import org.apache.camel.util.StopWatch; @@ -24,9 +27,10 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotSame; -public class DefaultUuidGeneratorTest { +class DefaultUuidGeneratorTest { private static final Logger LOG = LoggerFactory.getLogger(DefaultUuidGeneratorTest.class); @Test @@ -40,17 +44,20 @@ public void testGenerateUUID() { } @Test - public void testPerformance() { + void testPerformance() { UuidGenerator uuidGenerator = new DefaultUuidGenerator(); StopWatch watch = new StopWatch(); + int count = 500000; + Set ids = new HashSet<>(count + 2); - LOG.info("First id: {}", uuidGenerator.generateUuid()); - for (int i = 0; i < 500000; i++) { - uuidGenerator.generateUuid(); + ids.add(uuidGenerator.generateUuid()); + for (int i = 0; i < count; i++) { + ids.add(uuidGenerator.generateUuid()); } - LOG.info("Last id: {}", uuidGenerator.generateUuid()); + ids.add(uuidGenerator.generateUuid()); LOG.info("Took {}", TimeUtils.printDuration(watch.taken(), true)); + assertEquals(count + 2, ids.size(), "All generated UUIDs should be unique"); } } diff --git a/core/camel-core/src/test/java/org/apache/camel/impl/RandomUuidGeneratorTest.java b/core/camel-core/src/test/java/org/apache/camel/impl/RandomUuidGeneratorTest.java index db959e37a9dc2..bfa8e8ef3a3f4 100644 --- a/core/camel-core/src/test/java/org/apache/camel/impl/RandomUuidGeneratorTest.java +++ b/core/camel-core/src/test/java/org/apache/camel/impl/RandomUuidGeneratorTest.java @@ -16,6 +16,9 @@ */ package org.apache.camel.impl; +import java.util.HashSet; +import java.util.Set; + import org.apache.camel.spi.UuidGenerator; import org.apache.camel.support.RandomUuidGenerator; import org.apache.camel.util.StopWatch; @@ -24,9 +27,10 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotSame; -public class RandomUuidGeneratorTest { +class RandomUuidGeneratorTest { private static final Logger LOG = LoggerFactory.getLogger(RandomUuidGeneratorTest.class); @Test @@ -40,17 +44,20 @@ public void testGenerateUUID() { } @Test - public void testPerformance() { + void testPerformance() { UuidGenerator uuidGenerator = new RandomUuidGenerator(); StopWatch watch = new StopWatch(); + int count = 500000; + Set ids = new HashSet<>(count + 2); - LOG.info("First id: {}", uuidGenerator.generateUuid()); - for (int i = 0; i < 500000; i++) { - uuidGenerator.generateUuid(); + ids.add(uuidGenerator.generateUuid()); + for (int i = 0; i < count; i++) { + ids.add(uuidGenerator.generateUuid()); } - LOG.info("Last id: {}", uuidGenerator.generateUuid()); + ids.add(uuidGenerator.generateUuid()); LOG.info("Took {}", TimeUtils.printDuration(watch.taken(), true)); + assertEquals(count + 2, ids.size(), "All generated UUIDs should be unique"); } } diff --git a/core/camel-core/src/test/java/org/apache/camel/impl/RouteMustHaveOutputOnExceptionTest.java b/core/camel-core/src/test/java/org/apache/camel/impl/RouteMustHaveOutputOnExceptionTest.java index 83b743dd1b21e..3277c4f2680df 100644 --- a/core/camel-core/src/test/java/org/apache/camel/impl/RouteMustHaveOutputOnExceptionTest.java +++ b/core/camel-core/src/test/java/org/apache/camel/impl/RouteMustHaveOutputOnExceptionTest.java @@ -18,11 +18,12 @@ import org.apache.camel.ContextTestSupport; import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.mock.MockEndpoint; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertThrows; -public class RouteMustHaveOutputOnExceptionTest extends ContextTestSupport { +class RouteMustHaveOutputOnExceptionTest extends ContextTestSupport { @Override public boolean isUseRouteBuilder() { @@ -30,7 +31,7 @@ public boolean isUseRouteBuilder() { } @Test - public void testValid() throws Exception { + void testValid() throws Exception { context.addRoutes(new RouteBuilder() { @Override public void configure() { @@ -40,6 +41,13 @@ public void configure() { } }); context.start(); + + MockEndpoint mockResult = getMockEndpoint("mock:result"); + mockResult.expectedMessageCount(1); + + template.sendBody("direct:start", "Hello World"); + + mockResult.assertIsSatisfied(); } @Test diff --git a/core/camel-core/src/test/java/org/apache/camel/impl/ShortUuidGeneratorTest.java b/core/camel-core/src/test/java/org/apache/camel/impl/ShortUuidGeneratorTest.java index e27dcd2fcda1e..e5d567a0cbeb5 100644 --- a/core/camel-core/src/test/java/org/apache/camel/impl/ShortUuidGeneratorTest.java +++ b/core/camel-core/src/test/java/org/apache/camel/impl/ShortUuidGeneratorTest.java @@ -16,6 +16,9 @@ */ package org.apache.camel.impl; +import java.util.HashSet; +import java.util.Set; + import org.apache.camel.spi.UuidGenerator; import org.apache.camel.support.ShortUuidGenerator; import org.apache.camel.util.StopWatch; @@ -24,9 +27,10 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotSame; -public class ShortUuidGeneratorTest { +class ShortUuidGeneratorTest { private static final Logger LOG = LoggerFactory.getLogger(ShortUuidGeneratorTest.class); @Test @@ -40,17 +44,20 @@ public void testGenerateUUID() { } @Test - public void testPerformance() { + void testPerformance() { UuidGenerator uuidGenerator = new ShortUuidGenerator(); StopWatch watch = new StopWatch(); + int count = 500000; + Set ids = new HashSet<>(count + 2); - LOG.info("First id: {}", uuidGenerator.generateUuid()); - for (int i = 0; i < 500000; i++) { - uuidGenerator.generateUuid(); + ids.add(uuidGenerator.generateUuid()); + for (int i = 0; i < count; i++) { + ids.add(uuidGenerator.generateUuid()); } - LOG.info("Last id: {}", uuidGenerator.generateUuid()); + ids.add(uuidGenerator.generateUuid()); LOG.info("Took {}", TimeUtils.printDuration(watch.taken(), true)); + assertEquals(count + 2, ids.size(), "All generated UUIDs should be unique"); } } diff --git a/core/camel-core/src/test/java/org/apache/camel/impl/SimpleUuidGeneratorTest.java b/core/camel-core/src/test/java/org/apache/camel/impl/SimpleUuidGeneratorTest.java index 380204d0998bd..cc49ad28a0e48 100644 --- a/core/camel-core/src/test/java/org/apache/camel/impl/SimpleUuidGeneratorTest.java +++ b/core/camel-core/src/test/java/org/apache/camel/impl/SimpleUuidGeneratorTest.java @@ -25,7 +25,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; -public class SimpleUuidGeneratorTest { +class SimpleUuidGeneratorTest { private static final Logger LOG = LoggerFactory.getLogger(SimpleUuidGeneratorTest.class); @@ -38,17 +38,21 @@ public void testGenerateUUID() { } @Test - public void testPerformance() { + void testPerformance() { SimpleUuidGenerator uuidGenerator = new SimpleUuidGenerator(); StopWatch watch = new StopWatch(); + int count = 500000; - LOG.info("First id: {}", uuidGenerator.generateUuid()); - for (int i = 0; i < 500000; i++) { + String first = uuidGenerator.generateUuid(); + for (int i = 0; i < count; i++) { uuidGenerator.generateUuid(); } - LOG.info("Last id: {}", uuidGenerator.generateUuid()); + String last = uuidGenerator.generateUuid(); LOG.info("Took {}", TimeUtils.printDuration(watch.taken(), true)); + // SimpleUuidGenerator is sequential, so the last id should be count + 2 + assertEquals(String.valueOf(count + 2), last); + assertEquals("1", first); } } diff --git a/core/camel-core/src/test/java/org/apache/camel/impl/health/RouteHealthCheckTest.java b/core/camel-core/src/test/java/org/apache/camel/impl/health/RouteHealthCheckTest.java index f3fe4c2d2c05e..0b3866af0ff5e 100644 --- a/core/camel-core/src/test/java/org/apache/camel/impl/health/RouteHealthCheckTest.java +++ b/core/camel-core/src/test/java/org/apache/camel/impl/health/RouteHealthCheckTest.java @@ -27,12 +27,12 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; -public class RouteHealthCheckTest { +class RouteHealthCheckTest { private static final String TEST_ROUTE_ID = "Test-Route"; @Test - public void testDoCallDoesNotHaveNPEWhenJmxDisabled() throws Exception { + void testDoCallDoesNotHaveNPEWhenJmxDisabled() throws Exception { CamelContext context = new DefaultCamelContext(); context.addRoutes(new RouteBuilder() { @Override @@ -48,6 +48,9 @@ public void configure() { final HealthCheckResultBuilder builder = HealthCheckResultBuilder.on(healthCheck); healthCheck.doCall(builder, Collections.emptyMap()); + HealthCheck.Result result = builder.build(); + + Assertions.assertEquals(HealthCheck.State.UP, result.getState()); context.stop(); } diff --git a/core/camel-core/src/test/java/org/apache/camel/issues/AdviceWithTryCatchFinallyTest.java b/core/camel-core/src/test/java/org/apache/camel/issues/AdviceWithTryCatchFinallyTest.java index b76b560166bf6..30d525a91fcdf 100644 --- a/core/camel-core/src/test/java/org/apache/camel/issues/AdviceWithTryCatchFinallyTest.java +++ b/core/camel-core/src/test/java/org/apache/camel/issues/AdviceWithTryCatchFinallyTest.java @@ -18,11 +18,12 @@ import org.apache.camel.ContextTestSupport; import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.mock.MockEndpoint; import org.junit.jupiter.api.Test; import static org.apache.camel.builder.AdviceWith.adviceWith; -public class AdviceWithTryCatchFinallyTest extends ContextTestSupport { +class AdviceWithTryCatchFinallyTest extends ContextTestSupport { @Override public boolean isUseRouteBuilder() { @@ -30,13 +31,23 @@ public boolean isUseRouteBuilder() { } @Test - public void testAdviceTryCatchFinally() throws Exception { + void testAdviceTryCatchFinally() throws Exception { context.addRoutes(createRouteBuilder()); adviceWith(context, "my-route", a -> a.weaveById("replace-me") .replace().to("mock:replaced")); context.start(); + + MockEndpoint mockReplaced = getMockEndpoint("mock:replaced"); + mockReplaced.expectedMessageCount(1); + + MockEndpoint mockReplaceMe = getMockEndpoint("mock:replace-me"); + mockReplaceMe.expectedMessageCount(0); + + template.sendBody("direct:start", "Hello World"); + + MockEndpoint.assertIsSatisfied(context); } @Override diff --git a/core/camel-core/src/test/java/org/apache/camel/issues/Issue3Test.java b/core/camel-core/src/test/java/org/apache/camel/issues/Issue3Test.java index 25afd3cb31187..0df8efa9690ca 100644 --- a/core/camel-core/src/test/java/org/apache/camel/issues/Issue3Test.java +++ b/core/camel-core/src/test/java/org/apache/camel/issues/Issue3Test.java @@ -21,16 +21,24 @@ import org.apache.camel.Message; import org.apache.camel.Processor; import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.mock.MockEndpoint; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; -public class Issue3Test extends ContextTestSupport { +class Issue3Test extends ContextTestSupport { protected final String fromQueue = "direct:A"; @Test - public void testIssue() { + void testIssue() throws Exception { + MockEndpoint mock = getMockEndpoint("mock:result"); + mock.expectedBodiesReceived("cluster!"); + sendBody(fromQueue, "cluster!"); + + MockEndpoint.assertIsSatisfied(context); } @Override @@ -51,7 +59,7 @@ public void process(Exchange exchange) { boolean isDebug2 = in.getHeader("someproperty", boolean.class); assertFalse(isDebug2); } - }); + }).to("mock:result"); } }; } diff --git a/core/camel-core/src/test/java/org/apache/camel/processor/MDCErrorHandlerTest.java b/core/camel-core/src/test/java/org/apache/camel/processor/MDCErrorHandlerTest.java index fea33212c1a6e..8020dffbd93d6 100644 --- a/core/camel-core/src/test/java/org/apache/camel/processor/MDCErrorHandlerTest.java +++ b/core/camel-core/src/test/java/org/apache/camel/processor/MDCErrorHandlerTest.java @@ -22,16 +22,22 @@ import org.apache.camel.Exchange; import org.apache.camel.Processor; import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.mock.MockEndpoint; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.slf4j.MDC; @Deprecated(since = "4.19.0") -public class MDCErrorHandlerTest extends ContextTestSupport { +class MDCErrorHandlerTest extends ContextTestSupport { @Test - public void testMDC() { + void testMDC() throws Exception { + MockEndpoint mock = getMockEndpoint("mock:dead"); + mock.expectedMessageCount(1); + template.sendBody("direct:start", "Hello World"); + + MockEndpoint.assertIsSatisfied(context); } @Override @@ -68,7 +74,8 @@ public void process(Exchange exchange) { Assertions.assertEquals("dead", m.get("camel.routeId")); } }) - .to("log:dead"); + .to("log:dead") + .to("mock:dead"); } }; } diff --git a/core/camel-core/src/test/java/org/apache/camel/processor/ThreadsInvalidConfigTest.java b/core/camel-core/src/test/java/org/apache/camel/processor/ThreadsInvalidConfigTest.java index b0b388e2815eb..6ff5dd1350ff1 100644 --- a/core/camel-core/src/test/java/org/apache/camel/processor/ThreadsInvalidConfigTest.java +++ b/core/camel-core/src/test/java/org/apache/camel/processor/ThreadsInvalidConfigTest.java @@ -22,15 +22,17 @@ import org.junit.jupiter.api.Test; import static org.apache.camel.util.concurrent.ThreadPoolRejectedPolicy.Abort; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; -public class ThreadsInvalidConfigTest extends ContextTestSupport { +class ThreadsInvalidConfigTest extends ContextTestSupport { final ThreadPoolProfile threadPoolProfile = new ThreadPoolProfile("poll"); @Test - public void testCreateRouteIfNoInvalidOptions() throws Exception { + void testCreateRouteIfNoInvalidOptions() throws Exception { context.addRoutes(new RouteBuilder() { @Override public void configure() { @@ -38,10 +40,11 @@ public void configure() { from("direct:start").threads().executorService(threadPoolProfile.getId()).to("mock:test"); } }); + assertEquals(1, context.getRoutes().size(), "Route should be created when no invalid options are set"); } @Test - public void testFailIfThreadNameAndExecutorServiceRef() { + void testFailIfThreadNameAndExecutorServiceRef() { Exception exception = assertThrows(Exception.class, () -> context.addRoutes(new RouteBuilder() { @Override public void configure() { @@ -51,13 +54,12 @@ public void configure() { } })); - boolean b = exception.getCause() instanceof IllegalArgumentException; - assertTrue(b); + assertInstanceOf(IllegalArgumentException.class, exception.getCause()); assertTrue(exception.getCause().getMessage().startsWith("ThreadName")); } @Test - public void testPassIfThreadNameWithoutExecutorServiceRef() throws Exception { + void testPassIfThreadNameWithoutExecutorServiceRef() throws Exception { context.addRoutes(new RouteBuilder() { @Override public void configure() { @@ -65,10 +67,11 @@ public void configure() { from("direct:start").threads().threadName("foo").to("mock:test"); } }); + assertEquals(1, context.getRoutes().size(), "Route should be created with threadName and no executorServiceRef"); } @Test - public void testFailIfPoolSizeAndExecutorServiceRef() { + void testFailIfPoolSizeAndExecutorServiceRef() { Exception exception = assertThrows(Exception.class, () -> context.addRoutes(new RouteBuilder() { @Override public void configure() { @@ -77,13 +80,12 @@ public void configure() { } })); - boolean b = exception.getCause() instanceof IllegalArgumentException; - assertTrue(b); + assertInstanceOf(IllegalArgumentException.class, exception.getCause()); assertTrue(exception.getCause().getMessage().startsWith("PoolSize")); } @Test - public void testFailIfMaxPoolSizeAndExecutorServiceRef() { + void testFailIfMaxPoolSizeAndExecutorServiceRef() { Exception exception = assertThrows(Exception.class, () -> context.addRoutes(new RouteBuilder() { @Override public void configure() { @@ -92,13 +94,12 @@ public void configure() { } })); - boolean b = exception.getCause() instanceof IllegalArgumentException; - assertTrue(b); + assertInstanceOf(IllegalArgumentException.class, exception.getCause()); assertTrue(exception.getCause().getMessage().startsWith("MaxPoolSize")); } @Test - public void testFailIfKeepAliveTimeAndExecutorServiceRef() { + void testFailIfKeepAliveTimeAndExecutorServiceRef() { Exception exception = assertThrows(Exception.class, () -> context.addRoutes(new RouteBuilder() { @Override public void configure() { @@ -108,13 +109,12 @@ public void configure() { } })); - boolean b = exception.getCause() instanceof IllegalArgumentException; - assertTrue(b); + assertInstanceOf(IllegalArgumentException.class, exception.getCause()); assertTrue(exception.getCause().getMessage().startsWith("KeepAliveTime")); } @Test - public void testFailIfMaxQueueSizeAndExecutorServiceRef() { + void testFailIfMaxQueueSizeAndExecutorServiceRef() { Exception exception = assertThrows(Exception.class, () -> context.addRoutes(new RouteBuilder() { @Override public void configure() { @@ -124,13 +124,12 @@ public void configure() { } })); - boolean b = exception.getCause() instanceof IllegalArgumentException; - assertTrue(b); + assertInstanceOf(IllegalArgumentException.class, exception.getCause()); assertTrue(exception.getCause().getMessage().startsWith("MaxQueueSize")); } @Test - public void testFailIfRejectedPolicyAndExecutorServiceRef() { + void testFailIfRejectedPolicyAndExecutorServiceRef() { Exception exception = assertThrows(Exception.class, () -> context.addRoutes(new RouteBuilder() { @Override public void configure() { @@ -140,8 +139,7 @@ public void configure() { } })); - boolean b = exception.getCause() instanceof IllegalArgumentException; - assertTrue(b); + assertInstanceOf(IllegalArgumentException.class, exception.getCause()); assertTrue(exception.getCause().getMessage().startsWith("RejectedPolicy")); } diff --git a/core/camel-core/src/test/java/org/apache/camel/processor/TraceInterceptorTest.java b/core/camel-core/src/test/java/org/apache/camel/processor/TraceInterceptorTest.java index aaf474d556269..b825359d260e8 100644 --- a/core/camel-core/src/test/java/org/apache/camel/processor/TraceInterceptorTest.java +++ b/core/camel-core/src/test/java/org/apache/camel/processor/TraceInterceptorTest.java @@ -20,15 +20,24 @@ import org.apache.camel.Exchange; import org.apache.camel.Processor; import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.mock.MockEndpoint; import org.junit.jupiter.api.Test; -public class TraceInterceptorTest extends ContextTestSupport { +class TraceInterceptorTest extends ContextTestSupport { // START SNIPPET: e1 @Test - public void testSendingSomeMessages() { + void testSendingSomeMessages() throws Exception { + MockEndpoint mockFoo = getMockEndpoint("mock:foo"); + mockFoo.expectedMessageCount(2); + + MockEndpoint mockBar = getMockEndpoint("mock:bar"); + mockBar.expectedMessageCount(2); + template.sendBodyAndHeader("direct:start", "Hello London", "to", "James"); template.sendBodyAndHeader("direct:start", "This is Copenhagen calling", "from", "Claus"); + + MockEndpoint.assertIsSatisfied(context); } @Override diff --git a/core/camel-core/src/test/java/org/apache/camel/processor/VirtualThreadsLoadTest.java b/core/camel-core/src/test/java/org/apache/camel/processor/VirtualThreadsLoadTest.java index 291b2b5a6e8a5..2d52f1e0f58d8 100644 --- a/core/camel-core/src/test/java/org/apache/camel/processor/VirtualThreadsLoadTest.java +++ b/core/camel-core/src/test/java/org/apache/camel/processor/VirtualThreadsLoadTest.java @@ -28,6 +28,7 @@ import org.apache.camel.Processor; import org.apache.camel.builder.RouteBuilder; import org.apache.camel.util.StopWatch; +import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.slf4j.Logger; @@ -57,7 +58,7 @@ * */ @Disabled("Manual load test - run explicitly for benchmarking") -public class VirtualThreadsLoadTest extends ContextTestSupport { +class VirtualThreadsLoadTest extends ContextTestSupport { private static final Logger LOG = LoggerFactory.getLogger(VirtualThreadsLoadTest.class); @@ -85,7 +86,7 @@ protected CamelContext createCamelContext() throws Exception { } @Test - public void testHighConcurrencyWithSimulatedIO() throws Exception { + void testHighConcurrencyWithSimulatedIO() throws Exception { completionLatch = new CountDownLatch(TOTAL_MESSAGES); processedCount.reset(); @@ -140,6 +141,8 @@ public void testHighConcurrencyWithSimulatedIO() throws Exception { System.out.println("Virtual threads: " + System.getProperty("camel.threads.virtual.enabled", "false")); System.out.println("Thread-per-task mode: " + VIRTUAL_THREAD_PER_TASK); System.out.println(); + + Assertions.assertTrue(completed, "Not all messages processed within timeout"); } @Override diff --git a/core/camel-core/src/test/java/org/apache/camel/processor/onexception/OnExceptionMisconfiguredTest.java b/core/camel-core/src/test/java/org/apache/camel/processor/onexception/OnExceptionMisconfiguredTest.java index 651665dbb0641..c66f547d62355 100644 --- a/core/camel-core/src/test/java/org/apache/camel/processor/onexception/OnExceptionMisconfiguredTest.java +++ b/core/camel-core/src/test/java/org/apache/camel/processor/onexception/OnExceptionMisconfiguredTest.java @@ -29,7 +29,7 @@ /** * */ -public class OnExceptionMisconfiguredTest extends ContextTestSupport { +class OnExceptionMisconfiguredTest extends ContextTestSupport { @Override public boolean isUseRouteBuilder() { @@ -131,7 +131,7 @@ public void configure() { } @Test - public void testOnExceptionNotMisconfigured() throws Exception { + void testOnExceptionNotMisconfigured() throws Exception { context.addRoutes(new RouteBuilder() { @Override public void configure() { @@ -141,11 +141,11 @@ public void configure() { } }); context.start(); - // okay + assertEquals(1, context.getRoutes().size()); } @Test - public void testOnExceptionNotMisconfigured2() throws Exception { + void testOnExceptionNotMisconfigured2() throws Exception { context.addRoutes(new RouteBuilder() { @Override public void configure() { @@ -155,11 +155,11 @@ public void configure() { } }); context.start(); - // okay + assertEquals(1, context.getRoutes().size()); } @Test - public void testOnExceptionNotMisconfigured3() throws Exception { + void testOnExceptionNotMisconfigured3() throws Exception { context.addRoutes(new RouteBuilder() { @Override public void configure() { @@ -169,11 +169,11 @@ public void configure() { } }); context.start(); - // okay + assertEquals(1, context.getRoutes().size()); } @Test - public void testOnExceptionNotMisconfigured4() throws Exception { + void testOnExceptionNotMisconfigured4() throws Exception { context.addRoutes(new RouteBuilder() { @Override public void configure() { @@ -183,20 +183,21 @@ public void configure() { } }); context.start(); - // okay + assertEquals(1, context.getRoutes().size()); } @Test - public void testOnExceptionNotMisconfigured5() throws Exception { + void testOnExceptionNotMisconfigured5() throws Exception { context.addRoutes(new RouteBuilder() { @Override public void configure() { - from("direct:start").onException(SOAPException.class).onException(IOException.class).to("mock:error").end() + from("direct:start").onException(SOAPException.class).onException(IOException.class).to("mock:error") + .end() .to("mock:result"); } }); context.start(); - // okay + assertEquals(1, context.getRoutes().size()); } } diff --git a/core/camel-core/src/test/java/org/apache/camel/util/IOHelperTest.java b/core/camel-core/src/test/java/org/apache/camel/util/IOHelperTest.java index d30f034b6e453..f55ae1f5173d2 100644 --- a/core/camel-core/src/test/java/org/apache/camel/util/IOHelperTest.java +++ b/core/camel-core/src/test/java/org/apache/camel/util/IOHelperTest.java @@ -21,7 +21,6 @@ import java.io.File; import java.io.IOException; import java.io.InputStream; -import java.io.OutputStream; import java.io.PrintWriter; import java.nio.charset.Charset; import java.nio.file.Files; @@ -33,9 +32,11 @@ import org.apache.camel.support.ExchangeHelper; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; +import static org.junit.jupiter.api.Assertions.assertNull; -public class IOHelperTest { +class IOHelperTest { @Test public void testIOException() { @@ -52,10 +53,11 @@ public void testIOExceptionWithMessage() { } @Test - public void testCopyAndCloseInput() throws Exception { + void testCopyAndCloseInput() throws Exception { InputStream is = new ByteArrayInputStream("Hello".getBytes()); - OutputStream os = new ByteArrayOutputStream(); + ByteArrayOutputStream os = new ByteArrayOutputStream(); IOHelper.copyAndCloseInput(is, os, 256); + assertEquals("Hello", os.toString()); } @Test diff --git a/core/camel-core/src/test/java/org/apache/camel/util/InetAddressUtilTest.java b/core/camel-core/src/test/java/org/apache/camel/util/InetAddressUtilTest.java index 86549097dcb5c..c8dc03f2216a9 100644 --- a/core/camel-core/src/test/java/org/apache/camel/util/InetAddressUtilTest.java +++ b/core/camel-core/src/test/java/org/apache/camel/util/InetAddressUtilTest.java @@ -22,7 +22,7 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; -public class InetAddressUtilTest { +class InetAddressUtilTest { @Test public void testGetLocalHostName() { @@ -35,7 +35,7 @@ public void testGetLocalHostName() { } @Test - public void testGetLocalHostNameSafe() { - InetAddressUtil.getLocalHostNameSafe(); + void testGetLocalHostNameSafe() { + assertNotNull(InetAddressUtil.getLocalHostNameSafe()); } }