/sigmah/src/test/java/org/sigmah/server/endpoint/gwtrpc/CreateDatabaseTest.java

http://sigma-h.googlecode.com/ · Java · 68 lines · 46 code · 18 blank · 4 comment · 0 complexity · 7bbe66878d3083276c7e49328d691aa6 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. package org.sigmah.server.endpoint.gwtrpc;
  6. import org.junit.Assert;
  7. import org.junit.Test;
  8. import org.junit.runner.RunWith;
  9. import org.sigmah.server.dao.OnDataSet;
  10. import org.sigmah.shared.command.CreateEntity;
  11. import org.sigmah.shared.command.GetSchema;
  12. import org.sigmah.shared.command.result.CreateResult;
  13. import org.sigmah.shared.dto.SchemaDTO;
  14. import org.sigmah.shared.dto.UserDatabaseDTO;
  15. import org.sigmah.shared.exception.CommandException;
  16. import org.sigmah.test.InjectionSupport;
  17. import static org.hamcrest.CoreMatchers.*;
  18. import static org.junit.Assert.assertThat;
  19. @RunWith(InjectionSupport.class)
  20. public class CreateDatabaseTest extends CommandTestCase {
  21. @Test
  22. @OnDataSet("/dbunit/sites-simple1.db.xml")
  23. public void testCreate() throws CommandException {
  24. UserDatabaseDTO db = new UserDatabaseDTO();
  25. db.setName("RIMS");
  26. db.setFullName("Reintegration Management Information System");
  27. CreateResult cr = execute(new CreateEntity(db));
  28. SchemaDTO schema = execute(new GetSchema());
  29. UserDatabaseDTO newdb = schema.getDatabaseById(cr.getNewId());
  30. Assert.assertEquals(db.getName(), newdb.getName());
  31. Assert.assertEquals(db.getFullName(), newdb.getFullName());
  32. Assert.assertNotNull(newdb.getCountry());
  33. Assert.assertEquals("Alex", newdb.getOwnerName());
  34. }
  35. @Test
  36. @OnDataSet("/dbunit/multicountry.db.xml")
  37. public void createWithSpecificCountry() throws CommandException {
  38. UserDatabaseDTO db = new UserDatabaseDTO();
  39. db.setName("Warchild Haiti");
  40. db.setFullName("Warchild Haiti");
  41. setUser(1);
  42. CreateEntity cmd = new CreateEntity(db);
  43. cmd.getProperties().put("countryId", 2);
  44. CreateResult cr = execute(cmd);
  45. SchemaDTO schema = execute(new GetSchema());
  46. UserDatabaseDTO newdb = schema.getDatabaseById(cr.getNewId());
  47. assertThat(newdb.getCountry(), is(notNullValue()));
  48. assertThat(newdb.getCountry().getName(), is(equalTo("Haiti")));
  49. }
  50. }