SWF-1375 Add <faces:resources /> element, JsfFlowHandlerAdapter, and provide useful error message when FacesContext is null.
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
package org.springframework.faces.config;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.faces.webflow.JsfResourceRequestHandler;
|
||||
import org.springframework.web.servlet.handler.SimpleUrlHandlerMapping;
|
||||
import org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter;
|
||||
|
||||
public class ResourcesBeanDefinitionParserTests extends TestCase {
|
||||
|
||||
private ClassPathXmlApplicationContext context;
|
||||
|
||||
public void setUp() throws Exception {
|
||||
context = new ClassPathXmlApplicationContext("org/springframework/faces/config/resources.xml");
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
}
|
||||
|
||||
public void testConfigureDefaults() {
|
||||
Map map = context.getBeansOfType(HttpRequestHandlerAdapter.class);
|
||||
assertEquals(1, map.values().size());
|
||||
|
||||
Object resourceHandler = context.getBean(ResourcesBeanDefinitionParser.RESOURCE_HANDLER_BEAN_NAME);
|
||||
assertNotNull(resourceHandler);
|
||||
assertTrue(resourceHandler instanceof JsfResourceRequestHandler);
|
||||
|
||||
map = context.getBeansOfType(SimpleUrlHandlerMapping.class);
|
||||
assertEquals(1, map.values().size());
|
||||
SimpleUrlHandlerMapping handlerMapping = (SimpleUrlHandlerMapping) map.values().iterator().next();
|
||||
assertEquals(ResourcesBeanDefinitionParser.RESOURCE_HANDLER_BEAN_NAME, handlerMapping.getUrlMap().get(
|
||||
"/javax.faces.resource/**"));
|
||||
assertEquals(0, handlerMapping.getOrder());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:faces="http://www.springframework.org/schema/faces"
|
||||
xsi:schemaLocation="
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
|
||||
http://www.springframework.org/schema/faces http://www.springframework.org/schema/faces/spring-faces-2.0.xsd">
|
||||
|
||||
<faces:resources />
|
||||
|
||||
</beans>
|
||||
@@ -0,0 +1,47 @@
|
||||
package org.springframework.faces.webflow;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.js.ajax.AjaxHandler;
|
||||
import org.springframework.js.ajax.SpringJavascriptAjaxHandler;
|
||||
import org.springframework.webflow.context.ExternalContext;
|
||||
import org.springframework.webflow.core.FlowException;
|
||||
import org.springframework.webflow.core.collection.MutableAttributeMap;
|
||||
import org.springframework.webflow.executor.FlowExecutionResult;
|
||||
import org.springframework.webflow.executor.FlowExecutor;
|
||||
|
||||
public class JsfFlowHandlerAdapterTests extends TestCase {
|
||||
|
||||
private JsfFlowHandlerAdapter handlerAdapter;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
handlerAdapter = new JsfFlowHandlerAdapter();
|
||||
handlerAdapter.setFlowExecutor(new StubFlowExecutor());
|
||||
}
|
||||
|
||||
public void testAjaxHandlerNotProvided() throws Exception {
|
||||
handlerAdapter.afterPropertiesSet();
|
||||
assertNotNull(handlerAdapter.getAjaxHandler());
|
||||
assertTrue(handlerAdapter.getAjaxHandler() instanceof JsfAjaxHandler);
|
||||
}
|
||||
|
||||
public void testAjaxHandlerProvided() throws Exception {
|
||||
AjaxHandler myAjaxHandler = new SpringJavascriptAjaxHandler();
|
||||
handlerAdapter.setAjaxHandler(myAjaxHandler);
|
||||
handlerAdapter.afterPropertiesSet();
|
||||
assertTrue(myAjaxHandler == handlerAdapter.getAjaxHandler());
|
||||
}
|
||||
|
||||
private final class StubFlowExecutor implements FlowExecutor {
|
||||
public FlowExecutionResult resumeExecution(String flowExecutionKey, ExternalContext context)
|
||||
throws FlowException {
|
||||
throw new UnsupportedOperationException("Not expected");
|
||||
}
|
||||
|
||||
public FlowExecutionResult launchExecution(String flowId, MutableAttributeMap input, ExternalContext context)
|
||||
throws FlowException {
|
||||
throw new UnsupportedOperationException("Not expected");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user