Search in sources :

Example 6 with CreateSite

use of org.activityinfo.legacy.shared.command.CreateSite in project activityinfo by bedatadriven.

the class CreateSiteTest method testAdminBoundCreate.

@Test
@Ignore("WIP")
public void testAdminBoundCreate() throws CommandException {
    // create a new detached, client model
    SiteDTO newSite = new SiteDTO();
    newSite.setActivityId(4);
    newSite.setPartner(new PartnerDTO(1, "Foobar"));
    newSite.setDate1((new GregorianCalendar(2008, 12, 1)).getTime());
    newSite.setDate2((new GregorianCalendar(2009, 1, 3)).getTime());
    newSite.setAdminEntity(1, new AdminEntityDTO(1, 2, "Sud Kivu"));
    newSite.setAdminEntity(2, new AdminEntityDTO(2, 11, "Walungu"));
    newSite.setAdminEntity(3, null);
    newSite.setX(27.432);
    newSite.setY(1.23);
    newSite.setComments("huba huba");
    newSite.setProject(new ProjectDTO(1, "SomeProject"));
    // create command
    CreateSite cmd = new CreateSite(newSite);
    // execute the command
    setUser(1);
    newSite.setProject(new ProjectDTO(1, "SomeProject"));
    CreateResult result = execute(cmd);
    newSite.setId(result.getNewId());
    // try to retrieve what we've created
    SiteDTO secondRead = readSite(newSite.getId());
    // confirm that the changes are there
    Assert.assertEquals("site.location.name", "Walungu", secondRead.getLocationName());
}
Also used : CreateResult(org.activityinfo.legacy.shared.command.result.CreateResult) GregorianCalendar(java.util.GregorianCalendar) CreateSite(org.activityinfo.legacy.shared.command.CreateSite) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 7 with CreateSite

use of org.activityinfo.legacy.shared.command.CreateSite in project activityinfo by bedatadriven.

the class CreateSiteTest method unauthorized.

@Test(expected = IllegalAccessCommandException.class)
public void unauthorized() throws CommandException {
    // create a new detached, client model
    SiteDTO newSite = SiteDTOs.newSite();
    newSite.setPartner(new PartnerDTO(2, "Not NRC"));
    // create command
    CreateSite cmd = new CreateSite(newSite);
    // execute the command
    // bavon (only has access to his own partners in database 1)
    setUser(2);
    execute(cmd);
}
Also used : CreateSite(org.activityinfo.legacy.shared.command.CreateSite) Test(org.junit.Test)

Aggregations

CreateSite (org.activityinfo.legacy.shared.command.CreateSite)7 Test (org.junit.Test)6 CreateResult (org.activityinfo.legacy.shared.command.result.CreateResult)5 GregorianCalendar (java.util.GregorianCalendar)3 KeyGenerator (org.activityinfo.model.legacy.KeyGenerator)3 SqlTransaction (com.bedatadriven.rebar.sql.client.SqlTransaction)1 SqlTransactionCallback (com.bedatadriven.rebar.sql.client.SqlTransactionCallback)1 LocalDate (com.bedatadriven.rebar.time.calendar.LocalDate)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 CreateLocation (org.activityinfo.legacy.shared.command.CreateLocation)1 UpdateSite (org.activityinfo.legacy.shared.command.UpdateSite)1 SiteDTO (org.activityinfo.legacy.shared.model.SiteDTO)1 OnDataSet (org.activityinfo.server.database.OnDataSet)1 Ignore (org.junit.Ignore)1