PageRenderTime 8ms CodeModel.GetById 1ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/sigmah/src/test/java/org/sigmah/client/page/project/pivot/LayoutComposerTest.java

http://sigma-h.googlecode.com/
Java | 104 lines | 68 code | 35 blank | 1 comment | 0 complexity | 8ef871d0ad10bb69652451c7ac54595a MD5 | raw file
  1package org.sigmah.client.page.project.pivot;
  2
  3import static org.hamcrest.CoreMatchers.equalTo;
  4import static org.junit.Assert.assertThat;
  5
  6import java.util.Calendar;
  7import java.util.Date;
  8import java.util.List;
  9
 10import org.junit.Before;
 11import org.junit.Test;
 12import org.junit.runner.RunWith;
 13import org.sigmah.server.dao.OnDataSet;
 14import org.sigmah.server.endpoint.gwtrpc.CommandTestCase;
 15import org.sigmah.server.util.DateUtilCalendarImpl;
 16import org.sigmah.shared.command.GenerateElement;
 17import org.sigmah.shared.command.GetProject;
 18import org.sigmah.shared.date.DateUtil;
 19import org.sigmah.shared.dto.ProjectDTO;
 20import org.sigmah.shared.exception.CommandException;
 21import org.sigmah.shared.report.content.EntityCategory;
 22import org.sigmah.shared.report.content.PivotContent;
 23import org.sigmah.shared.report.content.PivotTableData.Axis;
 24import org.sigmah.shared.report.model.DimensionType;
 25import org.sigmah.shared.report.model.PivotTableElement;
 26import org.sigmah.test.InjectionSupport;
 27
 28@RunWith(InjectionSupport.class)
 29@OnDataSet("/dbunit/project-indicator.db.xml")
 30public class LayoutComposerTest extends CommandTestCase {
 31
 32	
 33	private LayoutComposer composer;
 34	private DateUtil dateUtil = new DateUtilCalendarImpl();
 35	
 36	public void setupComposer() throws CommandException {
 37		setUser(1);
 38		
 39		ProjectDTO project = execute(new GetProject(1));
 40		composer = new LayoutComposer(new DateUtilCalendarImpl(), project);
 41	}
 42	
 43
 44
 45	@Test
 46	public void dateFixed() throws CommandException {
 47
 48		setupComposer();
 49		
 50		PivotTableElement element = executeLayout(composer.fixDateRange(dateUtil.monthRange(2010, 1), false));			
 51	
 52		System.out.println(element.getContent());
 53
 54		List<Axis> indicatorColumns = element.getContent().getData().getRootColumn().getDescendantsAtDepth(2);
 55	
 56		assertThat(indicatorColumns.size(), equalTo(4));
 57		
 58		// make sure that empty admin levels are skipped
 59		Axis nordKivu = element.getContent().getData().getRootRow().getChild(new EntityCategory(3));
 60		Axis goma = nordKivu.firstChild();
 61		
 62		assertThat( goma.getDimension().getType(), equalTo(DimensionType.Site) );
 63	}
 64	
 65	@Test
 66	public void siteFixed() throws CommandException {
 67		setupComposer();
 68
 69					
 70		PivotTableElement element = executeLayout(composer.fixSite(1));
 71		
 72		System.out.println(element.getContent());
 73		
 74	}
 75	
 76	@Test
 77	public void siteFixedWithNoDataEntered() throws CommandException {
 78
 79		setupComposer();
 80
 81		PivotTableElement element = executeLayout(composer.fixSite(4));
 82		
 83		System.out.println(element.getContent());
 84		
 85	}
 86	
 87	@Test
 88	public void indicatorFixed() throws CommandException {
 89		setupComposer();
 90
 91		PivotTableElement element = executeLayout(composer.fixSite(1));
 92		
 93		System.out.println(element.getContent());
 94		
 95	}
 96	
 97		
 98	
 99	private PivotTableElement executeLayout(PivotTableElement element) throws CommandException {
100		PivotContent content = execute(new GenerateElement<PivotContent>(element));
101		element.setContent(content);
102		return element;
103	}
104}