Search in sources :

Example 6 with Book

use of org.talend.esb.examples.ebook.model.Book in project tesb-rt-se by Talend.

the class ImportRouteTest method testImport.

@Test
public void testImport() throws Exception {
    final Book book = createBook("My title");
    sendMessage("books.in", book);
    Book book2 = tryTo("get book", new Callable<Book>() {

        public Book call() throws Exception {
            return bookRepo.getBook(book.getId());
        }
    });
    Assert.assertEquals(book.getId(), book2.getId());
    Assert.assertEquals(book.getTitle(), book2.getTitle());
    bookRepo.delete(book.getId());
}
Also used : Book(org.talend.esb.examples.ebook.model.Book) TimeoutException(java.util.concurrent.TimeoutException) JMSException(javax.jms.JMSException) JAXBException(javax.xml.bind.JAXBException) Test(org.junit.Test)

Example 7 with Book

use of org.talend.esb.examples.ebook.model.Book in project tesb-rt-se by Talend.

the class ImportRouteTest method testImportError.

@Test(expected = TimeoutException.class)
public void testImportError() throws Exception {
    final Book book = createBook("error1");
    sendMessage("books.in", book);
    tryTo("get book", new Callable<Book>() {

        public Book call() throws Exception {
            return bookRepo.getBook(book.getId());
        }
    }, 10000);
}
Also used : Book(org.talend.esb.examples.ebook.model.Book) TimeoutException(java.util.concurrent.TimeoutException) JMSException(javax.jms.JMSException) JAXBException(javax.xml.bind.JAXBException) Test(org.junit.Test)

Example 8 with Book

use of org.talend.esb.examples.ebook.model.Book in project tesb-rt-se by Talend.

the class BookService method getBook.

@GET
@Path("{id}")
public Response getBook(@PathParam("id") String id) {
    System.out.println(id);
    Book book = bookRepo.getBook(id);
    return book == null ? Response.status(Status.NOT_FOUND).build() : Response.ok(book).build();
}
Also used : Book(org.talend.esb.examples.ebook.model.Book) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 9 with Book

use of org.talend.esb.examples.ebook.model.Book in project tesb-rt-se by Talend.

the class BookService method getBooks.

@GET
public Collection<Book> getBooks() {
    List<Book> outBooks = new ArrayList<>();
    for (Book book : bookRepo.getBooks()) {
        Book outBook = new Book();
        outBook.setId(book.getId());
        outBook.setTitle(book.getTitle());
        outBook.setCreator(book.getCreator());
        outBooks.add(outBook);
    }
    return outBooks;
}
Also used : Book(org.talend.esb.examples.ebook.model.Book) ArrayList(java.util.ArrayList) GET(javax.ws.rs.GET)

Example 10 with Book

use of org.talend.esb.examples.ebook.model.Book in project tesb-rt-se by Talend.

the class ParseTest method testParse.

@Test
public void testParse() throws Exception {
    Document doc = readDocument("pg50180.rdf");
    BookParser parser = new BookParser();
    Book book = parser.parse(doc);
    Assert.assertEquals("Maugham, W. Somerset (William Somerset) - Penelope\nA Comedy in Three Acts", book.toString());
    Assert.assertEquals("ebooks/50180", book.getId());
    Assert.assertEquals("Penelope\nA Comedy in Three Acts", book.getTitle());
    Assert.assertEquals("Maugham, W. Somerset (William Somerset)", book.getCreator());
    // Assert.assertEquals(4, book.getSubjects().size());
    // Assert.assertEquals("Justice -- Early works to 1800", book.getSubjects().get(0).getSubject());
    Assert.assertEquals("http://www.gutenberg.org/cache/epub/50180/pg50180.cover.medium.jpg", book.getCover().toString());
    Assert.assertEquals(11, book.getFormats().size());
    Format format = book.getFormats().get(0);
    Assert.assertEquals("http://www.gutenberg.org/ebooks/50180.kindle.images", format.getFile().toString());
    Assert.assertEquals("application/x-mobipocket-ebook", format.getMediaType().toString());
}
Also used : Format(org.talend.esb.examples.ebook.model.Format) Book(org.talend.esb.examples.ebook.model.Book) Document(org.w3c.dom.Document) Test(org.junit.Test)

Aggregations

Book (org.talend.esb.examples.ebook.model.Book)12 Test (org.junit.Test)7 Format (org.talend.esb.examples.ebook.model.Format)5 URI (java.net.URI)2 TimeoutException (java.util.concurrent.TimeoutException)2 JMSException (javax.jms.JMSException)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 JAXBException (javax.xml.bind.JAXBException)2 URISyntaxException (java.net.URISyntaxException)1 ArrayList (java.util.ArrayList)1 POST (javax.ws.rs.POST)1 Coordination (org.osgi.service.coordinator.Coordination)1 Document (org.w3c.dom.Document)1 NodeList (org.w3c.dom.NodeList)1