DetailsPlace: Use a date-formatting API available in GWT client code.
[online-glom:gwt-glom.git] / src / test / java / org / glom / web / client / place / GwtTestListPlace.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 GwtTestListPlace extends GwtTest {
11
12         public GwtTestListPlace() {
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 ListPlace, testing getPlace():
26                 final String documentId = "somedocument";
27                 final String tableName = "sometable";
28                 ListPlace place = getListPlaceFromToken("document=" + documentId + "&table=" + tableName);
29                 checkParameters(place, documentId, tableName);
30
31                 // Recreate it, testing getToken(),
32                 // checking that the same parameters are read back:
33                 final ListPlace.Tokenizer tokenizer = new ListPlace.Tokenizer();
34                 final String token = tokenizer.getToken(place);
35                 place = getListPlaceFromToken(token);
36                 checkParameters(place, documentId, tableName);
37         }
38
39         private void checkParameters(final ListPlace place, final String documentID, final String tableName) {
40                 assertTrue(place != null);
41
42                 assertEquals(documentID, place.getDocumentID());
43                 assertEquals(tableName, place.getTableName());
44         }
45
46         private ListPlace getListPlaceFromToken(final String token) {
47                 final ListPlace.Tokenizer tokenizer = new ListPlace.Tokenizer();
48                 final ListPlace place = tokenizer.getPlace(token);
49                 assertTrue(place != null);
50                 return place;
51         }
52
53         private void checkTokenWithoutParameters(final String token) {
54                 final ListPlace place = getListPlaceFromToken(token);
55
56                 assertTrue(place.getDocumentID() != null);
57                 assertTrue(place.getDocumentID().isEmpty());
58
59                 assertTrue(place.getTableName() != null);
60                 assertTrue(place.getTableName().isEmpty());
61         }
62
63 }