In the UI, allow primary keys to be any type, and test it.
[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 static org.junit.Assert.*;
4 import org.junit.Test;
5
6 public class ListPlaceTest {
7
8         public ListPlaceTest() {
9         }
10
11         @Test
12         public void testGetPlaceNoParameters() {
13                 checkTokenWithoutParameters("");
14                 checkTokenWithoutParameters("something");
15                 checkTokenWithoutParameters("list:a=1");
16                 checkTokenWithoutParameters("value1=123");
17         }
18
19         @Test
20         public void testGetPlaceParameters() {
21                 // Create a ListPlace, testing getPlace():
22                 final String documentId = "somedocument";
23                 final String tableName = "sometable";
24                 ListPlace place = getListPlaceFromToken("document=" + documentId + "&table=" + tableName);
25                 checkParameters(place, documentId, tableName);
26
27                 // Recreate it, testing getToken(),
28                 // checking that the same parameters are read back:
29                 final ListPlace.Tokenizer tokenizer = new ListPlace.Tokenizer();
30                 final String token = tokenizer.getToken(place);
31                 place = getListPlaceFromToken(token);
32                 checkParameters(place, documentId, tableName);
33         }
34
35         private void checkParameters(final ListPlace place, final String documentID, final String tableName) {
36                 assertTrue(place != null);
37
38                 assertEquals(documentID, place.getDocumentID());
39                 assertEquals(tableName, place.getTableName());
40         }
41
42         private ListPlace getListPlaceFromToken(final String token) {
43                 final ListPlace.Tokenizer tokenizer = new ListPlace.Tokenizer();
44                 final ListPlace place = tokenizer.getPlace(token);
45                 assertTrue(place != null);
46                 return place;
47         }
48
49         private void checkTokenWithoutParameters(final String token) {
50                 final ListPlace place = getListPlaceFromToken(token);
51
52                 assertTrue(place.getDocumentID() != null);
53                 assertTrue(place.getDocumentID().isEmpty());
54
55                 assertTrue(place.getTableName() != null);
56                 assertTrue(place.getTableName().isEmpty());
57         }
58
59 }