/sigmah/src/test/java/org/sigmah/server/endpoint/gwtrpc/GetIndicatorsHandlerTest.java
Java | 113 lines | 75 code | 38 blank | 0 comment | 0 complexity | 66b06318749fb95027755025fd2995ac MD5 | raw file
1package org.sigmah.server.endpoint.gwtrpc; 2 3import static org.hamcrest.CoreMatchers.equalTo; 4import static org.junit.Assert.assertThat; 5 6import org.junit.Test; 7import org.junit.runner.RunWith; 8import org.sigmah.server.dao.OnDataSet; 9import org.sigmah.shared.command.GetIndicators; 10import org.sigmah.shared.command.result.IndicatorListResult; 11import org.sigmah.shared.dto.IndicatorDTO; 12import org.sigmah.shared.dto.IndicatorGroup; 13import org.sigmah.shared.exception.CommandException; 14import org.sigmah.test.InjectionSupport; 15 16@RunWith(InjectionSupport.class) 17@OnDataSet("/dbunit/sites-simple1.db.xml") 18public class GetIndicatorsHandlerTest extends CommandTestCase { 19 20 private static final int DATABASE_OWNER = 1; 21 22 23 @Test 24 public void testList() throws CommandException { 25 26 27 setUser(DATABASE_OWNER); 28 29 GetIndicators cmd = new GetIndicators(); 30 cmd.setUserDatabaseId(1); 31 32 IndicatorListResult result = execute(cmd); 33 34 assertThat(result.getData().size(), equalTo(3)); 35 36 IndicatorDTO i0 = result.getData().get(0); 37 IndicatorDTO i1 = result.getData().get(1); 38 IndicatorDTO i2 = result.getData().get(2); 39 40 assertThat(i0.getName(), equalTo("baches")); 41 assertThat(i0.isDirectDataEntryEnabled(), equalTo(true)); 42 43 assertThat(i1.getName(), equalTo("beneficiaries")); 44 assertThat(i1.getId(), equalTo(1)); 45 assertThat(i1.getCurrentValue(), equalTo(15100d)); 46 assertThat(i1.getObjective(), equalTo(10000d)); 47 assertThat(i1.getGroupId(), equalTo(1)); 48 49 assertThat(i2.getName(), equalTo("Nb. of distributions")); 50 51 assertThat(result.getGroups().size(), equalTo(2)); 52 53 IndicatorGroup g1 = result.getGroups().get(0); 54 assertThat(g1.getId(), equalTo(1)); 55 assertThat(g1.getName(), equalTo("NFI")); 56 assertThat(g1.getIndicators().size(), equalTo(3)); 57 } 58 59 60 @Test 61 @OnDataSet("/dbunit/project-indicator.db.xml") 62 public void testListWithCategorical() throws CommandException { 63 64 65 setUser(DATABASE_OWNER); 66 67 GetIndicators cmd = new GetIndicators(); 68 cmd.setUserDatabaseId(2); 69 70 IndicatorListResult result = execute(cmd); 71 72 assertThat(result.getData().size(), equalTo(2)); 73 74 IndicatorDTO construction = result.getData().get(0); 75 IndicatorDTO service = result.getData().get(1); 76 77 assertThat(construction.getLabels().size(), equalTo(3)); 78 assertThat(construction.getLabels().get(0), equalTo("Good")); 79 assertThat(construction.getLabels().get(1), equalTo("Bad")); 80 assertThat(construction.getLabels().get(2), equalTo("Ugly")); 81 82 assertThat(construction.getLabelCounts().size(), equalTo(3)); 83 assertThat(construction.getLabelCounts().get(0), equalTo(1)); 84 assertThat(construction.getLabelCounts().get(1), equalTo(2)); 85 assertThat(construction.getLabelCounts().get(2), equalTo(1)); 86 87 assertThat(construction.formatMode(), equalTo("Bad (50%)")); 88 89 assertThat(service.getLabels().size(), equalTo(3)); 90 assertThat(service.getLabels().get(0), equalTo("Mediocre")); 91 assertThat(service.getLabels().get(1), equalTo("Pretty bad")); 92 assertThat(service.getLabels().get(2), equalTo("Terrible")); 93 } 94 95 @Test 96 @OnDataSet("/dbunit/project-indicator-linked.db.xml") 97 public void valuesFromDataSourcesAreIncludedInAggregates_Issue359() throws Exception { 98 99 IndicatorListResult result = execute(GetIndicators.forDatabase(1)); 100 101 IndicatorDTO indicator2 = result.getIndicatorById(2); 102 assertThat(indicator2.getCurrentValue(), equalTo(2644d)); 103 104 IndicatorDTO indicator91 = result.getIndicatorById(91); 105 assertThat(indicator91.getLabelCounts().get(0), equalTo(1)); 106 assertThat(indicator91.getLabelCounts().get(1), equalTo(1)); 107 108 } 109 110 111 112 113}