Java Reference
In-Depth Information
//...
}
For comparison purposes, the following JUnit test creates a Book instance that you know the
service should return. The test makes use of JAXB annotated objects generated off of the
WSDL:
public class CatalogTest {
private Book hamlet;
@org.junit.Before
public void init(){
hamlet = new Book();
Author shakespeare = new Author();
shakespeare.setFirstName("William");
shakespeare.setLastName("Shakespeare");
hamlet.setAuthor(shakespeare);
hamlet.setIsbn("1234");
hamlet.setCategory(Category.LITERATURE);
hamlet.setTitle("Hamlet");
}
public CatalogTest() { }
@Test
public void searchByAuthorTest() {
Author shakespeare = new Author();
shakespeare.setFirstName("William");
shakespeare.setLastName("Shakespeare");
CatalogService svc = new CatalogService();
Catalog catalog = svc.getCatalogPort();
SearchResults results = catalog.authorSearch(shakespeare);
Book book = results.getBookList().get(0);
assertTrue(book.getTitle().equals(hamlet.getTitle()));
}
The unit test illustrates how working with domain objects generated from JAXB allow for a
familiar, object-oriented style when programming against a web service. There are no XML
or low-level plumbing details here.
Search WWH ::




Custom Search