Package org.switchyard.quickstarts.demos.library.types

Examples of org.switchyard.quickstarts.demos.library.types.Book


        addBook("978-1-4516-7486-6", "Tesla, Man Out of Time", "Explores the brilliant and prescient mind of one of the twentieth century's greatest scientists and inventors, Nikola Tesla.", 4);
        addBook("978-1-59474-449-5", "Pride and Prejudice and Zombies", "The Classic Regency Romance -- Now with Ultraviolent Zombie Mayhem!", 7);
    }

    private void addBook(String isbn, String title, String synopsis, int quantity) {
        Book book = new Book();
        book.setIsbn(isbn);
        book.setTitle(title);
        book.setSynopsis(synopsis);
        isbns_to_books.put(isbn, book);
        isbns_to_quantities.put(isbn, quantity);
    }
View Full Code Here


    }

    public Loan attemptLoan(String isbn, String loanId) {
        Loan loan = new Loan();
        loan.setId(loanId);
        Book book = getBook(isbn);
        if (book != null) {
            synchronized (librarian) {
                int quantity = getQuantity(book);
                if (quantity > 0) {
                    quantity--;
View Full Code Here

        return loan;
    }

    public boolean returnLoan(Loan loan) {
        if (loan != null) {
            Book book = loan.getBook();
            if (book != null) {
                String isbn = book.getIsbn();
                if (isbn != null) {
                    synchronized (librarian) {
                        Integer quantity = isbns_to_quantities.get(isbn);
                        if (quantity != null) {
                            quantity = new Integer(quantity.intValue() + 1);
View Full Code Here

    public void testLibraryServices() throws Exception {
        System.out.println();
        // get 1st suggestion
        Suggestion suggestion1_Zombie = getSuggestion("Zombie");
        Book book1_WorldWarZ = suggestion1_Zombie.getBook();
        System.out.println("Received suggestion for book: " + book1_WorldWarZ.getTitle() + " (isbn: " + book1_WorldWarZ.getIsbn() + ")");
        Assert.assertEquals("World War Z", book1_WorldWarZ.getTitle());
        // take out 1st loan
        System.out.println("Attempting 1st loan for isbn: " + book1_WorldWarZ.getIsbn());
        Loan loan1_WorldWarZ = attemptLoan(book1_WorldWarZ.getIsbn());
        System.out.println("1st loan approved? " + loan1_WorldWarZ.isApproved());
        Assert.assertTrue(loan1_WorldWarZ.isApproved());
        // 2nd loan should not be approved since 1st loan hasn't been returned
        System.out.println("Attempting 2nd loan for isbn: " + book1_WorldWarZ.getIsbn());
        Loan loan2_WorldWarZ = attemptLoan(book1_WorldWarZ.getIsbn());
        System.out.println("2nd loan approved? " + loan2_WorldWarZ.isApproved());
        Assert.assertFalse(loan2_WorldWarZ.isApproved());
        // return 1st loan
        System.out.println("Returning 1st loan for isbn: " + loan1_WorldWarZ.getBook().getIsbn());
        boolean return1_ack = returnLoan(loan1_WorldWarZ);
        System.out.println("1st loan return acknowledged? " + return1_ack);
        Assert.assertTrue(return1_ack);
        // try 2nd loan again; this time it should work
        System.out.println("Re-attempting 2nd loan for isbn: " + book1_WorldWarZ.getIsbn());
        loan2_WorldWarZ = attemptLoan(book1_WorldWarZ.getIsbn());
        System.out.println("Re-attempt of 2nd loan approved? " + loan2_WorldWarZ.isApproved());
        Assert.assertTrue(loan2_WorldWarZ.isApproved());
        // get 2nd suggestion, and since 1st book not available (again), 2nd match will return
        Suggestion suggestion2_TheZombieSurvivalGuide = getSuggestion("Zombie");
        Book book2_TheZombieSurvivalGuide = suggestion2_TheZombieSurvivalGuide.getBook();
        System.out.println("Received suggestion for book: " + book2_TheZombieSurvivalGuide.getTitle() + " (isbn: " + book2_TheZombieSurvivalGuide.getIsbn() + ")");
        Assert.assertEquals("The Zombie Survival Guide", book2_TheZombieSurvivalGuide.getTitle());
        // take out 3rd loan
        System.out.println("Attempting 3rd loan for isbn: " + book2_TheZombieSurvivalGuide.getIsbn());
        Loan loan3_TheZombieSurvivalGuide = attemptLoan(book2_TheZombieSurvivalGuide.getIsbn());
        System.out.println("3rd loan approved? " + loan3_TheZombieSurvivalGuide.isApproved());
        Assert.assertTrue(loan3_TheZombieSurvivalGuide.isApproved());
        // return 2nd loan
        System.out.println("Returning 2nd loan for isbn: " + loan2_WorldWarZ.getBook().getIsbn());
        boolean return2_ack = returnLoan(loan2_WorldWarZ);
View Full Code Here

TOP

Related Classes of org.switchyard.quickstarts.demos.library.types.Book

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.