PageRenderTime 8ms CodeModel.GetById 2ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

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

http://sigma-h.googlecode.com/
Java | 86 lines | 51 code | 25 blank | 10 comment | 0 complexity | 64a416d56d7cd7261eeb9b143f82a710 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.Before;
10import org.junit.Test;
11import org.junit.runner.RunWith;
12import org.sigmah.server.dao.OnDataSet;
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.AttributeGroupDTO;
19import org.sigmah.shared.dto.SchemaDTO;
20import org.sigmah.test.InjectionSupport;
21
22import java.util.HashMap;
23import java.util.Map;
24
25@RunWith(InjectionSupport.class)
26@OnDataSet("/dbunit/schema1.db.xml")
27public class AttributeGroupTest extends CommandTestCase {
28
29
30    @Before
31    public void setUp() {
32        setUser(1);
33    }
34
35    @Test
36    public void testCreate() throws Exception {
37
38        // execute the command
39
40        Map<String, Object> properties = new HashMap<String, Object>();
41        properties.put("name", "Type de Conflit");
42        properties.put("multipleAllowed", true);
43        properties.put("activityId", 1);
44
45        CreateEntity cmd = new CreateEntity("AttributeGroup", properties);
46
47        CreateResult result = execute(cmd);
48
49        // check if it has been added
50
51        SchemaDTO schema = execute(new GetSchema());
52
53        ActivityDTO activity = schema.getActivityById(1);
54        AttributeGroupDTO group = activity.getAttributeGroupById(result.getNewId());
55
56        Assert.assertNotNull("attribute group is created", group);
57        Assert.assertEquals("name is correct", group.getName(), "Type de Conflit");
58        Assert.assertTrue("multiple allowed is set to true", group.isMultipleAllowed());
59    }
60
61
62    @Test
63    public void testUpdate() throws Exception {
64
65        // initial data load
66
67        SchemaDTO schema = execute(new GetSchema());
68
69        // change the name of an entity group
70        ActivityDTO activity = schema.getActivityById(1);
71        AttributeGroupDTO group = activity.getAttributeGroups().get(0);
72        group.setName("Foobar");
73
74        Map<String, Object> changes = new HashMap<String, Object>();
75        changes.put("name", group.getName());
76
77        execute(new UpdateEntity(group, changes));
78
79        // reload data
80        schema = execute(new GetSchema());
81
82        // verify the property has been duly changed
83        Assert.assertEquals(group.getName(), schema.getActivityById(1).getAttributeGroups().get(0).getName());
84
85    }
86}