/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

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