PageRenderTime 18ms CodeModel.GetById 9ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/sigmah/src/test/java/org/sigmah/client/page/config/DbUserTest.java

http://sigma-h.googlecode.com/
Java | 133 lines | 73 code | 36 blank | 24 comment | 0 complexity | 245d879295a29d1fcb48834122735b9f 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.page.config;
  7
  8import com.extjs.gxt.ui.client.store.Record;
  9import org.junit.Assert;
 10import org.junit.Test;
 11import org.sigmah.client.mock.DispatcherStub;
 12import org.sigmah.client.mock.DummyData;
 13import org.sigmah.client.mock.MockEventBus;
 14import org.sigmah.client.mock.MockStateManager;
 15import org.sigmah.client.page.common.toolbar.UIActions;
 16import org.sigmah.shared.command.GetUsers;
 17import org.sigmah.shared.command.UpdateUserPermissions;
 18import org.sigmah.shared.command.result.UserResult;
 19import org.sigmah.shared.command.result.VoidResult;
 20import org.sigmah.shared.dto.SchemaDTO;
 21
 22import static org.easymock.EasyMock.*;
 23
 24/**
 25 * @author Alex Bertram
 26 */
 27public class DbUserTest {
 28
 29    @Test
 30    public void testSaveButtonEnabled() {
 31
 32
 33        // Test Data
 34        UserResult users = DummyData.RRM_Users();
 35        SchemaDTO schema = DummyData.PEAR();
 36
 37        // Collaborator: command service
 38        DispatcherStub service = new DispatcherStub();
 39        service.setResult(GetUsers.class, users);
 40
 41        // Collaborator: View
 42        DbUserEditor.View view = createNiceMock(DbUserEditor.View.class);
 43        view.setActionEnabled(UIActions.save, false);
 44        replay(view);
 45
 46        // Class under test
 47        DbUserEditor editor = new DbUserEditor(new MockEventBus(), service, new MockStateManager(), view);
 48
 49        // VERIFY save button is initially disabled
 50        editor.go(schema.getDatabaseById(1), new DbPageState(DbUserEditor.DatabaseUsers, 1));
 51        verify(view);
 52
 53        // VERIFY that following a modification the button is enabled
 54        reset(view);
 55        view.setActionEnabled(UIActions.save, true);
 56        replay(view);
 57
 58        Record record = editor.getStore().getRecord(users.getData().get(0));
 59        record.set("allowViewAll", true);
 60
 61        verify(view);
 62    }
 63
 64    @Test
 65    public void testSave() {
 66
 67
 68        // Test Data
 69        UserResult users = DummyData.RRM_Users();
 70        SchemaDTO schema = DummyData.PEAR();
 71
 72        // Collaborator: command service
 73        DispatcherStub service = new DispatcherStub();
 74        service.setResult(GetUsers.class, users);
 75        service.setResult(UpdateUserPermissions.class, new VoidResult());
 76
 77        // Collaborator: View
 78        DbUserEditor.View view = createNiceMock(DbUserEditor.View.class);
 79        replay(view);
 80
 81        // Class under test
 82        DbUserEditor editor = new DbUserEditor(new MockEventBus(), service, new MockStateManager(), view);
 83        editor.go(schema.getDatabaseById(1), new DbPageState(DbUserEditor.DatabaseUsers, 1));
 84        
 85        // VERIFY that following a modification a user command to save results in
 86        // an update user command
 87
 88        Record record = editor.getStore().getRecord(users.getData().get(0));
 89        record.set("allowViewAll", true);
 90
 91        editor.onUIAction(UIActions.save);
 92
 93        UpdateUserPermissions cmd = service.getLastExecuted(UpdateUserPermissions.class);
 94        Assert.assertEquals("typhaine@sol.net", cmd.getModel().getEmail());
 95        Assert.assertEquals(true, cmd.getModel().getAllowViewAll());
 96    }
 97
 98
 99    @Test
100    public void testSaveButtonDisabledAfterSave() {
101
102
103        // Test Data
104        UserResult users = DummyData.RRM_Users();
105        SchemaDTO schema = DummyData.PEAR();
106
107        // Collaborator: command service
108        DispatcherStub service = new DispatcherStub();
109        service.setResult(GetUsers.class, users);
110        service.setResult(UpdateUserPermissions.class, new VoidResult());
111
112        // Collaborator: View
113        DbUserEditor.View view = createNiceMock(DbUserEditor.View.class);
114        replay(view);
115
116        // Class under test
117        DbUserEditor editor = new DbUserEditor(new MockEventBus(), service, new MockStateManager(), view);
118        editor.go(schema.getDatabaseById(1), new DbPageState(DbUserEditor.DatabaseUsers, 1));
119
120        // VERIFY that following a successful save the save button is disabled
121
122        Record record = editor.getStore().getRecord(users.getData().get(0));
123        record.set("allowViewAll", true);
124
125        reset(view);
126        view.setActionEnabled(UIActions.save, false);
127        replay(view);
128
129        editor.onUIAction(UIActions.save);
130
131        verify(view);
132    }
133}