use of jakarta.ws.rs.client.WebTarget in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method webTargetConfigNotImpactClientTest.
/*
* @testName: webTargetConfigNotImpactClientTest
*
* @assertion_ids: JAXRS:SPEC:74;
*
* @test_Strategy: However, any additional changes to the instance of
* WebTarget will not impact the Client's configuration and vice versa.
*/
@Test
public void webTargetConfigNotImpactClientTest() throws Fault {
Client client = ClientBuilder.newClient();
WebTarget target = client.target("resource");
target.property("any", "some");
Object property = client.getConfiguration().getProperty("any");
assertTrue(property == null, "WebTarget config impacts Client config");
client.property("some", "any");
property = target.getConfiguration().getProperty("some");
assertTrue(property == null, "Client config impacts WebTarget config");
}
use of jakarta.ws.rs.client.WebTarget in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method deepCopyConfigWebTargetLevelTest.
/*
* @testName: deepCopyConfigWebTargetLevelTest
*
* @assertion_ids: JAXRS:SPEC:68; JAXRS:SPEC:72; JAXRS:JAVADOC:988;
*
* @test_Strategy: Note that changes to hello's configuration do not affect
* base, i.e. configuration inheritance requires performing a deep copy of the
* configuration.
*
* The following Client API types are configurable: Client, Invocation,
* Invocation.Builder and WebTarget.
*
* Get access to the underlying Configuration configuration.
*/
@Test
public void deepCopyConfigWebTargetLevelTest() throws Fault {
Client client = ClientBuilder.newClient();
Configuration config = client.getConfiguration();
int registeredInstances = config.getInstances().size();
// WebTarget level inheritance
WebTarget target1 = client.target("");
WebTarget target2 = client.target("");
target1.register(new StringBeanEntityProvider());
config = target2.getConfiguration();
assertTrue(config.getInstances().size() == registeredInstances, "configuration() does not perform deep copy");
}
use of jakarta.ws.rs.client.WebTarget in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method sseStageCheckTest.
/*
* @testName: sseStageCheckTest
*
* @assertion_ids: JAXRS:JAVADOC:1232; JAXRS:JAVADOC:1217;
*
* @test_Strategy: check the stage is ever done
*/
@Test
public void sseStageCheckTest() throws Fault {
LinkedHolder<InboundSseEvent> holder = new LinkedHolder<>();
WebTarget target = ClientBuilder.newClient().target(getAbsoluteUrl("stage"));
try (SseEventSource source = SseEventSource.target(target).build()) {
source.register(holder::add);
source.open();
sleepUntilHolderGetsFilled(holder);
assertNotNull(holder.get(), "No message received");
assertTrue(holder.get(0).readData().contains(SSEJAXRSClient.MESSAGE), holder.get(0) + "does not contain expected" + SSEJAXRSClient.MESSAGE);
if (!holder.get(1).readData().contains(StageCheckerResource.DONE)) {
sleepUntilHolderGetsFilled(holder);
}
}
assertNotNull(holder.get(1), "No message received");
assertEquals(holder.get(1).readData(), StageCheckerResource.DONE, "The stage has not ever been done, message is", holder.get().readData());
}
use of jakarta.ws.rs.client.WebTarget in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method closeTest.
/*
* @testName: closeTest
*
* @assertion_ids: JAXRS:JAVADOC:1233; JAXRS:JAVADOC:1197; JAXRS:JAVADOC:1198;
* JAXRS:JAVADOC:1199; JAXRS:JAVADOC:1200; JAXRS:JAVADOC:1201;
* JAXRS:JAVADOC:1202; JAXRS:JAVADOC:1241; JAXRS:JAVADOC:1240;
* JAXRS:JAVADOC:1236;
*
* @test_Strategy:
*/
@Test
public void closeTest() throws Fault {
boolean isOpen = true;
LinkedHolder<InboundSseEvent> holder = new LinkedHolder<>();
WebTarget target = ClientBuilder.newClient().target(getAbsoluteUrl("repeat/cast"));
// set clear
setRequestContentEntity(Boolean.TRUE);
setProperty(Property.REQUEST, buildRequest(Request.POST, "repeat/set"));
setProperty(Property.REQUEST_HEADERS, buildContentType(MediaType.TEXT_PLAIN_TYPE));
invoke();
assertTrue(getResponse().readEntity(Boolean.class), "Cast has not been set");
// ask for a message
SseEventSource source = SseEventSource.target(target).build();
source.register(holder::add);
source.open();
sleepUntilHolderGetsFilled(holder);
assertNotNull(holder.get(), "Message was not received");
for (InboundSseEvent e : holder) logMsg("Received message no", e.readData());
// check the session is opened
setProperty(Property.REQUEST, buildRequest(Request.GET, "repeat/isopen"));
invoke();
isOpen = getResponseBody(Boolean.class);
assertTrue(isOpen, "SseEventSource is closed");
// Wait 3 times
for (int i = 0; i != 3; i++) {
holder.clear();
sleepUntilHolderGetsFilled(holder);
for (InboundSseEvent e : holder) logMsg("Received message no", e.readData());
}
// close
source.close();
assertFalse(source.isOpen(), "SseEventSource was not closed");
// check it was closed
int cnt = 0;
int size = holder.size();
try {
while (isOpen && cnt < 20) {
// check the server sends events
holder.clear();
cnt++;
setProperty(Property.REQUEST, buildRequest(Request.GET, "repeat/isopen"));
invoke();
isOpen = getResponseBody(Boolean.class);
assertFalse(size == 0 && isOpen, "Message was not received and SseEventSink is open");
sleepUntilHolderGetsFilled(holder);
for (InboundSseEvent e : holder) logMsg("Received message no", e.readData());
size = holder.size();
}
} finally {
System.out.println("Sending false");
setRequestContentEntity(Boolean.FALSE);
setProperty(Property.REQUEST, buildRequest(Request.POST, "repeat/set"));
setProperty(Property.REQUEST_HEADERS, buildContentType(MediaType.TEXT_PLAIN_TYPE));
invoke();
System.out.println("Sent false");
}
}
use of jakarta.ws.rs.client.WebTarget in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method startBuilderForMethod.
// ///////////////////////////////////////////////////////////////////////
// utility methods
protected Invocation.Builder startBuilderForMethod(String methodName) {
Client client = createClient();
client.register(new JdkLoggingFilter(false));
WebTarget target = client.target(getAbsoluteUrl(methodName));
Invocation.Builder ib = target.request();
return ib;
}
Aggregations