1
2
3 package com.pnpconsult.zeiterfassung.table;
4
5 import java.text.ParseException;
6 import java.util.ArrayList;
7 import java.util.HashSet;
8 import java.util.Iterator;
9 import java.util.List;
10 import java.util.Set;
11
12 import jface.mockobject.Actions;
13 import jface.mockobject.Expectation;
14
15 import com.pnpconsult.zeiterfassung.model.Activity;
16 import com.pnpconsult.zeiterfassung.model.Bill;
17 import com.pnpconsult.zeiterfassung.model.BillEntry;
18 import com.pnpconsult.zeiterfassung.model.Customer;
19 import com.pnpconsult.zeiterfassung.model.Project;
20 import com.pnpconsult.zeiterfassung.model.User;
21 import com.pnpconsult.zeiterfassung.model.UserEntry;
22 import com.pnpconsult.zeiterfassung.model.UserProject;
23 import com.pnpconsult.zeiterfassung.util.DateUtils;
24
25 /***
26 * @author <a href="mailto:powerpete@users.sf.net">M. Petersen</a>
27 * @version $Id: TableTest.java,v 1.9 2004/07/22 08:41:28 powerpete Exp $
28 */
29 public class TableTest extends AbstractTableTestCase
30 {
31 public TableTest(String arg0)
32 {
33 super(arg0);
34 }
35
36 public void testStupid()
37 {
38 System.out.println("----- STUPID ------");
39 }
40
41 public void testTableWithDifferentEntryTypes() throws Exception
42 {
43 if (true)
44 return;
45
46 final Actions actions = new Actions();
47
48 Activity konzeption = new Activity();
49 konzeption.setName("Konzeption");
50 konzeption.setBillingFactor(1.0F);
51 Activity praesentation = new Activity();
52 praesentation.setName("Präsentation");
53 praesentation.setBillingFactor(2.0F);
54
55 Customer customer = new Customer();
56 customer.setName("Testkunde");
57
58 Project project = new Project();
59 project.setCurrency("EUR");
60 project.setCustomer(customer);
61 project.setName("Testprojekt");
62 project.setTaxValue0(16.0F);
63 project.setTaxDate0(DateUtils.parse("01.01.2003"));
64
65 User aschmidt = new User();
66 aschmidt.setFirstName("Alexander");
67 aschmidt.setLastName("Schmidt");
68 aschmidt.setRate(80.0F);
69 UserProject aschmidtUserProject = new UserProject();
70 aschmidtUserProject.setBillingFactor(2.0F);
71 aschmidtUserProject.setProject(project);
72 aschmidtUserProject.setUser(aschmidt);
73 aschmidt.addUserProject(aschmidtUserProject);
74
75 User bthiede = new User();
76 bthiede.setFirstName("Britta");
77 bthiede.setLastName("Thiede");
78 bthiede.setRate(120.0F);
79 UserProject bthiedeUserProject = new UserProject();
80 bthiedeUserProject.setBillingFactor(1.0F);
81 bthiedeUserProject.setProject(project);
82 bthiedeUserProject.setUser(bthiede);
83 bthiede.addUserProject(bthiedeUserProject);
84
85 Bill bill = new Bill();
86 bill.setEndDate(DateUtils.parse("30.09.2003"));
87 bill.setProject(project);
88 bill.setStartDate(DateUtils.parse("01.09.2003"));
89
90 List userEntries = new ArrayList();
91 userEntries.add(createUserEntry(
92 1.0F,
93 "21.09.2003",
94 2.0F,
95 konzeption,
96 "Information",
97 "Verkaufsbüro",
98 project,
99 "22.09.2003",
100 aschmidt));
101 userEntries.add(createUserEntry(
102 1.0F,
103 "21.09.2003",
104 3.0F,
105 konzeption,
106 "Information",
107 "Verkaufsbüro",
108 project,
109 "22.09.2003",
110 bthiede));
111 userEntries.add(createUserEntry(
112 1.0F,
113 "21.09.2003",
114 2.0F,
115 praesentation,
116 null,
117 null,
118 project,
119 "22.09.2003",
120 bthiede));
121 actions.expect(new Expectation("loadUserEntries")
122 .parameter(bill)
123 .returnValue(userEntries));
124
125 Set billEntries = new HashSet();
126 billEntries.add(createBillEntry(
127 bill,
128 "Workshop Vorbereitung",
129 3.0F,
130 project,
131 120.0F,
132 "22.09.2003",
133 aschmidt));
134 billEntries.add(createBillEntry(
135 bill,
136 "Workshop Vorbereitung",
137 3.0F,
138 project,
139 120.0F,
140 "22.09.2003",
141 aschmidt));
142 bill.setBillEntries(billEntries);
143
144 Table table = new Table(bill);
145
146 assertEquals("16 %", table.getTax());
147 assertEquals("1.880,00", table.getTotal());
148 assertEquals("300,80", table.getTotalTax());
149 assertEquals("2.180,80", table.getTotalIncludingTax());
150
151 assertEquals(4, table.getRows().size());
152
153 Iterator rows = table.getRows().iterator();
154 Row row1 = (Row) rows.next();
155 Row row2 = (Row) rows.next();
156 Row row3 = (Row) rows.next();
157 Row row4 = (Row) rows.next();
158
159 assertRow(row1, BillEntryRow.class, 1, "Workshop Vorbereitung");
160 assertRow(row2, BillEntryRow.class, 1, "Workshop Vorbereitung");
161 assertRow(
162 row3,
163 UserEntryRow.class,
164 1,
165 "Präsentation, Termin: 22.09.2003");
166 assertRow(
167 row4,
168 UserEntryRow.class,
169 2,
170 "Konzeption, Verkaufsbüro, Termin: 22.09.2003, Information");
171
172 actions.assertEmpty();
173 }
174
175 private void assertRow(Row row1, Class clazz, int size, String description)
176 {
177 assertEquals(clazz, row1.getClass());
178 assertEquals(size, row1.getRateRowsSize());
179 assertEquals(description, row1.getDescription());
180 }
181
182 private BillEntry createBillEntry(
183 Bill bill,
184 String description,
185 float hours,
186 Project project,
187 float rate,
188 String targetDate,
189 User aschmidt) throws ParseException
190 {
191 BillEntry billEntry = new BillEntry();
192 billEntry.setBill(bill);
193 billEntry.setDescription(description);
194 billEntry.setHours(hours);
195 billEntry.setProject(project);
196 billEntry.setRate(rate);
197 billEntry.setTargetDate(DateUtils.parse(targetDate));
198 billEntry.setUser(aschmidt);
199 return billEntry;
200 }
201
202 private UserEntry createUserEntry(
203 float billingFactor,
204 String date,
205 float hours,
206 Activity konzeption,
207 String information,
208 String involved,
209 Project project,
210 String targetDate,
211 User aschmidt) throws ParseException
212 {
213 UserEntry userEntry = new UserEntry();
214 userEntry.setActivity(konzeption);
215 userEntry.setBillingFactor(billingFactor);
216 userEntry.setDate(DateUtils.parse(date));
217 userEntry.setHours(hours);
218 userEntry.setInformation(information);
219 userEntry.setInvolved(involved);
220 userEntry.setProject(project);
221 userEntry.setTargetDate(DateUtils.parse(targetDate));
222 userEntry.setUser(aschmidt);
223 return userEntry;
224 }
225 }