1 4 package com.openedit.store.retailproconvert; 5 6 import java.io.File ; 7 import java.io.FilenameFilter ; 8 import java.util.ArrayList ; 9 import java.util.Iterator ; 10 import java.util.List ; 11 12 import org.openedit.money.Money; 13 14 import com.openedit.store.Category; 15 import com.openedit.store.InventoryItem; 16 import com.openedit.store.Option; 17 import com.openedit.store.Product; 18 import com.openedit.store.StoreTestCase; 19 import com.openedit.store.customer.Customer; 20 import com.openedit.util.OutputFiller; 21 22 26 public class RpConvertTest extends StoreTestCase 27 { 28 29 32 public RpConvertTest(String inArg0) 33 { 34 super(inArg0); 35 36 } 37 public static void main(String [] args) throws Exception 38 { 39 RpConvertTest test = new RpConvertTest("dffd"); 42 test.setUp(); 43 test.testCatalogConvert(); 44 } 45 public void testFind() throws Exception 46 { 47 String f= "R:/Web Pics/Some Path.jpg"; 48 String r = f.replaceAll("R:/Web Pics/","/store/products/images/extras/"); 49 assertEquals(r,"/store/products/images/extras/Some Path.jpg"); 50 } 51 52 public void testCatalogConvert() throws Exception 53 { 54 55 RetailProCatalogConverter convert = new RetailProCatalogConverter(); 56 List errors = new ArrayList (); 57 convert.convert(getStore(), errors); 58 59 for (Iterator iter = errors.iterator(); iter.hasNext();) 60 { 61 String element = (String ) iter.next(); 62 System.out.println(element); 63 64 } 65 File productsDir = new File ( getStore().getStoreDirectory(), "products"); 66 67 File [] listxconfs = productsDir.listFiles(new FilenameFilter () 68 { 69 public boolean accept(File inDir, String inName) 70 { 71 if ( inName.startsWith("PAA") && inName.endsWith(".xconf") ) 72 { 73 return true; 74 } 75 return false; 76 } 77 }); 78 79 assertTrue(listxconfs.length > 50); 80 File [] listhtml = productsDir.listFiles(new FilenameFilter () 81 { 82 public boolean accept(File inDir, String inName) 83 { 84 if ( inName.startsWith("PAA") && inName.endsWith(".html") ) 85 { 86 return true; 87 } 88 return false; 89 } 90 }); 91 assertTrue(listhtml.length > 50); 92 File thumbnailsDir = new File ( getStore().getStoreDirectory(), "/products/images/thumb" ); 93 File [] thumbnailList = thumbnailsDir.listFiles( new FilenameFilter () 94 { 95 public boolean accept( File dir, String name ) 96 { 97 if ( name.startsWith("PAA") && name.endsWith(".jpg") ) 98 { 99 return true; 100 } 101 return false; 102 } 103 }); 104 assertTrue( thumbnailList.length > 20); 105 } 106 107 public void testCatalog() throws Exception 108 { 109 110 List catalogs = getStore().getCatalogArchive().listAllCatalogs(); 111 assertTrue( catalogs.size() > 2); 112 113 Product product = getStore().getProduct("PAAAAAPCJLCAEGAI"); 114 115 assertEquals(6, product.getInventoryItemCount() ); 117 118 assertTrue(product.isAvailable()); 119 assertTrue(product.isInStock()); 120 Money price = product.getYourPrice(); 122 assertNotNull(price); 123 126 InventoryItem item = product.getInventoryItemBySku("4163"); 127 assertEquals(0, item.getQuantityInStock()); 128 129 Category catalog = getStore().getCatalog("LMABAAAAGHOLGIBC"); 130 assertNotNull(catalog); 131 assertTrue(product.isInCatalog(catalog)); 132 133 product = getStore().getProduct("PAAAIAJDBDFHAEBN"); 134 item = product.getInventoryItem(3); 135 Option option = item.getOption("handling"); 136 assertNotNull( "Should have handling option", option ); 137 assertEquals( "Handling amount", 1.00, 138 option.getPriceSupport().getYourPriceByQuantity( 1 ).doubleValue(), 139 0.001 ); 140 141 142 product = getStore().getProduct("PAAAIACGONDPBBAI"); 144 assertTrue( product.isAvailable() ); 145 assertTrue( product.isInStock() ); 146 assertEquals( "Please Allow 6-8 Weeks for Delivery",product.get("outOfStockMsg") ); 147 } 148 149 public void XXXtestCustomerData() throws Exception 150 { 151 Customer user = getStore().getCustomerArchive().getCustomer("3452"); 152 assertNotNull(user); 153 } 154 155 public void testParseDescription_Keywords() throws Exception 156 { 157 RetailProCatalogConverter convert = new RetailProCatalogConverter(); 158 String input = "Test keywords."; 159 String desc = convert.parseDescription( input ); 160 String kwds = convert.parseKeywords( input ); 161 assertEquals( input, desc ); 162 assertNull( kwds ); 163 input = "[[keyword1, keyword2 ]] Test keywords."; 164 desc = convert.parseDescription( input ); 165 kwds = convert.parseKeywords( input ); 166 assertEquals( "Test keywords.", desc ); 167 assertEquals( "keyword1, keyword2", kwds ); 168 169 } 170 171 172 public void setUp() throws Exception 173 { 174 File uploadDir = new File ( getStore().getStoreDirectory(), "/upload" ); 175 uploadDir.mkdir(); 176 File testDir = new File ( uploadDir.getParentFile().getParentFile().getParentFile(), "etc/testupload"); 177 File [] zipfiles = testDir.listFiles(new FilenameFilter () { 178 179 public boolean accept(File inDir, String inName) 180 { 181 return inName.endsWith(".zip"); 182 } 183 }); 184 OutputFiller filler = new OutputFiller(); 185 for ( int i = 0; i < zipfiles.length; i++ ) 186 { 187 String name = zipfiles[i].getName(); 188 File newFile = new File ( uploadDir, name ); 189 if( !newFile.exists()) 190 { 191 filler.fill( zipfiles[i], newFile ); 192 } 193 } 194 } 195 196 197 } 198 | Popular Tags |