PageRenderTime 25ms CodeModel.GetById 11ms app.highlight 10ms RepoModel.GetById 2ms app.codeStats 0ms

/sigmah/src/test/java/org/sigmah/server/endpoint/gwtrpc/MonthlyReportsTest.java

http://sigma-h.googlecode.com/
Java | 84 lines | 54 code | 25 blank | 5 comment | 0 complexity | fd7e5042e3afaaf5c80b4195f34a1d8d MD5 | raw file
 1/*
 2 * All Sigmah code is released under the GNU General Public License v3
 3 * See COPYRIGHT.txt and LICENSE.txt.
 4 */
 5
 6package org.sigmah.server.endpoint.gwtrpc;
 7
 8import org.junit.Assert;
 9import org.junit.Test;
10import org.junit.runner.RunWith;
11import org.sigmah.server.dao.OnDataSet;
12import org.sigmah.shared.command.GetMonthlyReports;
13import org.sigmah.shared.command.Month;
14import org.sigmah.shared.command.UpdateMonthlyReports;
15import org.sigmah.shared.command.result.MonthlyReportResult;
16import org.sigmah.test.InjectionSupport;
17
18import java.util.ArrayList;
19
20@RunWith(InjectionSupport.class)
21@OnDataSet("/dbunit/sites-simple1.db.xml")
22public class MonthlyReportsTest extends CommandTestCase {
23
24
25    @Test
26    public void testMonthCompare() throws Exception {
27
28        Month feb = new Month(2009, 2);
29
30        Month maxMonth = new Month(2009, 2);
31
32        Assert.assertEquals(0, maxMonth.compareTo(feb));
33    }
34
35    @Test
36    public void testGetReports() throws Exception {
37
38        GetMonthlyReports cmd = new GetMonthlyReports(6);
39        cmd.setStartMonth(new Month(2009, 1));
40        cmd.setEndMonth(new Month(2009, 2));
41
42        MonthlyReportResult result = execute(cmd);
43
44        Assert.assertEquals(1, result.getData().size());
45        Assert.assertEquals(35, result.getData().get(0).getValue(2009, 1).intValue());
46        Assert.assertEquals(70, result.getData().get(0).getValue(2009, 2).intValue());
47    }
48
49    @Test
50    public void testGetReportsWhenEmpty() throws Exception {
51
52        GetMonthlyReports cmd = new GetMonthlyReports(7);
53        cmd.setStartMonth(new Month(2009, 1));
54        cmd.setEndMonth(new Month(2009, 2));
55
56        MonthlyReportResult result = execute(cmd);
57
58        Assert.assertEquals(1, result.getData().size());
59    }
60
61    @Test
62    public void testUpdate() throws Exception {
63        ArrayList<UpdateMonthlyReports.Change> changes = new ArrayList<UpdateMonthlyReports.Change>();
64        changes.add(new UpdateMonthlyReports.Change(6, new Month(2009, 1), 45.0));
65        changes.add(new UpdateMonthlyReports.Change(6, new Month(2009, 3), 22.0));
66
67
68        execute(new UpdateMonthlyReports(6, changes));
69
70        // verify that that changes have been made
71        GetMonthlyReports cmd = new GetMonthlyReports(6);
72        cmd.setStartMonth(new Month(2009, 1));
73        cmd.setEndMonth(new Month(2009, 3));
74
75        MonthlyReportResult result = execute(cmd);
76
77        Assert.assertEquals(1, result.getData().size());
78        Assert.assertEquals(45, result.getData().get(0).getValue(2009, 1).intValue());
79        Assert.assertEquals(70, result.getData().get(0).getValue(2009, 2).intValue());
80        Assert.assertEquals(22, result.getData().get(0).getValue(2009, 3).intValue());
81    }
82
83
84}