Add GwtTestReportPlace.
[online-glom:gwt-glom.git] / src / test / java / org / glom / web / client / place / GwtTestReportPlace.java
1 package org.glom.web.client.place;
2
3 import static org.junit.Assert.*;
4 import org.junit.Test;
5
6 import com.googlecode.gwt.test.GwtModule;
7 import com.googlecode.gwt.test.GwtTest;
8
9 @GwtModule("org.glom.web.OnlineGlom")
10 public class GwtTestReportPlace extends GwtTest {
11
12         public GwtTestReportPlace() {
13         }
14
15         @Test
16         public void testGetPlaceNoParameters() {
17                 checkTokenWithoutParameters("");
18                 checkTokenWithoutParameters("something");
19                 checkTokenWithoutParameters("list:a=1");
20                 checkTokenWithoutParameters("value1=123");
21         }
22
23         @Test
24         public void testGetPlaceParameters() {
25                 // Create a ReportPlace, testing getPlace():
26                 final String documentId = "somedocument";
27                 final String tableName = "sometable";
28                 final String reportName = "somereport";
29                 ReportPlace place = getReportPlaceFromToken("document=" + documentId + "&table=" + tableName + "&report=" + reportName);
30                 checkParameters(place, documentId, tableName, reportName);
31
32                 // Recreate it, testing getToken(),
33                 // checking that the same parameters are read back:
34                 final ReportPlace.Tokenizer tokenizer = new ReportPlace.Tokenizer();
35                 final String token = tokenizer.getToken(place);
36                 place = getReportPlaceFromToken(token);
37                 checkParameters(place, documentId, tableName, reportName);
38         }
39
40         private void checkParameters(final ReportPlace place, final String documentID, final String tableName, final String reportName) {
41                 assertTrue(place != null);
42
43                 assertEquals(documentID, place.getDocumentID());
44                 assertEquals(tableName, place.getTableName());
45                 assertEquals(reportName, place.getReportName());
46         }
47
48         private ReportPlace getReportPlaceFromToken(final String token) {
49                 final ReportPlace.Tokenizer tokenizer = new ReportPlace.Tokenizer();
50                 final ReportPlace place = tokenizer.getPlace(token);
51                 assertTrue(place != null);
52                 return place;
53         }
54
55         private void checkTokenWithoutParameters(final String token) {
56                 final ReportPlace place = getReportPlaceFromToken(token);
57
58                 assertTrue(place.getDocumentID() != null);
59                 assertTrue(place.getDocumentID().isEmpty());
60
61                 assertTrue(place.getTableName() != null);
62                 assertTrue(place.getTableName().isEmpty());
63                 
64                 assertTrue(place.getReportName() != null);
65                 assertTrue(place.getReportName().isEmpty());
66                                 
67         }
68
69 }