|
| 1 | +package org.jboss.resteasy.reactive.client.impl; |
| 2 | + |
| 3 | +import static org.junit.jupiter.api.Assertions.assertFalse; |
| 4 | +import static org.junit.jupiter.api.Assertions.assertNotSame; |
| 5 | +import static org.junit.jupiter.api.Assertions.assertNull; |
| 6 | + |
| 7 | +import java.io.IOException; |
| 8 | + |
| 9 | +import jakarta.ws.rs.client.Client; |
| 10 | +import jakarta.ws.rs.client.ClientBuilder; |
| 11 | +import jakarta.ws.rs.client.ClientRequestContext; |
| 12 | +import jakarta.ws.rs.client.ClientRequestFilter; |
| 13 | +import jakarta.ws.rs.core.Response; |
| 14 | + |
| 15 | +import org.junit.jupiter.api.Test; |
| 16 | + |
| 17 | +public class ClientBuilderTest { |
| 18 | + |
| 19 | + @Test |
| 20 | + void configurationCopiedOnBuild() { |
| 21 | + ClientBuilder builder = ClientBuilder.newBuilder(); |
| 22 | + |
| 23 | + Client firstClient = builder.build(); |
| 24 | + firstClient.property("foo", "bar"); |
| 25 | + firstClient.register(Always500.class); |
| 26 | + |
| 27 | + Client secondClient = builder.build(); |
| 28 | + |
| 29 | + try (firstClient; secondClient) { |
| 30 | + // Should not be the same instance |
| 31 | + assertNotSame(firstClient.getConfiguration(), secondClient.getConfiguration()); |
| 32 | + |
| 33 | + // Should not be affected by changes to firstClient's Configuration |
| 34 | + assertNull(secondClient.getConfiguration().getProperty("foo")); |
| 35 | + assertFalse(secondClient.getConfiguration().getClasses().contains(Always500.class)); |
| 36 | + } |
| 37 | + } |
| 38 | + |
| 39 | + public static class Always500 implements ClientRequestFilter { |
| 40 | + |
| 41 | + @Override |
| 42 | + public void filter(ClientRequestContext requestContext) throws IOException { |
| 43 | + requestContext.abortWith(Response.serverError().build()); |
| 44 | + } |
| 45 | + } |
| 46 | +} |
0 commit comments