View Javadoc

1   /*
2    * $Id: BookstoreTestCase.java 19191 2010-08-25 21:05:23Z tcarlson $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  
11  package org.mule.example.bookstore;
12  
13  import org.mule.tck.FunctionalTestCase;
14  
15  import java.util.Collection;
16  
17  import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
18  
19  public class BookstoreTestCase extends FunctionalTestCase
20  {
21      @Override
22      protected String getConfigResources()
23      {
24          return "bookstore-config.xml";
25      }
26      
27      public void testGetBooks()
28      {
29          // Catalog web service
30          JaxWsProxyFactoryBean pf = new JaxWsProxyFactoryBean();
31          pf.setServiceClass(CatalogService.class);
32          pf.setAddress(CatalogService.URL);
33          CatalogService catalog = (CatalogService) pf.create();
34          assertNotNull(catalog);
35  
36          Collection <Book> books = catalog.getBooks();
37          assertNotNull(books);
38          // Number of books added as test data in CatalogServiceImpl.initialise()
39          assertEquals(13, books.size());
40      }
41  
42      public void testOrderBook()
43      {
44          // Catalog web service
45          JaxWsProxyFactoryBean pf = new JaxWsProxyFactoryBean();
46          pf.setServiceClass(CatalogService.class);
47          pf.setAddress(CatalogService.URL);
48          CatalogService catalog = (CatalogService) pf.create();
49          assertNotNull(catalog);
50  
51          // Order web service
52          JaxWsProxyFactoryBean pf2 = new JaxWsProxyFactoryBean();
53          pf2.setServiceClass(OrderService.class);
54          pf2.setAddress(OrderService.URL);
55          OrderService orderService = (OrderService) pf2.create();     
56          assertNotNull(orderService);
57  
58          // Place an order for book #3 from the catalog
59          Book book = catalog.getBook(3); 
60          assertNotNull(book);
61          Order order = orderService.orderBook(book, 2, "Somewhere", "me@my-mail.com"); 
62          assertNotNull(order);
63          assertEquals(3, order.getBook().getId());
64          assertEquals(2, order.getQuantity());
65          assertEquals("me@my-mail.com", order.getEmail());
66      }
67  
68  //    public void testAddBook() throws Exception
69  //    {
70  //        HttpServletRequest request = new Request();
71  //        request.setAttribute("title", "blah");
72  //        request.setAttribute("author", "blah");
73  //        
74  //        MuleClient client = new MuleClient(muleContext);
75  //        client.send("servlet://catalog", request, null);
76  //    }
77  }