use of org.glassfish.jersey.internal.util.collection.MultivaluedStringMap in project jersey by jersey.
the class MainTest method testPostOnForm.
/**
* Test checks that POST on the '/form' resource gives a response page
* with the entered data.
*/
@Test
public void testPostOnForm() {
MultivaluedMap<String, String> formData = new MultivaluedStringMap();
formData.add("name", "testName");
formData.add("colour", "red");
formData.add("hint", "re");
Response response = target().path("form").request().post(Entity.entity(formData, MediaType.APPLICATION_FORM_URLENCODED));
assertEquals(Response.Status.OK.getStatusCode(), response.getStatusInfo().getStatusCode());
// check that the generated response is the expected one
InputStream responseInputStream = response.readEntity(InputStream.class);
try {
byte[] responseData = new byte[responseInputStream.available()];
final int read = responseInputStream.read(responseData);
assertTrue(read > 0);
assertTrue(new String(responseData).contains("Hello, you entered"));
} catch (IOException ex) {
Logger.getLogger(MainTest.class.getName()).log(Level.SEVERE, null, ex);
}
}
use of org.glassfish.jersey.internal.util.collection.MultivaluedStringMap in project dropwizard by dropwizard.
the class OptionalFormParamResourceTest method shouldReturnDefaultMessageWhenMessageIsNotPresent.
@Test
public void shouldReturnDefaultMessageWhenMessageIsNotPresent() throws IOException {
final String defaultMessage = "Default Message";
final Response response = target("/optional/message").request().post(Entity.form(new MultivaluedStringMap()));
assertThat(response.readEntity(String.class)).isEqualTo(defaultMessage);
}
use of org.glassfish.jersey.internal.util.collection.MultivaluedStringMap in project dropwizard by dropwizard.
the class OptionalFormParamResourceTest method shouldReturnDefaultUUIDWhenUUIDIsNotPresent.
@Test
public void shouldReturnDefaultUUIDWhenUUIDIsNotPresent() throws IOException {
final String defaultUUID = "d5672fa8-326b-40f6-bf71-d9dacf44bcdc";
final Response response = target("/optional/uuid").request().post(Entity.form(new MultivaluedStringMap()));
assertThat(response.readEntity(String.class)).isEqualTo(defaultUUID);
}
Aggregations