Skip to content

Commit a486a1f

Browse files
authored
Merge pull request #119 from kabir/unify-tests
Reuse the server test for Quarkus and Jakarta
2 parents b89a245 + 0fe2144 commit a486a1f

File tree

15 files changed

+259
-41
lines changed

15 files changed

+259
-41
lines changed

pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,5 +177,6 @@
177177
<module>sdk-quarkus</module>
178178
<module>tck</module>
179179
<module>examples</module>
180+
<module>tests/server-common</module>
180181
</modules>
181182
</project>

sdk-jakarta/pom.xml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,28 @@
2222
<artifactId>a2a-java-sdk-core</artifactId>
2323
<version>${project.version}</version>
2424
</dependency>
25+
<dependency>
26+
<groupId>${project.groupId}</groupId>
27+
<artifactId>a2a-java-sdk-tests-server-common</artifactId>
28+
<version>${project.version}</version>
29+
<scope>provided</scope>
30+
</dependency>
31+
<dependency>
32+
<groupId>${project.groupId}</groupId>
33+
<artifactId>a2a-java-sdk-tests-server-common</artifactId>
34+
<type>test-jar</type>
35+
<scope>test</scope>
36+
<version>${project.version}</version>
37+
</dependency>
38+
<dependency>
39+
<groupId>com.fasterxml.jackson.core</groupId>
40+
<artifactId>jackson-databind</artifactId>
41+
<scope>provided</scope>
42+
</dependency>
2543
<dependency>
2644
<groupId>jakarta.enterprise</groupId>
2745
<artifactId>jakarta.enterprise.cdi-api</artifactId>
46+
<scope>provided</scope>
2847
</dependency>
2948
<dependency>
3049
<groupId>jakarta.json</groupId>
@@ -36,5 +55,40 @@
3655
<artifactId>jakarta.ws.rs-api</artifactId>
3756
<scope>provided</scope>
3857
</dependency>
58+
<dependency>
59+
<groupId>com.fasterxml.jackson.datatype</groupId>
60+
<artifactId>jackson-datatype-jsr310</artifactId>
61+
<scope>test</scope>
62+
</dependency>
63+
<dependency>
64+
<groupId>io.quarkus</groupId>
65+
<artifactId>quarkus-junit5</artifactId>
66+
<scope>test</scope>
67+
</dependency>
68+
<dependency>
69+
<groupId>io.quarkus</groupId>
70+
<artifactId>quarkus-resteasy-jackson</artifactId>
71+
<scope>test</scope>
72+
</dependency>
73+
<dependency>
74+
<groupId>io.quarkus</groupId>
75+
<artifactId>quarkus-resteasy-client-jackson</artifactId>
76+
<scope>test</scope>
77+
</dependency>
78+
<dependency>
79+
<groupId>org.jboss.resteasy</groupId>
80+
<artifactId>resteasy-client</artifactId>
81+
<scope>test</scope>
82+
</dependency>
83+
<dependency>
84+
<groupId>org.junit.jupiter</groupId>
85+
<artifactId>junit-jupiter-api</artifactId>
86+
<scope>test</scope>
87+
</dependency>
88+
<dependency>
89+
<groupId>io.rest-assured</groupId>
90+
<artifactId>rest-assured</artifactId>
91+
<scope>test</scope>
92+
</dependency>
3993
</dependencies>
4094
</project>

sdk-jakarta/src/main/java/io/a2a/server/apps/A2ARequestFilter.java renamed to sdk-jakarta/src/main/java/io/a2a/server/apps/jakarta/A2ARequestFilter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package io.a2a.server.apps;
1+
package io.a2a.server.apps.jakarta;
22

33
import static io.a2a.spec.A2A.CANCEL_TASK_METHOD;
44
import static io.a2a.spec.A2A.GET_TASK_METHOD;

sdk-jakarta/src/main/java/io/a2a/server/apps/A2AServerResource.java renamed to sdk-jakarta/src/main/java/io/a2a/server/apps/jakarta/A2AServerResource.java

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
package io.a2a.server.apps;
1+
package io.a2a.server.apps.jakarta;
22

3+
import java.util.concurrent.Executor;
4+
import java.util.concurrent.Executors;
35
import java.util.concurrent.Flow;
46

57
import jakarta.enterprise.inject.Instance;
@@ -56,6 +58,12 @@ public class A2AServerResource {
5658
@ExtendedAgentCard
5759
Instance<AgentCard> extendedAgentCard;
5860

61+
// Hook so testing can wait until the async Subscription is subscribed.
62+
private static volatile Runnable streamingIsSubscribedRunnable;
63+
64+
65+
private final Executor executor = Executors.newCachedThreadPool();
66+
5967
/**
6068
* Handles incoming POST requests to the main A2A endpoint. Dispatches the
6169
* request to the appropriate JSON-RPC handler method and returns the response.
@@ -78,7 +86,9 @@ public JSONRPCResponse<?> handleNonStreamingRequests(NonStreamingJSONRPCRequest<
7886
@Consumes(MediaType.APPLICATION_JSON)
7987
@Produces(MediaType.SERVER_SENT_EVENTS)
8088
public void handleStreamingRequests(StreamingJSONRPCRequest<?> request, @Context SseEventSink sseEventSink, @Context Sse sse) {
81-
processStreamingRequest(request, sseEventSink, sse);
89+
System.out.println("=====> Streaming");
90+
executor.execute(() -> processStreamingRequest(request, sseEventSink, sse));
91+
System.out.println("=====> Streaming - done");
8292
}
8393

8494
/**
@@ -156,10 +166,17 @@ private void handleStreamingResponse(Flow.Publisher<? extends JSONRPCResponse<?>
156166
public void onSubscribe(Flow.Subscription subscription) {
157167
this.subscription = subscription;
158168
subscription.request(Long.MAX_VALUE);
169+
System.out.println("SUBSCRIBING!");
170+
// Notify tests that we are subscribed
171+
Runnable runnable = streamingIsSubscribedRunnable;
172+
if (runnable != null) {
173+
runnable.run();
174+
}
159175
}
160176

161177
@Override
162178
public void onNext(JSONRPCResponse<?> item) {
179+
163180
sseEventSink.send(sse.newEventBuilder()
164181
.mediaType(MediaType.APPLICATION_JSON_TYPE)
165182
.data(item)
@@ -183,6 +200,10 @@ private JSONRPCResponse<?> generateErrorResponse(JSONRPCRequest<?> request, JSON
183200
return new JSONRPCErrorResponse(request.getId(), error);
184201
}
185202

203+
static void setStreamingIsSubscribedRunnable(Runnable streamingIsSubscribedRunnable) {
204+
A2AServerResource.streamingIsSubscribedRunnable = streamingIsSubscribedRunnable;
205+
}
206+
186207
@Provider
187208
public class JsonParseExceptionMapper implements ExceptionMapper<JsonParseException> {
188209

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package io.a2a.server.apps.jakarta;
2+
3+
import jakarta.inject.Inject;
4+
5+
import io.a2a.server.apps.common.AbstractA2AServerTest;
6+
import io.a2a.server.events.InMemoryQueueManager;
7+
import io.a2a.server.tasks.TaskStore;
8+
import io.quarkus.test.junit.QuarkusTest;
9+
import org.junit.jupiter.api.Disabled;
10+
import org.junit.jupiter.api.Test;
11+
12+
@QuarkusTest
13+
public class JakartaA2AServerTest extends AbstractA2AServerTest {
14+
@Inject
15+
TaskStore taskStore;
16+
17+
@Inject
18+
InMemoryQueueManager queueManager;
19+
20+
@Override
21+
protected TaskStore getTaskStore() {
22+
return taskStore;
23+
}
24+
25+
@Override
26+
protected InMemoryQueueManager getQueueManager() {
27+
return queueManager;
28+
}
29+
30+
@Override
31+
protected void setStreamingSubscribedRunnable(Runnable runnable) {
32+
A2AServerResource.setStreamingIsSubscribedRunnable(runnable);
33+
}
34+
}

sdk-quarkus/pom.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,19 @@
2222
<artifactId>a2a-java-sdk-core</artifactId>
2323
<version>${project.version}</version>
2424
</dependency>
25+
<dependency>
26+
<groupId>${project.groupId}</groupId>
27+
<artifactId>a2a-java-sdk-tests-server-common</artifactId>
28+
<version>${project.version}</version>
29+
<scope>provided</scope>
30+
</dependency>
31+
<dependency>
32+
<groupId>${project.groupId}</groupId>
33+
<artifactId>a2a-java-sdk-tests-server-common</artifactId>
34+
<type>test-jar</type>
35+
<scope>test</scope>
36+
<version>${project.version}</version>
37+
</dependency>
2538
<dependency>
2639
<groupId>io.quarkus</groupId>
2740
<artifactId>quarkus-reactive-routes</artifactId>

sdk-quarkus/src/main/java/io/a2a/server/apps/quarkus/A2AServerRoutes.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public class A2AServerRoutes {
6868
@ExtendedAgentCard
6969
Instance<AgentCard> extendedAgentCard;
7070

71-
// Hook so testing can wait until the MultiSseSupport is subscribes.
71+
// Hook so testing can wait until the MultiSseSupport is subscribed.
7272
private static volatile Runnable streamingMultiSseSupportSubscribedRunnable;
7373

7474
private final Executor executor = Executors.newCachedThreadPool();
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package io.a2a.server.apps.quarkus;
2+
3+
import jakarta.inject.Inject;
4+
5+
import io.a2a.server.apps.common.AbstractA2AServerTest;
6+
import io.a2a.server.events.InMemoryQueueManager;
7+
import io.a2a.server.tasks.TaskStore;
8+
import io.quarkus.test.junit.QuarkusTest;
9+
10+
@QuarkusTest
11+
public class QuarkusA2AServerTest extends AbstractA2AServerTest {
12+
13+
@Inject
14+
TaskStore taskStore;
15+
16+
@Inject
17+
InMemoryQueueManager queueManager;
18+
19+
@Override
20+
protected TaskStore getTaskStore() {
21+
return taskStore;
22+
}
23+
24+
@Override
25+
protected InMemoryQueueManager getQueueManager() {
26+
return queueManager;
27+
}
28+
29+
@Override
30+
protected void setStreamingSubscribedRunnable(Runnable runnable) {
31+
A2AServerRoutes.setStreamingMultiSseSupportSubscribedRunnable(runnable);
32+
}
33+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
quarkus.arc.selected-alternatives=io.a2a.server.apps.quarkus.TestHttpClient
1+
quarkus.arc.selected-alternatives=io.a2a.server.apps.common.TestHttpClient

tests/server-common/pom.xml

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?xml version="1.0"?>
2+
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"
3+
xmlns="http://maven.apache.org/POM/4.0.0"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<parent>
8+
<groupId>io.a2a.sdk</groupId>
9+
<artifactId>a2a-java-sdk-parent</artifactId>
10+
<version>1.0.0-SNAPSHOT</version>
11+
<relativePath>../../pom.xml</relativePath>
12+
</parent>
13+
<artifactId>a2a-java-sdk-tests-server-common</artifactId>
14+
15+
<packaging>jar</packaging>
16+
17+
<name>Java A2A SDK Server Tests Common</name>
18+
<description>Java SDK for the Agent2Agent Protocol (A2A) - SDK - Server Tests Common</description>
19+
20+
<dependencies>
21+
<dependency>
22+
<groupId>${project.groupId}</groupId>
23+
<artifactId>a2a-java-sdk-core</artifactId>
24+
<version>${project.version}</version>
25+
</dependency>
26+
<dependency>
27+
<groupId>jakarta.ws.rs</groupId>
28+
<artifactId>jakarta.ws.rs-api</artifactId>
29+
<scope>test</scope>
30+
</dependency>
31+
<dependency>
32+
<groupId>org.junit.jupiter</groupId>
33+
<artifactId>junit-jupiter-api</artifactId>
34+
<scope>test</scope>
35+
</dependency>
36+
<dependency>
37+
<groupId>io.rest-assured</groupId>
38+
<artifactId>rest-assured</artifactId>
39+
<scope>test</scope>
40+
</dependency>
41+
</dependencies>
42+
43+
<build>
44+
<plugins>
45+
<plugin>
46+
<groupId>org.apache.maven.plugins</groupId>
47+
<artifactId>maven-surefire-plugin</artifactId>
48+
<configuration>
49+
<skipTests>true</skipTests>
50+
</configuration>
51+
</plugin>
52+
<plugin>
53+
<groupId>org.apache.maven.plugins</groupId>
54+
<artifactId>maven-jar-plugin</artifactId>
55+
<executions>
56+
<execution>
57+
<goals>
58+
<goal>test-jar</goal>
59+
</goals>
60+
</execution>
61+
</executions>
62+
</plugin>
63+
</plugins>
64+
</build>
65+
</project>

0 commit comments

Comments
 (0)