View Javadoc

1   /*
2    * $Id: BookstoreTestCase.java 22620 2011-08-09 10:02:17Z dirk.olmes $
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.junit4.FunctionalTestCase;
14  
15  import java.util.Collection;
16  
17  import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
18  import org.junit.Test;
19  
20  import static org.junit.Assert.assertEquals;
21  import static org.junit.Assert.assertNotNull;
22  
23  public class BookstoreTestCase extends FunctionalTestCase
24  {
25  
26      @Override
27      protected String getConfigResources()
28      {
29          return "bookstore-config.xml";
30      }
31      
32      @Test
33      public void testGetBooks()
34      {
35          // Catalog web service
36          JaxWsProxyFactoryBean pf = new JaxWsProxyFactoryBean();
37          pf.setServiceClass(CatalogService.class);
38          pf.setAddress(CatalogService.URL);
39          CatalogService catalog = (CatalogService) pf.create();
40          assertNotNull(catalog);
41  
42          Collection <Book> books = catalog.getBooks();
43          assertNotNull(books);
44          // Number of books added as test data in CatalogServiceImpl.initialise()
45          assertEquals(13, books.size());
46      }
47  
48      @Test
49      public void testOrderBook()
50      {
51          // Catalog web service
52          JaxWsProxyFactoryBean pf = new JaxWsProxyFactoryBean();
53          pf.setServiceClass(CatalogService.class);
54          pf.setAddress(CatalogService.URL);
55          CatalogService catalog = (CatalogService) pf.create();
56          assertNotNull(catalog);
57  
58          // Order web service
59          JaxWsProxyFactoryBean pf2 = new JaxWsProxyFactoryBean();
60          pf2.setServiceClass(OrderService.class);
61          pf2.setAddress(OrderService.URL);
62          OrderService orderService = (OrderService) pf2.create();     
63          assertNotNull(orderService);
64  
65          // Place an order for book #3 from the catalog
66          Book book = catalog.getBook(3); 
67          assertNotNull(book);
68          Order order = orderService.orderBook(book, 2, "Somewhere", "me@my-mail.com"); 
69          assertNotNull(order);
70          assertEquals(3, order.getBook().getId());
71          assertEquals(2, order.getQuantity());
72          assertEquals("me@my-mail.com", order.getEmail());
73      }
74  
75  //    @Test
76  //    public void testAddBook() throws Exception
77  //    {
78  //        HttpServletRequest request = new Request();
79  //        request.setAttribute("title", "blah");
80  //        request.setAttribute("author", "blah");
81  //        
82  //        MuleClient client = new MuleClient(muleContext);
83  //        client.send("servlet://catalog", request, null);
84  //    }
85  }