001    package org.cocome.tradingsystem.systests.scenarios;
002    
003    import java.util.concurrent.TimeoutException;
004    
005    import org.cocome.tradingsystem.systests.util.GeneratedStockItem;
006    
007    /**
008     * This test covers use case 1 (ProcessSale) with an invalid item id entered
009     * (excepetion in step 3).
010     * 
011     * @author Christian Pfaller
012     * @author $Author: hummel $
013     * @version $Rev: 64 $
014     * @levd.rating GREEN Rev: 64
015     */
016    public class ProcessSaleInvalidItemIdTest extends ProcessSaleBase {
017    
018            /** Executes the test scenario. */
019            public void testScenario() throws Exception {
020    
021                    // a single purchase of on product will be done
022    
023                    initializeCashDesk(0, 0);
024                    startNewSale(1);
025                    
026                    enterAllRemainingProducts();
027                    
028                    finishSale();
029                    handleCashPayment();
030                    updateInventory();
031            }
032    
033            /**
034             * Executes actions for entering a product where at first the barcode reader
035             * send an invalid item id.
036             */
037            protected void enterAllRemainingProducts() throws Exception,
038                            TimeoutException {
039    
040                    // get an item customer wants to buy
041                    GeneratedStockItem stockItem = stores.get(0).getStockGenerator()
042                                    .getGeneratedStockItem(2 * currentlySold + 3);
043                    products[currentlySold] = stockItem.getProduct().getProduct();
044                    expectedAmounts[currentlySold] = stockItem.getAmount() - 1;
045                    priceSum += stockItem.getSalesPrice();
046    
047                    // barcode scanner reads an unkown barcode
048                    int invalidBarcode = productGenerator.getUnusedBarcode();
049                    cashDesk.getBarcodeScanner().sendBarcode(invalidBarcode);
050    
051                    // 1. System signals error
052                    cashDesk.getUserDisplay().waitForUpdate(500);
053                    assertTrue("The message indicating invalid Barcode should be shown.",
054                                    cashDesk.getUserDisplay().isMessageForInvalidBarcodeShown());
055    
056                    // 2.1.1 Cashier again enters item Id (using barcode scanner)
057                    int correctBarcode = stockItem.getProduct().getBarcode();
058                    cashDesk.getBarcodeScanner().sendBarcode(correctBarcode);
059    
060                    // The system records sale item and presents product description,
061                    // price, and running total.
062                    cashDesk.getUserDisplay().waitForUpdate(1000);
063                    assertTrue(cashDesk.getUserDisplay().isPriceShown(
064                                    stockItem.getSalesPrice()));
065                    assertTrue(cashDesk.getUserDisplay().isProductNameShown(
066                                    stockItem.getProduct().getName()));
067    
068                    currentlySold++;
069            }
070    }