Tests: Use junit4-style syntax instead of junit3-style.
[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 org.junit.Test;
4 import org.junit.Assert;
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                 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(DetailsPlace place, final String documentID, final String tableName,
38                         final String primaryKeyValue) {
39                 Assert.assertTrue(place != null);
40
41                 Assert.assertEquals(documentID, place.getDocumentID());
42                 Assert.assertEquals(tableName, place.getTableName());
43                 Assert.assertEquals(primaryKeyValue, place.getPrimaryKeyValue().getUnknown());
44         }
45
46         private DetailsPlace getDetailsPlaceFromToken(final String token) {
47                 DetailsPlace.Tokenizer tokenizer = new DetailsPlace.Tokenizer();
48                 DetailsPlace place = tokenizer.getPlace(token);
49                 Assert.assertTrue(place != null);
50                 return place;
51         }
52
53         private void checkTokenWithoutParameters(final String token) {
54                 DetailsPlace place = getDetailsPlaceFromToken(token);
55
56                 Assert.assertTrue(place.getDocumentID() != null);
57                 Assert.assertTrue(place.getDocumentID().isEmpty());
58
59                 Assert.assertTrue(place.getTableName() != null);
60                 Assert.assertTrue(place.getTableName().isEmpty());
61
62                 Assert.assertTrue(place.getPrimaryKeyValue() != null);
63                 Assert.assertTrue(place.getPrimaryKeyValue().isEmpty());
64                 Assert.assertEquals(null, place.getPrimaryKeyValue().getUnknown());
65                 Assert.assertEquals(0.0, place.getPrimaryKeyValue().getNumber(), 0.0);
66                 Assert.assertEquals(null, place.getPrimaryKeyValue().getText());
67         }
68
69 }