01: // Copyright (C) 2003,2004,2005 by Object Mentor, Inc. All rights reserved.
02: // Released under the terms of the GNU General Public License version 2 or later.
03: package fitnesse.responders.versions;
04:
05: import fitnesse.testutil.AbstractRegex;
06: import fitnesse.wiki.*;
07: import fitnesse.*;
08: import fitnesse.http.*;
09:
10: import java.util.*;
11:
12: public class VersionSelectionResponderTest extends AbstractRegex {
13: private WikiPage page;
14:
15: private WikiPage root;
16:
17: public void setUp() throws Exception {
18: root = InMemoryPage.makeRoot("RooT");
19: page = root.getPageCrawler().addPage(root,
20: PathParser.parse("PageOne"), "some content");
21: }
22:
23: public void tearDown() throws Exception {
24: }
25:
26: public void testGetVersionsList() throws Exception {
27: Set set = new HashSet();
28: VersionInfo v1 = new VersionInfo("1-12345678901234");
29: VersionInfo v2 = new VersionInfo("2-45612345678901");
30: VersionInfo v3 = new VersionInfo("3-11112345678901");
31: VersionInfo v4 = new VersionInfo("4-12212345465679");
32: set.add(v1);
33: set.add(v2);
34: set.add(v3);
35: set.add(v4);
36:
37: PageData data = new PageData(page);
38: data.addVersions(set);
39:
40: List list = VersionSelectionResponder.getVersionsList(data);
41: assertEquals(v3, list.get(3));
42: assertEquals(v4, list.get(2));
43: assertEquals(v1, list.get(1));
44: assertEquals(v2, list.get(0));
45: }
46:
47: public void testConvertVersionNameToAge() throws Exception {
48: Date now = new GregorianCalendar(2003, 0, 1, 00, 00, 01)
49: .getTime();
50: Date tenSeconds = new GregorianCalendar(2003, 0, 1, 00, 00, 11)
51: .getTime();
52: Date twoMinutes = new GregorianCalendar(2003, 0, 1, 00, 02, 01)
53: .getTime();
54: Date fiftyNineSecs = new GregorianCalendar(2003, 0, 1, 00, 01,
55: 00).getTime();
56: Date oneHour = new GregorianCalendar(2003, 0, 1, 01, 00, 01)
57: .getTime();
58: Date fiveDays = new GregorianCalendar(2003, 0, 6, 00, 00, 01)
59: .getTime();
60: Date years = new GregorianCalendar(2024, 0, 1, 00, 00, 01)
61: .getTime();
62:
63: assertEquals("10 seconds", VersionSelectionResponder
64: .howLongAgoString(now, tenSeconds));
65: assertEquals("2 minutes", VersionSelectionResponder
66: .howLongAgoString(now, twoMinutes));
67: assertEquals("59 seconds", VersionSelectionResponder
68: .howLongAgoString(now, fiftyNineSecs));
69: assertEquals("1 hour", VersionSelectionResponder
70: .howLongAgoString(now, oneHour));
71: assertEquals("5 days", VersionSelectionResponder
72: .howLongAgoString(now, fiveDays));
73: assertEquals("21 years", VersionSelectionResponder
74: .howLongAgoString(now, years));
75: }
76:
77: public void testMakeReponder() throws Exception {
78: MockRequest request = new MockRequest();
79: request.setResource("PageOne");
80:
81: Responder responder = new VersionSelectionResponder();
82: SimpleResponse response = (SimpleResponse) responder
83: .makeResponse(new FitNesseContext(root), request);
84:
85: String content = response.getContent();
86: assertSubString("<input", content);
87: assertSubString("name=\"version\"", content);
88: assertSubString("<form", content);
89: assertSubString("action=\"PageOne\"", content);
90: assertSubString("name=\"responder\"", content);
91: assertSubString(" value=\"viewVersion\"", content);
92: }
93: }
|