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());
}
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());
}
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());
}
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}"));
}
Aggregations