Search in sources :

Example 1 with UpdateEntity

use of org.activityinfo.shared.command.UpdateEntity in project activityinfo by bedatadriven.

the class DesignTest method testSaveOnNavigateAway.

@Test
public void testSaveOnNavigateAway() {
    // Dummy Data
    SchemaDTO schema = DTOs.pear();
    // Collaborator
    MockEventBus eventBus = new MockEventBus();
    // Collaborator
    DispatcherStub service = new DispatcherStub();
    service.setResult(GetSchema.class, schema);
    service.setResult(UpdateEntity.class, new VoidResult());
    // Collaborator
    DesignPresenter.View view = createNiceMock(DesignPresenter.View.class);
    replay(view);
    // Collaborator
    UIConstants constants = createNiceMock(UIConstants.class);
    replay(constants);
    DesignPresenter designer = new DesignPresenter(eventBus, service, new StateManagerStub(), view, constants);
    designer.go(schema.getDatabaseById(1));
    // Verify that following a change to the record, a save call
    // triggers an update command
    ActivityDTO activity = (ActivityDTO) ((TreeStore) designer.getStore()).getRootItems().get(0);
    Record record = designer.getStore().getRecord(activity);
    record.set("name", "New Name");
    designer.requestToNavigateAway(new DataEntryPlace(), new NavigationCallback() {

        @Override
        public void onDecided(boolean allowed) {
        }
    });
    UpdateEntity cmd = service.getLastExecuted(UpdateEntity.class);
    Assert.assertTrue(cmd.getChanges().containsKey("name"));
    Assert.assertEquals("New Name", cmd.getChanges().get("name"));
}
Also used : VoidResult(org.activityinfo.shared.command.result.VoidResult) UpdateEntity(org.activityinfo.shared.command.UpdateEntity) DispatcherStub(org.activityinfo.client.dispatch.DispatcherStub) ActivityDTO(org.activityinfo.shared.dto.ActivityDTO) SchemaDTO(org.activityinfo.shared.dto.SchemaDTO) TreeStore(com.extjs.gxt.ui.client.store.TreeStore) DataEntryPlace(org.activityinfo.client.page.entry.place.DataEntryPlace) MockEventBus(org.activityinfo.client.MockEventBus) NavigationCallback(org.activityinfo.client.page.NavigationCallback) Record(com.extjs.gxt.ui.client.store.Record) UIConstants(org.activityinfo.client.i18n.UIConstants) StateManagerStub(org.activityinfo.client.mock.StateManagerStub) Test(org.junit.Test)

Example 2 with UpdateEntity

use of org.activityinfo.shared.command.UpdateEntity in project activityinfo by bedatadriven.

the class ActivityTest method updatePublished.

@Test
public void updatePublished() throws Throwable {
    /* Update Sort Order */
    Map<String, Object> changes = new HashMap<String, Object>();
    changes.put("published", Published.ALL_ARE_PUBLISHED.getIndex());
    execute(new UpdateEntity("Activity", 1, changes));
    /* Confirm the order is changed */
    SchemaDTO schema = execute(new GetSchema());
    Assert.assertEquals(Published.ALL_ARE_PUBLISHED.getIndex(), schema.getActivityById(1).getPublished());
}
Also used : UpdateEntity(org.activityinfo.shared.command.UpdateEntity) HashMap(java.util.HashMap) SchemaDTO(org.activityinfo.shared.dto.SchemaDTO) GetSchema(org.activityinfo.shared.command.GetSchema) Test(org.junit.Test)

Example 3 with UpdateEntity

use of org.activityinfo.shared.command.UpdateEntity in project activityinfo by bedatadriven.

the class ActivityTest method updateSortOrderTest.

@Test
public void updateSortOrderTest() throws Throwable {
    /* Update Sort Order */
    Map<String, Object> changes1 = new HashMap<String, Object>();
    changes1.put("sortOrder", 2);
    Map<String, Object> changes2 = new HashMap<String, Object>();
    changes2.put("sortOrder", 1);
    execute(new BatchCommand(new UpdateEntity("Activity", 1, changes1), new UpdateEntity("Activity", 2, changes2)));
    /* Confirm the order is changed */
    SchemaDTO schema = execute(new GetSchema());
    Assert.assertEquals(2, schema.getDatabaseById(1).getActivities().get(0).getId());
    Assert.assertEquals(1, schema.getDatabaseById(1).getActivities().get(1).getId());
}
Also used : UpdateEntity(org.activityinfo.shared.command.UpdateEntity) HashMap(java.util.HashMap) BatchCommand(org.activityinfo.shared.command.BatchCommand) SchemaDTO(org.activityinfo.shared.dto.SchemaDTO) GetSchema(org.activityinfo.shared.command.GetSchema) Test(org.junit.Test)

Example 4 with UpdateEntity

use of org.activityinfo.shared.command.UpdateEntity in project activityinfo by bedatadriven.

the class AttributeGroupTest method testUpdate.

@Test
public void testUpdate() throws Exception {
    // initial data load
    SchemaDTO schema = execute(new GetSchema());
    // change the name of an entity group
    ActivityDTO activity = schema.getActivityById(1);
    AttributeGroupDTO group = activity.getAttributeGroups().get(0);
    group.setName("Foobar");
    Map<String, Object> changes = new HashMap<String, Object>();
    changes.put("name", group.getName());
    execute(new UpdateEntity(group, changes));
    // reload data
    schema = execute(new GetSchema());
    // verify the property has been duly changed
    Assert.assertEquals(group.getName(), schema.getActivityById(1).getAttributeGroups().get(0).getName());
}
Also used : AttributeGroupDTO(org.activityinfo.shared.dto.AttributeGroupDTO) UpdateEntity(org.activityinfo.shared.command.UpdateEntity) HashMap(java.util.HashMap) ActivityDTO(org.activityinfo.shared.dto.ActivityDTO) SchemaDTO(org.activityinfo.shared.dto.SchemaDTO) GetSchema(org.activityinfo.shared.command.GetSchema) Test(org.junit.Test)

Example 5 with UpdateEntity

use of org.activityinfo.shared.command.UpdateEntity in project activityinfo by bedatadriven.

the class LocalSchemaChangeTest method updateIndicator.

@Test
public void updateIndicator() {
    synchronizeFirstTime();
    Map<String, Object> changes = Maps.newHashMap();
    changes.put("name", "New Name");
    UpdateEntity update = new UpdateEntity("Indicator", 5, changes);
    executeRemotely(update);
    synchronize();
    SchemaDTO schema = executeLocally(new GetSchema());
    assertThat(schema.getIndicatorById(5).getName(), equalTo("New Name"));
}
Also used : UpdateEntity(org.activityinfo.shared.command.UpdateEntity) SchemaDTO(org.activityinfo.shared.dto.SchemaDTO) GetSchema(org.activityinfo.shared.command.GetSchema) Test(org.junit.Test)

Aggregations

UpdateEntity (org.activityinfo.shared.command.UpdateEntity)11 Test (org.junit.Test)9 SchemaDTO (org.activityinfo.shared.dto.SchemaDTO)6 HashMap (java.util.HashMap)5 GetSchema (org.activityinfo.shared.command.GetSchema)4 VoidResult (org.activityinfo.shared.command.result.VoidResult)4 Record (com.extjs.gxt.ui.client.store.Record)3 ActivityDTO (org.activityinfo.shared.dto.ActivityDTO)3 TreeStore (com.extjs.gxt.ui.client.store.TreeStore)2 MockEventBus (org.activityinfo.client.MockEventBus)2 DispatcherStub (org.activityinfo.client.dispatch.DispatcherStub)2 UIConstants (org.activityinfo.client.i18n.UIConstants)2 StateManagerStub (org.activityinfo.client.mock.StateManagerStub)2 BatchCommand (org.activityinfo.shared.command.BatchCommand)2 LocalDate (com.bedatadriven.rebar.time.calendar.LocalDate)1 AsyncCallback (com.google.gwt.user.client.rpc.AsyncCallback)1 NavigationCallback (org.activityinfo.client.page.NavigationCallback)1 FormDialogCallback (org.activityinfo.client.page.common.dialog.FormDialogCallback)1 FormDialogTether (org.activityinfo.client.page.common.dialog.FormDialogTether)1 DataEntryPlace (org.activityinfo.client.page.entry.place.DataEntryPlace)1