1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package net.sf.oness.order.webapp.controller.action;
17
18 import java.math.BigDecimal;
19 import java.util.ArrayList;
20 import java.util.Calendar;
21 import java.util.List;
22
23 import net.sf.oness.common.model.temporal.Date;
24 import net.sf.oness.common.model.util.CollectionUtils;
25 import net.sf.oness.common.model.util.PaginatedList;
26 import net.sf.oness.common.webapp.controller.action.ActionUtils;
27 import net.sf.oness.common.webapp.controller.testing.JMockStrutsTestCase;
28 import net.sf.oness.order.model.bo.Invoice;
29 import net.sf.oness.order.model.bo.InvoiceItem;
30 import net.sf.oness.order.model.facade.OrderFacadeDelegate;
31 import net.sf.oness.order.model.to.InvoiceWithParty;
32 import net.sf.oness.order.webapp.controller.actionform.MasterActionForm;
33 import net.sf.oness.party.model.party.bo.Person;
34
35 import org.jmock.Mock;
36
37 /***
38 * @author Carlos Sanchez
39 * @version $Revision: 1.1 $
40 */
41 public class InvoiceActionTest extends JMockStrutsTestCase {
42
43 private Mock mockFacade;
44
45 private Invoice invoice;
46
47 private InvoiceItem invoiceItem;
48
49 private InvoiceWithParty invoiceWithParty;
50
51 /***
52 * @see junit.framework.TestCase#setUp()
53 */
54 protected void setUp() throws Exception {
55 super.setUp();
56 mockFacade = new Mock(OrderFacadeDelegate.class);
57 getMockWebApplicationContext().expects(atLeastOnce()).method("getBean")
58 .with(eq("orderFacadeDelegate")).will(
59 returnValue(mockFacade.proxy()));
60
61 invoice = new Invoice();
62 invoice.setType(new Integer(1));
63 invoice.setPartyId(new Long(1));
64 invoice.setDate(new Date(2004, Calendar.JANUARY, 1));
65 invoice.setItems(CollectionUtils.newList(new InvoiceItem()));
66
67 invoiceItem = new InvoiceItem();
68 invoiceItem.setPrice(new BigDecimal("10"));
69 invoiceItem.setProductId(new Long(1));
70 invoiceItem.setQuantity(new BigDecimal("1"));
71
72 invoiceWithParty = new InvoiceWithParty();
73 invoiceWithParty.setInvoice(invoice);
74 invoiceWithParty.setParty(new Person());
75 invoiceWithParty.setItems(CollectionUtils.newList(invoiceItem));
76 invoiceWithParty.setAmount(new BigDecimal(0));
77 }
78
79 final public void testCreate() {
80
81 List deliveryDocketIds = new ArrayList(2);
82 deliveryDocketIds.add(new Long(1));
83 deliveryDocketIds.add(new Long(2));
84
85
86 mockFacade.expects(once()).method("createInvoices").with(eq(deliveryDocketIds));
87
88 Invoice returned = (Invoice) invoice.clone();
89 returned.setId(new Long(1));
90
91 struts().setRequestPathInfo("/invoice/create");
92 struts().addRequestParameter("dateAsString", "1/1/04");
93 struts().addRequestParameter("deliveryDocketsSize", "2");
94 struts().addRequestParameter("deliveryDocket[0].id", "1");
95 struts().addRequestParameter("deliveryDocket[1].id", "2");
96
97 struts().actionPerform();
98 struts().verifyNoActionErrors();
99 mockFacade.verify();
100 }
101
102 }