PageRenderTime 24ms CodeModel.GetById 13ms app.highlight 9ms RepoModel.GetById 1ms app.codeStats 0ms

/sigmah/src/test/java/org/sigmah/client/page/table/ColumnMappingTest.java

http://sigma-h.googlecode.com/
Java | 107 lines | 80 code | 26 blank | 1 comment | 10 complexity | 472fb011b0d2a17cc15e3626d904b1c8 MD5 | raw file
  1package org.sigmah.client.page.table;
  2
  3import java.util.Arrays;
  4import java.util.Collections;
  5
  6import org.junit.Test;
  7import org.sigmah.shared.domain.AdminEntity;
  8import org.sigmah.shared.report.content.DimensionCategory;
  9import org.sigmah.shared.report.content.EntityCategory;
 10import org.sigmah.shared.report.content.PivotTableData;
 11import org.sigmah.shared.report.content.PivotTableData.Axis;
 12import org.sigmah.shared.report.model.AdminDimension;
 13import org.sigmah.shared.report.model.Dimension;
 14import org.sigmah.shared.report.model.DimensionType;
 15import org.sigmah.shared.report.model.PivotTableElement;
 16
 17import com.extjs.gxt.ui.client.widget.grid.ColumnModel;
 18import com.extjs.gxt.ui.client.widget.grid.HeaderGroupConfig;
 19import com.google.gwt.junit.GWTMockUtilities;
 20
 21public class ColumnMappingTest {
 22
 23	@Test
 24	public void unbalancedColumnTree() {
 25		
 26		
 27		AdminDimension province = new AdminDimension(1);
 28		AdminDimension territory = new AdminDimension(2);
 29		AdminDimension groupement = new AdminDimension(3);
 30		Dimension site = new Dimension(DimensionType.Site);
 31		Dimension indicator = new Dimension(DimensionType.Indicator);
 32				
 33		
 34		PivotTableData data = new PivotTableData(Arrays.asList(indicator), Arrays.asList(province, territory, groupement, site));
 35		
 36		PivotTableData.Axis kinshasa = data.getRootColumn().addChild(province, entity(1, "Kinshasa"));
 37		PivotTableData.Axis citeDeJoix = kinshasa.addChild(site, entity(1, "Cite de Joix"));
 38		
 39		PivotTableData.Axis nordKivu = data.getRootColumn().addChild(province, entity(2, "Nord Kivu"));
 40		PivotTableData.Axis goma = nordKivu.addChild(site, entity(2, "Goma"));
 41		PivotTableData.Axis lubero = nordKivu.addChild(territory, entity(3, "Lubero"));
 42		PivotTableData.Axis baswali = lubero.addChild(groupement, entity(4, "Baswali"));
 43		PivotTableData.Axis beni = baswali.addChild(site, entity(3, "Beni"));
 44		
 45		PivotTableElement element = new PivotTableElement();
 46		
 47		ColumnMapping mapping = new ColumnMapping(data, new ProviderStub(), new HeaderDecoratorStub());
 48		
 49										 /* row, 	col, 	rowSpan, 	colSpan */
 50		assertGroupPos(mapping, kinshasa, 	0, 		1, 		3, 			1);
 51		assertGroupPos(mapping, nordKivu, 	0, 		2, 		1, 			2);
 52		assertGroupPos(mapping, lubero, 	1,		3, 		1, 			1);
 53		assertGroupPos(mapping, baswali, 	2, 		3, 		1, 			1);
 54
 55		
 56	}
 57
 58	private void assertGroupPos(ColumnMapping mapping, Axis axis, int row,
 59			int col, int rowSpan, int colSpan) {
 60
 61		for(HeaderGroupConfig group : mapping.getColumnModel().getHeaderGroups()) {
 62			if(group.getHtml().equals(axis.getLabel())) {
 63				if(group.getRow() != row || group.getColumn() != col || group.getRowspan() != rowSpan || group.getColspan() != colSpan) {
 64					throw new AssertionError(String.format("Expected header group '%s' at (%d, %d) with rowspan %d, colspan %d, but found at (%d, %d), rowspan %d, colspan %d",
 65							axis.getLabel(),
 66							row,
 67							col,
 68							rowSpan,
 69							colSpan,
 70							group.getRow(),
 71							group.getColumn(),
 72							group.getColspan(),
 73							group.getRowspan()));
 74				}
 75				return;
 76			}
 77		}
 78		throw new AssertionError(String.format("Did not find header group '%s'", axis.getLabel()));
 79	}
 80
 81	private EntityCategory entity(int id, String label) {
 82		return new EntityCategory(id, label);
 83	}
 84	
 85	private static class ProviderStub implements PivotCellRendererProvider {
 86
 87		@Override
 88		public PivotCellRenderer getRendererForColumn(Axis column) {
 89			return null;
 90		}
 91		
 92	}
 93	
 94	private static class HeaderDecoratorStub implements HeaderDecorator {
 95
 96		@Override
 97		public String decorateHeader(Axis axis) {
 98			return axis.getLabel();
 99		}
100
101		@Override
102		public String cornerCellHtml() {
103			return ""; 
104		}
105		
106	}
107}