Skip to content
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,25 @@
*/
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;
import org.apache.camel.Exchange;
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";

Expand Down Expand Up @@ -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<Path> files;
try (Stream<Path> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);

Expand All @@ -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<String> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@

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;

import static org.junit.jupiter.api.Assertions.assertEquals;
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 {
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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<String> 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");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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<String> 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");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,20 @@

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() {
return false;
}

@Test
public void testValid() throws Exception {
void testValid() throws Exception {
context.addRoutes(new RouteBuilder() {
@Override
public void configure() {
Expand All @@ -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
Expand Down
Loading