Source code: org/repoweb/action/UriBeautifierTest.java
1 /*
2 * REPOWEB, repository manager.
3 *
4 * Terms of license - http://opensource.org/licenses/apachepl.php
5 */
6 package org.repoweb.action;
7 import javax.servlet.http.HttpServletRequest;
8 import javax.servlet.http.HttpServletRequestWrapper;
9 import org.apache.struts.action.DynaActionForm;
10 import servletunit.struts.MockStrutsTestCase;
11 /**
12 * Test classes for UriBeautifier.
13 */
14 public class UriBeautifierTest extends MockStrutsTestCase {
15 // @todo Voir et comprendre pourquoi verifyForward ne semble pas tjrs marcher.
16 public UriBeautifierTest(String name) {
17 super(name);
18 }
19
20 public void test_badUri_short() throws Exception {
21 // setup
22 final String requestedPath = "/bad";
23 setRequestPathInfo(requestedPath);
24 setRequestWrapper(new Mocker(getRequest(), "repoweb/do" + requestedPath));
25
26 // Launch action
27 actionPerform();
28
29 // Verify Forward
30 // verifyForward("badURI");
31 verifyForwardPath("/pages/bug.jsp");
32
33 // Verify Error
34 verifyActionErrors(new String[] {"global.bad.url"});
35 verifyNoActionMessages();
36 }
37
38
39 public void test_badUri_long() throws Exception {
40 // setup
41 final String requestedPath = "/long/but/still/bad";
42 setRequestPathInfo(requestedPath);
43 setRequestWrapper(new Mocker(getRequest(), "repoweb/do" + requestedPath));
44
45 // Launch action
46 actionPerform();
47
48 // Verify Forward
49 // verifyForward("badURI");
50 verifyForwardPath("/pages/bug.jsp");
51
52 // Verify Error
53 verifyActionErrors(new String[] {"global.bad.url"});
54 verifyNoActionMessages();
55 }
56
57
58 public void test_root() throws Exception {
59 // setup
60 final String requestedPath = "/maven";
61 setRequestPathInfo(requestedPath);
62 setRequestWrapper(new Mocker(getRequest(), "repoweb/do" + requestedPath));
63
64 // Launch action
65 actionPerform();
66
67 // Verify Forward
68 verifyForward("allGroups");
69 verifyForwardPath("/do/root");
70
71 // Verify Error
72 verifyNoActionErrors();
73 verifyNoActionMessages();
74 }
75
76
77 public void test_group() throws Exception {
78 // setup
79 final String requestedPath = "/maven/junit";
80 setRequestPathInfo(requestedPath);
81 setRequestWrapper(new Mocker(getRequest(), "repoweb/do" + requestedPath));
82
83 // Launch action
84 actionPerform();
85
86 // Verify Forward
87 // verifyForward("oneGroup");
88 verifyForwardPath("/do/show/group");
89
90 // Verify Error
91 verifyNoActionErrors();
92 verifyNoActionMessages();
93
94 // Verify Parameter
95 assertEquals("junit", getDynaForm().get(FindArtifact.SEARCH_BY_GROUP_KEY));
96 }
97
98
99 public void test_type() throws Exception {
100 // setup
101 final String requestedPath = "/maven/junit/jars";
102 setRequestPathInfo(requestedPath);
103 setRequestWrapper(new Mocker(getRequest(), "repoweb/do" + requestedPath));
104
105 // Launch action
106 actionPerform();
107
108 // Verify Forward
109 // verifyForward("oneGroupByType");
110 verifyForwardPath("/do/group/artifact/byType");
111
112 // Verify Error
113 verifyNoActionErrors();
114 verifyNoActionMessages();
115
116 // Verify Parameter
117 assertEquals("junit", getDynaForm().get(FindArtifact.SEARCH_BY_GROUP_KEY));
118 assertEquals("jar", getDynaForm().get(FindArtifact.SEARCH_BY_TYPE_KEY));
119 }
120
121
122 public void test_type_noS() throws Exception {
123 // setup
124 final String requestedPath = "/maven/junit/jar";
125 setRequestPathInfo(requestedPath);
126 setRequestWrapper(new Mocker(getRequest(), "repoweb/do" + requestedPath));
127
128 // Launch action
129 actionPerform();
130
131 // Verify Forward
132 // verifyForward("oneGroupByType");
133 verifyForwardPath("/do/group/artifact/byType");
134
135 // Verify Error
136 verifyNoActionErrors();
137 verifyNoActionMessages();
138
139 // Verify Parameter
140 assertEquals("junit", getDynaForm().get(FindArtifact.SEARCH_BY_GROUP_KEY));
141 assertEquals("jar", getDynaForm().get(FindArtifact.SEARCH_BY_TYPE_KEY));
142 }
143
144
145 public void test_artifact() throws Exception {
146 // setup
147 final String requestedPath = "/maven/junit/jars/junit-3.8.1.jar";
148 setRequestPathInfo(requestedPath);
149 setRequestWrapper(new Mocker(getRequest(), "repoweb/do" + requestedPath));
150
151 // Launch action
152 actionPerform();
153
154 // Verify Forward
155 // verifyForward("oneAritfact");
156 verifyForwardPath("/do/group/artifact");
157
158 // Verify Error
159 verifyNoActionErrors();
160 verifyNoActionMessages();
161
162 // Verify Parameter
163 assertEquals("junit", getDynaForm().get(FindArtifact.SEARCH_BY_GROUP_KEY));
164 assertEquals("jar", getDynaForm().get(FindArtifact.SEARCH_BY_TYPE_KEY));
165 assertEquals("junit-3.8.1.jar", getDynaForm().get(FindArtifact.SEARCH_BY_FILE_KEY));
166 }
167
168
169 private DynaActionForm getDynaForm() {
170 return (DynaActionForm)getRequest().getAttribute("SearchArtifactForm");
171 }
172
173 /**
174 * Mock wrapper to allow the method getRequestURI() to return valid data.
175 */
176 private class Mocker extends HttpServletRequestWrapper {
177 private final String _requestURI;
178
179 public Mocker(HttpServletRequest request, String requestURI) {
180 super(request);
181 _requestURI = requestURI;
182 }
183
184 public String getRequestURI() {
185 return _requestURI;
186 }
187 }
188 }