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