/sigmah/src/test/java/org/sigmah/server/endpoint/gwtrpc/GetSchemaTest.java
Java | 116 lines | 72 code | 37 blank | 7 comment | 7 complexity | aa7565619ea10d20d71835b8311282c6 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 8 9import org.junit.Assert; 10import org.junit.Test; 11import org.junit.runner.RunWith; 12import org.sigmah.server.dao.OnDataSet; 13import org.sigmah.shared.command.GetSchema; 14import org.sigmah.shared.dto.ActivityDTO; 15import org.sigmah.shared.dto.AttributeDTO; 16import org.sigmah.shared.dto.IndicatorDTO; 17import org.sigmah.shared.dto.SchemaDTO; 18import org.sigmah.shared.exception.CommandException; 19import org.sigmah.test.InjectionSupport; 20 21 22@RunWith(InjectionSupport.class) 23@OnDataSet("/dbunit/schema1.db.xml") 24public class GetSchemaTest extends CommandTestCase { 25 26 @Test 27 public void testDatabaseVisibilityForOwners() throws CommandException { 28 29 // owners should be able to see their databases 30 31 setUser(1); // Alex 32 33 SchemaDTO schema = execute(new GetSchema()); 34 35 Assert.assertTrue("ALEX(owner) in PEAR", schema.getDatabaseById(1) != null); // PEAR 36 Assert.assertTrue("ALEX can design", schema.getDatabaseById(1).isDesignAllowed()); 37 Assert.assertTrue("Alex can edit all", schema.getDatabaseById(1).isEditAllowed()); 38 Assert.assertTrue("object graph is preserved", schema.getDatabaseById(1).getCountry() == schema.getDatabaseById(2).getCountry()); 39 Assert.assertTrue("object graph is preserved (database-activity)", 40 schema.getDatabaseById(1) == 41 schema.getDatabaseById(1).getActivities().get(0).getDatabase()); 42 } 43 44 @Test 45 public void testDatabaseVisibilityForView() throws CommandException { 46 47 48 setUser(2); // Bavon 49 50 SchemaDTO schema = execute(new GetSchema()); 51 52 Assert.assertTrue("BAVON in PEAR", schema.getDatabaseById(1) != null); 53 54 Assert.assertTrue("bavon can edit", schema.getDatabaseById(1).isEditAllowed()); 55 Assert.assertFalse("bavon cannot edit all", schema.getDatabaseById(1).isEditAllAllowed()); 56 57 } 58 59 @Test 60 public void testDatabaseVisibilityNone() throws CommandException { 61 setUser(3); // Stefan 62 63 SchemaDTO schema = execute(new GetSchema()); 64 65 Assert.assertTrue("STEFAN not in PEAR", schema.getDatabaseById(1) == null); 66 } 67 68 @Test 69 public void testIndicators() throws CommandException { 70 71 setUser(1); // Alex 72 73 SchemaDTO schema = execute(new GetSchema()); 74 75 Assert.assertTrue("no indicators case", 76 schema.getActivityById(2).getIndicators().size() == 0); 77 78 ActivityDTO nfi = schema.getActivityById(1); 79 IndicatorDTO[] indicators = nfi.getIndicators().toArray(new IndicatorDTO[0]); 80 81 Assert.assertEquals("indicators are present", 2, indicators.length); 82 //Assert.assertTrue("indicators are sorted", 83 // indicators[0].getSortOrder() <= indicators[1].getSortOrder()); 84 85 IndicatorDTO test = nfi.getIndicatorById(2); 86 Assert.assertEquals("property:name", test.getName(), "kits"); 87 Assert.assertEquals("property:units", test.getUnits(), "menages"); 88 Assert.assertEquals("property:aggregation", test.getAggregation(), 0); 89 Assert.assertEquals("property:collectIntervention", test.isCollectIntervention(), true); 90 Assert.assertEquals("property:collectMonitoring", test.isCollectMonitoring(), true); 91 Assert.assertEquals("property:category", test.getCategory(), "outputs"); 92 Assert.assertEquals("property:code", test.getCode(), "header"); 93 Assert.assertEquals("property:description", test.getDescription(), "desc"); 94 } 95 96 @Test 97 public void testAttributes() throws CommandException { 98 99 setUser(1); // Alex 100 101 SchemaDTO schema = execute(new GetSchema()); 102 103 Assert.assertTrue("no attributes case", schema.getActivityById(2).getAttributeGroups().size() == 0); 104 105 ActivityDTO nfi = schema.getActivityById(1); 106 AttributeDTO[] attributes = nfi.getAttributeGroups().get(0).getAttributes().toArray(new AttributeDTO[0]); 107 108 Assert.assertTrue("attributes are present", attributes.length == 2); 109 110 AttributeDTO test = nfi.getAttributeById(1); 111 112 Assert.assertEquals("property:name", "Retour", test.getName()); 113 } 114 115 116}