/sigmah/src/test/java/org/sigmah/server/endpoint/gwtrpc/GetIndicatorDataSourcesTest.java
Java | 82 lines | 55 code | 23 blank | 4 comment | 0 complexity | 0c4098a510d8a3e19f1a5bb8d89180c8 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 org.junit.Test; 9import org.junit.runner.RunWith; 10import org.sigmah.server.dao.OnDataSet; 11import org.sigmah.shared.command.CreateEntity; 12import org.sigmah.shared.command.GetIndicatorDataSources; 13import org.sigmah.shared.command.UpdateEntity; 14import org.sigmah.shared.command.result.CreateResult; 15import org.sigmah.shared.command.result.IndicatorDataSourceList; 16import org.sigmah.shared.exception.CommandException; 17import org.sigmah.test.InjectionSupport; 18 19import java.util.HashMap; 20import java.util.HashSet; 21import java.util.Map; 22import java.util.Set; 23 24import static org.hamcrest.CoreMatchers.equalTo; 25import static org.junit.Assert.assertThat; 26 27@RunWith(InjectionSupport.class) 28@OnDataSet("/dbunit/sites-simple1.db.xml") 29public class GetIndicatorDataSourcesTest extends CommandTestCase { 30 31 32 @Test 33 public void indicatorWithNoDataSources() throws CommandException { 34 35 setUser(1); 36 37 IndicatorDataSourceList dsList = execute(new GetIndicatorDataSources(1)); 38 assertThat(dsList.getData().size(), equalTo(0)); 39 } 40 41 @Test 42 public void indicatorWithAddedDataSources() throws CommandException { 43 setUser(1); 44 45 Set<Integer> dataSources = new HashSet<Integer>(); 46 dataSources.add(2); 47 48 Map<String,Object> changes = new HashMap<String,Object>(); 49 changes.put("dataSourceIds", dataSources); 50 51 52 execute(new UpdateEntity("Indicator", 1, changes)); 53 54 IndicatorDataSourceList dsList = execute(new GetIndicatorDataSources(1)); 55 assertThat(dsList.getData().size(), equalTo(1)); 56 assertThat(dsList.getData().get(0).getIndicatorName(), equalTo("baches")); 57 assertThat(dsList.getData().get(0).getIndicatorId(), equalTo(2)); 58 assertThat(dsList.getData().get(0).getDatabaseId(), equalTo(1)); 59 assertThat(dsList.getData().get(0).getDatabaseName(), equalTo("PEAR")); 60 } 61 62 @Test 63 public void createIndicatorWithSources() throws CommandException { 64 65 Set<Integer> dataSources = new HashSet<Integer>(); 66 dataSources.add(1); 67 dataSources.add(2); 68 69 Map<String,Object> properties = new HashMap<String,Object>(); 70 properties.put("databaseId", 1); 71 properties.put("name", "total beneficiaries"); 72 properties.put("dataSourceIds", dataSources); 73 74 CreateResult created = execute(new CreateEntity("Indicator", properties)); 75 76 IndicatorDataSourceList dsList = execute(new GetIndicatorDataSources(created.getNewId())); 77 78 assertThat(dsList.getData().size(), equalTo(2)); 79 80 81 } 82}