001: /*
002: * Created on Sep 15, 2004
003: */
004: package com.openedit.store.retailproconvert;
005:
006: import java.io.File;
007: import java.io.FilenameFilter;
008: import java.util.Iterator;
009: import java.util.List;
010:
011: import org.openedit.money.Money;
012: import org.openedit.store.Category;
013: import org.openedit.store.InventoryItem;
014: import org.openedit.store.Option;
015: import org.openedit.store.Product;
016: import org.openedit.store.StoreTestCase;
017: import org.openedit.store.convert.ConvertStatus;
018: import org.openedit.store.customer.Customer;
019: import org.openedit.store.retailproconvert.RetailProCatalogConverter;
020:
021: import com.openedit.util.OutputFiller;
022:
023: /**
024: * @author cburkey
025: *
026: */
027: public class RpConvertTest extends StoreTestCase {
028:
029: /**
030: * @param inArg0
031: */
032: public RpConvertTest(String inArg0) {
033: super (inArg0);
034:
035: }
036:
037: public static void main(String[] args) throws Exception {
038: // runner = new TestRunner();
039: //TestRunner.run(ProductEditTest.class);
040: RpConvertTest test = new RpConvertTest("dffd");
041: test.setUp();
042: test.testCatalogConvert();
043: }
044:
045: public void testFind() throws Exception {
046: String f = "R:/Web Pics/Some Path.jpg";
047: String r = f.replaceAll("R:/Web Pics/",
048: "/store/products/images/extras/");
049: assertEquals(r, "/store/products/images/extras/Some Path.jpg");
050: }
051:
052: public void testCatalogConvert() throws Exception {
053:
054: RetailProCatalogConverter convert = new RetailProCatalogConverter();
055: ConvertStatus errors = new ConvertStatus();
056: convert.convert(getStore(), errors);
057:
058: for (Iterator iter = errors.getLog().iterator(); iter.hasNext();) {
059: String element = (String) iter.next();
060: System.out.println(element);
061:
062: }
063: File productsDir = new File(getStore().getStoreDirectory(),
064: "products");
065:
066: File[] listxconfs = productsDir.listFiles(new FilenameFilter() {
067: public boolean accept(File inDir, String inName) {
068: if (inName.startsWith("PAA")
069: && inName.endsWith(".xconf")) {
070: return true;
071: }
072: return false;
073: }
074: });
075:
076: assertTrue(listxconfs.length > 50);
077: File[] listhtml = productsDir.listFiles(new FilenameFilter() {
078: public boolean accept(File inDir, String inName) {
079: if (inName.startsWith("PAA")
080: && inName.endsWith(".html")) {
081: return true;
082: }
083: return false;
084: }
085: });
086: assertTrue(listhtml.length > 50);
087: File thumbnailsDir = new File(getStore().getStoreDirectory(),
088: "/products/images/thumb");
089: File[] thumbnailList = thumbnailsDir
090: .listFiles(new FilenameFilter() {
091: public boolean accept(File dir, String name) {
092: if (name.startsWith("PAA")
093: && name.endsWith(".jpg")) {
094: return true;
095: }
096: return false;
097: }
098: });
099: assertTrue(thumbnailList.length > 20);
100: }
101:
102: public void testCatalog() throws Exception {
103:
104: List catalogs = getStore().getCatalogArchive()
105: .listAllCatalogs();
106: assertTrue(catalogs.size() > 2);
107:
108: Product product = getStore().getProduct("PAAAAAPCJLCAEGAI");
109:
110: // there are 6 items, and all 6 should be imported even though one is out of stock
111: assertEquals(6, product.getInventoryItemCount());
112:
113: assertTrue(product.isAvailable());
114: assertTrue(product.isInStock());
115: //assertTrue(product.isOnSale()); //New Retail pro data has sale in new field
116: Money price = product.getYourPrice();
117: assertNotNull(price);
118: //this depend on what is in stock
119: //assertEquals(545D,price.doubleValue(),0.001);
120:
121: InventoryItem item = product.getInventoryItemBySku("4163");
122: assertEquals(0, item.getQuantityInStock());
123:
124: Category catalog = getStore().getCatalog("LMABAAAAGHOLGIBC");
125: assertNotNull(catalog);
126: assertTrue(product.isInCatalog(catalog));
127:
128: product = getStore().getProduct("PAAAIAJDBDFHAEBN");
129: item = product.getInventoryItem(3);
130: Option option = item.getOption("handling");
131: assertNotNull("Should have handling option", option);
132: assertEquals("Handling amount", 1.00, option.getPriceSupport()
133: .getYourPriceByQuantity(1).doubleValue(), 0.001);
134:
135: //fldProdAvail="Sell Always" fldOutStockMsg_i="3" fldOutStockMsg="Please Allow 6-8 Weeks for Delivery"
136: product = getStore().getProduct("PAAAIACGONDPBBAI");
137: assertTrue(product.isAvailable());
138: assertTrue(product.isInStock());
139: assertEquals("Please Allow 6-8 Weeks for Delivery", product
140: .getProperty("outOfStockMsg"));
141: }
142:
143: public void XXXtestCustomerData() throws Exception {
144: Customer user = getStore().getCustomerArchive().getCustomer(
145: "3452");
146: assertNotNull(user);
147: }
148:
149: public void testParseDescription_Keywords() throws Exception {
150: RetailProCatalogConverter convert = new RetailProCatalogConverter();
151: String input = "Test keywords.";
152: String desc = convert.parseDescription(input);
153: String kwds = convert.parseKeywords(input);
154: assertEquals(input, desc);
155: assertNull(kwds);
156: input = "[[keyword1, keyword2 ]] Test keywords.";
157: desc = convert.parseDescription(input);
158: kwds = convert.parseKeywords(input);
159: assertEquals("Test keywords.", desc);
160: assertEquals("keyword1, keyword2", kwds);
161:
162: }
163:
164: public void setUp() throws Exception {
165: File uploadDir = new File(getStore().getStoreDirectory(),
166: "/upload");
167: uploadDir.mkdir();
168: File testDir = new File(uploadDir.getParentFile()
169: .getParentFile().getParentFile(), "etc/testupload");
170: File[] zipfiles = testDir.listFiles(new FilenameFilter() {
171:
172: public boolean accept(File inDir, String inName) {
173: return inName.endsWith(".zip");
174: }
175: });
176: OutputFiller filler = new OutputFiller();
177: for (int i = 0; i < zipfiles.length; i++) {
178: String name = zipfiles[i].getName();
179: File newFile = new File(uploadDir, name);
180: if (!newFile.exists()) {
181: filler.fill(zipfiles[i], newFile);
182: }
183: }
184: }
185:
186: }
|