Coverage Report - org.mule.example.bookstore.CatalogServiceImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
CatalogServiceImpl
0%
0/29
0%
0/4
0
 
 1  
 /*
 2  
  * $Id$
 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.api.lifecycle.Initialisable;
 14  
 import org.mule.api.lifecycle.InitialisationException;
 15  
 
 16  
 import java.util.ArrayList;
 17  
 import java.util.Collection;
 18  
 import java.util.HashMap;
 19  
 import java.util.List;
 20  
 import java.util.Map;
 21  
 
 22  
 import javax.jws.WebService;
 23  
 
 24  
 /**
 25  
  * Bookstore catalog service which implements both the public interface for 
 26  
  * browsing the catalog and the admin interface for adding books to the catalog.
 27  
  * 
 28  
  * @see CatalogService
 29  
  * @see CatalogAdminService
 30  
  */
 31  
 @WebService(serviceName="CatalogService", endpointInterface="org.mule.example.bookstore.CatalogService")
 32  0
 public class CatalogServiceImpl implements CatalogService, CatalogAdminService, Initialisable
 33  
 {
 34  
     /** Simple hashmap used to store the catalog, in real life this would be a database */
 35  0
     private Map <Long, Book> books = new HashMap <Long, Book> ();
 36  
     
 37  
     public void initialise() throws InitialisationException
 38  
     {
 39  0
         books = new HashMap <Long, Book> ();
 40  
 
 41  
         // Add some initial test data
 42  0
         addBook(new Book("J.R.R. Tolkien", "The Fellowship of the Ring", 8));
 43  0
         addBook(new Book("J.R.R. Tolkien", "The Two Towers", 10));
 44  0
         addBook(new Book("J.R.R. Tolkien", "The Return of the King", 10));
 45  0
         addBook(new Book("C.S. Lewis", "The Lion, the Witch and the Wardrobe", 6));
 46  0
         addBook(new Book("C.S. Lewis", "Prince Caspian", 8));
 47  0
         addBook(new Book("C.S. Lewis", "The Voyage of the Dawn Treader", 6));
 48  0
         addBook(new Book("Leo Tolstoy", "War and Peace", 8));
 49  0
         addBook(new Book("Leo Tolstoy", "Anna Karenina", 6));
 50  0
         addBook(new Book("Henry David Thoreau", "Walden", 8));
 51  0
         addBook(new Book("Harriet Beecher Stowe", "Uncle Tom's Cabin", 6));
 52  0
         addBook(new Book("George Orwell", "1984", 8));
 53  0
         addBook(new Book("George Orwell", "Animal Farm", 8));
 54  0
         addBook(new Book("Aldous Huxley", "Brave New World", 8));
 55  
 
 56  0
     }
 57  
 
 58  
     public long addBook(Book book)
 59  
     {
 60  0
         System.out.println("Adding book " + book.getTitle());
 61  0
         long id = books.size() + 1;
 62  0
         book.setId(id);
 63  0
         books.put(id, book);
 64  0
         return id;
 65  
     }
 66  
 
 67  
     public Collection <Long> addBooks(Collection<Book> booksToAdd)
 68  
     {
 69  0
         List <Long> ids = new ArrayList <Long> ();
 70  0
         if (booksToAdd != null)
 71  
         {
 72  0
             for (Book book : booksToAdd)
 73  
             {
 74  0
                 ids.add(addBook(book));
 75  
             }
 76  
         }
 77  0
         return ids;
 78  
     }
 79  
 
 80  
     public Collection <Book> getBooks()
 81  
     {
 82  0
         return books.values();
 83  
     }
 84  
 
 85  
     public Book getBook(long bookId)
 86  
     {
 87  0
         return books.get(bookId);
 88  
     }
 89  
 }