Search in sources :

Example 6 with MultivaluedStringMap

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);
    }
}
Also used : Response(javax.ws.rs.core.Response) MultivaluedStringMap(org.glassfish.jersey.internal.util.collection.MultivaluedStringMap) InputStream(java.io.InputStream) IOException(java.io.IOException) Test(org.junit.Test) JerseyTest(org.glassfish.jersey.test.JerseyTest)

Example 7 with MultivaluedStringMap

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);
}
Also used : Response(javax.ws.rs.core.Response) MultivaluedStringMap(org.glassfish.jersey.internal.util.collection.MultivaluedStringMap) AbstractJerseyTest(io.dropwizard.jersey.AbstractJerseyTest) Test(org.junit.Test)

Example 8 with MultivaluedStringMap

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);
}
Also used : Response(javax.ws.rs.core.Response) MultivaluedStringMap(org.glassfish.jersey.internal.util.collection.MultivaluedStringMap) AbstractJerseyTest(io.dropwizard.jersey.AbstractJerseyTest) Test(org.junit.Test)

Aggregations

MultivaluedStringMap (org.glassfish.jersey.internal.util.collection.MultivaluedStringMap)8 Test (org.junit.Test)8 Response (javax.ws.rs.core.Response)7 AbstractJerseyTest (io.dropwizard.jersey.AbstractJerseyTest)6 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 WebTarget (javax.ws.rs.client.WebTarget)1 MultivaluedMap (javax.ws.rs.core.MultivaluedMap)1 JerseyTest (org.glassfish.jersey.test.JerseyTest)1