1 4 package com.openedit.store; 5 6 import java.util.ArrayList ; 7 import java.util.Collection ; 8 import java.util.List ; 9 10 import org.openedit.money.Money; 11 12 import com.openedit.store.products.PropertyDetails; 13 14 18 public class ProductTest extends StoreTestCase 19 { 20 21 25 public ProductTest(String arg0) 26 { 27 super(arg0); 28 } 29 30 public void testGetPriceByQuantity() 31 { 32 33 Product brandNewCar = new Product("brand new car"); 34 35 brandNewCar.addTierPrice(1, createPrice(25000)); 36 brandNewCar.addTierPrice(2, createPrice(23000)); 37 brandNewCar.addTierPrice(4, createPrice(22000)); 38 assertEquals( 3, brandNewCar.getPriceSupport().getTiers().size() ); 39 Money price = brandNewCar.getPriceSupport().getYourPriceByQuantity(2); 40 assertEquals(23000, price.doubleValue(), 0.001); 41 brandNewCar.addTierPrice( 2, createPrice(24000) ); 42 assertEquals( 3, brandNewCar.getPriceSupport().getTiers().size() ); 43 price = brandNewCar.getPriceSupport().getYourPriceByQuantity(2); 44 assertEquals(24000, price.doubleValue(), 0.001); 45 price = brandNewCar.getPriceSupport().getYourPriceByQuantity(3); 46 assertNotNull( price ); 47 48 assertEquals( 3, brandNewCar.getPriceSupport().getTiers().size() ); 49 price = brandNewCar.getPriceSupport().getYourPriceByQuantity(1); 50 assertEquals(25000, price.doubleValue(), 0.001); 51 price = brandNewCar.getPriceSupport().getYourPriceByQuantity(4); 52 assertEquals(22000, price.doubleValue(), 0.001); 53 } 54 55 public void testCreateCartItem() throws StoreException 56 { 57 Product brandNewCar = new Product("brand new car"); 58 brandNewCar.setId("322123ER"); 59 60 brandNewCar.addTierPrice(1, createPrice(25000)); 61 brandNewCar.addTierPrice(2, createPrice(23000)); 62 brandNewCar.addTierPrice(4, createPrice(22000)); 63 64 65 InventoryItem item = new InventoryItem(); 66 item.setQuantityInStock(10000); 67 item.setColor( "Blue" ); 68 item.setSize( "Van" ); 69 item.setSku( "300" ); 70 item.setSku("junk"); 71 brandNewCar.addInventoryItem(item); 72 73 InventoryItem blueCar = new InventoryItem(); 74 blueCar.setColor( "Blue" ); 75 blueCar.setSize( "Sedan" ); 76 blueCar.setSku( "300" ); 77 blueCar.setQuantityInStock(100); 78 brandNewCar.addInventoryItem( blueCar ); 79 80 Collection options = new ArrayList (); 82 options.add( new Option("size","Sedan")); 83 options.add( new Option("color","Blue")); 84 InventoryItem found = brandNewCar.getInventoryItemByOptions(options); 85 CartItem cartItem = new CartItem(); cartItem.setInventoryItem(found); 87 cartItem.setQuantity(1); 88 assertEquals( "Blue", found.getColor().getValue() ); 89 assertEquals( "Sedan", found.getSize().getValue() ); 90 assertEquals( "300", found.getSku() ); 91 assertEquals( 1, cartItem.getQuantity() ); 92 93 94 options = new ArrayList (); 95 options.add( new Option("size","Sedan")); 96 found = brandNewCar.getInventoryItemByOptions(options); 97 assertNotNull(found); 98 cartItem = new CartItem(); 99 cartItem.setInventoryItem(found); 100 cartItem.setQuantity(1); 101 assertEquals( "Blue", cartItem.getColor().getValue() ); 102 assertEquals( "Sedan", cartItem.getSize().getValue() ); 103 assertEquals( "300", cartItem.getSku() ); 104 assertEquals( 1, cartItem.getQuantity() ); 105 } 106 107 public void testIsInStockWithZeroQuantityItems() 108 { 109 Product brandNewCar = createOutOfStockProduct(); 110 assertFalse( "Car should not be in stock", brandNewCar.isInStock() ); 111 assertEquals( "Unit price", 24000, brandNewCar.getYourPrice().doubleValue(), 0.001 ); 112 } 113 114 public void testGetSizesAndGetColorsWithZeroQuantityItems() 115 { 116 Product brandNewCar = createOutOfStockProduct(); 117 brandNewCar.getInventoryItem( 1 ).setQuantityInStock( 2 ); 118 assertEquals( "Number of sizes", 2, brandNewCar.getSizes().size() ); 119 assertEquals( "Number of colors", 2, brandNewCar.getColors().size() ); 120 } 123 124 protected Product createOutOfStockProduct() 125 { 126 Product brandNewCar = new Product( "brand new car" ); 127 brandNewCar.setId( "12345" ); 128 129 InventoryItem item = new InventoryItem(); 130 item.setQuantityInStock( 0 ); 131 item.setColor( "Blue" ); 132 item.setSize( "Sedan" ); 133 item.setSku( "300" ); 134 PriceSupport priceSupport = new PriceSupport(); 135 priceSupport.addTierPrice( 1, createPrice( 24000 ) ); 136 item.setPriceSupport( priceSupport ); 137 brandNewCar.addInventoryItem( item ); 138 139 item = new InventoryItem(); 140 item.setQuantityInStock( 0 ); 141 item.setColor( "Red" ); 142 item.setSize( "Wagon" ); 143 item.setSku( "200" ); 144 priceSupport = new PriceSupport(); 145 priceSupport.addTierPrice( 1, createPrice( 25000 ) ); 146 item.setPriceSupport( priceSupport ); 147 brandNewCar.addInventoryItem( item ); 148 149 return brandNewCar; 150 } 151 public void testProductDetails() throws Exception 152 { 153 PropertyDetails list = getStore().getProductArchive().getPropertyDetails(); 154 assertTrue( list.getDetails().size() == 0 ); 156 List index = list.findIndexProperties(); 157 assertTrue(index.size() == 0); 158 } 159 } | Popular Tags |