KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > openedit > store > StoreTestCase


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

4 package com.openedit.store;
5
6 import org.openedit.money.Fraction;
7 import org.openedit.money.Money;
8
9 import com.openedit.BaseTestCase;
10 import com.openedit.modules.cart.StoreDataReader;
11 import com.openedit.store.customer.Address;
12 import com.openedit.store.customer.Customer;
13 import com.openedit.store.shipping.FixedCostShippingMethod;
14
15 /**
16  * @author Matthew Avery, mavery@einnovation.com
17  */

18 public abstract class StoreTestCase extends BaseTestCase
19 {
20     protected Store fieldStore;
21     
22     public StoreTestCase( String JavaDoc arg0 )
23     {
24         super( arg0 );
25         String JavaDoc base = System.getProperty("oe.root.path");
26         if ( base == null)
27         {
28             System.setProperty("oe.root.path","webapp");
29         }
30     }
31     protected Store getStore() throws Exception JavaDoc
32     {
33         if ( fieldStore == null)
34         {
35             StoreDataReader reader = (StoreDataReader)getFixture().getModuleManager().getBean("StoreDataReader");
36             fieldStore = reader.getStore("store");
37         }
38         return fieldStore;
39     }
40     protected Price createPrice( double inValue )
41     {
42         Price price = new Price();
43         price.setRetailPrice( new Money( inValue ) );
44         return price;
45     }
46     protected CartItem createCheapToyCartItem() throws StoreException
47     {
48         Product cheapToyProduct = new Product( "cheap toy" );
49         final double CHEAP_TOY_PRICE = 1.99;
50         cheapToyProduct.setPriceSupport(new PriceSupport());
51         cheapToyProduct.addTierPrice(1, createPrice( CHEAP_TOY_PRICE ) );
52     
53         InventoryItem item = new InventoryItem();
54         item.setQuantityInStock(10000);
55         item.setSku("5432145dde");
56         
57         cheapToyProduct.addInventoryItem(item);
58         CartItem cheapToy = new CartItem();
59         cheapToy.setQuantity(5);
60         cheapToy.setInventoryItem(item);
61         return cheapToy;
62     }
63     protected Customer createCustomer()
64     {
65         Customer customer = new Customer();
66         Address address = customer.getBillingAddress();
67         address.setAddress1( "5052 Gray Rd");
68         address.setCity("Cincinnati");
69         address.setState("OH");
70         customer.setFirstName("Christopher");
71         customer.setLastName( "Burkey");
72         customer.setEmail( "cburkey@openedit.org");
73         address.setCountry("USA");
74         customer.setPhone1("513-542-3401");
75         customer.setUserName( "cburkey" );
76         address.setZipCode("45232");
77         customer.setTaxRate( new Fraction( 0.07 ) );
78         return customer;
79     }
80     protected ShippingMethod createShippingMethod()
81     {
82         FixedCostShippingMethod method = new FixedCostShippingMethod();
83         method.setCost( new Money(6.50) );
84         method.setDescription( "UPS ground" );
85         method.setId("UPS1");
86         return method;
87     }
88     protected PaymentMethod createPaymentMethod()
89     {
90         CreditPaymentMethod paymentMethod = new CreditPaymentMethod();
91         CreditCardType type = new CreditCardType();
92         type.setName( "Mastercard" );
93         paymentMethod.setCreditCardType( type );
94         paymentMethod.setCardNumber( "5555444455554444" );
95         paymentMethod.setExpirationMonth( 12 );
96         paymentMethod.setExpirationYear( 2004 );
97         return paymentMethod;
98     }
99     protected Cart createCart() throws StoreException
100     {
101         Cart cart = new Cart();
102         
103         cart.addItem( createCheapToyCartItem() );
104         cart.setCustomer( createCustomer() );
105         cart.setShippingMethod( createShippingMethod() );
106         return cart;
107     }
108     protected Order createOrder() throws Exception JavaDoc
109     {
110         Order order = getStore().getOrderGenerator().createNewOrder(getStore(),createCart());
111         order.setId( "TESTORDER1" );
112         order.setPaymentMethod( createPaymentMethod() );
113         return order;
114     }
115
116 }
117
Popular Tags