Skip to content
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,21 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;

import org.apache.camel.maven.htmlxlsx.TestUtil;
import org.apache.camel.maven.htmlxlsx.model.ChildEip;
import org.apache.camel.maven.htmlxlsx.model.ChildEipStatistic;
import org.apache.camel.maven.htmlxlsx.model.Components;
import org.apache.camel.maven.htmlxlsx.model.EipAttribute;
import org.apache.camel.maven.htmlxlsx.model.EipStatistic;
import org.apache.camel.maven.htmlxlsx.model.Route;
import org.apache.camel.maven.htmlxlsx.model.RouteStatistic;
import org.apache.camel.maven.htmlxlsx.model.RouteTotalsStatistic;
import org.apache.camel.maven.htmlxlsx.model.TestResult;
import org.apache.commons.lang3.reflect.FieldUtils;
import org.apache.maven.project.MavenProject;
Expand All @@ -46,7 +55,7 @@
import static org.mockito.ArgumentMatchers.any;

@ExtendWith(MockitoExtension.class)
public class CoverageResultsProcessorTest {
class CoverageResultsProcessorTest {

private static final String TARGET = "_target";

Expand Down Expand Up @@ -181,18 +190,65 @@ public void testGenerateEipStatistics() throws IllegalAccessException, IOExcepti
}

@Test
public void testGenerateChildEipStatistics() {
void testGenerateChildEipStatistics() {

}
ChildEip childEip = new ChildEip();

@Test
public void testGenerateExcel() {
// Add an EipAttribute entry (simulates a child EIP node with coverage data)
EipAttribute eipAttribute = new EipAttribute();
eipAttribute.setId("setBody");
eipAttribute.setIndex(5);
eipAttribute.setExchangesTotal(3);
eipAttribute.setTotalProcessingTime(42);
Properties props = new Properties();
props.put("uri", "direct:test");
eipAttribute.setProperties(props);
childEip.getEipAttributeMap().put("setBody", eipAttribute);

// Add a String entry (simulates a simple property like a constant expression)
childEip.getEipAttributeMap().put("constant", "Hello World");

ChildEipStatistic childEipStatistic = new ChildEipStatistic();

processor.generateChildEipStatistics(childEip, childEipStatistic);

Map<Integer, EipStatistic> resultMap = childEipStatistic.getEipStatisticMap();

assertAll(
() -> assertNotNull(resultMap),
() -> assertEquals(2, resultMap.size()),
// EipAttribute entry: keyed by index=5, tested because exchangesTotal > 0
() -> assertNotNull(resultMap.get(5)),
() -> assertEquals("setBody", resultMap.get(5).getId()),
() -> assertTrue(resultMap.get(5).isTested()),
() -> assertEquals(42, resultMap.get(5).getTotalProcessingTime()),
// String entry: keyed by 0, wraps value in Properties
() -> assertNotNull(resultMap.get(0)),
() -> assertEquals("constant", resultMap.get(0).getId()),
() -> assertEquals("Hello World", resultMap.get(0).getProperties().get("value")));
}

@Test
public void testGenerateHtml() {
void testGenerateHtml() throws IllegalAccessException, IOException {

Mockito
.doNothing()
.when(processor).writeDetailsAsHtml(any(RouteStatistic.class), any(File.class));

@SuppressWarnings("unchecked")
Map<String, RouteStatistic> routeStatisticMap
= (Map<String, RouteStatistic>) FieldUtils.readDeclaredField(processor, "routeStatisticMap", true);

RouteStatistic stat1 = new RouteStatistic();
stat1.setId("route1");
RouteStatistic stat2 = new RouteStatistic();
stat2.setId("route2");
routeStatisticMap.put("route1", stat1);
routeStatisticMap.put("route2", stat2);

processor.generateHtml(htmlPath());

Mockito.verify(processor, Mockito.times(2)).writeDetailsAsHtml(any(RouteStatistic.class), any(File.class));
Comment on lines +232 to +251

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

based on what is tested, I think we should rename the test to something like testHtmlGenerationCalledWhenHtmlFormatAsked because it is not testing if the html file is really generated neither checking the content of it

}

@Test
Expand Down Expand Up @@ -262,8 +318,37 @@ public void testGenerateRouteStatistics() throws IllegalAccessException, IOExcep
}

@Test
public void testAddToRouteTotals() {
void testAddToRouteTotals() throws IllegalAccessException {

RouteTotalsStatistic totals
= (RouteTotalsStatistic) FieldUtils.readDeclaredField(processor, "routeTotalsStatistic", true);

RouteStatistic routeStatistic = new RouteStatistic();
routeStatistic.setTotalEips(10);
routeStatistic.setTotalEipsTested(5);
routeStatistic.setTotalProcessingTime(100);

processor.addToRouteTotals(routeStatistic);

assertAll(
() -> assertEquals(10, totals.getTotalEips()),
() -> assertEquals(5, totals.getTotalEipsTested()),
() -> assertEquals(100, totals.getTotalProcessingTime()),
() -> assertEquals(50, totals.getCoverage()));

// Call again to verify accumulation
RouteStatistic routeStatistic2 = new RouteStatistic();
routeStatistic2.setTotalEips(10);
routeStatistic2.setTotalEipsTested(5);
routeStatistic2.setTotalProcessingTime(50);

processor.addToRouteTotals(routeStatistic2);

assertAll(
() -> assertEquals(20, totals.getTotalEips()),
() -> assertEquals(10, totals.getTotalEipsTested()),
() -> assertEquals(150, totals.getTotalProcessingTime()),
() -> assertEquals(50, totals.getCoverage()));
}

@Test
Expand Down Expand Up @@ -297,8 +382,43 @@ public void testGetRouteStatistic() throws IllegalAccessException {
}

@Test
public void testRecalculate() {
void testRecalculate() {

Route route = new Route();
route.setId("test-route");

// Build Components with two EIP attributes: one tested, one untested
Components components = new Components();
EipAttribute fromAttr = new EipAttribute();
fromAttr.setIndex(0);
fromAttr.setExchangesTotal(1);
fromAttr.setTotalProcessingTime(10);

EipAttribute toAttr = new EipAttribute();
toAttr.setIndex(1);
toAttr.setExchangesTotal(0);
toAttr.setTotalProcessingTime(5);

Map<String, List<EipAttribute>> attributeMap = new HashMap<>();
attributeMap.put("from", Collections.singletonList(fromAttr));
attributeMap.put("to", Collections.singletonList(toAttr));
components.setAttributeMap(attributeMap);
route.setComponents(components);

// Fresh RouteStatistic (not yet initialized)
RouteStatistic input = new RouteStatistic();
input.setId("test-route");

RouteStatistic result = processor.recalculate(route, input);

assertAll(
() -> assertNotNull(result),
() -> assertEquals("test-route", result.getId()),
() -> assertEquals(2, result.getTotalEips()),
() -> assertEquals(1, result.getTotalEipsTested()),
() -> assertEquals(15, result.getTotalProcessingTime()),
() -> assertEquals(50, result.getCoverage()),
() -> assertTrue(result.isTotalEipsInitialized()));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,25 +61,37 @@ void tearDown() throws Exception {
void emitWithoutTaskIdDoesNotThrow() {
Exchange exchange = new DefaultExchange(context);
A2AProgress.emit(exchange, "safe message");
// emit is a safe no-op when there is no task context
assertThat(exchange.getException()).isNull();
assertThat(exchange.getMessage()).isNotNull();
}

@Test
void emitWithoutStoreDoesNotThrow() {
Exchange exchange = new DefaultExchange(context);
exchange.getMessage().setHeader(A2AConstants.TASK_ID, "t1");
A2AProgress.emit(exchange, "safe message");
// emit is a safe no-op when no task store is available
assertThat(exchange.getException()).isNull();
assertThat(exchange.getMessage().getHeader(A2AConstants.TASK_ID)).isEqualTo("t1");
}

@Test
void emitWithExplicitStateDoesNotThrow() {
Exchange exchange = new DefaultExchange(context);
A2AProgress.emit(exchange, TaskState.INPUT_REQUIRED, "need info");
// emit with explicit state is a safe no-op when there is no task context
assertThat(exchange.getException()).isNull();
assertThat(exchange.getMessage()).isNotNull();
}

@Test
void emitArtifactWithoutStoreDoesNotThrow() {
Exchange exchange = new DefaultExchange(context);
A2AProgress.emitArtifact(exchange, Artifact.builder().name("test").build(), false, true);
// emitArtifact is a safe no-op when there is no task context
assertThat(exchange.getException()).isNull();
assertThat(exchange.getMessage()).isNotNull();
}

@Test
Expand All @@ -90,6 +102,9 @@ void emitMessageWithoutStoreDoesNotThrow() {
.parts(List.of(new TextPart("hello")))
.build();
A2AProgress.emitMessage(exchange, msg);
// emitMessage is a safe no-op when there is no task context
assertThat(exchange.getException()).isNull();
assertThat(exchange.getMessage()).isNotNull();
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ void dispatchMultipleConfigsInParallel() throws Exception {
}

@Test
void dispatchSkipsWhenNoConfigs() {
void dispatchSkipsWhenNoConfigs() throws Exception {
dispatcher = new PushNotificationDispatcher(
HttpClient.newHttpClient(), store, 0, 1000, executor, true);

Expand All @@ -270,6 +270,9 @@ void dispatchSkipsWhenNoConfigs() {
.status(new TaskStatus(TaskState.COMPLETED))
.build();
dispatcher.dispatch("task-1", StreamResponse.ofStatusUpdate(event));

// No push configs registered, so no work should have been dispatched
assertThat(pendingWork(dispatcher)).isEqualTo(0);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;

import org.apache.camel.component.a2a.model.Artifact;
import org.apache.camel.component.a2a.model.Message;
Expand Down Expand Up @@ -175,11 +176,50 @@ void listRespectsPageSize() {
@Test
void subscribeAndUnsubscribe() {
store.put("t1", createTask("t1", TaskState.WORKING));
A2AStreamEmitter emitter = createNoOpEmitter();
A2ATaskSubscriber subscriber = new StreamSubscriber(emitter);
AtomicInteger callCount = new AtomicInteger(0);
A2AStreamEmitter countingEmitter = new A2AStreamEmitter() {
@Override
public void emitStatus(TaskState state, String message) {
callCount.incrementAndGet();
}

@Override
public void emitArtifact(Artifact artifact, Boolean append, Boolean lastChunk) {
callCount.incrementAndGet();
}

@Override
public void emitMessage(Message message) {
callCount.incrementAndGet();
}

@Override
public boolean isClosed() {
return false;
}
};
StreamSubscriber subscriber = new StreamSubscriber(countingEmitter);

store.addSubscriber("t1", subscriber);

// Notify while subscribed -- subscriber should be called
TaskStatusUpdateEvent statusEvent = TaskStatusUpdateEvent.builder()
.taskId("t1")
.status(new TaskStatus(TaskState.WORKING))
.build();
store.notifySubscribers("t1", StreamResponse.ofStatusUpdate(statusEvent));
assertThat(callCount.get()).as("subscriber should be called once while subscribed").isEqualTo(1);

// Unsubscribe
store.removeSubscriber("t1", subscriber);

// Notify again -- unsubscribed subscriber should NOT be called
store.notifySubscribers("t1", StreamResponse.ofStatusUpdate(statusEvent));
assertThat(callCount.get()).as("subscriber should not be called after removal").isEqualTo(1);

// Task should still be intact after subscribe/unsubscribe cycle
assertThat(store.get("t1")).isNotNull();
assertThat(store.get("t1").status().state()).isEqualTo(TaskState.WORKING);
Comment thread
gnodet marked this conversation as resolved.
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,13 @@
import org.apache.camel.component.langchain4j.embeddingstore.LangChain4jEmbeddingStore;
import org.apache.camel.component.langchain4j.embeddingstore.LangChain4jEmbeddingStoreComponent;
import org.apache.camel.test.junit6.CamelTestSupport;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;

public class LangChain4jEmbeddingStoreComponentTest extends CamelTestSupport {
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;

class LangChain4jEmbeddingStoreComponentTest extends CamelTestSupport {

@Override
protected CamelContext createCamelContext() throws Exception {
Expand All @@ -51,16 +55,26 @@ protected CamelContext createCamelContext() throws Exception {
}

@Test
public void testSimpleEmbedding() {

void testEmbeddingModel() {
EmbeddingModel embeddingModel = new AllMiniLmL6V2EmbeddingModel();

TextSegment segment1 = TextSegment.from("I like football.");
Embedding testEmbedding = embeddingModel.embed(segment1).content();
assertNotNull(testEmbedding, "embedding model should produce a non-null embedding");
assertFalse(testEmbedding.vectorAsList().isEmpty(), "embedding vector should not be empty");
}

@Disabled("Requires a running Weaviate instance — convert to an integration test with Testcontainers")
@Test
void testStoreRouting() throws Exception {
EmbeddingModel embeddingModel = new AllMiniLmL6V2EmbeddingModel();
Embedding testEmbedding = embeddingModel.embed(TextSegment.from("I like football.")).content();

Message first = fluentTemplate.to("langchain4j-embeddingstore:first")
.withBody(testEmbedding)
.request(Message.class);

assertNotNull(first, "response message should not be null");
Comment thread
gnodet marked this conversation as resolved.
assertNotNull(first.getBody(), "response body should not be null");
assertFalse(first.getBody(String.class).isEmpty(), "response body should contain store content");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
*/
@EnabledIf(value = "org.apache.camel.component.box.AbstractBoxITSupport#hasCredentials",
disabledReason = "Box credentials were not provided")
public class BoxFilesManagerIT extends AbstractBoxITSupport {
class BoxFilesManagerIT extends AbstractBoxITSupport {

private static final Logger LOG = LoggerFactory.getLogger(BoxFilesManagerIT.class);
private static final String PATH_PREFIX = BoxApiCollection.getCollection()
Expand Down Expand Up @@ -132,9 +132,20 @@ public void testCreateFileSharedLink() {
}

@Test
public void testDeleteFile() {
void testDeleteFile() {
assertNotNull(testFile.getID(), "test file should have an ID before deletion");
// using String message body for single parameter "fileId"
requestBody("direct://DELETEFILE", testFile.getID());

// Verify the file no longer exists (same pattern as testDeleteFileMetadata)
try {
testFile.getInfo();
} catch (BoxAPIException e) {
if (e.getResponseCode() == 404) {
return;
}
}
fail("deleteFile file still accessible");
}
Comment thread
gnodet marked this conversation as resolved.

@Test
Expand Down
Loading