PageRenderTime 12ms CodeModel.GetById 1ms app.highlight 7ms RepoModel.GetById 2ms app.codeStats 0ms

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

http://sigma-h.googlecode.com/
Java | 68 lines | 46 code | 18 blank | 4 comment | 0 complexity | 7bbe66878d3083276c7e49328d691aa6 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.CreateEntity;
13import org.sigmah.shared.command.GetSchema;
14import org.sigmah.shared.command.result.CreateResult;
15import org.sigmah.shared.dto.SchemaDTO;
16import org.sigmah.shared.dto.UserDatabaseDTO;
17import org.sigmah.shared.exception.CommandException;
18import org.sigmah.test.InjectionSupport;
19
20import static org.hamcrest.CoreMatchers.*;
21import static org.junit.Assert.assertThat;
22
23@RunWith(InjectionSupport.class)
24public class CreateDatabaseTest extends CommandTestCase {
25
26    @Test
27    @OnDataSet("/dbunit/sites-simple1.db.xml")
28    public void testCreate() throws CommandException {
29
30        UserDatabaseDTO db = new UserDatabaseDTO();
31        db.setName("RIMS");
32        db.setFullName("Reintegration Management Information System");
33
34        CreateResult cr = execute(new CreateEntity(db));
35
36        SchemaDTO schema = execute(new GetSchema());
37
38        UserDatabaseDTO newdb = schema.getDatabaseById(cr.getNewId());
39
40        Assert.assertEquals(db.getName(), newdb.getName());
41        Assert.assertEquals(db.getFullName(), newdb.getFullName());
42        Assert.assertNotNull(newdb.getCountry());
43        Assert.assertEquals("Alex", newdb.getOwnerName());
44    }
45
46    @Test
47    @OnDataSet("/dbunit/multicountry.db.xml")
48    public void createWithSpecificCountry() throws CommandException {
49
50        UserDatabaseDTO db = new UserDatabaseDTO();
51        db.setName("Warchild Haiti");
52        db.setFullName("Warchild Haiti");
53
54        setUser(1);
55
56        CreateEntity cmd = new CreateEntity(db);
57        cmd.getProperties().put("countryId", 2);
58        CreateResult cr = execute(cmd);
59
60        SchemaDTO schema = execute(new GetSchema());
61
62        UserDatabaseDTO newdb = schema.getDatabaseById(cr.getNewId());
63
64        assertThat(newdb.getCountry(), is(notNullValue()));
65        assertThat(newdb.getCountry().getName(), is(equalTo("Haiti")));
66    }
67
68}