/sigmah/src/test/java/org/sigmah/server/endpoint/gwtrpc/DeleteTest.java
Java | 95 lines | 66 code | 25 blank | 4 comment | 2 complexity | d2d7893b5b45a3ac1897c3d492f6e666 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 6package org.sigmah.server.endpoint.gwtrpc; 7 8import java.util.Collection; 9 10import junit.framework.Assert; 11 12import org.junit.Test; 13import org.junit.runner.RunWith; 14import org.sigmah.server.dao.OnDataSet; 15import org.sigmah.server.endpoint.gwtrpc.handler.CommandHandlerModule; 16import org.sigmah.shared.command.Delete; 17import org.sigmah.shared.command.GetSchema; 18import org.sigmah.shared.command.GetSites; 19import org.sigmah.shared.command.result.PagingResult; 20import org.sigmah.shared.dto.SchemaDTO; 21import org.sigmah.shared.dto.SiteDTO; 22import org.sigmah.shared.exception.CommandException; 23import org.sigmah.test.InjectionSupport; 24import org.sigmah.test.Modules; 25 26import com.extjs.gxt.ui.client.data.ModelData; 27 28@RunWith(InjectionSupport.class) 29@OnDataSet("/dbunit/sites-simple1.db.xml") 30@Modules({ 31 CommandHandlerModule.class 32}) 33public class DeleteTest extends CommandTestCase { 34 35 36 public <T extends ModelData> T getById(Collection<T> list, Integer id) { 37 for (T element : list) { 38 if (id.equals(element.get("id"))) { 39 return element; 40 } 41 } 42 return null; 43 } 44 45 @Test 46 public void testDeleteSite() throws CommandException { 47 48 PagingResult<SiteDTO> sites = execute(GetSites.byId(3)); 49 execute(new Delete(sites.getData().get(0))); 50 51 sites = execute(GetSites.byId(3)); 52 Assert.assertEquals(0, sites.getData().size()); 53 54 sites = execute(new GetSites()); 55 Assert.assertNull(getById(sites.getData(), 3)); 56 } 57 58 @Test 59 public void testDeleteIndicator() throws CommandException { 60 61 SchemaDTO schema = execute(new GetSchema()); 62 execute(new Delete(schema.getIndicatorById(1))); 63 64 schema = execute(new GetSchema()); 65 Assert.assertNull(schema.getIndicatorById(1)); 66 67 PagingResult<SiteDTO> sites = execute(GetSites.byId(1)); 68 Assert.assertNull(sites.getData().get(0).getIndicatorValue(1)); 69 } 70 71 @Test 72 public void testDeleteAttribute() throws CommandException { 73 74 SchemaDTO schema = execute(new GetSchema()); 75 execute(new Delete(schema.getActivityById(1).getAttributeById(1))); 76 77 schema = execute(new GetSchema()); 78 Assert.assertNull(schema.getActivityById(1).getAttributeById(1)); 79 } 80 81 82 @Test 83 public void testDeleteActivity() throws CommandException { 84 85 SchemaDTO schema = execute(new GetSchema()); 86 execute(new Delete(schema.getActivityById(1))); 87 execute(new Delete("Activity", 4)); 88 89 schema = execute(new GetSchema()); 90 Assert.assertNull("delete by entity reference", schema.getActivityById(1)); 91 Assert.assertNull("delete by id", schema.getActivityById(4)); 92 93 } 94 95}