Author: nbelaevski
Date: 2008-07-30 21:08:11 -0400 (Wed, 30 Jul 2008)
New Revision: 9833
Modified:
trunk/framework/test/src/main/java/org/ajax4jsf/tests/AbstractAjax4JsfTestCase.java
trunk/framework/test/src/test/java/org/ajax4jsf/resource/CSSTemplateTestCase.java
trunk/framework/test/src/test/java/org/ajax4jsf/webapp/WebXmlTest.java
Log:
https://jira.jboss.org/jira/browse/RF-4063
Modified:
trunk/framework/test/src/main/java/org/ajax4jsf/tests/AbstractAjax4JsfTestCase.java
===================================================================
---
trunk/framework/test/src/main/java/org/ajax4jsf/tests/AbstractAjax4JsfTestCase.java 2008-07-30
16:26:35 UTC (rev 9832)
+++
trunk/framework/test/src/main/java/org/ajax4jsf/tests/AbstractAjax4JsfTestCase.java 2008-07-31
01:08:11 UTC (rev 9833)
@@ -96,6 +96,7 @@
private static final String HTTP_PREFIX = "http:";
+ @Deprecated
protected final static String SLASHED_RESOURCE_URI_PREFIX = "/" +
WebXml.RESOURCE_URI_PREFIX;
private File tmpRoot = null;
@@ -356,15 +357,13 @@
webConnection = new MockWebConnection(webClient) {
public WebResponse getResponse(WebRequestSettings settings)
throws IOException {
- String testResourceContextPath =
facesContext.getExternalContext().getRequestContextPath() +
- AbstractAjax4JsfTestCase.SLASHED_RESOURCE_URI_PREFIX;
- if (settings.getURL().getFile().startsWith(testResourceContextPath)) {
- String uri =
settings.getURL().getFile().substring(testResourceContextPath.length());
-
+ String resourceKey =
WebXml.getInstance(facesContext).getFacesResourceKey(settings.getURL().getFile().substring(
+ request.getContextPath().length()));
+ if (resourceKey != null) {
InternetResourceBuilder resourceBuilder = InternetResourceBuilder.getInstance();
- InternetResource resource = resourceBuilder.getResourceForKey(uri);
- Object resourceData = resourceBuilder.getResourceDataForKey(uri);
+ InternetResource resource = resourceBuilder.getResourceForKey(resourceKey);
+ Object resourceData = resourceBuilder.getResourceDataForKey(resourceKey);
final MockFacesResourceContext resourceContext = new
MockFacesResourceContext(facesContext);
resourceContext.setResourceData(resourceData);
Modified:
trunk/framework/test/src/test/java/org/ajax4jsf/resource/CSSTemplateTestCase.java
===================================================================
---
trunk/framework/test/src/test/java/org/ajax4jsf/resource/CSSTemplateTestCase.java 2008-07-30
16:26:35 UTC (rev 9832)
+++
trunk/framework/test/src/test/java/org/ajax4jsf/resource/CSSTemplateTestCase.java 2008-07-31
01:08:11 UTC (rev 9833)
@@ -156,9 +156,10 @@
String templatePath = "org/ajax4jsf/resource/styles.xml";
TemplateCSSResource resource = new TemplateCSSResource(templatePath);
// System.out.println(resource.getUri(facesContext,null));
- String expextedUri =
request.getContextPath()+"/"+WebXml.RESOURCE_URI_PREFIX+resource.getKey();
// System.out.println(expextedUri);
- assertTrue(resource.getUri(facesContext,null).startsWith(expextedUri));
+ String uri = resource.getUri(facesContext,null);
+ assertTrue(uri.startsWith(request.getContextPath()+"/"+WebXml.RESOURCE_URI_PREFIX));
+ assertTrue(uri.startsWith(request.getContextPath()+"/"+WebXml.SESSION_RESOURCE_URI_PREFIX_VERSIONED
+ resource.getKey()));
}
/*
Modified: trunk/framework/test/src/test/java/org/ajax4jsf/webapp/WebXmlTest.java
===================================================================
--- trunk/framework/test/src/test/java/org/ajax4jsf/webapp/WebXmlTest.java 2008-07-30
16:26:35 UTC (rev 9832)
+++ trunk/framework/test/src/test/java/org/ajax4jsf/webapp/WebXmlTest.java 2008-07-31
01:08:11 UTC (rev 9833)
@@ -26,7 +26,6 @@
import javax.servlet.ServletException;
import org.ajax4jsf.tests.AbstractAjax4JsfTestCase;
-import org.ajax4jsf.webapp.WebXml;
import org.apache.shale.test.mock.MockServletContext;
public class WebXmlTest extends AbstractAjax4JsfTestCase {
@@ -84,19 +83,111 @@
public void testGetInstance() {
}
+
+ public void testDefaultResourcePrefix() throws Exception {
+ WebXml webXml = new WebXml();
+ webXml.init(context,"ajax4jsf");
+ assertEquals('/' + WebXml.RESOURCE_URI_PREFIX_VERSIONED,
webXml.getResourcePrefix());
+ assertEquals('/' + WebXml.GLOBAL_RESOURCE_URI_PREFIX_VERSIONED,
webXml.getGlobalResourcePrefix());
+ assertEquals('/' + WebXml.SESSION_RESOURCE_URI_PREFIX_VERSIONED,
webXml.getSessionResourcePrefix());
+ }
+
+ public void testOverrideResourcePrefix() throws Exception {
+ context.addInitParameter(WebXml.RESOURCE_URI_PREFIX_PARAM, "rich-rsrc/");
+ WebXml webXml = new WebXml();
+ webXml.init(context,"ajax4jsf");
+
+ assertEquals("/rich-rsrc/", webXml.getResourcePrefix());
+ assertEquals(webXml.getResourcePrefix(), webXml.getGlobalResourcePrefix());
+ assertEquals(webXml.getResourcePrefix(), webXml.getSessionResourcePrefix());
+ }
+
+ public void testCustomizedResourcePrefixes() throws Exception {
+ context.addInitParameter(WebXml.SESSION_RESOURCE_URI_PREFIX_PARAM, "sess/");
+ context.addInitParameter(WebXml.GLOBAL_RESOURCE_URI_PREFIX_PARAM, "glb/");
+ WebXml webXml = new WebXml();
+ webXml.init(context,"ajax4jsf");
+
+ assertTrue(webXml.getResourcePrefix().startsWith("/a4j/"));
+ assertTrue(webXml.getGlobalResourcePrefix().startsWith("/glb/"));
+ assertTrue(webXml.getSessionResourcePrefix().startsWith("/sess/"));
+ }
+
+ public void testOverrideGlobalResourcePrefix() throws Exception {
+ context.addInitParameter(WebXml.RESOURCE_URI_PREFIX_PARAM, "j4a/");
+ context.addInitParameter(WebXml.GLOBAL_RESOURCE_URI_PREFIX_PARAM, "glb/");
+ WebXml webXml = new WebXml();
+ webXml.init(context,"ajax4jsf");
+
+ assertTrue(webXml.getResourcePrefix().startsWith("/j4a/"));
+ assertTrue(webXml.getGlobalResourcePrefix().startsWith("/glb/"));
+ assertEquals(webXml.getResourcePrefix(), webXml.getSessionResourcePrefix());
+ }
+
+ public void testOverrideSessionResourcePrefix() throws Exception {
+ context.addInitParameter(WebXml.RESOURCE_URI_PREFIX_PARAM, "j4a/");
+ context.addInitParameter(WebXml.SESSION_RESOURCE_URI_PREFIX_PARAM, "ssn/");
+ WebXml webXml = new WebXml();
+ webXml.init(context,"ajax4jsf");
+
+ assertTrue(webXml.getResourcePrefix().startsWith("/j4a/"));
+ assertTrue(webXml.getSessionResourcePrefix().startsWith("/ssn/"));
+ assertEquals(webXml.getResourcePrefix(), webXml.getGlobalResourcePrefix());
+ }
+
+ public void testOverrideAll() throws Exception {
+ context.addInitParameter(WebXml.RESOURCE_URI_PREFIX_PARAM, "j4a/");
+ context.addInitParameter(WebXml.GLOBAL_RESOURCE_URI_PREFIX_PARAM, "glb/");
+ context.addInitParameter(WebXml.SESSION_RESOURCE_URI_PREFIX_PARAM, "ssn/");
+ WebXml webXml = new WebXml();
+ webXml.init(context,"ajax4jsf");
+
+ assertTrue(webXml.getResourcePrefix().startsWith("/j4a/"));
+ assertTrue(webXml.getSessionResourcePrefix().startsWith("/ssn/"));
+ assertTrue(webXml.getGlobalResourcePrefix().startsWith("/glb/"));
+ }
+
/*
* Test method for 'org.ajax4jsf.webapp.WebXml.getFacesResourceURL(FacesContext,
String)'
*/
public void testGetFacesResourceURL() throws ServletException {
WebXml webXml = new WebXml();
webXml.init(context,"ajax4jsf");
- String resourceURL = webXml.getFacesResourceURL(facesContext,"foo.Bar");
+ String resourceURL = webXml.getFacesResourceURL(facesContext,"foo.Bar",
false);
System.out.println(resourceURL);
- assertEquals("/testContext/"+WebXml.RESOURCE_URI_PREFIX+"foo.Bar.jsf",resourceURL);
+ assertEquals("/testContext/"+WebXml.SESSION_RESOURCE_URI_PREFIX_VERSIONED+"foo.Bar.jsf",resourceURL);
+ resourceURL = webXml.getFacesResourceURL(facesContext,"rich.Tree", true);
+ System.out.println(resourceURL);
+ assertEquals("/testContext/"+WebXml.GLOBAL_RESOURCE_URI_PREFIX_VERSIONED+"rich.Tree.jsf",resourceURL);
}
+ public void testOverridenLegacyGetFacesResourceURL() throws ServletException {
+ context.addInitParameter(WebXml.RESOURCE_URI_PREFIX_PARAM, "j4a/");
+
+ WebXml webXml = new WebXml();
+ webXml.init(context,"ajax4jsf");
+ String resourceURL = webXml.getFacesResourceURL(facesContext,"foo.Bar",
false);
+ assertEquals("/testContext/j4a/foo.Bar.jsf",resourceURL);
+
+ resourceURL = webXml.getFacesResourceURL(facesContext,"rich.Tree", true);
+ assertEquals("/testContext/j4a/rich.Tree.jsf",resourceURL);
+ }
+
+ public void testOverridenGetFacesResourceURL() throws ServletException {
+ context.addInitParameter(WebXml.GLOBAL_RESOURCE_URI_PREFIX_PARAM, "glb/");
+ context.addInitParameter(WebXml.SESSION_RESOURCE_URI_PREFIX_PARAM, "ssn/");
+
+ WebXml webXml = new WebXml();
+ webXml.init(context,"ajax4jsf");
+ String resourceURL = webXml.getFacesResourceURL(facesContext,"foo.Bar",
false);
+ assertEquals("/testContext/ssn/foo.Bar.jsf",resourceURL);
+
+ resourceURL = webXml.getFacesResourceURL(facesContext,"rich.Tree", true);
+ assertEquals("/testContext/glb/rich.Tree.jsf",resourceURL);
+ }
+
/*
* Test method for
'org.ajax4jsf.webapp.WebXml.getFacesResourceKey(HttpServletRequest)'
*/