001: /*
002: * Created on Sep 23, 2004
003: */
004: package org.openedit.store;
005:
006: import org.openedit.money.Fraction;
007: import org.openedit.money.Money;
008: import org.openedit.store.customer.Address;
009: import org.openedit.store.customer.Customer;
010: import org.openedit.store.orders.Order;
011: import org.openedit.store.shipping.FixedCostShippingMethod;
012: import org.openedit.store.xmldb.XmlStoreArchive;
013:
014: import com.openedit.BaseTestCase;
015: import com.openedit.TestFixture;
016:
017: /**
018: * @author Matthew Avery, mavery@einnovation.com
019: */
020: public abstract class StoreTestCase extends BaseTestCase {
021: protected Store fieldStore;
022: protected static TestFixture fieldStaticFixture;
023:
024: public TestFixture getFixture() {
025: if (fieldStaticFixture == null) {
026: fieldStaticFixture = super .getFixture();
027: }
028: return fieldStaticFixture;
029: }
030:
031: public StoreTestCase(String arg0) {
032: super (arg0);
033: }
034:
035: protected Store getStore() throws Exception {
036: if (fieldStore == null) {
037: XmlStoreArchive reader = (XmlStoreArchive) getFixture()
038: .getModuleManager().getBean("StoreDataReader");
039: fieldStore = reader.getStore("store");
040: }
041: return fieldStore;
042: }
043:
044: protected Price createPrice(double inValue) {
045: Price price = new Price();
046: price.setRetailPrice(new Money(inValue));
047: return price;
048: }
049:
050: protected CartItem createCheapToyCartItem() throws StoreException {
051: Product cheapToyProduct = new Product("cheap toy");
052: final double CHEAP_TOY_PRICE = 1.99;
053: cheapToyProduct.setPriceSupport(new PriceSupport());
054: cheapToyProduct.addTierPrice(1, createPrice(CHEAP_TOY_PRICE));
055:
056: InventoryItem item = new InventoryItem();
057: item.setQuantityInStock(10000);
058: item.setSku("5432145dde");
059:
060: cheapToyProduct.addInventoryItem(item);
061: CartItem cheapToy = new CartItem();
062: cheapToy.setQuantity(5);
063: cheapToy.setInventoryItem(item);
064: return cheapToy;
065: }
066:
067: protected Customer createCustomer() {
068: Customer customer = new Customer();
069: Address address = customer.getBillingAddress();
070: address.setAddress1("5052 Gray Rd");
071: address.setCity("Cincinnati");
072: address.setState("OH");
073: customer.setFirstName("Christopher");
074: customer.setLastName("Burkey");
075: customer.setEmail("cburkey@openedit.org");
076: address.setCountry("USA");
077: customer.setPhone1("513-542-3401");
078: customer.setUserName("cburkey");
079: address.setZipCode("45232");
080: customer.setTaxRate(new Fraction(0.07));
081: return customer;
082: }
083:
084: protected ShippingMethod createShippingMethod() {
085: FixedCostShippingMethod method = new FixedCostShippingMethod();
086: method.setCost(new Money(6.50));
087: method.setDescription("UPS ground");
088: method.setId("UPS1");
089: return method;
090: }
091:
092: protected PaymentMethod createPaymentMethod() {
093: CreditPaymentMethod paymentMethod = new CreditPaymentMethod();
094: CreditCardType type = new CreditCardType();
095: type.setName("Mastercard");
096: paymentMethod.setCreditCardType(type);
097: paymentMethod.setCardNumber("5555444455554444");
098: paymentMethod.setExpirationMonth(12);
099: paymentMethod.setExpirationYear(2004);
100: return paymentMethod;
101: }
102:
103: protected Cart createCart() throws StoreException {
104: Cart cart = new Cart();
105:
106: cart.addItem(createCheapToyCartItem());
107: cart.setCustomer(createCustomer());
108: cart.setShippingMethod(createShippingMethod());
109: return cart;
110: }
111:
112: protected Order createOrder() throws Exception {
113: Order order = getStore().getOrderGenerator().createNewOrder(
114: getStore(), createCart());
115: order.setId("TESTORDER1");
116: order.setPaymentMethod(createPaymentMethod());
117: return order;
118: }
119:
120: }
|