use of jakarta.ws.rs.core.Response in project jaxrs-api by eclipse-ee4j.
the class StreamOutputTest method testIOException.
@GET
@Path("IOExceptionTest")
public Response testIOException() {
StreamingOutput so = new StreamingOutput() {
public void write(OutputStream output) throws IOException {
throw new IOException("TckIOExceptionTest");
}
};
Response response = Response.ok(so).build();
return response;
}
use of jakarta.ws.rs.core.Response in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method getLanguageNotPresentTest.
/*
* @testName: getLanguageNotPresentTest
*
* @assertion_ids: JAXRS:JAVADOC:850;
*
* @test_Strategy: Get null if not present.
*/
@Test
public void getLanguageNotPresentTest() throws Fault {
ResponseHeaderValue<Locale> value = new ResponseHeaderValue<>();
addProvider(new HeaderNotPresent<Locale>(value) {
@Override
protected void setHeader(ClientResponseContext responseContext, ResponseHeaderValue<Locale> header) {
header.value = responseContext.getLanguage();
}
});
Response response = invokePost("language", null);
Locale locale = response.getLanguage();
assertHeaderNull(locale, value, "getLanguage");
}
use of jakarta.ws.rs.core.Response in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method readEntityGenericTypeCloseIsNotCalledOnInputStreamTest.
/*
* @testName: readEntityGenericTypeCloseIsNotCalledOnInputStreamTest
*
* @assertion_ids: JAXRS:JAVADOC:866;
*
* @test_Strategy: Unless the supplied entity type is an input stream, this
* method automatically closes the consumed response entity stream if it is
* not buffered.
*/
@Test
public void readEntityGenericTypeCloseIsNotCalledOnInputStreamTest() throws Fault {
AtomicInteger ai = setCorruptedStream();
Response response = invokeGet("corrupted");
try {
response.readEntity(generic(InputStream.class));
logMsg("Close() has not been called on entity stream as expected");
} catch (Exception e) {
throw new Fault("Close was called", e);
}
assertTrue(ai.get() == 0, "Close was called");
}
use of jakarta.ws.rs.core.Response in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method responseCreatedRelativeURITest.
/*
* @testName: responseCreatedRelativeURITest
*
* @assertion_ids: JAXRS:JAVADOC:121;
*
* @test_Strategy: The resource calls Response.created() to set the Location header with a
* relative URI. The relative URI should be converted into an absolute URI by resolving it
* relative to the base URI.
*/
@Test
public void responseCreatedRelativeURITest() throws Fault {
String resourceUrl = getAbsoluteUrl();
String expected = resourceUrl.substring(0, resourceUrl.length() - "resource".length()) + "created";
Response response = invokeGet("created");
try {
assertTrue(expected.equals(response.getHeaderString("location")), "#response.getHeaderString(\"location\") [" + response.getHeaderString("location") + "] differs from " + expected);
} finally {
response.close();
}
}
use of jakarta.ws.rs.core.Response in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method readEntityClassAnnotationTest.
/*
* @testName: readEntityClassAnnotationTest
*
* @assertion_ids: JAXRS:JAVADOC:869;
*
* @test_Strategy: Read the message entity input stream as an instance of
* specified Java type using a MessageBodyReader that supports mapping the
* message entity stream onto the requested type. annotations - annotations
* that will be passed to the MessageBodyReader.
*/
@Test
public void readEntityClassAnnotationTest() throws Fault {
Date date = Calendar.getInstance().getTime();
String sDate = String.valueOf(date.getTime());
Annotation[] annotations = AnnotatedClass.class.getAnnotations();
int expected = DateReaderWriter.ANNOTATION_CONSUMES | DateReaderWriter.ANNOTATION_PROVIDER;
AtomicInteger ai = new AtomicInteger();
DateReaderWriter drw = new DateReaderWriter(ai);
addProvider(drw);
Response response = invokeGet("date?date=" + sDate);
response.bufferEntity();
Date entity = response.readEntity(Date.class, annotations);
assertTrue(date.equals(entity), "#readEntity(Date, annotations)={" + entity + "} differs from expected" + date);
assertTrue(ai.get() == expected, ai.get() + "differes from expected" + expected + "which suggest a problem with annotation passing");
String responseDate = response.readEntity(String.class, annotations);
assertTrue(sDate.equals(responseDate), "#readEntity(String.class, annotations)={" + responseDate + "} differs from expected" + sDate);
assertTrue(ai.get() == expected, ai.get() + "differes from expected" + expected + "which suggest a problem with annotation passing");
logMsg("Got expected date", date);
}
Aggregations