{
log.info("starting testEJBs()");
// Create book.
ClientRequest request = new ClientRequest("http://localhost:8080/resteasy-cdi-ejb-test/rest/create/");
Book book1 = new Book("RESTEasy: the Sequel");
request.body("application/test+xml", book1);
ClientResponse<?> response = request.post();
invocationCounter++;
assertEquals(200, response.getStatus());
log.info("Status: " + response.getStatus());
int id1 = response.getEntity(int.class);
log.info("id: " + id1);
Assert.assertEquals(Counter.INITIAL_VALUE, id1);
// Create another book.
request = new ClientRequest("http://localhost:8080/resteasy-cdi-ejb-test/rest/create/");
Book book2 = new Book("RESTEasy: It's Alive");
request.body("application/test+xml", book2);
response = request.post();
invocationCounter++;
assertEquals(200, response.getStatus());
log.info("Status: " + response.getStatus());
int id2 = response.getEntity(int.class);
log.info("id: " + id2);
Assert.assertEquals(Counter.INITIAL_VALUE + 1, id2);
// Retrieve first book.
request = new ClientRequest("http://localhost:8080/resteasy-cdi-ejb-test/rest/book/" + id1);
request.accept("application/test+xml");
response = request.get();
invocationCounter++;
log.info("Status: " + response.getStatus());
assertEquals(200, response.getStatus());
Book result = response.getEntity(Book.class);
log.info("book: " + book1);
Assert.assertEquals(book1, result);
// Retrieve second book.
request = new ClientRequest("http://localhost:8080/resteasy-cdi-ejb-test/rest/book/" + id2);
request.accept("application/test+xml");
response = request.get();
invocationCounter++;
log.info("Status: " + response.getStatus());
assertEquals(200, response.getStatus());
result = response.getEntity(Book.class);
log.info("book: " + book2);
Assert.assertEquals(book2, result);
// Retrieve all books.
request = new ClientRequest("http://localhost:8080/resteasy-cdi-ejb-test/rest/books/");
request.accept(MediaType.APPLICATION_XML);
response = request.get();
invocationCounter++;
log.info("Status: " + response.getStatus());
@SuppressWarnings("unchecked")
Collection<Book> books = response.getEntity(Collection.class, BookCollectionType);
log.info("Collection: " + books);
Assert.assertEquals(2, books.size());
Iterator<Book> it = books.iterator();
Book b1 = it.next();
Book b2 = it.next();
log.info("First book in list: " + b1);
log.info("Second book in list: " + b2);
Assert.assertTrue(book1.equals(b1) && book2.equals(b2) || book1.equals(b2) && book2.equals(b1));
// Test EntityManager injected in BookResource