use of org.ecabrerar.examples.javax.rs.validation.domain.Book in project javaee7-firstcup by ecabrerar.
the class BooksCollectionTest method setup.
@BeforeClass
public static void setup() {
books.add(new Book("Java EE development using GlassFish Aplication Server", "782345689", "David Heffinger"));
books.add(new Book("Java 7 JAX-WS Web Services", "123456789", "Deepak Vohra"));
books.add(new Book("Netbeans IDE7 CookBook", "2234555567", "Rhawi Dantas"));
books.add(new Book("Getting Started with RESTful WebServices", "11233333", "Bhakti Mehta, Masoud Kalali"));
}
use of org.ecabrerar.examples.javax.rs.validation.domain.Book in project javaee7-firstcup by ecabrerar.
the class SampleMessageBodyReader method readFrom.
@Override
public Book readFrom(Class<Book> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream entityStream) throws IOException, WebApplicationException {
try {
JAXBContext jaxbContext = JAXBContext.newInstance(Book.class);
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
Book book = (Book) unmarshaller.unmarshal(entityStream);
return book;
} catch (JAXBException e) {
e.printStackTrace();
}
return null;
}
use of org.ecabrerar.examples.javax.rs.validation.domain.Book in project javaee7-firstcup by ecabrerar.
the class BooksCollectionTest method shouldReturnAValidationError.
@Test
public void shouldReturnAValidationError() {
Book book = new Book("Effective Java", "2234555568", "");
Validator validator = Validation.buildDefaultValidatorFactory().getValidator();
Set<ConstraintViolation<Book>> violations = validator.validate(book);
Assert.assertEquals(2, violations.size());
System.out.println(violations.stream().map(error -> error.getMessage()).collect(Collectors.joining(", ")));
}
Aggregations