|
1 | 1 | /* |
2 | | - * Copyright (c) 2019, 2022 Oracle and/or its affiliates. All rights reserved. |
| 2 | + * Copyright (c) 2019, 2025 Oracle and/or its affiliates. All rights reserved. |
3 | 3 | * |
4 | 4 | * This program and the accompanying materials are made available under the |
5 | 5 | * terms of the Eclipse Public License v. 2.0, which is available at |
|
16 | 16 |
|
17 | 17 | package org.glassfish.jersey.client.spi; |
18 | 18 |
|
19 | | -import org.glassfish.jersey.internal.PropertiesDelegate; |
20 | 19 | import org.hamcrest.Matchers; |
21 | 20 | import org.hamcrest.MatcherAssert; |
22 | 21 | import org.junit.jupiter.api.Assertions; |
23 | 22 | import org.junit.jupiter.api.BeforeEach; |
24 | 23 | import org.junit.jupiter.api.Test; |
25 | 24 |
|
26 | | -import javax.annotation.Priority; |
27 | 25 | import javax.ws.rs.client.ClientBuilder; |
28 | 26 | import javax.ws.rs.client.ClientRequestContext; |
29 | 27 | import javax.ws.rs.client.ClientRequestFilter; |
30 | | -import javax.ws.rs.client.Entity; |
31 | 28 | import javax.ws.rs.client.WebTarget; |
32 | 29 | import javax.ws.rs.core.CacheControl; |
33 | | -import javax.ws.rs.core.Configuration; |
34 | | -import javax.ws.rs.core.Context; |
35 | 30 | import javax.ws.rs.core.HttpHeaders; |
36 | 31 | import javax.ws.rs.core.MediaType; |
37 | 32 | import javax.ws.rs.core.Response; |
@@ -95,6 +90,20 @@ public void testGetters() { |
95 | 90 | } |
96 | 91 | } |
97 | 92 |
|
| 93 | + @Test |
| 94 | + public void testCounter() { |
| 95 | + CountingInvocationBuilderListener listener = new CountingInvocationBuilderListener(); |
| 96 | + target = target.register(listener); |
| 97 | + try (Response r = target.request().get()) { |
| 98 | + assertDefault(r); |
| 99 | + Assertions.assertEquals(1, listener.getCount()); |
| 100 | + } |
| 101 | + try (Response r = target.request().get()) { |
| 102 | + assertDefault(r); |
| 103 | + Assertions.assertEquals(2, listener.getCount()); |
| 104 | + } |
| 105 | + } |
| 106 | + |
98 | 107 | private void assertDefault(Response response) { |
99 | 108 | Assertions.assertEquals(key(ONE) + "=" + ONE, response.readEntity(String.class)); |
100 | 109 | } |
@@ -193,4 +202,17 @@ public void onNewBuilder(InvocationBuilderContext context) { |
193 | 202 | MatcherAssert.assertThat(context.getCookies().get("Cookie"), Matchers.notNullValue()); |
194 | 203 | } |
195 | 204 | } |
| 205 | + |
| 206 | + private static class CountingInvocationBuilderListener implements InvocationBuilderListener { |
| 207 | + private int counter = 0; |
| 208 | + |
| 209 | + @Override |
| 210 | + public void onNewBuilder(InvocationBuilderContext context) { |
| 211 | + counter++; |
| 212 | + } |
| 213 | + |
| 214 | + public int getCount() { |
| 215 | + return counter; |
| 216 | + } |
| 217 | + } |
196 | 218 | } |
0 commit comments