Allow primary keys to be any type, and test it.
[online-glom:gwt-glom.git] / src / test / java / org / glom / web / client / place / DetailsPlaceTest.java
1 package org.glom.web.client.place;
2
3 import static org.junit.Assert.*;
4 import org.junit.Test;
5
6 public class DetailsPlaceTest {
7
8         public DetailsPlaceTest() {
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 DetailsPlace, testing getPlace():
22                 final String documentId = "somedocument";
23                 final String tableName = "sometable";
24                 final String primaryKeyValue = "123";
25                 DetailsPlace place = getDetailsPlaceFromToken("document=" + documentId + "&table=" + tableName + "&value="
26                                 + primaryKeyValue);
27                 checkParameters(place, documentId, tableName, primaryKeyValue);
28
29                 // Recreate it, testing getToken(),
30                 // checking that the same parameters are read back:
31                 final DetailsPlace.Tokenizer tokenizer = new DetailsPlace.Tokenizer();
32                 final String token = tokenizer.getToken(place);
33                 place = getDetailsPlaceFromToken(token);
34                 checkParameters(place, documentId, tableName, primaryKeyValue);
35         }
36
37         private void checkParameters(final DetailsPlace place, final String documentID, final String tableName,
38                         final String primaryKeyValue) {
39                 assertNotNull(place);
40
41                 assertEquals(documentID, place.getDocumentID());
42                 assertEquals(tableName, place.getTableName());
43                 assertEquals(primaryKeyValue, place.getPrimaryKeyValue().getUnknown());
44         }
45
46         private DetailsPlace getDetailsPlaceFromToken(final String token) {
47                 final DetailsPlace.Tokenizer tokenizer = new DetailsPlace.Tokenizer();
48                 final DetailsPlace place = tokenizer.getPlace(token);
49                 assertNotNull(place);
50                 return place;
51         }
52
53         private void checkTokenWithoutParameters(final String token) {
54                 final DetailsPlace place = getDetailsPlaceFromToken(token);
55
56                 assertNotNull(place.getDocumentID());
57                 assertTrue(place.getDocumentID().isEmpty());
58
59                 assertNotNull(place.getTableName());
60                 assertTrue(place.getTableName().isEmpty());
61
62                 assertNotNull(place.getPrimaryKeyValue());
63                 assertTrue(place.getPrimaryKeyValue().isEmpty());
64                 assertEquals(null, place.getPrimaryKeyValue().getUnknown());
65                 assertEquals(0.0, place.getPrimaryKeyValue().getNumber(), 0.0); //TODO: Handle other types.
66                 assertEquals(null, place.getPrimaryKeyValue().getText());
67         }
68
69 }