KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > openedit > store > retailproconvert > RpConvertTest


1 /*
2  * Created on Sep 15, 2004
3  */

4 package com.openedit.store.retailproconvert;
5
6 import java.io.File JavaDoc;
7 import java.io.FilenameFilter JavaDoc;
8 import java.util.ArrayList JavaDoc;
9 import java.util.Iterator JavaDoc;
10 import java.util.List JavaDoc;
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 /**
23  * @author cburkey
24  *
25  */

26 public class RpConvertTest extends StoreTestCase
27 {
28     
29     /**
30      * @param inArg0
31      */

32     public RpConvertTest(String JavaDoc inArg0)
33     {
34         super(inArg0);
35
36     }
37     public static void main(String JavaDoc[] args) throws Exception JavaDoc
38     {
39 // runner = new TestRunner();
40
//TestRunner.run(ProductEditTest.class);
41
RpConvertTest test = new RpConvertTest("dffd");
42         test.setUp();
43         test.testCatalogConvert();
44     }
45     public void testFind() throws Exception JavaDoc
46     {
47         String JavaDoc f= "R:/Web Pics/Some Path.jpg";
48         String JavaDoc 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 JavaDoc
53     {
54     
55         RetailProCatalogConverter convert = new RetailProCatalogConverter();
56         List JavaDoc errors = new ArrayList JavaDoc();
57         convert.convert(getStore(), errors);
58         
59         for (Iterator JavaDoc iter = errors.iterator(); iter.hasNext();)
60         {
61             String JavaDoc element = (String JavaDoc) iter.next();
62             System.out.println(element);
63             
64         }
65         File JavaDoc productsDir = new File JavaDoc( getStore().getStoreDirectory(), "products");
66         
67         File JavaDoc[] listxconfs = productsDir.listFiles(new FilenameFilter JavaDoc()
68         {
69             public boolean accept(File JavaDoc inDir, String JavaDoc 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 JavaDoc[] listhtml = productsDir.listFiles(new FilenameFilter JavaDoc()
81             {
82                 public boolean accept(File JavaDoc inDir, String JavaDoc 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 JavaDoc thumbnailsDir = new File JavaDoc( getStore().getStoreDirectory(), "/products/images/thumb" );
93         File JavaDoc[] thumbnailList = thumbnailsDir.listFiles( new FilenameFilter JavaDoc()
94             {
95                 public boolean accept( File JavaDoc dir, String JavaDoc 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 JavaDoc
108     {
109         
110         List JavaDoc catalogs = getStore().getCatalogArchive().listAllCatalogs();
111         assertTrue( catalogs.size() > 2);
112         
113         Product product = getStore().getProduct("PAAAAAPCJLCAEGAI");
114         
115         // there are 6 items, and all 6 should be imported even though one is out of stock
116
assertEquals(6, product.getInventoryItemCount() );
117         
118         assertTrue(product.isAvailable());
119         assertTrue(product.isInStock());
120         //assertTrue(product.isOnSale()); //New Retail pro data has sale in new field
121
Money price = product.getYourPrice();
122         assertNotNull(price);
123         //this depend on what is in stock
124
//assertEquals(545D,price.doubleValue(),0.001);
125

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         //fldProdAvail="Sell Always" fldOutStockMsg_i="3" fldOutStockMsg="Please Allow 6-8 Weeks for Delivery"
143
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 JavaDoc
150     {
151         Customer user = getStore().getCustomerArchive().getCustomer("3452");
152         assertNotNull(user);
153     }
154     
155     public void testParseDescription_Keywords() throws Exception JavaDoc
156     {
157         RetailProCatalogConverter convert = new RetailProCatalogConverter();
158         String JavaDoc input = "Test keywords.";
159         String JavaDoc desc = convert.parseDescription( input );
160         String JavaDoc 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 JavaDoc
173     {
174         File JavaDoc uploadDir = new File JavaDoc( getStore().getStoreDirectory(), "/upload" );
175         uploadDir.mkdir();
176         File JavaDoc testDir = new File JavaDoc( uploadDir.getParentFile().getParentFile().getParentFile(), "etc/testupload");
177         File JavaDoc[] zipfiles = testDir.listFiles(new FilenameFilter JavaDoc() {
178         
179             public boolean accept(File JavaDoc inDir, String JavaDoc 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 JavaDoc name = zipfiles[i].getName();
188             File JavaDoc newFile = new File JavaDoc( uploadDir, name );
189             if( !newFile.exists())
190             {
191                 filler.fill( zipfiles[i], newFile );
192             }
193         }
194     }
195     
196
197 }
198
Popular Tags