001 package org.cocome.tradingsystem.systests.scenarios; 002 003 import java.util.concurrent.TimeoutException; 004 005 import org.cocome.tradingsystem.systests.interfaces.IProduct; 006 import org.cocome.tradingsystem.systests.interfaces.IStorePC; 007 import org.cocome.tradingsystem.systests.util.GeneratedStockItem; 008 009 /** 010 * This test case covers use case 8 - prodcut exchange among stores 011 * 012 * @author Christian Pfaller 013 */ 014 public class ProductExchangeAmongStoresTest extends ProcessSaleBase { 015 016 private int productIndex; 017 018 @Override 019 protected void setUp() throws Exception { 020 super.setUp(); 021 022 // create two more sores, store no. 0 was already created in 023 // super.setUp(); 024 createStore(0); // store no. 1 025 createStore(0); // store no. 2 026 027 productIndex = productGenerator.generate(); 028 029 // set stock amount almost low for store no. 0 030 stores.get(0).getStockGenerator().generate(productIndex, 100, 100, 200); 031 032 // set enough amount in store no. 1 033 stores.get(1).getStockGenerator().generate(productIndex, 10, 300, 300); 034 035 // set nothing to store no. 2 --> they don't have it at all 036 037 } 038 039 /** Execute the test scenario. */ 040 public void testScenario() throws Exception { 041 042 // execute sales szenario 043 initializeCashDesk(0, 0); 044 045 // we buy one item of the product --> low on stock (amount < minAmount) 046 startNewSale(1); 047 enterProduct(); // first piece 048 049 finishSale(); 050 handleCashPayment(); 051 052 // check for products transfer between store 053 IProduct product = productGenerator.getGeneratedProduct(productIndex) 054 .getProduct(); 055 IStorePC store0 = stores.get(0).getStorePC(); 056 IStorePC store1 = stores.get(1).getStorePC(); 057 IStorePC store2 = stores.get(2).getStorePC(); 058 059 Thread.sleep(5000); 060 061 // there should be transfer form store 1 to store 0 062 assertTrue("There should be transfer form store 1 to store 0", 063 enterprise.existsProductTransfer(product, store1, store0)); 064 065 // there should be no transfer form store 2 to store 0 066 assertFalse("There should be NO transfer form store 2 to store 0", 067 enterprise.existsProductTransfer(product, store2, store0)); 068 069 // there should be no transfer form store 1 to store 2 070 assertFalse("There should be NO transfer form store 1 to store 2", 071 enterprise.existsProductTransfer(product, store1, store2)); 072 073 } 074 075 /** 076 * Executes actions for entering the specific product 077 */ 078 private void enterProduct() throws Exception, TimeoutException { 079 080 // The cashier enters item identifier. 081 GeneratedStockItem stockItem = stores.get(0).getStockGenerator() 082 .getGeneratedStockItem(productIndex); 083 084 int barcode = stockItem.getProduct().getBarcode(); 085 // This can be done ... by using the barcode scanner. 086 cashDesk.getBarcodeScanner().sendBarcode(barcode); 087 088 } 089 090 }