Example usage for com.fasterxml.jackson.jaxrs.json JacksonJsonProvider JacksonJsonProvider

List of usage examples for com.fasterxml.jackson.jaxrs.json JacksonJsonProvider JacksonJsonProvider

Introduction

In this page you can find the example usage for com.fasterxml.jackson.jaxrs.json JacksonJsonProvider JacksonJsonProvider.

Prototype

public JacksonJsonProvider(ObjectMapper mapper) 

Source Link

Usage

From source file:com.unboundid.scim2.server.EndpointTestCase.java

/**
 * Test delete operation.//from ww w  . j  ava2 s . c om
 *
 * @throws ScimException if an error occurs.
 */
@Test
public void testDelete() throws ScimException {
    ScimService scimService = new ScimService(target());

    // Create a new user.
    UserResource newUser = new UserResource().setUserName("deleteUser");
    UserResource createdUser = scimService.create("SingletonUsers", newUser);
    assertNotNull(createdUser.getId());
    assertEquals(createdUser.getUserName(), newUser.getUserName());

    scimService.delete(createdUser);

    try {
        scimService.retrieve(createdUser);
        fail("Resource should have been deleted");
    } catch (ResourceNotFoundException e) {
        // expected
    }

    // Now with no accept header
    WebTarget target = target().register(new JacksonJsonProvider(JsonUtils.createObjectMapper()));

    Response response = target.path("SingletonUsers").path("deleteUser").request().delete();
    assertEquals(response.getStatus(), 404);
    assertEquals(response.getMediaType(), ServerUtils.MEDIA_TYPE_SCIM_TYPE);

    // With invalid accept type (DS-14520)
    target = target().register(new JacksonJsonProvider(JsonUtils.createObjectMapper()));
    response = target.path("SingletonUsers").path("deleteUser").request()
            .accept(MediaType.APPLICATION_ATOM_XML_TYPE).delete();
    assertEquals(response.getStatus(), 404);
    assertEquals(response.getMediaType(), ServerUtils.MEDIA_TYPE_SCIM_TYPE);
}

From source file:com.unboundid.scim2.server.EndpointTestCase.java

/**
 * Test error response when invalid JSON is submitted.
 *
 * @throws ScimException if an error occurs.
 *//*  w ww .  j av a 2 s. c  o  m*/
@Test
public void testInvalidJson() throws ScimException {
    WebTarget target = target().register(new JacksonJsonProvider(JsonUtils.createObjectMapper()));

    Response response = target.path("SingletonUsers").request().accept(MEDIA_TYPE_SCIM)
            .post(Entity.entity("{badJson}", MEDIA_TYPE_SCIM));
    assertEquals(response.getStatus(), 400);
    assertEquals(response.getMediaType(), MediaType.valueOf(MEDIA_TYPE_SCIM));
    ErrorResponse errorResponse = response.readEntity(ErrorResponse.class);
    assertEquals(errorResponse.getStatus(), new Integer(400));
    assertEquals(errorResponse.getScimType(), "invalidSyntax");
    assertNotNull(errorResponse.getDetail());

    // Now with application/json
    response = target.path("SingletonUsers").request()
            .accept(MediaType.APPLICATION_JSON_TYPE, ServerUtils.MEDIA_TYPE_SCIM_TYPE)
            .post(Entity.entity("{badJson}", MediaType.APPLICATION_JSON_TYPE));
    assertEquals(response.getStatus(), 400);
    assertEquals(response.getMediaType(), MediaType.APPLICATION_JSON_TYPE);
}

From source file:com.unboundid.scim2.server.EndpointTestCase.java

/**
 * Test error response when an invalid standard SCIM message is submitted and
 * a Jackson binding error occurs.//  w w  w .  j  a va2  s.  com
 *
 * @throws ScimException if an error occurs.
 */
@Test
public void testInvalidMessage() throws ScimException {
    WebTarget target = target().register(new JacksonJsonProvider(JsonUtils.createObjectMapper()));

    Response response = target.path("SingletonUsers").path(".search").request().accept(MEDIA_TYPE_SCIM)
            .post(Entity.entity("{\"undefinedField\": \"value\"}", MEDIA_TYPE_SCIM));
    assertEquals(response.getStatus(), 400);
    assertEquals(response.getMediaType(), MediaType.valueOf(MEDIA_TYPE_SCIM));
    ErrorResponse errorResponse = response.readEntity(ErrorResponse.class);
    assertEquals(errorResponse.getStatus(), new Integer(400));
    assertEquals(errorResponse.getScimType(), "invalidSyntax");
    assertNotNull(errorResponse.getDetail());

    // Now with application/json
    response = target.path("SingletonUsers").path(".search").request()
            .accept(MediaType.APPLICATION_JSON_TYPE, ServerUtils.MEDIA_TYPE_SCIM_TYPE)
            .post(Entity.entity("{\"undefinedField\": \"value\"}", MediaType.APPLICATION_JSON_TYPE));
    assertEquals(response.getStatus(), 400);
    assertEquals(response.getMediaType(), MediaType.APPLICATION_JSON_TYPE);
}

From source file:com.unboundid.scim2.server.EndpointTestCase.java

/**
 * Test empty entity in PATCH, and POST requests are handled correctly.
 * Jersey client can't issue PUT request with empty entity.
 *
 * @throws ScimException if an error occurs.
 *//*w w  w. jav  a 2 s  .  co  m*/
@Test
public void testEmptyEntity() throws ScimException {
    WebTarget target = target().register(new JacksonJsonProvider(JsonUtils.createObjectMapper()));

    // No content-type header and no entity
    Invocation.Builder b = target.path("SingletonUsers").request("application/scim+json");
    Response response = b.build("POST").invoke();
    assertEquals(response.getStatus(), 400);
    ErrorResponse error = response.readEntity(ErrorResponse.class);
    assertTrue(error.getDetail().contains("No content provided"));
    response.close();

    b = target.path("SingletonUsers").path("123").request("application/scim+json");
    response = b.build("PATCH").invoke();
    assertEquals(response.getStatus(), 400);
    assertEquals(response.getMediaType(), ServerUtils.MEDIA_TYPE_SCIM_TYPE);
    error = response.readEntity(ErrorResponse.class);
    assertTrue(error.getDetail().contains("No content provided"));
    response.close();

    // Content-type header set but no entity
    b = target.path("SingletonUsers").request("application/scim+json").header(HttpHeaders.CONTENT_TYPE,
            "application/scim+json");
    response = b.build("POST").invoke();
    assertEquals(response.getStatus(), 400);
    assertEquals(response.getMediaType(), ServerUtils.MEDIA_TYPE_SCIM_TYPE);
    error = response.readEntity(ErrorResponse.class);
    assertTrue(error.getDetail().contains("No content provided"));
    response.close();

    b = target.path("SingletonUsers").path("123").request("application/scim+json")
            .header(HttpHeaders.CONTENT_TYPE, "application/scim+json");
    response = b.build("PATCH").invoke();
    assertEquals(response.getStatus(), 400);
    assertEquals(response.getMediaType(), ServerUtils.MEDIA_TYPE_SCIM_TYPE);
    error = response.readEntity(ErrorResponse.class);
    assertTrue(error.getDetail().contains("No content provided"));
    response.close();
}