Added a test for ListPlace token parsing and creation.
[online-glom:gwt-glom.git] / src / test / java / org / glom / web / client / place / ListPlaceTest.java
1 package org.glom.web.client.place;
2
3 import junit.framework.TestCase;
4 import junit.framework.Assert;
5
6 public class ListPlaceTest extends TestCase {
7
8         public ListPlaceTest() {
9         }
10
11         public void testGetPlaceNoParameters() {
12                 checkTokenWithoutParameters("");
13                 checkTokenWithoutParameters("something");
14                 checkTokenWithoutParameters("list:a=1");
15                 checkTokenWithoutParameters("value1=123");
16         }
17
18         public void testGetPlaceParameters() {
19                 // Create a ListPlace, testing getPlace():
20                 final String documentId = "somedocument";
21                 final String tableName = "sometable";
22                 ListPlace place = getListPlaceFromToken("document=" + documentId + "&table=" + tableName);
23                 checkParameters(place, documentId, tableName);
24
25                 // Recreate it, testing getToken(),
26                 // checking that the same parameters are read back:
27                 ListPlace.Tokenizer tokenizer = new ListPlace.Tokenizer();
28                 final String token = tokenizer.getToken(place);
29                 place = getListPlaceFromToken(token);
30                 checkParameters(place, documentId, tableName);
31         }
32
33         private void checkParameters(ListPlace place, final String documentID, final String tableName) {
34                 Assert.assertTrue(place != null);
35
36                 Assert.assertEquals(documentID, place.getDocumentID());
37                 Assert.assertEquals(tableName, place.getTableName());
38         }
39
40         private ListPlace getListPlaceFromToken(final String token) {
41                 ListPlace.Tokenizer tokenizer = new ListPlace.Tokenizer();
42                 ListPlace place = tokenizer.getPlace(token);
43                 Assert.assertTrue(place != null);
44                 return place;
45         }
46
47         private void checkTokenWithoutParameters(final String token) {
48                 ListPlace place = getListPlaceFromToken(token);
49
50                 Assert.assertTrue(place.getDocumentID() != null);
51                 Assert.assertTrue(place.getDocumentID().isEmpty());
52
53                 Assert.assertTrue(place.getTableName() != null);
54                 Assert.assertTrue(place.getTableName().isEmpty());
55         }
56
57 }