1 4 package com.openedit.store; 5 6 import org.openedit.money.Money; 7 8 import com.openedit.WebPageRequest; 9 import com.openedit.modules.cart.CartModule; 10 11 15 public class ProductEditTest extends StoreTestCase 16 { 17 18 22 public ProductEditTest(String arg0) 23 { 24 super(arg0); 25 } 26 27 public void testEdit() throws Exception 28 { 29 CartModule module = (CartModule)getFixture().getModuleManager().getModule("CartModule"); 30 assertNotNull(module); 31 32 WebPageRequest context = getFixture().createPageRequest("/store/index.html"); 34 context.setRequestParameter("productid","1"); 35 module.loadProductDetails(context); 36 Product item = (Product)context.getPageValue("product"); 37 assertNotNull(item); 38 context.setRequestParameter("product.name","New Name"); 40 context.setRequestParameter("productid","1"); 41 module.saveProduct(context); 42 43 Store store = module.getStore(context); 44 store.getProductArchive().clearProducts(); 45 46 module.loadProductDetails(context); 48 item = (Product)context.getPageValue("product"); 49 assertEquals( "New Name", item.getName()); 50 } 51 52 public void testEditProductProperties() throws Exception 53 { 54 String originaltext = "Some weird & whacky product attribute's to \"insert\""; 55 Product product = getStore().getProduct("1"); 56 product.addProperty("insertdata",originaltext); 57 58 getStore().saveProduct(product); 59 getStore().clear(); 60 product = getStore().getProduct("1"); 61 String returntext = product.get("insertdata"); 62 assertEquals(originaltext, returntext); 63 64 } 65 66 public void testEditItemProperties() throws Exception 67 { 68 String originaltext = "weird & whacky data insert'ed at \"item\" level"; 69 Product product = getStore().getProduct("1"); 70 InventoryItem item = product.getInventoryItem(0); 71 assertNotNull(item); 72 73 item.addProperty("insertdata",originaltext); 74 75 getStore().saveProduct(product); 76 getStore().clearProducts(); 77 product = getStore().getProduct("1"); 78 item = product.getInventoryItem(0); 79 String returntext = item.get("insertdata"); 80 assertTrue(originaltext.equals( returntext) ); 81 82 } 83 84 public void testAvailableFlag() throws Exception 85 { 86 Product product = getStore().getProduct("1"); 87 product.setAvailable(false); 88 getStore().saveProduct(product); 89 getStore().clearProducts(); 90 product = getStore().getProduct("1"); 92 assertFalse( product.isAvailable()); 93 94 product.setAvailable(true); 95 getStore().saveProduct(product); 96 getStore().clearProducts(); 97 product = getStore().getProduct("1"); 98 assertTrue( product.isAvailable()); 99 } 100 101 public void testOptions() throws Exception 102 { 103 Product product = getStore().getProduct("2"); 104 product.clearOptions(); 105 106 final String OPTION_NAME = "Mandatory Gold Plating"; 107 final String OPTION_ID = "gold"; 108 final Money OPTION_COST = new Money("750.00"); 109 110 Option option = new Option(); 111 option.setName(OPTION_NAME); 112 option.setId(OPTION_ID); 113 option.setRequired(true); 114 option.addTierPrice(1, new Price(OPTION_COST)); 115 product.addOption(option); 116 117 getStore().saveProduct(product); 118 getStore().clearProducts(); 119 120 product = getStore().getProduct("2"); 121 assertTrue(product.getOptions().size() == 1); 122 123 option = (Option)product.getOptions().get(0); 124 assertTrue(option.isRequired()); 125 assertEquals(OPTION_NAME, option.getName()); 126 assertEquals(OPTION_ID, option.getId()); 127 PriceSupport ps = option.getPriceSupport(); 128 assertNotNull(ps); 129 assertTrue(ps.getTiers().size() == 1); 130 assertEquals(OPTION_COST, ps.getYourPriceByQuantity(1)); 131 132 product.clearOptions(); 133 getStore().saveProduct(product); 134 } 135 136 public void testEditRelatedProducts() throws Exception 137 { 138 Product product = getStore().getProduct("1"); 139 product.clearRelatedProductIds(); 140 141 product.addRelatedProductId("2"); 142 143 getStore().saveProduct(product); 144 try 145 { 146 getStore().clearProducts(); 147 148 product = getStore().getProduct("1"); 149 assertEquals("Number of related products", 1, product.getRelatedProductIds().size()); 150 151 String relatedProductId = (String ) product.getRelatedProductIds().get( 0 ); 152 assertEquals("2", relatedProductId); 153 } 154 finally 155 { 156 product.clearRelatedProductIds(); 157 getStore().saveProduct(product); 158 } 159 } 160 } 161 | Popular Tags |