PageRenderTime 47ms CodeModel.GetById 37ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

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

http://sigma-h.googlecode.com/
Java | 93 lines | 53 code | 25 blank | 15 comment | 0 complexity | 9176ad934208bd2015e43acb5edf249f 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 junit.framework.Assert;
 9import org.junit.Test;
10import org.junit.runner.RunWith;
11import org.sigmah.server.dao.OnDataSet;
12import org.sigmah.shared.command.BatchCommand;
13import org.sigmah.shared.command.CreateEntity;
14import org.sigmah.shared.command.GetSchema;
15import org.sigmah.shared.command.UpdateEntity;
16import org.sigmah.shared.command.result.CreateResult;
17import org.sigmah.shared.dto.ActivityDTO;
18import org.sigmah.shared.dto.LocationTypeDTO;
19import org.sigmah.shared.dto.SchemaDTO;
20import org.sigmah.shared.dto.UserDatabaseDTO;
21import org.sigmah.shared.exception.CommandException;
22import org.sigmah.test.InjectionSupport;
23
24import java.util.HashMap;
25import java.util.Map;
26
27@RunWith(InjectionSupport.class)
28@OnDataSet("/dbunit/schema1.db.xml")
29public class ActivityTest extends CommandTestCase {
30
31
32    @Test
33    public void testActivity() throws CommandException {
34
35        /*
36           * Initial data load
37           */
38
39        SchemaDTO schema = execute(new GetSchema());
40
41        UserDatabaseDTO db = schema.getDatabaseById(1);
42
43        /*
44           * Create a new activity
45           */
46
47        LocationTypeDTO locType = schema.getCountryById(1).getLocationTypes().get(0);
48
49        ActivityDTO act = new ActivityDTO();
50        act.setName("Warshing the dishes");
51        act.setLocationTypeId(locType.getId());
52        act.setReportingFrequency(ActivityDTO.REPORT_MONTHLY);
53
54        CreateResult cresult = execute(CreateEntity.Activity(db, act));
55
56        int newId = cresult.getNewId();
57
58        /*
59           * Reload schema to verify the changes have stuck
60           */
61
62        schema = execute(new GetSchema());
63
64        act = schema.getActivityById(newId);
65
66        Assert.assertEquals("name", "Warshing the dishes", act.getName());
67        Assert.assertEquals("locationType", locType.getName(), act.getLocationType().getName());
68        Assert.assertEquals("reportingFrequency", ActivityDTO.REPORT_MONTHLY, act.getReportingFrequency());
69
70    }
71
72    @Test
73    public void updateSortOrderTest() throws Throwable {
74
75        /* Update Sort Order */
76        Map<String, Object> changes1 = new HashMap<String, Object>();
77        changes1.put("sortOrder", 2);
78        Map<String, Object> changes2 = new HashMap<String, Object>();
79        changes2.put("sortOrder", 1);
80
81        execute(new BatchCommand(
82                new UpdateEntity("Activity", 1, changes1),
83                new UpdateEntity("Activity", 2, changes2)
84        ));
85
86        /* Confirm the order is changed */
87
88        SchemaDTO schema = execute(new GetSchema());
89        Assert.assertEquals(2, schema.getDatabaseById(1).getActivities().get(0).getId());
90        Assert.assertEquals(1, schema.getDatabaseById(1).getActivities().get(1).getId());
91    }
92
93}