From d06efc9c714fd685fe270f28b9166b5f224e0028 Mon Sep 17 00:00:00 2001 From: Murray Cumming Date: Sun, 2 Dec 2012 22:53:36 +0100 Subject: [PATCH] Add GwtTestReportPlace. * src/test/java/org/glom/web/client/place/GwtTestReportPlace.java: This is like the existing GwtTest*Place tests. It would be nice if we could just test that all client and shared code can be compiled to Javascript without creating a test for it. Currently, we only discover problems when starting it in a browser. --- ChangeLog | 10 ++++ .../glom/web/client/place/GwtTestReportPlace.java | 69 ++++++++++++++++++++++ 2 files changed, 79 insertions(+) create mode 100644 src/test/java/org/glom/web/client/place/GwtTestReportPlace.java diff --git a/ChangeLog b/ChangeLog index bdba10c..04b730b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,15 @@ 2012-12-02 Murray Cumming + Add GwtTestReportPlace. + + * src/test/java/org/glom/web/client/place/GwtTestReportPlace.java: + This is like the existing GwtTest*Place tests. + It would be nice if we could just test that all client and shared + code can be compiled to Javascript without creating a test for it. + Currently, we only discover problems when starting it in a browser. + +2012-12-02 Murray Cumming + Add GwtTestDetailsPlace to test the same code as client-side. * src/test/java/org/glom/web/client/place/GwtTestDetailsPlace.java: diff --git a/src/test/java/org/glom/web/client/place/GwtTestReportPlace.java b/src/test/java/org/glom/web/client/place/GwtTestReportPlace.java new file mode 100644 index 0000000..25fe986 --- /dev/null +++ b/src/test/java/org/glom/web/client/place/GwtTestReportPlace.java @@ -0,0 +1,69 @@ +package org.glom.web.client.place; + +import static org.junit.Assert.*; +import org.junit.Test; + +import com.googlecode.gwt.test.GwtModule; +import com.googlecode.gwt.test.GwtTest; + +@GwtModule("org.glom.web.OnlineGlom") +public class GwtTestReportPlace extends GwtTest { + + public GwtTestReportPlace() { + } + + @Test + public void testGetPlaceNoParameters() { + checkTokenWithoutParameters(""); + checkTokenWithoutParameters("something"); + checkTokenWithoutParameters("list:a=1"); + checkTokenWithoutParameters("value1=123"); + } + + @Test + public void testGetPlaceParameters() { + // Create a ReportPlace, testing getPlace(): + final String documentId = "somedocument"; + final String tableName = "sometable"; + final String reportName = "somereport"; + ReportPlace place = getReportPlaceFromToken("document=" + documentId + "&table=" + tableName + "&report=" + reportName); + checkParameters(place, documentId, tableName, reportName); + + // Recreate it, testing getToken(), + // checking that the same parameters are read back: + final ReportPlace.Tokenizer tokenizer = new ReportPlace.Tokenizer(); + final String token = tokenizer.getToken(place); + place = getReportPlaceFromToken(token); + checkParameters(place, documentId, tableName, reportName); + } + + private void checkParameters(final ReportPlace place, final String documentID, final String tableName, final String reportName) { + assertTrue(place != null); + + assertEquals(documentID, place.getDocumentID()); + assertEquals(tableName, place.getTableName()); + assertEquals(reportName, place.getReportName()); + } + + private ReportPlace getReportPlaceFromToken(final String token) { + final ReportPlace.Tokenizer tokenizer = new ReportPlace.Tokenizer(); + final ReportPlace place = tokenizer.getPlace(token); + assertTrue(place != null); + return place; + } + + private void checkTokenWithoutParameters(final String token) { + final ReportPlace place = getReportPlaceFromToken(token); + + assertTrue(place.getDocumentID() != null); + assertTrue(place.getDocumentID().isEmpty()); + + assertTrue(place.getTableName() != null); + assertTrue(place.getTableName().isEmpty()); + + assertTrue(place.getReportName() != null); + assertTrue(place.getReportName().isEmpty()); + + } + +} -- 2.1.4