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

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

http://sigma-h.googlecode.com/
Java | 107 lines | 79 code | 28 blank | 0 comment | 0 complexity | 891bd9f545b8bb7f6777a80295edb9a3 MD5 | raw file
  1package org.sigmah.client.page.project.pivot;
  2
  3import static org.junit.Assert.*;
  4import static org.hamcrest.CoreMatchers.*;
  5
  6import org.junit.Test;
  7import org.junit.runner.RunWith;
  8import org.sigmah.server.dao.OnDataSet;
  9import org.sigmah.server.endpoint.gwtrpc.CommandTestCase;
 10import org.sigmah.server.util.DateUtilCalendarImpl;
 11import org.sigmah.shared.command.Month;
 12import org.sigmah.shared.date.DateUtil;
 13import org.sigmah.shared.dto.IndicatorDTO;
 14import org.sigmah.shared.dto.SiteDTO;
 15import org.sigmah.shared.report.model.DateRange;
 16import org.sigmah.test.InjectionSupport;
 17
 18import com.google.gwt.user.client.rpc.AsyncCallback;
 19
 20@RunWith(InjectionSupport.class)
 21@OnDataSet("/dbunit/project-indicator.db.xml")
 22public class PivotLayoutTest extends CommandTestCase {
 23
 24	private DateUtil dateUtil = new DateUtilCalendarImpl();
 25	
 26	@Test
 27	public void dateSerialization() {
 28		
 29		final DateRange range = dateUtil.monthRange(new Month(2011,1));
 30
 31		DateRangeModel model = new DateRangeModel("Jan 2011", range.getMinDate(), range.getMaxDate());
 32		DateLayout layout = new DateLayout(model, false);
 33		
 34		String serialized = layout.serialize();
 35		
 36		PivotLayout.deserialize(dispatcher, 1, serialized, new AsyncCallback<PivotLayout>() {
 37			
 38			@Override
 39			public void onSuccess(PivotLayout result) {
 40				DateLayout relayout = (DateLayout)result;
 41				assertThat(relayout.getModel().getLabel(), equalTo("Jan 2011"));
 42				assertThat(relayout.getAxesSwapped(), equalTo(false));
 43				assertThat(relayout.getDateRange(), equalTo(range));
 44			}
 45			
 46			@Override
 47			public void onFailure(Throwable caught) {
 48				throw new AssertionError(caught);
 49			}
 50		});
 51	}
 52	
 53	@Test
 54	public void indicatorSerialization() {
 55		
 56		IndicatorDTO indicator = new IndicatorDTO();
 57		indicator.setId(1);
 58		indicator.setName("Nombre de menages ayant recu une kit nfi");
 59		
 60		IndicatorLayout layout = new IndicatorLayout(indicator);
 61		
 62		String serialized = layout.serialize();
 63		
 64		PivotLayout.deserialize(dispatcher, 1, serialized, new AsyncCallback<PivotLayout>() {
 65
 66			@Override
 67			public void onFailure(Throwable caught) {
 68				throw new AssertionError(caught);
 69			}
 70
 71			@Override
 72			public void onSuccess(PivotLayout result) {
 73				IndicatorLayout relayout = (IndicatorLayout)result;
 74				assertThat(relayout.getIndicator().getId(), equalTo(1));
 75				assertThat(relayout.getIndicator().getName(), equalTo("Nombre de menages ayant recu une kit nfi"));
 76			}
 77		});
 78		
 79	}
 80	
 81	@Test
 82	public void siteSerialization() {
 83		
 84		SiteDTO site = new SiteDTO();
 85		site.setId(2);
 86		site.setLocationName("Ngshwe");
 87		
 88		SiteLayout layout = new SiteLayout(site);
 89		
 90		PivotLayout.deserialize(dispatcher, 1, layout.serialize(), new AsyncCallback<PivotLayout>() {
 91
 92			@Override
 93			public void onFailure(Throwable caught) {
 94				throw new AssertionError(caught);
 95			}
 96
 97			@Override
 98			public void onSuccess(PivotLayout result) {
 99				SiteLayout resite = (SiteLayout)result;
100				assertThat(resite.getSite().getId(), equalTo(2));
101				assertThat(resite.getSite().getLocationName(), equalTo("Ngshwe"));
102			}
103		});
104		
105	}
106	
107}