PageRenderTime 15ms CodeModel.GetById 1ms app.highlight 11ms RepoModel.GetById 1ms app.codeStats 0ms

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

http://sigma-h.googlecode.com/
Java | 97 lines | 61 code | 25 blank | 11 comment | 0 complexity | a634fc1846a2da42d2b6627846aa0e9a 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.Ignore;
10import org.junit.Test;
11import org.junit.runner.RunWith;
12import org.sigmah.server.dao.OnDataSet;
13import org.sigmah.shared.command.GetSites;
14import org.sigmah.shared.command.UpdateEntity;
15import org.sigmah.shared.command.result.ListResult;
16import org.sigmah.shared.domain.Site;
17import org.sigmah.shared.dto.SiteDTO;
18import org.sigmah.shared.exception.CommandException;
19import org.sigmah.test.InjectionSupport;
20
21import java.util.HashMap;
22import java.util.Map;
23
24
25@RunWith(InjectionSupport.class)
26@OnDataSet("/dbunit/sites-simple1.db.xml")
27public class UpdateSiteTest extends CommandTestCase {
28
29
30    @Test
31    public void testUpdate() throws CommandException {
32        // retrieve from the server
33        ListResult<SiteDTO> result = execute(GetSites.byId(1));
34
35        SiteDTO model = result.getData().get(0);
36
37        // modify and generate command
38        model.setComments("NEW <b>Commentaire</b>");
39        model.setLocationName("NEWNAME");
40        model.setAttributeValue(1, true);
41        model.setAttributeValue(2, null);
42        model.setAttributeValue(3, true);
43        model.setAttributeValue(4, false);
44        model.setIndicatorValue(2, 995.0);
45        model.setAdminEntity(2, null);
46
47
48        execute(new UpdateEntity(model, model.getProperties()));
49
50        // retrieve the old one
51
52        result = execute(GetSites.byId(1));
53        SiteDTO secondRead = result.getData().get(0);
54
55        // confirm that the changes are there
56        Assert.assertEquals("site.comments", model.getComments(), secondRead.getComments());
57        Assert.assertEquals("site.location.name", model.getLocationName(), secondRead.getLocationName());
58        Assert.assertEquals("site.reportingPeriod[0].indicatorValue[0]", 995,
59                secondRead.getIndicatorValue(2).intValue());
60
61        Assert.assertEquals("site.attribute[1]", true, model.getAttributeValue(1));
62        Assert.assertNull("site.attribute[2]", model.getAttributeValue(2));
63        Assert.assertEquals("site.attribute[3]", true, model.getAttributeValue(1));
64        Assert.assertEquals("site.attribute[4]", true, model.getAttributeValue(1));
65    }
66
67    @Ignore
68    @Test
69    public void testUpdatePartner() throws CommandException {
70        // define changes for site id=2
71        Map<String, Object> changes = new HashMap<String, Object>();
72        changes.put("partnerId", 2);
73
74        execute(new UpdateEntity("Site", 2, changes));
75
76        // assure that the change has been effected
77
78        Site site = em.find(Site.class, 2);
79        Assert.assertEquals("partnerId", 2, site.getPartner().getId());
80    }
81
82    @Test
83    @OnDataSet("/dbunit/project-indicator.db.xml")
84    public void updateLocationNameOnSiteWithoutActivityId() throws CommandException {
85    	
86    	Map<String, Object> changes = new HashMap<String, Object>();
87    	changes.put("locationName", "Goma 2");
88    	
89    	execute(new UpdateEntity("Site", 4, changes));
90    	
91        // assure that the change has been effected
92    	
93        Site site = em.find(Site.class, 4);
94        Assert.assertEquals("location Name", "Goma 2", site.getLocation().getName());
95    	
96    }
97}