Search in sources :

Example 16 with SchemaDTO

use of org.activityinfo.shared.dto.SchemaDTO in project activityinfo by bedatadriven.

the class DesignTest method testDelete.

@Test
public void testDelete() {
    // Dummy Data
    SchemaDTO schema = DTOs.pear();
    // Collaborator
    DispatcherStub service = new DispatcherStub();
    service.setResult(GetSchema.class, schema);
    service.setResult(Delete.class, new VoidResult());
    // Collaborator
    DesignPresenter.View view = createNiceMock(DesignPresenter.View.class);
    expect(view.getSelection()).andReturn(schema.getActivityById(91));
    view.confirmDeleteSelected(isA(ConfirmCallback.class));
    expectLastCall().andAnswer(new IAnswer<Object>() {

        @Override
        public Object answer() throws Throwable {
            ((ConfirmCallback) getCurrentArguments()[0]).confirmed();
            return null;
        }
    });
    replay(view);
    // Collaborator
    UIConstants constants = createNiceMock(UIConstants.class);
    replay(constants);
    DesignPresenter designer = new DesignPresenter(new MockEventBus(), service, new StateManagerStub(), view, constants);
    designer.go(schema.getDatabaseById(1));
    // Verify that the proper delete command executes
    designer.onUIAction(UIActions.DELETE);
    Delete cmd = service.getLastExecuted(Delete.class);
    Assert.assertEquals("Activity", cmd.getEntityName());
    Assert.assertEquals(91, cmd.getId());
}
Also used : Delete(org.activityinfo.shared.command.Delete) ConfirmCallback(org.activityinfo.client.page.common.grid.ConfirmCallback) VoidResult(org.activityinfo.shared.command.result.VoidResult) DispatcherStub(org.activityinfo.client.dispatch.DispatcherStub) SchemaDTO(org.activityinfo.shared.dto.SchemaDTO) MockEventBus(org.activityinfo.client.MockEventBus) UIConstants(org.activityinfo.client.i18n.UIConstants) StateManagerStub(org.activityinfo.client.mock.StateManagerStub) Test(org.junit.Test)

Example 17 with SchemaDTO

use of org.activityinfo.shared.dto.SchemaDTO in project activityinfo by bedatadriven.

the class DesignTest method testNewActivityComesWithFolders.

@Test
public void testNewActivityComesWithFolders() {
    // Test data
    SchemaDTO schema = DTOs.pear();
    // Collaborator : EventBus
    MockEventBus eventBus = new MockEventBus();
    // Collaborator : Command Service
    DispatcherStub service = new DispatcherStub();
    service.setResult(GetSchema.class, schema);
    service.setResult(CreateEntity.class, new CreateResult(991));
    // Collaborator : View
    MockDesignTree view = new MockDesignTree();
    // Constants
    UIConstants constants = createNiceMock(UIConstants.class);
    replay(constants);
    // Class under test
    DesignPresenter designer = new DesignPresenter(eventBus, service, new StateManagerStub(), view, constants);
    // VERIFY that when an activity is added, it appears at the end of the
    // list with two
    // sub folders
    designer.go(schema.getDatabaseById(1));
    view.newEntityProperties.put("name", "Psychosocial support");
    designer.onNew("Activity");
    List<ModelData> rootItems = designer.getTreeStore().getRootItems();
    ActivityDTO addedActivity = (ActivityDTO) rootItems.get(rootItems.size() - 1);
    Assert.assertEquals("Psychosocial support", addedActivity.getName());
    Assert.assertEquals("child nodes", 2, designer.getTreeStore().getChildCount(addedActivity));
}
Also used : ModelData(com.extjs.gxt.ui.client.data.ModelData) CreateResult(org.activityinfo.shared.command.result.CreateResult) MockEventBus(org.activityinfo.client.MockEventBus) DispatcherStub(org.activityinfo.client.dispatch.DispatcherStub) UIConstants(org.activityinfo.client.i18n.UIConstants) StateManagerStub(org.activityinfo.client.mock.StateManagerStub) ActivityDTO(org.activityinfo.shared.dto.ActivityDTO) SchemaDTO(org.activityinfo.shared.dto.SchemaDTO) Test(org.junit.Test)

Example 18 with SchemaDTO

use of org.activityinfo.shared.dto.SchemaDTO in project activityinfo by bedatadriven.

the class DimensionPrunerTest method setupData.

@Before
public void setupData() {
    ActivityDTO dist = new ActivityDTO(1, "Distribution");
    IndicatorDTO nbMenages = new IndicatorDTO();
    nbMenages.setId(NB_MENAGES_INDICATOR_ID);
    nbMenages.setName("Nb Menages");
    dist.getIndicators().add(nbMenages);
    AttributeGroupDTO distFunding = new AttributeGroupDTO(NFI_FUNDING_GROUP_ID);
    distFunding.setName("Funding Source");
    dist.getAttributeGroups().add(distFunding);
    ActivityDTO fairs = new ActivityDTO(2, "Faire");
    AttributeGroupDTO fairFunding = new AttributeGroupDTO(FAIR_FUNDING_GROUP_ID);
    fairFunding.setName("Funding Source");
    fairs.getAttributeGroups().add(fairFunding);
    IndicatorDTO voucherValue = new IndicatorDTO();
    voucherValue.setId(VOUCHER_INDICATOR_ID);
    voucherValue.setName("Voucher Value");
    fairs.getIndicators().add(voucherValue);
    UserDatabaseDTO nfi = new UserDatabaseDTO(1, "NFI");
    nfi.getActivities().add(dist);
    nfi.getActivities().add(fairs);
    this.schema = new SchemaDTO();
    schema.getDatabases().add(nfi);
    dispatcher.setResult(GetSchema.class, schema);
}
Also used : IndicatorDTO(org.activityinfo.shared.dto.IndicatorDTO) AttributeGroupDTO(org.activityinfo.shared.dto.AttributeGroupDTO) UserDatabaseDTO(org.activityinfo.shared.dto.UserDatabaseDTO) ActivityDTO(org.activityinfo.shared.dto.ActivityDTO) SchemaDTO(org.activityinfo.shared.dto.SchemaDTO) Before(org.junit.Before)

Example 19 with SchemaDTO

use of org.activityinfo.shared.dto.SchemaDTO 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 20 with SchemaDTO

use of org.activityinfo.shared.dto.SchemaDTO 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)

Aggregations

SchemaDTO (org.activityinfo.shared.dto.SchemaDTO)66 GetSchema (org.activityinfo.shared.command.GetSchema)56 Test (org.junit.Test)41 ActivityDTO (org.activityinfo.shared.dto.ActivityDTO)20 UserDatabaseDTO (org.activityinfo.shared.dto.UserDatabaseDTO)10 CreateResult (org.activityinfo.shared.command.result.CreateResult)9 AsyncCallback (com.google.gwt.user.client.rpc.AsyncCallback)8 MockEventBus (org.activityinfo.client.MockEventBus)6 HashMap (java.util.HashMap)5 DispatcherStub (org.activityinfo.client.dispatch.DispatcherStub)5 UIConstants (org.activityinfo.client.i18n.UIConstants)5 StateManagerStub (org.activityinfo.client.mock.StateManagerStub)5 OnDataSet (org.activityinfo.server.database.OnDataSet)5 Delete (org.activityinfo.shared.command.Delete)5 Filter (org.activityinfo.shared.command.Filter)5 UpdateEntity (org.activityinfo.shared.command.UpdateEntity)5 AttributeGroupDTO (org.activityinfo.shared.dto.AttributeGroupDTO)5 MaskingAsyncMonitor (org.activityinfo.client.dispatch.monitor.MaskingAsyncMonitor)4 CreateEntity (org.activityinfo.shared.command.CreateEntity)4 VoidResult (org.activityinfo.shared.command.result.VoidResult)4