Upgrade spring-faces to JSF 2 as a minimum requirement
* Rework all state handling, removed FlowSerializedView class and save state as opaque object * Use FacesWrapper classes instead of custom delegates * Deprecate isAtLeastJSFXXX() methods and removed all internal use * Remove all Jsf2XXX versions of classes * Refactor all calls to deprecated JSF methods * Removed older VariableResolver and PropertyResolver classes * Deprecate Jsf2FlowResourceResolver and log warning if used * Create new FlowELResolver to replace removed VariableResolvers and PropertyResolvers * Update faces-config.xml to use newer xsd * Significantly rework FlowFacesContext to remove the message delegate and generally improve the code * Added "provided" dependency to MyFaces and fixed partial state saving on MyFaces * Fixed FlowResourceResolver to delegate to both MyFaces or Mojarra depending on availability * Add JsfUtils.findFactory method and rework existing code to replace FactoryFinder calls and casts * Refactor JsfViewFactory to improve code readability * Rename FlowViewStateManager and FlowViewResponseStateManager to FlowStateManager and FlowResponseStateManager * Ensure ResponseContextHolder is reset after each test * Update JSF portlet support to function with JSF 2.0 Issue: SWF-1536, SWF-1540, SWF-1550
This commit is contained in:
committed by
Rossen Stoyanchev
parent
7e03970fbf
commit
706490c4dc
@@ -26,52 +26,52 @@ public class FacesFlowBuilderServicesBeanDefinitionParserTests extends TestCase
|
||||
|
||||
private ClassPathXmlApplicationContext context;
|
||||
private FlowBuilderServices builderServices;
|
||||
private JSFMockHelper jsf = new JSFMockHelper();
|
||||
private final JSFMockHelper jsf = new JSFMockHelper();
|
||||
|
||||
public void setUp() throws Exception {
|
||||
jsf.setUp();
|
||||
context = new ClassPathXmlApplicationContext("org/springframework/faces/config/flow-builder-services.xml");
|
||||
this.jsf.setUp();
|
||||
this.context = new ClassPathXmlApplicationContext("org/springframework/faces/config/flow-builder-services.xml");
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
jsf.tearDown();
|
||||
this.jsf.tearDown();
|
||||
}
|
||||
|
||||
public void testConfigureDefaults() {
|
||||
builderServices = (FlowBuilderServices) context.getBean("flowBuilderServicesDefault");
|
||||
assertNotNull(builderServices);
|
||||
assertTrue(builderServices.getExpressionParser() instanceof SpringELExpressionParser);
|
||||
assertTrue(builderServices.getViewFactoryCreator() instanceof JsfViewFactoryCreator);
|
||||
assertTrue(builderServices.getConversionService() instanceof FacesConversionService);
|
||||
assertFalse(builderServices.getDevelopment());
|
||||
this.builderServices = (FlowBuilderServices) this.context.getBean("flowBuilderServicesDefault");
|
||||
assertNotNull(this.builderServices);
|
||||
assertTrue(this.builderServices.getExpressionParser() instanceof SpringELExpressionParser);
|
||||
assertTrue(this.builderServices.getViewFactoryCreator() instanceof JsfViewFactoryCreator);
|
||||
assertTrue(this.builderServices.getConversionService() instanceof FacesConversionService);
|
||||
assertFalse(this.builderServices.getDevelopment());
|
||||
}
|
||||
|
||||
public void testEnableManagedBeans() {
|
||||
builderServices = (FlowBuilderServices) context.getBean("flowBuilderServicesLegacy");
|
||||
assertNotNull(builderServices);
|
||||
assertTrue(builderServices.getExpressionParser() instanceof FacesSpringELExpressionParser);
|
||||
assertTrue(builderServices.getViewFactoryCreator() instanceof JsfViewFactoryCreator);
|
||||
assertTrue(builderServices.getConversionService() instanceof FacesConversionService);
|
||||
assertFalse(builderServices.getDevelopment());
|
||||
this.builderServices = (FlowBuilderServices) this.context.getBean("flowBuilderServicesLegacy");
|
||||
assertNotNull(this.builderServices);
|
||||
assertTrue(this.builderServices.getExpressionParser() instanceof FacesSpringELExpressionParser);
|
||||
assertTrue(this.builderServices.getViewFactoryCreator() instanceof JsfViewFactoryCreator);
|
||||
assertTrue(this.builderServices.getConversionService() instanceof FacesConversionService);
|
||||
assertFalse(this.builderServices.getDevelopment());
|
||||
}
|
||||
|
||||
public void testFlowBuilderServicesAllCustomized() {
|
||||
builderServices = (FlowBuilderServices) context.getBean("flowBuilderServicesAllCustom");
|
||||
assertNotNull(builderServices);
|
||||
assertTrue(builderServices.getExpressionParser() instanceof WebFlowSpringELExpressionParser);
|
||||
assertTrue(builderServices.getViewFactoryCreator() instanceof TestViewFactoryCreator);
|
||||
assertTrue(builderServices.getConversionService() instanceof TestConversionService);
|
||||
assertTrue(builderServices.getDevelopment());
|
||||
this.builderServices = (FlowBuilderServices) this.context.getBean("flowBuilderServicesAllCustom");
|
||||
assertNotNull(this.builderServices);
|
||||
assertTrue(this.builderServices.getExpressionParser() instanceof WebFlowSpringELExpressionParser);
|
||||
assertTrue(this.builderServices.getViewFactoryCreator() instanceof TestViewFactoryCreator);
|
||||
assertTrue(this.builderServices.getConversionService() instanceof TestConversionService);
|
||||
assertTrue(this.builderServices.getDevelopment());
|
||||
}
|
||||
|
||||
public void testFlowBuilderServicesConversionServiceCustomized() {
|
||||
builderServices = (FlowBuilderServices) context.getBean("flowBuilderServicesConversionServiceCustom");
|
||||
assertNotNull(builderServices);
|
||||
assertTrue(builderServices.getConversionService() instanceof TestConversionService);
|
||||
assertTrue(builderServices.getExpressionParser() instanceof WebFlowSpringELExpressionParser);
|
||||
assertTrue(((SpringELExpressionParser) builderServices.getExpressionParser()).getConversionService() instanceof TestConversionService);
|
||||
assertTrue(builderServices.getViewFactoryCreator() instanceof JsfViewFactoryCreator);
|
||||
assertFalse(builderServices.getDevelopment());
|
||||
this.builderServices = (FlowBuilderServices) this.context.getBean("flowBuilderServicesConversionServiceCustom");
|
||||
assertNotNull(this.builderServices);
|
||||
assertTrue(this.builderServices.getConversionService() instanceof TestConversionService);
|
||||
assertTrue(this.builderServices.getExpressionParser() instanceof WebFlowSpringELExpressionParser);
|
||||
assertTrue(((SpringELExpressionParser) this.builderServices.getExpressionParser()).getConversionService() instanceof TestConversionService);
|
||||
assertTrue(this.builderServices.getViewFactoryCreator() instanceof JsfViewFactoryCreator);
|
||||
assertFalse(this.builderServices.getDevelopment());
|
||||
}
|
||||
|
||||
public static class TestViewFactoryCreator implements ViewFactoryCreator {
|
||||
|
||||
@@ -14,21 +14,21 @@ public class ResourcesBeanDefinitionParserTests extends TestCase {
|
||||
private ClassPathXmlApplicationContext context;
|
||||
|
||||
public void setUp() throws Exception {
|
||||
context = new ClassPathXmlApplicationContext("org/springframework/faces/config/resources.xml");
|
||||
this.context = new ClassPathXmlApplicationContext("org/springframework/faces/config/resources.xml");
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
}
|
||||
|
||||
public void testConfigureDefaults() {
|
||||
Map<String, ?> map = context.getBeansOfType(HttpRequestHandlerAdapter.class);
|
||||
Map<String, ?> map = this.context.getBeansOfType(HttpRequestHandlerAdapter.class);
|
||||
assertEquals(1, map.values().size());
|
||||
|
||||
Object resourceHandler = context.getBean(ResourcesBeanDefinitionParser.RESOURCE_HANDLER_BEAN_NAME);
|
||||
Object resourceHandler = this.context.getBean(ResourcesBeanDefinitionParser.RESOURCE_HANDLER_BEAN_NAME);
|
||||
assertNotNull(resourceHandler);
|
||||
assertTrue(resourceHandler instanceof JsfResourceRequestHandler);
|
||||
|
||||
map = context.getBeansOfType(SimpleUrlHandlerMapping.class);
|
||||
map = this.context.getBeansOfType(SimpleUrlHandlerMapping.class);
|
||||
assertEquals(1, map.values().size());
|
||||
SimpleUrlHandlerMapping handlerMapping = (SimpleUrlHandlerMapping) map.values().iterator().next();
|
||||
assertEquals(ResourcesBeanDefinitionParser.RESOURCE_HANDLER_BEAN_NAME,
|
||||
|
||||
@@ -26,7 +26,7 @@ public class SelectionTrackingActionListenerTests extends TestCase {
|
||||
/**
|
||||
* JSF Mock Helper
|
||||
*/
|
||||
private JSFMockHelper jsfMockHelper = new JSFMockHelper();
|
||||
private final JSFMockHelper jsfMockHelper = new JSFMockHelper();
|
||||
|
||||
/**
|
||||
* The JSF view to simulate
|
||||
@@ -41,58 +41,58 @@ public class SelectionTrackingActionListenerTests extends TestCase {
|
||||
/**
|
||||
* The delegate action listener that should be called
|
||||
*/
|
||||
private TestDelegateActionListener delegateListener = new TestDelegateActionListener();
|
||||
private final TestDelegateActionListener delegateListener = new TestDelegateActionListener();
|
||||
|
||||
/**
|
||||
* The class under test
|
||||
*/
|
||||
private ActionListener selectionTrackingListener = new SelectionTrackingActionListener(delegateListener);
|
||||
private final ActionListener selectionTrackingListener = new SelectionTrackingActionListener(this.delegateListener);
|
||||
|
||||
public void setUp() throws Exception {
|
||||
jsfMockHelper.setUp();
|
||||
viewToTest = new UIViewRoot();
|
||||
this.jsfMockHelper.setUp();
|
||||
this.viewToTest = new UIViewRoot();
|
||||
List<Object> rows = new ArrayList<Object>();
|
||||
rows.add(new TestRowData());
|
||||
rows.add(new TestRowData());
|
||||
rows.add(new TestRowData());
|
||||
dataModel = new OneSelectionTrackingListDataModel<Object>(rows);
|
||||
this.dataModel = new OneSelectionTrackingListDataModel<Object>(rows);
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
jsfMockHelper.tearDown();
|
||||
this.jsfMockHelper.tearDown();
|
||||
}
|
||||
|
||||
public void testProcessActionWithUIData() {
|
||||
|
||||
UIData dataTable = new UIData();
|
||||
dataTable.setValue(dataModel);
|
||||
dataTable.setValue(this.dataModel);
|
||||
UIColumn column = new UIColumn();
|
||||
UICommand commandButton = new UICommand();
|
||||
column.getChildren().add(commandButton);
|
||||
dataTable.getChildren().add(column);
|
||||
viewToTest.getChildren().add(dataTable);
|
||||
this.viewToTest.getChildren().add(dataTable);
|
||||
dataTable.setRowIndex(1);
|
||||
|
||||
ActionEvent event = new ActionEvent(commandButton);
|
||||
|
||||
selectionTrackingListener.processAction(event);
|
||||
this.selectionTrackingListener.processAction(event);
|
||||
|
||||
assertTrue(dataModel.isCurrentRowSelected());
|
||||
assertSame(dataModel.getSelectedRow(), dataModel.getRowData());
|
||||
assertTrue(delegateListener.processedEvent);
|
||||
assertTrue(this.dataModel.isCurrentRowSelected());
|
||||
assertSame(this.dataModel.getSelectedRow(), this.dataModel.getRowData());
|
||||
assertTrue(this.delegateListener.processedEvent);
|
||||
|
||||
dataModel.setRowIndex(2);
|
||||
assertFalse(dataModel.isCurrentRowSelected());
|
||||
assertTrue(dataModel.getSelectedRow() != dataModel.getRowData());
|
||||
this.dataModel.setRowIndex(2);
|
||||
assertFalse(this.dataModel.isCurrentRowSelected());
|
||||
assertTrue(this.dataModel.getSelectedRow() != this.dataModel.getRowData());
|
||||
}
|
||||
|
||||
public void testProcessActionWithUIRepeat() {
|
||||
|
||||
UIRepeat uiRepeat = new UIRepeat();
|
||||
uiRepeat.setValue(dataModel);
|
||||
uiRepeat.setValue(this.dataModel);
|
||||
UICommand commandButton = new UICommand();
|
||||
uiRepeat.getChildren().add(commandButton);
|
||||
viewToTest.getChildren().add(uiRepeat);
|
||||
this.viewToTest.getChildren().add(uiRepeat);
|
||||
|
||||
Method indexMutator = ReflectionUtils.findMethod(UIRepeat.class, "setIndex", new Class[] { FacesContext.class,
|
||||
int.class });
|
||||
@@ -102,15 +102,15 @@ public class SelectionTrackingActionListenerTests extends TestCase {
|
||||
|
||||
ActionEvent event = new ActionEvent(commandButton);
|
||||
|
||||
selectionTrackingListener.processAction(event);
|
||||
this.selectionTrackingListener.processAction(event);
|
||||
|
||||
assertTrue(dataModel.isCurrentRowSelected());
|
||||
assertSame(dataModel.getSelectedRow(), dataModel.getRowData());
|
||||
assertTrue(delegateListener.processedEvent);
|
||||
assertTrue(this.dataModel.isCurrentRowSelected());
|
||||
assertSame(this.dataModel.getSelectedRow(), this.dataModel.getRowData());
|
||||
assertTrue(this.delegateListener.processedEvent);
|
||||
|
||||
ReflectionUtils.invokeMethod(indexMutator, uiRepeat, new Object[] { new MockFacesContext(), 2 });
|
||||
assertFalse(dataModel.isCurrentRowSelected());
|
||||
assertTrue(dataModel.getSelectedRow() != dataModel.getRowData());
|
||||
assertFalse(this.dataModel.isCurrentRowSelected());
|
||||
assertTrue(this.dataModel.getSelectedRow() != this.dataModel.getRowData());
|
||||
}
|
||||
|
||||
private class TestRowData {
|
||||
@@ -122,7 +122,7 @@ public class SelectionTrackingActionListenerTests extends TestCase {
|
||||
public boolean processedEvent = false;
|
||||
|
||||
public void processAction(ActionEvent event) throws AbortProcessingException {
|
||||
processedEvent = true;
|
||||
this.processedEvent = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ public class DataModelConverterTests extends TestCase {
|
||||
public void testConvertListToDataModel() throws Exception {
|
||||
List<Object> sourceList = new ArrayList<Object>();
|
||||
|
||||
DataModel<Object> resultModel = (DataModel<Object>) converter.convertSourceToTargetClass(sourceList,
|
||||
DataModel<Object> resultModel = (DataModel<Object>) this.converter.convertSourceToTargetClass(sourceList,
|
||||
DataModel.class);
|
||||
|
||||
assertNotNull(resultModel);
|
||||
@@ -31,7 +31,7 @@ public class DataModelConverterTests extends TestCase {
|
||||
public void testConvertListToListDataModel() throws Exception {
|
||||
List<Object> sourceList = new ArrayList<Object>();
|
||||
|
||||
DataModel<Object> resultModel = (DataModel<Object>) converter.convertSourceToTargetClass(sourceList,
|
||||
DataModel<Object> resultModel = (DataModel<Object>) this.converter.convertSourceToTargetClass(sourceList,
|
||||
ListDataModel.class);
|
||||
|
||||
assertNotNull(resultModel);
|
||||
@@ -42,7 +42,7 @@ public class DataModelConverterTests extends TestCase {
|
||||
public void testConvertListToSerializableListDataModel() throws Exception {
|
||||
List<Object> sourceList = new ArrayList<Object>();
|
||||
|
||||
DataModel<Object> resultModel = (DataModel<Object>) converter.convertSourceToTargetClass(sourceList,
|
||||
DataModel<Object> resultModel = (DataModel<Object>) this.converter.convertSourceToTargetClass(sourceList,
|
||||
SerializableListDataModel.class);
|
||||
|
||||
assertNotNull(resultModel);
|
||||
@@ -54,7 +54,7 @@ public class DataModelConverterTests extends TestCase {
|
||||
public void testConvertListToSerializableListDataModelNullSource() throws Exception {
|
||||
List<Object> sourceList = null;
|
||||
|
||||
DataModel<Object> resultModel = (DataModel<Object>) converter.convertSourceToTargetClass(sourceList,
|
||||
DataModel<Object> resultModel = (DataModel<Object>) this.converter.convertSourceToTargetClass(sourceList,
|
||||
SerializableListDataModel.class);
|
||||
|
||||
assertNotNull(resultModel);
|
||||
|
||||
@@ -13,11 +13,11 @@ public class FacesConversionServiceTests extends TestCase {
|
||||
private FacesConversionService service;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
service = new FacesConversionService();
|
||||
this.service = new FacesConversionService();
|
||||
}
|
||||
|
||||
public void testGetAbstractType() {
|
||||
ConversionExecutor executor = service.getConversionExecutor(List.class, DataModel.class);
|
||||
ConversionExecutor executor = this.service.getConversionExecutor(List.class, DataModel.class);
|
||||
ArrayList<Object> list = new ArrayList<Object>();
|
||||
list.add("foo");
|
||||
executor.execute(list);
|
||||
|
||||
@@ -21,30 +21,30 @@ public class JsfViewTests extends TestCase {
|
||||
|
||||
UrlBasedViewResolver resolver;
|
||||
|
||||
private JSFMockHelper jsfMock = new JSFMockHelper();
|
||||
private final JSFMockHelper jsfMock = new JSFMockHelper();
|
||||
|
||||
public void setUp() throws Exception {
|
||||
jsfMock.setUp();
|
||||
jsfMock.facesContext().getApplication().setViewHandler(new ResourceCheckingViewHandler());
|
||||
this.jsfMock.setUp();
|
||||
this.jsfMock.facesContext().getApplication().setViewHandler(new ResourceCheckingViewHandler());
|
||||
|
||||
resolver = new UrlBasedViewResolver();
|
||||
resolver.setPrefix("/WEB-INF/views/");
|
||||
resolver.setSuffix(".xhtml");
|
||||
resolver.setViewClass(JsfView.class);
|
||||
resolver.setApplicationContext(new StaticWebApplicationContext());
|
||||
this.resolver = new UrlBasedViewResolver();
|
||||
this.resolver.setPrefix("/WEB-INF/views/");
|
||||
this.resolver.setSuffix(".xhtml");
|
||||
this.resolver.setViewClass(JsfView.class);
|
||||
this.resolver.setApplicationContext(new StaticWebApplicationContext());
|
||||
}
|
||||
|
||||
public void tearDown() throws Exception {
|
||||
jsfMock.tearDown();
|
||||
this.jsfMock.tearDown();
|
||||
}
|
||||
|
||||
public void testViewResolution() throws Exception {
|
||||
View view = resolver.resolveViewName("intro", new Locale("EN"));
|
||||
View view = this.resolver.resolveViewName("intro", new Locale("EN"));
|
||||
assertTrue(view instanceof JsfView);
|
||||
}
|
||||
|
||||
public void testViewRender() throws Exception {
|
||||
JsfView view = (JsfView) resolver.resolveViewName("intro", new Locale("EN"));
|
||||
JsfView view = (JsfView) this.resolver.resolveViewName("intro", new Locale("EN"));
|
||||
view.setApplicationContext(new StaticWebApplicationContext());
|
||||
view.setServletContext(new MockServletContext());
|
||||
view.render(new HashMap<String, Object>(), new MockHttpServletRequest(), new MockHttpServletResponse());
|
||||
|
||||
@@ -22,16 +22,16 @@ public class AjaxViewRootTests extends TestCase {
|
||||
|
||||
UIViewRoot testTree = new UIViewRoot();
|
||||
|
||||
private StringWriter output = new StringWriter();
|
||||
private final StringWriter output = new StringWriter();
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
jsf.setUp();
|
||||
jsf.facesContext().getApplication().setViewHandler(new MockViewHandler());
|
||||
jsf.facesContext().setResponseWriter(new MockResponseWriter(output, null, null));
|
||||
this.jsf.setUp();
|
||||
this.jsf.facesContext().getApplication().setViewHandler(new MockViewHandler());
|
||||
this.jsf.facesContext().setResponseWriter(new MockResponseWriter(this.output, null, null));
|
||||
|
||||
UIForm form = new UIForm();
|
||||
form.setId("foo");
|
||||
testTree.getChildren().add(form);
|
||||
this.testTree.getChildren().add(form);
|
||||
UIPanel panel = new UIPanel();
|
||||
panel.setId("bar");
|
||||
form.getChildren().add(panel);
|
||||
@@ -39,31 +39,31 @@ public class AjaxViewRootTests extends TestCase {
|
||||
command.setId("baz");
|
||||
panel.getChildren().add(command);
|
||||
|
||||
testTree.setRenderKitId(RenderKitFactory.HTML_BASIC_RENDER_KIT);
|
||||
this.testTree.setRenderKitId(RenderKitFactory.HTML_BASIC_RENDER_KIT);
|
||||
|
||||
jsf.facesContext().setViewRoot(testTree);
|
||||
this.jsf.facesContext().setViewRoot(this.testTree);
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
jsf.tearDown();
|
||||
this.jsf.tearDown();
|
||||
}
|
||||
|
||||
public void testProcessDecodes() {
|
||||
jsf.externalContext().getRequestParameterMap().put("processIds", "foo:bar, foo:baz");
|
||||
this.jsf.externalContext().getRequestParameterMap().put("processIds", "foo:bar, foo:baz");
|
||||
|
||||
AjaxViewRoot ajaxRoot = new AjaxViewRoot(testTree);
|
||||
AjaxViewRoot ajaxRoot = new AjaxViewRoot(this.testTree);
|
||||
|
||||
ajaxRoot.processDecodes(jsf.facesContext());
|
||||
ajaxRoot.processDecodes(this.jsf.facesContext());
|
||||
|
||||
assertEquals(1, ajaxRoot.getProcessIds().length);
|
||||
}
|
||||
|
||||
public void testEncodeAll_NoRenderIds() throws IOException {
|
||||
jsf.externalContext().getRequestParameterMap().put("processIds", "foo:bar, foo:baz");
|
||||
this.jsf.externalContext().getRequestParameterMap().put("processIds", "foo:bar, foo:baz");
|
||||
|
||||
AjaxViewRoot ajaxRoot = new AjaxViewRoot(testTree);
|
||||
AjaxViewRoot ajaxRoot = new AjaxViewRoot(this.testTree);
|
||||
|
||||
ajaxRoot.encodeAll(jsf.facesContext());
|
||||
ajaxRoot.encodeAll(this.jsf.facesContext());
|
||||
|
||||
assertEquals(1, ajaxRoot.getProcessIds().length);
|
||||
assertEquals(1, ajaxRoot.getRenderIds().length);
|
||||
@@ -73,14 +73,14 @@ public class AjaxViewRootTests extends TestCase {
|
||||
|
||||
public void testEncodeAll_RenderIdsExpr() throws IOException {
|
||||
|
||||
jsf.externalContext()
|
||||
this.jsf.externalContext()
|
||||
.getRequestMap()
|
||||
.put(View.RENDER_FRAGMENTS_ATTRIBUTE,
|
||||
StringUtils.delimitedListToStringArray("foo:bar,foo:baz", ",", " "));
|
||||
|
||||
AjaxViewRoot ajaxRoot = new AjaxViewRoot(testTree);
|
||||
AjaxViewRoot ajaxRoot = new AjaxViewRoot(this.testTree);
|
||||
|
||||
ajaxRoot.encodeAll(jsf.facesContext());
|
||||
ajaxRoot.encodeAll(this.jsf.facesContext());
|
||||
|
||||
assertEquals(1, ajaxRoot.getRenderIds().length);
|
||||
|
||||
|
||||
@@ -14,11 +14,11 @@ public class ProgressiveCommandLinkRendererTests extends TestCase {
|
||||
ProgressiveCommandLinkRenderer renderer = new ProgressiveCommandLinkRenderer();
|
||||
|
||||
public void setUp() throws Exception {
|
||||
jsf.setUp();
|
||||
this.jsf.setUp();
|
||||
}
|
||||
|
||||
public void tearDown() throws Exception {
|
||||
jsf.tearDown();
|
||||
this.jsf.tearDown();
|
||||
}
|
||||
|
||||
public void testRenderOnClick_AjaxEnabled_NoParams() throws Exception {
|
||||
@@ -31,15 +31,15 @@ public class ProgressiveCommandLinkRendererTests extends TestCase {
|
||||
link.setId("foo");
|
||||
form.getChildren().add(link);
|
||||
|
||||
RenderAttributeCallback callback = renderer.getAttributeCallbacks(link).get("onclick");
|
||||
RenderAttributeCallback callback = this.renderer.getAttributeCallbacks(link).get("onclick");
|
||||
|
||||
jsf.facesContext().getResponseWriter().startElement("a", link);
|
||||
this.jsf.facesContext().getResponseWriter().startElement("a", link);
|
||||
|
||||
callback.doRender(jsf.facesContext(), jsf.facesContext().getResponseWriter(), link, "onclick", null, "onclick");
|
||||
callback.doRender(this.jsf.facesContext(), this.jsf.facesContext().getResponseWriter(), link, "onclick", null, "onclick");
|
||||
|
||||
jsf.facesContext().getResponseWriter().endElement("a");
|
||||
this.jsf.facesContext().getResponseWriter().endElement("a");
|
||||
|
||||
assertEquals(expected, jsf.contentAsString());
|
||||
assertEquals(expected, this.jsf.contentAsString());
|
||||
}
|
||||
|
||||
public void testRenderOnClick_AjaxEnabled_WithParams() throws Exception {
|
||||
@@ -61,15 +61,15 @@ public class ProgressiveCommandLinkRendererTests extends TestCase {
|
||||
link.getChildren().add(param1);
|
||||
link.getChildren().add(param2);
|
||||
|
||||
RenderAttributeCallback callback = renderer.getAttributeCallbacks(link).get("onclick");
|
||||
RenderAttributeCallback callback = this.renderer.getAttributeCallbacks(link).get("onclick");
|
||||
|
||||
jsf.facesContext().getResponseWriter().startElement("a", link);
|
||||
this.jsf.facesContext().getResponseWriter().startElement("a", link);
|
||||
|
||||
callback.doRender(jsf.facesContext(), jsf.facesContext().getResponseWriter(), link, "onclick", null, "onclick");
|
||||
callback.doRender(this.jsf.facesContext(), this.jsf.facesContext().getResponseWriter(), link, "onclick", null, "onclick");
|
||||
|
||||
jsf.facesContext().getResponseWriter().endElement("a");
|
||||
this.jsf.facesContext().getResponseWriter().endElement("a");
|
||||
|
||||
assertEquals(expected, jsf.contentAsString());
|
||||
assertEquals(expected, this.jsf.contentAsString());
|
||||
}
|
||||
|
||||
public void testRenderOnClick_AjaxDisabled_NoParams() throws Exception {
|
||||
@@ -82,15 +82,15 @@ public class ProgressiveCommandLinkRendererTests extends TestCase {
|
||||
link.setAjaxEnabled(false);
|
||||
form.getChildren().add(link);
|
||||
|
||||
RenderAttributeCallback callback = renderer.getAttributeCallbacks(link).get("onclick");
|
||||
RenderAttributeCallback callback = this.renderer.getAttributeCallbacks(link).get("onclick");
|
||||
|
||||
jsf.facesContext().getResponseWriter().startElement("a", link);
|
||||
this.jsf.facesContext().getResponseWriter().startElement("a", link);
|
||||
|
||||
callback.doRender(jsf.facesContext(), jsf.facesContext().getResponseWriter(), link, "onclick", null, "onclick");
|
||||
callback.doRender(this.jsf.facesContext(), this.jsf.facesContext().getResponseWriter(), link, "onclick", null, "onclick");
|
||||
|
||||
jsf.facesContext().getResponseWriter().endElement("a");
|
||||
this.jsf.facesContext().getResponseWriter().endElement("a");
|
||||
|
||||
assertEquals(expected, jsf.contentAsString());
|
||||
assertEquals(expected, this.jsf.contentAsString());
|
||||
}
|
||||
|
||||
public void testRenderOnClick_AjaxDisabled_WithParams() throws Exception {
|
||||
@@ -113,14 +113,14 @@ public class ProgressiveCommandLinkRendererTests extends TestCase {
|
||||
link.getChildren().add(param1);
|
||||
link.getChildren().add(param2);
|
||||
|
||||
RenderAttributeCallback callback = renderer.getAttributeCallbacks(link).get("onclick");
|
||||
RenderAttributeCallback callback = this.renderer.getAttributeCallbacks(link).get("onclick");
|
||||
|
||||
jsf.facesContext().getResponseWriter().startElement("a", link);
|
||||
this.jsf.facesContext().getResponseWriter().startElement("a", link);
|
||||
|
||||
callback.doRender(jsf.facesContext(), jsf.facesContext().getResponseWriter(), link, "onclick", null, "onclick");
|
||||
callback.doRender(this.jsf.facesContext(), this.jsf.facesContext().getResponseWriter(), link, "onclick", null, "onclick");
|
||||
|
||||
jsf.facesContext().getResponseWriter().endElement("a");
|
||||
this.jsf.facesContext().getResponseWriter().endElement("a");
|
||||
|
||||
assertEquals(expected, jsf.contentAsString());
|
||||
assertEquals(expected, this.jsf.contentAsString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,8 +10,7 @@ public class TestConverter implements Converter {
|
||||
}
|
||||
|
||||
public Object getAsObject(FacesContext context, UIComponent component, String value) {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Auto-generated method stub");
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public String getAsString(FacesContext context, UIComponent component, Object value) {
|
||||
|
||||
@@ -15,13 +15,13 @@ public class FlowResourceHelperTests extends TestCase {
|
||||
JSFMockHelper jsf = new JSFMockHelper();
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
jsf.setUp();
|
||||
this.jsf.setUp();
|
||||
// TODO figure out how to set the context path
|
||||
jsf.facesContext().setResponseWriter(new MockResponseWriter(writer, "text/html", "UTF-8"));
|
||||
this.jsf.facesContext().setResponseWriter(new MockResponseWriter(this.writer, "text/html", "UTF-8"));
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
jsf.tearDown();
|
||||
this.jsf.tearDown();
|
||||
}
|
||||
|
||||
public final void testRenderScriptLink() throws IOException {
|
||||
@@ -29,12 +29,12 @@ public class FlowResourceHelperTests extends TestCase {
|
||||
String scriptPath = "/dojo/dojo.js";
|
||||
String expectedUrl = "null/resources/dojo/dojo.js";
|
||||
|
||||
ResourceHelper.renderScriptLink(jsf.facesContext(), scriptPath);
|
||||
ResourceHelper.renderScriptLink(jsf.facesContext(), scriptPath);
|
||||
ResourceHelper.renderScriptLink(this.jsf.facesContext(), scriptPath);
|
||||
ResourceHelper.renderScriptLink(this.jsf.facesContext(), scriptPath);
|
||||
|
||||
String expectedOutput = "<script type=\"text/javascript\" src=\"" + expectedUrl + "\"/>";
|
||||
|
||||
assertEquals(expectedOutput, writer.toString());
|
||||
assertEquals(expectedOutput, this.writer.toString());
|
||||
|
||||
}
|
||||
|
||||
@@ -43,11 +43,11 @@ public class FlowResourceHelperTests extends TestCase {
|
||||
String scriptPath = "/dijit/themes/dijit.css";
|
||||
String expectedUrl = "null/resources/dijit/themes/dijit.css";
|
||||
|
||||
ResourceHelper.renderStyleLink(jsf.facesContext(), scriptPath);
|
||||
ResourceHelper.renderStyleLink(jsf.facesContext(), scriptPath);
|
||||
ResourceHelper.renderStyleLink(this.jsf.facesContext(), scriptPath);
|
||||
ResourceHelper.renderStyleLink(this.jsf.facesContext(), scriptPath);
|
||||
|
||||
String expectedOutput = "<link type=\"text/css\" rel=\"stylesheet\" href=\"" + expectedUrl + "\"/>";
|
||||
|
||||
assertEquals(expectedOutput, writer.toString());
|
||||
assertEquals(expectedOutput, this.writer.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,18 +27,20 @@ public class FlowActionListenerTests extends TestCase {
|
||||
RequestContext context = EasyMock.createMock(RequestContext.class);
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
jsfMock.setUp();
|
||||
this.jsfMock.setUp();
|
||||
|
||||
listener = new FlowActionListener(jsfMock.application().getActionListener());
|
||||
RequestContextHolder.setRequestContext(context);
|
||||
this.listener = new FlowActionListener(this.jsfMock.application().getActionListener());
|
||||
RequestContextHolder.setRequestContext(this.context);
|
||||
LocalAttributeMap<Object> flash = new LocalAttributeMap<Object>();
|
||||
EasyMock.expect(context.getFlashScope()).andStubReturn(flash);
|
||||
EasyMock.expect(context.getCurrentState()).andStubReturn(new MockViewState());
|
||||
EasyMock.replay(new Object[] { context });
|
||||
EasyMock.expect(this.context.getFlashScope()).andStubReturn(flash);
|
||||
EasyMock.expect(this.context.getCurrentState()).andStubReturn(new MockViewState());
|
||||
EasyMock.replay(new Object[] { this.context });
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
jsfMock.tearDown();
|
||||
super.tearDown();
|
||||
this.jsfMock.tearDown();
|
||||
RequestContextHolder.setRequestContext(null);
|
||||
}
|
||||
|
||||
public final void testProcessAction() {
|
||||
@@ -49,12 +51,12 @@ public class FlowActionListenerTests extends TestCase {
|
||||
commandButton.setAction(binding);
|
||||
ActionEvent event = new ActionEvent(commandButton);
|
||||
|
||||
listener.processAction(event);
|
||||
this.listener.processAction(event);
|
||||
|
||||
assertTrue("The event was not signaled",
|
||||
jsfMock.externalContext().getRequestMap().containsKey(JsfView.EVENT_KEY));
|
||||
this.jsfMock.externalContext().getRequestMap().containsKey(JsfView.EVENT_KEY));
|
||||
assertEquals("The event should be " + outcome, outcome,
|
||||
jsfMock.externalContext().getRequestMap().get(JsfView.EVENT_KEY));
|
||||
this.jsfMock.externalContext().getRequestMap().get(JsfView.EVENT_KEY));
|
||||
}
|
||||
|
||||
public final void testProcessAction_NullOutcome() {
|
||||
@@ -65,10 +67,10 @@ public class FlowActionListenerTests extends TestCase {
|
||||
commandButton.setAction(binding);
|
||||
ActionEvent event = new ActionEvent(commandButton);
|
||||
|
||||
listener.processAction(event);
|
||||
this.listener.processAction(event);
|
||||
|
||||
assertFalse("An unexpected event was signaled",
|
||||
jsfMock.externalContext().getRequestMap().containsKey(JsfView.EVENT_KEY));
|
||||
this.jsfMock.externalContext().getRequestMap().containsKey(JsfView.EVENT_KEY));
|
||||
}
|
||||
|
||||
private class MethodBindingStub extends MethodBinding {
|
||||
@@ -95,8 +97,7 @@ public class FlowActionListenerTests extends TestCase {
|
||||
super(new Flow("mockFlow"), "mockView", new ViewFactory() {
|
||||
|
||||
public View getView(RequestContext context) {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Auto-generated method stub");
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -0,0 +1,94 @@
|
||||
package org.springframework.faces.webflow;
|
||||
|
||||
import javax.el.ELContext;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.apache.myfaces.test.el.MockELContext;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.web.context.support.StaticWebApplicationContext;
|
||||
import org.springframework.webflow.core.collection.LocalAttributeMap;
|
||||
import org.springframework.webflow.engine.Flow;
|
||||
import org.springframework.webflow.execution.RequestContext;
|
||||
import org.springframework.webflow.execution.RequestContextHolder;
|
||||
import org.springframework.webflow.test.MockRequestContext;
|
||||
|
||||
/**
|
||||
* Tests for {@link FlowELResolver}.
|
||||
*
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
public class FlowELResolverTests extends TestCase {
|
||||
|
||||
private final FlowELResolver resolver = new FlowELResolver();
|
||||
|
||||
private final RequestContext requestContext = new MockRequestContext();
|
||||
|
||||
private final ELContext elContext = new MockELContext();
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
RequestContextHolder.setRequestContext(this.requestContext);
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
RequestContextHolder.setRequestContext(null);
|
||||
}
|
||||
|
||||
public void testRequestContextResolve() throws Exception {
|
||||
Object actual = this.resolver.getValue(this.elContext, null, "flowRequestContext");
|
||||
assertTrue(this.elContext.isPropertyResolved());
|
||||
assertNotNull(actual);
|
||||
assertSame(this.requestContext, actual);
|
||||
}
|
||||
|
||||
public void testImplicitFlowResolve() throws Exception {
|
||||
Object actual = this.resolver.getValue(this.elContext, null, "flowScope");
|
||||
assertTrue(this.elContext.isPropertyResolved());
|
||||
assertNotNull(actual);
|
||||
assertSame(this.requestContext.getFlowScope(), actual);
|
||||
}
|
||||
|
||||
public void testFlowResourceResolve() throws Exception {
|
||||
ApplicationContext applicationContext = new StaticWebApplicationContext();
|
||||
((Flow) this.requestContext.getActiveFlow()).setApplicationContext(applicationContext);
|
||||
Object actual = this.resolver.getValue(this.elContext, null, "resourceBundle");
|
||||
assertTrue(this.elContext.isPropertyResolved());
|
||||
assertNotNull(actual);
|
||||
assertSame(applicationContext, actual);
|
||||
}
|
||||
|
||||
public void testScopeResolve() throws Exception {
|
||||
this.requestContext.getFlowScope().put("test", "test");
|
||||
Object actual = this.resolver.getValue(this.elContext, null, "test");
|
||||
assertTrue(this.elContext.isPropertyResolved());
|
||||
assertEquals("test", actual);
|
||||
}
|
||||
|
||||
public void testMapAdaptableResolve() throws Exception {
|
||||
LocalAttributeMap<String> base = new LocalAttributeMap<String>();
|
||||
base.put("test", "test");
|
||||
Object actual = this.resolver.getValue(this.elContext, base, "test");
|
||||
assertTrue(this.elContext.isPropertyResolved());
|
||||
assertEquals("test", actual);
|
||||
}
|
||||
|
||||
public void testBeanResolveWithRequestContext() throws Exception {
|
||||
StaticWebApplicationContext applicationContext = new StaticWebApplicationContext();
|
||||
((Flow) this.requestContext.getActiveFlow()).setApplicationContext(applicationContext);
|
||||
applicationContext.registerSingleton("test", Bean.class);
|
||||
Object actual = this.resolver.getValue(this.elContext, null, "test");
|
||||
assertTrue(this.elContext.isPropertyResolved());
|
||||
assertNotNull(actual);
|
||||
assertTrue(actual instanceof Bean);
|
||||
}
|
||||
|
||||
public void testBeanResolveWithoutRequestContext() throws Exception {
|
||||
RequestContextHolder.setRequestContext(null);
|
||||
Object actual = this.resolver.getValue(this.elContext, null, "test");
|
||||
assertFalse(this.elContext.isPropertyResolved());
|
||||
assertNull(actual);
|
||||
}
|
||||
|
||||
public static class Bean {
|
||||
}
|
||||
}
|
||||
@@ -19,6 +19,7 @@ import org.springframework.binding.message.DefaultMessageContext;
|
||||
import org.springframework.binding.message.Message;
|
||||
import org.springframework.binding.message.MessageBuilder;
|
||||
import org.springframework.binding.message.MessageContext;
|
||||
import org.springframework.faces.webflow.FlowFacesContext.FacesMessageSource;
|
||||
import org.springframework.webflow.execution.RequestContext;
|
||||
|
||||
public class FlowFacesContextTests extends TestCase {
|
||||
@@ -35,45 +36,43 @@ public class FlowFacesContextTests extends TestCase {
|
||||
|
||||
@SuppressWarnings("cast")
|
||||
protected void setUp() throws Exception {
|
||||
jsf.setUp();
|
||||
requestContext = (RequestContext) EasyMock.createMock(RequestContext.class);
|
||||
facesContext = new Jsf2FlowFacesContext(requestContext, jsf.facesContext());
|
||||
|
||||
this.jsf.setUp();
|
||||
this.requestContext = (RequestContext) EasyMock.createMock(RequestContext.class);
|
||||
this.facesContext = new FlowFacesContext(this.requestContext, this.jsf.facesContext());
|
||||
setupMessageContext();
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
jsf.tearDown();
|
||||
super.tearDown();
|
||||
this.jsf.tearDown();
|
||||
}
|
||||
|
||||
public final void testCurrentInstance() {
|
||||
assertSame(FacesContext.getCurrentInstance(), facesContext);
|
||||
assertSame(FacesContext.getCurrentInstance(), this.facesContext);
|
||||
}
|
||||
|
||||
public final void testAddMessage() {
|
||||
messageContext = new DefaultMessageContext();
|
||||
EasyMock.expect(requestContext.getMessageContext()).andStubReturn(messageContext);
|
||||
EasyMock.replay(new Object[] { requestContext });
|
||||
this.messageContext = new DefaultMessageContext();
|
||||
EasyMock.expect(this.requestContext.getMessageContext()).andStubReturn(this.messageContext);
|
||||
EasyMock.replay(new Object[] { this.requestContext });
|
||||
|
||||
facesContext.addMessage("foo", new FacesMessage(FacesMessage.SEVERITY_INFO, "foo", "bar"));
|
||||
this.facesContext.addMessage("foo", new FacesMessage(FacesMessage.SEVERITY_INFO, "foo", "bar"));
|
||||
|
||||
assertEquals("Message count is incorrect", 2, messageContext.getAllMessages().length);
|
||||
Message summaryMessage = messageContext.getMessagesBySource("foo_summary")[0];
|
||||
assertEquals("foo", summaryMessage.getText());
|
||||
Message detailMessage = messageContext.getMessagesBySource("foo_detail")[0];
|
||||
assertEquals("bar", detailMessage.getText());
|
||||
assertEquals("Message count is incorrect", 1, this.messageContext.getAllMessages().length);
|
||||
Message message = this.messageContext.getMessagesBySource(new FacesMessageSource("foo"))[0];
|
||||
assertEquals("foo : bar", message.getText());
|
||||
}
|
||||
|
||||
public final void testGetGlobalMessagesOnly() {
|
||||
messageContext = new DefaultMessageContext();
|
||||
EasyMock.expect(requestContext.getMessageContext()).andStubReturn(messageContext);
|
||||
EasyMock.replay(new Object[] { requestContext });
|
||||
this.messageContext = new DefaultMessageContext();
|
||||
EasyMock.expect(this.requestContext.getMessageContext()).andStubReturn(this.messageContext);
|
||||
EasyMock.replay(new Object[] { this.requestContext });
|
||||
|
||||
facesContext.addMessage("foo", new FacesMessage(FacesMessage.SEVERITY_INFO, "foo", "bar"));
|
||||
facesContext.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "FOO", "BAR"));
|
||||
this.facesContext.addMessage("foo", new FacesMessage(FacesMessage.SEVERITY_INFO, "foo", "bar"));
|
||||
this.facesContext.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "FOO", "BAR"));
|
||||
|
||||
int iterationCount = 0;
|
||||
Iterator<FacesMessage> i = facesContext.getMessages(null);
|
||||
Iterator<FacesMessage> i = this.facesContext.getMessages(null);
|
||||
while (i.hasNext()) {
|
||||
FacesMessage message = i.next();
|
||||
assertNotNull(message);
|
||||
@@ -83,15 +82,15 @@ public class FlowFacesContextTests extends TestCase {
|
||||
}
|
||||
|
||||
public final void testGetAllMessages() {
|
||||
messageContext = new DefaultMessageContext();
|
||||
EasyMock.expect(requestContext.getMessageContext()).andStubReturn(messageContext);
|
||||
EasyMock.replay(new Object[] { requestContext });
|
||||
this.messageContext = new DefaultMessageContext();
|
||||
EasyMock.expect(this.requestContext.getMessageContext()).andStubReturn(this.messageContext);
|
||||
EasyMock.replay(new Object[] { this.requestContext });
|
||||
|
||||
facesContext.addMessage("foo", new FacesMessage(FacesMessage.SEVERITY_INFO, "foo", "bar"));
|
||||
facesContext.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "FOO", "BAR"));
|
||||
this.facesContext.addMessage("foo", new FacesMessage(FacesMessage.SEVERITY_INFO, "foo", "bar"));
|
||||
this.facesContext.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "FOO", "BAR"));
|
||||
|
||||
int iterationCount = 0;
|
||||
Iterator<FacesMessage> i = facesContext.getMessages();
|
||||
Iterator<FacesMessage> i = this.facesContext.getMessages();
|
||||
while (i.hasNext()) {
|
||||
FacesMessage message = i.next();
|
||||
assertNotNull(message);
|
||||
@@ -101,31 +100,26 @@ public class FlowFacesContextTests extends TestCase {
|
||||
}
|
||||
|
||||
public final void testAddMessages_MultipleNullIds() {
|
||||
messageContext = new DefaultMessageContext();
|
||||
EasyMock.expect(requestContext.getMessageContext()).andStubReturn(messageContext);
|
||||
EasyMock.replay(new Object[] { requestContext });
|
||||
this.messageContext = new DefaultMessageContext();
|
||||
EasyMock.expect(this.requestContext.getMessageContext()).andStubReturn(this.messageContext);
|
||||
EasyMock.replay(new Object[] { this.requestContext });
|
||||
|
||||
facesContext.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "foo", "bar"));
|
||||
facesContext.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "zoo", "zar"));
|
||||
this.facesContext.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "foo", "bar"));
|
||||
this.facesContext.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "zoo", "zar"));
|
||||
|
||||
assertEquals("Message count is incorrect", 4, messageContext.getAllMessages().length);
|
||||
Message summaryMessage1 = messageContext.getMessagesBySource("null_summary")[0];
|
||||
assertEquals("foo", summaryMessage1.getText());
|
||||
Message detailMessage1 = messageContext.getMessagesBySource("null_detail")[0];
|
||||
assertEquals("bar", detailMessage1.getText());
|
||||
Message summaryMessage2 = messageContext.getMessagesBySource("null_summary")[1];
|
||||
assertEquals("zoo", summaryMessage2.getText());
|
||||
Message detailMessage2 = messageContext.getMessagesBySource("null_detail")[1];
|
||||
assertEquals("zar", detailMessage2.getText());
|
||||
assertEquals("Message count is incorrect", 2, this.messageContext.getAllMessages().length);
|
||||
Message[] messages = this.messageContext.getMessagesBySource(new FacesMessageSource(null));
|
||||
assertEquals("foo : bar", messages[0].getText());
|
||||
assertEquals("zoo : zar", messages[1].getText());
|
||||
}
|
||||
|
||||
public final void testGetMessages() {
|
||||
messageContext = prepopulatedMessageContext;
|
||||
EasyMock.expect(requestContext.getMessageContext()).andStubReturn(messageContext);
|
||||
EasyMock.replay(new Object[] { requestContext });
|
||||
this.messageContext = this.prepopulatedMessageContext;
|
||||
EasyMock.expect(this.requestContext.getMessageContext()).andStubReturn(this.messageContext);
|
||||
EasyMock.replay(new Object[] { this.requestContext });
|
||||
|
||||
int iterationCount = 0;
|
||||
Iterator<FacesMessage> i = facesContext.getMessages();
|
||||
Iterator<FacesMessage> i = this.facesContext.getMessages();
|
||||
while (i.hasNext()) {
|
||||
assertNotNull(i.next());
|
||||
iterationCount++;
|
||||
@@ -134,17 +128,17 @@ public class FlowFacesContextTests extends TestCase {
|
||||
}
|
||||
|
||||
public final void testMutableGetMessages() {
|
||||
messageContext = prepopulatedMessageContext;
|
||||
EasyMock.expect(requestContext.getMessageContext()).andStubReturn(messageContext);
|
||||
EasyMock.replay(new Object[] { requestContext });
|
||||
this.messageContext = this.prepopulatedMessageContext;
|
||||
EasyMock.expect(this.requestContext.getMessageContext()).andStubReturn(this.messageContext);
|
||||
EasyMock.replay(new Object[] { this.requestContext });
|
||||
|
||||
facesContext.addMessage("TESTID", new FacesMessage("summary1"));
|
||||
FacesMessage soruceMessage = facesContext.getMessages("TESTID").next();
|
||||
this.facesContext.addMessage("TESTID", new FacesMessage("summary1"));
|
||||
FacesMessage soruceMessage = this.facesContext.getMessages("TESTID").next();
|
||||
soruceMessage.setSummary("summary2");
|
||||
|
||||
// check that message sticks around even when the facesContext has been torn down and re-created during the
|
||||
// processing of the current request
|
||||
FacesContext newFacesContext = new FlowFacesContext(requestContext, jsf.facesContext());
|
||||
FacesContext newFacesContext = new FlowFacesContext(this.requestContext, this.jsf.facesContext());
|
||||
assertSame(FacesContext.getCurrentInstance(), newFacesContext);
|
||||
|
||||
FacesMessage gotMessage = newFacesContext.getMessages("TESTID").next();
|
||||
@@ -152,12 +146,12 @@ public class FlowFacesContextTests extends TestCase {
|
||||
}
|
||||
|
||||
public final void testGetMessagesByClientId_ForComponent() {
|
||||
messageContext = prepopulatedMessageContext;
|
||||
EasyMock.expect(requestContext.getMessageContext()).andStubReturn(messageContext);
|
||||
EasyMock.replay(new Object[] { requestContext });
|
||||
this.messageContext = this.prepopulatedMessageContext;
|
||||
EasyMock.expect(this.requestContext.getMessageContext()).andStubReturn(this.messageContext);
|
||||
EasyMock.replay(new Object[] { this.requestContext });
|
||||
|
||||
int iterationCount = 0;
|
||||
Iterator<FacesMessage> i = facesContext.getMessages("componentId");
|
||||
Iterator<FacesMessage> i = this.facesContext.getMessages("componentId");
|
||||
while (i.hasNext()) {
|
||||
FacesMessage message = i.next();
|
||||
assertNotNull(message);
|
||||
@@ -169,12 +163,12 @@ public class FlowFacesContextTests extends TestCase {
|
||||
}
|
||||
|
||||
public final void testGetMessagesByClientId_ForUserMessage() {
|
||||
messageContext = prepopulatedMessageContext;
|
||||
EasyMock.expect(requestContext.getMessageContext()).andStubReturn(messageContext);
|
||||
EasyMock.replay(new Object[] { requestContext });
|
||||
this.messageContext = this.prepopulatedMessageContext;
|
||||
EasyMock.expect(this.requestContext.getMessageContext()).andStubReturn(this.messageContext);
|
||||
EasyMock.replay(new Object[] { this.requestContext });
|
||||
|
||||
int iterationCount = 0;
|
||||
Iterator<FacesMessage> i = facesContext.getMessages("userMessage");
|
||||
Iterator<FacesMessage> i = this.facesContext.getMessages("userMessage");
|
||||
while (i.hasNext()) {
|
||||
FacesMessage message = i.next();
|
||||
assertNotNull(message);
|
||||
@@ -186,18 +180,18 @@ public class FlowFacesContextTests extends TestCase {
|
||||
}
|
||||
|
||||
public final void testgetMessagesByClientId_InvalidId() {
|
||||
messageContext = prepopulatedMessageContext;
|
||||
EasyMock.expect(requestContext.getMessageContext()).andStubReturn(messageContext);
|
||||
EasyMock.replay(new Object[] { requestContext });
|
||||
this.messageContext = this.prepopulatedMessageContext;
|
||||
EasyMock.expect(this.requestContext.getMessageContext()).andStubReturn(this.messageContext);
|
||||
EasyMock.replay(new Object[] { this.requestContext });
|
||||
|
||||
Iterator<FacesMessage> i = facesContext.getMessages("unknown");
|
||||
Iterator<FacesMessage> i = this.facesContext.getMessages("unknown");
|
||||
assertFalse(i.hasNext());
|
||||
}
|
||||
|
||||
public final void testGetClientIdsWithMessages() {
|
||||
messageContext = prepopulatedMessageContext;
|
||||
EasyMock.expect(requestContext.getMessageContext()).andStubReturn(messageContext);
|
||||
EasyMock.replay(new Object[] { requestContext });
|
||||
this.messageContext = this.prepopulatedMessageContext;
|
||||
EasyMock.expect(this.requestContext.getMessageContext()).andStubReturn(this.messageContext);
|
||||
EasyMock.replay(new Object[] { this.requestContext });
|
||||
|
||||
List<String> expectedOrderedIds = new ArrayList<String>();
|
||||
expectedOrderedIds.add(null);
|
||||
@@ -205,7 +199,7 @@ public class FlowFacesContextTests extends TestCase {
|
||||
expectedOrderedIds.add("userMessage");
|
||||
|
||||
int iterationCount = 0;
|
||||
Iterator<String> i = facesContext.getClientIdsWithMessages();
|
||||
Iterator<String> i = this.facesContext.getClientIdsWithMessages();
|
||||
while (i.hasNext()) {
|
||||
String clientId = i.next();
|
||||
assertEquals("Client id not expected", expectedOrderedIds.get(iterationCount), clientId);
|
||||
@@ -216,11 +210,11 @@ public class FlowFacesContextTests extends TestCase {
|
||||
|
||||
public final void testMessagesAreSerializable() throws Exception {
|
||||
DefaultMessageContext messageContext = new DefaultMessageContext();
|
||||
EasyMock.expect(requestContext.getMessageContext()).andStubReturn(messageContext);
|
||||
EasyMock.replay(new Object[] { requestContext });
|
||||
EasyMock.expect(this.requestContext.getMessageContext()).andStubReturn(messageContext);
|
||||
EasyMock.replay(new Object[] { this.requestContext });
|
||||
|
||||
facesContext.addMessage("TESTID", new FacesMessage("summary1"));
|
||||
FacesMessage sourceMessage = facesContext.getMessages("TESTID").next();
|
||||
this.facesContext.addMessage("TESTID", new FacesMessage("summary1"));
|
||||
FacesMessage sourceMessage = this.facesContext.getMessages("TESTID").next();
|
||||
sourceMessage.setSummary("summary2");
|
||||
sourceMessage.setSeverity(FacesMessage.SEVERITY_FATAL);
|
||||
|
||||
@@ -238,11 +232,11 @@ public class FlowFacesContextTests extends TestCase {
|
||||
ois.close();
|
||||
|
||||
messageContext.restoreMessages(mementoRead);
|
||||
EasyMock.reset(new Object[] { requestContext });
|
||||
EasyMock.expect(requestContext.getMessageContext()).andStubReturn(messageContext);
|
||||
EasyMock.replay(new Object[] { requestContext });
|
||||
EasyMock.reset(new Object[] { this.requestContext });
|
||||
EasyMock.expect(this.requestContext.getMessageContext()).andStubReturn(messageContext);
|
||||
EasyMock.replay(new Object[] { this.requestContext });
|
||||
|
||||
FacesContext newFacesContext = new FlowFacesContext(requestContext, jsf.facesContext());
|
||||
FacesContext newFacesContext = new FlowFacesContext(this.requestContext, this.jsf.facesContext());
|
||||
assertSame(FacesContext.getCurrentInstance(), newFacesContext);
|
||||
FacesMessage gotMessage = newFacesContext.getMessages("TESTID").next();
|
||||
assertEquals("summary2", gotMessage.getSummary());
|
||||
@@ -250,50 +244,42 @@ public class FlowFacesContextTests extends TestCase {
|
||||
}
|
||||
|
||||
public final void testGetMaximumSeverity() {
|
||||
messageContext = prepopulatedMessageContext;
|
||||
EasyMock.expect(requestContext.getMessageContext()).andStubReturn(messageContext);
|
||||
EasyMock.replay(new Object[] { requestContext });
|
||||
this.messageContext = this.prepopulatedMessageContext;
|
||||
EasyMock.expect(this.requestContext.getMessageContext()).andStubReturn(this.messageContext);
|
||||
EasyMock.replay(new Object[] { this.requestContext });
|
||||
|
||||
assertEquals(FacesMessage.SEVERITY_FATAL, facesContext.getMaximumSeverity());
|
||||
assertEquals(FacesMessage.SEVERITY_FATAL, this.facesContext.getMaximumSeverity());
|
||||
}
|
||||
|
||||
public final void testGetELContext() {
|
||||
|
||||
assertNotNull(facesContext.getELContext());
|
||||
assertSame(facesContext, facesContext.getELContext().getContext(FacesContext.class));
|
||||
assertNotNull(this.facesContext.getELContext());
|
||||
assertSame(this.facesContext, this.facesContext.getELContext().getContext(FacesContext.class));
|
||||
}
|
||||
|
||||
public final void testValidationFailed() {
|
||||
messageContext = new DefaultMessageContext();
|
||||
EasyMock.expect(requestContext.getMessageContext()).andStubReturn(messageContext);
|
||||
EasyMock.replay(new Object[] { requestContext });
|
||||
this.messageContext = new DefaultMessageContext();
|
||||
EasyMock.expect(this.requestContext.getMessageContext()).andStubReturn(this.messageContext);
|
||||
EasyMock.replay(new Object[] { this.requestContext });
|
||||
|
||||
facesContext.addMessage("foo", new FacesMessage(FacesMessage.SEVERITY_ERROR, "foo", "bar"));
|
||||
this.facesContext.addMessage("foo", new FacesMessage(FacesMessage.SEVERITY_ERROR, "foo", "bar"));
|
||||
|
||||
assertEquals(true, facesContext.isValidationFailed());
|
||||
assertEquals(true, this.facesContext.isValidationFailed());
|
||||
}
|
||||
|
||||
private void setupMessageContext() {
|
||||
prepopulatedMessageContext = new DefaultMessageContext();
|
||||
prepopulatedMessageContext.addMessage(new MessageBuilder().source("null_summary").defaultText("foo").info()
|
||||
.build());
|
||||
prepopulatedMessageContext.addMessage(new MessageBuilder().source("null_detail").defaultText("foo").info()
|
||||
.build());
|
||||
prepopulatedMessageContext.addMessage(new MessageBuilder().source("componentId_summary")
|
||||
.defaultText("componentId_summary1").warning().build());
|
||||
prepopulatedMessageContext.addMessage(new MessageBuilder().source("componentId_detail")
|
||||
.defaultText("componentId_detail1").warning().build());
|
||||
prepopulatedMessageContext.addMessage(new MessageBuilder().source("componentId_summary")
|
||||
.defaultText("componentId_summary2").warning().build());
|
||||
prepopulatedMessageContext.addMessage(new MessageBuilder().source("componentId_detail")
|
||||
.defaultText("componentId_detail2").warning().build());
|
||||
prepopulatedMessageContext.addMessage(new MessageBuilder().source("userMessage").defaultText("userMessage")
|
||||
this.prepopulatedMessageContext = new DefaultMessageContext();
|
||||
this.prepopulatedMessageContext.addMessage(new FlowFacesContext.FlowFacesMessage(new FacesMessageSource(null),
|
||||
new FacesMessage("foo")));
|
||||
this.prepopulatedMessageContext.addMessage(new FlowFacesContext.FlowFacesMessage(new FacesMessageSource(
|
||||
"componentId"), new FacesMessage("componentId_summary1", "componentId_detail1")));
|
||||
this.prepopulatedMessageContext.addMessage(new FlowFacesContext.FlowFacesMessage(new FacesMessageSource(
|
||||
"componentId"), new FacesMessage("componentId_summary2", "componentId_detail2")));
|
||||
this.prepopulatedMessageContext.addMessage(new FlowFacesContext.FlowFacesMessage(new FacesMessageSource(null),
|
||||
new FacesMessage("baz")));
|
||||
this.prepopulatedMessageContext.addMessage(new MessageBuilder().source("userMessage").defaultText("userMessage")
|
||||
.info().build());
|
||||
prepopulatedMessageContext.addMessage(new MessageBuilder().source("null_summary").defaultText("baz").error()
|
||||
.build());
|
||||
prepopulatedMessageContext.addMessage(new MessageBuilder().source("null_detail").defaultText("baz").error()
|
||||
.build());
|
||||
prepopulatedMessageContext.addMessage(new MessageBuilder().defaultText("Subzero Wins - Fatality").fatal()
|
||||
this.prepopulatedMessageContext.addMessage(new MessageBuilder().defaultText("Subzero Wins - Fatality").fatal()
|
||||
.build());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,11 @@ import org.springframework.webflow.test.MockRequestContext;
|
||||
|
||||
public class FlowPartialViewContextTests extends TestCase {
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
super.tearDown();
|
||||
RequestContextHolder.setRequestContext(null);
|
||||
}
|
||||
|
||||
public void testReturnFragmentIds() throws Exception {
|
||||
String[] fragmentIds = new String[] { "foo", "bar" };
|
||||
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
package org.springframework.faces.webflow;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.easymock.EasyMock;
|
||||
import org.springframework.web.context.support.StaticWebApplicationContext;
|
||||
import org.springframework.webflow.core.collection.LocalAttributeMap;
|
||||
import org.springframework.webflow.execution.FlowExecutionContext;
|
||||
import org.springframework.webflow.execution.RequestContext;
|
||||
import org.springframework.webflow.execution.RequestContextHolder;
|
||||
import org.springframework.webflow.test.MockFlowExecutionKey;
|
||||
|
||||
public class FlowResponseStateManagerTests extends TestCase {
|
||||
|
||||
private final JSFMockHelper jsfMock = new JSFMockHelper();
|
||||
|
||||
private FlowResponseStateManager responseStateManager;
|
||||
|
||||
private RequestContext requestContext;
|
||||
private FlowExecutionContext flowExecutionContext;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
this.jsfMock.setUp();
|
||||
StaticWebApplicationContext webappContext = new StaticWebApplicationContext();
|
||||
webappContext.setServletContext(this.jsfMock.servletContext());
|
||||
|
||||
this.requestContext = EasyMock.createMock(RequestContext.class);
|
||||
RequestContextHolder.setRequestContext(this.requestContext);
|
||||
this.flowExecutionContext = EasyMock.createMock(FlowExecutionContext.class);
|
||||
|
||||
this.responseStateManager = new FlowResponseStateManager(null);
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
super.tearDown();
|
||||
this.jsfMock.tearDown();
|
||||
RequestContextHolder.setRequestContext(null);
|
||||
}
|
||||
|
||||
public void testname() throws Exception {
|
||||
|
||||
}
|
||||
|
||||
public void testWriteFlowSerializedView() throws Exception {
|
||||
EasyMock.expect(this.flowExecutionContext.getKey()).andReturn(new MockFlowExecutionKey("e1s1"));
|
||||
LocalAttributeMap<Object> viewMap = new LocalAttributeMap<Object>();
|
||||
EasyMock.expect(this.requestContext.getViewScope()).andStubReturn(viewMap);
|
||||
EasyMock.expect(this.requestContext.getFlowExecutionContext()).andReturn(this.flowExecutionContext);
|
||||
EasyMock.replay(this.requestContext, this.flowExecutionContext);
|
||||
|
||||
Object state = new Object();
|
||||
this.responseStateManager.writeState(this.jsfMock.facesContext(), state);
|
||||
|
||||
assertEquals(state, viewMap.get(FlowResponseStateManager.FACES_VIEW_STATE));
|
||||
assertEquals(
|
||||
"<input type=\"hidden\" name=\"javax.faces.ViewState\" id=\"javax.faces.ViewState\" value=\"e1s1\" />",
|
||||
this.jsfMock.contentAsString());
|
||||
EasyMock.verify(this.flowExecutionContext, this.requestContext);
|
||||
}
|
||||
|
||||
public void testGetState() throws Exception {
|
||||
Object state = new Object();
|
||||
|
||||
LocalAttributeMap<Object> viewMap = new LocalAttributeMap<Object>();
|
||||
viewMap.put(FlowResponseStateManager.FACES_VIEW_STATE, state);
|
||||
EasyMock.expect(this.requestContext.getViewScope()).andStubReturn(viewMap);
|
||||
EasyMock.replay(this.requestContext);
|
||||
|
||||
Object actual = this.responseStateManager.getState(this.jsfMock.facesContext(), "viewId");
|
||||
|
||||
assertSame(state, actual);
|
||||
EasyMock.verify(this.requestContext);
|
||||
}
|
||||
}
|
||||
@@ -1,73 +0,0 @@
|
||||
package org.springframework.faces.webflow;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.easymock.EasyMock;
|
||||
import org.springframework.web.context.support.StaticWebApplicationContext;
|
||||
import org.springframework.webflow.core.collection.LocalAttributeMap;
|
||||
import org.springframework.webflow.execution.FlowExecutionContext;
|
||||
import org.springframework.webflow.execution.RequestContext;
|
||||
import org.springframework.webflow.execution.RequestContextHolder;
|
||||
import org.springframework.webflow.test.MockFlowExecutionKey;
|
||||
|
||||
public class FlowViewResponseStateManagerTests extends TestCase {
|
||||
|
||||
private JSFMockHelper jsfMock = new JSFMockHelper();
|
||||
|
||||
private FlowViewResponseStateManager responseStateManager;
|
||||
|
||||
private RequestContext requestContext;
|
||||
private FlowExecutionContext flowExecutionContext;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
jsfMock.setUp();
|
||||
StaticWebApplicationContext webappContext = new StaticWebApplicationContext();
|
||||
webappContext.setServletContext(jsfMock.servletContext());
|
||||
|
||||
requestContext = EasyMock.createMock(RequestContext.class);
|
||||
RequestContextHolder.setRequestContext(requestContext);
|
||||
flowExecutionContext = EasyMock.createMock(FlowExecutionContext.class);
|
||||
|
||||
responseStateManager = new FlowViewResponseStateManager(null);
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
jsfMock.tearDown();
|
||||
}
|
||||
|
||||
public void testWriteFlowSerializedView() throws Exception {
|
||||
EasyMock.expect(flowExecutionContext.getKey()).andReturn(new MockFlowExecutionKey("e1s1"));
|
||||
LocalAttributeMap<Object> viewMap = new LocalAttributeMap<Object>();
|
||||
EasyMock.expect(requestContext.getViewScope()).andStubReturn(viewMap);
|
||||
EasyMock.expect(requestContext.getFlowExecutionContext()).andReturn(flowExecutionContext);
|
||||
EasyMock.replay(requestContext, flowExecutionContext);
|
||||
|
||||
FlowSerializedView flowSerializedView = new FlowSerializedView("viewId", null, null);
|
||||
responseStateManager.writeState(jsfMock.facesContext(), flowSerializedView);
|
||||
|
||||
assertEquals(flowSerializedView, viewMap.get(FlowViewStateManager.SERIALIZED_VIEW_STATE));
|
||||
assertEquals(
|
||||
"<input type=\"hidden\" name=\"javax.faces.ViewState\" id=\"javax.faces.ViewState\" value=\"e1s1\" />",
|
||||
jsfMock.contentAsString());
|
||||
EasyMock.verify(flowExecutionContext, requestContext);
|
||||
}
|
||||
|
||||
public void testGetState() throws Exception {
|
||||
Object treeStructure = new Object();
|
||||
Object componentState = new Object();
|
||||
FlowSerializedView flowSerializedView = new FlowSerializedView("viewId", treeStructure, componentState);
|
||||
|
||||
LocalAttributeMap<Object> viewMap = new LocalAttributeMap<Object>();
|
||||
viewMap.put(FlowViewStateManager.SERIALIZED_VIEW_STATE, flowSerializedView);
|
||||
EasyMock.expect(requestContext.getViewScope()).andStubReturn(viewMap);
|
||||
EasyMock.replay(requestContext);
|
||||
|
||||
Object state = responseStateManager.getState(jsfMock.facesContext(), "viewId");
|
||||
|
||||
assertTrue(state instanceof Object[]);
|
||||
assertSame(treeStructure, ((Object[]) state)[0]);
|
||||
assertSame(componentState, ((Object[]) state)[1]);
|
||||
EasyMock.verify(requestContext);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,7 +10,7 @@ public class JSFManagedBean {
|
||||
List<String> values = new ArrayList<String>();
|
||||
|
||||
public JSFModel getModel() {
|
||||
return model;
|
||||
return this.model;
|
||||
}
|
||||
|
||||
public void setModel(JSFModel model) {
|
||||
@@ -18,7 +18,7 @@ public class JSFManagedBean {
|
||||
}
|
||||
|
||||
public String getProp1() {
|
||||
return prop1;
|
||||
return this.prop1;
|
||||
}
|
||||
|
||||
public void setProp1(String prop1) {
|
||||
@@ -26,10 +26,10 @@ public class JSFManagedBean {
|
||||
}
|
||||
|
||||
public void addValue(String value) {
|
||||
values.add(value);
|
||||
this.values.add(value);
|
||||
}
|
||||
|
||||
public List<String> getValues() {
|
||||
return values;
|
||||
return this.values;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,66 +39,66 @@ import org.apache.myfaces.test.mock.visit.MockVisitContextFactory;
|
||||
*/
|
||||
public class JSFMockHelper {
|
||||
|
||||
private JSFMock mock = new JSFMock();
|
||||
private final JSFMock mock = new JSFMock();
|
||||
|
||||
public Application application() {
|
||||
return mock.application();
|
||||
return this.mock.application();
|
||||
}
|
||||
|
||||
public MockServletConfig config() {
|
||||
return mock.config();
|
||||
return this.mock.config();
|
||||
}
|
||||
|
||||
public String contentAsString() throws IOException {
|
||||
return mock.contentAsString();
|
||||
return this.mock.contentAsString();
|
||||
}
|
||||
|
||||
public MockExternalContext externalContext() {
|
||||
return mock.externalContext();
|
||||
return this.mock.externalContext();
|
||||
}
|
||||
|
||||
public FacesContext facesContext() {
|
||||
return mock.facesContext();
|
||||
return this.mock.facesContext();
|
||||
}
|
||||
|
||||
public FacesContextFactory facesContextFactory() {
|
||||
return mock.facesContextFactory();
|
||||
return this.mock.facesContextFactory();
|
||||
}
|
||||
|
||||
public MockLifecycle lifecycle() {
|
||||
return mock.lifecycle();
|
||||
return this.mock.lifecycle();
|
||||
}
|
||||
|
||||
public MockLifecycleFactory lifecycleFactory() {
|
||||
return mock.lifecycleFactory();
|
||||
return this.mock.lifecycleFactory();
|
||||
}
|
||||
|
||||
public MockRenderKit renderKit() {
|
||||
return mock.renderKit();
|
||||
return this.mock.renderKit();
|
||||
}
|
||||
|
||||
public MockHttpServletRequest request() {
|
||||
return mock.request();
|
||||
return this.mock.request();
|
||||
}
|
||||
|
||||
public MockHttpServletResponse response() {
|
||||
return mock.response();
|
||||
return this.mock.response();
|
||||
}
|
||||
|
||||
public MockServletContext servletContext() {
|
||||
return mock.servletContext();
|
||||
return this.mock.servletContext();
|
||||
}
|
||||
|
||||
public MockHttpSession session() {
|
||||
return mock.session();
|
||||
return this.mock.session();
|
||||
}
|
||||
|
||||
public void setUp() throws Exception {
|
||||
mock.setUp();
|
||||
this.mock.setUp();
|
||||
}
|
||||
|
||||
public void tearDown() throws Exception {
|
||||
mock.tearDown();
|
||||
this.mock.tearDown();
|
||||
}
|
||||
|
||||
private static class JSFMock extends AbstractJsfTestCase {
|
||||
@@ -120,18 +120,18 @@ public class JSFMockHelper {
|
||||
}
|
||||
|
||||
// Set up a new thread context class loader
|
||||
threadContextClassLoader = Thread.currentThread().getContextClassLoader();
|
||||
this.threadContextClassLoader = Thread.currentThread().getContextClassLoader();
|
||||
Thread.currentThread().setContextClassLoader(
|
||||
new URLClassLoader(new URL[0], this.getClass().getClassLoader()));
|
||||
|
||||
// Set up Servlet API Objects
|
||||
servletContext = new MockServletContext();
|
||||
config = new MockServletConfig(servletContext);
|
||||
session = new MockHttpSession();
|
||||
session.setServletContext(servletContext);
|
||||
request = new MockHttpServletRequest(session);
|
||||
request.setServletContext(servletContext);
|
||||
response = new MockHttpServletResponse();
|
||||
this.servletContext = new MockServletContext();
|
||||
this.config = new MockServletConfig(this.servletContext);
|
||||
this.session = new MockHttpSession();
|
||||
this.session.setServletContext(this.servletContext);
|
||||
this.request = new MockHttpServletRequest(this.session);
|
||||
this.request.setServletContext(this.servletContext);
|
||||
this.response = new MockHttpServletResponse();
|
||||
|
||||
// Set up JSF API Objects
|
||||
FactoryFinder.setFactory(FactoryFinder.APPLICATION_FACTORY, MockApplicationFactory.class.getName());
|
||||
@@ -141,98 +141,98 @@ public class JSFMockHelper {
|
||||
FactoryFinder.setFactory(FactoryFinder.PARTIAL_VIEW_CONTEXT_FACTORY,
|
||||
MockPartialViewContextFactory.class.getName());
|
||||
FactoryFinder.setFactory(FactoryFinder.VISIT_CONTEXT_FACTORY, MockVisitContextFactory.class.getName());
|
||||
lifecycleFactory = (MockLifecycleFactory) FactoryFinder.getFactory(FactoryFinder.LIFECYCLE_FACTORY);
|
||||
lifecycle = (MockLifecycle) lifecycleFactory.getLifecycle(LifecycleFactory.DEFAULT_LIFECYCLE);
|
||||
facesContextFactory = (FacesContextFactory) FactoryFinder.getFactory(FactoryFinder.FACES_CONTEXT_FACTORY);
|
||||
facesContext = facesContextFactory.getFacesContext(servletContext, request, response, lifecycle);
|
||||
externalContext = (MockExternalContext) facesContext.getExternalContext();
|
||||
facesContext.setResponseWriter(new MockResponseWriter(response.getWriter()));
|
||||
this.lifecycleFactory = (MockLifecycleFactory) FactoryFinder.getFactory(FactoryFinder.LIFECYCLE_FACTORY);
|
||||
this.lifecycle = (MockLifecycle) this.lifecycleFactory.getLifecycle(LifecycleFactory.DEFAULT_LIFECYCLE);
|
||||
this.facesContextFactory = (FacesContextFactory) FactoryFinder.getFactory(FactoryFinder.FACES_CONTEXT_FACTORY);
|
||||
this.facesContext = this.facesContextFactory.getFacesContext(this.servletContext, this.request, this.response, this.lifecycle);
|
||||
this.externalContext = (MockExternalContext) this.facesContext.getExternalContext();
|
||||
this.facesContext.setResponseWriter(new MockResponseWriter(this.response.getWriter()));
|
||||
|
||||
UIViewRoot root = new UIViewRoot();
|
||||
root.setViewId("/viewId");
|
||||
root.setRenderKitId(RenderKitFactory.HTML_BASIC_RENDER_KIT);
|
||||
facesContext.setViewRoot(root);
|
||||
this.facesContext.setViewRoot(root);
|
||||
ApplicationFactory applicationFactory = (ApplicationFactory) FactoryFinder
|
||||
.getFactory(FactoryFinder.APPLICATION_FACTORY);
|
||||
application = (org.apache.myfaces.test.mock.MockApplication) applicationFactory.getApplication();
|
||||
this.application = (org.apache.myfaces.test.mock.MockApplication) applicationFactory.getApplication();
|
||||
RenderKitFactory renderKitFactory = (RenderKitFactory) FactoryFinder
|
||||
.getFactory(FactoryFinder.RENDER_KIT_FACTORY);
|
||||
renderKit = new MockRenderKit();
|
||||
renderKitFactory.addRenderKit(RenderKitFactory.HTML_BASIC_RENDER_KIT, renderKit);
|
||||
this.renderKit = new MockRenderKit();
|
||||
renderKitFactory.addRenderKit(RenderKitFactory.HTML_BASIC_RENDER_KIT, this.renderKit);
|
||||
}
|
||||
|
||||
public void tearDown() throws Exception {
|
||||
application = null;
|
||||
config = null;
|
||||
externalContext = null;
|
||||
if (facesContext != null) {
|
||||
facesContext.release();
|
||||
this.application = null;
|
||||
this.config = null;
|
||||
this.externalContext = null;
|
||||
if (this.facesContext != null) {
|
||||
this.facesContext.release();
|
||||
}
|
||||
facesContext = null;
|
||||
lifecycle = null;
|
||||
lifecycleFactory = null;
|
||||
renderKit = null;
|
||||
request = null;
|
||||
response = null;
|
||||
servletContext = null;
|
||||
session = null;
|
||||
this.facesContext = null;
|
||||
this.lifecycle = null;
|
||||
this.lifecycleFactory = null;
|
||||
this.renderKit = null;
|
||||
this.request = null;
|
||||
this.response = null;
|
||||
this.servletContext = null;
|
||||
this.session = null;
|
||||
FactoryFinder.releaseFactories();
|
||||
|
||||
Thread.currentThread().setContextClassLoader(threadContextClassLoader);
|
||||
threadContextClassLoader = null;
|
||||
Thread.currentThread().setContextClassLoader(this.threadContextClassLoader);
|
||||
this.threadContextClassLoader = null;
|
||||
}
|
||||
|
||||
public org.apache.myfaces.test.mock.MockApplication application() {
|
||||
return application;
|
||||
return this.application;
|
||||
}
|
||||
|
||||
public MockServletConfig config() {
|
||||
return config;
|
||||
return this.config;
|
||||
}
|
||||
|
||||
public String contentAsString() throws IOException {
|
||||
MockPrintWriter writer = (MockPrintWriter) response.getWriter();
|
||||
MockPrintWriter writer = (MockPrintWriter) this.response.getWriter();
|
||||
return new String(writer.content());
|
||||
}
|
||||
|
||||
public MockExternalContext externalContext() {
|
||||
return externalContext;
|
||||
return this.externalContext;
|
||||
}
|
||||
|
||||
public FacesContext facesContext() {
|
||||
return facesContext;
|
||||
return this.facesContext;
|
||||
}
|
||||
|
||||
public FacesContextFactory facesContextFactory() {
|
||||
return facesContextFactory;
|
||||
return this.facesContextFactory;
|
||||
}
|
||||
|
||||
public MockLifecycle lifecycle() {
|
||||
return lifecycle;
|
||||
return this.lifecycle;
|
||||
}
|
||||
|
||||
public MockLifecycleFactory lifecycleFactory() {
|
||||
return lifecycleFactory;
|
||||
return this.lifecycleFactory;
|
||||
}
|
||||
|
||||
public MockRenderKit renderKit() {
|
||||
return renderKit;
|
||||
return this.renderKit;
|
||||
}
|
||||
|
||||
public MockHttpServletRequest request() {
|
||||
return request;
|
||||
return this.request;
|
||||
}
|
||||
|
||||
public MockHttpServletResponse response() {
|
||||
return response;
|
||||
return this.response;
|
||||
}
|
||||
|
||||
public MockServletContext servletContext() {
|
||||
return servletContext;
|
||||
return this.servletContext;
|
||||
}
|
||||
|
||||
public MockHttpSession session() {
|
||||
return session;
|
||||
return this.session;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ public class JSFModel {
|
||||
String value;
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
return this.value;
|
||||
}
|
||||
|
||||
public void setValue(String value) {
|
||||
|
||||
@@ -6,27 +6,27 @@ import org.springframework.web.context.support.StaticWebApplicationContext;
|
||||
|
||||
public class JsfAjaxHandlerTests extends TestCase {
|
||||
|
||||
private JSFMockHelper jsfMock = new JSFMockHelper();
|
||||
private final JSFMockHelper jsfMock = new JSFMockHelper();
|
||||
private JsfAjaxHandler ajaxHandler;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
jsfMock.setUp();
|
||||
this.jsfMock.setUp();
|
||||
StaticWebApplicationContext webappContext = new StaticWebApplicationContext();
|
||||
webappContext.setServletContext(jsfMock.servletContext());
|
||||
ajaxHandler = new JsfAjaxHandler();
|
||||
ajaxHandler.setApplicationContext(webappContext);
|
||||
webappContext.setServletContext(this.jsfMock.servletContext());
|
||||
this.ajaxHandler = new JsfAjaxHandler();
|
||||
this.ajaxHandler.setApplicationContext(webappContext);
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
jsfMock.tearDown();
|
||||
this.jsfMock.tearDown();
|
||||
}
|
||||
|
||||
public void testSendAjaxRedirect() throws Exception {
|
||||
ajaxHandler.sendAjaxRedirectInternal("/target", jsfMock.request(), jsfMock.response(), false);
|
||||
this.ajaxHandler.sendAjaxRedirectInternal("/target", this.jsfMock.request(), this.jsfMock.response(), false);
|
||||
assertEquals(
|
||||
"<?xml version='1.0' encoding='utf-8'?>\n<partial-response><redirect url=\"/target\"/></partial-response>",
|
||||
jsfMock.contentAsString());
|
||||
assertEquals("application/xml", jsfMock.response().getContentType());
|
||||
this.jsfMock.contentAsString());
|
||||
assertEquals("application/xml", this.jsfMock.response().getContentType());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -37,11 +37,11 @@ public class JsfFinalResponseActionTests extends TestCase {
|
||||
|
||||
private JsfViewFactory factory;
|
||||
|
||||
private JSFMockHelper jsfMock = new JSFMockHelper();
|
||||
private final JSFMockHelper jsfMock = new JSFMockHelper();
|
||||
|
||||
private RequestContext context = EasyMock.createMock(RequestContext.class);
|
||||
private final RequestContext context = EasyMock.createMock(RequestContext.class);
|
||||
|
||||
private ViewHandler viewHandler = new NoRenderViewHandler();
|
||||
private final ViewHandler viewHandler = new NoRenderViewHandler();
|
||||
|
||||
private TestLifecycle lifecycle;
|
||||
|
||||
@@ -54,29 +54,31 @@ public class JsfFinalResponseActionTests extends TestCase {
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
jsfMock.tearDown();
|
||||
super.tearDown();
|
||||
this.jsfMock.tearDown();
|
||||
RequestContextHolder.setRequestContext(null);
|
||||
}
|
||||
|
||||
private void configureJsf() throws Exception {
|
||||
|
||||
jsfMock.setUp();
|
||||
this.jsfMock.setUp();
|
||||
|
||||
trackingListener = new TrackingPhaseListener();
|
||||
jsfMock.lifecycle().addPhaseListener(trackingListener);
|
||||
jsfMock.facesContext().setViewRoot(null);
|
||||
jsfMock.facesContext().getApplication().setViewHandler(viewHandler);
|
||||
lifecycle = new TestLifecycle(jsfMock.lifecycle());
|
||||
factory = new JsfViewFactory(parser.parseExpression("#{'" + VIEW_ID + "'}", new FluentParserContext()
|
||||
.template().evaluate(RequestContext.class).expectResult(String.class)), lifecycle);
|
||||
RequestContextHolder.setRequestContext(context);
|
||||
this.trackingListener = new TrackingPhaseListener();
|
||||
this.jsfMock.lifecycle().addPhaseListener(this.trackingListener);
|
||||
this.jsfMock.facesContext().setViewRoot(null);
|
||||
this.jsfMock.facesContext().getApplication().setViewHandler(this.viewHandler);
|
||||
this.lifecycle = new TestLifecycle(this.jsfMock.lifecycle());
|
||||
this.factory = new JsfViewFactory(this.parser.parseExpression("#{'" + VIEW_ID + "'}", new FluentParserContext()
|
||||
.template().evaluate(RequestContext.class).expectResult(String.class)), this.lifecycle);
|
||||
RequestContextHolder.setRequestContext(this.context);
|
||||
MockExternalContext ext = new MockExternalContext();
|
||||
ext.setNativeContext(new MockServletContext());
|
||||
ext.setNativeRequest(new MockHttpServletRequest());
|
||||
ext.setNativeResponse(new MockHttpServletResponse());
|
||||
EasyMock.expect(context.getExternalContext()).andStubReturn(ext);
|
||||
EasyMock.expect(this.context.getExternalContext()).andStubReturn(ext);
|
||||
LocalAttributeMap<Object> requestMap = new LocalAttributeMap<Object>();
|
||||
EasyMock.expect(context.getFlashScope()).andStubReturn(requestMap);
|
||||
EasyMock.expect(context.getRequestParameters()).andStubReturn(
|
||||
EasyMock.expect(this.context.getFlashScope()).andStubReturn(requestMap);
|
||||
EasyMock.expect(this.context.getRequestParameters()).andStubReturn(
|
||||
new LocalParameterMap(new HashMap<String, Object>()));
|
||||
}
|
||||
|
||||
@@ -85,18 +87,18 @@ public class JsfFinalResponseActionTests extends TestCase {
|
||||
UIViewRoot newRoot = new UIViewRoot();
|
||||
newRoot.setViewId(VIEW_ID);
|
||||
newRoot.setRenderKitId("HTML_BASIC");
|
||||
((MockViewHandler) viewHandler).setCreateView(newRoot);
|
||||
context.inViewState();
|
||||
((MockViewHandler) this.viewHandler).setCreateView(newRoot);
|
||||
this.context.inViewState();
|
||||
EasyMock.expectLastCall().andReturn(false);
|
||||
|
||||
EasyMock.replay(new Object[] { context });
|
||||
EasyMock.replay(new Object[] { this.context });
|
||||
|
||||
View view = factory.getView(context);
|
||||
View view = this.factory.getView(this.context);
|
||||
((JsfView) view).getViewRoot().setTransient(true);
|
||||
view.render();
|
||||
|
||||
assertTrue(newRoot.isTransient());
|
||||
assertTrue(((NoRenderViewHandler) viewHandler).rendered);
|
||||
assertTrue(((NoRenderViewHandler) this.viewHandler).rendered);
|
||||
}
|
||||
|
||||
private class TestLifecycle extends FlowLifecycle {
|
||||
@@ -108,29 +110,29 @@ public class JsfFinalResponseActionTests extends TestCase {
|
||||
}
|
||||
|
||||
public void execute(FacesContext context) throws FacesException {
|
||||
assertFalse("Lifecycle executed more than once", executed);
|
||||
assertFalse("Lifecycle executed more than once", this.executed);
|
||||
super.execute(context);
|
||||
executed = true;
|
||||
this.executed = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private class TrackingPhaseListener implements PhaseListener {
|
||||
|
||||
private List<String> phaseCallbacks = new ArrayList<String>();
|
||||
private final List<String> phaseCallbacks = new ArrayList<String>();
|
||||
|
||||
public void afterPhase(PhaseEvent event) {
|
||||
String phaseCallback = "AFTER_" + event.getPhaseId();
|
||||
assertFalse("Phase callback " + phaseCallback + " already executed.",
|
||||
phaseCallbacks.contains(phaseCallback));
|
||||
phaseCallbacks.add(phaseCallback);
|
||||
this.phaseCallbacks.contains(phaseCallback));
|
||||
this.phaseCallbacks.add(phaseCallback);
|
||||
}
|
||||
|
||||
public void beforePhase(PhaseEvent event) {
|
||||
String phaseCallback = "BEFORE_" + event.getPhaseId();
|
||||
assertFalse("Phase callback " + phaseCallback + " already executed.",
|
||||
phaseCallbacks.contains(phaseCallback));
|
||||
phaseCallbacks.add(phaseCallback);
|
||||
this.phaseCallbacks.contains(phaseCallback));
|
||||
this.phaseCallbacks.add(phaseCallback);
|
||||
}
|
||||
|
||||
public PhaseId getPhaseId() {
|
||||
@@ -142,7 +144,7 @@ public class JsfFinalResponseActionTests extends TestCase {
|
||||
boolean rendered = false;
|
||||
|
||||
public void renderView(FacesContext context, UIViewRoot viewToRender) throws IOException, FacesException {
|
||||
rendered = true;
|
||||
this.rendered = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -19,22 +19,22 @@ public class JsfFlowHandlerAdapterTests extends TestCase {
|
||||
protected void setUp() throws Exception {
|
||||
StaticWebApplicationContext context = new StaticWebApplicationContext();
|
||||
context.setServletContext(new MockServletContext());
|
||||
handlerAdapter = new JsfFlowHandlerAdapter();
|
||||
handlerAdapter.setApplicationContext(context);
|
||||
handlerAdapter.setFlowExecutor(new StubFlowExecutor());
|
||||
this.handlerAdapter = new JsfFlowHandlerAdapter();
|
||||
this.handlerAdapter.setApplicationContext(context);
|
||||
this.handlerAdapter.setFlowExecutor(new StubFlowExecutor());
|
||||
}
|
||||
|
||||
public void testAjaxHandlerNotProvided() throws Exception {
|
||||
handlerAdapter.afterPropertiesSet();
|
||||
assertNotNull(handlerAdapter.getAjaxHandler());
|
||||
assertTrue(handlerAdapter.getAjaxHandler() instanceof JsfAjaxHandler);
|
||||
this.handlerAdapter.afterPropertiesSet();
|
||||
assertNotNull(this.handlerAdapter.getAjaxHandler());
|
||||
assertTrue(this.handlerAdapter.getAjaxHandler() instanceof JsfAjaxHandler);
|
||||
}
|
||||
|
||||
public void testAjaxHandlerProvided() throws Exception {
|
||||
AjaxHandler myAjaxHandler = new SpringJavascriptAjaxHandler();
|
||||
handlerAdapter.setAjaxHandler(myAjaxHandler);
|
||||
handlerAdapter.afterPropertiesSet();
|
||||
assertTrue(myAjaxHandler == handlerAdapter.getAjaxHandler());
|
||||
this.handlerAdapter.setAjaxHandler(myAjaxHandler);
|
||||
this.handlerAdapter.afterPropertiesSet();
|
||||
assertTrue(myAjaxHandler == this.handlerAdapter.getAjaxHandler());
|
||||
}
|
||||
|
||||
private final class StubFlowExecutor implements FlowExecutor {
|
||||
|
||||
@@ -19,19 +19,21 @@ public class JsfManagedBeanAwareELExpressionParserTests extends TestCase {
|
||||
ExpressionParser parser;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
jsfMock.setUp();
|
||||
RequestContextHolder.setRequestContext(requestContext);
|
||||
parser = new JsfManagedBeanAwareELExpressionParser(new ExpressionFactoryImpl());
|
||||
this.jsfMock.setUp();
|
||||
RequestContextHolder.setRequestContext(this.requestContext);
|
||||
this.parser = new JsfManagedBeanAwareELExpressionParser(new ExpressionFactoryImpl());
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
jsfMock.tearDown();
|
||||
super.tearDown();
|
||||
this.jsfMock.tearDown();
|
||||
RequestContextHolder.setRequestContext(null);
|
||||
}
|
||||
|
||||
public void testGetJSFBean() {
|
||||
jsfMock.externalContext().getRequestMap().put("myJsfBean", new Object());
|
||||
Expression expr = parser.parseExpression("myJsfBean", new FluentParserContext().evaluate(RequestContext.class));
|
||||
Object result = expr.getValue(requestContext);
|
||||
this.jsfMock.externalContext().getRequestMap().put("myJsfBean", new Object());
|
||||
Expression expr = this.parser.parseExpression("myJsfBean", new FluentParserContext().evaluate(RequestContext.class));
|
||||
Object result = expr.getValue(this.requestContext);
|
||||
assertNotNull("The JSF Bean should not be null.", result);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,42 +30,44 @@ public class JsfManagedBeanPropertyAccessorTests extends TestCase {
|
||||
private MockRequestContext requestContext;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
jsfMock.setUp();
|
||||
requestContext = new MockRequestContext();
|
||||
RequestContextHolder.setRequestContext(requestContext);
|
||||
this.jsfMock.setUp();
|
||||
this.requestContext = new MockRequestContext();
|
||||
RequestContextHolder.setRequestContext(this.requestContext);
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
jsfMock.tearDown();
|
||||
super.tearDown();
|
||||
this.jsfMock.tearDown();
|
||||
RequestContextHolder.setRequestContext(null);
|
||||
}
|
||||
|
||||
public void testCanRead() throws Exception {
|
||||
jsfMock.externalContext().getRequestMap().put("myJsfBean", new Object());
|
||||
assertTrue(accessor.canRead(null, null, "myJsfBean"));
|
||||
this.jsfMock.externalContext().getRequestMap().put("myJsfBean", new Object());
|
||||
assertTrue(this.accessor.canRead(null, null, "myJsfBean"));
|
||||
}
|
||||
|
||||
public void testRead() throws Exception {
|
||||
Object jsfBean = new Object();
|
||||
jsfMock.externalContext().getRequestMap().put("myJsfBean", jsfBean);
|
||||
assertEquals(jsfBean, accessor.read(null, null, "myJsfBean").getValue());
|
||||
this.jsfMock.externalContext().getRequestMap().put("myJsfBean", jsfBean);
|
||||
assertEquals(jsfBean, this.accessor.read(null, null, "myJsfBean").getValue());
|
||||
}
|
||||
|
||||
public void testCanWrite() throws Exception {
|
||||
assertFalse(accessor.canWrite(null, null, "myJsfBean"));
|
||||
assertFalse(this.accessor.canWrite(null, null, "myJsfBean"));
|
||||
|
||||
MutableAttributeMap<Object> map = requestContext.getExternalContext().getRequestMap();
|
||||
MutableAttributeMap<Object> map = this.requestContext.getExternalContext().getRequestMap();
|
||||
map.put("myJsfBean", new Object());
|
||||
assertTrue(accessor.canWrite(null, null, "myJsfBean"));
|
||||
assertTrue(this.accessor.canWrite(null, null, "myJsfBean"));
|
||||
map.clear();
|
||||
|
||||
map = requestContext.getExternalContext().getSessionMap();
|
||||
map = this.requestContext.getExternalContext().getSessionMap();
|
||||
map.put("myJsfBean", new Object());
|
||||
assertTrue(accessor.canWrite(null, null, "myJsfBean"));
|
||||
assertTrue(this.accessor.canWrite(null, null, "myJsfBean"));
|
||||
map.clear();
|
||||
|
||||
map = requestContext.getExternalContext().getApplicationMap();
|
||||
map = this.requestContext.getExternalContext().getApplicationMap();
|
||||
map.put("myJsfBean", new Object());
|
||||
assertTrue(accessor.canWrite(null, null, "myJsfBean"));
|
||||
assertTrue(this.accessor.canWrite(null, null, "myJsfBean"));
|
||||
map.clear();
|
||||
}
|
||||
|
||||
@@ -73,12 +75,12 @@ public class JsfManagedBeanPropertyAccessorTests extends TestCase {
|
||||
Object jsfBean1 = new Object();
|
||||
Object jsfBean2 = new Object();
|
||||
|
||||
MutableAttributeMap<Object> map = requestContext.getExternalContext().getRequestMap();
|
||||
accessor.write(null, null, "myJsfBean", jsfBean1);
|
||||
MutableAttributeMap<Object> map = this.requestContext.getExternalContext().getRequestMap();
|
||||
this.accessor.write(null, null, "myJsfBean", jsfBean1);
|
||||
assertNull("Write occurs only if bean is present in the map", map.get("myJsfBean"));
|
||||
|
||||
map.put("myJsfBean", jsfBean1);
|
||||
accessor.write(null, null, "myJsfBean", jsfBean2);
|
||||
this.accessor.write(null, null, "myJsfBean", jsfBean2);
|
||||
assertEquals(jsfBean2, map.get("myJsfBean"));
|
||||
map.clear();
|
||||
}
|
||||
|
||||
@@ -1,18 +1,30 @@
|
||||
package org.springframework.faces.webflow;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.faces.application.ApplicationFactory;
|
||||
import javax.faces.context.FacesContextFactory;
|
||||
import javax.faces.event.PhaseEvent;
|
||||
import javax.faces.event.PhaseId;
|
||||
import javax.faces.event.PhaseListener;
|
||||
import javax.faces.lifecycle.LifecycleFactory;
|
||||
import javax.faces.render.RenderKitFactory;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.apache.myfaces.test.base.AbstractJsfTestCase;
|
||||
import org.apache.myfaces.test.mock.MockApplicationFactory;
|
||||
import org.apache.myfaces.test.mock.MockFacesContext20;
|
||||
import org.apache.myfaces.test.mock.MockFacesContextFactory;
|
||||
import org.apache.myfaces.test.mock.MockRenderKitFactory;
|
||||
import org.apache.myfaces.test.mock.lifecycle.MockLifecycle;
|
||||
import org.apache.myfaces.test.mock.lifecycle.MockLifecycleFactory;
|
||||
|
||||
public class JsfUtilsTests extends TestCase {
|
||||
public class JsfUtilsTests extends AbstractJsfTestCase {
|
||||
|
||||
public JsfUtilsTests(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
public void testBeforeListenersCalledInForwardOrder() throws Exception {
|
||||
List<OrderVerifyingPhaseListener> list = new ArrayList<OrderVerifyingPhaseListener>();
|
||||
@@ -44,10 +56,27 @@ public class JsfUtilsTests extends TestCase {
|
||||
assertEquals(listener1, list.get(2));
|
||||
}
|
||||
|
||||
public void testGetFactory() throws Exception {
|
||||
// Not testing all but at least test the mocked factories
|
||||
assertTrue(JsfUtils.findFactory(ApplicationFactory.class) instanceof MockApplicationFactory);
|
||||
assertTrue(JsfUtils.findFactory(FacesContextFactory.class) instanceof MockFacesContextFactory);
|
||||
assertTrue(JsfUtils.findFactory(LifecycleFactory.class) instanceof MockLifecycleFactory);
|
||||
assertTrue(JsfUtils.findFactory(RenderKitFactory.class) instanceof MockRenderKitFactory);
|
||||
}
|
||||
|
||||
public void testGetUnknowFactory() throws Exception {
|
||||
try {
|
||||
JsfUtils.findFactory(InputStream.class);
|
||||
fail("Did not throw");
|
||||
} catch (IllegalStateException e) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
private class OrderVerifyingPhaseListener implements PhaseListener {
|
||||
|
||||
private List<OrderVerifyingPhaseListener> afterPhaseList;
|
||||
private List<OrderVerifyingPhaseListener> beforePhaseList;
|
||||
private final List<OrderVerifyingPhaseListener> afterPhaseList;
|
||||
private final List<OrderVerifyingPhaseListener> beforePhaseList;
|
||||
|
||||
public OrderVerifyingPhaseListener(List<OrderVerifyingPhaseListener> afterPhaseList,
|
||||
List<OrderVerifyingPhaseListener> beforePhaseList) {
|
||||
@@ -56,11 +85,11 @@ public class JsfUtilsTests extends TestCase {
|
||||
}
|
||||
|
||||
public void afterPhase(PhaseEvent event) {
|
||||
afterPhaseList.add(this);
|
||||
this.afterPhaseList.add(this);
|
||||
}
|
||||
|
||||
public void beforePhase(PhaseEvent event) {
|
||||
beforePhaseList.add(this);
|
||||
this.beforePhaseList.add(this);
|
||||
}
|
||||
|
||||
public PhaseId getPhaseId() {
|
||||
|
||||
@@ -50,52 +50,54 @@ public class JsfViewFactoryTests extends TestCase {
|
||||
|
||||
private ViewFactory factory;
|
||||
|
||||
private JSFMockHelper jsfMock = new JSFMockHelper();
|
||||
private final JSFMockHelper jsfMock = new JSFMockHelper();
|
||||
|
||||
private RequestContext context = EasyMock.createMock(RequestContext.class);
|
||||
private final RequestContext context = EasyMock.createMock(RequestContext.class);
|
||||
|
||||
private LocalAttributeMap<Object> flashMap = new LocalAttributeMap<Object>();
|
||||
private final LocalAttributeMap<Object> flashMap = new LocalAttributeMap<Object>();
|
||||
|
||||
private ViewHandler viewHandler = new MockViewHandler();
|
||||
private final ViewHandler viewHandler = new MockViewHandler();
|
||||
|
||||
private Lifecycle lifecycle;
|
||||
|
||||
private PhaseListener trackingListener;
|
||||
|
||||
private ExpressionParser parser = new WebFlowELExpressionParser(new ExpressionFactoryImpl());
|
||||
private final ExpressionParser parser = new WebFlowELExpressionParser(new ExpressionFactoryImpl());
|
||||
|
||||
private MockExternalContext extContext = new MockExternalContext();
|
||||
private final MockExternalContext extContext = new MockExternalContext();
|
||||
|
||||
private MockServletContext servletContext = new MockServletContext();
|
||||
private final MockServletContext servletContext = new MockServletContext();
|
||||
|
||||
private MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
private final MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
|
||||
private MockHttpServletResponse response = new MockHttpServletResponse();
|
||||
private final MockHttpServletResponse response = new MockHttpServletResponse();
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
configureJsf();
|
||||
extContext.setNativeContext(servletContext);
|
||||
extContext.setNativeRequest(request);
|
||||
extContext.setNativeResponse(response);
|
||||
RequestContextHolder.setRequestContext(context);
|
||||
EasyMock.expect(context.getFlashScope()).andStubReturn(flashMap);
|
||||
EasyMock.expect(context.getExternalContext()).andStubReturn(extContext);
|
||||
EasyMock.expect(context.getRequestParameters()).andStubReturn(
|
||||
this.extContext.setNativeContext(this.servletContext);
|
||||
this.extContext.setNativeRequest(this.request);
|
||||
this.extContext.setNativeResponse(this.response);
|
||||
RequestContextHolder.setRequestContext(this.context);
|
||||
EasyMock.expect(this.context.getFlashScope()).andStubReturn(this.flashMap);
|
||||
EasyMock.expect(this.context.getExternalContext()).andStubReturn(this.extContext);
|
||||
EasyMock.expect(this.context.getRequestParameters()).andStubReturn(
|
||||
new LocalParameterMap(new HashMap<String, Object>()));
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
jsfMock.tearDown();
|
||||
super.tearDown();
|
||||
this.jsfMock.tearDown();
|
||||
RequestContextHolder.setRequestContext(null);
|
||||
}
|
||||
|
||||
private void configureJsf() throws Exception {
|
||||
jsfMock.setUp();
|
||||
this.jsfMock.setUp();
|
||||
ExceptionEventAwareMockApplication application = new ExceptionEventAwareMockApplication();
|
||||
((MockBaseFacesContext) FlowFacesContext.getCurrentInstance()).setApplication(application);
|
||||
trackingListener = new TrackingPhaseListener();
|
||||
jsfMock.lifecycle().addPhaseListener(trackingListener);
|
||||
jsfMock.facesContext().setViewRoot(null);
|
||||
jsfMock.facesContext().getApplication().setViewHandler(viewHandler);
|
||||
this.trackingListener = new TrackingPhaseListener();
|
||||
this.jsfMock.lifecycle().addPhaseListener(this.trackingListener);
|
||||
this.jsfMock.facesContext().setViewRoot(null);
|
||||
this.jsfMock.facesContext().getApplication().setViewHandler(this.viewHandler);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -103,20 +105,20 @@ public class JsfViewFactoryTests extends TestCase {
|
||||
*/
|
||||
public final void testGetView_Create() {
|
||||
|
||||
lifecycle = new NoExecutionLifecycle(jsfMock.lifecycle());
|
||||
factory = new JsfViewFactory(parser.parseExpression(VIEW_ID,
|
||||
this.lifecycle = new NoExecutionLifecycle(this.jsfMock.lifecycle());
|
||||
this.factory = new JsfViewFactory(this.parser.parseExpression(VIEW_ID,
|
||||
new FluentParserContext().template().evaluate(RequestContext.class).expectResult(String.class)),
|
||||
lifecycle);
|
||||
this.lifecycle);
|
||||
|
||||
MockUIViewRoot newRoot = new MockUIViewRoot();
|
||||
newRoot.setViewId(VIEW_ID);
|
||||
((MockViewHandler) viewHandler).setCreateView(newRoot);
|
||||
context.inViewState();
|
||||
((MockViewHandler) this.viewHandler).setCreateView(newRoot);
|
||||
this.context.inViewState();
|
||||
EasyMock.expectLastCall().andReturn(true);
|
||||
|
||||
EasyMock.replay(new Object[] { context });
|
||||
EasyMock.replay(new Object[] { this.context });
|
||||
|
||||
View newView = factory.getView(context);
|
||||
View newView = this.factory.getView(this.context);
|
||||
|
||||
assertNotNull("A View was not created", newView);
|
||||
assertTrue("A JsfView was expected", newView instanceof JsfView);
|
||||
@@ -129,10 +131,10 @@ public class JsfViewFactoryTests extends TestCase {
|
||||
*/
|
||||
public final void testGetView_Restore() {
|
||||
|
||||
lifecycle = new NoExecutionLifecycle(jsfMock.lifecycle());
|
||||
factory = new JsfViewFactory(parser.parseExpression(VIEW_ID,
|
||||
this.lifecycle = new NoExecutionLifecycle(this.jsfMock.lifecycle());
|
||||
this.factory = new JsfViewFactory(this.parser.parseExpression(VIEW_ID,
|
||||
new FluentParserContext().template().evaluate(RequestContext.class).expectResult(String.class)),
|
||||
lifecycle);
|
||||
this.lifecycle);
|
||||
|
||||
MockUIViewRoot existingRoot = new MockUIViewRoot();
|
||||
existingRoot.setViewId(VIEW_ID);
|
||||
@@ -140,14 +142,14 @@ public class JsfViewFactoryTests extends TestCase {
|
||||
input.setId("invalidInput");
|
||||
input.setValid(false);
|
||||
existingRoot.getChildren().add(input);
|
||||
((MockViewHandler) viewHandler).setRestoreView(existingRoot);
|
||||
((MockViewHandler) this.viewHandler).setRestoreView(existingRoot);
|
||||
|
||||
context.inViewState();
|
||||
this.context.inViewState();
|
||||
EasyMock.expectLastCall().andReturn(true);
|
||||
|
||||
EasyMock.replay(new Object[] { context });
|
||||
EasyMock.replay(new Object[] { this.context });
|
||||
|
||||
View restoredView = factory.getView(context);
|
||||
View restoredView = this.factory.getView(this.context);
|
||||
|
||||
assertNotNull("A View was not restored", restoredView);
|
||||
assertTrue("A JsfView was expected", restoredView instanceof JsfView);
|
||||
@@ -162,21 +164,21 @@ public class JsfViewFactoryTests extends TestCase {
|
||||
*/
|
||||
public final void testGetView_RestoreWithBindings() {
|
||||
|
||||
lifecycle = new NoExecutionLifecycle(jsfMock.lifecycle());
|
||||
factory = new JsfViewFactory(parser.parseExpression(VIEW_ID,
|
||||
this.lifecycle = new NoExecutionLifecycle(this.jsfMock.lifecycle());
|
||||
this.factory = new JsfViewFactory(this.parser.parseExpression(VIEW_ID,
|
||||
new FluentParserContext().template().evaluate(RequestContext.class).expectResult(String.class)),
|
||||
lifecycle);
|
||||
this.lifecycle);
|
||||
|
||||
MockUIViewRoot existingRoot = new MockUIViewRoot();
|
||||
existingRoot.setViewId(VIEW_ID);
|
||||
UIPanel panel = new UIPanel();
|
||||
panel.setId("panel1");
|
||||
UIOutput output = new UIOutput();
|
||||
output.setValueBinding("binding", jsfMock.facesContext().getApplication()
|
||||
output.setValueBinding("binding", this.jsfMock.facesContext().getApplication()
|
||||
.createValueBinding("#{myBean.output}"));
|
||||
output.setId("output1");
|
||||
UIInput input = new UIInput();
|
||||
input.setValueBinding("binding", jsfMock.facesContext().getApplication().createValueBinding("#{myBean.input}"));
|
||||
input.setValueBinding("binding", this.jsfMock.facesContext().getApplication().createValueBinding("#{myBean.input}"));
|
||||
input.setId("input1");
|
||||
|
||||
existingRoot.getChildren().add(panel);
|
||||
@@ -184,16 +186,16 @@ public class JsfViewFactoryTests extends TestCase {
|
||||
panel.getChildren().add(input);
|
||||
|
||||
TestBean testBean = new TestBean();
|
||||
jsfMock.externalContext().getRequestMap().put("myBean", testBean);
|
||||
this.jsfMock.externalContext().getRequestMap().put("myBean", testBean);
|
||||
|
||||
((MockViewHandler) viewHandler).setRestoreView(existingRoot);
|
||||
((MockViewHandler) this.viewHandler).setRestoreView(existingRoot);
|
||||
|
||||
context.inViewState();
|
||||
this.context.inViewState();
|
||||
EasyMock.expectLastCall().andReturn(true);
|
||||
|
||||
EasyMock.replay(new Object[] { context });
|
||||
EasyMock.replay(new Object[] { this.context });
|
||||
|
||||
View restoredView = factory.getView(context);
|
||||
View restoredView = this.factory.getView(this.context);
|
||||
|
||||
assertNotNull("A View was not restored", restoredView);
|
||||
assertTrue("A JsfView was expected", restoredView instanceof JsfView);
|
||||
@@ -210,25 +212,25 @@ public class JsfViewFactoryTests extends TestCase {
|
||||
*/
|
||||
public final void testGetView_Restore_Ajax() {
|
||||
|
||||
lifecycle = new NoExecutionLifecycle(jsfMock.lifecycle());
|
||||
factory = new JsfViewFactory(parser.parseExpression(VIEW_ID,
|
||||
this.lifecycle = new NoExecutionLifecycle(this.jsfMock.lifecycle());
|
||||
this.factory = new JsfViewFactory(this.parser.parseExpression(VIEW_ID,
|
||||
new FluentParserContext().template().evaluate(RequestContext.class).expectResult(String.class)),
|
||||
lifecycle);
|
||||
this.lifecycle);
|
||||
|
||||
MockUIViewRoot existingRoot = new MockUIViewRoot();
|
||||
existingRoot.setViewId(VIEW_ID);
|
||||
((MockViewHandler) viewHandler).setRestoreView(existingRoot);
|
||||
((MockViewHandler) this.viewHandler).setRestoreView(existingRoot);
|
||||
|
||||
request.addHeader("Accept", "text/html;type=ajax");
|
||||
this.request.addHeader("Accept", "text/html;type=ajax");
|
||||
|
||||
EasyMock.expect(context.getCurrentState()).andReturn(new NormalViewState());
|
||||
EasyMock.expect(this.context.getCurrentState()).andReturn(new NormalViewState());
|
||||
|
||||
context.inViewState();
|
||||
this.context.inViewState();
|
||||
EasyMock.expectLastCall().andReturn(true);
|
||||
|
||||
EasyMock.replay(new Object[] { context });
|
||||
EasyMock.replay(new Object[] { this.context });
|
||||
|
||||
View restoredView = factory.getView(context);
|
||||
View restoredView = this.factory.getView(this.context);
|
||||
|
||||
assertNotNull("A View was not restored", restoredView);
|
||||
assertTrue("A JsfView was expected", restoredView instanceof JsfView);
|
||||
@@ -242,19 +244,19 @@ public class JsfViewFactoryTests extends TestCase {
|
||||
* Third party sets the view root before RESTORE_VIEW
|
||||
*/
|
||||
public final void testGetView_ExternalViewRoot() {
|
||||
lifecycle = new NoExecutionLifecycle(jsfMock.lifecycle());
|
||||
factory = new JsfViewFactory(parser.parseExpression(VIEW_ID,
|
||||
this.lifecycle = new NoExecutionLifecycle(this.jsfMock.lifecycle());
|
||||
this.factory = new JsfViewFactory(this.parser.parseExpression(VIEW_ID,
|
||||
new FluentParserContext().template().evaluate(RequestContext.class).expectResult(String.class)),
|
||||
lifecycle);
|
||||
this.lifecycle);
|
||||
|
||||
MockUIViewRoot newRoot = new MockUIViewRoot();
|
||||
newRoot.setViewId(VIEW_ID);
|
||||
jsfMock.facesContext().setViewRoot(newRoot);
|
||||
jsfMock.facesContext().renderResponse();
|
||||
this.jsfMock.facesContext().setViewRoot(newRoot);
|
||||
this.jsfMock.facesContext().renderResponse();
|
||||
|
||||
EasyMock.replay(new Object[] { context });
|
||||
EasyMock.replay(new Object[] { this.context });
|
||||
|
||||
View newView = factory.getView(context);
|
||||
View newView = this.factory.getView(this.context);
|
||||
|
||||
assertNotNull("A View was not created", newView);
|
||||
assertTrue("A JsfView was expected", newView instanceof JsfView);
|
||||
@@ -265,21 +267,21 @@ public class JsfViewFactoryTests extends TestCase {
|
||||
}
|
||||
|
||||
public void testGetView_ExceptionsOnPostRestoreStateEvent() throws Exception {
|
||||
lifecycle = new NoExecutionLifecycle(jsfMock.lifecycle());
|
||||
factory = new JsfViewFactory(parser.parseExpression(VIEW_ID,
|
||||
this.lifecycle = new NoExecutionLifecycle(this.jsfMock.lifecycle());
|
||||
this.factory = new JsfViewFactory(this.parser.parseExpression(VIEW_ID,
|
||||
new FluentParserContext().template().evaluate(RequestContext.class).expectResult(String.class)),
|
||||
lifecycle);
|
||||
this.lifecycle);
|
||||
|
||||
MockUIViewRoot existingRoot = new MockUIViewRoot();
|
||||
existingRoot.setThrowOnPostRestoreStateEvent(true);
|
||||
existingRoot.setViewId(VIEW_ID);
|
||||
((MockViewHandler) viewHandler).setRestoreView(existingRoot);
|
||||
((MockViewHandler) this.viewHandler).setRestoreView(existingRoot);
|
||||
|
||||
context.inViewState();
|
||||
this.context.inViewState();
|
||||
EasyMock.expectLastCall().andReturn(true);
|
||||
|
||||
EasyMock.replay(new Object[] { context });
|
||||
factory.getView(context);
|
||||
EasyMock.replay(new Object[] { this.context });
|
||||
this.factory.getView(this.context);
|
||||
ExceptionEventAwareMockApplication application = (ExceptionEventAwareMockApplication) FlowFacesContext
|
||||
.getCurrentInstance().getApplication();
|
||||
assertNotNull("Expected exception event", application.getExceptionQueuedEventContext());
|
||||
@@ -300,20 +302,20 @@ public class JsfViewFactoryTests extends TestCase {
|
||||
|
||||
private class TrackingPhaseListener implements PhaseListener {
|
||||
|
||||
private List<String> phaseCallbacks = new ArrayList<String>();
|
||||
private final List<String> phaseCallbacks = new ArrayList<String>();
|
||||
|
||||
public void afterPhase(PhaseEvent event) {
|
||||
String phaseCallback = "AFTER_" + event.getPhaseId();
|
||||
assertFalse("Phase callback " + phaseCallback + " already executed.",
|
||||
phaseCallbacks.contains(phaseCallback));
|
||||
phaseCallbacks.add(phaseCallback);
|
||||
this.phaseCallbacks.contains(phaseCallback));
|
||||
this.phaseCallbacks.add(phaseCallback);
|
||||
}
|
||||
|
||||
public void beforePhase(PhaseEvent event) {
|
||||
String phaseCallback = "BEFORE_" + event.getPhaseId();
|
||||
assertFalse("Phase callback " + phaseCallback + " already executed.",
|
||||
phaseCallbacks.contains(phaseCallback));
|
||||
phaseCallbacks.add(phaseCallback);
|
||||
this.phaseCallbacks.contains(phaseCallback));
|
||||
this.phaseCallbacks.add(phaseCallback);
|
||||
}
|
||||
|
||||
public PhaseId getPhaseId() {
|
||||
@@ -354,7 +356,7 @@ public class JsfViewFactoryTests extends TestCase {
|
||||
UIInput input;
|
||||
|
||||
public UIOutput getOutput() {
|
||||
return output;
|
||||
return this.output;
|
||||
}
|
||||
|
||||
public void setOutput(UIOutput output) {
|
||||
@@ -362,7 +364,7 @@ public class JsfViewFactoryTests extends TestCase {
|
||||
}
|
||||
|
||||
public UIInput getInput() {
|
||||
return input;
|
||||
return this.input;
|
||||
}
|
||||
|
||||
public void setInput(UIInput input) {
|
||||
@@ -379,10 +381,10 @@ public class JsfViewFactoryTests extends TestCase {
|
||||
public void processEvent(ComponentSystemEvent event) throws AbortProcessingException {
|
||||
if (event instanceof PostRestoreStateEvent) {
|
||||
assertSame("Component did not match", this, ((PostRestoreStateEvent) event).getComponent());
|
||||
postRestoreStateEventSeen = true;
|
||||
if (throwOnPostRestoreStateEvent) {
|
||||
abortProcessingException = new AbortProcessingException();
|
||||
throw abortProcessingException;
|
||||
this.postRestoreStateEventSeen = true;
|
||||
if (this.throwOnPostRestoreStateEvent) {
|
||||
this.abortProcessingException = new AbortProcessingException();
|
||||
throw this.abortProcessingException;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -392,11 +394,11 @@ public class JsfViewFactoryTests extends TestCase {
|
||||
}
|
||||
|
||||
public boolean isPostRestoreStateEventSeen() {
|
||||
return postRestoreStateEventSeen;
|
||||
return this.postRestoreStateEventSeen;
|
||||
}
|
||||
|
||||
public AbortProcessingException getAbortProcessingException() {
|
||||
return abortProcessingException;
|
||||
return this.abortProcessingException;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -413,7 +415,7 @@ public class JsfViewFactoryTests extends TestCase {
|
||||
}
|
||||
|
||||
public ExceptionQueuedEventContext getExceptionQueuedEventContext() {
|
||||
return exceptionQueuedEventContext;
|
||||
return this.exceptionQueuedEventContext;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,24 +30,24 @@ public class JsfViewTests extends TestCase {
|
||||
|
||||
private static final String VIEW_ID = "testView.xhtml";
|
||||
|
||||
private MockExternalContext extContext = new MockExternalContext();
|
||||
private final MockExternalContext extContext = new MockExternalContext();
|
||||
|
||||
private JsfView view;
|
||||
|
||||
private JSFMockHelper jsfMock = new JSFMockHelper();
|
||||
private final JSFMockHelper jsfMock = new JSFMockHelper();
|
||||
|
||||
private StringWriter output = new StringWriter();
|
||||
private final StringWriter output = new StringWriter();
|
||||
|
||||
private String event = "foo";
|
||||
private final String event = "foo";
|
||||
|
||||
private RequestContext context = EasyMock.createMock(RequestContext.class);
|
||||
private FlowExecutionContext flowExecutionContext = EasyMock.createMock(FlowExecutionContext.class);
|
||||
private final RequestContext context = EasyMock.createMock(RequestContext.class);
|
||||
private final FlowExecutionContext flowExecutionContext = EasyMock.createMock(FlowExecutionContext.class);
|
||||
@SuppressWarnings("unchecked")
|
||||
private MutableAttributeMap<Object> flashScope = EasyMock.createMock(MutableAttributeMap.class);
|
||||
private final MutableAttributeMap<Object> flashScope = EasyMock.createMock(MutableAttributeMap.class);
|
||||
@SuppressWarnings("unchecked")
|
||||
private MutableAttributeMap<Object> flowMap = EasyMock.createMock(MutableAttributeMap.class);
|
||||
private final MutableAttributeMap<Object> flowMap = EasyMock.createMock(MutableAttributeMap.class);
|
||||
|
||||
private FlowExecutionKey key = new FlowExecutionKey() {
|
||||
private final FlowExecutionKey key = new FlowExecutionKey() {
|
||||
|
||||
public String toString() {
|
||||
return "MOCK_KEY";
|
||||
@@ -64,15 +64,15 @@ public class JsfViewTests extends TestCase {
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
|
||||
jsfMock.setUp();
|
||||
jsfMock.facesContext().getApplication().setViewHandler(new MockViewHandler());
|
||||
jsfMock.facesContext().getApplication().setStateManager(new TestStateManager());
|
||||
jsfMock.facesContext().setResponseWriter(new MockResponseWriter(output, null, null));
|
||||
this.jsfMock.setUp();
|
||||
this.jsfMock.facesContext().getApplication().setViewHandler(new MockViewHandler());
|
||||
this.jsfMock.facesContext().getApplication().setStateManager(new TestStateManager());
|
||||
this.jsfMock.facesContext().setResponseWriter(new MockResponseWriter(this.output, null, null));
|
||||
|
||||
UIViewRoot viewToRender = new UIViewRoot();
|
||||
viewToRender.setRenderKitId("HTML_BASIC");
|
||||
viewToRender.setViewId(VIEW_ID);
|
||||
jsfMock.facesContext().setViewRoot(viewToRender);
|
||||
this.jsfMock.facesContext().setViewRoot(viewToRender);
|
||||
|
||||
UIForm form = new HtmlForm();
|
||||
form.setId("myForm");
|
||||
@@ -83,52 +83,54 @@ public class JsfViewTests extends TestCase {
|
||||
form.getChildren().add(input);
|
||||
viewToRender.getChildren().add(form);
|
||||
|
||||
RequestContextHolder.setRequestContext(context);
|
||||
EasyMock.expect(context.getExternalContext()).andStubReturn(extContext);
|
||||
EasyMock.expect(context.getFlashScope()).andStubReturn(flashScope);
|
||||
EasyMock.expect(context.getFlowScope()).andStubReturn(flowMap);
|
||||
EasyMock.expect(context.getFlowExecutionContext()).andStubReturn(flowExecutionContext);
|
||||
EasyMock.expect(flowExecutionContext.getKey()).andStubReturn(key);
|
||||
RequestContextHolder.setRequestContext(this.context);
|
||||
EasyMock.expect(this.context.getExternalContext()).andStubReturn(this.extContext);
|
||||
EasyMock.expect(this.context.getFlashScope()).andStubReturn(this.flashScope);
|
||||
EasyMock.expect(this.context.getFlowScope()).andStubReturn(this.flowMap);
|
||||
EasyMock.expect(this.context.getFlowExecutionContext()).andStubReturn(this.flowExecutionContext);
|
||||
EasyMock.expect(this.flowExecutionContext.getKey()).andStubReturn(this.key);
|
||||
|
||||
view = new JsfView(viewToRender, jsfMock.lifecycle(), context);
|
||||
this.view = new JsfView(viewToRender, this.jsfMock.lifecycle(), this.context);
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
jsfMock.tearDown();
|
||||
super.tearDown();
|
||||
this.jsfMock.tearDown();
|
||||
RequestContextHolder.setRequestContext(null);
|
||||
}
|
||||
|
||||
public final void testSaveState() {
|
||||
EasyMock.replay(new Object[] { context, flowExecutionContext, flowMap, flashScope });
|
||||
view.saveState();
|
||||
EasyMock.replay(new Object[] { this.context, this.flowExecutionContext, this.flowMap, this.flashScope });
|
||||
this.view.saveState();
|
||||
}
|
||||
|
||||
public final void testSaveState_AjaxViewRoot() {
|
||||
EasyMock.replay(new Object[] { context, flowExecutionContext, flowMap, flashScope });
|
||||
view.setViewRoot(new AjaxViewRoot(view.getViewRoot()));
|
||||
view.saveState();
|
||||
EasyMock.replay(new Object[] { this.context, this.flowExecutionContext, this.flowMap, this.flashScope });
|
||||
this.view.setViewRoot(new AjaxViewRoot(this.view.getViewRoot()));
|
||||
this.view.saveState();
|
||||
}
|
||||
|
||||
public final void testRender() throws IOException {
|
||||
|
||||
EasyMock.expect(flashScope.put(EasyMock.matches(FlowFacesContext.RENDER_RESPONSE_KEY), EasyMock.anyObject()))
|
||||
EasyMock.expect(this.flashScope.put(EasyMock.matches(FlowFacesContext.RENDER_RESPONSE_KEY), EasyMock.anyObject()))
|
||||
.andStubReturn(null);
|
||||
|
||||
EasyMock.replay(new Object[] { context, flowExecutionContext, flowMap, flashScope });
|
||||
EasyMock.replay(new Object[] { this.context, this.flowExecutionContext, this.flowMap, this.flashScope });
|
||||
|
||||
view.render();
|
||||
this.view.render();
|
||||
}
|
||||
|
||||
public final void testRenderException() throws IOException {
|
||||
|
||||
EasyMock.expect(flashScope.put(EasyMock.matches(FlowFacesContext.RENDER_RESPONSE_KEY), EasyMock.anyObject()))
|
||||
EasyMock.expect(this.flashScope.put(EasyMock.matches(FlowFacesContext.RENDER_RESPONSE_KEY), EasyMock.anyObject()))
|
||||
.andStubReturn(null);
|
||||
|
||||
EasyMock.replay(new Object[] { context, flowExecutionContext, flowMap, flashScope });
|
||||
EasyMock.replay(new Object[] { this.context, this.flowExecutionContext, this.flowMap, this.flashScope });
|
||||
|
||||
jsfMock.application().setViewHandler(new ExceptionalViewHandler());
|
||||
this.jsfMock.application().setViewHandler(new ExceptionalViewHandler());
|
||||
|
||||
try {
|
||||
view.render();
|
||||
this.view.render();
|
||||
} catch (Exception ex) {
|
||||
}
|
||||
}
|
||||
@@ -138,19 +140,19 @@ public class JsfViewTests extends TestCase {
|
||||
*/
|
||||
public final void testProcessUserEvent_Restored_NoEvent() {
|
||||
|
||||
EasyMock.expect(flashScope.getBoolean(EasyMock.matches(FlowFacesContext.RENDER_RESPONSE_KEY))).andStubReturn(
|
||||
EasyMock.expect(this.flashScope.getBoolean(EasyMock.matches(FlowFacesContext.RENDER_RESPONSE_KEY))).andStubReturn(
|
||||
false);
|
||||
EasyMock.expect(flashScope.put(EasyMock.matches(FlowFacesContext.RENDER_RESPONSE_KEY), EasyMock.anyObject()))
|
||||
EasyMock.expect(this.flashScope.put(EasyMock.matches(FlowFacesContext.RENDER_RESPONSE_KEY), EasyMock.anyObject()))
|
||||
.andStubReturn(null);
|
||||
|
||||
Lifecycle lifecycle = new NoEventLifecycle(jsfMock.lifecycle());
|
||||
Lifecycle lifecycle = new NoEventLifecycle(this.jsfMock.lifecycle());
|
||||
|
||||
UIViewRoot existingRoot = new UIViewRoot();
|
||||
existingRoot.setViewId(VIEW_ID);
|
||||
|
||||
EasyMock.replay(new Object[] { context, flowExecutionContext, flowMap, flashScope });
|
||||
EasyMock.replay(new Object[] { this.context, this.flowExecutionContext, this.flowMap, this.flashScope });
|
||||
|
||||
JsfView restoredView = new JsfView(existingRoot, lifecycle, context);
|
||||
JsfView restoredView = new JsfView(existingRoot, lifecycle, this.context);
|
||||
|
||||
restoredView.processUserEvent();
|
||||
|
||||
@@ -164,20 +166,20 @@ public class JsfViewTests extends TestCase {
|
||||
*/
|
||||
public final void testProcessUserEvent_Restored_Ajax_NoEvent() {
|
||||
|
||||
EasyMock.expect(flashScope.getBoolean(EasyMock.matches(FlowFacesContext.RENDER_RESPONSE_KEY))).andStubReturn(
|
||||
EasyMock.expect(this.flashScope.getBoolean(EasyMock.matches(FlowFacesContext.RENDER_RESPONSE_KEY))).andStubReturn(
|
||||
false);
|
||||
EasyMock.expect(flashScope.put(EasyMock.matches(FlowFacesContext.RENDER_RESPONSE_KEY), EasyMock.anyObject()))
|
||||
EasyMock.expect(this.flashScope.put(EasyMock.matches(FlowFacesContext.RENDER_RESPONSE_KEY), EasyMock.anyObject()))
|
||||
.andStubReturn(null);
|
||||
|
||||
Lifecycle lifecycle = new NoEventLifecycle(jsfMock.lifecycle());
|
||||
Lifecycle lifecycle = new NoEventLifecycle(this.jsfMock.lifecycle());
|
||||
|
||||
UIViewRoot existingRoot = new UIViewRoot();
|
||||
existingRoot.setViewId(VIEW_ID);
|
||||
AjaxViewRoot ajaxRoot = new AjaxViewRoot(existingRoot);
|
||||
|
||||
EasyMock.replay(new Object[] { context, flowExecutionContext, flowMap, flashScope });
|
||||
EasyMock.replay(new Object[] { this.context, this.flowExecutionContext, this.flowMap, this.flashScope });
|
||||
|
||||
JsfView restoredView = new JsfView(ajaxRoot, lifecycle, context);
|
||||
JsfView restoredView = new JsfView(ajaxRoot, lifecycle, this.context);
|
||||
|
||||
restoredView.processUserEvent();
|
||||
|
||||
@@ -190,24 +192,24 @@ public class JsfViewTests extends TestCase {
|
||||
*/
|
||||
public final void testProcessUserEvent_Restored_EventSignaled() {
|
||||
|
||||
EasyMock.expect(flashScope.getBoolean(EasyMock.matches(FlowFacesContext.RENDER_RESPONSE_KEY))).andStubReturn(
|
||||
EasyMock.expect(this.flashScope.getBoolean(EasyMock.matches(FlowFacesContext.RENDER_RESPONSE_KEY))).andStubReturn(
|
||||
false);
|
||||
EasyMock.expect(flashScope.put(EasyMock.matches(FlowFacesContext.RENDER_RESPONSE_KEY), EasyMock.anyObject()))
|
||||
EasyMock.expect(this.flashScope.put(EasyMock.matches(FlowFacesContext.RENDER_RESPONSE_KEY), EasyMock.anyObject()))
|
||||
.andStubReturn(null);
|
||||
|
||||
Lifecycle lifecycle = new EventSignalingLifecycle(jsfMock.lifecycle());
|
||||
Lifecycle lifecycle = new EventSignalingLifecycle(this.jsfMock.lifecycle());
|
||||
|
||||
UIViewRoot existingRoot = new UIViewRoot();
|
||||
existingRoot.setViewId(VIEW_ID);
|
||||
|
||||
EasyMock.replay(new Object[] { context, flowExecutionContext, flowMap, flashScope });
|
||||
EasyMock.replay(new Object[] { this.context, this.flowExecutionContext, this.flowMap, this.flashScope });
|
||||
|
||||
JsfView restoredView = new JsfView(existingRoot, lifecycle, context);
|
||||
JsfView restoredView = new JsfView(existingRoot, lifecycle, this.context);
|
||||
|
||||
restoredView.processUserEvent();
|
||||
|
||||
assertTrue("No event was signaled,", restoredView.hasFlowEvent());
|
||||
assertEquals("Event should be " + event, event, restoredView.getFlowEvent().getId());
|
||||
assertEquals("Event should be " + this.event, this.event, restoredView.getFlowEvent().getId());
|
||||
assertTrue("The lifecycle should have been invoked", ((EventSignalingLifecycle) lifecycle).executed);
|
||||
}
|
||||
|
||||
@@ -216,10 +218,10 @@ public class JsfViewTests extends TestCase {
|
||||
MockParameterMap requestParameterMap = new MockParameterMap();
|
||||
requestParameterMap.put("execution", "e1s1");
|
||||
|
||||
EasyMock.expect(context.getRequestParameters()).andStubReturn(requestParameterMap);
|
||||
EasyMock.replay(new Object[] { context, flowExecutionContext, flowMap, flashScope });
|
||||
EasyMock.expect(this.context.getRequestParameters()).andStubReturn(requestParameterMap);
|
||||
EasyMock.replay(new Object[] { this.context, this.flowExecutionContext, this.flowMap, this.flashScope });
|
||||
|
||||
JsfView createdView = new JsfView(new UIViewRoot(), jsfMock.lifecycle(), context);
|
||||
JsfView createdView = new JsfView(new UIViewRoot(), this.jsfMock.lifecycle(), this.context);
|
||||
|
||||
assertFalse("No user event should be queued", createdView.userEventQueued());
|
||||
}
|
||||
@@ -230,10 +232,10 @@ public class JsfViewTests extends TestCase {
|
||||
requestParameterMap.put("execution", "e1s1");
|
||||
requestParameterMap.put("javax.faces.ViewState", "e1s1");
|
||||
|
||||
EasyMock.expect(context.getRequestParameters()).andStubReturn(requestParameterMap);
|
||||
EasyMock.replay(new Object[] { context, flowExecutionContext, flowMap, flashScope });
|
||||
EasyMock.expect(this.context.getRequestParameters()).andStubReturn(requestParameterMap);
|
||||
EasyMock.replay(new Object[] { this.context, this.flowExecutionContext, this.flowMap, this.flashScope });
|
||||
|
||||
JsfView createdView = new JsfView(new UIViewRoot(), jsfMock.lifecycle(), context);
|
||||
JsfView createdView = new JsfView(new UIViewRoot(), this.jsfMock.lifecycle(), this.context);
|
||||
|
||||
assertTrue("User event should be queued", createdView.userEventQueued());
|
||||
}
|
||||
@@ -260,9 +262,9 @@ public class JsfViewTests extends TestCase {
|
||||
}
|
||||
|
||||
public void execute(FacesContext context) throws FacesException {
|
||||
assertFalse("Lifecycle executed more than once", executed);
|
||||
assertFalse("Lifecycle executed more than once", this.executed);
|
||||
super.execute(context);
|
||||
executed = true;
|
||||
this.executed = true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -275,10 +277,10 @@ public class JsfViewTests extends TestCase {
|
||||
}
|
||||
|
||||
public void execute(FacesContext context) throws FacesException {
|
||||
assertFalse("Lifecycle executed more than once", executed);
|
||||
assertFalse("Lifecycle executed more than once", this.executed);
|
||||
super.execute(context);
|
||||
extContext.getRequestMap().put(JsfView.EVENT_KEY, event);
|
||||
executed = true;
|
||||
JsfViewTests.this.extContext.getRequestMap().put(JsfView.EVENT_KEY, JsfViewTests.this.event);
|
||||
this.executed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -89,11 +89,11 @@ public class MockApplication extends Application {
|
||||
}
|
||||
|
||||
public ViewHandler getViewHandler() {
|
||||
return viewHandler;
|
||||
return this.viewHandler;
|
||||
}
|
||||
|
||||
public void setViewHandler(ViewHandler handler) {
|
||||
viewHandler = handler;
|
||||
this.viewHandler = handler;
|
||||
}
|
||||
|
||||
public StateManager getStateManager() {
|
||||
|
||||
@@ -31,12 +31,12 @@ public class MockBaseFacesContext extends MockFacesContext20 {
|
||||
}
|
||||
|
||||
public Application getApplication() {
|
||||
if (application == null) {
|
||||
if (this.application == null) {
|
||||
ApplicationFactory applicationFactory = (ApplicationFactory) FactoryFinder
|
||||
.getFactory(FactoryFinder.APPLICATION_FACTORY);
|
||||
application = applicationFactory.getApplication();
|
||||
this.application = applicationFactory.getApplication();
|
||||
}
|
||||
return application;
|
||||
return this.application;
|
||||
}
|
||||
|
||||
public void setApplication(Application application) {
|
||||
|
||||
@@ -47,7 +47,7 @@ public class MockFacesContext extends FacesContext {
|
||||
private UIViewRoot viewRoot;
|
||||
|
||||
public Application getApplication() {
|
||||
return application;
|
||||
return this.application;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -63,7 +63,7 @@ public class MockFacesContext extends FacesContext {
|
||||
}
|
||||
|
||||
public ExternalContext getExternalContext() {
|
||||
return externalContext;
|
||||
return this.externalContext;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -114,7 +114,7 @@ public class MockFacesContext extends FacesContext {
|
||||
}
|
||||
|
||||
public UIViewRoot getViewRoot() {
|
||||
return viewRoot;
|
||||
return this.viewRoot;
|
||||
}
|
||||
|
||||
public void setViewRoot(UIViewRoot viewRoot) {
|
||||
|
||||
@@ -32,9 +32,9 @@ import javax.faces.context.ExternalContext;
|
||||
|
||||
public class MockJsfExternalContext extends ExternalContext {
|
||||
|
||||
private Map<String, Object> applicationMap = new HashMap<String, Object>();
|
||||
private final Map<String, Object> applicationMap = new HashMap<String, Object>();
|
||||
|
||||
private Map<String, Object> sessionMap = new HashMap<String, Object>();
|
||||
private final Map<String, Object> sessionMap = new HashMap<String, Object>();
|
||||
|
||||
private Map<String, Object> requestMap = new HashMap<String, Object>();
|
||||
|
||||
@@ -56,7 +56,7 @@ public class MockJsfExternalContext extends ExternalContext {
|
||||
}
|
||||
|
||||
public Map<String, Object> getApplicationMap() {
|
||||
return applicationMap;
|
||||
return this.applicationMap;
|
||||
}
|
||||
|
||||
public String getAuthType() {
|
||||
@@ -108,7 +108,7 @@ public class MockJsfExternalContext extends ExternalContext {
|
||||
}
|
||||
|
||||
public Map<String, Object> getRequestMap() {
|
||||
return requestMap;
|
||||
return this.requestMap;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -120,7 +120,7 @@ public class MockJsfExternalContext extends ExternalContext {
|
||||
}
|
||||
|
||||
public Map<String, String> getRequestParameterMap() {
|
||||
return requestParameterMap;
|
||||
return this.requestParameterMap;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -132,7 +132,7 @@ public class MockJsfExternalContext extends ExternalContext {
|
||||
}
|
||||
|
||||
public Iterator<String> getRequestParameterNames() {
|
||||
return requestParameterMap.keySet().iterator();
|
||||
return this.requestParameterMap.keySet().iterator();
|
||||
}
|
||||
|
||||
public Map<String, String[]> getRequestParameterValuesMap() {
|
||||
@@ -168,7 +168,7 @@ public class MockJsfExternalContext extends ExternalContext {
|
||||
}
|
||||
|
||||
public Map<String, Object> getSessionMap() {
|
||||
return sessionMap;
|
||||
return this.sessionMap;
|
||||
}
|
||||
|
||||
public Principal getUserPrincipal() {
|
||||
|
||||
@@ -37,7 +37,7 @@ public class MockViewHandler extends ViewHandler {
|
||||
}
|
||||
|
||||
public UIViewRoot createView(FacesContext context, String viewId) {
|
||||
return createViewRoot;
|
||||
return this.createViewRoot;
|
||||
}
|
||||
|
||||
public void initView(FacesContext context) throws FacesException {
|
||||
@@ -77,7 +77,7 @@ public class MockViewHandler extends ViewHandler {
|
||||
}
|
||||
|
||||
public UIViewRoot restoreView(FacesContext context, String viewId) {
|
||||
return restoreViewRoot;
|
||||
return this.restoreViewRoot;
|
||||
}
|
||||
|
||||
public void writeState(FacesContext context) throws IOException {
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
package org.springframework.faces.webflow;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringWriter;
|
||||
|
||||
import javax.faces.context.FacesContext;
|
||||
|
||||
import org.apache.myfaces.renderkit.MyfacesResponseStateManager;
|
||||
import org.apache.myfaces.test.base.AbstractJsfTestCase;
|
||||
import org.apache.myfaces.test.mock.MockResponseWriter;
|
||||
import org.easymock.EasyMock;
|
||||
import org.springframework.webflow.engine.ViewState;
|
||||
import org.springframework.webflow.execution.RequestContextHolder;
|
||||
import org.springframework.webflow.execution.ViewFactory;
|
||||
import org.springframework.webflow.test.MockFlowExecutionContext;
|
||||
import org.springframework.webflow.test.MockFlowExecutionKey;
|
||||
import org.springframework.webflow.test.MockFlowSession;
|
||||
import org.springframework.webflow.test.MockRequestContext;
|
||||
|
||||
/**
|
||||
* Tests for {@link MyFacesFlowResponseStateManager}.
|
||||
*
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
public class MyFacesFlowResponseStateManagerTests extends AbstractJsfTestCase {
|
||||
|
||||
private MockMyfacesResponseStateManager root;
|
||||
private FlowResponseStateManager flow;
|
||||
private MyFacesFlowResponseStateManager manager;
|
||||
private MockRequestContext requestContext;
|
||||
|
||||
public MyFacesFlowResponseStateManagerTests(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
this.root = new MockMyfacesResponseStateManager();
|
||||
this.flow = new FlowResponseStateManager(this.root);
|
||||
this.manager = new MyFacesFlowResponseStateManager(this.flow);
|
||||
this.requestContext = new MockRequestContext();
|
||||
MockFlowExecutionContext executionContext = requestContext.getMockFlowExecutionContext();
|
||||
MockFlowSession session = executionContext.getMockActiveSession();
|
||||
ViewFactory viewFactory = EasyMock.createNiceMock(ViewFactory.class);
|
||||
session.setState(new ViewState(session.getDefinitionInternal(), "view", viewFactory));
|
||||
executionContext.setKey(new MockFlowExecutionKey("x"));
|
||||
RequestContextHolder.setRequestContext(requestContext);
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
RequestContextHolder.setRequestContext(null);
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
public void testDelegatesIsWriteStateAfterRenderViewRequired() throws Exception {
|
||||
this.manager.isWriteStateAfterRenderViewRequired(this.facesContext);
|
||||
assertTrue(this.root.isWriteStateAfterRenderViewRequiredCalled);
|
||||
}
|
||||
|
||||
public void testDelegatesWriteState() throws Exception {
|
||||
RequestContextHolder.setRequestContext(null);
|
||||
this.facesContext.setResponseWriter(new MockResponseWriter(new StringWriter()));
|
||||
this.manager.writeState(this.facesContext, new Object());
|
||||
assertTrue(this.root.writeStateCalled);
|
||||
}
|
||||
|
||||
public void testTriggersSaveStateInFlowResponseStateManager() throws Exception {
|
||||
Object state = new Object();
|
||||
this.manager.saveState(this.facesContext, state);
|
||||
assertSame(state, requestContext.getViewScope().get(FlowResponseStateManager.FACES_VIEW_STATE));
|
||||
assertFalse(this.root.saveStateCalled);
|
||||
}
|
||||
|
||||
private static class MockMyfacesResponseStateManager extends MyfacesResponseStateManager {
|
||||
private boolean isWriteStateAfterRenderViewRequiredCalled;
|
||||
private boolean saveStateCalled;
|
||||
private boolean writeStateCalled;
|
||||
|
||||
public boolean isWriteStateAfterRenderViewRequired(FacesContext facesContext) {
|
||||
this.isWriteStateAfterRenderViewRequiredCalled = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
public void saveState(FacesContext facesContext, Object state) {
|
||||
this.saveStateCalled = true;
|
||||
}
|
||||
|
||||
public void writeState(FacesContext context, Object state) throws IOException {
|
||||
this.writeStateCalled = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -12,14 +12,14 @@ public class MultiValueRequestParameterMapTests extends TestCase {
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
request = new MockPortletRequest();
|
||||
requestMap = new MultiValueRequestParameterMap(request);
|
||||
this.request = new MockPortletRequest();
|
||||
this.requestMap = new MultiValueRequestParameterMap(this.request);
|
||||
}
|
||||
|
||||
public void testMultiValueParameter() throws Exception {
|
||||
request.setParameter("key", "value");
|
||||
request.addParameter("key", "value2");
|
||||
Object actual = requestMap.getAttribute("key");
|
||||
this.request.setParameter("key", "value");
|
||||
this.request.addParameter("key", "value2");
|
||||
Object actual = this.requestMap.getAttribute("key");
|
||||
assertTrue(actual.getClass().isArray());
|
||||
assertEquals(2, ((String[]) actual).length);
|
||||
assertEquals("value", ((String[]) actual)[0]);
|
||||
@@ -27,8 +27,8 @@ public class MultiValueRequestParameterMapTests extends TestCase {
|
||||
}
|
||||
|
||||
public void testSingleValueParameterAsArray() throws Exception {
|
||||
request.setParameter("key", "value");
|
||||
Object actual = requestMap.getAttribute("key");
|
||||
this.request.setParameter("key", "value");
|
||||
Object actual = this.requestMap.getAttribute("key");
|
||||
assertTrue(actual.getClass().isArray());
|
||||
assertEquals(1, ((String[]) actual).length);
|
||||
assertEquals("value", ((String[]) actual)[0]);
|
||||
|
||||
@@ -12,22 +12,22 @@ public class MultiValueRequestPropertyMapTests extends TestCase {
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
request = new MockPortletRequest();
|
||||
requestMap = new MultiValueRequestPropertyMap(request);
|
||||
this.request = new MockPortletRequest();
|
||||
this.requestMap = new MultiValueRequestPropertyMap(this.request);
|
||||
}
|
||||
|
||||
public void testMultiValueProperty() throws Exception {
|
||||
request.setProperty("key", "value");
|
||||
request.addProperty("key", "value2");
|
||||
Object actual = requestMap.getAttribute("key");
|
||||
this.request.setProperty("key", "value");
|
||||
this.request.addProperty("key", "value2");
|
||||
Object actual = this.requestMap.getAttribute("key");
|
||||
assertEquals(2, ((String[]) actual).length);
|
||||
assertEquals("value", ((String[]) actual)[0]);
|
||||
assertEquals("value2", ((String[]) actual)[1]);
|
||||
}
|
||||
|
||||
public void testSingleValuePropertyAsArray() throws Exception {
|
||||
request.setProperty("key", "value");
|
||||
Object actual = requestMap.getAttribute("key");
|
||||
this.request.setProperty("key", "value");
|
||||
Object actual = this.requestMap.getAttribute("key");
|
||||
assertEquals(1, ((String[]) actual).length);
|
||||
assertEquals("value", ((String[]) actual)[0]);
|
||||
}
|
||||
|
||||
@@ -12,19 +12,19 @@ public class SingleValueRequestParameterMapTests extends TestCase {
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
request = new MockPortletRequest();
|
||||
requestMap = new SingleValueRequestParameterMap(request);
|
||||
this.request = new MockPortletRequest();
|
||||
this.requestMap = new SingleValueRequestParameterMap(this.request);
|
||||
}
|
||||
|
||||
public void testSingleValueParameter() throws Exception {
|
||||
request.setParameter("key", "value");
|
||||
assertEquals("value", requestMap.getAttribute("key"));
|
||||
this.request.setParameter("key", "value");
|
||||
assertEquals("value", this.requestMap.getAttribute("key"));
|
||||
}
|
||||
|
||||
public void testMultiValueParameterAsString() throws Exception {
|
||||
request.setParameter("key", "value");
|
||||
request.addParameter("key", "value2");
|
||||
Object actual = requestMap.getAttribute("key");
|
||||
this.request.setParameter("key", "value");
|
||||
this.request.addParameter("key", "value2");
|
||||
Object actual = this.requestMap.getAttribute("key");
|
||||
assertEquals("value", actual);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,19 +12,19 @@ public class SingleValueRequestPropertyMapTests extends TestCase {
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
request = new MockPortletRequest();
|
||||
requestMap = new SingleValueRequestPropertyMap(request);
|
||||
this.request = new MockPortletRequest();
|
||||
this.requestMap = new SingleValueRequestPropertyMap(this.request);
|
||||
}
|
||||
|
||||
public void testSingleValueProperty() throws Exception {
|
||||
request.setProperty("key", "value");
|
||||
assertEquals("value", requestMap.getAttribute("key"));
|
||||
this.request.setProperty("key", "value");
|
||||
assertEquals("value", this.requestMap.getAttribute("key"));
|
||||
}
|
||||
|
||||
public void testMultiValuePropertyAsString() throws Exception {
|
||||
request.setProperty("key", "value");
|
||||
request.addProperty("key", "value2");
|
||||
Object actual = requestMap.getAttribute("key");
|
||||
this.request.setProperty("key", "value");
|
||||
this.request.addProperty("key", "value2");
|
||||
Object actual = this.requestMap.getAttribute("key");
|
||||
assertEquals("value", actual);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user