use of org.activityinfo.shared.command.result.CreateResult in project activityinfo by bedatadriven.
the class CreateDatabaseTest method testCreate.
@Test
@OnDataSet("/dbunit/sites-simple1.db.xml")
public void testCreate() throws CommandException {
UserDatabaseDTO db = new UserDatabaseDTO();
db.setName("RIMS");
db.setFullName("Reintegration Management Information System");
CreateResult cr = execute(new CreateEntity(db));
SchemaDTO schema = execute(new GetSchema());
UserDatabaseDTO newdb = schema.getDatabaseById(cr.getNewId());
assertNotNull(newdb);
assertEquals(db.getName(), newdb.getName());
assertEquals(db.getFullName(), newdb.getFullName());
assertNotNull(newdb.getCountry());
assertEquals("Alex", newdb.getOwnerName());
}
use of org.activityinfo.shared.command.result.CreateResult in project activityinfo by bedatadriven.
the class CreateSiteTest method test.
@Test
public void test() throws CommandException {
LocationDTO location = LocationDTOs.newLocation();
execute(new CreateLocation(location));
SiteDTO newSite = SiteDTOs.newSite();
newSite.setLocation(location);
CreateSite cmd = new CreateSite(newSite);
setUser(1);
CreateResult result = execute(cmd);
newSite.setId(result.getNewId());
assertThat(result.getNewId(), not(equalTo(0)));
PagingLoadResult<SiteDTO> loadResult = execute(GetSites.byId(newSite.getId()));
Assert.assertEquals(1, loadResult.getData().size());
SiteDTO secondRead = loadResult.getData().get(0);
SiteDTOs.validateNewSite(secondRead);
}
use of org.activityinfo.shared.command.result.CreateResult in project activityinfo by bedatadriven.
the class CreateSiteTest method testAllAttribsFalse.
@Test
public void testAllAttribsFalse() throws CommandException {
// create a new detached, client model
SiteDTO newSite = new SiteDTO();
newSite.setId(new KeyGenerator().generateInt());
newSite.setActivityId(1);
newSite.setLocationId(1);
newSite.setPartner(new PartnerDTO(1, "Foobar"));
newSite.setDate1((new GregorianCalendar(2008, 12, 1)).getTime());
newSite.setDate2((new GregorianCalendar(2009, 1, 3)).getTime());
newSite.setLocationName("Virunga");
newSite.setAttributeValue(1, false);
newSite.setAttributeValue(2, false);
newSite.setProject(new ProjectDTO(1, "SomeProject"));
// create command
CreateSite cmd = new CreateSite(newSite);
assertThat((Integer) cmd.getProperties().get("locationId"), equalTo(1));
// execute the command
setUser(1);
CreateResult result = execute(cmd);
// let the client know the command has succeeded
newSite.setId(result.getNewId());
// cmd.onCompleted(result);
// try to retrieve what we've created
PagingLoadResult<SiteDTO> loadResult = execute(GetSites.byId(newSite.getId()));
Assert.assertEquals(1, loadResult.getData().size());
SiteDTO secondRead = loadResult.getData().get(0);
// confirm that the changes are there
Assert.assertEquals("site.attribute[2]", false, secondRead.getAttributeValue(1));
Assert.assertEquals("site.attribute[2]", false, secondRead.getAttributeValue(2));
}
use of org.activityinfo.shared.command.result.CreateResult in project activityinfo by bedatadriven.
the class LocalSchemaChangeTest method createActivity.
@Test
public void createActivity() {
synchronizeFirstTime();
SchemaDTO schema = executeLocally(new GetSchema());
ActivityDTO activity = new ActivityDTO();
activity.setName("New Activity");
activity.setReportingFrequency(0);
activity.setLocationTypeId(1);
CreateResult createResult = executeRemotely(CreateEntity.Activity(schema.getDatabaseById(1), activity));
synchronize();
schema = executeLocally(new GetSchema());
ActivityDTO createdActivity = schema.getActivityById(createResult.getNewId());
assertThat(createdActivity, is(not(nullValue())));
assertThat(createdActivity.getName(), equalTo(activity.getName()));
}
use of org.activityinfo.shared.command.result.CreateResult in project activityinfo by bedatadriven.
the class LocalSchemaChangeTest method createIndicator.
@Test
public void createIndicator() {
synchronizeFirstTime();
SchemaDTO schema = executeLocally(new GetSchema());
Map<String, Object> indicator = Maps.newHashMap();
indicator.put("name", "New Indicator");
indicator.put("units", "bricks");
indicator.put("activityId", 2);
CreateResult createResult = executeRemotely(new CreateEntity("Indicator", indicator));
synchronize();
schema = executeLocally(new GetSchema());
IndicatorDTO createdIndicator = schema.getIndicatorById(createResult.getNewId());
assertThat(createdIndicator, is(not(nullValue())));
assertThat(createdIndicator.getName(), equalTo("New Indicator"));
}
Aggregations