PageRenderTime 36ms CodeModel.GetById 25ms app.highlight 9ms RepoModel.GetById 1ms app.codeStats 0ms

/sigmah/src/test/java/org/sigmah/client/offline/command/handler/LocalGetSchemaHandlerIntTest.java

http://sigma-h.googlecode.com/
Java | 80 lines | 59 code | 17 blank | 4 comment | 0 complexity | 4cab9e3dbb3ad2b9b131706cd049bebc 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.client.offline.command.handler;
 7
 8import org.junit.Test;
 9import org.junit.runner.RunWith;
10import org.sigmah.server.dao.OnDataSet;
11import org.sigmah.server.endpoint.gwtrpc.GwtRpcModule;
12import org.sigmah.server.util.BeanMappingModule;
13import org.sigmah.server.util.logging.LoggingModule;
14import org.sigmah.shared.command.GetSchema;
15import org.sigmah.shared.command.handler.LocalHandlerTestCase;
16import org.sigmah.shared.dto.ActivityDTO;
17import org.sigmah.shared.dto.AttributeGroupDTO;
18import org.sigmah.shared.dto.SchemaDTO;
19import org.sigmah.shared.dto.UserDatabaseDTO;
20import org.sigmah.shared.exception.CommandException;
21import org.sigmah.test.InjectionSupport;
22import org.sigmah.test.MockHibernateModule;
23import org.sigmah.test.Modules;
24
25import static org.hamcrest.CoreMatchers.equalTo;
26import static org.junit.Assert.assertThat;
27
28@RunWith(InjectionSupport.class)
29@Modules({
30        MockHibernateModule.class,
31        BeanMappingModule.class,
32        GwtRpcModule.class,
33        LoggingModule.class
34})
35public class LocalGetSchemaHandlerIntTest extends LocalHandlerTestCase {
36
37
38    @Test
39    @OnDataSet("/dbunit/sites-simple1.db.xml")
40    public void forDatabaseOwner() throws CommandException {
41
42        synchronize();
43
44        LocalGetSchemaHandler handler = new LocalGetSchemaHandler(localConnection, localAuth);
45        SchemaDTO schema = handler.execute(new GetSchema(), user);
46
47        assertThat(schema.getDatabases().size(), equalTo(2));
48        assertThat(schema.getDatabaseById(1).isDesignAllowed(), equalTo(true));
49        assertThat(schema.getDatabaseById(1).getAmOwner(), equalTo(true));
50        assertThat(schema.getDatabaseById(2).getAmOwner(), equalTo(true));
51        assertThat(schema.getDatabaseById(1).getOwnerName(), equalTo("Alex"));
52
53    }
54
55    @Test
56    @OnDataSet("/dbunit/sites-simple1.db.xml")
57    public void forUser() throws CommandException {
58
59        setUser(2); // Bavon, has access only to PEAR
60        synchronize();
61
62        LocalGetSchemaHandler handler = new LocalGetSchemaHandler(localConnection, localAuth);
63        SchemaDTO schema = handler.execute(new GetSchema(), user);
64
65        assertThat(schema.getDatabases().size(), equalTo(1));
66
67        UserDatabaseDTO pearDb = schema.getDatabaseById(1);
68        assertThat(pearDb.getAmOwner(), equalTo(false));
69        assertThat(pearDb.isViewAllAllowed(), equalTo(false));
70        assertThat(pearDb.isEditAllowed(), equalTo(true));
71        assertThat(pearDb.isEditAllAllowed(), equalTo(false));
72
73        ActivityDTO activity = schema.getActivityById(1);
74        assertThat(activity.getAttributeGroups().size(), equalTo(2));
75
76        AttributeGroupDTO group = activity.getAttributeGroupById(1);
77        assertThat(group.getName(), equalTo("cause"));
78        assertThat(group.getAttributes().size(), equalTo(2));
79    }
80}