use of jakarta.ws.rs.core.Response in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method getLengthTest.
/*
* @testName: getLengthTest
*
* @assertion_ids: JAXRS:JAVADOC:852;
*
* @test_Strategy: Get Content-Length value.
*/
@Test
public void getLengthTest() throws Fault {
Response response = invokePost("length", "1234567890");
int len = response.getLength();
assertTrue(len > 9, "Expected Content-Length > 9" + "does NOT match response#getLength()" + len);
logMsg("#getLength matches expected Content-Length", len);
}
use of jakarta.ws.rs.core.Response in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method getLinksIsNotNullTest.
/*
* @testName: getLinksIsNotNullTest
*
* @assertion_ids: JAXRS:JAVADOC:855;
*
* @test_Strategy: Does not return null.
*/
@Test
public void getLinksIsNotNullTest() throws Fault {
Response response = invokeGet("entity");
Set<Link> responseLinks = response.getLinks();
assertTrue(responseLinks != null, "#getLinks() returned null!");
assertTrue(responseLinks.size() == 0, "#getLinks() returned non-empty map!");
logMsg("#getLinks contains no links as expected");
}
use of jakarta.ws.rs.core.Response in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method getDateTest.
/*
* @testName: getDateTest
*
* @assertion_ids: JAXRS:JAVADOC:845;
*
* @test_Strategy: Get message date.
*/
@Test
public void getDateTest() throws Fault {
long date = getCurrentTimeMillis();
Response response = invokePost("date", String.valueOf(date));
long responseDate = response.getDate().getTime();
// assertEqualsLong(date, responseDate, "Original date", date,
// "and response#getDate()", responseDate, "differs");
// int TC, the Date settings is overriden by underlaying containers
// But getDate is to be tested, not setDate, hence
assertTrue(Math.abs(responseDate - date) < (10 * 60 * 1000), "#getDate() returned time that differes by more than 10 minutes");
logMsg("#getDate matches the Date HTTP header");
}
use of jakarta.ws.rs.core.Response in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method readEntityGenericTypeAnnotationCloseIsNotCalledOnInputStreamTest.
/*
* @testName: readEntityGenericTypeAnnotationCloseIsNotCalledOnInputStreamTest
*
* @assertion_ids: JAXRS:JAVADOC:872;
*
* @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 readEntityGenericTypeAnnotationCloseIsNotCalledOnInputStreamTest() throws Fault {
Annotation[] annotations = AnnotatedClass.class.getAnnotations();
AtomicInteger ai = setCorruptedStream();
Response response = invokeGet("corrupted");
try {
response.readEntity(generic(InputStream.class), annotations);
} catch (ProcessingException e) {
fault("Close was called", e);
}
assertEqualsInt(ai.get(), 0, "Close was called");
logMsg("Close() has not been called on entity stream as expected");
}
use of jakarta.ws.rs.core.Response in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method readEntityGenericTypeThrowsIllegalStateExceptionTest.
/*
* @testName: readEntityGenericTypeThrowsIllegalStateExceptionTest
*
* @assertion_ids: JAXRS:JAVADOC:866;
*
* @test_Strategy: if the entity is not backed by an input stream, or if the
* entity input stream has been fully consumed already and has not been
* buffered prior consuming.
*/
@Test
public void readEntityGenericTypeThrowsIllegalStateExceptionTest() throws Fault {
// create a new client
Client client = ClientBuilder.newClient();
WebTarget target = // with no bufferEntity called
client.target("http://" + _hostname + ":" + _port + getContextRoot()).path("entity");
Response response = target.request(MediaType.TEXT_PLAIN_TYPE).buildGet().invoke();
String entity = response.readEntity(generic(String.class));
assertTrue(ResponseTest.ENTITY.equals(entity), "#readEntity(GenericType<byte[]>)={" + entity + "} differs from expected" + ResponseTest.ENTITY);
try {
response.readEntity(generic(Reader.class));
throw new Fault("No exception has been thrown when reader for entity is not buffered");
} catch (IllegalStateException e) {
logMsg("IllegalStateException has been thrown as expected");
}
}
Aggregations