Search in sources :

Example 1 with ContactCard

use of org.glassfish.jersey.examples.beanvalidation.webapp.domain.ContactCard in project jersey by jersey.

the class ContactCardTest method testSearchByEmailEmpty.

@Test
public void testSearchByEmailEmpty() throws Exception {
    final Response response = target().path("contact").path("search/email").queryParam("q", "er").request(MediaType.APPLICATION_JSON_TYPE).get();
    assertEquals(200, response.getStatus());
    final List<ContactCard> result = response.readEntity(new GenericType<List<ContactCard>>() {
    });
    assertEquals(0, result.size());
}
Also used : Response(javax.ws.rs.core.Response) ContactCard(org.glassfish.jersey.examples.beanvalidation.webapp.domain.ContactCard) List(java.util.List) JerseyTest(org.glassfish.jersey.test.JerseyTest) Test(org.junit.Test)

Example 2 with ContactCard

use of org.glassfish.jersey.examples.beanvalidation.webapp.domain.ContactCard in project jersey by jersey.

the class ContactCardTest method testSearchByName.

@Test
public void testSearchByName() throws Exception {
    final WebTarget target = target().path("contact");
    target.request(MediaType.APPLICATION_JSON_TYPE).post(Entity.entity(CARD_1, MediaType.APPLICATION_JSON_TYPE));
    target.request(MediaType.APPLICATION_JSON_TYPE).post(Entity.entity(CARD_2, MediaType.APPLICATION_JSON_TYPE));
    Response response = target.path("search/name").queryParam("q", "er").request(MediaType.APPLICATION_JSON_TYPE).get();
    List<ContactCard> contactCards = response.readEntity(new GenericType<List<ContactCard>>() {
    });
    assertEquals(200, response.getStatus());
    assertEquals(2, contactCards.size());
    for (final ContactCard contactCard : contactCards) {
        assertTrue(contactCard.getFullName().contains("er"));
    }
    response = target.path("search/name").queryParam("q", "Foo").request(MediaType.APPLICATION_JSON_TYPE).get();
    contactCards = response.readEntity(new GenericType<List<ContactCard>>() {
    });
    assertEquals(200, response.getStatus());
    assertEquals(1, contactCards.size());
    assertTrue(contactCards.get(0).getFullName().contains("Foo"));
    assertEquals(200, target.request(MediaType.APPLICATION_JSON_TYPE).delete().getStatus());
}
Also used : Response(javax.ws.rs.core.Response) ContactCard(org.glassfish.jersey.examples.beanvalidation.webapp.domain.ContactCard) GenericType(javax.ws.rs.core.GenericType) List(java.util.List) WebTarget(javax.ws.rs.client.WebTarget) JerseyTest(org.glassfish.jersey.test.JerseyTest) Test(org.junit.Test)

Example 3 with ContactCard

use of org.glassfish.jersey.examples.beanvalidation.webapp.domain.ContactCard in project jersey by jersey.

the class ContactCardTest method testAddContact.

@Test
public void testAddContact() throws Exception {
    final WebTarget target = target().path("contact");
    final Response response = target.request(MediaType.APPLICATION_JSON_TYPE).post(Entity.entity(CARD_1, MediaType.APPLICATION_JSON_TYPE));
    final ContactCard contactCard = response.readEntity(ContactCard.class);
    assertEquals(200, response.getStatus());
    assertNotNull(contactCard.getId());
    final Response invalidResponse = target.request(MediaType.APPLICATION_JSON_TYPE).post(Entity.entity(CARD_1, MediaType.APPLICATION_JSON_TYPE));
    assertEquals(500, invalidResponse.getStatus());
    assertTrue(getValidationMessageTemplates(invalidResponse).contains("{contact.already.exist}"));
    assertEquals(200, target.path("" + contactCard.getId()).request(MediaType.APPLICATION_JSON_TYPE).delete().getStatus());
}
Also used : Response(javax.ws.rs.core.Response) ContactCard(org.glassfish.jersey.examples.beanvalidation.webapp.domain.ContactCard) WebTarget(javax.ws.rs.client.WebTarget) JerseyTest(org.glassfish.jersey.test.JerseyTest) Test(org.junit.Test)

Example 4 with ContactCard

use of org.glassfish.jersey.examples.beanvalidation.webapp.domain.ContactCard in project jersey by jersey.

the class ContactCardTest method testAddInvalidContact.

@Test
public void testAddInvalidContact() throws Exception {
    final ContactCard entity = new ContactCard();
    entity.setPhone("Crrrn");
    final Response response = target().path("contact").request(MediaType.APPLICATION_JSON_TYPE).post(Entity.entity(entity, MediaType.APPLICATION_JSON_TYPE));
    assertEquals(400, response.getStatus());
    final List<ValidationError> validationErrorList = getValidationErrorList(response);
    for (final ValidationError validationError : validationErrorList) {
        assertTrue(validationError.getPath().contains("ContactCardResource.addContact.contact."));
    }
    final Set<String> messageTemplates = getValidationMessageTemplates(validationErrorList);
    assertEquals(2, messageTemplates.size());
    assertTrue(messageTemplates.contains("{contact.wrong.name}"));
    assertTrue(messageTemplates.contains("{contact.wrong.phone}"));
}
Also used : Response(javax.ws.rs.core.Response) ContactCard(org.glassfish.jersey.examples.beanvalidation.webapp.domain.ContactCard) ValidationError(org.glassfish.jersey.server.validation.ValidationError) JerseyTest(org.glassfish.jersey.test.JerseyTest) Test(org.junit.Test)

Aggregations

Response (javax.ws.rs.core.Response)4 ContactCard (org.glassfish.jersey.examples.beanvalidation.webapp.domain.ContactCard)4 JerseyTest (org.glassfish.jersey.test.JerseyTest)4 Test (org.junit.Test)4 List (java.util.List)2 WebTarget (javax.ws.rs.client.WebTarget)2 GenericType (javax.ws.rs.core.GenericType)1 ValidationError (org.glassfish.jersey.server.validation.ValidationError)1