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