You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by ma...@apache.org on 2005/01/14 06:27:33 UTC
svn commit: r125145 - /struts/taglib/trunk/src/test/org/apache/struts/taglib/TestTagUtils.java
Author: martinc
Date: Thu Jan 13 21:27:31 2005
New Revision: 125145
URL: http://svn.apache.org/viewcvs?view=rev&rev=125145
Log:
Add tests for methods moved here from RequestUtils in 'core'. These tests came from TestRequestUtils.
Modified:
struts/taglib/trunk/src/test/org/apache/struts/taglib/TestTagUtils.java
Modified: struts/taglib/trunk/src/test/org/apache/struts/taglib/TestTagUtils.java
Url: http://svn.apache.org/viewcvs/struts/taglib/trunk/src/test/org/apache/struts/taglib/TestTagUtils.java?view=diff&rev=125145&p1=struts/taglib/trunk/src/test/org/apache/struts/taglib/TestTagUtils.java&r1=125144&p2=struts/taglib/trunk/src/test/org/apache/struts/taglib/TestTagUtils.java&r2=125145
==============================================================================
--- struts/taglib/trunk/src/test/org/apache/struts/taglib/TestTagUtils.java (original)
+++ struts/taglib/trunk/src/test/org/apache/struts/taglib/TestTagUtils.java Thu Jan 13 21:27:31 2005
@@ -431,4 +431,553 @@
(String) map.get(Constants.TOKEN_KEY));
}
+ // ----------------------------------------------------------- computeURL()
+
+
+ // Default module -- Forward only
+ public void testComputeURL1a() {
+
+ request.setPathElements("/myapp", "/action.do", null, null);
+ String url = null;
+ try {
+ url = RequestUtils.computeURL
+ (page, "foo",
+ null, null,
+ null, null, false);
+ } catch (MalformedURLException e) {
+ fail("MalformedURLException: " + e);
+ }
+ assertNotNull("url present", url);
+ assertEquals("url value",
+ "/myapp/bar.jsp",
+ url);
+
+ }
+
+
+ // Default module -- Href only
+ public void testComputeURL1b() {
+
+ request.setPathElements("/myapp", "/action.do", null, null);
+ String url = null;
+ try {
+ url = RequestUtils.computeURL
+ (page, null,
+ "http://foo.com/bar", null,
+ null, null, false);
+ } catch (MalformedURLException e) {
+ fail("MalformedURLException: " + e);
+ }
+ assertNotNull("url present", url);
+ assertEquals("url value",
+ "http://foo.com/bar",
+ url);
+
+ }
+
+
+ // Default module -- Page only
+ public void testComputeURL1c() {
+
+ request.setPathElements("/myapp", "/action.do", null, null);
+ String url = null;
+ try {
+ url = RequestUtils.computeURL
+ (page, null,
+ null, "/bar",
+ null, null, false);
+ } catch (MalformedURLException e) {
+ fail("MalformedURLException: " + e);
+ }
+ assertNotNull("url present", url);
+ assertEquals("url value",
+ "/myapp/bar",
+ url);
+
+ }
+
+
+ // Default module -- Forward with pattern
+ public void testComputeURL1d() {
+
+ moduleConfig.getControllerConfig().setForwardPattern
+ ("$C/WEB-INF/pages$M$P");
+ request.setPathElements("/myapp", "/action.do", null, null);
+ String url = null;
+ try {
+ url = RequestUtils.computeURL
+ (page, "foo",
+ null, null,
+ null, null, false);
+ } catch (MalformedURLException e) {
+ fail("MalformedURLException: " + e);
+ }
+ assertNotNull("url present", url);
+ assertEquals("url value",
+ "/myapp/WEB-INF/pages/bar.jsp",
+ url);
+
+ }
+
+
+ // Default module -- Page with pattern
+ public void testComputeURL1e() {
+
+ moduleConfig.getControllerConfig().setPagePattern
+ ("$C/WEB-INF/pages$M$P");
+ request.setPathElements("/myapp", "/action.do", null, null);
+ String url = null;
+ try {
+ url = RequestUtils.computeURL
+ (page, null,
+ null, "/bar",
+ null, null, false);
+ } catch (MalformedURLException e) {
+ fail("MalformedURLException: " + e);
+ }
+ assertNotNull("url present", url);
+ assertEquals("url value",
+ "/myapp/WEB-INF/pages/bar",
+ url);
+
+ }
+
+
+ // Default module -- Forward with relative path (non-context-relative)
+ public void testComputeURL1f() {
+
+ request.setPathElements("/myapp", "/action.do", null, null);
+ String url = null;
+ try {
+ url = RequestUtils.computeURL
+ (page, "relative1",
+ null, null,
+ null, null, false);
+ } catch (MalformedURLException e) {
+ fail("MalformedURLException: " + e);
+ }
+ assertNotNull("url present", url);
+ assertEquals("url value",
+ // "/myapp/relative.jsp",
+ "relative.jsp",
+ url);
+ }
+
+
+ // Default module -- Forward with relative path (context-relative)
+ public void testComputeURL1g() {
+
+ request.setPathElements("/myapp", "/action.do", null, null);
+ String url = null;
+ try {
+ url = RequestUtils.computeURL
+ (page, "relative2",
+ null, null,
+ null, null, false);
+ } catch (MalformedURLException e) {
+ fail("MalformedURLException: " + e);
+ }
+ assertNotNull("url present", url);
+ assertEquals("url value",
+ // "/myapp/relative.jsp",
+ "relative.jsp",
+ url);
+ }
+
+
+ // Default module -- Forward with external path
+ public void testComputeURL1h() {
+
+ request.setPathElements("/myapp", "/action.do", null, null);
+ String url = null;
+ try {
+ url = RequestUtils.computeURL
+ (page, "external",
+ null, null,
+ null, null, false);
+ } catch (MalformedURLException e) {
+ fail("MalformedURLException: " + e);
+ }
+ assertNotNull("url present", url);
+ assertEquals("url value",
+ "http://jakarta.apache.org/",
+ url);
+ }
+
+
+ // Second module -- Forward only
+ public void testComputeURL2a() {
+
+ request.setAttribute(Globals.MODULE_KEY, moduleConfig2);
+ request.setPathElements("/myapp", "/2/action.do", null, null);
+ String url = null;
+ try {
+ url = RequestUtils.computeURL
+ (page, "foo",
+ null, null,
+ null, null, false);
+ } catch (MalformedURLException e) {
+ fail("MalformedURLException: " + e);
+ }
+ assertNotNull("url present", url);
+ assertEquals("url value",
+ "/myapp/2/baz.jsp",
+ url);
+
+ }
+
+
+ // Second module -- Href only
+ public void testComputeURL2b() {
+
+ request.setAttribute(Globals.MODULE_KEY, moduleConfig2);
+ request.setPathElements("/myapp", "/2/action.do", null, null);
+ String url = null;
+ try {
+ url = RequestUtils.computeURL
+ (page, null,
+ "http://foo.com/bar", null,
+ null, null, false);
+ } catch (MalformedURLException e) {
+ fail("MalformedURLException: " + e);
+ }
+ assertNotNull("url present", url);
+ assertEquals("url value",
+ "http://foo.com/bar",
+ url);
+
+ }
+
+
+ // Second module -- Page only
+ public void testComputeURL2c() {
+
+ request.setAttribute(Globals.MODULE_KEY, moduleConfig2);
+ request.setPathElements("/myapp", "/2/action.do", null, null);
+ String url = null;
+ try {
+ url = RequestUtils.computeURL
+ (page, null,
+ null, "/bar",
+ null, null, false);
+ } catch (MalformedURLException e) {
+ fail("MalformedURLException: " + e);
+ }
+ assertNotNull("url present", url);
+ assertEquals("url value",
+ "/myapp/2/bar",
+ url);
+
+ }
+
+
+ // Default module -- Forward with pattern
+ public void testComputeURL2d() {
+
+ request.setAttribute(Globals.MODULE_KEY, moduleConfig2);
+ moduleConfig2.getControllerConfig().setForwardPattern
+ ("$C/WEB-INF/pages$M$P");
+ request.setPathElements("/myapp", "/2/action.do", null, null);
+ String url = null;
+ try {
+ url = RequestUtils.computeURL
+ (page, "foo",
+ null, null,
+ null, null, false);
+ } catch (MalformedURLException e) {
+ fail("MalformedURLException: " + e);
+ }
+ assertNotNull("url present", url);
+ assertEquals("url value",
+ "/myapp/WEB-INF/pages/2/baz.jsp",
+ url);
+
+ }
+
+
+ // Second module -- Page with pattern
+ public void testComputeURL2e() {
+
+ moduleConfig2.getControllerConfig().setPagePattern
+ ("$C/WEB-INF/pages$M$P");
+ request.setAttribute(Globals.MODULE_KEY, moduleConfig2);
+ request.setPathElements("/myapp", "/2/action.do", null, null);
+ String url = null;
+ try {
+ url = RequestUtils.computeURL
+ (page, null,
+ null, "/bar",
+ null, null, false);
+ } catch (MalformedURLException e) {
+ fail("MalformedURLException: " + e);
+ }
+ assertNotNull("url present", url);
+ assertEquals("url value",
+ "/myapp/WEB-INF/pages/2/bar",
+ url);
+
+ }
+
+
+ // Second module -- Forward with relative path (non-context-relative)
+ public void testComputeURL2f() {
+
+ request.setAttribute(Globals.MODULE_KEY, moduleConfig2);
+ request.setPathElements("/myapp", "/2/action.do", null, null);
+ String url = null;
+ try {
+ url = RequestUtils.computeURL
+ (page, "relative1",
+ null, null,
+ null, null, false);
+ } catch (MalformedURLException e) {
+ fail("MalformedURLException: " + e);
+ }
+ assertNotNull("url present", url);
+ assertEquals("url value",
+ // "/myapp/2/relative.jsp",
+ "relative.jsp",
+ url);
+ }
+
+
+ // Second module -- Forward with relative path (context-relative)
+ public void testComputeURL2g() {
+
+ request.setAttribute(Globals.MODULE_KEY, moduleConfig2);
+ request.setPathElements("/myapp", "/2/action.do", null, null);
+ String url = null;
+ try {
+ url = RequestUtils.computeURL
+ (page, "relative2",
+ null, null,
+ null, null, false);
+ } catch (MalformedURLException e) {
+ fail("MalformedURLException: " + e);
+ }
+ assertNotNull("url present", url);
+ assertEquals("url value",
+ // "/myapp/relative.jsp",
+ "relative.jsp",
+ url);
+ }
+
+
+ // Second module -- Forward with external path
+ public void testComputeURL2h() {
+
+ request.setAttribute(Globals.MODULE_KEY, moduleConfig2);
+ request.setPathElements("/myapp", "/2/action.do", null, null);
+ String url = null;
+ try {
+ url = RequestUtils.computeURL
+ (page, "external",
+ null, null,
+ null, null, false);
+ } catch (MalformedURLException e) {
+ fail("MalformedURLException: " + e);
+ }
+ assertNotNull("url present", url);
+ assertEquals("url value",
+ "http://jakarta.apache.org/",
+ url);
+ }
+
+
+ // Add parameters only -- forward URL
+ public void testComputeURL3a() {
+
+ request.setPathElements("/myapp", "/action.do", null, null);
+ Map map = new HashMap();
+ map.put("foo1", "bar1");
+ map.put("foo2", "bar2");
+ String url = null;
+ try {
+ url = RequestUtils.computeURL
+ (page, null,
+ null, "/bar",
+ map, null, false);
+ } catch (MalformedURLException e) {
+ fail("MalformedURLException: " + e);
+ }
+ assertNotNull("url present", url);
+ assertTrue("url value",
+ url.equals("/myapp/bar?foo1=bar1&foo2=bar2") ||
+ url.equals("/myapp/bar?foo2=bar2&foo1=bar1"));
+
+ }
+
+
+ // Add anchor only -- forward URL
+ public void testComputeURL3b() {
+
+ request.setPathElements("/myapp", "/action.do", null, null);
+ String url = null;
+ try {
+ url = RequestUtils.computeURL
+ (page, null,
+ null, "/bar",
+ null, "anchor", false);
+ } catch (MalformedURLException e) {
+ fail("MalformedURLException: " + e);
+ }
+ assertNotNull("url present", url);
+ assertEquals("url value",
+ "/myapp/bar#anchor",
+ url);
+
+ }
+
+
+ // Add parameters + anchor -- forward URL
+ public void testComputeURL3c() {
+
+ request.setPathElements("/myapp", "/action.do", null, null);
+ Map map = new HashMap();
+ map.put("foo1", "bar1");
+ map.put("foo2", "bar2");
+ String url = null;
+ try {
+ url = RequestUtils.computeURL
+ (page, null,
+ null, "/bar",
+ map, "anchor", false);
+ } catch (MalformedURLException e) {
+ fail("MalformedURLException: " + e);
+ }
+ assertNotNull("url present", url);
+ assertTrue("url value",
+ url.equals("/myapp/bar?foo1=bar1&foo2=bar2#anchor") ||
+ url.equals("/myapp/bar?foo2=bar2&foo1=bar1#anchor"));
+
+ }
+
+
+ // Add parameters only -- redirect URL
+ public void testComputeURL3d() {
+
+ request.setPathElements("/myapp", "/action.do", null, null);
+ Map map = new HashMap();
+ map.put("foo1", "bar1");
+ map.put("foo2", "bar2");
+ String url = null;
+ try {
+ url = RequestUtils.computeURL
+ (page, null,
+ null, "/bar",
+ map, null, true);
+ } catch (MalformedURLException e) {
+ fail("MalformedURLException: " + e);
+ }
+ assertNotNull("url present", url);
+ assertTrue("url value",
+ url.equals("/myapp/bar?foo1=bar1&foo2=bar2") ||
+ url.equals("/myapp/bar?foo2=bar2&foo1=bar1"));
+
+ }
+
+
+ // Add anchor only -- redirect URL
+ public void testComputeURL3e() {
+
+ request.setPathElements("/myapp", "/action.do", null, null);
+ String url = null;
+ try {
+ url = RequestUtils.computeURL
+ (page, null,
+ null, "/bar",
+ null, "anchor", true);
+ } catch (MalformedURLException e) {
+ fail("MalformedURLException: " + e);
+ }
+ assertNotNull("url present", url);
+ assertEquals("url value",
+ "/myapp/bar#anchor",
+ url);
+
+ }
+
+
+ // Add parameters + anchor -- redirect URL
+ public void testComputeURL3f() {
+
+ request.setPathElements("/myapp", "/action.do", null, null);
+ Map map = new HashMap();
+ map.put("foo1", "bar1");
+ map.put("foo2", "bar2");
+ String url = null;
+ try {
+ url = RequestUtils.computeURL
+ (page, null,
+ null, "/bar",
+ map, "anchor", false);
+ } catch (MalformedURLException e) {
+ fail("MalformedURLException: " + e);
+ }
+ assertNotNull("url present", url);
+ assertTrue("url value",
+ url.equals("/myapp/bar?foo1=bar1&foo2=bar2#anchor") ||
+ url.equals("/myapp/bar?foo2=bar2&foo1=bar1#anchor"));
+
+ }
+
+ // -------------------------------------------------------------- pageURL()
+
+
+ // Default module (default pagePattern)
+ public void testPageURL1() {
+
+ request.setAttribute(Globals.MODULE_KEY, moduleConfig);
+ request.setPathElements("/myapp", "/action.do", null, null);
+ String page = null;
+ String result = null;
+
+ // Straight substitution
+ page = "/mypages/index.jsp";
+ result = RequestUtils.pageURL(request, page);
+ assertNotNull("straight sub found", result);
+ assertEquals("straight sub value",
+ "/mypages/index.jsp", result);
+
+
+ }
+
+
+ // Second module (default pagePattern)
+ public void testPageURL2() {
+
+ request.setAttribute(Globals.MODULE_KEY, moduleConfig2);
+ request.setPathElements("/myapp", "/2/action.do", null, null);
+ String page = null;
+ String result = null;
+
+ // Straight substitution
+ page = "/mypages/index.jsp";
+ result = RequestUtils.pageURL(request, page);
+ assertNotNull("straight sub found", result);
+ assertEquals("straight sub value",
+ "/2/mypages/index.jsp", result);
+
+
+ }
+
+
+ // Third module (custom pagePattern)
+ public void testPageURL3() {
+
+ request.setAttribute(Globals.MODULE_KEY, moduleConfig3);
+ request.setPathElements("/myapp", "/3/action.do", null, null);
+ String page = null;
+ String result = null;
+
+ // Straight substitution
+ page = "/mypages/index.jsp";
+ result = RequestUtils.pageURL(request, page);
+ assertNotNull("straight sub found", result);
+ assertEquals("straight sub value",
+ "/paging/3/mypages/index.jsp", result);
+
+
+ }
+
}
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org