Skip to content

Commit 6670cea

Browse files
committed
fix: Make gemini suggestions
1 parent faaa162 commit 6670cea

1 file changed

Lines changed: 33 additions & 48 deletions

File tree

client/base/src/test/java/io/a2a/client/AuthenticationAuthorizationTest.java

Lines changed: 33 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -123,12 +123,9 @@ public void testJsonRpcNonStreamingUnauthenticated() throws A2AClientException {
123123
.withStatusCode(401)
124124
);
125125

126-
Client client = Client.builder(agentCard)
127-
.clientConfig(new ClientConfig.Builder().setStreaming(false).build())
128-
.withTransport(JSONRPCTransport.class, new JSONRPCTransportConfigBuilder())
129-
.build();
126+
Client client = getJSONRPCClientBuilder(false).build();
130127

131-
IOException exception = assertThrows(IOException.class, () -> {
128+
A2AClientException exception = assertThrows(A2AClientException.class, () -> {
132129
client.sendMessage(MESSAGE);
133130
});
134131

@@ -147,12 +144,9 @@ public void testJsonRpcNonStreamingUnauthorized() throws A2AClientException {
147144
.withStatusCode(403)
148145
);
149146

150-
Client client = Client.builder(agentCard)
151-
.clientConfig(new ClientConfig.Builder().setStreaming(false).build())
152-
.withTransport(JSONRPCTransport.class, new JSONRPCTransportConfigBuilder())
153-
.build();
147+
Client client = getJSONRPCClientBuilder(false).build();
154148

155-
IOException exception = assertThrows(IOException.class, () -> {
149+
A2AClientException exception = assertThrows(A2AClientException.class, () -> {
156150
client.sendMessage(MESSAGE);
157151
});
158152

@@ -172,9 +166,7 @@ public void testJsonRpcStreamingUnauthenticated() throws Exception {
172166
);
173167

174168
assertStreamingError(
175-
Client.builder(agentCard)
176-
.clientConfig(new ClientConfig.Builder().setStreaming(true).build())
177-
.withTransport(JSONRPCTransport.class, new JSONRPCTransportConfigBuilder()),
169+
getJSONRPCClientBuilder(true),
178170
AUTHENTICATION_FAILED_MESSAGE);
179171
}
180172

@@ -191,9 +183,7 @@ public void testJsonRpcStreamingUnauthorized() throws Exception {
191183
);
192184

193185
assertStreamingError(
194-
Client.builder(agentCard)
195-
.clientConfig(new ClientConfig.Builder().setStreaming(true).build())
196-
.withTransport(JSONRPCTransport.class, new JSONRPCTransportConfigBuilder()),
186+
getJSONRPCClientBuilder(true),
197187
AUTHORIZATION_FAILED_MESSAGE);
198188
}
199189

@@ -211,10 +201,7 @@ public void testRestNonStreamingUnauthenticated() throws A2AClientException {
211201
.withStatusCode(401)
212202
);
213203

214-
Client client = Client.builder(agentCard)
215-
.clientConfig(new ClientConfig.Builder().setStreaming(false).build())
216-
.withTransport(RestTransport.class, new RestTransportConfigBuilder())
217-
.build();
204+
Client client = getRestClientBuilder(false).build();
218205

219206
A2AClientException exception = assertThrows(A2AClientException.class, () -> {
220207
client.sendMessage(MESSAGE);
@@ -235,10 +222,7 @@ public void testRestNonStreamingUnauthorized() throws A2AClientException {
235222
.withStatusCode(403)
236223
);
237224

238-
Client client = Client.builder(agentCard)
239-
.clientConfig(new ClientConfig.Builder().setStreaming(false).build())
240-
.withTransport(RestTransport.class, new RestTransportConfigBuilder())
241-
.build();
225+
Client client = getRestClientBuilder(false).build();
242226

243227
A2AClientException exception = assertThrows(A2AClientException.class, () -> {
244228
client.sendMessage(MESSAGE);
@@ -260,9 +244,7 @@ public void testRestStreamingUnauthenticated() throws Exception {
260244
);
261245

262246
assertStreamingError(
263-
Client.builder(agentCard)
264-
.clientConfig(new ClientConfig.Builder().setStreaming(true).build())
265-
.withTransport(RestTransport.class, new RestTransportConfigBuilder()),
247+
getRestClientBuilder(true),
266248
AUTHENTICATION_FAILED_MESSAGE);
267249
}
268250

@@ -279,9 +261,7 @@ public void testRestStreamingUnauthorized() throws Exception {
279261
);
280262

281263
assertStreamingError(
282-
Client.builder(agentCard)
283-
.clientConfig(new ClientConfig.Builder().setStreaming(true).build())
284-
.withTransport(RestTransport.class, new RestTransportConfigBuilder()),
264+
getRestClientBuilder(true),
285265
AUTHORIZATION_FAILED_MESSAGE);
286266
}
287267

@@ -291,11 +271,7 @@ public void testRestStreamingUnauthorized() throws Exception {
291271
public void testGrpcNonStreamingUnauthenticated() throws Exception {
292272
setupGrpcServer(Status.UNAUTHENTICATED);
293273

294-
Client client = Client.builder(agentCard)
295-
.clientConfig(new ClientConfig.Builder().setStreaming(false).build())
296-
.withTransport(GrpcTransport.class, new GrpcTransportConfigBuilder()
297-
.channelFactory(target -> grpcChannel))
298-
.build();
274+
Client client = getGrpcClientBuilder(false).build();
299275

300276
A2AClientException exception = assertThrows(A2AClientException.class, () -> {
301277
client.sendMessage(MESSAGE);
@@ -308,11 +284,7 @@ public void testGrpcNonStreamingUnauthenticated() throws Exception {
308284
public void testGrpcNonStreamingUnauthorized() throws Exception {
309285
setupGrpcServer(Status.PERMISSION_DENIED);
310286

311-
Client client = Client.builder(agentCard)
312-
.clientConfig(new ClientConfig.Builder().setStreaming(false).build())
313-
.withTransport(GrpcTransport.class, new GrpcTransportConfigBuilder()
314-
.channelFactory(target -> grpcChannel))
315-
.build();
287+
Client client = getGrpcClientBuilder(false).build();
316288

317289
A2AClientException exception = assertThrows(A2AClientException.class, () -> {
318290
client.sendMessage(MESSAGE);
@@ -326,10 +298,7 @@ public void testGrpcStreamingUnauthenticated() throws Exception {
326298
setupGrpcServer(Status.UNAUTHENTICATED);
327299

328300
assertStreamingError(
329-
Client.builder(agentCard)
330-
.clientConfig(new ClientConfig.Builder().setStreaming(true).build())
331-
.withTransport(GrpcTransport.class, new GrpcTransportConfigBuilder()
332-
.channelFactory(target -> grpcChannel)),
301+
getGrpcClientBuilder(true),
333302
AUTHENTICATION_FAILED_MESSAGE);
334303
}
335304

@@ -338,13 +307,29 @@ public void testGrpcStreamingUnauthorized() throws Exception {
338307
setupGrpcServer(Status.PERMISSION_DENIED);
339308

340309
assertStreamingError(
341-
Client.builder(agentCard)
342-
.clientConfig(new ClientConfig.Builder().setStreaming(true).build())
343-
.withTransport(GrpcTransport.class, new GrpcTransportConfigBuilder()
344-
.channelFactory(target -> grpcChannel)),
310+
getGrpcClientBuilder(true),
345311
AUTHORIZATION_FAILED_MESSAGE);
346312
}
347313

314+
private ClientBuilder getJSONRPCClientBuilder(boolean streaming) {
315+
return Client.builder(agentCard)
316+
.clientConfig(new ClientConfig.Builder().setStreaming(streaming).build())
317+
.withTransport(JSONRPCTransport.class, new JSONRPCTransportConfigBuilder());
318+
}
319+
320+
private ClientBuilder getRestClientBuilder(boolean streaming) {
321+
return Client.builder(agentCard)
322+
.clientConfig(new ClientConfig.Builder().setStreaming(streaming).build())
323+
.withTransport(RestTransport.class, new RestTransportConfigBuilder());
324+
}
325+
326+
private ClientBuilder getGrpcClientBuilder(boolean streaming) {
327+
return Client.builder(agentCard)
328+
.clientConfig(new ClientConfig.Builder().setStreaming(streaming).build())
329+
.withTransport(GrpcTransport.class, new GrpcTransportConfigBuilder()
330+
.channelFactory(target -> grpcChannel));
331+
}
332+
348333
private void assertStreamingError(ClientBuilder clientBuilder, String expectedErrorMessage) throws Exception {
349334
AtomicReference<Throwable> errorRef = new AtomicReference<>();
350335
CountDownLatch errorLatch = new CountDownLatch(1);

0 commit comments

Comments
 (0)