use of jakarta.ws.rs.ext.RuntimeDelegate in project jaxrs-api by eclipse-ee4j.
the class JAXRSDelegateClient method assertRuntimeDelegate.
/**
* Check what is the RuntimeDelegate
*
* @param wantTckRuntimeDelegate
* @throws Fault
* when wantTckRuntimeDelegate && RuntimeDelegate.getInstance !=
* TckRuntimeDelegate when !wantTckRuntimeDelegate &&
* RuntimeDelegate.getInstance == TckRuntimeDelegate
*/
protected void assertRuntimeDelegate(boolean wantTckRuntimeDelegate) throws Fault {
RuntimeDelegate delegate = RuntimeDelegate.getInstance();
Class<? extends RuntimeDelegate> clazz = delegate.getClass();
boolean check = clazz == TckRuntimeDelegate.class;
check = (wantTckRuntimeDelegate ? check : !check);
assertTrue(check, "TckRuntimeDelegate was " + (wantTckRuntimeDelegate ? "" : " not ") + "set, got " + clazz.getName());
logMsg("Found", clazz.getName());
}
use of jakarta.ws.rs.ext.RuntimeDelegate in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method getHeaderStringIsEmptyTest.
/*
* @testName: getHeaderStringIsEmptyTest
*
* @assertion_ids: JAXRS:JAVADOC:463; JAXRS:JAVADOC:479; JAXRS:JAVADOC:480;
*
* @test_Strategy: the message header value. If the message header is present
* but has no value then the empty string is returned.
*
* ClientResponseFilter.filter
*/
@Test
public <T> void getHeaderStringIsEmptyTest() throws Fault {
final String header1 = "header1";
RuntimeDelegate original = RuntimeDelegate.getInstance();
RuntimeDelegate.setInstance(new NullStringBeanRuntimeDelegate(original));
ContextProvider in = new ContextProvider() {
@Override
protected void checkFilterContext(ClientRequestContext requestContext, ClientResponseContext responseContext) throws Fault {
String header = responseContext.getHeaderString(header1);
assertTrue(header != null, "the #getHeaderString is null");
assertTrue(header.equals(""), "the #getHeaderString is NOT empty, but " + header);
logMsg("#getHeaderString is empty string as expected");
}
};
Response response = Response.ok().header(header1, new StringBean("aa")).build();
try {
invokeWithResponseAndAssertStatus(response, Status.OK, in);
} finally {
RuntimeDelegate.setInstance(original);
StringBeanRuntimeDelegate.assertNotStringBeanRuntimeDelegate();
}
}
use of jakarta.ws.rs.ext.RuntimeDelegate in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method getHeaderStringUsingHeaderDelegateTest.
/*
* @testName: getHeaderStringUsingHeaderDelegateTest
*
* @assertion_ids: JAXRS:JAVADOC:440; JAXRS:JAVADOC:455; JAXRS:JAVADOC:456;
* JAXRS:SPEC:85; JAXRS:JAVADOC:427;
*
* @test_Strategy: Get a message header as a single string value. Each single
* header value is converted to String using a RuntimeDelegate.HeaderDelegate.
*
* ClientRequestFilter.abortWith
*/
@Test
public void getHeaderStringUsingHeaderDelegateTest() throws Fault {
final String name = "BEAN";
final StringBean bean = new StringBean(name);
ContextProvider provider = new ContextProvider() {
@Override
protected void checkFilterContext(ClientRequestContext context) throws Fault {
String value = context.getHeaderString(name);
Response r = Response.ok(value).build();
context.abortWith(r);
}
};
RuntimeDelegate original = RuntimeDelegate.getInstance();
RuntimeDelegate.setInstance(new StringBeanRuntimeDelegate(original));
try {
Invocation invocation = buildBuilder(provider).header(name, bean).buildGet();
Response response = invoke(invocation);
String body = response.readEntity(String.class);
assertContains(name.toLowerCase(), body.toLowerCase());
} finally {
RuntimeDelegate.setInstance(original);
StringBeanRuntimeDelegate.assertNotStringBeanRuntimeDelegate();
}
}
use of jakarta.ws.rs.ext.RuntimeDelegate in project jaxrs-api by eclipse-ee4j.
the class Resource method setOriginalRuntime.
// We need to switch back to the original runtime delegate since
// we cannot be sure what happen when the war with our runtimedelegate gets
// undeployed
@Path("setoriginalruntime")
@GET
public Response setOriginalRuntime() {
ResponseBuilder builder = createResponseWithHeader();
RuntimeDelegate stringBeanDelegate = RuntimeDelegate.getInstance();
if (stringBeanDelegate instanceof StringBeanRuntimeDelegate) {
RuntimeDelegate original = ((StringBeanRuntimeDelegate) stringBeanDelegate).getOriginal();
RuntimeDelegate.setInstance(original);
} else
builder = builder.status(Status.NO_CONTENT);
return builder.build();
}
use of jakarta.ws.rs.ext.RuntimeDelegate in project jaxrs-api by eclipse-ee4j.
the class ReturnTypeTest method entityResponseTest.
@GET
@Path("entitybodyresponsetest")
public Response entityResponseTest() {
RuntimeDelegate rd = RuntimeDelegate.getInstance();
ResponseBuilder rb = rd.createResponseBuilder();
ReadableWritableEntity rwe = entityTest();
return rb.entity(rwe).build();
}
Aggregations