correct format to ASF style
diff --git a/test12/src/main/java/org/apache/myfaces/test/base/AbstractJsfTestCase.java b/test12/src/main/java/org/apache/myfaces/test/base/AbstractJsfTestCase.java
index ec6b027..3bd3405 100644
--- a/test12/src/main/java/org/apache/myfaces/test/base/AbstractJsfTestCase.java
+++ b/test12/src/main/java/org/apache/myfaces/test/base/AbstractJsfTestCase.java
@@ -73,34 +73,36 @@
* @since 1.0.0
*/
-public abstract class AbstractJsfTestCase extends TestCase {
-
+public abstract class AbstractJsfTestCase extends TestCase
+{
// ------------------------------------------------------------ Constructors
-
/**
* <p>Construct a new instance of this test case.</p>
*
* @param name Name of this test case
*/
- public AbstractJsfTestCase(String name) {
+ public AbstractJsfTestCase(String name)
+ {
super(name);
}
-
// ---------------------------------------------------- Overall Test Methods
-
/**
* <p>Set up instance variables required by this test case.</p>
*/
- protected void setUp() throws Exception {
+ protected void setUp() throws Exception
+ {
// Set up a new thread context class loader
- threadContextClassLoader = Thread.currentThread().getContextClassLoader();
- Thread.currentThread().setContextClassLoader(new URLClassLoader(new URL[0],
- this.getClass().getClassLoader()));
+ threadContextClassLoader = Thread.currentThread()
+ .getContextClassLoader();
+ Thread.currentThread()
+ .setContextClassLoader(
+ new URLClassLoader(new URL[0], this.getClass()
+ .getClassLoader()));
// Set up Servlet API Objects
setUpServletObjects();
@@ -112,7 +114,7 @@
setUpJSFObjects();
}
-
+
/**
* <p>Setup JSF object used for the test. By default it calls to the following
* methods in this order:</p>
@@ -128,7 +130,7 @@
*
* @throws Exception
*/
- protected void setUpJSFObjects() throws Exception
+ protected void setUpJSFObjects() throws Exception
{
setUpExternalContext();
setUpLifecycle();
@@ -137,7 +139,7 @@
setUpApplication();
setUpRenderKit();
}
-
+
/**
* <p>Setup servlet objects that will be used for the test:</p>
*
@@ -151,7 +153,7 @@
*
* @throws Exception
*/
- protected void setUpServletObjects() throws Exception
+ protected void setUpServletObjects() throws Exception
{
servletContext = new MockServletContext();
config = new MockServletConfig(servletContext);
@@ -161,22 +163,22 @@
request.setServletContext(servletContext);
response = new MockHttpServletResponse();
}
-
+
/**
* <p>Set JSF factories using FactoryFinder method setFactory.</p>
*
* @throws Exception
*/
- protected void setFactories() throws Exception
+ protected void setFactories() throws Exception
{
FactoryFinder.setFactory(FactoryFinder.APPLICATION_FACTORY,
- "org.apache.myfaces.test.mock.MockApplicationFactory");
+ "org.apache.myfaces.test.mock.MockApplicationFactory");
FactoryFinder.setFactory(FactoryFinder.FACES_CONTEXT_FACTORY,
- "org.apache.myfaces.test.mock.MockFacesContextFactory");
+ "org.apache.myfaces.test.mock.MockFacesContextFactory");
FactoryFinder.setFactory(FactoryFinder.LIFECYCLE_FACTORY,
- "org.apache.myfaces.test.mock.lifecycle.MockLifecycleFactory");
+ "org.apache.myfaces.test.mock.lifecycle.MockLifecycleFactory");
FactoryFinder.setFactory(FactoryFinder.RENDER_KIT_FACTORY,
- "org.apache.myfaces.test.mock.MockRenderKitFactory");
+ "org.apache.myfaces.test.mock.MockRenderKitFactory");
}
/**
@@ -187,8 +189,8 @@
*/
protected void setUpExternalContext() throws Exception
{
- externalContext =
- new MockExternalContext(servletContext, request, response);
+ externalContext = new MockExternalContext(servletContext, request,
+ response);
}
/**
@@ -199,12 +201,12 @@
*/
protected void setUpLifecycle() throws Exception
{
- lifecycleFactory = (MockLifecycleFactory)
- FactoryFinder.getFactory(FactoryFinder.LIFECYCLE_FACTORY);
- lifecycle = (MockLifecycle)
- lifecycleFactory.getLifecycle(LifecycleFactory.DEFAULT_LIFECYCLE);
+ lifecycleFactory = (MockLifecycleFactory) FactoryFinder
+ .getFactory(FactoryFinder.LIFECYCLE_FACTORY);
+ lifecycle = (MockLifecycle) lifecycleFactory
+ .getLifecycle(LifecycleFactory.DEFAULT_LIFECYCLE);
}
-
+
/**
* Setup the <code>facesContextFactory</code> and <code>facesContext</code>
* variable. Before end, by default it override <code>externalContext</code>
@@ -216,16 +218,14 @@
*/
protected void setUpFacesContext() throws Exception
{
- facesContextFactory = (MockFacesContextFactory)
- FactoryFinder.getFactory(FactoryFinder.FACES_CONTEXT_FACTORY);
- facesContext = (MockFacesContext)
- facesContextFactory.getFacesContext(servletContext,
- request,
- response,
- lifecycle);
+ facesContextFactory = (MockFacesContextFactory) FactoryFinder
+ .getFactory(FactoryFinder.FACES_CONTEXT_FACTORY);
+ facesContext = (MockFacesContext) facesContextFactory.getFacesContext(
+ servletContext, request, response, lifecycle);
if (facesContext.getExternalContext() != null)
{
- externalContext = (MockExternalContext) facesContext.getExternalContext();
+ externalContext = (MockExternalContext) facesContext
+ .getExternalContext();
}
}
@@ -242,7 +242,7 @@
root.setRenderKitId(RenderKitFactory.HTML_BASIC_RENDER_KIT);
facesContext.setViewRoot(root);
}
-
+
/**
* Setup the <code>application</code> variable and before
* the end by default it is assigned to the <code>facesContext</code>
@@ -252,12 +252,12 @@
*/
protected void setUpApplication() throws Exception
{
- ApplicationFactory applicationFactory = (ApplicationFactory)
- FactoryFinder.getFactory(FactoryFinder.APPLICATION_FACTORY);
+ ApplicationFactory applicationFactory = (ApplicationFactory) FactoryFinder
+ .getFactory(FactoryFinder.APPLICATION_FACTORY);
application = (MockApplication) applicationFactory.getApplication();
facesContext.setApplication(application);
}
-
+
/**
* Setup the <code>renderKit</code> variable. This is a good place to use
* <code>ConfigParser</code> to register converters, validators, components
@@ -267,21 +267,24 @@
*/
protected void setUpRenderKit() throws Exception
{
- RenderKitFactory renderKitFactory = (RenderKitFactory)
- FactoryFinder.getFactory(FactoryFinder.RENDER_KIT_FACTORY);
+ RenderKitFactory renderKitFactory = (RenderKitFactory) FactoryFinder
+ .getFactory(FactoryFinder.RENDER_KIT_FACTORY);
renderKit = new MockRenderKit();
- renderKitFactory.addRenderKit(RenderKitFactory.HTML_BASIC_RENDER_KIT, renderKit);
+ renderKitFactory.addRenderKit(RenderKitFactory.HTML_BASIC_RENDER_KIT,
+ renderKit);
}
/**
* <p>Tear down instance variables required by this test case.</p>
*/
- protected void tearDown() throws Exception {
+ protected void tearDown() throws Exception
+ {
application = null;
config = null;
externalContext = null;
- if (facesContext != null) {
+ if (facesContext != null)
+ {
facesContext.release();
}
facesContext = null;
@@ -299,23 +302,21 @@
}
-
// ------------------------------------------------------ Instance Variables
-
// Mock object instances for our tests
- protected MockApplication application = null;
- protected MockServletConfig config = null;
- protected MockExternalContext externalContext = null;
- protected MockFacesContext facesContext = null;
+ protected MockApplication application = null;
+ protected MockServletConfig config = null;
+ protected MockExternalContext externalContext = null;
+ protected MockFacesContext facesContext = null;
protected MockFacesContextFactory facesContextFactory = null;
- protected MockLifecycle lifecycle = null;
- protected MockLifecycleFactory lifecycleFactory = null;
- protected MockRenderKit renderKit = null;
- protected MockHttpServletRequest request = null;
+ protected MockLifecycle lifecycle = null;
+ protected MockLifecycleFactory lifecycleFactory = null;
+ protected MockRenderKit renderKit = null;
+ protected MockHttpServletRequest request = null;
protected MockHttpServletResponse response = null;
- protected MockServletContext servletContext = null;
- protected MockHttpSession session = null;
+ protected MockServletContext servletContext = null;
+ protected MockHttpSession session = null;
// Thread context class loader saved and restored after each test
private ClassLoader threadContextClassLoader = null;
diff --git a/test12/src/main/java/org/apache/myfaces/test/base/AbstractViewControllerTestCase.java b/test12/src/main/java/org/apache/myfaces/test/base/AbstractViewControllerTestCase.java
index fb3e21b..f983f79 100644
--- a/test12/src/main/java/org/apache/myfaces/test/base/AbstractViewControllerTestCase.java
+++ b/test12/src/main/java/org/apache/myfaces/test/base/AbstractViewControllerTestCase.java
@@ -31,30 +31,28 @@
*
* @since 1.0.0
*/
-public abstract class AbstractViewControllerTestCase extends AbstractJsfTestCase {
+public abstract class AbstractViewControllerTestCase extends
+ AbstractJsfTestCase
+{
// ------------------------------------------------------------ Constructors
-
/**
* <p>Construct a new instance of this test case.</p>
*
* @param name Test case name
*/
- public AbstractViewControllerTestCase(String name) {
+ public AbstractViewControllerTestCase(String name)
+ {
super(name);
}
-
// ---------------------------------------------------- Overall Test Methods
-
// ------------------------------------------------------ Instance Variables
-
// ------------------------------------------------------- Protected Methods
-
/**
* <p>Test that the specified number of messages have been queued on the
* <code>FacesContext</code> instance, without regard to matching a
@@ -62,11 +60,13 @@
*
* @param expected The expected number of messages
*/
- protected void checkMessageCount(int expected) {
+ protected void checkMessageCount(int expected)
+ {
int actual = 0;
Iterator messages = facesContext.getMessages();
- while (messages.hasNext()) {
+ while (messages.hasNext())
+ {
messages.next();
actual++;
}
@@ -74,7 +74,6 @@
}
-
/**
* <p>Test that the specified number of messages have been queued on the
* <code>FacesContext</code> instance, for the specified client id.</p>
@@ -83,11 +82,13 @@
* count queued messages
* @param expected The expected number of messages
*/
- protected void checkMessageCount(String clientId, int expected) {
+ protected void checkMessageCount(String clientId, int expected)
+ {
int actual = 0;
Iterator messages = facesContext.getMessages(clientId);
- while (messages.hasNext()) {
+ while (messages.hasNext())
+ {
messages.next();
actual++;
}
@@ -95,5 +96,4 @@
}
-
}
diff --git a/test12/src/main/java/org/apache/myfaces/test/base/junit4/AbstractJsfConfigurableMockTestCase.java b/test12/src/main/java/org/apache/myfaces/test/base/junit4/AbstractJsfConfigurableMockTestCase.java
index 3b5a2a5..fb0f416 100644
--- a/test12/src/main/java/org/apache/myfaces/test/base/junit4/AbstractJsfConfigurableMockTestCase.java
+++ b/test12/src/main/java/org/apache/myfaces/test/base/junit4/AbstractJsfConfigurableMockTestCase.java
@@ -75,12 +75,11 @@
* @since 1.0.0
*/
-public abstract class AbstractJsfConfigurableMockTestCase {
-
+public abstract class AbstractJsfConfigurableMockTestCase
+{
// ------------------------------------------------------------ Constructors
-
/**
* <p>Construct a new instance of this test case.</p>
*
@@ -90,20 +89,22 @@
{
}
-
// ---------------------------------------------------- Overall Test Methods
-
/**
* <p>Set up instance variables required by this test case.</p>
*/
@Before
- public void setUp() throws Exception {
+ public void setUp() throws Exception
+ {
// Set up a new thread context class loader
- threadContextClassLoader = Thread.currentThread().getContextClassLoader();
- Thread.currentThread().setContextClassLoader(new URLClassLoader(new URL[0],
- this.getClass().getClassLoader()));
+ threadContextClassLoader = Thread.currentThread()
+ .getContextClassLoader();
+ Thread.currentThread()
+ .setContextClassLoader(
+ new URLClassLoader(new URL[0], this.getClass()
+ .getClassLoader()));
// Set up Servlet API Objects
setUpServletObjects();
@@ -115,7 +116,7 @@
setUpJSFObjects();
}
-
+
/**
* <p>Setup JSF object used for the test. By default it calls to the following
* methods in this order:</p>
@@ -131,7 +132,7 @@
*
* @throws Exception
*/
- protected void setUpJSFObjects() throws Exception
+ protected void setUpJSFObjects() throws Exception
{
setUpExternalContext();
setUpLifecycle();
@@ -140,7 +141,7 @@
setUpApplication();
setUpRenderKit();
}
-
+
/**
* <p>Setup servlet objects that will be used for the test:</p>
*
@@ -154,7 +155,7 @@
*
* @throws Exception
*/
- protected void setUpServletObjects() throws Exception
+ protected void setUpServletObjects() throws Exception
{
servletContext = new MockServletContext();
config = new MockServletConfig(servletContext);
@@ -164,22 +165,22 @@
request.setServletContext(servletContext);
response = new MockHttpServletResponse();
}
-
+
/**
* <p>Set JSF factories using FactoryFinder method setFactory.</p>
*
* @throws Exception
*/
- protected void setFactories() throws Exception
+ protected void setFactories() throws Exception
{
FactoryFinder.setFactory(FactoryFinder.APPLICATION_FACTORY,
- "org.apache.myfaces.test.mock.MockApplicationFactory");
+ "org.apache.myfaces.test.mock.MockApplicationFactory");
FactoryFinder.setFactory(FactoryFinder.FACES_CONTEXT_FACTORY,
- "org.apache.myfaces.test.mock.MockFacesContextFactory");
+ "org.apache.myfaces.test.mock.MockFacesContextFactory");
FactoryFinder.setFactory(FactoryFinder.LIFECYCLE_FACTORY,
- "org.apache.myfaces.test.mock.lifecycle.MockLifecycleFactory");
+ "org.apache.myfaces.test.mock.lifecycle.MockLifecycleFactory");
FactoryFinder.setFactory(FactoryFinder.RENDER_KIT_FACTORY,
- "org.apache.myfaces.test.mock.MockRenderKitFactory");
+ "org.apache.myfaces.test.mock.MockRenderKitFactory");
}
/**
@@ -190,8 +191,8 @@
*/
protected void setUpExternalContext() throws Exception
{
- externalContext =
- new MockExternalContext(servletContext, request, response);
+ externalContext = new MockExternalContext(servletContext, request,
+ response);
}
/**
@@ -202,12 +203,12 @@
*/
protected void setUpLifecycle() throws Exception
{
- lifecycleFactory = (LifecycleFactory)
- FactoryFinder.getFactory(FactoryFinder.LIFECYCLE_FACTORY);
- lifecycle =
- lifecycleFactory.getLifecycle(LifecycleFactory.DEFAULT_LIFECYCLE);
+ lifecycleFactory = (LifecycleFactory) FactoryFinder
+ .getFactory(FactoryFinder.LIFECYCLE_FACTORY);
+ lifecycle = lifecycleFactory
+ .getLifecycle(LifecycleFactory.DEFAULT_LIFECYCLE);
}
-
+
/**
* Setup the <code>facesContextFactory</code> and <code>facesContext</code>
* variable. Before end, by default it override <code>externalContext</code>
@@ -219,13 +220,10 @@
*/
protected void setUpFacesContext() throws Exception
{
- facesContextFactory = (FacesContextFactory)
- FactoryFinder.getFactory(FactoryFinder.FACES_CONTEXT_FACTORY);
- facesContext = (FacesContext)
- facesContextFactory.getFacesContext(servletContext,
- request,
- response,
- lifecycle);
+ facesContextFactory = (FacesContextFactory) FactoryFinder
+ .getFactory(FactoryFinder.FACES_CONTEXT_FACTORY);
+ facesContext = (FacesContext) facesContextFactory.getFacesContext(
+ servletContext, request, response, lifecycle);
if (facesContext.getExternalContext() != null)
{
externalContext = facesContext.getExternalContext();
@@ -245,7 +243,7 @@
root.setRenderKitId(RenderKitFactory.HTML_BASIC_RENDER_KIT);
facesContext.setViewRoot(root);
}
-
+
/**
* Setup the <code>application</code> variable and before
* the end by default it is assigned to the <code>facesContext</code>
@@ -255,12 +253,12 @@
*/
protected void setUpApplication() throws Exception
{
- ApplicationFactory applicationFactory = (ApplicationFactory)
- FactoryFinder.getFactory(FactoryFinder.APPLICATION_FACTORY);
+ ApplicationFactory applicationFactory = (ApplicationFactory) FactoryFinder
+ .getFactory(FactoryFinder.APPLICATION_FACTORY);
application = applicationFactory.getApplication();
- ((MockFacesContext)facesContext).setApplication(application);
+ ((MockFacesContext) facesContext).setApplication(application);
}
-
+
/**
* Setup the <code>renderKit</code> variable. This is a good place to use
* <code>ConfigParser</code> to register converters, validators, components
@@ -270,22 +268,25 @@
*/
protected void setUpRenderKit() throws Exception
{
- RenderKitFactory renderKitFactory = (RenderKitFactory)
- FactoryFinder.getFactory(FactoryFinder.RENDER_KIT_FACTORY);
+ RenderKitFactory renderKitFactory = (RenderKitFactory) FactoryFinder
+ .getFactory(FactoryFinder.RENDER_KIT_FACTORY);
renderKit = new MockRenderKit();
- renderKitFactory.addRenderKit(RenderKitFactory.HTML_BASIC_RENDER_KIT, renderKit);
+ renderKitFactory.addRenderKit(RenderKitFactory.HTML_BASIC_RENDER_KIT,
+ renderKit);
}
/**
* <p>Tear down instance variables required by this test case.</p>
*/
@After
- public void tearDown() throws Exception {
+ public void tearDown() throws Exception
+ {
application = null;
config = null;
externalContext = null;
- if (facesContext != null) {
+ if (facesContext != null)
+ {
facesContext.release();
}
facesContext = null;
@@ -303,23 +304,21 @@
}
-
// ------------------------------------------------------ Instance Variables
-
// Mock object instances for our tests
- protected Application application = null;
- protected MockServletConfig config = null;
- protected ExternalContext externalContext = null;
- protected FacesContext facesContext = null;
- protected FacesContextFactory facesContextFactory = null;
- protected Lifecycle lifecycle = null;
- protected LifecycleFactory lifecycleFactory = null;
- protected RenderKit renderKit = null;
- protected MockHttpServletRequest request = null;
+ protected Application application = null;
+ protected MockServletConfig config = null;
+ protected ExternalContext externalContext = null;
+ protected FacesContext facesContext = null;
+ protected FacesContextFactory facesContextFactory = null;
+ protected Lifecycle lifecycle = null;
+ protected LifecycleFactory lifecycleFactory = null;
+ protected RenderKit renderKit = null;
+ protected MockHttpServletRequest request = null;
protected MockHttpServletResponse response = null;
- protected MockServletContext servletContext = null;
- protected MockHttpSession session = null;
+ protected MockServletContext servletContext = null;
+ protected MockHttpSession session = null;
// Thread context class loader saved and restored after each test
private ClassLoader threadContextClassLoader = null;
diff --git a/test12/src/main/java/org/apache/myfaces/test/base/junit4/AbstractJsfTestCase.java b/test12/src/main/java/org/apache/myfaces/test/base/junit4/AbstractJsfTestCase.java
index 99ede20..e1bdef3 100644
--- a/test12/src/main/java/org/apache/myfaces/test/base/junit4/AbstractJsfTestCase.java
+++ b/test12/src/main/java/org/apache/myfaces/test/base/junit4/AbstractJsfTestCase.java
@@ -73,12 +73,11 @@
* @since 1.0.0
*/
-public abstract class AbstractJsfTestCase {
-
+public abstract class AbstractJsfTestCase
+{
// ------------------------------------------------------------ Constructors
-
/**
* <p>Construct a new instance of this test case.</p>
*
@@ -88,20 +87,22 @@
{
}
-
// ---------------------------------------------------- Overall Test Methods
-
/**
* <p>Set up instance variables required by this test case.</p>
*/
@Before
- public void setUp() throws Exception {
+ public void setUp() throws Exception
+ {
// Set up a new thread context class loader
- threadContextClassLoader = Thread.currentThread().getContextClassLoader();
- Thread.currentThread().setContextClassLoader(new URLClassLoader(new URL[0],
- this.getClass().getClassLoader()));
+ threadContextClassLoader = Thread.currentThread()
+ .getContextClassLoader();
+ Thread.currentThread()
+ .setContextClassLoader(
+ new URLClassLoader(new URL[0], this.getClass()
+ .getClassLoader()));
// Set up Servlet API Objects
setUpServletObjects();
@@ -113,7 +114,7 @@
setUpJSFObjects();
}
-
+
/**
* <p>Setup JSF object used for the test. By default it calls to the following
* methods in this order:</p>
@@ -129,7 +130,7 @@
*
* @throws Exception
*/
- protected void setUpJSFObjects() throws Exception
+ protected void setUpJSFObjects() throws Exception
{
setUpExternalContext();
setUpLifecycle();
@@ -138,7 +139,7 @@
setUpApplication();
setUpRenderKit();
}
-
+
/**
* <p>Setup servlet objects that will be used for the test:</p>
*
@@ -152,7 +153,7 @@
*
* @throws Exception
*/
- protected void setUpServletObjects() throws Exception
+ protected void setUpServletObjects() throws Exception
{
servletContext = new MockServletContext();
config = new MockServletConfig(servletContext);
@@ -162,22 +163,22 @@
request.setServletContext(servletContext);
response = new MockHttpServletResponse();
}
-
+
/**
* <p>Set JSF factories using FactoryFinder method setFactory.</p>
*
* @throws Exception
*/
- protected void setFactories() throws Exception
+ protected void setFactories() throws Exception
{
FactoryFinder.setFactory(FactoryFinder.APPLICATION_FACTORY,
- "org.apache.myfaces.test.mock.MockApplicationFactory");
+ "org.apache.myfaces.test.mock.MockApplicationFactory");
FactoryFinder.setFactory(FactoryFinder.FACES_CONTEXT_FACTORY,
- "org.apache.myfaces.test.mock.MockFacesContextFactory");
+ "org.apache.myfaces.test.mock.MockFacesContextFactory");
FactoryFinder.setFactory(FactoryFinder.LIFECYCLE_FACTORY,
- "org.apache.myfaces.test.mock.lifecycle.MockLifecycleFactory");
+ "org.apache.myfaces.test.mock.lifecycle.MockLifecycleFactory");
FactoryFinder.setFactory(FactoryFinder.RENDER_KIT_FACTORY,
- "org.apache.myfaces.test.mock.MockRenderKitFactory");
+ "org.apache.myfaces.test.mock.MockRenderKitFactory");
}
/**
@@ -188,8 +189,8 @@
*/
protected void setUpExternalContext() throws Exception
{
- externalContext =
- new MockExternalContext(servletContext, request, response);
+ externalContext = new MockExternalContext(servletContext, request,
+ response);
}
/**
@@ -200,12 +201,12 @@
*/
protected void setUpLifecycle() throws Exception
{
- lifecycleFactory = (MockLifecycleFactory)
- FactoryFinder.getFactory(FactoryFinder.LIFECYCLE_FACTORY);
- lifecycle = (MockLifecycle)
- lifecycleFactory.getLifecycle(LifecycleFactory.DEFAULT_LIFECYCLE);
+ lifecycleFactory = (MockLifecycleFactory) FactoryFinder
+ .getFactory(FactoryFinder.LIFECYCLE_FACTORY);
+ lifecycle = (MockLifecycle) lifecycleFactory
+ .getLifecycle(LifecycleFactory.DEFAULT_LIFECYCLE);
}
-
+
/**
* Setup the <code>facesContextFactory</code> and <code>facesContext</code>
* variable. Before end, by default it override <code>externalContext</code>
@@ -217,16 +218,14 @@
*/
protected void setUpFacesContext() throws Exception
{
- facesContextFactory = (MockFacesContextFactory)
- FactoryFinder.getFactory(FactoryFinder.FACES_CONTEXT_FACTORY);
- facesContext = (MockFacesContext)
- facesContextFactory.getFacesContext(servletContext,
- request,
- response,
- lifecycle);
+ facesContextFactory = (MockFacesContextFactory) FactoryFinder
+ .getFactory(FactoryFinder.FACES_CONTEXT_FACTORY);
+ facesContext = (MockFacesContext) facesContextFactory.getFacesContext(
+ servletContext, request, response, lifecycle);
if (facesContext.getExternalContext() != null)
{
- externalContext = (MockExternalContext) facesContext.getExternalContext();
+ externalContext = (MockExternalContext) facesContext
+ .getExternalContext();
}
}
@@ -243,7 +242,7 @@
root.setRenderKitId(RenderKitFactory.HTML_BASIC_RENDER_KIT);
facesContext.setViewRoot(root);
}
-
+
/**
* Setup the <code>application</code> variable and before
* the end by default it is assigned to the <code>facesContext</code>
@@ -253,12 +252,12 @@
*/
protected void setUpApplication() throws Exception
{
- ApplicationFactory applicationFactory = (ApplicationFactory)
- FactoryFinder.getFactory(FactoryFinder.APPLICATION_FACTORY);
+ ApplicationFactory applicationFactory = (ApplicationFactory) FactoryFinder
+ .getFactory(FactoryFinder.APPLICATION_FACTORY);
application = (MockApplication) applicationFactory.getApplication();
facesContext.setApplication(application);
}
-
+
/**
* Setup the <code>renderKit</code> variable. This is a good place to use
* <code>ConfigParser</code> to register converters, validators, components
@@ -268,22 +267,25 @@
*/
protected void setUpRenderKit() throws Exception
{
- RenderKitFactory renderKitFactory = (RenderKitFactory)
- FactoryFinder.getFactory(FactoryFinder.RENDER_KIT_FACTORY);
+ RenderKitFactory renderKitFactory = (RenderKitFactory) FactoryFinder
+ .getFactory(FactoryFinder.RENDER_KIT_FACTORY);
renderKit = new MockRenderKit();
- renderKitFactory.addRenderKit(RenderKitFactory.HTML_BASIC_RENDER_KIT, renderKit);
+ renderKitFactory.addRenderKit(RenderKitFactory.HTML_BASIC_RENDER_KIT,
+ renderKit);
}
/**
* <p>Tear down instance variables required by this test case.</p>
*/
@After
- public void tearDown() throws Exception {
+ public void tearDown() throws Exception
+ {
application = null;
config = null;
externalContext = null;
- if (facesContext != null) {
+ if (facesContext != null)
+ {
facesContext.release();
}
facesContext = null;
@@ -301,23 +303,21 @@
}
-
// ------------------------------------------------------ Instance Variables
-
// Mock object instances for our tests
- protected MockApplication application = null;
- protected MockServletConfig config = null;
- protected MockExternalContext externalContext = null;
- protected MockFacesContext facesContext = null;
+ protected MockApplication application = null;
+ protected MockServletConfig config = null;
+ protected MockExternalContext externalContext = null;
+ protected MockFacesContext facesContext = null;
protected MockFacesContextFactory facesContextFactory = null;
- protected MockLifecycle lifecycle = null;
- protected MockLifecycleFactory lifecycleFactory = null;
- protected MockRenderKit renderKit = null;
- protected MockHttpServletRequest request = null;
+ protected MockLifecycle lifecycle = null;
+ protected MockLifecycleFactory lifecycleFactory = null;
+ protected MockRenderKit renderKit = null;
+ protected MockHttpServletRequest request = null;
protected MockHttpServletResponse response = null;
- protected MockServletContext servletContext = null;
- protected MockHttpSession session = null;
+ protected MockServletContext servletContext = null;
+ protected MockHttpSession session = null;
// Thread context class loader saved and restored after each test
private ClassLoader threadContextClassLoader = null;
diff --git a/test12/src/main/java/org/apache/myfaces/test/base/junit4/AbstractViewControllerTestCase.java b/test12/src/main/java/org/apache/myfaces/test/base/junit4/AbstractViewControllerTestCase.java
index a7ace71..8c4a904 100644
--- a/test12/src/main/java/org/apache/myfaces/test/base/junit4/AbstractViewControllerTestCase.java
+++ b/test12/src/main/java/org/apache/myfaces/test/base/junit4/AbstractViewControllerTestCase.java
@@ -33,30 +33,28 @@
*
* @since 1.0.0
*/
-public abstract class AbstractViewControllerTestCase extends AbstractJsfTestCase {
+public abstract class AbstractViewControllerTestCase extends
+ AbstractJsfTestCase
+{
// ------------------------------------------------------------ Constructors
-
/**
* <p>Construct a new instance of this test case.</p>
*
* @param name Test case name
*/
- public AbstractViewControllerTestCase() {
+ public AbstractViewControllerTestCase()
+ {
super();
}
-
// ---------------------------------------------------- Overall Test Methods
-
// ------------------------------------------------------ Instance Variables
-
// ------------------------------------------------------- Protected Methods
-
/**
* <p>Test that the specified number of messages have been queued on the
* <code>FacesContext</code> instance, without regard to matching a
@@ -64,11 +62,13 @@
*
* @param expected The expected number of messages
*/
- protected void checkMessageCount(int expected) {
+ protected void checkMessageCount(int expected)
+ {
int actual = 0;
Iterator messages = facesContext.getMessages();
- while (messages.hasNext()) {
+ while (messages.hasNext())
+ {
messages.next();
actual++;
}
@@ -76,7 +76,6 @@
}
-
/**
* <p>Test that the specified number of messages have been queued on the
* <code>FacesContext</code> instance, for the specified client id.</p>
@@ -85,11 +84,13 @@
* count queued messages
* @param expected The expected number of messages
*/
- protected void checkMessageCount(String clientId, int expected) {
+ protected void checkMessageCount(String clientId, int expected)
+ {
int actual = 0;
Iterator messages = facesContext.getMessages(clientId);
- while (messages.hasNext()) {
+ while (messages.hasNext())
+ {
messages.next();
actual++;
}
@@ -97,5 +98,4 @@
}
-
}
diff --git a/test12/src/main/java/org/apache/myfaces/test/cargo/CargoTestSetup.java b/test12/src/main/java/org/apache/myfaces/test/cargo/CargoTestSetup.java
index 3985ad8..b39c32b 100644
--- a/test12/src/main/java/org/apache/myfaces/test/cargo/CargoTestSetup.java
+++ b/test12/src/main/java/org/apache/myfaces/test/cargo/CargoTestSetup.java
@@ -41,7 +41,8 @@
*
* @since 1.0.0
*/
-public class CargoTestSetup extends TestSetup {
+public class CargoTestSetup extends TestSetup
+{
// ------------------------------------------------------------ Constructors
@@ -50,7 +51,8 @@
*
* @param test Tests to be run within this test setup.
*/
- public CargoTestSetup(Test test) {
+ public CargoTestSetup(Test test)
+ {
super(test);
}
@@ -80,13 +82,15 @@
*
* @throws Exception if an error occurs.
*/
- protected void setUp() throws Exception {
+ protected void setUp() throws Exception
+ {
super.setUp();
// If there is no container id, default to Tomcat 5x
String containerId = System.getProperty("cargo.container.id");
- if (containerId == null) {
+ if (containerId == null)
+ {
containerId = Tomcat5xInstalledLocalContainer.ID;
}
System.out.println("[INFO] container id: " + containerId);
@@ -95,37 +99,33 @@
String deployablePath = System.getProperty("cargo.deployable");
System.out.println("[INFO] deployable: " + deployablePath);
Deployable war = new DefaultDeployableFactory().createDeployable(
- containerId,
- deployablePath,
- DeployableType.WAR);
+ containerId, deployablePath, DeployableType.WAR);
// Container configuration
- ConfigurationFactory configurationFactory =
- new DefaultConfigurationFactory();
+ ConfigurationFactory configurationFactory = new DefaultConfigurationFactory();
- LocalConfiguration configuration =
- (LocalConfiguration) configurationFactory.createConfiguration(
- containerId,
- ConfigurationType.STANDALONE);
+ LocalConfiguration configuration = (LocalConfiguration) configurationFactory
+ .createConfiguration(containerId, ConfigurationType.STANDALONE);
// Find and (if provided) set the port to use for the container.
String servletPort = System.getProperty("cargo.servlet.port");
- if (servletPort != null) {
+ if (servletPort != null)
+ {
configuration.setProperty("cargo.servlet.port", servletPort);
System.out.println("[INFO] servlet port: " + servletPort);
}
configuration.addDeployable(war);
- container = (InstalledLocalContainer)
- new DefaultContainerFactory().createContainer(
- containerId,
- ContainerType.INSTALLED, configuration);
+ container = (InstalledLocalContainer) new DefaultContainerFactory()
+ .createContainer(containerId, ContainerType.INSTALLED,
+ configuration);
// If 'cargo.container.home' is not set, or if an expression was
// passed through, try to use the TOMCAT_HOME environment variable.
String containerHome = System.getProperty("cargo.container.home");
- if (containerHome == null || containerHome.startsWith("$")) {
+ if (containerHome == null || containerHome.startsWith("$"))
+ {
containerHome = System.getenv("TOMCAT_HOME");
}
System.out.println("[INFO] container home: " + containerHome);
@@ -133,14 +133,16 @@
// Find and (if provided) set the path to a log file
String containerLog = System.getProperty("cargo.container.log");
- if (containerLog != null) {
+ if (containerLog != null)
+ {
System.out.println("[INFO] container log: " + containerLog);
container.setLogger(new FileLogger(containerLog, false));
}
// Find and (if provided) set the path to an output file
String containerOutput = System.getProperty("cargo.container.output");
- if (containerOutput != null) {
+ if (containerOutput != null)
+ {
System.out.println("[INFO] container output: " + containerOutput);
container.setOutput(new File(containerOutput));
}
@@ -148,18 +150,17 @@
container.start();
}
-
/**
* Stop the container after running the tests.
*
* @throws Exception if an error occurs.
*/
- protected void tearDown() throws Exception {
+ protected void tearDown() throws Exception
+ {
container.stop();
super.tearDown();
}
-
/**
* Return the name of the test setup.
* (Temporarily required due to MSUREFIRE-119.)
@@ -168,9 +169,9 @@
* @deprecated No replacement.
*/
- public String getName() {
+ public String getName()
+ {
return "CargoTestSetup";
}
}
-
diff --git a/test12/src/main/java/org/apache/myfaces/test/config/ConfigParser.java b/test12/src/main/java/org/apache/myfaces/test/config/ConfigParser.java
index 93968d7..d47273a 100644
--- a/test12/src/main/java/org/apache/myfaces/test/config/ConfigParser.java
+++ b/test12/src/main/java/org/apache/myfaces/test/config/ConfigParser.java
@@ -56,54 +56,42 @@
*
* @since 1.0.0
*/
-public class ConfigParser {
-
+public class ConfigParser
+{
// ------------------------------------------------------------ Constructors
-
/** Creates a new instance of ConfigParser */
- public ConfigParser() {
+ public ConfigParser()
+ {
}
-
// ------------------------------------------------------ Manifest Constants
-
/**
* <p>Configuration resource URLs for the JSF RI.</p>
*/
- private static final String[] JSFRI_RESOURCES =
- { "/com/sun/faces/jsf-ri-runtime.xml",
- };
-
+ private static final String[] JSFRI_RESOURCES = { "/com/sun/faces/jsf-ri-runtime.xml", };
/**
* <p>Configuration resource URLs for Apache MyFaces.</p>
*/
- private static final String[] MYFACES_RESOURCES =
- { "/org/apache/myfaces/resource/standard-faces-config.xml",
- };
+ private static final String[] MYFACES_RESOURCES = { "/org/apache/myfaces/resource/standard-faces-config.xml", };
/**
* <p>Configuration resource URLs for Apache MyFaces 1.2.</p>
*/
- private static final String[] MYFACES_RESOURCES12 =
- { "/META-INF/standard-faces-config.xml",
- };
+ private static final String[] MYFACES_RESOURCES12 = { "/META-INF/standard-faces-config.xml", };
// ------------------------------------------------------ Instance Variables
-
/**
* <p>The <code>Digester</code> instance we will use for parsing.</p>
*/
private Digester digester = null;
-
// ------------------------------------------------------- Public Properties
-
/**
* <p>Return the URLs of the platform configuration resources for this
* application. The following platforms are currently supported:</p>
@@ -115,12 +103,15 @@
* <p>If MyFaces (version 1.2), currently under development, does not change
* the name of the configuration resource, it will be supported as well.</p>
*/
- public URL[] getPlatformURLs() {
+ public URL[] getPlatformURLs()
+ {
URL[] urls = translate(JSFRI_RESOURCES);
- if (urls[0] == null) {
+ if (urls[0] == null)
+ {
urls = translate(MYFACES_RESOURCES12);
- if (urls[0] == null) {
+ if (urls[0] == null)
+ {
urls = translate(MYFACES_RESOURCES);
}
}
@@ -128,10 +119,8 @@
}
-
// ---------------------------------------------------------- Public Methods
-
/**
* <p>Parse the specified JavaServer Faces configuration resource, causing
* the appropriate JSF artifacts to be registered with the mock object
@@ -142,25 +131,28 @@
* @exception IOException if an input/output error occurs
* @exception SAXException if a parsing error occurs
*/
- public void parse(URL url) throws IOException, SAXException {
+ public void parse(URL url) throws IOException, SAXException
+ {
// Acquire and configure the Digester instance we will use
Digester digester = digester();
- ApplicationFactory factory = (ApplicationFactory)
- FactoryFinder.getFactory(FactoryFinder.APPLICATION_FACTORY);
+ ApplicationFactory factory = (ApplicationFactory) FactoryFinder
+ .getFactory(FactoryFinder.APPLICATION_FACTORY);
Application application = factory.getApplication();
digester.push(application);
// Perform the required parsing
- try {
+ try
+ {
digester.parse(url);
- } finally {
+ }
+ finally
+ {
digester.clear();
}
}
-
/**
* <p>Parse the specified set of JavaServer Faces configuration resources,
* in the listed order, causing the appropriate JSF artifacts to be registered
@@ -171,226 +163,272 @@
* @exception IOException if an input/output error occurs
* @exception SAXException if a parsing error occurs
*/
- public void parse(URL[] urls) throws IOException, SAXException {
+ public void parse(URL[] urls) throws IOException, SAXException
+ {
- for (int i = 0; i < urls.length; i++) {
+ for (int i = 0; i < urls.length; i++)
+ {
parse(urls[i]);
}
}
-
// --------------------------------------------------------- Private Methods
-
/**
* <p>Return the <code>Digester</code> instance we will use for parsing,
* creating and configuring a new instance if necessary.</p>
*/
- private Digester digester() {
+ private Digester digester()
+ {
- if (this.digester == null) {
+ if (this.digester == null)
+ {
this.digester = new Digester();
digester.addRule("faces-config/component", new ComponentRule());
- digester.addCallMethod
- ("faces-config/component/component-type", "setComponentType", 0);
- digester.addCallMethod
- ("faces-config/component/component-class", "setComponentClass", 0);
+ digester.addCallMethod("faces-config/component/component-type",
+ "setComponentType", 0);
+ digester.addCallMethod("faces-config/component/component-class",
+ "setComponentClass", 0);
digester.addRule("faces-config/converter", new ConverterRule());
- digester.addCallMethod
- ("faces-config/converter/converter-id", "setConverterId", 0);
- digester.addCallMethod
- ("faces-config/converter/converter-class", "setConverterClass", 0);
- digester.addCallMethod
- ("faces-config/converter/converter-for-class", "setConverterForClass", 0);
+ digester.addCallMethod("faces-config/converter/converter-id",
+ "setConverterId", 0);
+ digester.addCallMethod("faces-config/converter/converter-class",
+ "setConverterClass", 0);
+ digester.addCallMethod(
+ "faces-config/converter/converter-for-class",
+ "setConverterForClass", 0);
digester.addRule("faces-config/render-kit", new RenderKitRule());
- digester.addRule("faces-config/render-kit/render-kit-id", new RenderKitIdRule());
- digester.addRule("faces-config/render-kit/renderer", new RendererRule());
- digester.addCallMethod
- ("faces-config/render-kit/renderer/component-family", "setComponentFamily", 0);
- digester.addCallMethod
- ("faces-config/render-kit/renderer/renderer-class", "setRendererClass", 0);
- digester.addCallMethod
- ("faces-config/render-kit/renderer/renderer-type", "setRendererType", 0);
+ digester.addRule("faces-config/render-kit/render-kit-id",
+ new RenderKitIdRule());
+ digester.addRule("faces-config/render-kit/renderer",
+ new RendererRule());
+ digester.addCallMethod(
+ "faces-config/render-kit/renderer/component-family",
+ "setComponentFamily", 0);
+ digester.addCallMethod(
+ "faces-config/render-kit/renderer/renderer-class",
+ "setRendererClass", 0);
+ digester.addCallMethod(
+ "faces-config/render-kit/renderer/renderer-type",
+ "setRendererType", 0);
digester.addRule("faces-config/validator", new ValidatorRule());
- digester.addCallMethod
- ("faces-config/validator/validator-id", "setValidatorId", 0);
- digester.addCallMethod
- ("faces-config/validator/validator-class", "setValidatorClass", 0);
+ digester.addCallMethod("faces-config/validator/validator-id",
+ "setValidatorId", 0);
+ digester.addCallMethod("faces-config/validator/validator-class",
+ "setValidatorClass", 0);
}
return this.digester;
}
-
/**
* <p>Translate an array of resource names into an array of resource URLs.</p>
*
* @param names Resource names to translate
*/
- private URL[] translate(String[] names) {
+ private URL[] translate(String[] names)
+ {
URL[] results = new URL[names.length];
- for (int i = 0; i < names.length; i++) {
+ for (int i = 0; i < names.length; i++)
+ {
results[i] = this.getClass().getResource(names[i]);
}
return results;
-
+
}
-
// --------------------------------------------------------- Private Classes
-
/**
* <p>Data bean that stores information related to a component.</p>
*/
- class ComponentBean {
+ class ComponentBean
+ {
private String componentClass;
- public String getComponentClass() {
+
+ public String getComponentClass()
+ {
return this.componentClass;
}
- public void setComponentClass(String componentClass) {
+
+ public void setComponentClass(String componentClass)
+ {
this.componentClass = componentClass;
}
private String componentType;
- public String getComponentType() {
+
+ public String getComponentType()
+ {
return this.componentType;
}
- public void setComponentType(String componentType) {
+
+ public void setComponentType(String componentType)
+ {
this.componentType = componentType;
}
}
-
/**
* <p>Digester <code>Rule</code> for processing components.</p>
*/
- class ComponentRule extends Rule {
+ class ComponentRule extends Rule
+ {
- public void begin(String namespace, String name, Attributes attributes) {
+ public void begin(String namespace, String name, Attributes attributes)
+ {
getDigester().push(new ComponentBean());
}
- public void end(String namespace, String name) {
+ public void end(String namespace, String name)
+ {
ComponentBean bean = (ComponentBean) getDigester().pop();
Application application = (Application) getDigester().peek();
- application.addComponent(bean.getComponentType(), bean.getComponentClass());
+ application.addComponent(bean.getComponentType(), bean
+ .getComponentClass());
}
}
-
/**
* <p>Data bean that stores information related to a converter.</p>
*/
- class ConverterBean {
+ class ConverterBean
+ {
private String converterClass;
- public String getConverterClass() {
+
+ public String getConverterClass()
+ {
return this.converterClass;
}
- public void setConverterClass(String converterClass) {
+
+ public void setConverterClass(String converterClass)
+ {
this.converterClass = converterClass;
}
private String converterForClass;
- public String getConverterForClass() {
+
+ public String getConverterForClass()
+ {
return this.converterForClass;
}
- public void setConverterForClass(String converterForClass) {
+
+ public void setConverterForClass(String converterForClass)
+ {
this.converterForClass = converterForClass;
}
private String converterId;
- public String getConverterId() {
+
+ public String getConverterId()
+ {
return this.converterId;
}
- public void setConverterId(String converterId) {
+
+ public void setConverterId(String converterId)
+ {
this.converterId = converterId;
}
}
-
/**
* <p>Digester <code>Rule</code> for processing converers.</p>
*/
- class ConverterRule extends Rule {
+ class ConverterRule extends Rule
+ {
- public void begin(String namespace, String name, Attributes attributes) {
+ public void begin(String namespace, String name, Attributes attributes)
+ {
getDigester().push(new ConverterBean());
}
- public void end(String namespace, String name) {
+ public void end(String namespace, String name)
+ {
ConverterBean bean = (ConverterBean) getDigester().pop();
Application application = (Application) getDigester().peek();
- if (bean.getConverterId() != null) {
- application.addConverter(bean.getConverterId(), bean.getConverterClass());
- } else {
+ if (bean.getConverterId() != null)
+ {
+ application.addConverter(bean.getConverterId(), bean
+ .getConverterClass());
+ }
+ else
+ {
Class clazz = null;
- try {
+ try
+ {
clazz = classForName(bean.getConverterForClass());
- } catch (ClassNotFoundException e) {
- throw new IllegalArgumentException("java.lang.ClassNotFoundException: "
- + bean.getConverterForClass());
+ }
+ catch (ClassNotFoundException e)
+ {
+ throw new IllegalArgumentException(
+ "java.lang.ClassNotFoundException: "
+ + bean.getConverterForClass());
}
application.addConverter(clazz, bean.getConverterClass());
}
}
}
-
+
private Class classForName(String type) throws ClassNotFoundException
{
try
{
// Try WebApp ClassLoader first
- return Class.forName(type,
- false, // do not initialize for faster startup
- Thread.currentThread().getContextClassLoader());
+ return Class.forName(type, false, // do not initialize for faster startup
+ Thread.currentThread().getContextClassLoader());
}
catch (ClassNotFoundException ignore)
{
// fallback: Try ClassLoader for ClassUtils (i.e. the myfaces.jar lib)
- return Class.forName(type,
- false, // do not initialize for faster startup
- this.getClass().getClassLoader());
- }
+ return Class.forName(type, false, // do not initialize for faster startup
+ this.getClass().getClassLoader());
+ }
}
/**
* <p>Digester <code>Rule</code> for processing render kits.</p>
*/
- class RenderKitRule extends Rule {
+ class RenderKitRule extends Rule
+ {
- public void begin(String namespace, String name, Attributes attributes) {
- RenderKitFactory factory = (RenderKitFactory)
- FactoryFinder.getFactory(FactoryFinder.RENDER_KIT_FACTORY);
- getDigester().push(factory.getRenderKit(null, RenderKitFactory.HTML_BASIC_RENDER_KIT));
+ public void begin(String namespace, String name, Attributes attributes)
+ {
+ RenderKitFactory factory = (RenderKitFactory) FactoryFinder
+ .getFactory(FactoryFinder.RENDER_KIT_FACTORY);
+ getDigester().push(
+ factory.getRenderKit(null,
+ RenderKitFactory.HTML_BASIC_RENDER_KIT));
}
- public void end(String namespace, String name) {
+ public void end(String namespace, String name)
+ {
getDigester().pop();
}
}
-
/**
* <p>Digester <code>Rule</code> for processing render kit identifiers.</p>
*/
- class RenderKitIdRule extends Rule {
+ class RenderKitIdRule extends Rule
+ {
- public void body(String namespace, String name, String text) {
+ public void body(String namespace, String name, String text)
+ {
String renderKitId = text.trim();
- RenderKitFactory factory = (RenderKitFactory)
- FactoryFinder.getFactory(FactoryFinder.RENDER_KIT_FACTORY);
+ RenderKitFactory factory = (RenderKitFactory) FactoryFinder
+ .getFactory(FactoryFinder.RENDER_KIT_FACTORY);
RenderKit renderKit = factory.getRenderKit(null, renderKitId);
- if (renderKit == null) {
+ if (renderKit == null)
+ {
renderKit = new MockRenderKit();
factory.addRenderKit(renderKitId, renderKit);
}
@@ -400,108 +438,136 @@
}
-
/**
* <p>Data bean that stores information related to a renderer.</p>
*/
- class RendererBean {
+ class RendererBean
+ {
private String componentFamily;
- public String getComponentFamily() {
+
+ public String getComponentFamily()
+ {
return this.componentFamily;
}
- public void setComponentFamily(String componentFamily) {
+
+ public void setComponentFamily(String componentFamily)
+ {
this.componentFamily = componentFamily;
}
private String rendererClass;
- public String getRendererClass() {
+
+ public String getRendererClass()
+ {
return this.rendererClass;
}
- public void setRendererClass(String rendererClass) {
+
+ public void setRendererClass(String rendererClass)
+ {
this.rendererClass = rendererClass;
}
private String rendererType;
- public String getRendererType() {
+
+ public String getRendererType()
+ {
return this.rendererType;
}
- public void setRendererType(String rendererType) {
+
+ public void setRendererType(String rendererType)
+ {
this.rendererType = rendererType;
}
}
-
/**
* <p>Digester <code>Rule</code> for processing renderers.</p>
*/
- class RendererRule extends Rule {
+ class RendererRule extends Rule
+ {
- public void begin(String namespace, String name, Attributes attributes) {
+ public void begin(String namespace, String name, Attributes attributes)
+ {
getDigester().push(new RendererBean());
}
- public void end(String namespace, String name) {
+ public void end(String namespace, String name)
+ {
RendererBean bean = (RendererBean) getDigester().pop();
RenderKit kit = (RenderKit) getDigester().peek();
Renderer renderer = null;
Class clazz = null;
- try {
+ try
+ {
clazz = classForName(bean.getRendererClass());
renderer = (Renderer) clazz.newInstance();
- } catch (Exception e) {
- throw new IllegalArgumentException("Exception while trying to instantiate"
- + " renderer class '" + bean.getRendererClass() + "' : "
- + e.getMessage());
+ }
+ catch (Exception e)
+ {
+ throw new IllegalArgumentException(
+ "Exception while trying to instantiate"
+ + " renderer class '" + bean.getRendererClass()
+ + "' : " + e.getMessage());
}
kit.addRenderer(bean.getComponentFamily(), bean.getRendererType(),
- renderer);
+ renderer);
}
}
-
/**
* <p>Data bean that stores information related to a validator.</p>
*/
- class ValidatorBean {
+ class ValidatorBean
+ {
private String validatorClass;
- public String getValidatorClass() {
+
+ public String getValidatorClass()
+ {
return this.validatorClass;
}
- public void setValidatorClass(String validatorClass) {
+
+ public void setValidatorClass(String validatorClass)
+ {
this.validatorClass = validatorClass;
}
private String validatorId;
- public String getValidatorId() {
+
+ public String getValidatorId()
+ {
return this.validatorId;
}
- public void setValidatorId(String validatorId) {
+
+ public void setValidatorId(String validatorId)
+ {
this.validatorId = validatorId;
}
}
-
/**
* <p>Digester <code>Rule</code> for processing validators.</p>
*/
- class ValidatorRule extends Rule {
+ class ValidatorRule extends Rule
+ {
- public void begin(String namespace, String name, Attributes attributes) {
+ public void begin(String namespace, String name, Attributes attributes)
+ {
getDigester().push(new ValidatorBean());
}
- public void end(String namespace, String name) {
+ public void end(String namespace, String name)
+ {
ValidatorBean bean = (ValidatorBean) getDigester().pop();
Application application = (Application) getDigester().peek();
- application.addValidator(bean.getValidatorId(), bean.getValidatorClass());
+ application.addValidator(bean.getValidatorId(), bean
+ .getValidatorClass());
}
}
-
}
diff --git a/test12/src/main/java/org/apache/myfaces/test/el/AbstractELResolver.java b/test12/src/main/java/org/apache/myfaces/test/el/AbstractELResolver.java
index cd5a552..a96e22f 100644
--- a/test12/src/main/java/org/apache/myfaces/test/el/AbstractELResolver.java
+++ b/test12/src/main/java/org/apache/myfaces/test/el/AbstractELResolver.java
@@ -25,13 +25,11 @@
*
* @since 1.0.0
*/
-abstract class AbstractELResolver extends ELResolver {
-
-
+abstract class AbstractELResolver extends ELResolver
+{
// ------------------------------------------------------- Protected Methods
-
/**
* <p>Create and return a <code>FeatureDescriptor</code> configured with
* the specified arguments.</p>
@@ -47,27 +45,32 @@
* @param designTime Flag indicating feature is resolvable at design time
*/
protected FeatureDescriptor descriptor(String name, String displayName,
- String description, boolean expert, boolean hidden, boolean preferred,
- Object type, boolean designTime) {
+ String description, boolean expert, boolean hidden,
+ boolean preferred, Object type, boolean designTime)
+ {
- FeatureDescriptor descriptor = new FeatureDescriptor();
+ FeatureDescriptor descriptor = new FeatureDescriptor();
- descriptor.setName(name);
- descriptor.setDisplayName(displayName);
- descriptor.setShortDescription(description);
- descriptor.setExpert(expert);
- descriptor.setHidden(hidden);
- descriptor.setPreferred(preferred);
- descriptor.setValue(ELResolver.TYPE, type);
- if (designTime) {
- descriptor.setValue(ELResolver.RESOLVABLE_AT_DESIGN_TIME, Boolean.TRUE);
- } else {
- descriptor.setValue(ELResolver.RESOLVABLE_AT_DESIGN_TIME, Boolean.FALSE);
- }
+ descriptor.setName(name);
+ descriptor.setDisplayName(displayName);
+ descriptor.setShortDescription(description);
+ descriptor.setExpert(expert);
+ descriptor.setHidden(hidden);
+ descriptor.setPreferred(preferred);
+ descriptor.setValue(ELResolver.TYPE, type);
+ if (designTime)
+ {
+ descriptor.setValue(ELResolver.RESOLVABLE_AT_DESIGN_TIME,
+ Boolean.TRUE);
+ }
+ else
+ {
+ descriptor.setValue(ELResolver.RESOLVABLE_AT_DESIGN_TIME,
+ Boolean.FALSE);
+ }
- return descriptor;
+ return descriptor;
}
-
}
diff --git a/test12/src/main/java/org/apache/myfaces/test/el/FacesImplicitObjectELResolver.java b/test12/src/main/java/org/apache/myfaces/test/el/FacesImplicitObjectELResolver.java
index 2f5e112..2bbdec4 100644
--- a/test12/src/main/java/org/apache/myfaces/test/el/FacesImplicitObjectELResolver.java
+++ b/test12/src/main/java/org/apache/myfaces/test/el/FacesImplicitObjectELResolver.java
@@ -36,52 +36,51 @@
*
* @since 1.0.0
*/
-public class FacesImplicitObjectELResolver extends AbstractELResolver {
-
+public class FacesImplicitObjectELResolver extends AbstractELResolver
+{
/**
* <p>The names of all implicit objects recognized by this resolver.</p>
*/
- private static final String[] NAMES =
- { "application", "applicationScope", "cookie", "facesContext",
- "header", "headerValues", "initParam", "param", "paramValues",
- "request", "requestScope", "session", "sessionScope", "view" };
-
+ private static final String[] NAMES = { "application", "applicationScope",
+ "cookie", "facesContext", "header", "headerValues", "initParam",
+ "param", "paramValues", "request", "requestScope", "session",
+ "sessionScope", "view" };
/**
* <p>The property types corresponding to the implicit object names.</p>
*/
- private static final Class[] TYPES =
- { Object.class, Map.class, Map.class, FacesContext.class,
- Map.class, Map.class, Map.class, Map.class, Map.class,
- Object.class, Map.class, Object.class, Map.class, UIViewRoot.class };
-
+ private static final Class[] TYPES = { Object.class, Map.class, Map.class,
+ FacesContext.class, Map.class, Map.class, Map.class, Map.class,
+ Map.class, Object.class, Map.class, Object.class, Map.class,
+ UIViewRoot.class };
/**
* <p>The settable value types corresponding to the implicit
* object names.</p>
*/
- private static final Class[] VALUES =
- { null, Object.class, null, null,
- null, null, null, null, null,
- null, Object.class, null, Object.class, null };
-
+ private static final Class[] VALUES = { null, Object.class, null, null,
+ null, null, null, null, null, null, Object.class, null,
+ Object.class, null };
/**
* <p>Return the most general type this resolver accepts for the
* <code>property</code> argument.</p>
*/
- public Class getCommonPropertyType(ELContext context, Object base) {
+ public Class getCommonPropertyType(ELContext context, Object base)
+ {
- if (base != null) {
+ if (base != null)
+ {
return null;
- } else {
+ }
+ else
+ {
return String.class;
}
}
-
/**
* <p>Return an <code>Iterator</code> over the attributes that this
* resolver knows how to deal with.</p>
@@ -89,20 +88,24 @@
* @param context <code>ELContext</code> for evaluating this value
* @param base Base object against which this evaluation occurs
*/
- public Iterator getFeatureDescriptors(ELContext context, Object base) {
+ public Iterator getFeatureDescriptors(ELContext context, Object base)
+ {
- if (base != null) {
+ if (base != null)
+ {
return null;
}
// Create the variables we will need
- FacesContext fcontext = (FacesContext) context.getContext(FacesContext.class);
+ FacesContext fcontext = (FacesContext) context
+ .getContext(FacesContext.class);
List descriptors = new ArrayList();
// Add feature descriptors for each implicit object
- for (int i = 0; i < NAMES.length; i++) {
- descriptors.add(descriptor(NAMES[i], NAMES[i], NAMES[i],
- false, false, true, TYPES[i], true));
+ for (int i = 0; i < NAMES.length; i++)
+ {
+ descriptors.add(descriptor(NAMES[i], NAMES[i], NAMES[i], false,
+ false, true, TYPES[i], true));
}
// Return the accumulated descriptors
@@ -110,8 +113,6 @@
}
-
-
/**
* <p>Return the Java type of the specified property.</p>
*
@@ -120,17 +121,22 @@
* (must be null because we are evaluating a top level variable)
* @param property Property name to be accessed
*/
- public Class getType(ELContext context, Object base, Object property) {
+ public Class getType(ELContext context, Object base, Object property)
+ {
- if (base != null) {
+ if (base != null)
+ {
return null;
}
- if (property == null) {
+ if (property == null)
+ {
throw new PropertyNotFoundException("No property specified");
}
String name = property.toString();
- for (int i = 0; i < NAMES.length; i++) {
- if (name.equals(NAMES[i])) {
+ for (int i = 0; i < NAMES.length; i++)
+ {
+ if (name.equals(NAMES[i]))
+ {
context.setPropertyResolved(true);
return VALUES[i];
}
@@ -139,7 +145,6 @@
}
-
/**
* <p>Return an existing scoped object for the specified name (if any);
* otherwise, return <code>null</code>.</p>
@@ -149,59 +154,90 @@
* (must be null because we are evaluating a top level variable)
* @param property Property name to be accessed
*/
- public Object getValue(ELContext context, Object base, Object property) {
+ public Object getValue(ELContext context, Object base, Object property)
+ {
- if (base != null) {
+ if (base != null)
+ {
return null;
}
- if (property == null) {
+ if (property == null)
+ {
throw new PropertyNotFoundException("No property specified");
}
- FacesContext fcontext = (FacesContext) context.getContext(FacesContext.class);
+ FacesContext fcontext = (FacesContext) context
+ .getContext(FacesContext.class);
ExternalContext econtext = fcontext.getExternalContext();
String name = property.toString();
- if (name.equals("application")) {
+ if (name.equals("application"))
+ {
context.setPropertyResolved(true);
return econtext.getContext();
- } else if (name.equals("applicationScope")) {
+ }
+ else if (name.equals("applicationScope"))
+ {
context.setPropertyResolved(true);
return econtext.getApplicationMap();
- } else if (name.equals("cookie")) {
+ }
+ else if (name.equals("cookie"))
+ {
context.setPropertyResolved(true);
return econtext.getRequestCookieMap();
- } else if (name.equals("facesContext")) {
+ }
+ else if (name.equals("facesContext"))
+ {
context.setPropertyResolved(true);
return fcontext;
- } else if (name.equals("header")) {
+ }
+ else if (name.equals("header"))
+ {
context.setPropertyResolved(true);
return econtext.getRequestHeaderMap();
- } else if (name.equals("headerValues")) {
+ }
+ else if (name.equals("headerValues"))
+ {
context.setPropertyResolved(true);
return econtext.getRequestHeaderValuesMap();
- } else if (name.equals("initParam")) {
+ }
+ else if (name.equals("initParam"))
+ {
context.setPropertyResolved(true);
return econtext.getInitParameterMap();
- } else if (name.equals("param")) {
+ }
+ else if (name.equals("param"))
+ {
context.setPropertyResolved(true);
return econtext.getRequestParameterMap();
- } else if (name.equals("paramValues")) {
+ }
+ else if (name.equals("paramValues"))
+ {
context.setPropertyResolved(true);
return econtext.getRequestParameterValuesMap();
- } else if (name.equals("request")) {
+ }
+ else if (name.equals("request"))
+ {
context.setPropertyResolved(true);
return econtext.getRequest();
- } else if (name.equals("requestScope")) {
+ }
+ else if (name.equals("requestScope"))
+ {
context.setPropertyResolved(true);
return econtext.getRequestMap();
- } else if (name.equals("session")) {
+ }
+ else if (name.equals("session"))
+ {
context.setPropertyResolved(true);
return econtext.getSession(true);
- } else if (name.equals("sessionScope")) {
+ }
+ else if (name.equals("sessionScope"))
+ {
context.setPropertyResolved(true);
return econtext.getSessionMap();
- } else if (name.equals("view")) {
+ }
+ else if (name.equals("view"))
+ {
context.setPropertyResolved(true);
return fcontext.getViewRoot();
}
@@ -210,7 +246,6 @@
}
-
/**
* <p>Return <code>true</code> if the specified property is read only.</p>
*
@@ -219,17 +254,22 @@
* (must be null because we are evaluating a top level variable)
* @param property Property name to be accessed
*/
- public boolean isReadOnly(ELContext context, Object base, Object property) {
+ public boolean isReadOnly(ELContext context, Object base, Object property)
+ {
- if (base != null) {
+ if (base != null)
+ {
return false;
}
- if (property == null) {
+ if (property == null)
+ {
throw new PropertyNotFoundException("No property specified");
}
String name = property.toString();
- for (int i = 0; i < NAMES.length; i++) {
- if (name.equals(NAMES[i])) {
+ for (int i = 0; i < NAMES.length; i++)
+ {
+ if (name.equals(NAMES[i]))
+ {
context.setPropertyResolved(true);
return true;
}
@@ -238,8 +278,6 @@
}
-
-
/**
* <p>Set the value of a scoped object for the specified name.</p>
*
@@ -249,18 +287,24 @@
* @param property Property name to be accessed
* @param value New value to be set
*/
- public void setValue(ELContext context, Object base, Object property, Object value) {
+ public void setValue(ELContext context, Object base, Object property,
+ Object value)
+ {
- if (base != null) {
+ if (base != null)
+ {
return;
}
- if (property == null) {
+ if (property == null)
+ {
throw new PropertyNotFoundException("No property specified");
}
String name = property.toString();
- for (int i = 0; i < NAMES.length; i++) {
- if (name.equals(NAMES[i])) {
+ for (int i = 0; i < NAMES.length; i++)
+ {
+ if (name.equals(NAMES[i]))
+ {
context.setPropertyResolved(true);
throw new PropertyNotWritableException(name);
}
@@ -268,5 +312,4 @@
}
-
}
diff --git a/test12/src/main/java/org/apache/myfaces/test/el/FacesPropertyResolverChainWrapper.java b/test12/src/main/java/org/apache/myfaces/test/el/FacesPropertyResolverChainWrapper.java
index 6b6b79b..1600667 100644
--- a/test12/src/main/java/org/apache/myfaces/test/el/FacesPropertyResolverChainWrapper.java
+++ b/test12/src/main/java/org/apache/myfaces/test/el/FacesPropertyResolverChainWrapper.java
@@ -33,24 +33,27 @@
*
* @since 1.0.0
*/
-public class FacesPropertyResolverChainWrapper extends AbstractELResolver {
-
+public class FacesPropertyResolverChainWrapper extends AbstractELResolver
+{
/**
* <p>Return the most general type this resolver accepts for the
* <code>property</code> argument.</p>
*/
- public Class getCommonPropertyType(ELContext context, Object base) {
+ public Class getCommonPropertyType(ELContext context, Object base)
+ {
- if (base != null) {
+ if (base != null)
+ {
return null;
- } else {
+ }
+ else
+ {
return Object.class;
}
}
-
/**
* <p>Return an <code>Iterator</code> over the attributes that this
* resolver knows how to deal with.</p>
@@ -58,14 +61,13 @@
* @param context <code>ELContext</code> for evaluating this value
* @param base Base object against which this evaluation occurs
*/
- public Iterator getFeatureDescriptors(ELContext context, Object base) {
+ public Iterator getFeatureDescriptors(ELContext context, Object base)
+ {
return null;
}
-
-
/**
* <p>Evaluate with the legacy property resolver chain and return
* the value.</p>
@@ -75,30 +77,43 @@
* (must be null because we are evaluating a top level variable)
* @param property Property name to be accessed
*/
- public Class getType(ELContext context, Object base, Object property) {
+ public Class getType(ELContext context, Object base, Object property)
+ {
- if ((base == null) || (property == null)) {
+ if ((base == null) || (property == null))
+ {
return null;
}
context.setPropertyResolved(true);
- FacesContext fcontext = (FacesContext) context.getContext(FacesContext.class);
+ FacesContext fcontext = (FacesContext) context
+ .getContext(FacesContext.class);
ELContext elContext = fcontext.getELContext();
PropertyResolver pr = fcontext.getApplication().getPropertyResolver();
- if ((base instanceof List) || base.getClass().isArray()) {
- Integer index = (Integer) fcontext.getApplication().getExpressionFactory().
- coerceToType(property, Integer.class);
- try {
+ if ((base instanceof List) || base.getClass().isArray())
+ {
+ Integer index = (Integer) fcontext.getApplication()
+ .getExpressionFactory().coerceToType(property,
+ Integer.class);
+ try
+ {
return pr.getType(base, index.intValue());
- } catch (EvaluationException e) {
+ }
+ catch (EvaluationException e)
+ {
context.setPropertyResolved(false);
throw new ELException(e);
}
- } else {
- try {
+ }
+ else
+ {
+ try
+ {
return pr.getType(base, property);
- } catch (EvaluationException e) {
+ }
+ catch (EvaluationException e)
+ {
context.setPropertyResolved(false);
throw new ELException(e);
}
@@ -106,7 +121,6 @@
}
-
/**
* <p>Evaluate with the legacy property resolver chain and return
* the value.</p>
@@ -116,30 +130,43 @@
* (must be null because we are evaluating a top level variable)
* @param property Property name to be accessed
*/
- public Object getValue(ELContext context, Object base, Object property) {
+ public Object getValue(ELContext context, Object base, Object property)
+ {
- if ((base == null) || (property == null)) {
+ if ((base == null) || (property == null))
+ {
return null;
}
context.setPropertyResolved(true);
- FacesContext fcontext = (FacesContext) context.getContext(FacesContext.class);
+ FacesContext fcontext = (FacesContext) context
+ .getContext(FacesContext.class);
ELContext elContext = fcontext.getELContext();
PropertyResolver pr = fcontext.getApplication().getPropertyResolver();
- if ((base instanceof List) || base.getClass().isArray()) {
- Integer index = (Integer) fcontext.getApplication().getExpressionFactory().
- coerceToType(property, Integer.class);
- try {
+ if ((base instanceof List) || base.getClass().isArray())
+ {
+ Integer index = (Integer) fcontext.getApplication()
+ .getExpressionFactory().coerceToType(property,
+ Integer.class);
+ try
+ {
return pr.getValue(base, index.intValue());
- } catch (EvaluationException e) {
+ }
+ catch (EvaluationException e)
+ {
context.setPropertyResolved(false);
throw new ELException(e);
}
- } else {
- try {
+ }
+ else
+ {
+ try
+ {
return pr.getValue(base, property);
- } catch (EvaluationException e) {
+ }
+ catch (EvaluationException e)
+ {
context.setPropertyResolved(false);
throw new ELException(e);
}
@@ -147,7 +174,6 @@
}
-
/**
* <p>Return <code>true</code> if the specified property is read only.</p>
*
@@ -156,30 +182,43 @@
* (must be null because we are evaluating a top level variable)
* @param property Property name to be accessed
*/
- public boolean isReadOnly(ELContext context, Object base, Object property) {
+ public boolean isReadOnly(ELContext context, Object base, Object property)
+ {
- if ((base == null) || (property == null)) {
+ if ((base == null) || (property == null))
+ {
return false;
}
context.setPropertyResolved(true);
- FacesContext fcontext = (FacesContext) context.getContext(FacesContext.class);
+ FacesContext fcontext = (FacesContext) context
+ .getContext(FacesContext.class);
ELContext elContext = fcontext.getELContext();
PropertyResolver pr = fcontext.getApplication().getPropertyResolver();
- if ((base instanceof List) || base.getClass().isArray()) {
- Integer index = (Integer) fcontext.getApplication().getExpressionFactory().
- coerceToType(property, Integer.class);
- try {
+ if ((base instanceof List) || base.getClass().isArray())
+ {
+ Integer index = (Integer) fcontext.getApplication()
+ .getExpressionFactory().coerceToType(property,
+ Integer.class);
+ try
+ {
return pr.isReadOnly(base, index.intValue());
- } catch (EvaluationException e) {
+ }
+ catch (EvaluationException e)
+ {
context.setPropertyResolved(false);
throw new ELException(e);
}
- } else {
- try {
+ }
+ else
+ {
+ try
+ {
return pr.isReadOnly(base, property);
- } catch (EvaluationException e) {
+ }
+ catch (EvaluationException e)
+ {
context.setPropertyResolved(false);
throw new ELException(e);
}
@@ -187,8 +226,6 @@
}
-
-
/**
* <p>Set the value of a property for the specified name.</p>
*
@@ -198,30 +235,44 @@
* @param property Property name to be accessed
* @param value New value to be set
*/
- public void setValue(ELContext context, Object base, Object property, Object value) {
+ public void setValue(ELContext context, Object base, Object property,
+ Object value)
+ {
- if ((base == null) || (property == null)) {
+ if ((base == null) || (property == null))
+ {
return;
}
context.setPropertyResolved(true);
- FacesContext fcontext = (FacesContext) context.getContext(FacesContext.class);
+ FacesContext fcontext = (FacesContext) context
+ .getContext(FacesContext.class);
ELContext elContext = fcontext.getELContext();
PropertyResolver pr = fcontext.getApplication().getPropertyResolver();
- if ((base instanceof List) || base.getClass().isArray()) {
- Integer index = (Integer) fcontext.getApplication().getExpressionFactory().
- coerceToType(property, Integer.class);
- try {
+ if ((base instanceof List) || base.getClass().isArray())
+ {
+ Integer index = (Integer) fcontext.getApplication()
+ .getExpressionFactory().coerceToType(property,
+ Integer.class);
+ try
+ {
pr.setValue(base, index.intValue(), value);
- } catch (EvaluationException e) {
+ }
+ catch (EvaluationException e)
+ {
context.setPropertyResolved(false);
throw new ELException(e);
}
- } else {
- try {
+ }
+ else
+ {
+ try
+ {
pr.setValue(base, property, value);
- } catch (EvaluationException e) {
+ }
+ catch (EvaluationException e)
+ {
context.setPropertyResolved(false);
throw new ELException(e);
}
@@ -229,5 +280,4 @@
}
-
}
diff --git a/test12/src/main/java/org/apache/myfaces/test/el/FacesResourceBundleELResolver.java b/test12/src/main/java/org/apache/myfaces/test/el/FacesResourceBundleELResolver.java
index fe0ed61..edd304d 100644
--- a/test12/src/main/java/org/apache/myfaces/test/el/FacesResourceBundleELResolver.java
+++ b/test12/src/main/java/org/apache/myfaces/test/el/FacesResourceBundleELResolver.java
@@ -37,24 +37,27 @@
*
* @since 1.0.0
*/
-public class FacesResourceBundleELResolver extends AbstractELResolver {
-
+public class FacesResourceBundleELResolver extends AbstractELResolver
+{
/**
* <p>Return the most general type this resolver accepts for the
* <code>property</code> argument.</p>
*/
- public Class getCommonPropertyType(ELContext context, Object base) {
+ public Class getCommonPropertyType(ELContext context, Object base)
+ {
- if (base != null) {
+ if (base != null)
+ {
return null;
- } else {
+ }
+ else
+ {
return String.class;
}
}
-
/**
* <p>Return an <code>Iterator</code> over the attributes that this
* resolver knows how to deal with.</p>
@@ -62,29 +65,33 @@
* @param context <code>ELContext</code> for evaluating this value
* @param base Base object against which this evaluation occurs
*/
- public Iterator getFeatureDescriptors(ELContext context, Object base) {
+ public Iterator getFeatureDescriptors(ELContext context, Object base)
+ {
- if (base != null) {
+ if (base != null)
+ {
return null;
}
// Create the variables we will need
List descriptors = new ArrayList();
- FacesContext fcontext = (FacesContext) context.getContext(FacesContext.class);
- MockApplication12 application =
- (MockApplication12) fcontext.getApplication();
+ FacesContext fcontext = (FacesContext) context
+ .getContext(FacesContext.class);
+ MockApplication12 application = (MockApplication12) fcontext
+ .getApplication();
String key = null;
Object value = null;
// Create a feature descriptor for each configured resource bundle
- Iterator entries = application.getResourceBundles().entrySet().iterator();
- while (entries.hasNext()) {
+ Iterator entries = application.getResourceBundles().entrySet()
+ .iterator();
+ while (entries.hasNext())
+ {
Entry entry = (Entry) entries.next();
key = (String) entry.getKey();
value = entry.getValue();
descriptors.add(descriptor(key, key, "Resource Bundle " + key,
- false, false, true,
- ResourceBundle.class, true));
+ false, false, true, ResourceBundle.class, true));
}
// Return the accumulated descriptors
@@ -92,7 +99,6 @@
}
-
/**
* <p>Return the Java type of the specified property.</p>
*
@@ -101,18 +107,23 @@
* (must be null because we are evaluating a top level variable)
* @param property Property name to be accessed
*/
- public Class getType(ELContext context, Object base, Object property) {
+ public Class getType(ELContext context, Object base, Object property)
+ {
- if (base != null) {
+ if (base != null)
+ {
return null;
}
- if (property == null) {
+ if (property == null)
+ {
throw new PropertyNotFoundException("No property specified");
}
- FacesContext fcontext = (FacesContext) context.getContext(FacesContext.class);
- ResourceBundle bundle =
- fcontext.getApplication().getResourceBundle(fcontext, property.toString());
- if (bundle != null) {
+ FacesContext fcontext = (FacesContext) context
+ .getContext(FacesContext.class);
+ ResourceBundle bundle = fcontext.getApplication().getResourceBundle(
+ fcontext, property.toString());
+ if (bundle != null)
+ {
context.setPropertyResolved(true);
return ResourceBundle.class;
}
@@ -120,7 +131,6 @@
}
-
/**
* <p>Return a resource bundle for the specified name (if any);
* otherwise, return <code>null</code>.</p>
@@ -130,19 +140,24 @@
* (must be null because we are evaluating a top level variable)
* @param property Property name to be accessed
*/
- public Object getValue(ELContext context, Object base, Object property) {
+ public Object getValue(ELContext context, Object base, Object property)
+ {
- if (base != null) {
+ if (base != null)
+ {
return null;
}
- if (property == null) {
+ if (property == null)
+ {
throw new PropertyNotFoundException("No property specified");
}
- FacesContext fcontext = (FacesContext) context.getContext(FacesContext.class);
- ResourceBundle bundle =
- fcontext.getApplication().getResourceBundle(fcontext, property.toString());
- if (bundle != null) {
+ FacesContext fcontext = (FacesContext) context
+ .getContext(FacesContext.class);
+ ResourceBundle bundle = fcontext.getApplication().getResourceBundle(
+ fcontext, property.toString());
+ if (bundle != null)
+ {
context.setPropertyResolved(true);
return bundle;
}
@@ -150,7 +165,6 @@
}
-
/**
* <p>Return <code>true</code> if the specified property is read only.</p>
*
@@ -159,18 +173,23 @@
* (must be null because we are evaluating a top level variable)
* @param property Property name to be accessed
*/
- public boolean isReadOnly(ELContext context, Object base, Object property) {
+ public boolean isReadOnly(ELContext context, Object base, Object property)
+ {
- if (base != null) {
+ if (base != null)
+ {
return false;
}
- if (property == null) {
+ if (property == null)
+ {
throw new PropertyNotFoundException("No property specified");
}
- FacesContext fcontext = (FacesContext) context.getContext(FacesContext.class);
- ResourceBundle bundle =
- fcontext.getApplication().getResourceBundle(fcontext, property.toString());
- if (bundle != null) {
+ FacesContext fcontext = (FacesContext) context
+ .getContext(FacesContext.class);
+ ResourceBundle bundle = fcontext.getApplication().getResourceBundle(
+ fcontext, property.toString());
+ if (bundle != null)
+ {
context.setPropertyResolved(true);
return true;
}
@@ -178,8 +197,6 @@
}
-
-
/**
* <p>Set the value of a scoped object for the specified name.</p>
*
@@ -189,24 +206,29 @@
* @param property Property name to be accessed
* @param value New value to be set
*/
- public void setValue(ELContext context, Object base, Object property, Object value) {
+ public void setValue(ELContext context, Object base, Object property,
+ Object value)
+ {
- if (base != null) {
+ if (base != null)
+ {
return;
}
- if (property == null) {
+ if (property == null)
+ {
throw new PropertyNotFoundException("No property specified");
}
- FacesContext fcontext = (FacesContext) context.getContext(FacesContext.class);
- ResourceBundle bundle =
- fcontext.getApplication().getResourceBundle(fcontext, property.toString());
- if (bundle != null) {
+ FacesContext fcontext = (FacesContext) context
+ .getContext(FacesContext.class);
+ ResourceBundle bundle = fcontext.getApplication().getResourceBundle(
+ fcontext, property.toString());
+ if (bundle != null)
+ {
context.setPropertyResolved(true);
throw new PropertyNotWritableException(property.toString());
}
}
-
}
diff --git a/test12/src/main/java/org/apache/myfaces/test/el/FacesScopedAttributeELResolver.java b/test12/src/main/java/org/apache/myfaces/test/el/FacesScopedAttributeELResolver.java
index 14fcd71..8afadfb 100644
--- a/test12/src/main/java/org/apache/myfaces/test/el/FacesScopedAttributeELResolver.java
+++ b/test12/src/main/java/org/apache/myfaces/test/el/FacesScopedAttributeELResolver.java
@@ -36,24 +36,27 @@
*
* @since 1.0.0
*/
-public class FacesScopedAttributeELResolver extends AbstractELResolver {
-
+public class FacesScopedAttributeELResolver extends AbstractELResolver
+{
/**
* <p>Return the most general type this resolver accepts for the
* <code>property</code> argument.</p>
*/
- public Class getCommonPropertyType(ELContext context, Object base) {
+ public Class getCommonPropertyType(ELContext context, Object base)
+ {
- if (base != null) {
+ if (base != null)
+ {
return null;
- } else {
+ }
+ else
+ {
return String.class;
}
}
-
/**
* <p>Return an <code>Iterator</code> over the attributes that this
* resolver knows how to deal with.</p>
@@ -61,14 +64,17 @@
* @param context <code>ELContext</code> for evaluating this value
* @param base Base object against which this evaluation occurs
*/
- public Iterator getFeatureDescriptors(ELContext context, Object base) {
+ public Iterator getFeatureDescriptors(ELContext context, Object base)
+ {
- if (base != null) {
+ if (base != null)
+ {
return null;
}
// Create the variables we will need
- FacesContext fcontext = (FacesContext) context.getContext(FacesContext.class);
+ FacesContext fcontext = (FacesContext) context
+ .getContext(FacesContext.class);
ExternalContext econtext = fcontext.getExternalContext();
List descriptors = new ArrayList();
Map map = null;
@@ -80,34 +86,37 @@
// Add feature descriptors for request scoped attributes
set = econtext.getRequestMap().entrySet();
items = set.iterator();
- while (items.hasNext()) {
+ while (items.hasNext())
+ {
Entry item = (Entry) items.next();
key = (String) item.getKey();
value = item.getValue();
- descriptors.add(descriptor(key, key, "Request Scope Attribute " + key,
- false, false, true, value.getClass(), true));
+ descriptors.add(descriptor(key, key, "Request Scope Attribute "
+ + key, false, false, true, value.getClass(), true));
}
// Add feature descriptors for session scoped attributes
set = econtext.getSessionMap().entrySet();
items = set.iterator();
- while (items.hasNext()) {
+ while (items.hasNext())
+ {
Entry item = (Entry) items.next();
key = (String) item.getKey();
value = item.getValue();
- descriptors.add(descriptor(key, key, "Session Scope Attribute " + key,
- false, false, true, value.getClass(), true));
+ descriptors.add(descriptor(key, key, "Session Scope Attribute "
+ + key, false, false, true, value.getClass(), true));
}
// Add feature descriptors for application scoped attributes
set = econtext.getApplicationMap().entrySet();
items = set.iterator();
- while (items.hasNext()) {
+ while (items.hasNext())
+ {
Entry item = (Entry) items.next();
key = (String) item.getKey();
value = item.getValue();
- descriptors.add(descriptor(key, key, "Application Scope Attribute " + key,
- false, false, true, value.getClass(), true));
+ descriptors.add(descriptor(key, key, "Application Scope Attribute "
+ + key, false, false, true, value.getClass(), true));
}
// Return the accumulated descriptors
@@ -115,8 +124,6 @@
}
-
-
/**
* <p>Return the Java type of the specified property.</p>
*
@@ -125,12 +132,15 @@
* (must be null because we are evaluating a top level variable)
* @param property Property name to be accessed
*/
- public Class getType(ELContext context, Object base, Object property) {
+ public Class getType(ELContext context, Object base, Object property)
+ {
- if (base != null) {
+ if (base != null)
+ {
return null;
}
- if (property == null) {
+ if (property == null)
+ {
throw new PropertyNotFoundException("No property specified");
}
context.setPropertyResolved(true);
@@ -138,7 +148,6 @@
}
-
/**
* <p>Return an existing scoped object for the specified name (if any);
* otherwise, return <code>null</code>.</p>
@@ -148,30 +157,37 @@
* (must be null because we are evaluating a top level variable)
* @param property Property name to be accessed
*/
- public Object getValue(ELContext context, Object base, Object property) {
+ public Object getValue(ELContext context, Object base, Object property)
+ {
- if (base != null) {
+ if (base != null)
+ {
return null;
}
- if (property == null) {
+ if (property == null)
+ {
throw new PropertyNotFoundException("No property specified");
}
- FacesContext fcontext = (FacesContext) context.getContext(FacesContext.class);
+ FacesContext fcontext = (FacesContext) context
+ .getContext(FacesContext.class);
ExternalContext econtext = fcontext.getExternalContext();
Object value = null;
value = econtext.getRequestMap().get(property);
- if (value != null) {
+ if (value != null)
+ {
context.setPropertyResolved(true);
return value;
}
value = econtext.getSessionMap().get(property);
- if (value != null) {
+ if (value != null)
+ {
context.setPropertyResolved(true);
return value;
}
value = econtext.getApplicationMap().get(property);
- if (value != null) {
+ if (value != null)
+ {
context.setPropertyResolved(true);
return value;
}
@@ -180,7 +196,6 @@
}
-
/**
* <p>Return <code>true</code> if the specified property is read only.</p>
*
@@ -189,9 +204,11 @@
* (must be null because we are evaluating a top level variable)
* @param property Property name to be accessed
*/
- public boolean isReadOnly(ELContext context, Object base, Object property) {
+ public boolean isReadOnly(ELContext context, Object base, Object property)
+ {
- if (base == null) {
+ if (base == null)
+ {
context.setPropertyResolved(true);
return false;
}
@@ -199,8 +216,6 @@
}
-
-
/**
* <p>Set the value of a scoped object for the specified name.</p>
*
@@ -210,32 +225,43 @@
* @param property Property name to be accessed
* @param value New value to be set
*/
- public void setValue(ELContext context, Object base, Object property, Object value) {
+ public void setValue(ELContext context, Object base, Object property,
+ Object value)
+ {
- if (base != null) {
+ if (base != null)
+ {
return;
}
- if (property == null) {
+ if (property == null)
+ {
throw new PropertyNotFoundException("No property specified");
}
context.setPropertyResolved(true);
String key = property.toString();
Object result = null;
- FacesContext fcontext = (FacesContext) context.getContext(FacesContext.class);
+ FacesContext fcontext = (FacesContext) context
+ .getContext(FacesContext.class);
ExternalContext econtext = fcontext.getExternalContext();
- if (econtext.getRequestMap().containsKey(property)) {
+ if (econtext.getRequestMap().containsKey(property))
+ {
econtext.getRequestMap().put(key, value);
- } else if (econtext.getSessionMap().containsKey(property)) {
+ }
+ else if (econtext.getSessionMap().containsKey(property))
+ {
econtext.getSessionMap().put(key, value);
- } else if (econtext.getApplicationMap().containsKey(property)) {
+ }
+ else if (econtext.getApplicationMap().containsKey(property))
+ {
econtext.getApplicationMap().put(key, value);
- } else {
+ }
+ else
+ {
econtext.getRequestMap().put(key, value);
}
}
-
}
diff --git a/test12/src/main/java/org/apache/myfaces/test/el/FacesVariableResolverChainWrapper.java b/test12/src/main/java/org/apache/myfaces/test/el/FacesVariableResolverChainWrapper.java
index 13d5c00..4b4ecee 100644
--- a/test12/src/main/java/org/apache/myfaces/test/el/FacesVariableResolverChainWrapper.java
+++ b/test12/src/main/java/org/apache/myfaces/test/el/FacesVariableResolverChainWrapper.java
@@ -33,24 +33,27 @@
*
* @since 1.0.0
*/
-public class FacesVariableResolverChainWrapper extends AbstractELResolver {
-
+public class FacesVariableResolverChainWrapper extends AbstractELResolver
+{
/**
* <p>Return the most general type this resolver accepts for the
* <code>property</code> argument.</p>
*/
- public Class getCommonPropertyType(ELContext context, Object base) {
+ public Class getCommonPropertyType(ELContext context, Object base)
+ {
- if (base != null) {
+ if (base != null)
+ {
return null;
- } else {
+ }
+ else
+ {
return String.class;
}
}
-
/**
* <p>Return an <code>Iterator</code> over the attributes that this
* resolver knows how to deal with.</p>
@@ -58,14 +61,13 @@
* @param context <code>ELContext</code> for evaluating this value
* @param base Base object against which this evaluation occurs
*/
- public Iterator getFeatureDescriptors(ELContext context, Object base) {
+ public Iterator getFeatureDescriptors(ELContext context, Object base)
+ {
return null;
}
-
-
/**
* <p>Return the Java type of the specified property.</p>
*
@@ -74,16 +76,17 @@
* (must be null because we are evaluating a top level variable)
* @param property Property name to be accessed
*/
- public Class getType(ELContext context, Object base, Object property) {
+ public Class getType(ELContext context, Object base, Object property)
+ {
- if ((base == null) && (property == null)) {
+ if ((base == null) && (property == null))
+ {
throw new PropertyNotFoundException("No property specified");
}
return null;
}
-
/**
* <p>Evaluate with the legacy variable resolver chain and return
* the value.</p>
@@ -93,35 +96,42 @@
* (must be null because we are evaluating a top level variable)
* @param property Property name to be accessed
*/
- public Object getValue(ELContext context, Object base, Object property) {
+ public Object getValue(ELContext context, Object base, Object property)
+ {
- if (base != null) {
+ if (base != null)
+ {
return null;
}
- if (property == null) {
+ if (property == null)
+ {
throw new PropertyNotFoundException("No property specified");
}
- FacesContext fcontext = (FacesContext) context.getContext(FacesContext.class);
+ FacesContext fcontext = (FacesContext) context
+ .getContext(FacesContext.class);
ExternalContext econtext = fcontext.getExternalContext();
String name = property.toString();
ELContext elContext = fcontext.getELContext();
VariableResolver vr = fcontext.getApplication().getVariableResolver();
- try {
+ try
+ {
Object value = vr.resolveVariable(fcontext, name);
- if (value != null) {
+ if (value != null)
+ {
context.setPropertyResolved(true);
}
return value;
- } catch (Exception e) {
+ }
+ catch (Exception e)
+ {
context.setPropertyResolved(false);
throw new ELException(e);
}
}
-
/**
* <p>Return <code>true</code> if the specified property is read only.</p>
*
@@ -130,17 +140,17 @@
* (must be null because we are evaluating a top level variable)
* @param property Property name to be accessed
*/
- public boolean isReadOnly(ELContext context, Object base, Object property) {
+ public boolean isReadOnly(ELContext context, Object base, Object property)
+ {
- if ((base == null) && (property == null)) {
+ if ((base == null) && (property == null))
+ {
throw new PropertyNotFoundException("No property specified");
}
return false;
}
-
-
/**
* <p>Set the value of a scoped object for the specified name.</p>
*
@@ -150,13 +160,15 @@
* @param property Property name to be accessed
* @param value New value to be set
*/
- public void setValue(ELContext context, Object base, Object property, Object value) {
+ public void setValue(ELContext context, Object base, Object property,
+ Object value)
+ {
- if ((base == null) && (property == null)) {
+ if ((base == null) && (property == null))
+ {
throw new PropertyNotFoundException("No property specified");
}
}
-
}
diff --git a/test12/src/main/java/org/apache/myfaces/test/el/MockELContext.java b/test12/src/main/java/org/apache/myfaces/test/el/MockELContext.java
index a8e5832..cb6edda 100644
--- a/test12/src/main/java/org/apache/myfaces/test/el/MockELContext.java
+++ b/test12/src/main/java/org/apache/myfaces/test/el/MockELContext.java
@@ -32,93 +32,89 @@
* @since 1.0.0
*/
-public class MockELContext extends ELContext {
-
+public class MockELContext extends ELContext
+{
// ------------------------------------------------------------ Constructors
-
/** Creates a new instance of MockELContext */
- public MockELContext() {
+ public MockELContext()
+ {
}
-
// ------------------------------------------------------ Instance Variables
-
private Map contexts = new HashMap();
private FunctionMapper functionMapper = new MockFunctionMapper();
private Locale locale = Locale.getDefault();
private boolean propertyResolved;
private VariableMapper variableMapper = new MockVariableMapper();
-
// ----------------------------------------------------- Mock Object Methods
-
-
// ------------------------------------------------------- ELContext Methods
-
/** {@inheritDoc} */
- public Object getContext(Class key) {
- if (key == null) {
+ public Object getContext(Class key)
+ {
+ if (key == null)
+ {
throw new NullPointerException();
}
return contexts.get(key);
}
-
/** {@inheritDoc} */
- public ELResolver getELResolver() {
+ public ELResolver getELResolver()
+ {
FacesContext context = FacesContext.getCurrentInstance();
return context.getApplication().getELResolver();
}
-
/** {@inheritDoc} */
- public FunctionMapper getFunctionMapper() {
+ public FunctionMapper getFunctionMapper()
+ {
return this.functionMapper;
}
-
/** {@inheritDoc} */
- public Locale getLocale() {
+ public Locale getLocale()
+ {
return this.locale;
}
-
/** {@inheritDoc} */
- public boolean isPropertyResolved() {
+ public boolean isPropertyResolved()
+ {
return this.propertyResolved;
}
-
/** {@inheritDoc} */
- public void putContext(Class key, Object value) {
- if ((key == null) || (value == null)) {
+ public void putContext(Class key, Object value)
+ {
+ if ((key == null) || (value == null))
+ {
throw new NullPointerException();
}
contexts.put(key, value);
}
-
/** {@inheritDoc} */
- public void setPropertyResolved(boolean propertyResolved) {
+ public void setPropertyResolved(boolean propertyResolved)
+ {
this.propertyResolved = propertyResolved;
}
-
/** {@inheritDoc} */
- public VariableMapper getVariableMapper() {
+ public VariableMapper getVariableMapper()
+ {
return this.variableMapper;
}
-
/** {@inheritDoc} */
- public void setLocale(Locale locale) {
+ public void setLocale(Locale locale)
+ {
this.locale = locale;
}
-
}
diff --git a/test12/src/main/java/org/apache/myfaces/test/el/MockExpressionFactory.java b/test12/src/main/java/org/apache/myfaces/test/el/MockExpressionFactory.java
index cd1e6eb..e75f713 100644
--- a/test12/src/main/java/org/apache/myfaces/test/el/MockExpressionFactory.java
+++ b/test12/src/main/java/org/apache/myfaces/test/el/MockExpressionFactory.java
@@ -29,233 +29,305 @@
*
* @since 1.0.0
*/
-public class MockExpressionFactory extends ExpressionFactory {
-
+public class MockExpressionFactory extends ExpressionFactory
+{
// ------------------------------------------------------------ Constructors
-
/** Creates a new instance of MockExpressionFactory */
- public MockExpressionFactory() {
+ public MockExpressionFactory()
+ {
}
-
// ------------------------------------------------------ Instance Variables
-
/**
* <p>Literal numeric value for zero.</p>
*/
private static final Integer ZERO = new Integer(0);
-
// ----------------------------------------------------- Mock Object Methods
-
-
// ----------------------------------------------- ExpressionFactory Methods
-
/** {@inheritDoc} */
- public Object coerceToType(Object object, Class targetType) {
+ public Object coerceToType(Object object, Class targetType)
+ {
// Check for no conversion necessary
- if ((targetType == null) || Object.class.equals(targetType)) {
+ if ((targetType == null) || Object.class.equals(targetType))
+ {
return object;
}
// Coerce to String if appropriate
- if (String.class.equals(targetType)) {
- if (object == null) {
+ if (String.class.equals(targetType))
+ {
+ if (object == null)
+ {
return "";
- } else if (object instanceof String) {
+ }
+ else if (object instanceof String)
+ {
return (String) object;
- } else {
+ }
+ else
+ {
return object.toString();
}
}
// Coerce to Number (or a subclass of Number) if appropriate
- if (isNumeric(targetType)) {
- if (object == null) {
+ if (isNumeric(targetType))
+ {
+ if (object == null)
+ {
return coerce(ZERO, targetType);
- } else if ("".equals(object)) {
+ }
+ else if ("".equals(object))
+ {
return coerce(ZERO, targetType);
- } else if (object instanceof String) {
+ }
+ else if (object instanceof String)
+ {
return coerce((String) object, targetType);
- } else if (isNumeric(object.getClass())) {
+ }
+ else if (isNumeric(object.getClass()))
+ {
return coerce((Number) object, targetType);
}
- throw new IllegalArgumentException("Cannot convert " + object + " to Number");
+ throw new IllegalArgumentException("Cannot convert " + object
+ + " to Number");
}
// Coerce to Boolean if appropriate
- if (Boolean.class.equals(targetType) || (Boolean.TYPE == targetType)) {
- if (object == null) {
+ if (Boolean.class.equals(targetType) || (Boolean.TYPE == targetType))
+ {
+ if (object == null)
+ {
return Boolean.FALSE;
- } else if ("".equals(object)) {
+ }
+ else if ("".equals(object))
+ {
return Boolean.FALSE;
- } else if ((object instanceof Boolean) || (object.getClass() == Boolean.TYPE)) {
+ }
+ else if ((object instanceof Boolean)
+ || (object.getClass() == Boolean.TYPE))
+ {
return (Boolean) object;
- } else if (object instanceof String) {
+ }
+ else if (object instanceof String)
+ {
return Boolean.valueOf((String) object);
}
- throw new IllegalArgumentException("Cannot convert " + object + " to Boolean");
+ throw new IllegalArgumentException("Cannot convert " + object
+ + " to Boolean");
}
// Coerce to Character if appropriate
- if (Character.class.equals(targetType) || (Character.TYPE == targetType)) {
- if (object == null) {
+ if (Character.class.equals(targetType)
+ || (Character.TYPE == targetType))
+ {
+ if (object == null)
+ {
return new Character((char) 0);
- } else if ("".equals(object)) {
+ }
+ else if ("".equals(object))
+ {
return new Character((char) 0);
- } else if (object instanceof String) {
+ }
+ else if (object instanceof String)
+ {
return new Character(((String) object).charAt(0));
- } else if (isNumeric(object.getClass())) {
+ }
+ else if (isNumeric(object.getClass()))
+ {
return new Character((char) ((Number) object).shortValue());
- } else if ((object instanceof Character) || (object.getClass() == Character.TYPE)) {
+ }
+ else if ((object instanceof Character)
+ || (object.getClass() == Character.TYPE))
+ {
return (Character) object;
}
- throw new IllegalArgumentException("Cannot convert " + object + " to Character");
+ throw new IllegalArgumentException("Cannot convert " + object
+ + " to Character");
}
// Is the specified value type-compatible already?
- if ((object != null) && targetType.isAssignableFrom(object.getClass())) {
+ if ((object != null) && targetType.isAssignableFrom(object.getClass()))
+ {
return object;
}
-
+
// new to spec
if (object == null)
return null;
// We do not know how to perform this conversion
- throw new IllegalArgumentException("Cannot convert " + object + " to " + targetType.getName());
+ throw new IllegalArgumentException("Cannot convert " + object + " to "
+ + targetType.getName());
}
-
/** {@inheritDoc} */
public MethodExpression createMethodExpression(ELContext context,
- String expression,
- Class expectedType,
- Class[] signature) {
+ String expression, Class expectedType, Class[] signature)
+ {
return new MockMethodExpression(expression, signature, expectedType);
}
-
/** {@inheritDoc} */
public ValueExpression createValueExpression(ELContext context,
- String expression,
- Class expectedType) {
+ String expression, Class expectedType)
+ {
return new MockCompositeValueExpression(expression, expectedType);
}
-
/** {@inheritDoc} */
public ValueExpression createValueExpression(Object instance,
- Class expectedType) {
+ Class expectedType)
+ {
return new MockVariableValueExpression(instance, expectedType);
}
-
// --------------------------------------------------------- Private Methods
-
/**
* <p>Coerce the specified value to the specified Number subclass.</p>
*
* @param value Value to be coerced
* @param type Destination type
*/
- private Number coerce(Number value, Class type) {
+ private Number coerce(Number value, Class type)
+ {
- if ((type == Byte.TYPE) || (type == Byte.class)) {
+ if ((type == Byte.TYPE) || (type == Byte.class))
+ {
return new Byte(value.byteValue());
- } else if ((type == Double.TYPE) || (type == Double.class)) {
+ }
+ else if ((type == Double.TYPE) || (type == Double.class))
+ {
return new Double(value.doubleValue());
- } else if ((type == Float.TYPE) || (type == Float.class)) {
+ }
+ else if ((type == Float.TYPE) || (type == Float.class))
+ {
return new Float(value.floatValue());
- } else if ((type == Integer.TYPE) || (type == Integer.class)) {
+ }
+ else if ((type == Integer.TYPE) || (type == Integer.class))
+ {
return new Integer(value.intValue());
- } else if ((type == Long.TYPE) || (type == Long.class)) {
+ }
+ else if ((type == Long.TYPE) || (type == Long.class))
+ {
return new Long(value.longValue());
- } else if ((type == Short.TYPE) || (type == Short.class)) {
+ }
+ else if ((type == Short.TYPE) || (type == Short.class))
+ {
return new Short(value.shortValue());
- } else if (type == BigDecimal.class) {
- if (value instanceof BigDecimal) {
+ }
+ else if (type == BigDecimal.class)
+ {
+ if (value instanceof BigDecimal)
+ {
return (BigDecimal) value;
- } else if (value instanceof BigInteger) {
+ }
+ else if (value instanceof BigInteger)
+ {
return new BigDecimal((BigInteger) value);
- } else {
+ }
+ else
+ {
return new BigDecimal(((Number) value).doubleValue());
}
- } else if (type == BigInteger.class) {
- if (value instanceof BigInteger) {
+ }
+ else if (type == BigInteger.class)
+ {
+ if (value instanceof BigInteger)
+ {
return (BigInteger) value;
- } else if (value instanceof BigDecimal) {
+ }
+ else if (value instanceof BigDecimal)
+ {
return ((BigDecimal) value).toBigInteger();
- } else {
+ }
+ else
+ {
return BigInteger.valueOf(((Number) value).longValue());
}
}
- throw new IllegalArgumentException("Cannot convert " + value + " to " + type.getName());
+ throw new IllegalArgumentException("Cannot convert " + value + " to "
+ + type.getName());
}
-
/**
* <p>Coerce the specified value to the specified Number subclass.</p>
*
* @param value Value to be coerced
* @param type Destination type
*/
- private Number coerce(String value, Class type) {
+ private Number coerce(String value, Class type)
+ {
- if ((type == Byte.TYPE) || (type == Byte.class)) {
+ if ((type == Byte.TYPE) || (type == Byte.class))
+ {
return Byte.valueOf(value);
- } else if ((type == Double.TYPE) || (type == Double.class)) {
+ }
+ else if ((type == Double.TYPE) || (type == Double.class))
+ {
return Double.valueOf(value);
- } else if ((type == Float.TYPE) || (type == Float.class)) {
+ }
+ else if ((type == Float.TYPE) || (type == Float.class))
+ {
return Float.valueOf(value);
- } else if ((type == Integer.TYPE) || (type == Integer.class)) {
+ }
+ else if ((type == Integer.TYPE) || (type == Integer.class))
+ {
return Integer.valueOf(value);
- } else if ((type == Long.TYPE) || (type == Long.class)) {
+ }
+ else if ((type == Long.TYPE) || (type == Long.class))
+ {
return Long.valueOf(value);
- } else if ((type == Short.TYPE) || (type == Short.class)) {
+ }
+ else if ((type == Short.TYPE) || (type == Short.class))
+ {
return Short.valueOf(value);
- } else if (type == BigDecimal.class) {
+ }
+ else if (type == BigDecimal.class)
+ {
return new BigDecimal(value);
- } else if (type == BigInteger.class) {
+ }
+ else if (type == BigInteger.class)
+ {
return new BigInteger(value);
}
- throw new IllegalArgumentException("Cannot convert " + value + " to " + type.getName());
+ throw new IllegalArgumentException("Cannot convert " + value + " to "
+ + type.getName());
}
-
/**
* <p>Return <code>true</code> if the specified type is numeric.</p>
*
* @param type Type to check
*/
- private boolean isNumeric(Class type) {
+ private boolean isNumeric(Class type)
+ {
- return
- (type == Byte.TYPE) || (type == Byte.class)
- || (type == Double.TYPE) || (type == Double.class)
- || (type == Float.TYPE) || (type == Float.class)
- || (type == Integer.TYPE) || (type == Integer.class)
- || (type == Long.TYPE) || (type == Long.class)
- || (type == Short.TYPE) || (type == Short.class)
- || (type == BigDecimal.class) || (type == BigInteger.class);
+ return (type == Byte.TYPE) || (type == Byte.class)
+ || (type == Double.TYPE) || (type == Double.class)
+ || (type == Float.TYPE) || (type == Float.class)
+ || (type == Integer.TYPE) || (type == Integer.class)
+ || (type == Long.TYPE) || (type == Long.class)
+ || (type == Short.TYPE) || (type == Short.class)
+ || (type == BigDecimal.class) || (type == BigInteger.class);
}
-
}
diff --git a/test12/src/main/java/org/apache/myfaces/test/el/MockFunctionMapper.java b/test12/src/main/java/org/apache/myfaces/test/el/MockFunctionMapper.java
index 11b04b4..8f65c4c 100644
--- a/test12/src/main/java/org/apache/myfaces/test/el/MockFunctionMapper.java
+++ b/test12/src/main/java/org/apache/myfaces/test/el/MockFunctionMapper.java
@@ -28,50 +28,45 @@
* @since 1.0.0
*/
-public class MockFunctionMapper extends FunctionMapper {
-
+public class MockFunctionMapper extends FunctionMapper
+{
// ------------------------------------------------------------ Constructors
-
/** Creates a new instance of MockFunctionMapper */
- public MockFunctionMapper() {
+ public MockFunctionMapper()
+ {
}
-
// ------------------------------------------------------ Instance Variables
-
/**
* <p>Map of <code>Method</code> descriptors for static methods, keyed by
* a string composed of the prefix (or "" if none), a ":", and the local name.</p>
*/
private Map functions = new HashMap();
-
// ----------------------------------------------------- Mock Object Methods
-
/**
* <p>Store a mapping of the specified prefix and localName to the
* specified method, which must be static.</p>
*/
- public void mapFunction(String prefix, String localName, Method method) {
+ public void mapFunction(String prefix, String localName, Method method)
+ {
functions.put(prefix + ":" + localName, method);
}
-
// -------------------------------------------------- FunctionMapper Methods
-
/** {@inheritDoc} */
- public Method resolveFunction(String prefix, String localName) {
+ public Method resolveFunction(String prefix, String localName)
+ {
return (Method) functions.get(prefix + ":" + localName);
}
-
}
diff --git a/test12/src/main/java/org/apache/myfaces/test/el/MockMethodExpression.java b/test12/src/main/java/org/apache/myfaces/test/el/MockMethodExpression.java
index 3f945bb..6f3ee8f 100644
--- a/test12/src/main/java/org/apache/myfaces/test/el/MockMethodExpression.java
+++ b/test12/src/main/java/org/apache/myfaces/test/el/MockMethodExpression.java
@@ -32,18 +32,16 @@
*
* @since 1.0.0
*/
-public class MockMethodExpression extends MethodExpression {
-
+public class MockMethodExpression extends MethodExpression
+{
// ------------------------------------------------------------ Constructors
-
/**
* Serial version UID.
*/
private static final long serialVersionUID = 5694105394290316715L;
-
/**
* <p>Construct a new expression for the specified expression string.</p>
*
@@ -51,9 +49,12 @@
* @param signature Parameter signature of the method to be called
* @param expectedType Expected type of the result
*/
- public MockMethodExpression(String expression, Class[] signature, Class expectedType) {
+ public MockMethodExpression(String expression, Class[] signature,
+ Class expectedType)
+ {
- if (expression == null) {
+ if (expression == null)
+ {
throw new NullPointerException("Expression string cannot be null");
}
this.expression = expression;
@@ -63,105 +64,103 @@
}
-
// ------------------------------------------------------ Instance Variables
-
/**
* <p>The parsed elements of this expression.</p>
*/
private String[] elements = null;
-
/**
* <p>The expected result type for <code>getValue()</code> calls.</p>
*/
private Class expectedType = null;
-
/**
* <p>The original expression string used to create this expression.</p>
*/
private String expression = null;
-
/**
* <p>The method signature of the method to be called.</p>
*/
private Class[] signature = null;
-
// ------------------------------------------------------ Expression Methods
-
/**
* <p>Return <code>true</code> if this expression is equal to the
* specified expression.</p>
*
* @param obj Object to be compared
*/
- public boolean equals(Object obj) {
+ public boolean equals(Object obj)
+ {
- if ((obj != null) & (obj instanceof MethodExpression)) {
- return expression.equals(((MethodExpression) obj).getExpressionString());
- } else {
+ if ((obj != null) & (obj instanceof MethodExpression))
+ {
+ return expression.equals(((MethodExpression) obj)
+ .getExpressionString());
+ }
+ else
+ {
return false;
}
}
-
/**
* <p>Return the original String used to create this expression,
* unmodified.</p>
*/
- public String getExpressionString() {
+ public String getExpressionString()
+ {
return this.expression;
}
-
/**
* <p>Return the hash code for this expression.</p>
*/
- public int hashCode() {
+ public int hashCode()
+ {
return this.expression.hashCode();
}
-
/**
* <p>Return <code>true</code> if the expression string for this expression
* contains only literal text.</p>
*/
- public boolean isLiteralText() {
+ public boolean isLiteralText()
+ {
return (expression.indexOf("${") < 0) && (expression.indexOf("#{") < 0);
}
-
// ------------------------------------------------ MethodExpression Methods
-
/**
* <p>Evaluate the expression relative to the specified context,
* and return information about the actual implementation method.</p>
*
* @param context ELContext for this evaluation
*/
- public MethodInfo getMethodInfo(ELContext context) {
+ public MethodInfo getMethodInfo(ELContext context)
+ {
- if (context == null) {
+ if (context == null)
+ {
throw new NullPointerException();
}
- return new MethodInfo(elements[elements.length - 1], expectedType, signature);
+ return new MethodInfo(elements[elements.length - 1], expectedType,
+ signature);
}
-
/**
* <p>Evaluate the expression relative to the specified ocntext,
* and return the result after coercion to the expected result type.</p>
@@ -169,71 +168,93 @@
* @param context ELContext for this evaluation
* @param params Parameters for this method call
*/
- public Object invoke(ELContext context, Object[] params) {
+ public Object invoke(ELContext context, Object[] params)
+ {
- if (context == null) {
+ if (context == null)
+ {
throw new NullPointerException();
}
- if (isLiteralText()) {
+ if (isLiteralText())
+ {
return expression;
}
- FacesContext fcontext = (FacesContext) context.getContext(FacesContext.class);
+ FacesContext fcontext = (FacesContext) context
+ .getContext(FacesContext.class);
ELResolver resolver = fcontext.getApplication().getELResolver();
Object base = null;
- for (int i = 0; i < elements.length - 1; i++) {
+ for (int i = 0; i < elements.length - 1; i++)
+ {
base = resolver.getValue(context, base, elements[i]);
}
- try {
- Method method = base.getClass().getMethod(elements[elements.length - 1], signature);
+ try
+ {
+ Method method = base.getClass().getMethod(
+ elements[elements.length - 1], signature);
Object result = method.invoke(base, params);
- return fcontext.getApplication().getExpressionFactory().coerceToType(result, expectedType);
- } catch (RuntimeException e) {
+ return fcontext.getApplication().getExpressionFactory()
+ .coerceToType(result, expectedType);
+ }
+ catch (RuntimeException e)
+ {
throw e;
- } catch (Exception e) {
+ }
+ catch (Exception e)
+ {
throw new ELException(e);
}
}
-
// --------------------------------------------------------- Private Methods
-
/**
* <p>Parse the expression string into its constituent elemetns.</p>
*/
- private void parse() {
+ private void parse()
+ {
- if (isLiteralText()) {
+ if (isLiteralText())
+ {
elements = new String[0];
return;
}
- if (expression.startsWith("${") || expression.startsWith("#{")) {
- if (expression.endsWith("}")) {
- String temp = expression.substring(2, expression.length() - 1).replaceAll(" ", "");
+ if (expression.startsWith("${") || expression.startsWith("#{"))
+ {
+ if (expression.endsWith("}"))
+ {
+ String temp = expression.substring(2, expression.length() - 1)
+ .replaceAll(" ", "");
List names = new ArrayList();
- while (temp.length() > 0) {
- int period= temp.indexOf(".");
- if (period >= 0) {
+ while (temp.length() > 0)
+ {
+ int period = temp.indexOf(".");
+ if (period >= 0)
+ {
names.add(temp.substring(0, period));
temp = temp.substring(period + 1);
- } else {
+ }
+ else
+ {
names.add(temp);
temp = "";
}
}
elements = (String[]) names.toArray(new String[names.size()]);
- } else {
+ }
+ else
+ {
throw new IllegalArgumentException(expression);
}
- } else {
+ }
+ else
+ {
throw new IllegalArgumentException(expression);
}
}
-
}
diff --git a/test12/src/main/java/org/apache/myfaces/test/el/MockValueExpression.java b/test12/src/main/java/org/apache/myfaces/test/el/MockValueExpression.java
index 747d452..7255b04 100644
--- a/test12/src/main/java/org/apache/myfaces/test/el/MockValueExpression.java
+++ b/test12/src/main/java/org/apache/myfaces/test/el/MockValueExpression.java
@@ -35,27 +35,27 @@
*
* @since 1.0.0
*/
-public class MockValueExpression extends ValueExpression {
-
+public class MockValueExpression extends ValueExpression
+{
// ------------------------------------------------------------ Constructors
-
/**
* Serial version UID.
*/
private static final long serialVersionUID = -8649071428507512623L;
-
/**
* <p>Construct a new expression for the specified expression string.</p>
*
* @param expression Expression string to be evaluated
* @param expectedType Expected type of the result
*/
- public MockValueExpression(String expression, Class expectedType) {
+ public MockValueExpression(String expression, Class expectedType)
+ {
- if (expression == null) {
+ if (expression == null)
+ {
throw new NullPointerException("Expression string cannot be null");
}
this.expression = expression;
@@ -64,94 +64,91 @@
}
-
// ------------------------------------------------------ Instance Variables
-
/**
* <p>The parsed elements of this expression.</p>
*/
private String[] elements = null;
-
/**
* <p>The expected result type for <code>getValue()</code> calls.</p>
*/
private Class expectedType = null;
-
/**
* <p>The original expression string used to create this expression.</p>
*/
private String expression = null;
-
// ------------------------------------------------------ Expression Methods
-
/**
* <p>Return <code>true</code> if this expression is equal to the
* specified expression.</p>
*
* @param obj Object to be compared
*/
- public boolean equals(Object obj) {
+ public boolean equals(Object obj)
+ {
- if ((obj != null) & (obj instanceof ValueExpression)) {
- return expression.equals(((ValueExpression) obj).getExpressionString());
- } else {
+ if ((obj != null) & (obj instanceof ValueExpression))
+ {
+ return expression.equals(((ValueExpression) obj)
+ .getExpressionString());
+ }
+ else
+ {
return false;
}
}
-
/**
* <p>Return the original String used to create this expression,
* unmodified.</p>
*/
- public String getExpressionString() {
+ public String getExpressionString()
+ {
return this.expression;
}
-
/**
* <p>Return the hash code for this expression.</p>
*/
- public int hashCode() {
+ public int hashCode()
+ {
return this.expression.hashCode();
}
-
/**
* <p>Return <code>true</code> if the expression string for this expression
* contains only literal text.</p>
*/
- public boolean isLiteralText() {
+ public boolean isLiteralText()
+ {
return (expression.indexOf("${") < 0) && (expression.indexOf("#{") < 0);
}
-
// ------------------------------------------------- ValueExpression Methods
-
/**
* <p>Return the type that the result of this expression will
* be coerced to.</p>
*/
- public Class getExpectedType() {
+ public Class getExpectedType()
+ {
return this.expectedType;
}
-
/**
* <p>Evaluate this expression relative to the specified context,
* and return the most general type that is acceptable for the
@@ -159,47 +156,56 @@
*
* @param context ELContext for this evaluation
*/
- public Class getType(ELContext context) {
+ public Class getType(ELContext context)
+ {
- if (context == null) {
+ if (context == null)
+ {
throw new NullPointerException();
}
Object value = getValue(context);
- if (value == null) {
+ if (value == null)
+ {
return null;
- } else {
+ }
+ else
+ {
return value.getClass();
}
}
-
/**
* <p>Evaluate this expression relative to the specified context,
* and return the result.</p>
*
* @param context ELContext for this evaluation
*/
- public Object getValue(ELContext context) {
+ public Object getValue(ELContext context)
+ {
- if (context == null) {
+ if (context == null)
+ {
throw new NullPointerException();
}
- if (isLiteralText()) {
+ if (isLiteralText())
+ {
return expression;
}
- FacesContext fcontext = (FacesContext) context.getContext(FacesContext.class);
+ FacesContext fcontext = (FacesContext) context
+ .getContext(FacesContext.class);
ELResolver resolver = fcontext.getApplication().getELResolver();
Object base = null;
- for (int i = 0; i < elements.length; i++) {
+ for (int i = 0; i < elements.length; i++)
+ {
base = resolver.getValue(context, base, elements[i]);
}
- return fcontext.getApplication().getExpressionFactory().coerceToType(base, getExpectedType());
+ return fcontext.getApplication().getExpressionFactory().coerceToType(
+ base, getExpectedType());
}
-
/**
* <p>Evaluate this expression relative to the specified context,
* and return <code>true</code> if a call to <code>setValue()</code>
@@ -207,27 +213,31 @@
*
* @param context ELContext for this evaluation
*/
- public boolean isReadOnly(ELContext context) {
+ public boolean isReadOnly(ELContext context)
+ {
- if (context == null) {
+ if (context == null)
+ {
throw new NullPointerException();
}
- if (isLiteralText()) {
+ if (isLiteralText())
+ {
return true;
}
- FacesContext fcontext = (FacesContext) context.getContext(FacesContext.class);
+ FacesContext fcontext = (FacesContext) context
+ .getContext(FacesContext.class);
ELResolver resolver = fcontext.getApplication().getELResolver();
Object base = null;
- for (int i = 0; i < elements.length - 1; i++) {
+ for (int i = 0; i < elements.length - 1; i++)
+ {
base = resolver.getValue(context, base, elements[i]);
}
- return resolver.isReadOnly(context, base, elements[elements.length - 1]);
+ return resolver
+ .isReadOnly(context, base, elements[elements.length - 1]);
}
-
-
/**
* <p>Evaluate this expression relative to the specified context,
* and set the result to the specified value.</p>
@@ -235,74 +245,98 @@
* @param context ELContext for this evaluation
* @param value Value to which the result should be set
*/
- public void setValue(ELContext context, Object value) {
+ public void setValue(ELContext context, Object value)
+ {
- if (context == null) {
+ if (context == null)
+ {
throw new NullPointerException();
}
- FacesContext fcontext = (FacesContext) context.getContext(FacesContext.class);
+ FacesContext fcontext = (FacesContext) context
+ .getContext(FacesContext.class);
ELResolver resolver = fcontext.getApplication().getELResolver();
Object base = null;
- for (int i = 0; i < elements.length - 1; i++) {
+ for (int i = 0; i < elements.length - 1; i++)
+ {
base = resolver.getValue(context, base, elements[i]);
}
resolver.setValue(context, base, elements[elements.length - 1], value);
}
-
// --------------------------------------------------------- Private Methods
-
/**
* <p>Parse the expression string into its constituent elemetns.</p>
*/
- private void parse() {
+ private void parse()
+ {
- if (isLiteralText()) {
+ if (isLiteralText())
+ {
elements = new String[0];
return;
}
- if (expression.startsWith("${") || expression.startsWith("#{")) {
- if (expression.endsWith("}")) {
+ if (expression.startsWith("${") || expression.startsWith("#{"))
+ {
+ if (expression.endsWith("}"))
+ {
List names = new ArrayList();
- StringBuffer expr = new StringBuffer(expression.substring(2, expression.length() - 1).replaceAll(" ", ""));
+ StringBuffer expr = new StringBuffer(expression.substring(2,
+ expression.length() - 1).replaceAll(" ", ""));
boolean isBlockOn = false;
- for (int i = expr.length() - 1; i > -1; i--) {
- if (expr.charAt(i) == ' ') {
+ for (int i = expr.length() - 1; i > -1; i--)
+ {
+ if (expr.charAt(i) == ' ')
+ {
expr.deleteCharAt(i);
- } else if (expr.charAt(i) == ']') {
+ }
+ else if (expr.charAt(i) == ']')
+ {
expr.deleteCharAt(i);
- } else if (expr.charAt(i) == '[') {
+ }
+ else if (expr.charAt(i) == '[')
+ {
expr.deleteCharAt(i);
- } else if (expr.charAt(i) == '\'') {
- if (!isBlockOn) {
+ }
+ else if (expr.charAt(i) == '\'')
+ {
+ if (!isBlockOn)
+ {
expr.deleteCharAt(i);
- } else {
+ }
+ else
+ {
names.add(0, expr.substring(i + 1));
expr.delete(i, expr.length());
}
isBlockOn = !isBlockOn;
- } else if (expr.charAt(i) == '.' && !isBlockOn) {
+ }
+ else if (expr.charAt(i) == '.' && !isBlockOn)
+ {
names.add(0, expr.substring(i + 1));
expr.delete(i, expr.length());
}
}
- if (expr.length() > 0) {
+ if (expr.length() > 0)
+ {
names.add(0, expr.toString());
}
elements = (String[]) names.toArray(new String[names.size()]);
- } else {
+ }
+ else
+ {
throw new IllegalArgumentException(expression);
}
- } else {
+ }
+ else
+ {
throw new IllegalArgumentException(expression);
}
}
-
}
diff --git a/test12/src/main/java/org/apache/myfaces/test/el/MockVariableMapper.java b/test12/src/main/java/org/apache/myfaces/test/el/MockVariableMapper.java
index 4bcb53e..9b25a8c 100644
--- a/test12/src/main/java/org/apache/myfaces/test/el/MockVariableMapper.java
+++ b/test12/src/main/java/org/apache/myfaces/test/el/MockVariableMapper.java
@@ -28,52 +28,51 @@
* @since 1.0.0
*/
-public class MockVariableMapper extends VariableMapper {
-
+public class MockVariableMapper extends VariableMapper
+{
// ------------------------------------------------------------ Constructors
-
/** Creates a new instance of MockVariableMapper */
- public MockVariableMapper() {
+ public MockVariableMapper()
+ {
}
-
// ------------------------------------------------------ Instance Variables
-
/**
* <p>Map of <code>ValueExpression</code>s, keyed by variable name.</p>
*/
private Map expressions = new HashMap();
-
// ----------------------------------------------------- Mock Object Methods
-
// -------------------------------------------------- FunctionMapper Methods
-
/** {@inheritDoc} */
- public ValueExpression resolveVariable(String variable) {
+ public ValueExpression resolveVariable(String variable)
+ {
return (ValueExpression) expressions.get(variable);
}
-
/** {@inheritDoc} */
- public ValueExpression setVariable(String variable, ValueExpression expression) {
+ public ValueExpression setVariable(String variable,
+ ValueExpression expression)
+ {
ValueExpression original = (ValueExpression) expressions.get(variable);
- if (expression == null) {
+ if (expression == null)
+ {
expressions.remove(variable);
- } else {
+ }
+ else
+ {
expressions.put(variable, expression);
}
return original;
}
-
}
diff --git a/test12/src/main/java/org/apache/myfaces/test/el/MockVariableValueExpression.java b/test12/src/main/java/org/apache/myfaces/test/el/MockVariableValueExpression.java
index 140b521..ce87719 100644
--- a/test12/src/main/java/org/apache/myfaces/test/el/MockVariableValueExpression.java
+++ b/test12/src/main/java/org/apache/myfaces/test/el/MockVariableValueExpression.java
@@ -27,27 +27,27 @@
*
* @since 1.0.0
*/
-public class MockVariableValueExpression extends ValueExpression {
-
+public class MockVariableValueExpression extends ValueExpression
+{
// ------------------------------------------------------------ Constructors
-
/**
* Serial version UID.
*/
private static final long serialVersionUID = 4475919948345298291L;
-
/**
* <p>Construct a new expression for the specified instance.</p>
*
* @param instance Variable instance to be wrapped
* @param expectedType Expected type of the result
*/
- public MockVariableValueExpression(Object instance, Class expectedType) {
+ public MockVariableValueExpression(Object instance, Class expectedType)
+ {
- if (instance == null) {
+ if (instance == null)
+ {
throw new NullPointerException("Instance cannot be null");
}
this.instance = instance;
@@ -55,88 +55,86 @@
}
-
// ------------------------------------------------------ Instance Variables
-
/**
* <p>The expected result type for <code>getValue()</code> calls.</p>
*/
private Class expectedType = null;
-
/**
* <p>The variable instance being wrapped by this expression.</p>
*/
private Object instance = null;
-
// ------------------------------------------------------ Expression Methods
-
/**
* <p>Return <code>true</code> if this expression is equal to the
* specified expression.</p>
*
* @param obj Object to be compared
*/
- public boolean equals(Object obj) {
+ public boolean equals(Object obj)
+ {
- if ((obj != null) & (obj instanceof ValueExpression)) {
- return instance.toString().equals(((ValueExpression) obj).getExpressionString());
- } else {
+ if ((obj != null) & (obj instanceof ValueExpression))
+ {
+ return instance.toString().equals(
+ ((ValueExpression) obj).getExpressionString());
+ }
+ else
+ {
return false;
}
}
-
/**
* <p>Return the original String used to create this expression,
* unmodified.</p>
*/
- public String getExpressionString() {
+ public String getExpressionString()
+ {
return this.instance.toString();
}
-
/**
* <p>Return the hash code for this expression.</p>
*/
- public int hashCode() {
+ public int hashCode()
+ {
return this.instance.toString().hashCode();
}
-
/**
* <p>Return <code>true</code> if the expression string for this expression
* contains only literal text.</p>
*/
- public boolean isLiteralText() {
+ public boolean isLiteralText()
+ {
return true;
}
-
// ------------------------------------------------- ValueExpression Methods
-
/**
* <p>Return the type that the result of this expression will
* be coerced to.</p>
*/
- public Class getExpectedType() {
+ public Class getExpectedType()
+ {
return this.expectedType;
}
-
/**
* <p>Evaluate this expression relative to the specified context,
* and return the most general type that is acceptable for the
@@ -144,33 +142,37 @@
*
* @param context ELContext for this evaluation
*/
- public Class getType(ELContext context) {
+ public Class getType(ELContext context)
+ {
- if (context == null) {
+ if (context == null)
+ {
throw new NullPointerException();
}
return this.instance.getClass();
}
-
/**
* <p>Evaluate this expression relative to the specified context,
* and return the result.</p>
*
* @param context ELContext for this evaluation
*/
- public Object getValue(ELContext context) {
+ public Object getValue(ELContext context)
+ {
- if (context == null) {
+ if (context == null)
+ {
throw new NullPointerException();
}
- FacesContext fcontext = (FacesContext) context.getContext(FacesContext.class);
- return fcontext.getApplication().getExpressionFactory().coerceToType(instance, expectedType);
+ FacesContext fcontext = (FacesContext) context
+ .getContext(FacesContext.class);
+ return fcontext.getApplication().getExpressionFactory().coerceToType(
+ instance, expectedType);
}
-
/**
* <p>Evaluate this expression relative to the specified context,
* and return <code>true</code> if a call to <code>setValue()</code>
@@ -178,17 +180,17 @@
*
* @param context ELContext for this evaluation
*/
- public boolean isReadOnly(ELContext context) {
+ public boolean isReadOnly(ELContext context)
+ {
- if (context == null) {
+ if (context == null)
+ {
throw new NullPointerException();
}
return true;
}
-
-
/**
* <p>Evaluate this expression relative to the specified context,
* and set the result to the specified value.</p>
@@ -196,9 +198,11 @@
* @param context ELContext for this evaluation
* @param value Value to which the result should be set
*/
- public void setValue(ELContext context, Object value) {
+ public void setValue(ELContext context, Object value)
+ {
- if (context == null) {
+ if (context == null)
+ {
throw new NullPointerException();
}
@@ -206,5 +210,4 @@
}
-
}
diff --git a/test12/src/main/java/org/apache/myfaces/test/htmlunit/AbstractHtmlUnitTestCase.java b/test12/src/main/java/org/apache/myfaces/test/htmlunit/AbstractHtmlUnitTestCase.java
index 6b38122..69013da 100644
--- a/test12/src/main/java/org/apache/myfaces/test/htmlunit/AbstractHtmlUnitTestCase.java
+++ b/test12/src/main/java/org/apache/myfaces/test/htmlunit/AbstractHtmlUnitTestCase.java
@@ -33,8 +33,6 @@
import junit.framework.TestCase;
import junit.framework.TestSuite;
-
-
/**
* <p>Abstract base class for system integration tests based on HtmlUnit.
* These tests will expect a system property named <code>url</code> to be
@@ -43,33 +41,30 @@
*
* @since 1.0.0
*/
-public abstract class AbstractHtmlUnitTestCase extends TestCase {
-
+public abstract class AbstractHtmlUnitTestCase extends TestCase
+{
// ------------------------------------------------------------ Constructors
-
/**
* <p>Construct a new instance of this test case.</p>
*
* @param name Name of the new test case
*/
- public AbstractHtmlUnitTestCase(String name) {
+ public AbstractHtmlUnitTestCase(String name)
+ {
super(name);
}
-
// ------------------------------------------------------ Instance Variables
-
/**
* <p>The most recently retrieved page from the server.</p>
*/
protected HtmlPage page = null;
-
/**
* <p>The calculated URL for the installed "systest" web application.
* This value is based on a system property named <code>url</code>,
@@ -78,22 +73,20 @@
*/
protected URL url = null;
-
/**
* <p>The web client for this test case.</p>
*/
protected WebClient webClient = null;
-
// ------------------------------------------------------ Test Setup Methods
-
/**
* <p>Set up the instance variables required for this test case.</p>
*
* @exception Exception if an error occurs
*/
- protected void setUp() throws Exception {
+ protected void setUp() throws Exception
+ {
// Calculate the URL for the installed "systest" web application
String url = System.getProperty("url");
@@ -104,21 +97,21 @@
}
-
/**
* <p>Return the set of tests included in this test suite.</p>
*/
- public static Test suite() {
+ public static Test suite()
+ {
return (new TestSuite(AbstractHtmlUnitTestCase.class));
}
-
/**
* <p>Tear down instance variables required by this test case.</p>
*/
- protected void tearDown() throws Exception {
+ protected void tearDown() throws Exception
+ {
page = null;
url = null;
@@ -126,23 +119,23 @@
}
-
-
// ------------------------------------------------------- Protected Methods
-
/**
* <p>Return the body element for the most recently retrieved page.
* If there is no such element, return <code>null</code>.</p>
*
* @exception Exception if an error occurs
*/
- protected HtmlBody body() throws Exception {
+ protected HtmlBody body() throws Exception
+ {
Iterator elements = page.getAllHtmlChildElements();
- while (elements.hasNext()) {
+ while (elements.hasNext())
+ {
HtmlElement element = (HtmlElement) elements.next();
- if (element instanceof HtmlBody) {
+ if (element instanceof HtmlBody)
+ {
return ((HtmlBody) element);
}
}
@@ -150,7 +143,6 @@
}
-
/**
* <p>Return the HTML element with the specified <code>id</code> from the
* most recently retrieved page. If there is no such element, return
@@ -160,17 +152,20 @@
*
* @exception Exception if an error occurs
*/
- protected HtmlElement element(String id) throws Exception {
+ protected HtmlElement element(String id) throws Exception
+ {
- try {
+ try
+ {
return (page.getHtmlElementById(id));
- } catch (ElementNotFoundException e) {
+ }
+ catch (ElementNotFoundException e)
+ {
return (null);
}
}
-
/**
* <p>Return the form with the specified <code>id</code> from the most
* recently retrieved page. If there is no such form, return
@@ -180,12 +175,15 @@
*
* @exception Exception if an error occurs
*/
- protected HtmlForm form(String id) throws Exception {
+ protected HtmlForm form(String id) throws Exception
+ {
Iterator forms = page.getForms().iterator();
- while (forms.hasNext()) {
+ while (forms.hasNext())
+ {
HtmlForm form = (HtmlForm) forms.next();
- if (id.equals(form.getAttributeValue("id"))) {
+ if (id.equals(form.getAttributeValue("id")))
+ {
return (form);
}
}
@@ -193,19 +191,21 @@
}
-
/**
* <p>Return the head element for the most recently retrieved page.
* If there is no such element, return <code>null</code>.</p>
*
* @exception Exception if an error occurs
*/
- protected HtmlHead head() throws Exception {
+ protected HtmlHead head() throws Exception
+ {
Iterator elements = page.getAllHtmlChildElements();
- while (elements.hasNext()) {
+ while (elements.hasNext())
+ {
HtmlElement element = (HtmlElement) elements.next();
- if (element instanceof HtmlHead) {
+ if (element instanceof HtmlHead)
+ {
return ((HtmlHead) element);
}
}
@@ -213,7 +213,6 @@
}
-
/**
* <p>Click the specified hyperlink, and retrieve the subsequent page,
* saving a reference so that other utility methods may be used to
@@ -223,7 +222,8 @@
*
* @exception IOException if an input/output error occurs
*/
- protected HtmlPage link(HtmlAnchor anchor) throws IOException {
+ protected HtmlPage link(HtmlAnchor anchor) throws IOException
+ {
HtmlPage page = (HtmlPage) anchor.click();
this.page = page;
@@ -231,17 +231,16 @@
}
-
/**
* <p>Return the currently stored page reference.</p>
*/
- protected HtmlPage page() {
+ protected HtmlPage page()
+ {
return this.page;
}
-
/**
* <p>Retrieve and return the page at the specified context relative path.
* Save a reference to this page so that other utility methods may be used
@@ -253,7 +252,8 @@
* does not begin with a '/' character
* @exception Exception if a different error occurs
*/
- protected HtmlPage page(String path) throws Exception {
+ protected HtmlPage page(String path) throws Exception
+ {
HtmlPage page = (HtmlPage) webClient.getPage(url(path));
this.page = page;
@@ -261,7 +261,6 @@
}
-
/**
* <p>Reset the stored page reference to the specified value. This is
* useful for scenarios testing resubmit of the same page (simulating the
@@ -269,13 +268,13 @@
*
* @param page Previously saved page to which to reset
*/
- protected void reset(HtmlPage page) {
+ protected void reset(HtmlPage page)
+ {
this.page = page;
}
-
/**
* <p>Submit the current page, using the specified component, and retrieve
* the subsequent page, saving a reference so that other utility methods
@@ -285,7 +284,8 @@
*
* @exception IOException if an input/output error occurs
*/
- protected HtmlPage submit(HtmlSubmitInput submit) throws IOException {
+ protected HtmlPage submit(HtmlSubmitInput submit) throws IOException
+ {
HtmlPage page = (HtmlPage) submit.click();
this.page = page;
@@ -293,20 +293,19 @@
}
-
/**
* <p>Return the page title from the most recently retrieved page.
* Any leading and trailing whitespace will be trimmed.</p>
*
* @exception Exception if an error occurs
*/
- protected String title() throws Exception {
+ protected String title() throws Exception
+ {
return (page.getTitleText().trim());
}
-
/**
* <p>Calculate and return an absolute URL for the specified context
* relative path, which must begin with a '/' character.</p>
@@ -317,15 +316,16 @@
* does not begin with a '/' character
* @exception Exception if a different error ocurs
*/
- protected URL url(String path) throws Exception {
+ protected URL url(String path) throws Exception
+ {
- if (path.charAt(0) != '/') {
+ if (path.charAt(0) != '/')
+ {
throw new IllegalArgumentException("Context path '" + path
- + "' does not start with '/'");
+ + "' does not start with '/'");
}
return new URL(url, path.substring(1));
}
-
}
diff --git a/test12/src/main/java/org/apache/myfaces/test/htmlunit/junit4/AbstractHtmlUnitTestCase.java b/test12/src/main/java/org/apache/myfaces/test/htmlunit/junit4/AbstractHtmlUnitTestCase.java
index 1526615..3533928 100644
--- a/test12/src/main/java/org/apache/myfaces/test/htmlunit/junit4/AbstractHtmlUnitTestCase.java
+++ b/test12/src/main/java/org/apache/myfaces/test/htmlunit/junit4/AbstractHtmlUnitTestCase.java
@@ -34,8 +34,6 @@
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput;
-
-
/**
* <p>Abstract base class for system integration tests based on HtmlUnit.
* These tests will expect a system property named <code>url</code> to be
@@ -44,12 +42,11 @@
*
* @since 1.0.0
*/
-public abstract class AbstractHtmlUnitTestCase {
-
+public abstract class AbstractHtmlUnitTestCase
+{
// ------------------------------------------------------------ Constructors
-
/**
* <p>Construct a new instance of this test case.</p>
*
@@ -59,16 +56,13 @@
{
}
-
// ------------------------------------------------------ Instance Variables
-
/**
* <p>The most recently retrieved page from the server.</p>
*/
protected HtmlPage page = null;
-
/**
* <p>The calculated URL for the installed "systest" web application.
* This value is based on a system property named <code>url</code>,
@@ -77,23 +71,21 @@
*/
protected URL url = null;
-
/**
* <p>The web client for this test case.</p>
*/
protected WebClient webClient = null;
-
// ------------------------------------------------------ Test Setup Methods
-
/**
* <p>Set up the instance variables required for this test case.</p>
*
* @exception Exception if an error occurs
*/
@Before
- protected void setUp() throws Exception {
+ protected void setUp() throws Exception
+ {
// Calculate the URL for the installed "systest" web application
String url = System.getProperty("url");
@@ -108,7 +100,8 @@
* <p>Tear down instance variables required by this test case.</p>
*/
@After
- protected void tearDown() throws Exception {
+ protected void tearDown() throws Exception
+ {
page = null;
url = null;
@@ -116,23 +109,23 @@
}
-
-
// ------------------------------------------------------- Protected Methods
-
/**
* <p>Return the body element for the most recently retrieved page.
* If there is no such element, return <code>null</code>.</p>
*
* @exception Exception if an error occurs
*/
- protected HtmlBody body() throws Exception {
+ protected HtmlBody body() throws Exception
+ {
Iterator elements = page.getAllHtmlChildElements();
- while (elements.hasNext()) {
+ while (elements.hasNext())
+ {
HtmlElement element = (HtmlElement) elements.next();
- if (element instanceof HtmlBody) {
+ if (element instanceof HtmlBody)
+ {
return ((HtmlBody) element);
}
}
@@ -140,7 +133,6 @@
}
-
/**
* <p>Return the HTML element with the specified <code>id</code> from the
* most recently retrieved page. If there is no such element, return
@@ -150,17 +142,20 @@
*
* @exception Exception if an error occurs
*/
- protected HtmlElement element(String id) throws Exception {
+ protected HtmlElement element(String id) throws Exception
+ {
- try {
+ try
+ {
return (page.getHtmlElementById(id));
- } catch (ElementNotFoundException e) {
+ }
+ catch (ElementNotFoundException e)
+ {
return (null);
}
}
-
/**
* <p>Return the form with the specified <code>id</code> from the most
* recently retrieved page. If there is no such form, return
@@ -170,12 +165,15 @@
*
* @exception Exception if an error occurs
*/
- protected HtmlForm form(String id) throws Exception {
+ protected HtmlForm form(String id) throws Exception
+ {
Iterator forms = page.getForms().iterator();
- while (forms.hasNext()) {
+ while (forms.hasNext())
+ {
HtmlForm form = (HtmlForm) forms.next();
- if (id.equals(form.getAttributeValue("id"))) {
+ if (id.equals(form.getAttributeValue("id")))
+ {
return (form);
}
}
@@ -183,19 +181,21 @@
}
-
/**
* <p>Return the head element for the most recently retrieved page.
* If there is no such element, return <code>null</code>.</p>
*
* @exception Exception if an error occurs
*/
- protected HtmlHead head() throws Exception {
+ protected HtmlHead head() throws Exception
+ {
Iterator elements = page.getAllHtmlChildElements();
- while (elements.hasNext()) {
+ while (elements.hasNext())
+ {
HtmlElement element = (HtmlElement) elements.next();
- if (element instanceof HtmlHead) {
+ if (element instanceof HtmlHead)
+ {
return ((HtmlHead) element);
}
}
@@ -203,7 +203,6 @@
}
-
/**
* <p>Click the specified hyperlink, and retrieve the subsequent page,
* saving a reference so that other utility methods may be used to
@@ -213,7 +212,8 @@
*
* @exception IOException if an input/output error occurs
*/
- protected HtmlPage link(HtmlAnchor anchor) throws IOException {
+ protected HtmlPage link(HtmlAnchor anchor) throws IOException
+ {
HtmlPage page = (HtmlPage) anchor.click();
this.page = page;
@@ -221,17 +221,16 @@
}
-
/**
* <p>Return the currently stored page reference.</p>
*/
- protected HtmlPage page() {
+ protected HtmlPage page()
+ {
return this.page;
}
-
/**
* <p>Retrieve and return the page at the specified context relative path.
* Save a reference to this page so that other utility methods may be used
@@ -243,7 +242,8 @@
* does not begin with a '/' character
* @exception Exception if a different error occurs
*/
- protected HtmlPage page(String path) throws Exception {
+ protected HtmlPage page(String path) throws Exception
+ {
HtmlPage page = (HtmlPage) webClient.getPage(url(path));
this.page = page;
@@ -251,7 +251,6 @@
}
-
/**
* <p>Reset the stored page reference to the specified value. This is
* useful for scenarios testing resubmit of the same page (simulating the
@@ -259,13 +258,13 @@
*
* @param page Previously saved page to which to reset
*/
- protected void reset(HtmlPage page) {
+ protected void reset(HtmlPage page)
+ {
this.page = page;
}
-
/**
* <p>Submit the current page, using the specified component, and retrieve
* the subsequent page, saving a reference so that other utility methods
@@ -275,7 +274,8 @@
*
* @exception IOException if an input/output error occurs
*/
- protected HtmlPage submit(HtmlSubmitInput submit) throws IOException {
+ protected HtmlPage submit(HtmlSubmitInput submit) throws IOException
+ {
HtmlPage page = (HtmlPage) submit.click();
this.page = page;
@@ -283,20 +283,19 @@
}
-
/**
* <p>Return the page title from the most recently retrieved page.
* Any leading and trailing whitespace will be trimmed.</p>
*
* @exception Exception if an error occurs
*/
- protected String title() throws Exception {
+ protected String title() throws Exception
+ {
return (page.getTitleText().trim());
}
-
/**
* <p>Calculate and return an absolute URL for the specified context
* relative path, which must begin with a '/' character.</p>
@@ -307,15 +306,16 @@
* does not begin with a '/' character
* @exception Exception if a different error ocurs
*/
- protected URL url(String path) throws Exception {
+ protected URL url(String path) throws Exception
+ {
- if (path.charAt(0) != '/') {
+ if (path.charAt(0) != '/')
+ {
throw new IllegalArgumentException("Context path '" + path
- + "' does not start with '/'");
+ + "' does not start with '/'");
}
return new URL(url, path.substring(1));
}
-
}
diff --git a/test12/src/main/java/org/apache/myfaces/test/jmock/AbstractJmockJsfTestCase.java b/test12/src/main/java/org/apache/myfaces/test/jmock/AbstractJmockJsfTestCase.java
index 4e5646c..f0a9e38 100644
--- a/test12/src/main/java/org/apache/myfaces/test/jmock/AbstractJmockJsfTestCase.java
+++ b/test12/src/main/java/org/apache/myfaces/test/jmock/AbstractJmockJsfTestCase.java
@@ -71,34 +71,36 @@
*
* @since 1.0.0
*/
-public abstract class AbstractJmockJsfTestCase extends MockObjectTestCase {
-
+public abstract class AbstractJmockJsfTestCase extends MockObjectTestCase
+{
// ------------------------------------------------------------ Constructors
-
/**
* <p>Construct a new instance of this test case.</p>
*
* @param name Name of this test case
*/
- public AbstractJmockJsfTestCase(String name) {
+ public AbstractJmockJsfTestCase(String name)
+ {
setName(name);
}
-
// ---------------------------------------------------- Overall Test Methods
-
/**
* <p>Set up instance variables required by this test case.</p>
*/
- protected void setUp() throws Exception {
+ protected void setUp() throws Exception
+ {
// Set up a new thread context class loader
- threadContextClassLoader = Thread.currentThread().getContextClassLoader();
- Thread.currentThread().setContextClassLoader(new URLClassLoader(new URL[0],
- this.getClass().getClassLoader()));
+ threadContextClassLoader = Thread.currentThread()
+ .getContextClassLoader();
+ Thread.currentThread()
+ .setContextClassLoader(
+ new URLClassLoader(new URL[0], this.getClass()
+ .getClassLoader()));
// Set up Servlet API Objects
setUpServletObjects();
@@ -110,7 +112,7 @@
setUpJSFObjects();
}
-
+
/**
* <p>Setup JSF object used for the test. By default it calls to the following
* methods in this order:</p>
@@ -126,7 +128,7 @@
*
* @throws Exception
*/
- protected void setUpJSFObjects() throws Exception
+ protected void setUpJSFObjects() throws Exception
{
setUpExternalContext();
setUpLifecycle();
@@ -135,7 +137,7 @@
setUpApplication();
setUpRenderKit();
}
-
+
/**
* <p>Setup servlet objects that will be used for the test:</p>
*
@@ -149,7 +151,7 @@
*
* @throws Exception
*/
- protected void setUpServletObjects() throws Exception
+ protected void setUpServletObjects() throws Exception
{
servletContext = new MockServletContext();
config = new MockServletConfig(servletContext);
@@ -159,22 +161,22 @@
request.setServletContext(servletContext);
response = new MockHttpServletResponse();
}
-
+
/**
* <p>Set JSF factories using FactoryFinder method setFactory.</p>
*
* @throws Exception
*/
- protected void setFactories() throws Exception
+ protected void setFactories() throws Exception
{
FactoryFinder.setFactory(FactoryFinder.APPLICATION_FACTORY,
- "org.apache.myfaces.test.mock.MockApplicationFactory");
+ "org.apache.myfaces.test.mock.MockApplicationFactory");
FactoryFinder.setFactory(FactoryFinder.FACES_CONTEXT_FACTORY,
- "org.apache.myfaces.test.mock.MockFacesContextFactory");
+ "org.apache.myfaces.test.mock.MockFacesContextFactory");
FactoryFinder.setFactory(FactoryFinder.LIFECYCLE_FACTORY,
- "org.apache.myfaces.test.mock.lifecycle.MockLifecycleFactory");
+ "org.apache.myfaces.test.mock.lifecycle.MockLifecycleFactory");
FactoryFinder.setFactory(FactoryFinder.RENDER_KIT_FACTORY,
- "org.apache.myfaces.test.mock.MockRenderKitFactory");
+ "org.apache.myfaces.test.mock.MockRenderKitFactory");
}
/**
@@ -185,8 +187,8 @@
*/
protected void setUpExternalContext() throws Exception
{
- externalContext =
- new MockExternalContext(servletContext, request, response);
+ externalContext = new MockExternalContext(servletContext, request,
+ response);
}
/**
@@ -197,12 +199,12 @@
*/
protected void setUpLifecycle() throws Exception
{
- lifecycleFactory = (MockLifecycleFactory)
- FactoryFinder.getFactory(FactoryFinder.LIFECYCLE_FACTORY);
- lifecycle = (MockLifecycle)
- lifecycleFactory.getLifecycle(LifecycleFactory.DEFAULT_LIFECYCLE);
+ lifecycleFactory = (MockLifecycleFactory) FactoryFinder
+ .getFactory(FactoryFinder.LIFECYCLE_FACTORY);
+ lifecycle = (MockLifecycle) lifecycleFactory
+ .getLifecycle(LifecycleFactory.DEFAULT_LIFECYCLE);
}
-
+
/**
* Setup the <code>facesContextFactory</code> and <code>facesContext</code>
* variable. Before end, by default it override <code>externalContext</code>
@@ -214,16 +216,14 @@
*/
protected void setUpFacesContext() throws Exception
{
- facesContextFactory = (MockFacesContextFactory)
- FactoryFinder.getFactory(FactoryFinder.FACES_CONTEXT_FACTORY);
- facesContext = (MockFacesContext)
- facesContextFactory.getFacesContext(servletContext,
- request,
- response,
- lifecycle);
+ facesContextFactory = (MockFacesContextFactory) FactoryFinder
+ .getFactory(FactoryFinder.FACES_CONTEXT_FACTORY);
+ facesContext = (MockFacesContext) facesContextFactory.getFacesContext(
+ servletContext, request, response, lifecycle);
if (facesContext.getExternalContext() != null)
{
- externalContext = (MockExternalContext) facesContext.getExternalContext();
+ externalContext = (MockExternalContext) facesContext
+ .getExternalContext();
}
}
@@ -240,7 +240,7 @@
root.setRenderKitId(RenderKitFactory.HTML_BASIC_RENDER_KIT);
facesContext.setViewRoot(root);
}
-
+
/**
* Setup the <code>application</code> variable and before
* the end by default it is assigned to the <code>facesContext</code>
@@ -250,12 +250,12 @@
*/
protected void setUpApplication() throws Exception
{
- ApplicationFactory applicationFactory = (ApplicationFactory)
- FactoryFinder.getFactory(FactoryFinder.APPLICATION_FACTORY);
+ ApplicationFactory applicationFactory = (ApplicationFactory) FactoryFinder
+ .getFactory(FactoryFinder.APPLICATION_FACTORY);
application = (MockApplication) applicationFactory.getApplication();
facesContext.setApplication(application);
}
-
+
/**
* Setup the <code>renderKit</code> variable. This is a good place to use
* <code>ConfigParser</code> to register converters, validators, components
@@ -265,21 +265,24 @@
*/
protected void setUpRenderKit() throws Exception
{
- RenderKitFactory renderKitFactory = (RenderKitFactory)
- FactoryFinder.getFactory(FactoryFinder.RENDER_KIT_FACTORY);
+ RenderKitFactory renderKitFactory = (RenderKitFactory) FactoryFinder
+ .getFactory(FactoryFinder.RENDER_KIT_FACTORY);
renderKit = new MockRenderKit();
- renderKitFactory.addRenderKit(RenderKitFactory.HTML_BASIC_RENDER_KIT, renderKit);
+ renderKitFactory.addRenderKit(RenderKitFactory.HTML_BASIC_RENDER_KIT,
+ renderKit);
}
/**
* <p>Tear down instance variables required by this test case.</p>
*/
- protected void tearDown() throws Exception {
+ protected void tearDown() throws Exception
+ {
application = null;
config = null;
externalContext = null;
- if (facesContext != null) {
+ if (facesContext != null)
+ {
facesContext.release();
}
facesContext = null;
@@ -297,23 +300,21 @@
}
-
// ------------------------------------------------------ Instance Variables
-
// Mock object instances for our tests
- protected MockApplication application = null;
- protected MockServletConfig config = null;
- protected MockExternalContext externalContext = null;
- protected MockFacesContext facesContext = null;
+ protected MockApplication application = null;
+ protected MockServletConfig config = null;
+ protected MockExternalContext externalContext = null;
+ protected MockFacesContext facesContext = null;
protected MockFacesContextFactory facesContextFactory = null;
- protected MockLifecycle lifecycle = null;
- protected MockLifecycleFactory lifecycleFactory = null;
- protected MockRenderKit renderKit = null;
- protected MockHttpServletRequest request = null;
+ protected MockLifecycle lifecycle = null;
+ protected MockLifecycleFactory lifecycleFactory = null;
+ protected MockRenderKit renderKit = null;
+ protected MockHttpServletRequest request = null;
protected MockHttpServletResponse response = null;
- protected MockServletContext servletContext = null;
- protected MockHttpSession session = null;
+ protected MockServletContext servletContext = null;
+ protected MockHttpSession session = null;
// Thread context class loader saved and restored after each test
private ClassLoader threadContextClassLoader = null;
diff --git a/test12/src/main/java/org/apache/myfaces/test/mock/MockActionListener.java b/test12/src/main/java/org/apache/myfaces/test/mock/MockActionListener.java
index 413b46f..7f0f863 100644
--- a/test12/src/main/java/org/apache/myfaces/test/mock/MockActionListener.java
+++ b/test12/src/main/java/org/apache/myfaces/test/mock/MockActionListener.java
@@ -28,28 +28,24 @@
* @since 1.0.0
*/
-public class MockActionListener implements ActionListener {
-
+public class MockActionListener implements ActionListener
+{
// ------------------------------------------------------------ Constructors
-
/**
* <p>Construct a default instance.</p>
*/
- public MockActionListener() {
+ public MockActionListener()
+ {
}
-
// ----------------------------------------------------- Mock Object Methods
-
// ------------------------------------------------------ Instance Variables
-
// -------------------------------------------------- ActionListener Methods
-
/**
* <p>Process the specified <code>ActionEvent</code>.</p>
*
@@ -58,9 +54,10 @@
* @exception AbortProcessingException if further event firing
* should be skipped
*/
- public void processAction(ActionEvent event) throws AbortProcessingException {
+ public void processAction(ActionEvent event)
+ throws AbortProcessingException
+ {
// FIXME - provide default implementation
}
-
}
diff --git a/test12/src/main/java/org/apache/myfaces/test/mock/MockApplication.java b/test12/src/main/java/org/apache/myfaces/test/mock/MockApplication.java
index f8786fe..b74bb49 100644
--- a/test12/src/main/java/org/apache/myfaces/test/mock/MockApplication.java
+++ b/test12/src/main/java/org/apache/myfaces/test/mock/MockApplication.java
@@ -47,15 +47,16 @@
* @since 1.0.0
*/
-public class MockApplication extends Application {
-
+public class MockApplication extends Application
+{
// ------------------------------------------------------------ Constructors
/**
* <p>Construct a default instance.</p>
*/
- public MockApplication() {
+ public MockApplication()
+ {
setActionListener(new MockActionListener());
components = new HashMap();
@@ -72,46 +73,51 @@
setViewHandler(new MockViewHandler());
// Register the standard by-id converters
- addConverter("javax.faces.BigDecimal", "javax.faces.convert.BigDecimalConverter");
- addConverter("javax.faces.BigInteger", "javax.faces.convert.BigIntegerConverter");
- addConverter("javax.faces.Boolean", "javax.faces.convert.BooleanConverter");
- addConverter("javax.faces.Byte", "javax.faces.convert.ByteConverter");
- addConverter("javax.faces.Character", "javax.faces.convert.CharacterConverter");
- addConverter("javax.faces.DateTime", "javax.faces.convert.DateTimeConverter");
- addConverter("javax.faces.Double", "javax.faces.convert.DoubleConverter");
- addConverter("javax.faces.Float", "javax.faces.convert.FloatConverter");
- addConverter("javax.faces.Integer", "javax.faces.Convert.IntegerConverter");
- addConverter("javax.faces.Long", "javax.faces.convert.LongConverter");
- addConverter("javax.faces.Number", "javax.faces.convert.NumberConverter");
- addConverter("javax.faces.Short", "javax.faces.convert.ShortConverter");
+ addConverter("javax.faces.BigDecimal",
+ "javax.faces.convert.BigDecimalConverter");
+ addConverter("javax.faces.BigInteger",
+ "javax.faces.convert.BigIntegerConverter");
+ addConverter("javax.faces.Boolean",
+ "javax.faces.convert.BooleanConverter");
+ addConverter("javax.faces.Byte", "javax.faces.convert.ByteConverter");
+ addConverter("javax.faces.Character",
+ "javax.faces.convert.CharacterConverter");
+ addConverter("javax.faces.DateTime",
+ "javax.faces.convert.DateTimeConverter");
+ addConverter("javax.faces.Double",
+ "javax.faces.convert.DoubleConverter");
+ addConverter("javax.faces.Float", "javax.faces.convert.FloatConverter");
+ addConverter("javax.faces.Integer",
+ "javax.faces.Convert.IntegerConverter");
+ addConverter("javax.faces.Long", "javax.faces.convert.LongConverter");
+ addConverter("javax.faces.Number",
+ "javax.faces.convert.NumberConverter");
+ addConverter("javax.faces.Short", "javax.faces.convert.ShortConverter");
// Register the standard by-type converters
- addConverter(Boolean.class, "javax.faces.convert.BooleanConverter");
- addConverter(Boolean.TYPE, "javax.faces.convert.BooleanConverter");
- addConverter(Byte.class, "javax.faces.convert.ByteConverter");
- addConverter(Byte.TYPE, "javax.faces.convert.ByteConverter");
- addConverter(Character.class, "javax.faces.convert.CharacterConverter");
- addConverter(Character.TYPE, "javax.faces.convert.CharacterConverter");
- addConverter(Double.class, "javax.faces.convert.DoubleConverter");
- addConverter(Double.TYPE, "javax.faces.convert.DoubleConverter");
- addConverter(Float.class, "javax.faces.convert.FloatConverter");
- addConverter(Float.TYPE, "javax.faces.convert.FloatConverter");
- addConverter(Integer.class, "javax.faces.convert.IntegerConverter");
- addConverter(Integer.TYPE, "javax.faces.convert.IntegerConverter");
- addConverter(Long.class, "javax.faces.convert.LongConverter");
- addConverter(Long.TYPE, "javax.faces.convert.LongConverter");
- addConverter(Short.class, "javax.faces.convert.ShortConverter");
- addConverter(Short.TYPE, "javax.faces.convert.ShortConverter");
+ addConverter(Boolean.class, "javax.faces.convert.BooleanConverter");
+ addConverter(Boolean.TYPE, "javax.faces.convert.BooleanConverter");
+ addConverter(Byte.class, "javax.faces.convert.ByteConverter");
+ addConverter(Byte.TYPE, "javax.faces.convert.ByteConverter");
+ addConverter(Character.class, "javax.faces.convert.CharacterConverter");
+ addConverter(Character.TYPE, "javax.faces.convert.CharacterConverter");
+ addConverter(Double.class, "javax.faces.convert.DoubleConverter");
+ addConverter(Double.TYPE, "javax.faces.convert.DoubleConverter");
+ addConverter(Float.class, "javax.faces.convert.FloatConverter");
+ addConverter(Float.TYPE, "javax.faces.convert.FloatConverter");
+ addConverter(Integer.class, "javax.faces.convert.IntegerConverter");
+ addConverter(Integer.TYPE, "javax.faces.convert.IntegerConverter");
+ addConverter(Long.class, "javax.faces.convert.LongConverter");
+ addConverter(Long.TYPE, "javax.faces.convert.LongConverter");
+ addConverter(Short.class, "javax.faces.convert.ShortConverter");
+ addConverter(Short.TYPE, "javax.faces.convert.ShortConverter");
}
-
// ----------------------------------------------------- Mock Object Methods
-
// ------------------------------------------------------ Instance Variables
-
private ActionListener actionListener = null;
private Map components = null;
private Map converters = null; // By id
@@ -127,338 +133,364 @@
private VariableResolver variableResolver = null;
private ViewHandler viewHandler = null;
-
// ----------------------------------------------------- Application Methods
-
/** {@inheritDoc} */
- public ActionListener getActionListener() {
+ public ActionListener getActionListener()
+ {
return this.actionListener;
}
-
/** {@inheritDoc} */
- public void setActionListener(ActionListener actionListener) {
+ public void setActionListener(ActionListener actionListener)
+ {
this.actionListener = actionListener;
}
-
/** {@inheritDoc} */
- public Locale getDefaultLocale() {
+ public Locale getDefaultLocale()
+ {
return this.defaultLocale;
}
/** {@inheritDoc} */
- public void setDefaultLocale(Locale defaultLocale) {
+ public void setDefaultLocale(Locale defaultLocale)
+ {
this.defaultLocale = defaultLocale;
}
/** {@inheritDoc} */
- public String getDefaultRenderKitId() {
+ public String getDefaultRenderKitId()
+ {
return this.defaultRenderKitId;
}
/** {@inheritDoc} */
- public void setDefaultRenderKitId(String defaultRenderKitId) {
+ public void setDefaultRenderKitId(String defaultRenderKitId)
+ {
this.defaultRenderKitId = defaultRenderKitId;
}
-
/** {@inheritDoc} */
- public String getMessageBundle() {
+ public String getMessageBundle()
+ {
return this.messageBundle;
}
-
/** {@inheritDoc} */
- public void setMessageBundle(String messageBundle) {
+ public void setMessageBundle(String messageBundle)
+ {
this.messageBundle = messageBundle;
}
-
/** {@inheritDoc} */
- public NavigationHandler getNavigationHandler() {
+ public NavigationHandler getNavigationHandler()
+ {
return this.navigationHandler;
}
-
/** {@inheritDoc} */
- public void setNavigationHandler(NavigationHandler navigationHandler) {
+ public void setNavigationHandler(NavigationHandler navigationHandler)
+ {
this.navigationHandler = navigationHandler;
}
-
/** {@inheritDoc} */
- public PropertyResolver getPropertyResolver() {
+ public PropertyResolver getPropertyResolver()
+ {
return this.propertyResolver;
}
-
/** {@inheritDoc} */
- public void setPropertyResolver(PropertyResolver propertyResolver) {
+ public void setPropertyResolver(PropertyResolver propertyResolver)
+ {
this.propertyResolver = propertyResolver;
}
-
/** {@inheritDoc} */
- public StateManager getStateManager() {
+ public StateManager getStateManager()
+ {
return this.stateManager;
}
-
/** {@inheritDoc} */
- public void setStateManager(StateManager stateManager) {
+ public void setStateManager(StateManager stateManager)
+ {
this.stateManager = stateManager;
}
-
/** {@inheritDoc} */
- public Iterator getSupportedLocales() {
+ public Iterator getSupportedLocales()
+ {
return this.supportedLocales.iterator();
}
-
/** {@inheritDoc} */
- public void setSupportedLocales(Collection supportedLocales) {
+ public void setSupportedLocales(Collection supportedLocales)
+ {
this.supportedLocales = supportedLocales;
}
-
/** {@inheritDoc} */
- public VariableResolver getVariableResolver() {
+ public VariableResolver getVariableResolver()
+ {
return this.variableResolver;
}
-
/** {@inheritDoc} */
- public void setVariableResolver(VariableResolver variableResolver) {
+ public void setVariableResolver(VariableResolver variableResolver)
+ {
this.variableResolver = variableResolver;
}
-
/** {@inheritDoc} */
- public ViewHandler getViewHandler() {
+ public ViewHandler getViewHandler()
+ {
return this.viewHandler;
}
-
/** {@inheritDoc} */
- public void setViewHandler(ViewHandler viewHandler) {
+ public void setViewHandler(ViewHandler viewHandler)
+ {
this.viewHandler = viewHandler;
}
-
/** {@inheritDoc} */
- public void addComponent(String componentType, String componentClass) {
+ public void addComponent(String componentType, String componentClass)
+ {
components.put(componentType, componentClass);
}
-
/** {@inheritDoc} */
- public UIComponent createComponent(String componentType) {
+ public UIComponent createComponent(String componentType)
+ {
- if (componentType == null) {
+ if (componentType == null)
+ {
throw new NullPointerException("Requested component type is null");
}
String componentClass = (String) components.get(componentType);
- if (componentClass == null) {
- throw new FacesException("No component class registered for component type '"
- + componentType + "'");
+ if (componentClass == null)
+ {
+ throw new FacesException(
+ "No component class registered for component type '"
+ + componentType + "'");
}
- try {
+ try
+ {
Class clazz = Class.forName(componentClass);
return ((UIComponent) clazz.newInstance());
- } catch (Exception e) {
+ }
+ catch (Exception e)
+ {
throw new FacesException(e);
}
}
-
/** {@inheritDoc} */
public UIComponent createComponent(ValueBinding componentBinding,
- FacesContext context,
- String componentType)
- throws FacesException {
+ FacesContext context, String componentType) throws FacesException
+ {
UIComponent component = null;
- try {
+ try
+ {
component = (UIComponent) componentBinding.getValue(context);
- if (component == null) {
+ if (component == null)
+ {
component = createComponent(componentType);
componentBinding.setValue(context, component);
}
- } catch (Exception e) {
+ }
+ catch (Exception e)
+ {
throw new FacesException(e);
}
return component;
}
-
/** {@inheritDoc} */
- public Iterator getComponentTypes() {
+ public Iterator getComponentTypes()
+ {
return (components.keySet().iterator());
}
-
/** {@inheritDoc} */
- public void addConverter(String converterId, String converterClass) {
+ public void addConverter(String converterId, String converterClass)
+ {
converters.put(converterId, converterClass);
}
-
/** {@inheritDoc} */
- public void addConverter(Class targetClass, String converterClass) {
+ public void addConverter(Class targetClass, String converterClass)
+ {
converters1.put(targetClass, converterClass);
}
-
/** {@inheritDoc} */
- public Converter createConverter(String converterId) {
+ public Converter createConverter(String converterId)
+ {
String converterClass = (String) converters.get(converterId);
- if (converterClass == null) {
+ if (converterClass == null)
+ {
return null;
}
- try {
+ try
+ {
Class clazz = Class.forName(converterClass);
return ((Converter) clazz.newInstance());
- } catch (Exception e) {
+ }
+ catch (Exception e)
+ {
throw new FacesException(e);
}
}
-
/** {@inheritDoc} */
- public Converter createConverter(Class targetClass) {
+ public Converter createConverter(Class targetClass)
+ {
String converterClass = (String) converters1.get(targetClass);
- if (converterClass == null) {
+ if (converterClass == null)
+ {
return null;
}
- try {
+ try
+ {
Class clazz = Class.forName(converterClass);
return ((Converter) clazz.newInstance());
- } catch (Exception e) {
+ }
+ catch (Exception e)
+ {
throw new FacesException(e);
}
}
-
/** {@inheritDoc} */
- public Iterator getConverterIds() {
+ public Iterator getConverterIds()
+ {
return (converters.keySet().iterator());
}
-
/** {@inheritDoc} */
- public Iterator getConverterTypes() {
+ public Iterator getConverterTypes()
+ {
return (converters1.keySet().iterator());
}
-
/** {@inheritDoc} */
- public MethodBinding createMethodBinding(String ref, Class[] params) {
+ public MethodBinding createMethodBinding(String ref, Class[] params)
+ {
- if (ref == null) {
+ if (ref == null)
+ {
throw new NullPointerException();
- } else {
+ }
+ else
+ {
return (new MockMethodBinding(this, ref, params));
}
}
-
/** {@inheritDoc} */
- public ValueBinding createValueBinding(String ref) {
+ public ValueBinding createValueBinding(String ref)
+ {
- if (ref == null) {
+ if (ref == null)
+ {
throw new NullPointerException();
- } else {
+ }
+ else
+ {
return (new MockValueBinding(this, ref));
}
}
-
/** {@inheritDoc} */
- public void addValidator(String validatorId, String validatorClass) {
+ public void addValidator(String validatorId, String validatorClass)
+ {
validators.put(validatorId, validatorClass);
}
-
/** {@inheritDoc} */
- public Validator createValidator(String validatorId) {
+ public Validator createValidator(String validatorId)
+ {
String validatorClass = (String) validators.get(validatorId);
- try {
+ try
+ {
Class clazz = Class.forName(validatorClass);
return ((Validator) clazz.newInstance());
- } catch (Exception e) {
+ }
+ catch (Exception e)
+ {
throw new FacesException(e);
}
}
-
/** {@inheritDoc} */
- public Iterator getValidatorIds() {
+ public Iterator getValidatorIds()
+ {
return (validators.keySet().iterator());
}
-
}
diff --git a/test12/src/main/java/org/apache/myfaces/test/mock/MockApplication12.java b/test12/src/main/java/org/apache/myfaces/test/mock/MockApplication12.java
index d4b6a77..e3e8527 100644
--- a/test12/src/main/java/org/apache/myfaces/test/mock/MockApplication12.java
+++ b/test12/src/main/java/org/apache/myfaces/test/mock/MockApplication12.java
@@ -56,16 +56,16 @@
*
* @since 1.0.0
*/
-public class MockApplication12 extends MockApplication {
-
+public class MockApplication12 extends MockApplication
+{
// ------------------------------------------------------------ Constructors
-
/**
* <p>Construct a default instance.</p>
*/
- public MockApplication12() {
+ public MockApplication12()
+ {
super();
@@ -74,44 +74,36 @@
}
-
// ------------------------------------------------------ Instance Variables
-
/**
* <p>A list of resource bundles configured for this application.</p>
*/
private Map bundles = new HashMap();
-
/**
* <p>The set of configured ELContextListener instances.</p>
*/
private List elContextListeners = new ArrayList();
-
/**
* <p>Expression factory for this instance.</p>
*/
private ExpressionFactory expressionFactory = null;
-
/**
* <p>The configured composite resolver to be returned by <code>getELResolver()</code>.
* This value is lazily instantiated.</p>
*/
private ELResolver resolver = null;
-
/**
* <p>The set of ELResolver instances configured on this instance.</p>
*/
private List resolvers = new ArrayList();
-
// ----------------------------------------------------- Mock Object Methods
-
/**
* <p>Add the specified resource bundle to those associated with
* this application.</p>
@@ -119,37 +111,38 @@
* @param name Name under which to add this resource bundle
* @param bundle ResourceBundle to add
*/
- public void addResourceBundle(String name, ResourceBundle bundle) {
+ public void addResourceBundle(String name, ResourceBundle bundle)
+ {
bundles.put(name, bundle);
}
-
/**
* <p>Return a <code>Map</code> of the resource bundles configured
* for this application, keyed by name.</p>
*/
- public Map getResourceBundles() {
+ public Map getResourceBundles()
+ {
return bundles;
}
-
// ----------------------------------------------------- Application Methods
-
/** {@inheritDoc} */
- public void addELContextListener(ELContextListener listener) {
+ public void addELContextListener(ELContextListener listener)
+ {
elContextListeners.add(listener);
}
-
/** {@inheritDoc} */
- public void addELResolver(ELResolver resolver) {
+ public void addELResolver(ELResolver resolver)
+ {
// Simulate the restriction that you cannot add resolvers after
// the first request has been processed.
- if (this.resolver != null) {
+ if (this.resolver != null)
+ {
throw new IllegalStateException("Cannot add resolvers now");
}
@@ -157,53 +150,57 @@
}
-
/** {@inheritDoc} */
public UIComponent createComponent(ValueExpression expression,
- FacesContext context,
- String componentType) {
+ FacesContext context, String componentType)
+ {
UIComponent component = null;
- try {
- component = (UIComponent) expression.getValue(context.getELContext());
- if (component == null) {
+ try
+ {
+ component = (UIComponent) expression.getValue(context
+ .getELContext());
+ if (component == null)
+ {
component = createComponent(componentType);
expression.setValue(context.getELContext(), component);
}
- } catch (Exception e) {
+ }
+ catch (Exception e)
+ {
throw new FacesException(e);
}
return component;
}
-
/** {@inheritDoc} */
public Object evaluateExpressionGet(FacesContext context,
- String expression,
- Class expectedType) throws ELException {
+ String expression, Class expectedType) throws ELException
+ {
- ValueExpression ve = getExpressionFactory().createValueExpression
- (context.getELContext(), expression, expectedType);
+ ValueExpression ve = getExpressionFactory().createValueExpression(
+ context.getELContext(), expression, expectedType);
return ve.getValue(context.getELContext());
}
-
/** {@inheritDoc} */
- public ELContextListener[] getELContextListeners() {
+ public ELContextListener[] getELContextListeners()
+ {
- return (ELContextListener[])
- elContextListeners.toArray(new ELContextListener[elContextListeners.size()]);
+ return (ELContextListener[]) elContextListeners
+ .toArray(new ELContextListener[elContextListeners.size()]);
}
-
/** {@inheritDoc} */
- public ELResolver getELResolver() {
+ public ELResolver getELResolver()
+ {
- if (resolver == null) {
+ if (resolver == null)
+ {
// Configure a default ELResolver per Section 5.6.2 of JSF 1.2
CompositeELResolver composite = new CompositeELResolver();
@@ -215,7 +212,8 @@
nested.add(new FacesVariableResolverChainWrapper());
nested.add(new FacesPropertyResolverChainWrapper());
Iterator items = resolvers.iterator();
- while (items.hasNext()) {
+ while (items.hasNext())
+ {
nested.add((ELResolver) items.next());
}
composite.add(nested);
@@ -237,46 +235,48 @@
}
-
/** {@inheritDoc} */
- public ExpressionFactory getExpressionFactory() {
+ public ExpressionFactory getExpressionFactory()
+ {
return this.expressionFactory;
}
-
/** {@inheritDoc} */
- public ResourceBundle getResourceBundle(FacesContext context, String name) {
+ public ResourceBundle getResourceBundle(FacesContext context, String name)
+ {
- if ((context == null) || (name == null)) {
+ if ((context == null) || (name == null))
+ {
throw new NullPointerException();
}
Locale locale = null;
UIViewRoot viewRoot = context.getViewRoot();
- if (viewRoot != null) {
+ if (viewRoot != null)
+ {
locale = viewRoot.getLocale();
}
- if (locale == null) {
+ if (locale == null)
+ {
locale = Locale.getDefault();
}
- try
+ try
{
return ResourceBundle.getBundle(name, locale);
}
- catch (MissingResourceException e)
+ catch (MissingResourceException e)
{
return null;
}
}
-
/** {@inheritDoc} */
- public void removeELContextListener(ELContextListener listener) {
+ public void removeELContextListener(ELContextListener listener)
+ {
elContextListeners.remove(listener);
}
-
}
diff --git a/test12/src/main/java/org/apache/myfaces/test/mock/MockApplicationFactory.java b/test12/src/main/java/org/apache/myfaces/test/mock/MockApplicationFactory.java
index c768446..9f06b6c 100644
--- a/test12/src/main/java/org/apache/myfaces/test/mock/MockApplicationFactory.java
+++ b/test12/src/main/java/org/apache/myfaces/test/mock/MockApplicationFactory.java
@@ -28,62 +28,74 @@
* @since 1.0.0
*/
-public class MockApplicationFactory extends ApplicationFactory {
-
+public class MockApplicationFactory extends ApplicationFactory
+{
// ------------------------------------------------------------ Constructors
-
/**
* <p>Construct a default instance.</p>
*/
- public MockApplicationFactory() {
+ public MockApplicationFactory()
+ {
}
-
// ----------------------------------------------------- Mock Object Methods
-
// ------------------------------------------------------ Instance Variables
-
/**
* <p>The <code>Application</code> instance to be returned by
* this factory.</p>
*/
private Application application = null;
-
// --------------------------------------------- AppolicationFactory Methods
-
/** {@inheritDoc} */
- public Application getApplication() {
+ public Application getApplication()
+ {
- if (this.application == null) {
+ if (this.application == null)
+ {
Class clazz = null;
- try {
- clazz = this.getClass().getClassLoader().loadClass
- ("org.apache.myfaces.test.mock.MockApplication12");
+ try
+ {
+ clazz = this.getClass().getClassLoader().loadClass(
+ "org.apache.myfaces.test.mock.MockApplication12");
this.application = (MockApplication) clazz.newInstance();
- } catch (NoClassDefFoundError e) {
+ }
+ catch (NoClassDefFoundError e)
+ {
clazz = null; // We are not running in a JSF 1.2 environment
- } catch (ClassNotFoundException e) {
+ }
+ catch (ClassNotFoundException e)
+ {
clazz = null; // Same as above
- } catch (RuntimeException e) {
+ }
+ catch (RuntimeException e)
+ {
throw e;
- } catch (Exception e) {
+ }
+ catch (Exception e)
+ {
throw new FacesException(e);
}
- if (clazz == null) {
- try {
- clazz = this.getClass().getClassLoader().loadClass
- ("org.apache.myfaces.test.mock.MockApplication");
+ if (clazz == null)
+ {
+ try
+ {
+ clazz = this.getClass().getClassLoader().loadClass(
+ "org.apache.myfaces.test.mock.MockApplication");
this.application = (MockApplication) clazz.newInstance();
- } catch (RuntimeException e) {
+ }
+ catch (RuntimeException e)
+ {
throw e;
- } catch (Exception e) {
+ }
+ catch (Exception e)
+ {
throw new FacesException(e);
}
}
@@ -92,13 +104,12 @@
}
-
/** {@inheritDoc} */
- public void setApplication(Application application) {
+ public void setApplication(Application application)
+ {
this.application = application;
}
-
}
diff --git a/test12/src/main/java/org/apache/myfaces/test/mock/MockEnumeration.java b/test12/src/main/java/org/apache/myfaces/test/mock/MockEnumeration.java
index fbb6061..e3febfb 100644
--- a/test12/src/main/java/org/apache/myfaces/test/mock/MockEnumeration.java
+++ b/test12/src/main/java/org/apache/myfaces/test/mock/MockEnumeration.java
@@ -28,53 +28,48 @@
* @since 1.0.0
*/
-class MockEnumeration implements Enumeration {
-
+class MockEnumeration implements Enumeration
+{
// ------------------------------------------------------------ Constructors
-
/**
* <p>Construct a wrapper instance.</p>
*
* @param iterator The <code>Iterator</code> to be wrapped
*/
- public MockEnumeration(Iterator iterator) {
+ public MockEnumeration(Iterator iterator)
+ {
this.iterator = iterator;
}
-
// ----------------------------------------------------- Mock Object Methods
-
// ------------------------------------------------------ Instance Variables
-
/**
* <p>The <code>Iterator</code> we are wrapping.</p>
*/
private Iterator iterator;
-
// ----------------------------------------------------- Enumeration Methods
-
/** {@inheritDoc} */
- public boolean hasMoreElements() {
+ public boolean hasMoreElements()
+ {
return iterator.hasNext();
}
-
/** {@inheritDoc} */
- public Object nextElement() {
+ public Object nextElement()
+ {
return iterator.next();
}
-
}
diff --git a/test12/src/main/java/org/apache/myfaces/test/mock/MockExternalContext.java b/test12/src/main/java/org/apache/myfaces/test/mock/MockExternalContext.java
index 887828d..853743e 100644
--- a/test12/src/main/java/org/apache/myfaces/test/mock/MockExternalContext.java
+++ b/test12/src/main/java/org/apache/myfaces/test/mock/MockExternalContext.java
@@ -56,8 +56,7 @@
* @param response <code>HttpServletResponse</code> for this request
*/
public MockExternalContext(ServletContext context,
- HttpServletRequest request,
- HttpServletResponse response)
+ HttpServletRequest request, HttpServletResponse response)
{
this.context = context;
@@ -101,10 +100,10 @@
public void addRequestCookieMap(Cookie cookie)
{
Map map = getRequestCookieMap();
- if (request instanceof MockHttpServletRequest &&
- map instanceof _CookieMap)
+ if (request instanceof MockHttpServletRequest
+ && map instanceof _CookieMap)
{
- ((MockHttpServletRequest)request).addCookie(cookie);
+ ((MockHttpServletRequest) request).addCookie(cookie);
}
else
{
@@ -131,10 +130,10 @@
public void addRequestParameterMap(String key, String value)
{
Map map = getRequestParameterMap();
- if (request instanceof MockHttpServletRequest &&
- map instanceof _RequestParameterMap)
+ if (request instanceof MockHttpServletRequest
+ && map instanceof _RequestParameterMap)
{
- ((MockHttpServletRequest)request).addParameter(key, value);
+ ((MockHttpServletRequest) request).addParameter(key, value);
}
else
{
@@ -161,10 +160,10 @@
public void addRequestHeader(String key, String value)
{
Map map = getRequestHeaderMap();
- if (request instanceof MockHttpServletRequest &&
- map instanceof _RequestHeaderMap)
+ if (request instanceof MockHttpServletRequest
+ && map instanceof _RequestHeaderMap)
{
- ((MockHttpServletRequest)request).addHeader(key, value);
+ ((MockHttpServletRequest) request).addHeader(key, value);
}
else
{
diff --git a/test12/src/main/java/org/apache/myfaces/test/mock/MockExternalContext12.java b/test12/src/main/java/org/apache/myfaces/test/mock/MockExternalContext12.java
index 3af1a60..ccdd97b 100644
--- a/test12/src/main/java/org/apache/myfaces/test/mock/MockExternalContext12.java
+++ b/test12/src/main/java/org/apache/myfaces/test/mock/MockExternalContext12.java
@@ -30,90 +30,86 @@
*
* @since 1.0.0
*/
-public class MockExternalContext12 extends MockExternalContext {
-
+public class MockExternalContext12 extends MockExternalContext
+{
// ------------------------------------------------------------ Constructors
-
public MockExternalContext12(ServletContext context,
- HttpServletRequest request,
- HttpServletResponse response) {
+ HttpServletRequest request, HttpServletResponse response)
+ {
super(context, request, response);
}
-
// ------------------------------------------------------ Instance Variables
-
// ----------------------------------------------------- Mock Object Methods
-
// ------------------------------------------------- ExternalContext Methods
-
/** {@inheritDoc} */
- public String getRequestCharacterEncoding() {
+ public String getRequestCharacterEncoding()
+ {
return this.request.getCharacterEncoding();
}
-
/** {@inheritDoc} */
- public String getRequestContentType() {
+ public String getRequestContentType()
+ {
return this.request.getContentType();
}
-
/** {@inheritDoc} */
- public String getResponseCharacterEncoding() {
+ public String getResponseCharacterEncoding()
+ {
return this.response.getCharacterEncoding();
}
-
/** {@inheritDoc} */
- public String getResponseContentType() {
+ public String getResponseContentType()
+ {
return this.response.getContentType();
}
-
/** {@inheritDoc} */
- public void setRequest(Object request) {
+ public void setRequest(Object request)
+ {
this.request = (HttpServletRequest) request;
}
-
/** {@inheritDoc} */
- public void setRequestCharacterEncoding(String encoding) throws UnsupportedEncodingException {
+ public void setRequestCharacterEncoding(String encoding)
+ throws UnsupportedEncodingException
+ {
this.request.setCharacterEncoding(encoding);
}
-
/** {@inheritDoc} */
- public void setResponse(Object response) {
+ public void setResponse(Object response)
+ {
this.response = (HttpServletResponse) response;
}
-
/** {@inheritDoc} */
- public void setResponseCharacterEncoding(String encoding) {
+ public void setResponseCharacterEncoding(String encoding)
+ {
this.response.setCharacterEncoding(encoding);
}
-
}
diff --git a/test12/src/main/java/org/apache/myfaces/test/mock/MockFacesContext.java b/test12/src/main/java/org/apache/myfaces/test/mock/MockFacesContext.java
index 6cfb0f2..3421c84 100644
--- a/test12/src/main/java/org/apache/myfaces/test/mock/MockFacesContext.java
+++ b/test12/src/main/java/org/apache/myfaces/test/mock/MockFacesContext.java
@@ -36,79 +36,75 @@
import javax.faces.render.RenderKit;
import javax.faces.render.RenderKitFactory;
-
/**
* <p>Mock implementation of <code>FacesContext</code>.</p>
*
* $Id$
* @since 1.0.0
*/
-public class MockFacesContext extends FacesContext {
-
+public class MockFacesContext extends FacesContext
+{
// ------------------------------------------------------------ Constructors
-
- public MockFacesContext() {
+ public MockFacesContext()
+ {
super();
setCurrentInstance(this);
}
-
- public MockFacesContext(ExternalContext externalContext) {
+ public MockFacesContext(ExternalContext externalContext)
+ {
setExternalContext(externalContext);
setCurrentInstance(this);
}
-
- public MockFacesContext(ExternalContext externalContext, Lifecycle lifecycle) {
+ public MockFacesContext(ExternalContext externalContext, Lifecycle lifecycle)
+ {
this(externalContext);
this.lifecycle = lifecycle;
}
-
// ----------------------------------------------------- Mock Object Methods
-
/**
* <p>Set the <code>Application</code> instance for this instance.</p>
*
* @param application The new Application
*/
- public void setApplication(Application application) {
+ public void setApplication(Application application)
+ {
this.application = application;
}
-
/**
* <p>Set the <code>ExternalContext</code> instance for this instance.</p>
*
* @param externalContext The new ExternalContext
*/
- public void setExternalContext(ExternalContext externalContext) {
+ public void setExternalContext(ExternalContext externalContext)
+ {
this.externalContext = externalContext;
}
-
/**
* <p>Set the <code>FacesContext</code> instance for this instance.</p>
*
* @param facesContext The new FacesContext
*/
- public static void setCurrentInstance(FacesContext facesContext) {
+ public static void setCurrentInstance(FacesContext facesContext)
+ {
FacesContext.setCurrentInstance(facesContext);
}
-
// ------------------------------------------------------ Instance Variables
-
private Application application = null;
private ExternalContext externalContext = null;
private Lifecycle lifecycle = null;
@@ -119,44 +115,47 @@
private ResponseWriter responseWriter = null;
private UIViewRoot viewRoot = null;
-
// ---------------------------------------------------- FacesContext Methods
-
/** {@inheritDoc} */
- public Application getApplication() {
+ public Application getApplication()
+ {
return this.application;
}
-
/** {@inheritDoc} */
- public Iterator getClientIdsWithMessages() {
+ public Iterator getClientIdsWithMessages()
+ {
return messages.keySet().iterator();
}
-
/** {@inheritDoc} */
- public ExternalContext getExternalContext() {
+ public ExternalContext getExternalContext()
+ {
return this.externalContext;
}
-
/** {@inheritDoc} */
- public Severity getMaximumSeverity() {
+ public Severity getMaximumSeverity()
+ {
Severity severity = null;
Iterator messages = getMessages();
- while (messages.hasNext()) {
+ while (messages.hasNext())
+ {
FacesMessage message = (FacesMessage) messages.next();
- if (severity == null) {
+ if (severity == null)
+ {
severity = message.getSeverity();
- } else if (message.getSeverity().getOrdinal() > severity.getOrdinal()) {
+ }
+ else if (message.getSeverity().getOrdinal() > severity.getOrdinal())
+ {
severity = message.getSeverity();
}
}
@@ -164,13 +163,14 @@
}
-
/** {@inheritDoc} */
- public Iterator getMessages() {
+ public Iterator getMessages()
+ {
ArrayList results = new ArrayList();
Iterator clientIds = messages.keySet().iterator();
- while (clientIds.hasNext()) {
+ while (clientIds.hasNext())
+ {
String clientId = (String) clientIds.next();
results.addAll((List) messages.get(clientId));
}
@@ -178,109 +178,114 @@
}
-
/** {@inheritDoc} */
- public Iterator getMessages(String clientId) {
+ public Iterator getMessages(String clientId)
+ {
List list = (List) messages.get(clientId);
- if (list == null) {
+ if (list == null)
+ {
list = new ArrayList();
}
return list.iterator();
}
-
/** {@inheritDoc} */
- public RenderKit getRenderKit() {
+ public RenderKit getRenderKit()
+ {
UIViewRoot vr = getViewRoot();
- if (vr == null) {
+ if (vr == null)
+ {
return null;
}
String renderKitId = vr.getRenderKitId();
- if (renderKitId == null) {
+ if (renderKitId == null)
+ {
return null;
}
- RenderKitFactory rkFactory = (RenderKitFactory)
- FactoryFinder.getFactory(FactoryFinder.RENDER_KIT_FACTORY);
+ RenderKitFactory rkFactory = (RenderKitFactory) FactoryFinder
+ .getFactory(FactoryFinder.RENDER_KIT_FACTORY);
return rkFactory.getRenderKit(this, renderKitId);
}
-
/** {@inheritDoc} */
- public boolean getRenderResponse() {
+ public boolean getRenderResponse()
+ {
return this.renderResponse;
}
-
/** {@inheritDoc} */
- public boolean getResponseComplete() {
+ public boolean getResponseComplete()
+ {
return this.responseComplete;
}
-
/** {@inheritDoc} */
- public ResponseStream getResponseStream() {
+ public ResponseStream getResponseStream()
+ {
return this.responseStream;
}
-
/** {@inheritDoc} */
- public void setResponseStream(ResponseStream responseStream) {
+ public void setResponseStream(ResponseStream responseStream)
+ {
this.responseStream = responseStream;
}
-
/** {@inheritDoc} */
- public ResponseWriter getResponseWriter() {
+ public ResponseWriter getResponseWriter()
+ {
return this.responseWriter;
}
-
/** {@inheritDoc} */
- public void setResponseWriter(ResponseWriter responseWriter) {
+ public void setResponseWriter(ResponseWriter responseWriter)
+ {
this.responseWriter = responseWriter;
}
-
/** {@inheritDoc} */
- public UIViewRoot getViewRoot() {
+ public UIViewRoot getViewRoot()
+ {
return this.viewRoot;
}
-
/** {@inheritDoc} */
- public void setViewRoot(UIViewRoot viewRoot) {
+ public void setViewRoot(UIViewRoot viewRoot)
+ {
this.viewRoot = viewRoot;
}
-
/** {@inheritDoc} */
- public void addMessage(String clientId, FacesMessage message) {
+ public void addMessage(String clientId, FacesMessage message)
+ {
- if (message == null) {
+ if (message == null)
+ {
throw new NullPointerException();
}
List list = (List) messages.get(clientId);
- if (list == null) {
+ if (list == null)
+ {
list = new ArrayList();
messages.put(clientId, list);
}
@@ -288,9 +293,9 @@
}
-
/** {@inheritDoc} */
- public void release() {
+ public void release()
+ {
application = null;
externalContext = null;
@@ -304,21 +309,20 @@
}
-
/** {@inheritDoc} */
- public void renderResponse() {
+ public void renderResponse()
+ {
this.renderResponse = true;
}
-
/** {@inheritDoc} */
- public void responseComplete() {
+ public void responseComplete()
+ {
this.responseComplete = true;
}
-
}
diff --git a/test12/src/main/java/org/apache/myfaces/test/mock/MockFacesContext12.java b/test12/src/main/java/org/apache/myfaces/test/mock/MockFacesContext12.java
index bdd2ae6..c9e95c0 100644
--- a/test12/src/main/java/org/apache/myfaces/test/mock/MockFacesContext12.java
+++ b/test12/src/main/java/org/apache/myfaces/test/mock/MockFacesContext12.java
@@ -34,66 +34,67 @@
*
* @since 1.0.0
*/
-public class MockFacesContext12 extends MockFacesContext {
-
+public class MockFacesContext12 extends MockFacesContext
+{
// ------------------------------------------------------------ Constructors
-
- public MockFacesContext12() {
+ public MockFacesContext12()
+ {
super();
setCurrentInstance(this);
}
-
- public MockFacesContext12(ExternalContext externalContext) {
+ public MockFacesContext12(ExternalContext externalContext)
+ {
super(externalContext);
}
-
- public MockFacesContext12(ExternalContext externalContext, Lifecycle lifecycle) {
+ public MockFacesContext12(ExternalContext externalContext,
+ Lifecycle lifecycle)
+ {
super(externalContext, lifecycle);
}
-
// ----------------------------------------------------- Mock Object Methods
-
/**
* <p>Set the <code>ELContext</code> instance for this instance.</p>
*
* @param elContext The new ELContext
*/
- public void setELContext(ELContext elContext) {
+ public void setELContext(ELContext elContext)
+ {
this.elContext = elContext;
}
-
// ------------------------------------------------------ Instance Variables
-
private ELContext elContext = null;
-
// ---------------------------------------------------- FacesContext Methods
-
/** {@inheritDoc} */
- public ELContext getELContext() {
+ public ELContext getELContext()
+ {
- if (this.elContext == null) {
+ if (this.elContext == null)
+ {
// Initialize a new ELContext
this.elContext = new MockELContext();
this.elContext.putContext(FacesContext.class, this);
// Notify interested listeners that this ELContext was created
- ELContextListener[] listeners = getApplication().getELContextListeners();
- if ((listeners != null) && (listeners.length > 0)) {
+ ELContextListener[] listeners = getApplication()
+ .getELContextListeners();
+ if ((listeners != null) && (listeners.length > 0))
+ {
ELContextEvent event = new ELContextEvent(this.elContext);
- for (int i = 0; i < listeners.length; i++) {
+ for (int i = 0; i < listeners.length; i++)
+ {
listeners[i].contextCreated(event);
}
}
@@ -103,12 +104,11 @@
}
-
/** {@inheritDoc} */
- public void release() {
+ public void release()
+ {
super.release();
this.elContext = null;
}
-
}
diff --git a/test12/src/main/java/org/apache/myfaces/test/mock/MockFacesContextFactory.java b/test12/src/main/java/org/apache/myfaces/test/mock/MockFacesContextFactory.java
index 04c24ee..c40d431 100644
--- a/test12/src/main/java/org/apache/myfaces/test/mock/MockFacesContextFactory.java
+++ b/test12/src/main/java/org/apache/myfaces/test/mock/MockFacesContextFactory.java
@@ -33,143 +33,171 @@
* $Id$
* @since 1.0.0
*/
-public class MockFacesContextFactory extends FacesContextFactory {
-
+public class MockFacesContextFactory extends FacesContextFactory
+{
// ------------------------------------------------------------ Constructors
-
/**
* <p>Look up the constructor we will use for creating <code>MockFacesContext</code>
* instances.</p>
*/
- public MockFacesContextFactory() {
+ public MockFacesContextFactory()
+ {
Class clazz = null;
// Try to load the 1.2 version of our mock FacesContext class
- try {
- clazz = this.getClass().getClassLoader().loadClass("org.apache.myfaces.test.mock.MockFacesContext12");
+ try
+ {
+ clazz = this.getClass().getClassLoader().loadClass(
+ "org.apache.myfaces.test.mock.MockFacesContext12");
constructor = clazz.getConstructor(facesContextSignature);
jsf12 = true;
- } catch (NoClassDefFoundError e) {
+ }
+ catch (NoClassDefFoundError e)
+ {
// We are not running on JSF 1.2, so go to our fallback
clazz = null;
constructor = null;
- } catch (ClassNotFoundException e) {
+ }
+ catch (ClassNotFoundException e)
+ {
// Same as above
clazz = null;
constructor = null;
- } catch (RuntimeException e) {
+ }
+ catch (RuntimeException e)
+ {
throw e;
- } catch (Exception e) {
+ }
+ catch (Exception e)
+ {
throw new FacesException(e);
}
// Fall back to the 1.1 version if we could not load the 1.2 version
- try {
- if (clazz == null) {
- clazz = this.getClass().getClassLoader().loadClass("org.apache.myfaces.test.mock.MockFacesContext");
+ try
+ {
+ if (clazz == null)
+ {
+ clazz = this.getClass().getClassLoader().loadClass(
+ "org.apache.myfaces.test.mock.MockFacesContext");
constructor = clazz.getConstructor(facesContextSignature);
jsf12 = false;
}
- } catch (RuntimeException e) {
+ }
+ catch (RuntimeException e)
+ {
throw e;
- } catch (Exception e) {
+ }
+ catch (Exception e)
+ {
throw new FacesException(e);
}
}
-
// ----------------------------------------------------- Mock Object Methods
-
// ------------------------------------------------------ Instance Variables
-
/**
* <p>The constructor for creating a <code>FacesContext</code> instance,
* taking an <code>ExternalContext</code> and <code>Lifecycle</code>.</p>
*/
private Constructor constructor = null;
-
/**
* <p>The parameter signature of the ExternalContext constructor we wish to call.</p>
*/
private static Class[] externalContextSignature = new Class[] {
- ServletContext.class, HttpServletRequest.class, HttpServletResponse.class
- };
-
+ ServletContext.class, HttpServletRequest.class,
+ HttpServletResponse.class };
/**
* <p>The parameter signature of the FacesContext constructor we wish to call.</p>
*/
private static Class[] facesContextSignature = new Class[] {
- ExternalContext.class, Lifecycle.class
- };
-
+ ExternalContext.class, Lifecycle.class };
/**
* <p>Flag indicating that we are running in a JSF 1.2 environment.</p>
*/
private boolean jsf12 = false;
-
// --------------------------------------------- FacesContextFactory Methods
-
/** {@inheritDoc} */
public FacesContext getFacesContext(Object context, Object request,
- Object response,
- Lifecycle lifecycle) throws FacesException {
+ Object response, Lifecycle lifecycle) throws FacesException
+ {
// Select the appropriate MockExternalContext implementation class
Class clazz = MockExternalContext.class;
- if (jsf12) {
- try {
- clazz = this.getClass().getClassLoader().loadClass
- ("org.apache.myfaces.test.mock.MockExternalContext12");
- } catch (RuntimeException e) {
+ if (jsf12)
+ {
+ try
+ {
+ clazz = this.getClass().getClassLoader().loadClass(
+ "org.apache.myfaces.test.mock.MockExternalContext12");
+ }
+ catch (RuntimeException e)
+ {
throw e;
- } catch (Exception e) {
+ }
+ catch (Exception e)
+ {
throw new FacesException(e);
}
}
// Select the constructor we wish to call
Constructor mecConstructor = null;
- try {
+ try
+ {
mecConstructor = clazz.getConstructor(externalContextSignature);
- } catch (RuntimeException e) {
+ }
+ catch (RuntimeException e)
+ {
throw e;
- } catch (Exception e) {
+ }
+ catch (Exception e)
+ {
throw new FacesException(e);
}
// Construct an appropriate MockExternalContext instance
MockExternalContext externalContext = null;
- try {
- externalContext = (MockExternalContext) mecConstructor.newInstance
- (new Object[] { context, request, response });
- } catch (RuntimeException e) {
+ try
+ {
+ externalContext = (MockExternalContext) mecConstructor
+ .newInstance(new Object[] { context, request, response });
+ }
+ catch (RuntimeException e)
+ {
throw e;
- } catch (Exception e) {
+ }
+ catch (Exception e)
+ {
throw new FacesException(e);
}
// Construct an appropriate MockFacesContext instance and return it
- try {
- return (MockFacesContext)
- constructor.newInstance(new Object[] { externalContext, lifecycle });
- } catch (RuntimeException e) {
+ try
+ {
+ return (MockFacesContext) constructor.newInstance(new Object[] {
+ externalContext, lifecycle });
+ }
+ catch (RuntimeException e)
+ {
throw e;
- } catch (Exception e) {
+ }
+ catch (Exception e)
+ {
throw new FacesException(e);
}
}
-
}
diff --git a/test12/src/main/java/org/apache/myfaces/test/mock/MockHttpServletRequest.java b/test12/src/main/java/org/apache/myfaces/test/mock/MockHttpServletRequest.java
index 49ec4d9..f193798 100644
--- a/test12/src/main/java/org/apache/myfaces/test/mock/MockHttpServletRequest.java
+++ b/test12/src/main/java/org/apache/myfaces/test/mock/MockHttpServletRequest.java
@@ -46,47 +46,44 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
-
/**
* <p>Mock implementation of <code>HttpServletContext</code>.</p>
*
* $Id$
* @since 1.0.0
*/
-public class MockHttpServletRequest implements HttpServletRequest {
-
+public class MockHttpServletRequest implements HttpServletRequest
+{
// ------------------------------------------------------------ Constructors
-
- public MockHttpServletRequest() {
+ public MockHttpServletRequest()
+ {
super();
}
-
- public MockHttpServletRequest(HttpSession session) {
+ public MockHttpServletRequest(HttpSession session)
+ {
super();
setHttpSession(session);
}
-
public MockHttpServletRequest(String contextPath, String servletPath,
- String pathInfo, String queryString) {
+ String pathInfo, String queryString)
+ {
super();
setPathElements(contextPath, servletPath, pathInfo, queryString);
}
-
-
public MockHttpServletRequest(String contextPath, String servletPath,
- String pathInfo, String queryString,
- HttpSession session) {
+ String pathInfo, String queryString, HttpSession session)
+ {
super();
setPathElements(contextPath, servletPath, pathInfo, queryString);
@@ -94,70 +91,70 @@
}
-
// ----------------------------------------------------- Mock Object Methods
-
/**
* <p>Add a new listener instance that should be notified about
* attribute changes.</p>
*
* @param listener The new listener to register
*/
- public void addAttributeListener(ServletRequestAttributeListener listener) {
+ public void addAttributeListener(ServletRequestAttributeListener listener)
+ {
attributeListeners.add(listener);
}
-
/**
* <p>Add a date-valued header for this request.</p>
*
* @param name Header name
* @param value Header value
*/
- public void addDateHeader(String name, long value) {
+ public void addDateHeader(String name, long value)
+ {
headers.add(name + ": " + formatDate(value));
}
-
/**
* <p>Add a String-valued header for this request.</p>
*
* @param name Header name
* @param value Header value
*/
- public void addHeader(String name, String value) {
+ public void addHeader(String name, String value)
+ {
headers.add(name + ": " + value);
}
-
/**
* <p>Add an integer-valued header for this request.</p>
*
* @param name Header name
* @param value Header value
*/
- public void addIntHeader(String name, int value) {
+ public void addIntHeader(String name, int value)
+ {
headers.add(name + ": " + value);
}
-
/**
* <p>Add a request parameter for this request.</p>
*
* @param name Parameter name
* @param value Parameter value
*/
- public void addParameter(String name, String value) {
+ public void addParameter(String name, String value)
+ {
String[] values = (String[]) parameters.get(name);
- if (values == null) {
+ if (values == null)
+ {
String[] results = new String[] { value };
parameters.put(name, results);
return;
@@ -168,12 +165,12 @@
parameters.put(name, results);
}
-
+
public void addCookie(Cookie c)
{
for (int i = 0; i < cookies.size(); i++)
{
- if ( ((Cookie)cookies.get(i)).getName().equals(c.getName()) )
+ if (((Cookie) cookies.get(i)).getName().equals(c.getName()))
{
cookies.set(i, c);
return;
@@ -186,37 +183,37 @@
* <p>Return the <code>ServletContext</code> associated with
* this request.</p>
*/
- public ServletContext getServletContext() {
+ public ServletContext getServletContext()
+ {
return this.servletContext;
}
-
/**
* <p>Set the <code>HttpSession</code> associated with this request.</p>
*
* @param session The new session
*/
- public void setHttpSession(HttpSession session) {
+ public void setHttpSession(HttpSession session)
+ {
this.session = session;
}
-
/**
* <p>Set the <code>Locale</code> associated with this request.</p>
*
* @param locale The new locale
*/
- public void setLocale(Locale locale) {
+ public void setLocale(Locale locale)
+ {
this.locale = locale;
}
-
/**
* <p>Set the parsed path elements associated with this request.</p>
*
@@ -226,7 +223,8 @@
* @param queryString The query string
*/
public void setPathElements(String contextPath, String servletPath,
- String pathInfo, String queryString) {
+ String pathInfo, String queryString)
+ {
this.contextPath = contextPath;
this.servletPath = servletPath;
@@ -235,34 +233,32 @@
}
-
/**
* <p>Set the <code>ServletContext</code> associated with this request.</p>
*
* @param servletContext The new servlet context
*/
- public void setServletContext(ServletContext servletContext) {
+ public void setServletContext(ServletContext servletContext)
+ {
this.servletContext = servletContext;
}
-
/**
* <p>Set the <code>Principal</code> associated with this request.</p>
*
* @param principal The new Principal
*/
- public void setUserPrincipal(Principal principal) {
+ public void setUserPrincipal(Principal principal)
+ {
this.principal = principal;
}
-
// ------------------------------------------------------ Instance Variables
-
private List attributeListeners = new ArrayList();
private HashMap attributes = new HashMap();
private String contextPath = null;
@@ -278,29 +274,29 @@
private String characterEncoding = null;
private ServletInputStream inputStream = null;
private List cookies = new ArrayList();
- private Vector locales = null;
+ private Vector locales = null;
// ---------------------------------------------- HttpServletRequest Methods
-
/** {@inheritDoc} */
- public String getAuthType() {
+ public String getAuthType()
+ {
throw new UnsupportedOperationException();
}
-
/** {@inheritDoc} */
- public String getContextPath() {
+ public String getContextPath()
+ {
return contextPath;
}
-
/** {@inheritDoc} */
- public Cookie[] getCookies() {
+ public Cookie[] getCookies()
+ {
Cookie[] array = new Cookie[cookies.size()];
for (int i = 0; i < cookies.size(); i++)
@@ -310,15 +306,17 @@
return array;
}
-
/** {@inheritDoc} */
- public long getDateHeader(String name) {
+ public long getDateHeader(String name)
+ {
String match = name + ":";
Iterator headers = this.headers.iterator();
- while (headers.hasNext()) {
+ while (headers.hasNext())
+ {
String header = (String) headers.next();
- if (header.startsWith(match)) {
+ if (header.startsWith(match))
+ {
return parseDate(header.substring(match.length() + 1).trim());
}
}
@@ -326,15 +324,17 @@
}
-
/** {@inheritDoc} */
- public String getHeader(String name) {
+ public String getHeader(String name)
+ {
String match = name + ":";
Iterator headers = this.headers.iterator();
- while (headers.hasNext()) {
+ while (headers.hasNext())
+ {
String header = (String) headers.next();
- if (header.startsWith(match)) {
+ if (header.startsWith(match))
+ {
return header.substring(match.length() + 1).trim();
}
}
@@ -342,18 +342,21 @@
}
-
/** {@inheritDoc} */
- public Enumeration getHeaderNames() {
+ public Enumeration getHeaderNames()
+ {
Vector values = new Vector();
Iterator headers = this.headers.iterator();
- while (headers.hasNext()) {
+ while (headers.hasNext())
+ {
String header = (String) headers.next();
int colon = header.indexOf(':');
- if (colon >= 0) {
+ if (colon >= 0)
+ {
String name = header.substring(0, colon).trim();
- if (!values.contains(name)) {
+ if (!values.contains(name))
+ {
values.add(name);
}
}
@@ -362,16 +365,18 @@
}
-
/** {@inheritDoc} */
- public Enumeration getHeaders(String name) {
+ public Enumeration getHeaders(String name)
+ {
String match = name + ":";
Vector values = new Vector();
Iterator headers = this.headers.iterator();
- while (headers.hasNext()) {
+ while (headers.hasNext())
+ {
String header = (String) headers.next();
- if (header.startsWith(match)) {
+ if (header.startsWith(match))
+ {
values.add(header.substring(match.length() + 1).trim());
}
}
@@ -379,557 +384,583 @@
}
-
/** {@inheritDoc} */
- public int getIntHeader(String name) {
+ public int getIntHeader(String name)
+ {
String match = name + ":";
Iterator headers = this.headers.iterator();
- while (headers.hasNext()) {
+ while (headers.hasNext())
+ {
String header = (String) headers.next();
- if (header.startsWith(match)) {
- return Integer.parseInt(header.substring(match.length() + 1).trim());
+ if (header.startsWith(match))
+ {
+ return Integer.parseInt(header.substring(match.length() + 1)
+ .trim());
}
}
return -1;
}
-
/** {@inheritDoc} */
- public String getMethod() {
+ public String getMethod()
+ {
throw new UnsupportedOperationException();
}
-
/** {@inheritDoc} */
- public String getPathInfo() {
+ public String getPathInfo()
+ {
return pathInfo;
}
-
/** {@inheritDoc} */
- public String getPathTranslated() {
+ public String getPathTranslated()
+ {
throw new UnsupportedOperationException();
}
-
/** {@inheritDoc} */
- public String getQueryString() {
+ public String getQueryString()
+ {
return queryString;
}
-
/** {@inheritDoc} */
- public String getRemoteUser() {
+ public String getRemoteUser()
+ {
- if (principal != null) {
+ if (principal != null)
+ {
return principal.getName();
- } else {
+ }
+ else
+ {
return null;
}
}
-
/** {@inheritDoc} */
- public String getRequestedSessionId() {
+ public String getRequestedSessionId()
+ {
throw new UnsupportedOperationException();
}
-
/** {@inheritDoc} */
- public String getRequestURI() {
+ public String getRequestURI()
+ {
StringBuffer sb = new StringBuffer();
- if (contextPath != null) {
+ if (contextPath != null)
+ {
sb.append(contextPath);
}
- if (servletPath != null) {
+ if (servletPath != null)
+ {
sb.append(servletPath);
}
- if (pathInfo != null) {
+ if (pathInfo != null)
+ {
sb.append(pathInfo);
}
- if (sb.length() > 0) {
+ if (sb.length() > 0)
+ {
return sb.toString();
}
throw new UnsupportedOperationException();
}
-
/** {@inheritDoc} */
- public StringBuffer getRequestURL() {
+ public StringBuffer getRequestURL()
+ {
throw new UnsupportedOperationException();
}
-
/** {@inheritDoc} */
- public String getServletPath() {
+ public String getServletPath()
+ {
return (servletPath);
}
-
/** {@inheritDoc} */
- public HttpSession getSession() {
+ public HttpSession getSession()
+ {
return getSession(true);
}
-
/** {@inheritDoc} */
- public HttpSession getSession(boolean create) {
+ public HttpSession getSession(boolean create)
+ {
- if (create && (session == null)) {
+ if (create && (session == null))
+ {
this.session = new MockHttpSession(this.servletContext);
}
return session;
}
-
/** {@inheritDoc} */
- public Principal getUserPrincipal() {
+ public Principal getUserPrincipal()
+ {
return principal;
}
-
/** {@inheritDoc} */
- public boolean isRequestedSessionIdFromCookie() {
+ public boolean isRequestedSessionIdFromCookie()
+ {
throw new UnsupportedOperationException();
}
-
/** {@inheritDoc} */
- public boolean isRequestedSessionIdFromUrl() {
+ public boolean isRequestedSessionIdFromUrl()
+ {
throw new UnsupportedOperationException();
}
-
/** {@inheritDoc} */
- public boolean isRequestedSessionIdFromURL() {
+ public boolean isRequestedSessionIdFromURL()
+ {
throw new UnsupportedOperationException();
}
-
/** {@inheritDoc} */
- public boolean isRequestedSessionIdValid() {
+ public boolean isRequestedSessionIdValid()
+ {
throw new UnsupportedOperationException();
}
-
/** {@inheritDoc} */
- public boolean isUserInRole(String role) {
+ public boolean isUserInRole(String role)
+ {
throw new UnsupportedOperationException();
}
-
// ------------------------------------------------- ServletRequest Methods
-
/** {@inheritDoc} */
- public Object getAttribute(String name) {
+ public Object getAttribute(String name)
+ {
return attributes.get(name);
}
-
/** {@inheritDoc} */
- public Enumeration getAttributeNames() {
+ public Enumeration getAttributeNames()
+ {
return new MockEnumeration(attributes.keySet().iterator());
}
-
/** {@inheritDoc} */
- public String getCharacterEncoding() {
+ public String getCharacterEncoding()
+ {
return characterEncoding;
}
-
/** {@inheritDoc} */
- public int getContentLength() {
+ public int getContentLength()
+ {
throw new UnsupportedOperationException();
}
-
/** {@inheritDoc} */
- public String getContentType() {
+ public String getContentType()
+ {
throw new UnsupportedOperationException();
}
-
/** {@inheritDoc} */
public ServletInputStream getInputStream()
{
return this.inputStream;
}
-
+
public void setInputStream(MockServletInputStream stream)
{
this.inputStream = stream;
}
/** {@inheritDoc} */
- public Locale getLocale() {
+ public Locale getLocale()
+ {
return locale;
}
-
/** {@inheritDoc} */
public Enumeration getLocales()
{
if (this.locales == null)
{
- locales = new Vector(Arrays.asList(Locale
- .getAvailableLocales()));
+ locales = new Vector(Arrays.asList(Locale.getAvailableLocales()));
}
return this.locales.elements();
}
-
/** {@inheritDoc} */
- public String getLocalAddr() {
+ public String getLocalAddr()
+ {
throw new UnsupportedOperationException();
}
-
/** {@inheritDoc} */
- public String getLocalName() {
+ public String getLocalName()
+ {
throw new UnsupportedOperationException();
}
-
/** {@inheritDoc} */
- public int getLocalPort() {
+ public int getLocalPort()
+ {
throw new UnsupportedOperationException();
}
-
/** {@inheritDoc} */
- public String getParameter(String name) {
+ public String getParameter(String name)
+ {
String[] values = (String[]) parameters.get(name);
- if (values != null) {
+ if (values != null)
+ {
return values[0];
- } else {
+ }
+ else
+ {
return null;
}
}
-
/** {@inheritDoc} */
- public Map getParameterMap() {
+ public Map getParameterMap()
+ {
return parameters;
}
-
/** {@inheritDoc} */
- public Enumeration getParameterNames() {
+ public Enumeration getParameterNames()
+ {
return new MockEnumeration(parameters.keySet().iterator());
}
-
/** {@inheritDoc} */
- public String[] getParameterValues(String name) {
+ public String[] getParameterValues(String name)
+ {
return (String[]) parameters.get(name);
}
-
/** {@inheritDoc} */
- public String getProtocol() {
+ public String getProtocol()
+ {
throw new UnsupportedOperationException();
}
-
/** {@inheritDoc} */
public BufferedReader getReader()
{
- if (this.inputStream != null) {
- try{
+ if (this.inputStream != null)
+ {
+ try
+ {
Reader sourceReader = (this.characterEncoding != null) ? new InputStreamReader(
this.inputStream, this.characterEncoding)
: new InputStreamReader(this.inputStream);
return new BufferedReader(sourceReader);
}
- catch(UnsupportedEncodingException e)
+ catch (UnsupportedEncodingException e)
{
throw new RuntimeException(e);
}
- } else {
+ }
+ else
+ {
return null;
}
}
-
/** {@inheritDoc} */
- public String getRealPath(String path) {
+ public String getRealPath(String path)
+ {
throw new UnsupportedOperationException();
}
-
/** {@inheritDoc} */
- public String getRemoteAddr() {
+ public String getRemoteAddr()
+ {
// i figure testing never assumes a specific remote - so anything works
return "1.2.3.4";
}
-
/** {@inheritDoc} */
- public String getRemoteHost() {
+ public String getRemoteHost()
+ {
// i figure testing never assumes a specific remote - so anything works
return "MyfacesServer";
}
-
/** {@inheritDoc} */
- public int getRemotePort() {
+ public int getRemotePort()
+ {
// i figure testing never assumes a specific remote - so anything works
return 46123;
}
-
/** {@inheritDoc} */
public RequestDispatcher getRequestDispatcher(String path)
{
return servletContext.getRequestDispatcher(path);
}
-
/** {@inheritDoc} */
- public String getScheme() {
+ public String getScheme()
+ {
return ("http");
}
-
/** {@inheritDoc} */
- public String getServerName() {
+ public String getServerName()
+ {
return ("localhost");
}
-
/** {@inheritDoc} */
- public int getServerPort() {
+ public int getServerPort()
+ {
return (8080);
}
-
/** {@inheritDoc} */
- public boolean isSecure() {
+ public boolean isSecure()
+ {
return false;
}
-
/** {@inheritDoc} */
- public void removeAttribute(String name) {
+ public void removeAttribute(String name)
+ {
- if (attributes.containsKey(name)) {
+ if (attributes.containsKey(name))
+ {
Object value = attributes.remove(name);
fireAttributeRemoved(name, value);
}
}
-
/** {@inheritDoc} */
- public void setAttribute(String name, Object value) {
+ public void setAttribute(String name, Object value)
+ {
- if (name == null) {
+ if (name == null)
+ {
throw new IllegalArgumentException("Attribute name cannot be null");
}
- if (value == null) {
+ if (value == null)
+ {
removeAttribute(name);
return;
}
- if (attributes.containsKey(name)) {
+ if (attributes.containsKey(name))
+ {
Object oldValue = attributes.get(name);
attributes.put(name, value);
fireAttributeReplaced(name, oldValue);
- } else {
+ }
+ else
+ {
attributes.put(name, value);
fireAttributeAdded(name, value);
}
}
-
/** {@inheritDoc} */
- public void setCharacterEncoding(String characterEncoding) {
+ public void setCharacterEncoding(String characterEncoding)
+ {
this.characterEncoding = characterEncoding;
}
-
// --------------------------------------------------------- Private Methods
-
/**
* <p>Fire an attribute added event to interested listeners.</p>
*
* @param key Attribute key whose value was added
* @param value The new attribute value
*/
- private void fireAttributeAdded(String key, Object value) {
- if (attributeListeners.size() < 1) {
+ private void fireAttributeAdded(String key, Object value)
+ {
+ if (attributeListeners.size() < 1)
+ {
return;
}
- ServletRequestAttributeEvent event =
- new ServletRequestAttributeEvent(getServletContext(), this, key, value);
+ ServletRequestAttributeEvent event = new ServletRequestAttributeEvent(
+ getServletContext(), this, key, value);
Iterator listeners = attributeListeners.iterator();
- while (listeners.hasNext()) {
- ServletRequestAttributeListener listener =
- (ServletRequestAttributeListener) listeners.next();
+ while (listeners.hasNext())
+ {
+ ServletRequestAttributeListener listener = (ServletRequestAttributeListener) listeners
+ .next();
listener.attributeAdded(event);
}
}
-
/**
* <p>Fire an attribute removed event to interested listeners.</p>
*
* @param key Attribute key whose value was removed
* @param value Attribute value that was removed
*/
- private void fireAttributeRemoved(String key, Object value) {
- if (attributeListeners.size() < 1) {
+ private void fireAttributeRemoved(String key, Object value)
+ {
+ if (attributeListeners.size() < 1)
+ {
return;
}
- ServletRequestAttributeEvent event =
- new ServletRequestAttributeEvent(getServletContext(), this, key, value);
+ ServletRequestAttributeEvent event = new ServletRequestAttributeEvent(
+ getServletContext(), this, key, value);
Iterator listeners = attributeListeners.iterator();
- while (listeners.hasNext()) {
- ServletRequestAttributeListener listener =
- (ServletRequestAttributeListener) listeners.next();
+ while (listeners.hasNext())
+ {
+ ServletRequestAttributeListener listener = (ServletRequestAttributeListener) listeners
+ .next();
listener.attributeRemoved(event);
}
}
-
/**
* <p>Fire an attribute replaced event to interested listeners.</p>
*
* @param key Attribute key whose value was replaced
* @param value The original value
*/
- private void fireAttributeReplaced(String key, Object value) {
- if (attributeListeners.size() < 1) {
+ private void fireAttributeReplaced(String key, Object value)
+ {
+ if (attributeListeners.size() < 1)
+ {
return;
}
- ServletRequestAttributeEvent event =
- new ServletRequestAttributeEvent(getServletContext(), this, key, value);
+ ServletRequestAttributeEvent event = new ServletRequestAttributeEvent(
+ getServletContext(), this, key, value);
Iterator listeners = attributeListeners.iterator();
- while (listeners.hasNext()) {
- ServletRequestAttributeListener listener =
- (ServletRequestAttributeListener) listeners.next();
+ while (listeners.hasNext())
+ {
+ ServletRequestAttributeListener listener = (ServletRequestAttributeListener) listeners
+ .next();
listener.attributeReplaced(event);
}
}
-
/**
* <p>The date formatting helper we will use in <code>httpTimestamp()</code>.
* Note that usage of this helper must be synchronized.</p>
*/
- private static SimpleDateFormat format =
- new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz");
- static {
+ private static SimpleDateFormat format = new SimpleDateFormat(
+ "EEE, dd MMM yyyy HH:mm:ss zzz");
+ static
+ {
format.setTimeZone(TimeZone.getTimeZone("GMT"));
}
-
/**
* <p>Return a properly formatted String version of the specified
* date/time, formatted as required by the HTTP specification.</p>
*
* @param date Date/time, expressed as milliseconds since the epoch
*/
- private String formatDate(long date) {
+ private String formatDate(long date)
+ {
return format.format(new Date(date));
}
-
/**
* <p>Return a date/time value, parsed from the specified String.</p>
*
* @param date Date/time, expressed as a String
*/
- private long parseDate(String date) {
- try {
+ private long parseDate(String date)
+ {
+ try
+ {
return format.parse(date).getTime();
- } catch (ParseException e) {
+ }
+ catch (ParseException e)
+ {
throw new IllegalArgumentException(date);
}
}
-
}
diff --git a/test12/src/main/java/org/apache/myfaces/test/mock/MockHttpServletResponse.java b/test12/src/main/java/org/apache/myfaces/test/mock/MockHttpServletResponse.java
index 8afbd5c..af329a5 100644
--- a/test12/src/main/java/org/apache/myfaces/test/mock/MockHttpServletResponse.java
+++ b/test12/src/main/java/org/apache/myfaces/test/mock/MockHttpServletResponse.java
@@ -41,60 +41,62 @@
* $Id$
* @since 1.0.0
*/
-public class MockHttpServletResponse implements HttpServletResponse {
-
+public class MockHttpServletResponse implements HttpServletResponse
+{
// ------------------------------------------------------------ Constructors
-
/**
* <p>Return a default instance.</p>
*/
- public MockHttpServletResponse() { }
-
+ public MockHttpServletResponse()
+ {
+ }
// ----------------------------------------------------- Mock Object Methods
-
/**
* <p>Retrieve the first value that was set for the specified header,
* if any. Otherwise, return <code>null</code>.</p>
*
* @param name Header name to look up
*/
- public String getHeader(String name) {
+ public String getHeader(String name)
+ {
String match = name + ":";
Iterator headers = this.headers.iterator();
- while (headers.hasNext()) {
+ while (headers.hasNext())
+ {
String header = (String) headers.next();
- if (header.startsWith(match)) {
+ if (header.startsWith(match))
+ {
return header.substring(match.length() + 1).trim();
}
}
return null;
}
-
+
public Cookie getCookie(String name)
{
- return (Cookie)cookies.get(name);
+ return (Cookie) cookies.get(name);
}
-
+
/**
* <p>Return the text message for the HTTP status that was set.</p>
*/
- public String getMessage() {
+ public String getMessage()
+ {
return this.message;
}
-
/**
* <p>Return the HTTP status code that was set.</p>
*/
- public int getStatus() {
+ public int getStatus()
+ {
return this.status;
}
-
/**
* <p>Set the <code>ServletOutputStream</code> to be returned by a call to
* <code>getOutputStream()</code>.</p>
@@ -104,11 +106,11 @@
* @deprecated Let the <code>getOutputStream()</code> method create and
* return an instance of <code>MockServletOutputStream</code> for you
*/
- public void setOutputStream(ServletOutputStream stream) {
+ public void setOutputStream(ServletOutputStream stream)
+ {
this.stream = stream;
}
-
/**
* <p>Set the <code>PrintWriter</code> to be returned by a call to
* <code>getWriter()</code>.</p>
@@ -118,14 +120,13 @@
* @deprecated Let the <code>getWriter()</code> method create and return
* an instance of <code>MockPrintWriter</code> for you
*/
- public void setWriter(PrintWriter writer) {
+ public void setWriter(PrintWriter writer)
+ {
this.writer = writer;
}
-
// ------------------------------------------------------ Instance Variables
-
private String encoding = "ISO-8859-1";
private String contentType = "text/html";
private List headers = new ArrayList();
@@ -133,7 +134,7 @@
private int status = HttpServletResponse.SC_OK;
private ServletOutputStream stream = null;
private PrintWriter writer = null;
-
+
private boolean committed = false;
private long contentLength = 0;
private int bufferSize = 0;
@@ -142,78 +143,76 @@
// -------------------------------------------- HttpServletResponse Methods
-
/** {@inheritDoc} */
public void addCookie(Cookie cookie)
{
cookies.put(cookie.getName(), cookie);
}
-
/** {@inheritDoc} */
- public void addDateHeader(String name, long value) {
+ public void addDateHeader(String name, long value)
+ {
headers.add(name + ": " + formatDate(value));
}
-
/** {@inheritDoc} */
- public void addHeader(String name, String value) {
+ public void addHeader(String name, String value)
+ {
headers.add(name + ": " + value);
}
-
/** {@inheritDoc} */
- public void addIntHeader(String name, int value) {
+ public void addIntHeader(String name, int value)
+ {
headers.add(name + ": " + value);
}
-
/** {@inheritDoc} */
- public boolean containsHeader(String name) {
+ public boolean containsHeader(String name)
+ {
return getHeader(name) != null;
}
-
/** {@inheritDoc} */
- public String encodeRedirectUrl(String url) {
+ public String encodeRedirectUrl(String url)
+ {
return encodeRedirectURL(url);
}
-
/** {@inheritDoc} */
- public String encodeRedirectURL(String url) {
+ public String encodeRedirectURL(String url)
+ {
return url;
}
-
/** {@inheritDoc} */
- public String encodeUrl(String url) {
+ public String encodeUrl(String url)
+ {
return encodeURL(url);
}
-
/** {@inheritDoc} */
- public String encodeURL(String url) {
+ public String encodeURL(String url)
+ {
return url;
}
-
/** {@inheritDoc} */
public void sendError(int status)
{
@@ -225,7 +224,6 @@
this.committed = true;
}
-
/** {@inheritDoc} */
public void sendError(int status, String message)
{
@@ -238,10 +236,11 @@
this.committed = true;
}
-
/** {@inheritDoc} */
- public void sendRedirect(String location) {
- if (this.committed) {
+ public void sendRedirect(String location)
+ {
+ if (this.committed)
+ {
throw new IllegalStateException("Response is already committed");
}
this.status = HttpServletResponse.SC_MOVED_TEMPORARILY;
@@ -249,93 +248,92 @@
this.committed = true;
}
-
/** {@inheritDoc} */
- public void setDateHeader(String name, long value) {
+ public void setDateHeader(String name, long value)
+ {
removeHeader(name);
addDateHeader(name, value);
}
-
/** {@inheritDoc} */
- public void setHeader(String name, String value) {
+ public void setHeader(String name, String value)
+ {
removeHeader(name);
addHeader(name, value);
}
-
/** {@inheritDoc} */
- public void setIntHeader(String name, int value) {
+ public void setIntHeader(String name, int value)
+ {
removeHeader(name);
addIntHeader(name, value);
}
-
/** {@inheritDoc} */
public void setStatus(int status)
{
this.status = status;
}
-
/** {@inheritDoc} */
- public void setStatus(int status, String message) {
+ public void setStatus(int status, String message)
+ {
this.status = status;
this.message = message;
}
-
// ------------------------------------------------ ServletResponse Methods
-
/** {@inheritDoc} */
public void flushBuffer()
{
-
+
}
-
/** {@inheritDoc} */
- public int getBufferSize() {
+ public int getBufferSize()
+ {
return bufferSize;
}
-
/** {@inheritDoc} */
- public String getCharacterEncoding() {
+ public String getCharacterEncoding()
+ {
return this.encoding;
}
-
/** {@inheritDoc} */
- public String getContentType() {
+ public String getContentType()
+ {
return this.contentType;
}
-
/** {@inheritDoc} */
public Locale getLocale()
{
return this.locale;
}
-
/** {@inheritDoc} */
- public ServletOutputStream getOutputStream() throws IOException {
+ public ServletOutputStream getOutputStream() throws IOException
+ {
- if (stream == null) {
- if (writer != null) {
- throw new IllegalStateException("Cannot call getOutputStream() after getWriter() has been called");
+ if (stream == null)
+ {
+ if (writer != null)
+ {
+ throw new IllegalStateException(
+ "Cannot call getOutputStream() after getWriter() has been called");
}
stream = new MockServletOutputStream(new ByteArrayOutputStream());
}
@@ -343,13 +341,16 @@
}
-
/** {@inheritDoc} */
- public PrintWriter getWriter() throws IOException {
+ public PrintWriter getWriter() throws IOException
+ {
- if (writer == null) {
- if (stream != null) {
- throw new IllegalStateException("Cannot call getWriter() after getOutputStream() was called");
+ if (writer == null)
+ {
+ if (stream != null)
+ {
+ throw new IllegalStateException(
+ "Cannot call getWriter() after getOutputStream() was called");
}
writer = new MockPrintWriter(new CharArrayWriter());
}
@@ -357,104 +358,98 @@
}
-
/** {@inheritDoc} */
public boolean isCommitted()
{
return committed;
}
-
/** {@inheritDoc} */
public void reset()
{
}
-
/** {@inheritDoc} */
public void resetBuffer()
{
}
-
/** {@inheritDoc} */
public void setBufferSize(int size)
{
this.bufferSize = size;
}
-
/** {@inheritDoc} */
- public void setCharacterEncoding(String charset) {
+ public void setCharacterEncoding(String charset)
+ {
this.encoding = charset;
}
-
/** {@inheritDoc} */
public void setContentLength(int length)
{
this.contentLength = length;
}
-
/** {@inheritDoc} */
- public void setContentType(String type) {
+ public void setContentType(String type)
+ {
contentType = type;
}
-
/** {@inheritDoc} */
public void setLocale(Locale locale)
{
this.locale = locale;
}
-
// --------------------------------------------------------- Private Methods
-
/**
* <p>The date formatting helper we will use in <code>httpTimestamp()</code>.
* Note that usage of this helper must be synchronized.</p>
*/
- private static SimpleDateFormat format =
- new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz");
- static {
+ private static SimpleDateFormat format = new SimpleDateFormat(
+ "EEE, dd MMM yyyy HH:mm:ss zzz");
+ static
+ {
format.setTimeZone(TimeZone.getTimeZone("GMT"));
}
-
/**
* <p>Return a properly formatted String version of the specified
* date/time, formatted as required by the HTTP specification.</p>
*
* @param date Date/time, expressed as milliseconds since the epoch
*/
- private String formatDate(long date) {
+ private String formatDate(long date)
+ {
return format.format(new Date(date));
}
-
/**
* <p>Remove any header that has been set with the specific name.</p>
*
* @param name Header name to look up
*/
- private void removeHeader(String name) {
+ private void removeHeader(String name)
+ {
String match = name + ":";
Iterator headers = this.headers.iterator();
- while (headers.hasNext()) {
+ while (headers.hasNext())
+ {
String header = (String) headers.next();
- if (header.startsWith(match)) {
+ if (header.startsWith(match))
+ {
headers.remove();
return;
}
}
}
-
}
diff --git a/test12/src/main/java/org/apache/myfaces/test/mock/MockHttpSession.java b/test12/src/main/java/org/apache/myfaces/test/mock/MockHttpSession.java
index 919b7f2..37acb88 100644
--- a/test12/src/main/java/org/apache/myfaces/test/mock/MockHttpSession.java
+++ b/test12/src/main/java/org/apache/myfaces/test/mock/MockHttpSession.java
@@ -35,90 +35,85 @@
* $Id$
* @since 1.0.0
*/
-public class MockHttpSession implements HttpSession {
-
+public class MockHttpSession implements HttpSession
+{
// ------------------------------------------------------------ Constructors
-
/**
* <p>Configure a default instance.</p>
*/
- public MockHttpSession() {
+ public MockHttpSession()
+ {
super();
}
-
/**
* <p>Configure a session instance associated with the specified
* servlet context.</p>
*
* @param servletContext The associated servlet context
*/
- public MockHttpSession(ServletContext servletContext) {
+ public MockHttpSession(ServletContext servletContext)
+ {
super();
setServletContext(servletContext);
}
-
// ----------------------------------------------------- Mock Object Methods
-
/**
* <p>Add a new listener instance that should be notified about
* attribute changes.</p>
*
* @param listener The new listener to be added
*/
- public void addAttributeListener(HttpSessionAttributeListener listener) {
+ public void addAttributeListener(HttpSessionAttributeListener listener)
+ {
attributeListeners.add(listener);
}
-
/**
* <p>Set the ServletContext associated with this session.</p>
*
* @param servletContext The associated servlet context
*/
- public void setServletContext(ServletContext servletContext) {
+ public void setServletContext(ServletContext servletContext)
+ {
this.servletContext = servletContext;
}
-
// ------------------------------------------------------ Instance Variables
-
private List attributeListeners = new ArrayList();
private HashMap attributes = new HashMap();
private String id = "123";
private ServletContext servletContext = null;
private boolean invalid = false;
-
// ---------------------------------------------------------- Public Methods
-
/**
* <p>Set the session identifier of this session.</p>
*
* @param id The new session identifier
*/
- public void setId(String id) {
+ public void setId(String id)
+ {
this.id = id;
}
-
// ----------------------------------------------------- HttpSession Methods
-
/** {@inheritDoc} */
- public Object getAttribute(String name) {
+ public Object getAttribute(String name)
+ {
assertValidity();
@@ -126,9 +121,9 @@
}
-
/** {@inheritDoc} */
- public Enumeration getAttributeNames() {
+ public Enumeration getAttributeNames()
+ {
assertValidity();
@@ -136,222 +131,232 @@
}
-
/** {@inheritDoc} */
- public long getCreationTime() {
+ public long getCreationTime()
+ {
throw new UnsupportedOperationException();
}
-
/** {@inheritDoc} */
- public String getId() {
+ public String getId()
+ {
return this.id;
}
-
/** {@inheritDoc} */
- public long getLastAccessedTime() {
+ public long getLastAccessedTime()
+ {
throw new UnsupportedOperationException();
}
-
/** {@inheritDoc} */
- public int getMaxInactiveInterval() {
+ public int getMaxInactiveInterval()
+ {
throw new UnsupportedOperationException();
}
-
/** {@inheritDoc} */
- public ServletContext getServletContext() {
+ public ServletContext getServletContext()
+ {
return this.servletContext;
}
-
/** {@inheritDoc} */
- public HttpSessionContext getSessionContext() {
+ public HttpSessionContext getSessionContext()
+ {
throw new UnsupportedOperationException();
}
-
/** {@inheritDoc} */
- public Object getValue(String name) {
+ public Object getValue(String name)
+ {
throw new UnsupportedOperationException();
}
-
/** {@inheritDoc} */
- public String[] getValueNames() {
+ public String[] getValueNames()
+ {
throw new UnsupportedOperationException();
}
-
/** {@inheritDoc} */
- public void invalidate() {
-
+ public void invalidate()
+ {
+
assertValidity();
attributes.clear();
invalid = true;
}
-
/** {@inheritDoc} */
- public boolean isNew() {
+ public boolean isNew()
+ {
throw new UnsupportedOperationException();
}
-
/** {@inheritDoc} */
- public void putValue(String name, Object value) {
+ public void putValue(String name, Object value)
+ {
throw new UnsupportedOperationException();
}
-
/** {@inheritDoc} */
- public void removeAttribute(String name) {
+ public void removeAttribute(String name)
+ {
assertValidity();
- if (attributes.containsKey(name)) {
+ if (attributes.containsKey(name))
+ {
Object value = attributes.remove(name);
fireAttributeRemoved(name, value);
}
}
-
/** {@inheritDoc} */
- public void removeValue(String name) {
+ public void removeValue(String name)
+ {
throw new UnsupportedOperationException();
}
-
/** {@inheritDoc} */
- public void setAttribute(String name, Object value) {
+ public void setAttribute(String name, Object value)
+ {
assertValidity();
- if (name == null) {
+ if (name == null)
+ {
throw new IllegalArgumentException("Attribute name cannot be null");
}
- if (value == null) {
+ if (value == null)
+ {
removeAttribute(name);
return;
}
- if (attributes.containsKey(name)) {
+ if (attributes.containsKey(name))
+ {
Object oldValue = attributes.get(name);
attributes.put(name, value);
fireAttributeReplaced(name, oldValue);
- } else {
+ }
+ else
+ {
attributes.put(name, value);
fireAttributeAdded(name, value);
}
}
-
/** {@inheritDoc} */
- public void setMaxInactiveInterval(int interval) {
+ public void setMaxInactiveInterval(int interval)
+ {
throw new UnsupportedOperationException();
}
-
// --------------------------------------------------------- Support Methods
-
/**
* <p>Fire an attribute added event to interested listeners.</p>
*
* @param key Attribute whose value was added
* @param value The new value
*/
- private void fireAttributeAdded(String key, Object value) {
- if (attributeListeners.size() < 1) {
+ private void fireAttributeAdded(String key, Object value)
+ {
+ if (attributeListeners.size() < 1)
+ {
return;
}
- HttpSessionBindingEvent event =
- new HttpSessionBindingEvent(this, key, value);
+ HttpSessionBindingEvent event = new HttpSessionBindingEvent(this, key,
+ value);
Iterator listeners = attributeListeners.iterator();
- while (listeners.hasNext()) {
- HttpSessionAttributeListener listener =
- (HttpSessionAttributeListener) listeners.next();
+ while (listeners.hasNext())
+ {
+ HttpSessionAttributeListener listener = (HttpSessionAttributeListener) listeners
+ .next();
listener.attributeAdded(event);
}
}
-
/**
* <p>Fire an attribute removed event to interested listeners.</p>
*
* @param key Attribute whose value was removed
* @param value The removed value
*/
- private void fireAttributeRemoved(String key, Object value) {
- if (attributeListeners.size() < 1) {
+ private void fireAttributeRemoved(String key, Object value)
+ {
+ if (attributeListeners.size() < 1)
+ {
return;
}
- HttpSessionBindingEvent event =
- new HttpSessionBindingEvent(this, key, value);
+ HttpSessionBindingEvent event = new HttpSessionBindingEvent(this, key,
+ value);
Iterator listeners = attributeListeners.iterator();
- while (listeners.hasNext()) {
- HttpSessionAttributeListener listener =
- (HttpSessionAttributeListener) listeners.next();
+ while (listeners.hasNext())
+ {
+ HttpSessionAttributeListener listener = (HttpSessionAttributeListener) listeners
+ .next();
listener.attributeRemoved(event);
}
}
-
/**
* <p>Fire an attribute replaced event to interested listeners.</p>
*
* @param key Attribute whose value was replaced
* @param value The original value
*/
- private void fireAttributeReplaced(String key, Object value) {
- if (attributeListeners.size() < 1) {
+ private void fireAttributeReplaced(String key, Object value)
+ {
+ if (attributeListeners.size() < 1)
+ {
return;
}
- HttpSessionBindingEvent event =
- new HttpSessionBindingEvent(this, key, value);
+ HttpSessionBindingEvent event = new HttpSessionBindingEvent(this, key,
+ value);
Iterator listeners = attributeListeners.iterator();
- while (listeners.hasNext()) {
- HttpSessionAttributeListener listener =
- (HttpSessionAttributeListener) listeners.next();
+ while (listeners.hasNext())
+ {
+ HttpSessionAttributeListener listener = (HttpSessionAttributeListener) listeners
+ .next();
listener.attributeReplaced(event);
}
}
-
/**
* <p>Throws an {@link IllegalStateException} if this session is invalid.</p>
*/
- private void assertValidity()
+ private void assertValidity()
{
- if (invalid)
+ if (invalid)
{
throw new IllegalStateException("Session is invalid.");
}
diff --git a/test12/src/main/java/org/apache/myfaces/test/mock/MockMethodBinding.java b/test12/src/main/java/org/apache/myfaces/test/mock/MockMethodBinding.java
index f1b777c..b993335 100644
--- a/test12/src/main/java/org/apache/myfaces/test/mock/MockMethodBinding.java
+++ b/test12/src/main/java/org/apache/myfaces/test/mock/MockMethodBinding.java
@@ -43,18 +43,18 @@
* @since 1.0.0
*/
-public class MockMethodBinding extends MethodBinding implements StateHolder {
-
+public class MockMethodBinding extends MethodBinding implements StateHolder
+{
// ------------------------------------------------------------ Constructors
/**
* <p>Construct a default instance.</p>
*/
- public MockMethodBinding() {
+ public MockMethodBinding()
+ {
}
-
/**
* <p>Construct a configured instance.</p>
*
@@ -62,89 +62,101 @@
* @param ref Method binding expression to be parsed
* @param args Signature of this method
*/
- public MockMethodBinding(Application application, String ref,
- Class[] args) {
+ public MockMethodBinding(Application application, String ref, Class[] args)
+ {
this.application = application;
this.args = args;
- if (ref.startsWith("#{") && ref.endsWith("}")) {
+ if (ref.startsWith("#{") && ref.endsWith("}"))
+ {
ref = ref.substring(2, ref.length() - 1);
}
this.ref = ref;
int period = ref.lastIndexOf(".");
- if (period < 0) {
+ if (period < 0)
+ {
throw new ReferenceSyntaxException(ref);
}
vb = application.createValueBinding(ref.substring(0, period));
name = ref.substring(period + 1);
- if (name.length() < 1) {
+ if (name.length() < 1)
+ {
throw new ReferenceSyntaxException(ref);
}
}
-
// ------------------------------------------------------ Instance Variables
-
private Application application;
private Class args[];
private String name;
private String ref;
private ValueBinding vb;
-
// --------------------------------------------------- MethodBinding Methods
-
/** {@inheritDoc} */
public Object invoke(FacesContext context, Object[] params)
- throws EvaluationException, MethodNotFoundException {
+ throws EvaluationException, MethodNotFoundException
+ {
- if (context == null) {
+ if (context == null)
+ {
throw new NullPointerException();
}
Object base = vb.getValue(context);
- if (base == null) {
- throw new EvaluationException("Cannot find object via expression \""
- + vb.getExpressionString() + "\"");
+ if (base == null)
+ {
+ throw new EvaluationException(
+ "Cannot find object via expression \""
+ + vb.getExpressionString() + "\"");
}
Method method = method(base);
- try {
+ try
+ {
return (method.invoke(base, params));
- } catch (IllegalAccessException e) {
+ }
+ catch (IllegalAccessException e)
+ {
throw new EvaluationException(e);
- } catch (InvocationTargetException e) {
+ }
+ catch (InvocationTargetException e)
+ {
throw new EvaluationException(e.getTargetException());
}
}
-
/** {@inheritDoc} */
- public Class getType(FacesContext context) {
+ public Class getType(FacesContext context)
+ {
Object base = vb.getValue(context);
Method method = method(base);
Class returnType = method.getReturnType();
- if ("void".equals(returnType.getName())) {
+ if ("void".equals(returnType.getName()))
+ {
return (null);
- } else {
+ }
+ else
+ {
return (returnType);
}
}
/** {@inheritDoc} */
- public String getExpressionString() {
+ public String getExpressionString()
+ {
return "#{" + ref + "}";
}
// ----------------------------------------------------- StateHolder Methods
-
/** {@inheritDoc} */
- public Object saveState(FacesContext context) {
+ public Object saveState(FacesContext context)
+ {
Object values[] = new Object[4];
values[0] = name;
values[1] = ref;
@@ -153,57 +165,65 @@
return (values);
}
-
/** {@inheritDoc} */
- public void restoreState(FacesContext context, Object state) {
+ public void restoreState(FacesContext context, Object state)
+ {
Object values[] = (Object[]) state;
name = (String) values[0];
ref = (String) values[1];
- vb = (ValueBinding) UIComponentBase.restoreAttachedState(context,
- values[2]);
- args = (Class []) values[3];
+ vb = (ValueBinding) UIComponentBase.restoreAttachedState(context,
+ values[2]);
+ args = (Class[]) values[3];
}
-
/**
* <p>Flag indicating this is a transient instance.</p>
*/
private boolean transientFlag = false;
-
/** {@inheritDoc} */
- public boolean isTransient() {
+ public boolean isTransient()
+ {
return (this.transientFlag);
}
-
/** {@inheritDoc} */
- public void setTransient(boolean transientFlag) {
+ public void setTransient(boolean transientFlag)
+ {
this.transientFlag = transientFlag;
}
/** {@inheritDoc} */
- public int hashCode() {
- if (ref == null) {
+ public int hashCode()
+ {
+ if (ref == null)
+ {
return 0;
- } else {
+ }
+ else
+ {
return ref.hashCode();
}
}
/** {@inheritDoc} */
- public boolean equals(Object otherObj) {
+ public boolean equals(Object otherObj)
+ {
MockMethodBinding other = null;
- if (!(otherObj instanceof MockMethodBinding)) {
+ if (!(otherObj instanceof MockMethodBinding))
+ {
return false;
}
other = (MockMethodBinding) otherObj;
// test object reference equality
- if (this.ref != other.ref) {
+ if (this.ref != other.ref)
+ {
// test object equality
- if (null != this.ref && null != other.ref) {
- if (!this.ref.equals(other.ref)) {
+ if (null != this.ref && null != other.ref)
+ {
+ if (!this.ref.equals(other.ref))
+ {
return false;
}
}
@@ -211,13 +231,18 @@
}
// no need to test name, since it flows from ref.
// test our args array
- if (this.args != other.args) {
- if (this.args.length != other.args.length) {
+ if (this.args != other.args)
+ {
+ if (this.args.length != other.args.length)
+ {
return false;
}
- for (int i = 0, len = this.args.length; i < len; i++) {
- if (this.args[i] != other.args[i]) {
- if (!this.ref.equals(other.ref)) {
+ for (int i = 0, len = this.args.length; i < len; i++)
+ {
+ if (this.args[i] != other.args[i])
+ {
+ if (!this.ref.equals(other.ref))
+ {
return false;
}
}
@@ -226,26 +251,26 @@
return true;
}
-
// --------------------------------------------------------- Private Methods
-
/**
* <p>Return the <code>Method</code> to be called.</p>
*
* @param base Base object from which to extract the method reference
*/
- Method method(Object base) {
+ Method method(Object base)
+ {
Class clazz = base.getClass();
- try {
+ try
+ {
return (clazz.getMethod(name, args));
- } catch (NoSuchMethodException e) {
+ }
+ catch (NoSuchMethodException e)
+ {
throw new MethodNotFoundException(ref + ": " + e.getMessage());
}
}
-
-
}
diff --git a/test12/src/main/java/org/apache/myfaces/test/mock/MockNavigationHandler.java b/test12/src/main/java/org/apache/myfaces/test/mock/MockNavigationHandler.java
index 05e4bb7..93c8d40 100644
--- a/test12/src/main/java/org/apache/myfaces/test/mock/MockNavigationHandler.java
+++ b/test12/src/main/java/org/apache/myfaces/test/mock/MockNavigationHandler.java
@@ -32,47 +32,43 @@
* @since 1.0.0
*/
-public class MockNavigationHandler extends NavigationHandler {
-
+public class MockNavigationHandler extends NavigationHandler
+{
// ------------------------------------------------------------ Constructors
/**
* <p>Construct a default instance.</p>
*/
- public MockNavigationHandler() {
+ public MockNavigationHandler()
+ {
}
-
// ----------------------------------------------------- Mock Object Methods
-
/**
* <p>Add a outcome-viewId pair to the destinations map.</p>
*
* @param outcome Logical outcome string
* @param viewId Destination view identifier
*/
- public void addDestination(String outcome, String viewId) {
+ public void addDestination(String outcome, String viewId)
+ {
destinations.put(outcome, viewId);
}
-
// ------------------------------------------------------ Instance Variables
-
/**
* <p>Set of destination view ids, keyed by logical outcome String
* that will cause navigation to that view id.</p>
*/
private Map destinations = new HashMap();
-
// ----------------------------------------------- NavigationHandler Methods
-
/**
* <p>Process the specified navigation request.</p>
*
@@ -80,32 +76,33 @@
* @param action Action method being executed
* @param outcome Logical outcome from this action method
*/
- public void handleNavigation(FacesContext context,
- String action, String outcome) {
+ public void handleNavigation(FacesContext context, String action,
+ String outcome)
+ {
// Navigate solely based on outcome, if we get a match
String viewId = (String) destinations.get(outcome);
- if (viewId != null) {
- UIViewRoot view = getViewHandler(context).createView(context, viewId);
+ if (viewId != null)
+ {
+ UIViewRoot view = getViewHandler(context).createView(context,
+ viewId);
context.setViewRoot(view);
}
}
-
// --------------------------------------------------------- Private Methods
-
/**
* <p>Return the <code>ViewHandler</code> instance for this application.</p>
*
* @param context <code>FacesContext</code> for the current request
*/
- private ViewHandler getViewHandler(FacesContext context) {
+ private ViewHandler getViewHandler(FacesContext context)
+ {
return context.getApplication().getViewHandler();
}
-
}
diff --git a/test12/src/main/java/org/apache/myfaces/test/mock/MockPortletContext.java b/test12/src/main/java/org/apache/myfaces/test/mock/MockPortletContext.java
index f79555b..abf9cec 100644
--- a/test12/src/main/java/org/apache/myfaces/test/mock/MockPortletContext.java
+++ b/test12/src/main/java/org/apache/myfaces/test/mock/MockPortletContext.java
@@ -36,7 +36,8 @@
* $Id$
* @since 1.0.0
*/
-public class MockPortletContext implements PortletContext {
+public class MockPortletContext implements PortletContext
+{
// ----------------------------------------------------- Mock Object Methods
@@ -47,13 +48,13 @@
* @param name Parameter name
* @param value Parameter value
*/
- public void addInitParameter(String name, String value) {
+ public void addInitParameter(String name, String value)
+ {
parameters.put(name, value);
}
-
/**
* <p>Add a new MIME type mapping to the set of mappings recognized by this
* instance.</p>
@@ -61,20 +62,21 @@
* @param extension Extension to check for (without the period)
* @param contentType Corresponding content type
*/
- public void addMimeType(String extension, String contentType) {
+ public void addMimeType(String extension, String contentType)
+ {
mimeTypes.put(extension, contentType);
}
-
/**
* <p>Set the document root for <code>getRealPath()</code> resolution.
* This parameter <strong>MUST</strong> represent a directory.</p>
*
* @param documentRoot The new base directory
*/
- public void setDocumentRoot(File documentRoot) {
+ public void setDocumentRoot(File documentRoot)
+ {
this.documentRoot = documentRoot;
@@ -87,55 +89,55 @@
private Hashtable mimeTypes = new Hashtable();
private Hashtable parameters = new Hashtable();
-
// -------------------------------------------------- PortletContext Methods
-
/** {@inheritDoc} */
- public Object getAttribute(String name) {
+ public Object getAttribute(String name)
+ {
return attributes.get(name);
}
-
/** {@inheritDoc} */
- public Enumeration getAttributeNames() {
+ public Enumeration getAttributeNames()
+ {
return attributes.keys();
}
-
/** {@inheritDoc} */
- public String getInitParameter(String name) {
+ public String getInitParameter(String name)
+ {
return (String) parameters.get(name);
}
-
/** {@inheritDoc} */
- public Enumeration getInitParameterNames() {
+ public Enumeration getInitParameterNames()
+ {
return parameters.keys();
}
-
/** {@inheritDoc} */
- public int getMajorVersion() {
+ public int getMajorVersion()
+ {
return 1;
}
-
/** {@inheritDoc} */
- public String getMimeType(String path) {
+ public String getMimeType(String path)
+ {
int period = path.lastIndexOf('.');
- if (period < 0) {
+ if (period < 0)
+ {
return null;
}
String extension = path.substring(period + 1);
@@ -143,114 +145,136 @@
}
-
- public int getMinorVersion() {
+ public int getMinorVersion()
+ {
// TODO Auto-generated method stub
return 0;
}
-
- public PortletRequestDispatcher getNamedDispatcher(String arg0) {
+ public PortletRequestDispatcher getNamedDispatcher(String arg0)
+ {
throw new UnsupportedOperationException();
}
-
/** {@inheritDoc} */
- public String getPortletContextName() {
+ public String getPortletContextName()
+ {
return "MockPortletContext";
}
-
/** {@inheritDoc} */
- public String getRealPath(String path) {
+ public String getRealPath(String path)
+ {
- if (documentRoot != null) {
- if (!path.startsWith("/")) {
+ if (documentRoot != null)
+ {
+ if (!path.startsWith("/"))
+ {
throw new IllegalArgumentException("The specified path ('"
+ path + "') does not start with a '/' character");
}
File resolved = new File(documentRoot, path.substring(1));
- try {
+ try
+ {
return resolved.getCanonicalPath();
- } catch (IOException e) {
+ }
+ catch (IOException e)
+ {
return resolved.getAbsolutePath();
}
- } else {
+ }
+ else
+ {
return null;
}
}
-
/** {@inheritDoc} */
- public PortletRequestDispatcher getRequestDispatcher(String arg0) {
+ public PortletRequestDispatcher getRequestDispatcher(String arg0)
+ {
throw new UnsupportedOperationException();
}
-
/** {@inheritDoc} */
- public URL getResource(String path) throws MalformedURLException {
+ public URL getResource(String path) throws MalformedURLException
+ {
- if (documentRoot != null) {
- if (!path.startsWith("/")) {
+ if (documentRoot != null)
+ {
+ if (!path.startsWith("/"))
+ {
throw new MalformedURLException("The specified path ('" + path
+ "') does not start with a '/' character");
}
File resolved = new File(documentRoot, path.substring(1));
- if (resolved.exists()) {
+ if (resolved.exists())
+ {
return resolved.toURL();
- } else {
+ }
+ else
+ {
return null;
}
- } else {
+ }
+ else
+ {
return null;
}
}
-
/** {@inheritDoc} */
- public InputStream getResourceAsStream(String path) {
+ public InputStream getResourceAsStream(String path)
+ {
- try {
+ try
+ {
URL url = getResource(path);
- if (url != null) {
+ if (url != null)
+ {
return url.openStream();
}
- } catch (Exception e) {
+ }
+ catch (Exception e)
+ {
;
}
return null;
}
-
/** {@inheritDoc} */
- public Set getResourcePaths(String path) {
+ public Set getResourcePaths(String path)
+ {
- if (documentRoot == null) {
+ if (documentRoot == null)
+ {
return null;
}
// Enforce the leading slash restriction
- if (!path.startsWith("/")) {
+ if (!path.startsWith("/"))
+ {
throw new IllegalArgumentException("The specified path ('" + path
+ "') does not start with a '/' character");
}
// Locate the File node for this path's directory (if it exists)
File node = new File(documentRoot, path.substring(1));
- if (!node.exists()) {
+ if (!node.exists())
+ {
return null;
}
- if (!node.isDirectory()) {
+ if (!node.isDirectory())
+ {
return null;
}
@@ -258,13 +282,16 @@
// directory
Set set = new HashSet();
String[] files = node.list();
- if (files == null) {
+ if (files == null)
+ {
return null;
}
- for (int i = 0; i < files.length; i++) {
+ for (int i = 0; i < files.length; i++)
+ {
String subfile = path + files[i];
File subnode = new File(node, files[i]);
- if (subnode.isDirectory()) {
+ if (subnode.isDirectory())
+ {
subfile += "/";
}
set.add(subfile);
@@ -275,48 +302,51 @@
}
-
/** {@inheritDoc} */
- public String getServerInfo() {
+ public String getServerInfo()
+ {
return "MockPortletContext";
}
-
/** {@inheritDoc} */
- public void log(String message) {
+ public void log(String message)
+ {
System.out.println(message);
}
-
/** {@inheritDoc} */
- public void log(String message, Throwable exception) {
+ public void log(String message, Throwable exception)
+ {
System.out.println(message);
exception.printStackTrace();
}
-
/** {@inheritDoc} */
- public void removeAttribute(String name) {
+ public void removeAttribute(String name)
+ {
- if (attributes.containsKey(name)) {
+ if (attributes.containsKey(name))
+ {
attributes.remove(name);
}
}
-
/** {@inheritDoc} */
- public void setAttribute(String name, Object value) {
+ public void setAttribute(String name, Object value)
+ {
- if (name == null) {
+ if (name == null)
+ {
throw new IllegalArgumentException("Attribute name cannot be null");
}
- if (value == null) {
+ if (value == null)
+ {
removeAttribute(name);
return;
}
diff --git a/test12/src/main/java/org/apache/myfaces/test/mock/MockPortletRequest.java b/test12/src/main/java/org/apache/myfaces/test/mock/MockPortletRequest.java
index 031fadf..e5b24fe 100644
--- a/test12/src/main/java/org/apache/myfaces/test/mock/MockPortletRequest.java
+++ b/test12/src/main/java/org/apache/myfaces/test/mock/MockPortletRequest.java
@@ -37,25 +37,26 @@
* @since 1.0.0
*/
-public class MockPortletRequest implements PortletRequest {
+public class MockPortletRequest implements PortletRequest
+{
// ------------------------------------------------------------ Constructors
- public MockPortletRequest() {
+ public MockPortletRequest()
+ {
super();
}
-
- public MockPortletRequest(PortletSession session) {
+ public MockPortletRequest(PortletSession session)
+ {
super();
this.session = session;
}
-
// ----------------------------------------------------- Mock Object Methods
/**
@@ -64,10 +65,12 @@
* @param name Parameter name
* @param value Parameter value
*/
- public void addParameter(String name, String value) {
+ public void addParameter(String name, String value)
+ {
String[] values = (String[]) parameters.get(name);
- if (values == null) {
+ if (values == null)
+ {
String[] results = new String[] { value };
parameters.put(name, results);
return;
@@ -79,37 +82,37 @@
}
-
/**
* <p> Set the <code>PortletSession</code> associated with this request.
* </p>
*
* @param session The new session
*/
- public void setPortletSession(PortletSession session) {
+ public void setPortletSession(PortletSession session)
+ {
this.session = session;
}
-
/**
* <p> Set the <code>Locale</code> associated with this request. </p>
*
* @param locale The new locale
*/
- public void setLocale(Locale locale) {
+ public void setLocale(Locale locale)
+ {
this.locale = locale;
}
-
/**
* <p> Set the <code>Principal</code> associated with this request. </p>
*
* @param principal The new Principal
*/
- public void setUserPrincipal(Principal principal) {
+ public void setUserPrincipal(Principal principal)
+ {
this.principal = principal;
@@ -124,294 +127,303 @@
private Principal principal = null;
private PortletSession session = null;
-
// -------------------------------------------------- PortletRequest Methods
-
/** {@inheritDoc} */
- public String getAuthType() {
+ public String getAuthType()
+ {
throw new UnsupportedOperationException();
}
-
/** {@inheritDoc} */
- public String getContextPath() {
+ public String getContextPath()
+ {
return contextPath;
}
-
/** {@inheritDoc} */
- public Object getAttribute(String name) {
+ public Object getAttribute(String name)
+ {
return attributes.get(name);
}
-
/** {@inheritDoc} */
- public Enumeration getAttributeNames() {
+ public Enumeration getAttributeNames()
+ {
return new MockEnumeration(attributes.keySet().iterator());
}
-
/** {@inheritDoc} */
- public Locale getLocale() {
+ public Locale getLocale()
+ {
return locale;
}
-
/** {@inheritDoc} */
- public Enumeration getLocales() {
+ public Enumeration getLocales()
+ {
throw new UnsupportedOperationException();
}
-
/** {@inheritDoc} */
- public String getParameter(String name) {
+ public String getParameter(String name)
+ {
String[] values = (String[]) parameters.get(name);
- if (values != null) {
+ if (values != null)
+ {
return values[0];
- } else {
+ }
+ else
+ {
return null;
}
}
-
/** {@inheritDoc} */
- public Map getParameterMap() {
+ public Map getParameterMap()
+ {
return parameters;
}
-
/** {@inheritDoc} */
- public Enumeration getParameterNames() {
+ public Enumeration getParameterNames()
+ {
return new MockEnumeration(parameters.keySet().iterator());
}
-
/** {@inheritDoc} */
- public String[] getParameterValues(String name) {
+ public String[] getParameterValues(String name)
+ {
return (String[]) parameters.get(name);
}
-
/** {@inheritDoc} */
- public PortalContext getPortalContext() {
+ public PortalContext getPortalContext()
+ {
throw new UnsupportedOperationException();
}
-
/** {@inheritDoc} */
- public PortletMode getPortletMode() {
+ public PortletMode getPortletMode()
+ {
throw new UnsupportedOperationException();
}
-
/** {@inheritDoc} */
- public PortletSession getPortletSession() {
+ public PortletSession getPortletSession()
+ {
return getPortletSession(true);
}
-
/** {@inheritDoc} */
- public PortletSession getPortletSession(boolean create) {
+ public PortletSession getPortletSession(boolean create)
+ {
- if (create && (session == null)) {
+ if (create && (session == null))
+ {
throw new UnsupportedOperationException();
}
return session;
}
-
/** {@inheritDoc} */
- public PortletPreferences getPreferences() {
+ public PortletPreferences getPreferences()
+ {
throw new UnsupportedOperationException();
}
-
/** {@inheritDoc} */
- public Enumeration getProperties(String arg0) {
+ public Enumeration getProperties(String arg0)
+ {
throw new UnsupportedOperationException();
}
-
/** {@inheritDoc} */
- public String getProperty(String arg0) {
+ public String getProperty(String arg0)
+ {
throw new UnsupportedOperationException();
}
-
/** {@inheritDoc} */
- public Enumeration getPropertyNames() {
+ public Enumeration getPropertyNames()
+ {
throw new UnsupportedOperationException();
}
-
/** {@inheritDoc} */
- public String getRemoteUser() {
+ public String getRemoteUser()
+ {
- if (principal != null) {
+ if (principal != null)
+ {
return principal.getName();
- } else {
+ }
+ else
+ {
return null;
}
}
-
/** {@inheritDoc} */
- public String getRequestedSessionId() {
+ public String getRequestedSessionId()
+ {
throw new UnsupportedOperationException();
}
-
/** {@inheritDoc} */
- public String getResponseContentType() {
+ public String getResponseContentType()
+ {
throw new UnsupportedOperationException();
}
-
/** {@inheritDoc} */
- public Enumeration getResponseContentTypes() {
+ public Enumeration getResponseContentTypes()
+ {
throw new UnsupportedOperationException();
}
-
/** {@inheritDoc} */
- public String getScheme() {
+ public String getScheme()
+ {
return ("http");
}
-
/** {@inheritDoc} */
- public String getServerName() {
+ public String getServerName()
+ {
return ("localhost");
}
-
/** {@inheritDoc} */
- public int getServerPort() {
+ public int getServerPort()
+ {
return (8080);
}
-
/** {@inheritDoc} */
- public Principal getUserPrincipal() {
+ public Principal getUserPrincipal()
+ {
return principal;
}
-
/** {@inheritDoc} */
- public WindowState getWindowState() {
+ public WindowState getWindowState()
+ {
throw new UnsupportedOperationException();
}
-
/** {@inheritDoc} */
- public boolean isPortletModeAllowed(PortletMode arg0) {
+ public boolean isPortletModeAllowed(PortletMode arg0)
+ {
throw new UnsupportedOperationException();
}
-
/** {@inheritDoc} */
- public boolean isRequestedSessionIdValid() {
+ public boolean isRequestedSessionIdValid()
+ {
throw new UnsupportedOperationException();
}
-
/** {@inheritDoc} */
- public boolean isSecure() {
+ public boolean isSecure()
+ {
return false;
}
-
/** {@inheritDoc} */
- public boolean isUserInRole(String arg0) {
+ public boolean isUserInRole(String arg0)
+ {
throw new UnsupportedOperationException();
}
-
/** {@inheritDoc} */
- public boolean isWindowStateAllowed(WindowState arg0) {
+ public boolean isWindowStateAllowed(WindowState arg0)
+ {
throw new UnsupportedOperationException();
}
-
/** {@inheritDoc} */
- public void removeAttribute(String name) {
+ public void removeAttribute(String name)
+ {
- if (attributes.containsKey(name)) {
+ if (attributes.containsKey(name))
+ {
attributes.remove(name);
}
}
-
/** {@inheritDoc} */
- public void setAttribute(String name, Object value) {
+ public void setAttribute(String name, Object value)
+ {
- if (name == null) {
+ if (name == null)
+ {
throw new IllegalArgumentException("Attribute name cannot be null");
}
- if (value == null) {
+ if (value == null)
+ {
removeAttribute(name);
return;
}
diff --git a/test12/src/main/java/org/apache/myfaces/test/mock/MockPortletResponse.java b/test12/src/main/java/org/apache/myfaces/test/mock/MockPortletResponse.java
index 5bed9bd..40be633 100644
--- a/test12/src/main/java/org/apache/myfaces/test/mock/MockPortletResponse.java
+++ b/test12/src/main/java/org/apache/myfaces/test/mock/MockPortletResponse.java
@@ -26,35 +26,37 @@
* @since 1.0.0
*/
-public class MockPortletResponse implements PortletResponse {
+public class MockPortletResponse implements PortletResponse
+{
/**
* <p>Return a default instance.</p>
*/
- public MockPortletResponse() {
+ public MockPortletResponse()
+ {
}
-
// -------------------------------------------------- PortletContext Methods
/** {@inheritDoc} */
- public void addProperty(String name, String value) {
+ public void addProperty(String name, String value)
+ {
throw new UnsupportedOperationException();
}
-
/** {@inheritDoc} */
- public String encodeURL(String url) {
+ public String encodeURL(String url)
+ {
return url;
}
-
/** {@inheritDoc} */
- public void setProperty(String name, String value) {
+ public void setProperty(String name, String value)
+ {
throw new UnsupportedOperationException();
diff --git a/test12/src/main/java/org/apache/myfaces/test/mock/MockPortletSession.java b/test12/src/main/java/org/apache/myfaces/test/mock/MockPortletSession.java
index 6181586..139971c 100644
--- a/test12/src/main/java/org/apache/myfaces/test/mock/MockPortletSession.java
+++ b/test12/src/main/java/org/apache/myfaces/test/mock/MockPortletSession.java
@@ -30,34 +30,35 @@
* $Id$
* @since 1.0.0
*/
-public class MockPortletSession implements PortletSession {
+public class MockPortletSession implements PortletSession
+{
// ------------------------------------------------------------ Constructors
/**
* <p> Configure a default instance. </p>
*/
- public MockPortletSession() {
+ public MockPortletSession()
+ {
super();
}
-
/**
* <p> Configure a session instance associated with the specified servlet
* context. </p>
*
* @param servletContext The associated servlet context
*/
- public MockPortletSession(PortletContext portletContext) {
+ public MockPortletSession(PortletContext portletContext)
+ {
super();
this.portletContext = portletContext;
}
-
// ----------------------------------------------------- Mock Object Methods
/**
@@ -66,7 +67,8 @@
*
* @param servletContext The associated servlet context
*/
- public void setPortletContext(PortletContext portletContext) {
+ public void setPortletContext(PortletContext portletContext)
+ {
this.portletContext = portletContext;
@@ -79,7 +81,6 @@
private String id = "123";
private PortletContext portletContext = null;
-
// ---------------------------------------------------------- Public Methods
/**
@@ -87,30 +88,33 @@
*
* @param id The new session identifier
*/
- public void setId(String id) {
+ public void setId(String id)
+ {
this.id = id;
}
-
// -------------------------------------------------- PortletSession Methods
-
/** {@inheritDoc} */
- public Object getAttribute(String name) {
+ public Object getAttribute(String name)
+ {
return getAttribute(name, PORTLET_SCOPE);
}
-
/** {@inheritDoc} */
- public Object getAttribute(String name, int scope) {
+ public Object getAttribute(String name, int scope)
+ {
- if (scope == PORTLET_SCOPE) {
+ if (scope == PORTLET_SCOPE)
+ {
return portletAttributes.get(name);
- } else if (scope == APPLICATION_SCOPE) {
+ }
+ else if (scope == APPLICATION_SCOPE)
+ {
return applicationAttributes.get(name);
}
@@ -119,21 +123,24 @@
}
-
/** {@inheritDoc} */
- public Enumeration getAttributeNames() {
+ public Enumeration getAttributeNames()
+ {
return getAttributeNames(PORTLET_SCOPE);
}
-
/** {@inheritDoc} */
- public Enumeration getAttributeNames(int scope) {
+ public Enumeration getAttributeNames(int scope)
+ {
- if (scope == PORTLET_SCOPE) {
+ if (scope == PORTLET_SCOPE)
+ {
return new MockEnumeration(portletAttributes.keySet().iterator());
- } else if (scope == APPLICATION_SCOPE) {
+ }
+ else if (scope == APPLICATION_SCOPE)
+ {
return new MockEnumeration(applicationAttributes.keySet()
.iterator());
}
@@ -143,114 +150,127 @@
}
-
/** {@inheritDoc} */
- public long getCreationTime() {
+ public long getCreationTime()
+ {
throw new UnsupportedOperationException();
}
-
/** {@inheritDoc} */
- public String getId() {
+ public String getId()
+ {
return this.id;
}
-
/** {@inheritDoc} */
- public long getLastAccessedTime() {
+ public long getLastAccessedTime()
+ {
throw new UnsupportedOperationException();
}
-
/** {@inheritDoc} */
- public int getMaxInactiveInterval() {
+ public int getMaxInactiveInterval()
+ {
throw new UnsupportedOperationException();
}
-
/** {@inheritDoc} */
- public PortletContext getPortletContext() {
+ public PortletContext getPortletContext()
+ {
return portletContext;
}
-
/** {@inheritDoc} */
- public void invalidate() {
+ public void invalidate()
+ {
throw new UnsupportedOperationException();
}
-
/** {@inheritDoc} */
- public boolean isNew() {
+ public boolean isNew()
+ {
throw new UnsupportedOperationException();
}
-
/** {@inheritDoc} */
- public void removeAttribute(String name) {
+ public void removeAttribute(String name)
+ {
removeAttribute(name, PORTLET_SCOPE);
}
-
/** {@inheritDoc} */
- public void removeAttribute(String name, int scope) {
+ public void removeAttribute(String name, int scope)
+ {
Map attributes;
- if (scope == PORTLET_SCOPE) {
+ if (scope == PORTLET_SCOPE)
+ {
attributes = portletAttributes;
- } else if (scope == APPLICATION_SCOPE) {
+ }
+ else if (scope == APPLICATION_SCOPE)
+ {
attributes = applicationAttributes;
- } else {
+ }
+ else
+ {
throw new IllegalArgumentException("Scope constant " + scope
+ " not recognized");
}
- if (attributes.containsKey(name)) {
+ if (attributes.containsKey(name))
+ {
attributes.remove(name);
}
}
-
/** {@inheritDoc} */
- public void setAttribute(String name, Object value) {
+ public void setAttribute(String name, Object value)
+ {
setAttribute(name, value, PORTLET_SCOPE);
}
-
/** {@inheritDoc} */
- public void setAttribute(String name, Object value, int scope) {
+ public void setAttribute(String name, Object value, int scope)
+ {
- if (name == null) {
+ if (name == null)
+ {
throw new IllegalArgumentException("Attribute name cannot be null");
}
- if (value == null) {
+ if (value == null)
+ {
removeAttribute(name, scope);
return;
}
Map attributes;
- if (scope == PORTLET_SCOPE) {
+ if (scope == PORTLET_SCOPE)
+ {
attributes = portletAttributes;
- } else if (scope == APPLICATION_SCOPE) {
+ }
+ else if (scope == APPLICATION_SCOPE)
+ {
attributes = applicationAttributes;
- } else {
+ }
+ else
+ {
throw new IllegalArgumentException("Scope constant " + scope
+ " not recognized");
}
@@ -258,9 +278,9 @@
}
-
/** {@inheritDoc} */
- public void setMaxInactiveInterval(int arg0) {
+ public void setMaxInactiveInterval(int arg0)
+ {
throw new UnsupportedOperationException();
diff --git a/test12/src/main/java/org/apache/myfaces/test/mock/MockPrincipal.java b/test12/src/main/java/org/apache/myfaces/test/mock/MockPrincipal.java
index 5544908..6a2d672 100644
--- a/test12/src/main/java/org/apache/myfaces/test/mock/MockPrincipal.java
+++ b/test12/src/main/java/org/apache/myfaces/test/mock/MockPrincipal.java
@@ -24,59 +24,54 @@
*
* @since 1.0.0
*/
-public class MockPrincipal implements Principal {
-
+public class MockPrincipal implements Principal
+{
// ------------------------------------------------------------ Constructors
-
/**
* <p>Construct a default Principal instance.</p>
*/
- public MockPrincipal() {
+ public MockPrincipal()
+ {
this(null);
}
-
/**
* <p>Construct a Principal with the specified name.</p>
*
* @param name Name for this Principal
*/
- public MockPrincipal(String name) {
+ public MockPrincipal(String name)
+ {
this.name = name;
}
-
// ------------------------------------------------------ Instance Variables
-
/**
* <p>The name for this Principal intance.</p>
*/
private String name = null;
-
// ----------------------------------------------------- Mock Object Methods
-
/**
* <p>Set the name for this Principal.</p>
*
* @param name The new name
*/
- public void setName(String name) {
+ public void setName(String name)
+ {
this.name = name;
}
-
// ------------------------------------------------------- Principal Methods
-
/** {@inheritDoc} */
- public String getName() {
+ public String getName()
+ {
return this.name;
}
-
}
diff --git a/test12/src/main/java/org/apache/myfaces/test/mock/MockPrintWriter.java b/test12/src/main/java/org/apache/myfaces/test/mock/MockPrintWriter.java
index a6019a4..0803698 100644
--- a/test12/src/main/java/org/apache/myfaces/test/mock/MockPrintWriter.java
+++ b/test12/src/main/java/org/apache/myfaces/test/mock/MockPrintWriter.java
@@ -20,7 +20,6 @@
import java.io.CharArrayWriter;
import java.io.PrintWriter;
-
/**
* <p>Mock implementation of <code>PrintWriter</code>.</p>
*
@@ -28,62 +27,56 @@
* @since 1.0.0
*/
-public class MockPrintWriter extends PrintWriter {
-
+public class MockPrintWriter extends PrintWriter
+{
// ------------------------------------------------------------ Constructors
-
/**
* <p>Return a default instance.</p>
*
* @param writer Temporary buffer storage for us to use
*/
- public MockPrintWriter(CharArrayWriter writer) {
+ public MockPrintWriter(CharArrayWriter writer)
+ {
super(writer);
this.caw = writer;
}
-
// ----------------------------------------------------- Mock Object Methods
-
/**
* <p>Return the content that has been written to this writer.</p>
*/
- public char[] content() {
+ public char[] content()
+ {
return caw.toCharArray();
}
-
/**
* <p>Reset this output stream so that it appears no content has been
* written.</p>
*/
- public void reset() {
+ public void reset()
+ {
caw.reset();
}
-
/**
* <p>Return the number of characters that have been written to this writer.</p>
*/
- public int size() {
+ public int size()
+ {
return caw.size();
}
-
-
// ------------------------------------------------------ Instance Variables
-
/**
* <p>The writer we will use for buffering.</p>
*/
private CharArrayWriter caw = null;
-
// ----------------------------------------------------- PrintWriter Methods
-
}
diff --git a/test12/src/main/java/org/apache/myfaces/test/mock/MockPropertyResolver.java b/test12/src/main/java/org/apache/myfaces/test/mock/MockPropertyResolver.java
index 5a86b55..6885358 100644
--- a/test12/src/main/java/org/apache/myfaces/test/mock/MockPropertyResolver.java
+++ b/test12/src/main/java/org/apache/myfaces/test/mock/MockPropertyResolver.java
@@ -34,101 +34,114 @@
* @since 1.0.0
*/
-public class MockPropertyResolver extends PropertyResolver {
-
+public class MockPropertyResolver extends PropertyResolver
+{
// ------------------------------------------------------------ Constructors
-
/**
* <p>Construct a default instance.</p>
*/
- public MockPropertyResolver() {
+ public MockPropertyResolver()
+ {
}
-
// ----------------------------------------------------- Mock Object Methods
-
// ------------------------------------------------------ Instance Variables
-
// ------------------------------------------------ PropertyResolver Methods
-
/** {@inheritDoc} */
public Object getValue(Object base, Object property)
- throws EvaluationException, PropertyNotFoundException {
+ throws EvaluationException, PropertyNotFoundException
+ {
- if (base == null) {
+ if (base == null)
+ {
throw new NullPointerException();
}
- if (base instanceof Map) {
+ if (base instanceof Map)
+ {
return ((Map) base).get(property);
}
String name = property.toString();
PropertyDescriptor descriptor = descriptor(base.getClass(), name);
- try {
+ try
+ {
return descriptor.getReadMethod().invoke(base, (Object[]) null);
- } catch (IllegalAccessException e) {
+ }
+ catch (IllegalAccessException e)
+ {
throw new EvaluationException(e);
- } catch (InvocationTargetException e) {
+ }
+ catch (InvocationTargetException e)
+ {
throw new EvaluationException(e.getTargetException());
}
}
-
/** {@inheritDoc} */
public Object getValue(Object base, int index)
- throws PropertyNotFoundException {
+ throws PropertyNotFoundException
+ {
return getValue(base, "" + index);
}
-
/** {@inheritDoc} */
public void setValue(Object base, Object property, Object value)
- throws PropertyNotFoundException {
+ throws PropertyNotFoundException
+ {
- if (base == null) {
+ if (base == null)
+ {
throw new NullPointerException();
}
- if (base instanceof Map) {
+ if (base instanceof Map)
+ {
((Map) base).put(property, value);
return;
}
String name = property.toString();
PropertyDescriptor descriptor = descriptor(base.getClass(), name);
- try {
+ try
+ {
descriptor.getWriteMethod().invoke(base, new Object[] { value });
- } catch (IllegalAccessException e) {
+ }
+ catch (IllegalAccessException e)
+ {
throw new EvaluationException(e);
- } catch (InvocationTargetException e) {
+ }
+ catch (InvocationTargetException e)
+ {
throw new EvaluationException(e.getTargetException());
}
}
-
/** {@inheritDoc} */
public void setValue(Object base, int index, Object value)
- throws PropertyNotFoundException {
+ throws PropertyNotFoundException
+ {
setValue(base, "" + index, value);
}
-
/** {@inheritDoc} */
public boolean isReadOnly(Object base, Object property)
- throws PropertyNotFoundException {
+ throws PropertyNotFoundException
+ {
- if (base == null) {
+ if (base == null)
+ {
throw new NullPointerException();
}
- if (base instanceof Map) {
+ if (base instanceof Map)
+ {
return false; // We have no way to know anything more specific
}
String name = property.toString();
@@ -137,28 +150,33 @@
}
-
/** {@inheritDoc} */
public boolean isReadOnly(Object base, int index)
- throws PropertyNotFoundException {
+ throws PropertyNotFoundException
+ {
return isReadOnly(base, "" + index);
}
-
/** {@inheritDoc} */
public Class getType(Object base, Object property)
- throws PropertyNotFoundException {
+ throws PropertyNotFoundException
+ {
- if (base == null) {
+ if (base == null)
+ {
throw new NullPointerException();
}
- if (base instanceof Map) {
+ if (base instanceof Map)
+ {
Object value = ((Map) base).get(property);
- if (value != null) {
+ if (value != null)
+ {
return value.getClass();
- } else {
+ }
+ else
+ {
return Object.class;
}
}
@@ -168,19 +186,17 @@
}
-
/** {@inheritDoc} */
public Class getType(Object base, int index)
- throws PropertyNotFoundException {
+ throws PropertyNotFoundException
+ {
return getType(base, "" + index);
}
-
// --------------------------------------------------------- Private Methods
-
/**
* <p>Return the <code>PropertyDescriptor</code> for the specified
* property of the specified class.</p>
@@ -193,20 +209,28 @@
* @exception PropertyNotFoundException if the specified property does
* not exist on the specified class
*/
- private PropertyDescriptor descriptor(Class clazz, String name) {
+ private PropertyDescriptor descriptor(Class clazz, String name)
+ {
- System.err.println("descriptor(class=" + clazz.getName() + ", name=" + name);
+ System.err.println("descriptor(class=" + clazz.getName() + ", name="
+ + name);
BeanInfo info = null;
- try {
+ try
+ {
info = Introspector.getBeanInfo(clazz);
System.err.println(" Found BeanInfo " + info);
- } catch (IntrospectionException e) {
+ }
+ catch (IntrospectionException e)
+ {
throw new EvaluationException(e);
}
PropertyDescriptor[] descriptors = info.getPropertyDescriptors();
- for (int i = 0; i < descriptors.length; i++) {
- if (name.equals(descriptors[i].getName())) {
- System.err.print(" Found PropertyDescriptor " + descriptors[i]);
+ for (int i = 0; i < descriptors.length; i++)
+ {
+ if (name.equals(descriptors[i].getName()))
+ {
+ System.err
+ .print(" Found PropertyDescriptor " + descriptors[i]);
return descriptors[i];
}
}
@@ -215,5 +239,4 @@
}
-
}
diff --git a/test12/src/main/java/org/apache/myfaces/test/mock/MockRenderKitFactory.java b/test12/src/main/java/org/apache/myfaces/test/mock/MockRenderKitFactory.java
index c1daa90..42c36c6 100644
--- a/test12/src/main/java/org/apache/myfaces/test/mock/MockRenderKitFactory.java
+++ b/test12/src/main/java/org/apache/myfaces/test/mock/MockRenderKitFactory.java
@@ -32,69 +32,70 @@
* @since 1.0.0
*/
-public class MockRenderKitFactory extends RenderKitFactory {
-
+public class MockRenderKitFactory extends RenderKitFactory
+{
// ------------------------------------------------------------ Constructors
-
/**
* <p>Return a default instance.</p>
*/
- public MockRenderKitFactory() {
+ public MockRenderKitFactory()
+ {
renderKits = new HashMap();
}
-
// ----------------------------------------------------- Mock Object Methods
-
// ------------------------------------------------------ Instance Variables
-
/**
* <p>The set of render kits that have been registered here.</p>
*/
private Map renderKits = new HashMap();
-
// ------------------------------------------------ RenderKitFactory Methods
-
/** {@inheritDoc} */
- public void addRenderKit(String renderKitId, RenderKit renderKit) {
+ public void addRenderKit(String renderKitId, RenderKit renderKit)
+ {
- if ((renderKitId == null) || (renderKit == null)) {
+ if ((renderKitId == null) || (renderKit == null))
+ {
throw new NullPointerException();
}
- if (renderKits.containsKey(renderKitId)) {
+ if (renderKits.containsKey(renderKitId))
+ {
throw new IllegalArgumentException(renderKitId);
}
renderKits.put(renderKitId, renderKit);
}
-
/** {@inheritDoc} */
- public RenderKit getRenderKit(FacesContext context, String renderKitId) {
+ public RenderKit getRenderKit(FacesContext context, String renderKitId)
+ {
- if (renderKitId == null) {
+ if (renderKitId == null)
+ {
throw new NullPointerException();
}
RenderKit renderKit = (RenderKit) renderKits.get(renderKitId);
- if (renderKit == null) {
+ if (renderKit == null)
+ {
// Issue 38294 -- We removed the automatic creation of the
// default renderkit in the constructor, allowing it to be
// added by AbstractJsfTestCase in the usual case. To preserve
// backwards compatibility, however, create one on the fly
// if the user asks for the default HTML renderkit and it has
// not been manually added yet
- if (RenderKitFactory.HTML_BASIC_RENDER_KIT.equals(renderKitId)) {
+ if (RenderKitFactory.HTML_BASIC_RENDER_KIT.equals(renderKitId))
+ {
renderKit = new MockRenderKit();
renderKits.put(RenderKitFactory.HTML_BASIC_RENDER_KIT,
- renderKit);
+ renderKit);
return renderKit;
}
throw new IllegalArgumentException(renderKitId);
@@ -103,13 +104,12 @@
}
-
/** {@inheritDoc} */
- public Iterator getRenderKitIds() {
+ public Iterator getRenderKitIds()
+ {
return renderKits.keySet().iterator();
}
-
}
diff --git a/test12/src/main/java/org/apache/myfaces/test/mock/MockResponseStateManager.java b/test12/src/main/java/org/apache/myfaces/test/mock/MockResponseStateManager.java
index 29ea726..8e16540 100644
--- a/test12/src/main/java/org/apache/myfaces/test/mock/MockResponseStateManager.java
+++ b/test12/src/main/java/org/apache/myfaces/test/mock/MockResponseStateManager.java
@@ -24,17 +24,16 @@
// ------------------------------------------------------------ Constructors
// ------------------------------------------------------ Instance Variables
-
+
private static final int TREE_PARAM = 0;
private static final int STATE_PARAM = 1;
private static final int VIEWID_PARAM = 2;
private static final String ZIP_CHARSET = "ISO-8859-1";
-
// ----------------------------------------------------- Mock Object Methods
// -------------------------------------------------- ResponseStateManager Methods
-
+
public Object getState(FacesContext facesContext, String viewId)
{
Object[] savedState = getSavedState(facesContext);
@@ -46,7 +45,8 @@
return new Object[] { savedState[TREE_PARAM], savedState[STATE_PARAM] };
}
- public Object getTreeStructureToRestore(FacesContext facesContext, String viewId)
+ public Object getTreeStructureToRestore(FacesContext facesContext,
+ String viewId)
{
// Although this method won't be called anymore,
// it has been kept for backward compatibility.
@@ -74,17 +74,19 @@
public boolean isPostback(FacesContext context)
{
- return context.getExternalContext().getRequestParameterMap().containsKey(ResponseStateManager.VIEW_STATE_PARAM);
+ return context.getExternalContext().getRequestParameterMap()
+ .containsKey(ResponseStateManager.VIEW_STATE_PARAM);
}
- public void writeState(FacesContext facescontext, SerializedView serializedview)
- throws IOException
+ public void writeState(FacesContext facescontext,
+ SerializedView serializedview) throws IOException
{
ResponseWriter responseWriter = facescontext.getResponseWriter();
Object[] savedState = new Object[3];
- if (facescontext.getApplication().getStateManager().isSavingStateInClient(facescontext))
+ if (facescontext.getApplication().getStateManager()
+ .isSavingStateInClient(facescontext))
{
Object treeStruct = serializedview.getStructure();
Object compStates = serializedview.getState();
@@ -121,10 +123,11 @@
writeRenderKitIdField(facescontext, responseWriter);
}
- private void writeViewStateField(FacesContext facesContext, ResponseWriter responseWriter, Object savedState)
- throws IOException
+ private void writeViewStateField(FacesContext facesContext,
+ ResponseWriter responseWriter, Object savedState)
+ throws IOException
{
-
+
String serializedState = construct(facesContext, savedState);
responseWriter.startElement("input", null);
responseWriter.writeAttribute("type", "hidden", null);
@@ -132,23 +135,28 @@
responseWriter.writeAttribute("value", serializedState, null);
responseWriter.endElement("input");
}
-
- private void writeRenderKitIdField(FacesContext facesContext, ResponseWriter responseWriter) throws IOException
+ private void writeRenderKitIdField(FacesContext facesContext,
+ ResponseWriter responseWriter) throws IOException
{
-
- String defaultRenderKitId = facesContext.getApplication().getDefaultRenderKitId();
- if (defaultRenderKitId != null && !RenderKitFactory.HTML_BASIC_RENDER_KIT.equals(defaultRenderKitId))
+
+ String defaultRenderKitId = facesContext.getApplication()
+ .getDefaultRenderKitId();
+ if (defaultRenderKitId != null
+ && !RenderKitFactory.HTML_BASIC_RENDER_KIT
+ .equals(defaultRenderKitId))
{
responseWriter.startElement("input", null);
responseWriter.writeAttribute("type", "hidden", null);
- responseWriter.writeAttribute("name", ResponseStateManager.RENDER_KIT_ID_PARAM, null);
+ responseWriter.writeAttribute("name",
+ ResponseStateManager.RENDER_KIT_ID_PARAM, null);
responseWriter.writeAttribute("value", defaultRenderKitId, null);
responseWriter.endElement("input");
}
}
-
- private String construct(FacesContext facesContext, Object savedState) throws IOException
+
+ private String construct(FacesContext facesContext, Object savedState)
+ throws IOException
{
byte[] bytes = null;
ByteArrayOutputStream baos = null;
@@ -168,7 +176,7 @@
{
oos.close();
}
- catch(IOException e)
+ catch (IOException e)
{
}
finally
@@ -182,7 +190,7 @@
{
baos.close();
}
- catch(IOException e)
+ catch (IOException e)
{
}
finally
@@ -193,19 +201,20 @@
}
return new String(new _Hex().encode(bytes), ZIP_CHARSET);
}
-
- private Object reconstruct(FacesContext facesContext, String encodedState) throws IOException
+
+ private Object reconstruct(FacesContext facesContext, String encodedState)
+ throws IOException
{
byte[] bytes = encodedState.getBytes(ZIP_CHARSET);
-
+
ByteArrayInputStream input = null;
ObjectInputStream s = null;
Object object = null;
-
+
try
{
input = new ByteArrayInputStream(bytes);
- s = new ObjectInputStream(input);
+ s = new ObjectInputStream(input);
object = s.readObject();
}
catch (ClassNotFoundException e)
@@ -220,7 +229,7 @@
{
s.close();
}
- catch(IOException e)
+ catch (IOException e)
{
}
finally
@@ -234,7 +243,7 @@
{
input.close();
}
- catch(IOException e)
+ catch (IOException e)
{
}
finally
@@ -246,31 +255,34 @@
return object;
}
- private Object[] getSavedState(FacesContext facesContext) {
- Object encodedState =
- facesContext.getExternalContext().
- getRequestParameterMap().get(VIEW_STATE_PARAM);
- if(encodedState==null || (((String) encodedState).length() == 0)) {
+ private Object[] getSavedState(FacesContext facesContext)
+ {
+ Object encodedState = facesContext.getExternalContext()
+ .getRequestParameterMap().get(VIEW_STATE_PARAM);
+ if (encodedState == null || (((String) encodedState).length() == 0))
+ {
return null;
}
Object[] savedState = null;
-
+
try
{
- savedState = (Object[])reconstruct(facesContext, (String)encodedState);
+ savedState = (Object[]) reconstruct(facesContext,
+ (String) encodedState);
}
- catch(IOException e)
+ catch (IOException e)
{
- facesContext.getExternalContext().log("Cannot reconstruct view state", e);
+ facesContext.getExternalContext().log(
+ "Cannot reconstruct view state", e);
}
if (savedState == null)
{
return null;
}
-
- String restoredViewId = (String)savedState[VIEWID_PARAM];
+
+ String restoredViewId = (String) savedState[VIEWID_PARAM];
if (restoredViewId == null)
{
diff --git a/test12/src/main/java/org/apache/myfaces/test/mock/MockResponseWriter.java b/test12/src/main/java/org/apache/myfaces/test/mock/MockResponseWriter.java
index ec98b15..8602717 100644
--- a/test12/src/main/java/org/apache/myfaces/test/mock/MockResponseWriter.java
+++ b/test12/src/main/java/org/apache/myfaces/test/mock/MockResponseWriter.java
@@ -27,17 +27,18 @@
*
* @since 1.0.0
*/
-public class MockResponseWriter extends ResponseWriter {
-
+public class MockResponseWriter extends ResponseWriter
+{
// ------------------------------------------------------------ Constructors
- public MockResponseWriter(Writer writer) {
+ public MockResponseWriter(Writer writer)
+ {
this.writer = writer;
this.contentType = "text/html";
this.characterEncoding = "UTF-8";
}
-
+
/**
* <p>Construct an instance wrapping the specified writer.</p>
*
@@ -45,56 +46,57 @@
* @param contentType Content type to be created
* @param characterEncoding Character encoding of this response
*/
- public MockResponseWriter(Writer writer, String contentType, String characterEncoding) {
+ public MockResponseWriter(Writer writer, String contentType,
+ String characterEncoding)
+ {
this.writer = writer;
this.contentType = contentType;
this.characterEncoding = characterEncoding;
}
-
// ------------------------------------------------------ Instance Variables
-
private String characterEncoding = null;
private String contentType = "text/html";
private boolean open = false; // Is an element currently open?
private UIComponent component;
private Writer writer = null;
-
// ----------------------------------------------------- Mock Object Methods
-
/**
* <p>Return the <code>Writer</code> that we are wrapping.</p>
*/
- public Writer getWriter() {
+ public Writer getWriter()
+ {
return this.writer;
}
-
// -------------------------------------------------- ResponseWriter Methods
-
/** {@inheritDoc} */
- public ResponseWriter cloneWithWriter(Writer writer) {
+ public ResponseWriter cloneWithWriter(Writer writer)
+ {
return new MockResponseWriter(writer, contentType, characterEncoding);
}
-
/** {@inheritDoc} */
- public void endDocument() throws IOException {
+ public void endDocument() throws IOException
+ {
finish();
writer.flush();
}
-
/** {@inheritDoc} */
- public void endElement(String name) throws IOException {
- if (open) {
+ public void endElement(String name) throws IOException
+ {
+ if (open)
+ {
writer.write("/");
finish();
- } else {
+ }
+ else
+ {
writer.write("</");
writer.write(name);
writer.write(">");
@@ -102,34 +104,36 @@
component = null;
}
-
/** {@inheritDoc} */
- public String getCharacterEncoding() {
+ public String getCharacterEncoding()
+ {
return this.characterEncoding;
}
-
/** {@inheritDoc} */
- public String getContentType() {
+ public String getContentType()
+ {
return this.contentType;
}
-
/** {@inheritDoc} */
- public void flush() throws IOException {
+ public void flush() throws IOException
+ {
finish();
}
-
/** {@inheritDoc} */
- public void startDocument() throws IOException {
+ public void startDocument() throws IOException
+ {
// Do nothing
}
-
/** {@inheritDoc} */
- public void startElement(String name, UIComponent component) throws IOException {
- if (name == null) {
+ public void startElement(String name, UIComponent component)
+ throws IOException
+ {
+ if (name == null)
+ {
throw new NullPointerException();
}
finish();
@@ -139,110 +143,124 @@
this.component = component;
}
-
/** {@inheritDoc} */
- public void writeAttribute(String name, Object value, String property) throws IOException {
- if (name == null) {
+ public void writeAttribute(String name, Object value, String property)
+ throws IOException
+ {
+ if (name == null)
+ {
throw new NullPointerException();
}
- if (!open) {
+ if (!open)
+ {
throw new IllegalStateException();
}
String attribute = findValue(value, property);
- if (attribute != null) {
- writer.write(" ");
- writer.write(name);
- writer.write("=\"");
- string(attribute);
+ if (attribute != null)
+ {
+ writer.write(" ");
+ writer.write(name);
+ writer.write("=\"");
+ string(attribute);
- writer.write("\"");
+ writer.write("\"");
}
}
-
/** {@inheritDoc} */
- public void writeComment(Object comment) throws IOException {
- if (comment == null) {
+ public void writeComment(Object comment) throws IOException
+ {
+ if (comment == null)
+ {
throw new NullPointerException();
}
finish();
writer.write("<!-- ");
- if (comment instanceof String) {
+ if (comment instanceof String)
+ {
writer.write((String) comment);
- } else {
+ }
+ else
+ {
writer.write(comment.toString());
}
writer.write(" -->");
}
-
/** {@inheritDoc} */
- public void writeText(Object text, String property) throws IOException {
- if (text == null) {
+ public void writeText(Object text, String property) throws IOException
+ {
+ if (text == null)
+ {
throw new NullPointerException();
}
finish();
String value = findValue(text, property);
- if (value != null) {
- string(value);
+ if (value != null)
+ {
+ string(value);
}
}
-
/** {@inheritDoc} */
- public void writeText(char[] text, int off, int len) throws IOException {
- if (text == null) {
+ public void writeText(char[] text, int off, int len) throws IOException
+ {
+ if (text == null)
+ {
throw new NullPointerException();
}
- if ((off < 0) || (off > text.length) || (len < 0) || (len > text.length)) {
+ if ((off < 0) || (off > text.length) || (len < 0)
+ || (len > text.length))
+ {
throw new IndexOutOfBoundsException();
}
finish();
string(text, off, len);
}
-
/** {@inheritDoc} */
- public void writeURIAttribute(String name, Object value, String property) throws IOException {
- if (name == null) {
+ public void writeURIAttribute(String name, Object value, String property)
+ throws IOException
+ {
+ if (name == null)
+ {
throw new NullPointerException();
}
- if (!open) {
+ if (!open)
+ {
throw new IllegalStateException();
}
String attribute = findValue(value, property);
- if (attribute != null) {
- writer.write(" ");
- writer.write(name);
- writer.write("=\"");
+ if (attribute != null)
+ {
+ writer.write(" ");
+ writer.write(name);
+ writer.write("=\"");
- string(attribute);
- writer.write("\"");
+ string(attribute);
+ writer.write("\"");
}
}
-
// ---------------------------------------------------------- Writer Methods
-
/** {@inheritDoc} */
- public void close() throws IOException {
+ public void close() throws IOException
+ {
finish();
writer.close();
}
-
/** {@inheritDoc} */
- public void write(char[] cbuf, int off, int len) throws IOException {
+ public void write(char[] cbuf, int off, int len) throws IOException
+ {
finish();
writer.write(cbuf, off, len);
}
-
// --------------------------------------------------------- Support Methods
-
/**
* <p>Write the specified character, filtering if necessary.</p>
*
@@ -250,50 +268,68 @@
*
* @exception IOException if an input/output error occurs
*/
- private void character(char ch) throws IOException {
+ private void character(char ch) throws IOException
+ {
- if (ch <= 0xff) {
+ if (ch <= 0xff)
+ {
// In single byte characters, replace only the five
// characters for which well-known entities exist in XML
- if (ch == 0x22) {
+ if (ch == 0x22)
+ {
writer.write(""");
- } else if (ch == 0x26) {
+ }
+ else if (ch == 0x26)
+ {
writer.write("&");
- } else if (ch == 0x27) {
+ }
+ else if (ch == 0x27)
+ {
writer.write("'");
- } else if (ch == 0x3C) {
+ }
+ else if (ch == 0x3C)
+ {
writer.write("<");
- } else if (ch == 0X3E) {
+ }
+ else if (ch == 0X3E)
+ {
writer.write(">");
- } else {
+ }
+ else
+ {
writer.write(ch);
}
- } else {
- if (substitution()) {
+ }
+ else
+ {
+ if (substitution())
+ {
numeric(writer, ch);
- } else {
+ }
+ else
+ {
writer.write(ch);
}
}
}
-
/**
* <p>Close any element that is currently open.</p>
*
* @exception IOException if an input/output error occurs
*/
- private void finish() throws IOException {
+ private void finish() throws IOException
+ {
- if (open) {
+ if (open)
+ {
writer.write(">");
open = false;
}
}
-
/**
* <p>Write a numeric character reference for specified character
* to the specfied writer.</p>
@@ -303,7 +339,8 @@
*
* @exception IOException if an input/output error occurs
*/
- private void numeric(Writer writer, char ch) throws IOException {
+ private void numeric(Writer writer, char ch) throws IOException
+ {
writer.write("&#");
writer.write(String.valueOf(ch));
@@ -311,7 +348,6 @@
}
-
/**
* <p>Write the specified characters (after performing suitable
* replacement of characters by corresponding entities).</p>
@@ -322,16 +358,17 @@
*
* @exception IOException if an input/output error occurs
*/
- private void string(char[] text, int off, int len) throws IOException {
+ private void string(char[] text, int off, int len) throws IOException
+ {
// Process the specified characters
- for (int i = off; i < (off + len); i++) {
+ for (int i = off; i < (off + len); i++)
+ {
character(text[i]);
}
}
-
/**
* <p>Write the specified string (after performing suitable
* replacement of characters by corresponding entities).</p>
@@ -340,33 +377,45 @@
*
* @exception IOException if an input/output error occurs
*/
- private void string(String s) throws IOException {
- for (int i = 0; i < s.length(); i++) {
+ private void string(String s) throws IOException
+ {
+ for (int i = 0; i < s.length(); i++)
+ {
character(s.charAt(i));
}
}
-
/**
* <p>Return true if entity substitution should be performed on double
* byte character values.</p>
*/
- private boolean substitution() {
+ private boolean substitution()
+ {
- return !("UTF-8".equals(characterEncoding) || "UTF-16".equals(characterEncoding));
+ return !("UTF-8".equals(characterEncoding) || "UTF-16"
+ .equals(characterEncoding));
}
- private String findValue(final Object value, final String property) {
- if (value != null) {
+ private String findValue(final Object value, final String property)
+ {
+ if (value != null)
+ {
return value instanceof String ? (String) value : value.toString();
- } else if (property != null) {
- if (component != null) {
+ }
+ else if (property != null)
+ {
+ if (component != null)
+ {
final Object object = component.getAttributes().get(property);
- if (object != null) {
- return object instanceof String ? (String) object : object.toString();
- } else {
+ if (object != null)
+ {
+ return object instanceof String ? (String) object : object
+ .toString();
+ }
+ else
+ {
return null;
}
}
diff --git a/test12/src/main/java/org/apache/myfaces/test/mock/MockServlet.java b/test12/src/main/java/org/apache/myfaces/test/mock/MockServlet.java
index d616293..6bffb80 100644
--- a/test12/src/main/java/org/apache/myfaces/test/mock/MockServlet.java
+++ b/test12/src/main/java/org/apache/myfaces/test/mock/MockServlet.java
@@ -32,92 +32,87 @@
* @since 1.0.0
*/
-public class MockServlet implements Servlet {
-
+public class MockServlet implements Servlet
+{
// ------------------------------------------------------------ Constructors
-
/**
* <p>Create a default Servlet instance.</p>
*/
- public MockServlet() {
+ public MockServlet()
+ {
}
-
/**
* <p>Create a new Servlet with the specified ServletConfig.</p>
*
* @param config The new ServletConfig instance
*/
- public MockServlet(ServletConfig config) throws ServletException {
+ public MockServlet(ServletConfig config) throws ServletException
+ {
init(config);
}
-
// ----------------------------------------------------- Mock Object Methods
-
/**
* <p>Set the <code>ServletConfig</code> instance for this servlet.</p>
*
* @param config The new ServletConfig instance
*/
- public void setServletConfig(ServletConfig config) {
+ public void setServletConfig(ServletConfig config)
+ {
this.config = config;
}
-
// ------------------------------------------------------ Instance Variables
-
/**
* <p>The <code>ServletConfig</code> instance for this servlet.</p>
*/
private ServletConfig config;
-
// --------------------------------------------------------- Servlet Methods
-
/** {@inheritDoc} */
- public void destroy() {
+ public void destroy()
+ {
}
-
/** {@inheritDoc} */
- public ServletConfig getServletConfig() {
+ public ServletConfig getServletConfig()
+ {
return this.config;
}
-
/** {@inheritDoc} */
- public String getServletInfo() {
+ public String getServletInfo()
+ {
return "MockServlet";
}
-
/** {@inheritDoc} */
- public void init(ServletConfig config) throws ServletException {
+ public void init(ServletConfig config) throws ServletException
+ {
this.config = config;
}
-
/** {@inheritDoc} */
public void service(ServletRequest request, ServletResponse response)
- throws IOException, ServletException {
+ throws IOException, ServletException
+ {
// Do nothing by default
}
-
}
diff --git a/test12/src/main/java/org/apache/myfaces/test/mock/MockServletConfig.java b/test12/src/main/java/org/apache/myfaces/test/mock/MockServletConfig.java
index 584a827..c726118 100644
--- a/test12/src/main/java/org/apache/myfaces/test/mock/MockServletConfig.java
+++ b/test12/src/main/java/org/apache/myfaces/test/mock/MockServletConfig.java
@@ -30,98 +30,93 @@
* @since 1.0.0
*/
-public class MockServletConfig implements ServletConfig {
-
+public class MockServletConfig implements ServletConfig
+{
// ------------------------------------------------------------ Constructors
-
/**
* <p>Construct a default instance.</p>
*/
- public MockServletConfig() {
+ public MockServletConfig()
+ {
}
-
/**
* <p>Construct an instance associated with the specified
* servlet context.</p>
*
* @param context The associated ServletContext
*/
- public MockServletConfig(ServletContext context) {
+ public MockServletConfig(ServletContext context)
+ {
setServletContext(context);
}
-
// ----------------------------------------------------- Mock Object Methods
-
/**
* <p>Add a servlet initialization parameter.</p>
*
* @param name Parameter name
* @param value Parameter value
*/
- public void addInitParameter(String name, String value) {
+ public void addInitParameter(String name, String value)
+ {
parameters.put(name, value);
}
-
/**
* <p>Set the servlet context for this application.</p>
*
* @param context The new servlet context
*/
- public void setServletContext(ServletContext context) {
+ public void setServletContext(ServletContext context)
+ {
this.context = context;
}
-
// ------------------------------------------------------ Instance Variables
-
private ServletContext context;
private Hashtable parameters = new Hashtable();
-
// --------------------------------------------------- ServletConfig Methods
-
/** {@inheritDoc} */
- public String getInitParameter(String name) {
+ public String getInitParameter(String name)
+ {
return (String) parameters.get(name);
}
-
/** {@inheritDoc} */
- public Enumeration getInitParameterNames() {
+ public Enumeration getInitParameterNames()
+ {
return parameters.keys();
}
-
/** {@inheritDoc} */
- public ServletContext getServletContext() {
+ public ServletContext getServletContext()
+ {
return this.context;
}
-
/** {@inheritDoc} */
- public String getServletName() {
+ public String getServletName()
+ {
return "MockServlet";
}
-
}
diff --git a/test12/src/main/java/org/apache/myfaces/test/mock/MockServletOutputStream.java b/test12/src/main/java/org/apache/myfaces/test/mock/MockServletOutputStream.java
index 8cfe07e..526ea89 100644
--- a/test12/src/main/java/org/apache/myfaces/test/mock/MockServletOutputStream.java
+++ b/test12/src/main/java/org/apache/myfaces/test/mock/MockServletOutputStream.java
@@ -27,71 +27,65 @@
* @since 1.0.0
*/
-public class MockServletOutputStream extends ServletOutputStream {
-
+public class MockServletOutputStream extends ServletOutputStream
+{
// ------------------------------------------------------------ Constructors
-
/**
* <p>Return a default instance.</p>
*
* @param stream The stream we will use to buffer output
*/
- public MockServletOutputStream(ByteArrayOutputStream stream) {
+ public MockServletOutputStream(ByteArrayOutputStream stream)
+ {
this.baos = stream;
}
-
// ----------------------------------------------------- Mock Object Methods
-
/**
* <p>Return the content that has been written to this output stream.</p>
*/
- public byte[] content() {
+ public byte[] content()
+ {
return baos.toByteArray();
}
-
/**
* <p>Reset this output stream so that it appears no content has been
* written.</p>
*/
- public void reset() {
+ public void reset()
+ {
baos.reset();
}
-
/**
* <p>Return the number of bytes that have been written to this output stream.</p>
*/
- public int size() {
+ public int size()
+ {
return baos.size();
}
-
-
// ------------------------------------------------------ Instance Variables
-
/**
* <p>The internal buffer we use to capture output.</p>
*/
private ByteArrayOutputStream baos = null;
-
// --------------------------------------------- ServletOutputStream Methods
-
/**
* <p>Write the specified content to our internal cache.</p>
*
* @param content Content to be written
*/
- public void write(int content) {
+ public void write(int content)
+ {
baos.write(content);
}
-
}
diff --git a/test12/src/main/java/org/apache/myfaces/test/mock/MockStateManager.java b/test12/src/main/java/org/apache/myfaces/test/mock/MockStateManager.java
index 89f70dc..3613843 100644
--- a/test12/src/main/java/org/apache/myfaces/test/mock/MockStateManager.java
+++ b/test12/src/main/java/org/apache/myfaces/test/mock/MockStateManager.java
@@ -29,86 +29,82 @@
* $Id$
* @since 1.0.0
*/
-public class MockStateManager extends StateManager {
-
+public class MockStateManager extends StateManager
+{
// ------------------------------------------------------------ Constructors
-
/**
* <p>Construct a default instance.</p>
*/
- public MockStateManager() {
+ public MockStateManager()
+ {
}
-
// ----------------------------------------------------- Mock Object Methods
-
// ------------------------------------------------------ Instance Variables
-
// ---------------------------------------------------- StateManager Methods
-
/** {@inheritDoc} */
- public SerializedView saveSerializedView(FacesContext context) {
+ public SerializedView saveSerializedView(FacesContext context)
+ {
throw new UnsupportedOperationException();
}
-
/** {@inheritDoc} */
- public Object getTreeStructureToSave(FacesContext context) {
+ public Object getTreeStructureToSave(FacesContext context)
+ {
throw new UnsupportedOperationException();
}
-
/** {@inheritDoc} */
- public Object getComponentStateToSave(FacesContext context) {
+ public Object getComponentStateToSave(FacesContext context)
+ {
throw new UnsupportedOperationException();
}
-
/** {@inheritDoc} */
public void writeState(FacesContext context, SerializedView view)
- throws IOException {
+ throws IOException
+ {
throw new UnsupportedOperationException();
}
-
/** {@inheritDoc} */
public UIViewRoot restoreView(FacesContext context, String viewId,
- String renderKitId) {
+ String renderKitId)
+ {
throw new UnsupportedOperationException();
}
-
/** {@inheritDoc} */
public UIViewRoot restoreTreeStructure(FacesContext context, String viewId,
- String renderKitId) {
+ String renderKitId)
+ {
throw new UnsupportedOperationException();
}
-
/** {@inheritDoc} */
public void restoreComponentState(FacesContext context, UIViewRoot view,
- String renderKitId) {
+ String renderKitId)
+ {
throw new UnsupportedOperationException();
}
-
}
diff --git a/test12/src/main/java/org/apache/myfaces/test/mock/MockValueBinding.java b/test12/src/main/java/org/apache/myfaces/test/mock/MockValueBinding.java
index 0aba9f3..b21dbe5 100644
--- a/test12/src/main/java/org/apache/myfaces/test/mock/MockValueBinding.java
+++ b/test12/src/main/java/org/apache/myfaces/test/mock/MockValueBinding.java
@@ -32,39 +32,40 @@
import javax.faces.el.ValueBinding;
import javax.faces.el.VariableResolver;
-
/**
* <p>Mock implementation of <code>ValueBinding</code>.</p>
*
* @since 1.0.0
*/
-public class MockValueBinding extends ValueBinding implements StateHolder {
-
+public class MockValueBinding extends ValueBinding implements StateHolder
+{
// ------------------------------------------------------------ Constructors
-
/**
* <p>Construct a default instance.</p>
*/
- public MockValueBinding() {
+ public MockValueBinding()
+ {
this(null, null);
}
-
/**
* <p>Construct a new value binding for the specified expression.</p>
*
* @param application Application instance to be wrapped
* @param ref Expression to be wrapped
*/
- public MockValueBinding(Application application, String ref) {
+ public MockValueBinding(Application application, String ref)
+ {
this.application = application;
- if (ref != null) {
- if (ref.startsWith("#{") && ref.endsWith("}")) {
+ if (ref != null)
+ {
+ if (ref.startsWith("#{") && ref.endsWith("}"))
+ {
ref = ref.substring(2, ref.length() - 1);
}
}
@@ -72,43 +73,39 @@
}
-
// ----------------------------------------------------- Mock Object Methods
-
/**
* <p>Return the expression string for this value binding.</p>
*/
- public String ref() {
+ public String ref()
+ {
return this.ref;
}
-
// ------------------------------------------------------ Instance Variables
-
/**
* <p>The <code>Application</code> instance for this application.</p>
*/
private transient Application application; // Restored as necessary
-
/**
* <p>The expression this value binding will evaluate.</p>
*/
private String ref;
-
// ---------------------------------------------------- ValueBinding Methods
-
/** {@inheritDoc} */
- public Object getValue(FacesContext context)
- throws EvaluationException, PropertyNotFoundException {
+ public Object getValue(FacesContext context) throws EvaluationException,
+ PropertyNotFoundException
+ {
- if (context == null) {
+ if (context == null)
+ {
throw new NullPointerException();
}
List names = parse(ref);
@@ -117,13 +114,15 @@
VariableResolver vr = application().getVariableResolver();
String name = (String) names.get(0);
Object base = vr.resolveVariable(context, name);
- if (names.size() < 2) {
+ if (names.size() < 2)
+ {
return (base);
}
// Resolve the property names
PropertyResolver pr = application().getPropertyResolver();
- for (int i = 1; i < names.size(); i++) {
+ for (int i = 1; i < names.size(); i++)
+ {
base = pr.getValue(base, (String) names.get(i));
}
@@ -132,12 +131,13 @@
}
-
/** {@inheritDoc} */
public void setValue(FacesContext context, Object value)
- throws EvaluationException, PropertyNotFoundException {
+ throws EvaluationException, PropertyNotFoundException
+ {
- if (context == null) {
+ if (context == null)
+ {
throw new NullPointerException();
}
List names = parse(ref);
@@ -146,25 +146,28 @@
VariableResolver vr = application().getVariableResolver();
String name = (String) names.get(0);
Object base = vr.resolveVariable(context, name);
- if (names.size() < 2) {
- if ("applicationScope".equals(name)
- || "requestScope".equals(name)
- || "sessionScope".equals(name)) {
- throw new ReferenceSyntaxException("Cannot set '"
- + name + "'");
+ if (names.size() < 2)
+ {
+ if ("applicationScope".equals(name) || "requestScope".equals(name)
+ || "sessionScope".equals(name))
+ {
+ throw new ReferenceSyntaxException("Cannot set '" + name + "'");
}
Map map = econtext().getRequestMap();
- if (map.containsKey(name)) {
+ if (map.containsKey(name))
+ {
map.put(name, value);
return;
}
map = econtext().getSessionMap();
- if ((map != null) && (map.containsKey(name))) {
+ if ((map != null) && (map.containsKey(name)))
+ {
map.put(name, value);
return;
}
map = econtext().getApplicationMap();
- if (map.containsKey(name)) {
+ if (map.containsKey(name))
+ {
map.put(name, value);
return;
}
@@ -174,7 +177,8 @@
// Resolve the property names
PropertyResolver pr = application().getPropertyResolver();
- for (int i = 1; i < (names.size() - 1); i++) {
+ for (int i = 1; i < (names.size() - 1); i++)
+ {
// System.out.println(" property=" + names.get(i));
base = pr.getValue(base, (String) names.get(i));
}
@@ -184,12 +188,13 @@
}
-
/** {@inheritDoc} */
public boolean isReadOnly(FacesContext context)
- throws PropertyNotFoundException {
+ throws PropertyNotFoundException
+ {
- if (context == null) {
+ if (context == null)
+ {
throw new NullPointerException();
}
List names = parse(ref);
@@ -198,13 +203,15 @@
VariableResolver vr = application().getVariableResolver();
String name = (String) names.get(0);
Object base = vr.resolveVariable(context, name);
- if (names.size() < 2) {
+ if (names.size() < 2)
+ {
return true;
}
// Resolve the property names
PropertyResolver pr = application().getPropertyResolver();
- for (int i = 1; i < names.size() - 1; i++) {
+ for (int i = 1; i < names.size() - 1; i++)
+ {
base = pr.getValue(base, (String) names.get(i));
}
@@ -213,12 +220,12 @@
}
-
/** {@inheritDoc} */
- public Class getType(FacesContext context)
- throws PropertyNotFoundException {
+ public Class getType(FacesContext context) throws PropertyNotFoundException
+ {
- if (context == null) {
+ if (context == null)
+ {
throw new NullPointerException();
}
List names = parse(ref);
@@ -227,13 +234,15 @@
VariableResolver vr = application().getVariableResolver();
String name = (String) names.get(0);
Object base = vr.resolveVariable(context, name);
- if (names.size() < 2) {
+ if (names.size() < 2)
+ {
return base.getClass();
}
// Resolve the property names
PropertyResolver pr = application().getPropertyResolver();
- for (int i = 1; i < names.size() - 1; i++) {
+ for (int i = 1; i < names.size() - 1; i++)
+ {
base = pr.getValue(base, (String) names.get(i));
}
@@ -243,18 +252,18 @@
}
/** {@inheritDoc} */
- public String getExpressionString() {
+ public String getExpressionString()
+ {
return "#{" + ref + "}";
}
-
// ----------------------------------------------------- StateHolder Methods
-
/** {@inheritDoc} */
- public Object saveState(FacesContext context) {
+ public Object saveState(FacesContext context)
+ {
Object[] values = new Object[1];
values[0] = ref;
@@ -262,113 +271,127 @@
}
-
/** {@inheritDoc} */
- public void restoreState(FacesContext context, Object state) {
+ public void restoreState(FacesContext context, Object state)
+ {
Object[] values = (Object[]) state;
ref = (String) values[0];
}
-
/**
* <p>Flag indicating that this value is transient.</p>
*/
private boolean transientFlag = false;
-
/** {@inheritDoc} */
- public boolean isTransient() {
+ public boolean isTransient()
+ {
return this.transientFlag;
}
-
/** {@inheritDoc} */
- public void setTransient(boolean transientFlag) {
+ public void setTransient(boolean transientFlag)
+ {
this.transientFlag = transientFlag;
}
-
// --------------------------------------------------------- Private Methods
-
/**
* <p>Return the relevant <code>Application</code> instance.</p>
*/
- private Application application() {
+ private Application application()
+ {
- if (application == null) {
+ if (application == null)
+ {
application = FacesContext.getCurrentInstance().getApplication();
}
return (application);
}
-
/**
* <p>Return the relevant <code>ExternalContext</code> instance.</p>
*/
- private ExternalContext econtext() {
+ private ExternalContext econtext()
+ {
return (FacesContext.getCurrentInstance().getExternalContext());
}
-
/**
* <p>Return a list of the expression elements in this expression.</p>
*
* @param ref Expression to be parsed
*/
- private List parse(String ref) {
+ private List parse(String ref)
+ {
List names = new ArrayList();
StringBuffer expr = new StringBuffer(ref);
boolean isBlockOn = false;
- for (int i = expr.length() - 1; i > -1; i--) {
- if (expr.charAt(i) == ' ') {
+ for (int i = expr.length() - 1; i > -1; i--)
+ {
+ if (expr.charAt(i) == ' ')
+ {
expr.deleteCharAt(i);
- } else if (expr.charAt(i) == ']') {
+ }
+ else if (expr.charAt(i) == ']')
+ {
expr.deleteCharAt(i);
- } else if (expr.charAt(i) == '[') {
+ }
+ else if (expr.charAt(i) == '[')
+ {
expr.deleteCharAt(i);
- } else if (expr.charAt(i) == '\'') {
- if (!isBlockOn) {
+ }
+ else if (expr.charAt(i) == '\'')
+ {
+ if (!isBlockOn)
+ {
expr.deleteCharAt(i);
- } else {
+ }
+ else
+ {
names.add(0, expr.substring(i + 1));
expr.delete(i, expr.length());
}
isBlockOn = !isBlockOn;
- } else if (expr.charAt(i) == '.' && !isBlockOn) {
+ }
+ else if (expr.charAt(i) == '.' && !isBlockOn)
+ {
names.add(0, expr.substring(i + 1));
expr.delete(i, expr.length());
}
}
- if (expr.length() > 0) {
+ if (expr.length() > 0)
+ {
names.add(0, expr.toString());
}
- if (names.size() < 1) {
- throw new ReferenceSyntaxException("No expression in '"
- + ref + "'");
+ if (names.size() < 1)
+ {
+ throw new ReferenceSyntaxException("No expression in '" + ref + "'");
}
- for (int i = 0; i < names.size(); i++) {
+ for (int i = 0; i < names.size(); i++)
+ {
String name = (String) names.get(i);
- if (name.length() < 1) {
- throw new ReferenceSyntaxException("Invalid expression '"
- + ref + "'");
+ if (name.length() < 1)
+ {
+ throw new ReferenceSyntaxException("Invalid expression '" + ref
+ + "'");
}
}
return (names);
}
-
}
diff --git a/test12/src/main/java/org/apache/myfaces/test/mock/MockVariableResolver.java b/test12/src/main/java/org/apache/myfaces/test/mock/MockVariableResolver.java
index f04b0bb..44cac67 100644
--- a/test12/src/main/java/org/apache/myfaces/test/mock/MockVariableResolver.java
+++ b/test12/src/main/java/org/apache/myfaces/test/mock/MockVariableResolver.java
@@ -36,78 +36,106 @@
* @since 1.0.0
*/
-public class MockVariableResolver extends VariableResolver {
-
+public class MockVariableResolver extends VariableResolver
+{
// ------------------------------------------------------------ Constructors
-
/**
* <p>Construct a default instance.</p>
*/
- public MockVariableResolver() {
+ public MockVariableResolver()
+ {
}
-
// ----------------------------------------------------- Mock Object Methods
-
// ------------------------------------------------------ Instance Variables
-
// ------------------------------------------------ VariableResolver Methods
-
/** {@inheritDoc} */
- public Object resolveVariable(FacesContext context, String name) {
+ public Object resolveVariable(FacesContext context, String name)
+ {
- if ((context == null) || (name == null)) {
+ if ((context == null) || (name == null))
+ {
throw new NullPointerException();
}
// Check for magic names
- if ("application".equals(name)) {
+ if ("application".equals(name))
+ {
return external().getContext();
- } else if ("applicationScope".equals(name)) {
+ }
+ else if ("applicationScope".equals(name))
+ {
return external().getApplicationMap();
- } else if ("cookie".equals(name)) {
+ }
+ else if ("cookie".equals(name))
+ {
return external().getRequestCookieMap();
- } else if ("facesContext".equals(name)) {
+ }
+ else if ("facesContext".equals(name))
+ {
return FacesContext.getCurrentInstance();
- } else if ("header".equals(name)) {
+ }
+ else if ("header".equals(name))
+ {
return external().getRequestHeaderMap();
- } else if ("headerValues".equals(name)) {
+ }
+ else if ("headerValues".equals(name))
+ {
return external().getRequestHeaderValuesMap();
- } else if ("param".equals(name)) {
+ }
+ else if ("param".equals(name))
+ {
return external().getRequestParameterMap();
- } else if ("paramValues".equals(name)) {
+ }
+ else if ("paramValues".equals(name))
+ {
return external().getRequestParameterValuesMap();
- } else if ("request".equals(name)) {
+ }
+ else if ("request".equals(name))
+ {
return external().getRequest();
- } else if ("requestScope".equals(name)) {
+ }
+ else if ("requestScope".equals(name))
+ {
return external().getRequestMap();
- } else if ("response".equals(name)) {
+ }
+ else if ("response".equals(name))
+ {
return external().getResponse();
- } else if ("session".equals(name)) {
+ }
+ else if ("session".equals(name))
+ {
return external().getSession(true);
- } else if ("sessionScope".equals(name)) {
+ }
+ else if ("sessionScope".equals(name))
+ {
return external().getSessionMap();
- } else if ("view".equals(name)) {
+ }
+ else if ("view".equals(name))
+ {
return FacesContext.getCurrentInstance().getViewRoot();
}
// Search ascending scopes for non-magic names
Map map = null;
map = external().getRequestMap();
- if (map.containsKey(name)) {
+ if (map.containsKey(name))
+ {
return map.get(name);
}
map = external().getSessionMap();
- if ((map != null) && (map.containsKey(name))) {
+ if ((map != null) && (map.containsKey(name)))
+ {
return map.get(name);
}
map = external().getApplicationMap();
- if (map.containsKey(name)) {
+ if (map.containsKey(name))
+ {
return map.get(name);
}
@@ -116,19 +144,16 @@
}
-
-
// --------------------------------------------------------- Private Methods
-
/**
* <p>Return the <code>ExternalContext</code> for this request.</p>
*/
- private ExternalContext external() {
+ private ExternalContext external()
+ {
return FacesContext.getCurrentInstance().getExternalContext();
}
-
}
diff --git a/test12/src/main/java/org/apache/myfaces/test/mock/MockViewHandler.java b/test12/src/main/java/org/apache/myfaces/test/mock/MockViewHandler.java
index 2048976..33eba85 100644
--- a/test12/src/main/java/org/apache/myfaces/test/mock/MockViewHandler.java
+++ b/test12/src/main/java/org/apache/myfaces/test/mock/MockViewHandler.java
@@ -31,59 +31,59 @@
* @since 1.0.0
*/
-public class MockViewHandler extends ViewHandler {
-
+public class MockViewHandler extends ViewHandler
+{
// ------------------------------------------------------------ Constructors
-
/**
* <p>Construct a default instance.</p>
*/
- public MockViewHandler() {
+ public MockViewHandler()
+ {
}
-
// ----------------------------------------------------- Mock Object Methods
-
// ------------------------------------------------------ Instance Variables
-
// ----------------------------------------------------- ViewHandler Methods
-
/** {@inheritDoc} */
- public Locale calculateLocale(FacesContext context) {
+ public Locale calculateLocale(FacesContext context)
+ {
Locale locale = context.getApplication().getDefaultLocale();
- if (locale == null) {
+ if (locale == null)
+ {
locale = Locale.getDefault();
}
return locale;
}
-
/** {@inheritDoc} */
- public String calculateRenderKitId(FacesContext context) {
+ public String calculateRenderKitId(FacesContext context)
+ {
String renderKitId = context.getApplication().getDefaultRenderKitId();
- if (renderKitId == null) {
+ if (renderKitId == null)
+ {
renderKitId = RenderKitFactory.HTML_BASIC_RENDER_KIT;
}
return renderKitId;
}
-
/** {@inheritDoc} */
- public UIViewRoot createView(FacesContext context, String viewId) {
+ public UIViewRoot createView(FacesContext context, String viewId)
+ {
// Save locale and renderKitId from previous view (if any), per spec
Locale locale = null;
String renderKitId = null;
- if (context.getViewRoot() != null) {
+ if (context.getViewRoot() != null)
+ {
locale = context.getViewRoot().getLocale();
renderKitId = context.getViewRoot().getRenderKitId();
}
@@ -91,17 +91,23 @@
// Configure a new UIViewRoot instance
UIViewRoot view = new UIViewRoot();
view.setViewId(viewId);
- if (locale != null) {
+ if (locale != null)
+ {
view.setLocale(locale);
- } else {
- view.setLocale
- (context.getApplication().getViewHandler().calculateLocale(context));
}
- if (renderKitId != null) {
+ else
+ {
+ view.setLocale(context.getApplication().getViewHandler()
+ .calculateLocale(context));
+ }
+ if (renderKitId != null)
+ {
view.setRenderKitId(renderKitId);
- } else {
- view.setRenderKitId
- (context.getApplication().getViewHandler().calculateRenderKitId(context));
+ }
+ else
+ {
+ view.setRenderKitId(context.getApplication().getViewHandler()
+ .calculateRenderKitId(context));
}
// Return the configured instance
@@ -109,45 +115,46 @@
}
-
/** {@inheritDoc} */
- public String getActionURL(FacesContext context, String viewId) {
+ public String getActionURL(FacesContext context, String viewId)
+ {
- return FacesContext.getCurrentInstance().getExternalContext().
- getRequestContextPath() + viewId;
+ return FacesContext.getCurrentInstance().getExternalContext()
+ .getRequestContextPath()
+ + viewId;
}
-
/** {@inheritDoc} */
- public String getResourceURL(FacesContext context, String path) {
+ public String getResourceURL(FacesContext context, String path)
+ {
- return FacesContext.getCurrentInstance().getExternalContext().
- getRequestContextPath() + path;
+ return FacesContext.getCurrentInstance().getExternalContext()
+ .getRequestContextPath()
+ + path;
}
-
/** {@inheritDoc} */
- public void renderView(FacesContext context, UIViewRoot view) {
+ public void renderView(FacesContext context, UIViewRoot view)
+ {
throw new UnsupportedOperationException();
}
-
/** {@inheritDoc} */
- public UIViewRoot restoreView(FacesContext context, String viewId) {
+ public UIViewRoot restoreView(FacesContext context, String viewId)
+ {
throw new UnsupportedOperationException();
}
-
/** {@inheritDoc} */
- public void writeState(FacesContext context) {
+ public void writeState(FacesContext context)
+ {
}
-
}
diff --git a/test12/src/main/java/org/apache/myfaces/test/mock/_AbstractAttributeMap.java b/test12/src/main/java/org/apache/myfaces/test/mock/_AbstractAttributeMap.java
index b9b0367..3d594b6 100644
--- a/test12/src/main/java/org/apache/myfaces/test/mock/_AbstractAttributeMap.java
+++ b/test12/src/main/java/org/apache/myfaces/test/mock/_AbstractAttributeMap.java
@@ -67,7 +67,8 @@
return false;
}
- for (final Enumeration<String> e = getAttributeNames(); e.hasMoreElements();)
+ for (final Enumeration<String> e = getAttributeNames(); e
+ .hasMoreElements();)
{
final Object value = getAttribute(e.nextElement());
if (findValue.equals(value))
@@ -133,7 +134,8 @@
public int size()
{
int size = 0;
- for (final Enumeration<String> e = getAttributeNames(); e.hasMoreElements();)
+ for (final Enumeration<String> e = getAttributeNames(); e
+ .hasMoreElements();)
{
size++;
e.nextElement();
@@ -206,14 +208,16 @@
// from getAttributeNames() will contain exactly the attribute names from the time
// getAttributeNames() was called and it will not be updated if attributes are
// removed or added.
- protected final Iterator<String> _i = Collections.list(getAttributeNames()).iterator();
+ protected final Iterator<String> _i = Collections.list(
+ getAttributeNames()).iterator();
protected String _currentKey;
public void remove()
{
if (_currentKey == null)
{
- throw new NoSuchElementException("You must call next() at least once");
+ throw new NoSuchElementException(
+ "You must call next() at least once");
}
_AbstractAttributeMap.this.remove(_currentKey);
}
@@ -314,7 +318,7 @@
return false;
}
- final Entry<String, V> entry = (Entry<String, V>)o;
+ final Entry<String, V> entry = (Entry<String, V>) o;
final Object key = entry.getKey();
final Object value = entry.getValue();
if (key == null || value == null)
@@ -334,15 +338,17 @@
return false;
}
- final Entry<String, V> entry = (Entry<String, V>)o;
+ final Entry<String, V> entry = (Entry<String, V>) o;
final Object key = entry.getKey();
final Object value = entry.getValue();
- if (key == null || value == null || !value.equals(_AbstractAttributeMap.this.get(key)))
+ if (key == null || value == null
+ || !value.equals(_AbstractAttributeMap.this.get(key)))
{
return false;
}
- return _AbstractAttributeMap.this.remove(((Entry<String, V>)o).getKey()) != null;
+ return _AbstractAttributeMap.this.remove(((Entry<String, V>) o)
+ .getKey()) != null;
}
}
@@ -350,7 +356,8 @@
* Not very efficient since it generates a new instance of <code>Entry</code> for each element and still internaly
* uses the <code>KeyIterator</code>. It is more efficient to use the <code>KeyIterator</code> directly.
*/
- private final class EntryIterator extends AbstractAttributeIterator<Entry<String, V>>
+ private final class EntryIterator extends
+ AbstractAttributeIterator<Entry<String, V>>
{
@Override
protected Entry<String, V> getValue(final String attributeName)
@@ -389,7 +396,8 @@
public int hashCode()
{
int result = 1;
- result = 31 * result + ((_currentKey == null) ? 0 : _currentKey.hashCode());
+ result = 31 * result
+ + ((_currentKey == null) ? 0 : _currentKey.hashCode());
return result;
}
@@ -402,7 +410,7 @@
return false;
if (getClass() != obj.getClass())
return false;
- final EntrySetEntry other = (EntrySetEntry)obj;
+ final EntrySetEntry other = (EntrySetEntry) obj;
if (_currentKey == null)
{
if (other._currentKey != null)
diff --git a/test12/src/main/java/org/apache/myfaces/test/mock/_ApplicationMap.java b/test12/src/main/java/org/apache/myfaces/test/mock/_ApplicationMap.java
index a077ac8..8f4088e 100644
--- a/test12/src/main/java/org/apache/myfaces/test/mock/_ApplicationMap.java
+++ b/test12/src/main/java/org/apache/myfaces/test/mock/_ApplicationMap.java
@@ -23,7 +23,6 @@
import javax.servlet.ServletContext;
-
/**
* ServletContext attributes as a Map.
*
@@ -65,14 +64,12 @@
return _servletContext.getAttributeNames();
}
-
@Override
public void putAll(final Map<? extends String, ? extends Object> t)
{
throw new UnsupportedOperationException();
}
-
@Override
public void clear()
{
diff --git a/test12/src/main/java/org/apache/myfaces/test/mock/_CookieMap.java b/test12/src/main/java/org/apache/myfaces/test/mock/_CookieMap.java
index 42fdf2c..947c486 100644
--- a/test12/src/main/java/org/apache/myfaces/test/mock/_CookieMap.java
+++ b/test12/src/main/java/org/apache/myfaces/test/mock/_CookieMap.java
@@ -48,7 +48,7 @@
public void clear()
{
throw new UnsupportedOperationException(
- "Cannot clear HttpRequest Cookies");
+ "Cannot clear HttpRequest Cookies");
}
@Override
@@ -114,14 +114,14 @@
protected void setAttribute(final String key, final Object value)
{
throw new UnsupportedOperationException(
- "Cannot set HttpRequest Cookies");
+ "Cannot set HttpRequest Cookies");
}
@Override
protected void removeAttribute(final String key)
{
throw new UnsupportedOperationException(
- "Cannot remove HttpRequest Cookies");
+ "Cannot remove HttpRequest Cookies");
}
@Override
@@ -129,8 +129,9 @@
{
final Cookie[] cookies = _httpServletRequest.getCookies();
- return cookies == null ? new CookieNameEnumeration(EMPTY_ARRAY) : new CookieNameEnumeration(cookies);
-
+ return cookies == null ? new CookieNameEnumeration(EMPTY_ARRAY)
+ : new CookieNameEnumeration(cookies);
+
}
private static class CookieNameEnumeration implements Enumeration<String>
diff --git a/test12/src/main/java/org/apache/myfaces/test/mock/_Hex.java b/test12/src/main/java/org/apache/myfaces/test/mock/_Hex.java
index afef008..28ce1a1 100644
--- a/test12/src/main/java/org/apache/myfaces/test/mock/_Hex.java
+++ b/test12/src/main/java/org/apache/myfaces/test/mock/_Hex.java
@@ -27,7 +27,8 @@
* @author Apache Software Foundation
* @version $Id: Hex.java 801639 2009-08-06 13:15:10Z niallp $
*/
-class _Hex {
+class _Hex
+{
/**
* Default charset name is {@link CharEncoding#UTF_8}
@@ -37,12 +38,14 @@
/**
* Used to build output as Hex
*/
- private static final char[] DIGITS_LOWER = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
+ private static final char[] DIGITS_LOWER = { '0', '1', '2', '3', '4', '5',
+ '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
/**
* Used to build output as Hex
*/
- private static final char[] DIGITS_UPPER = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
+ private static final char[] DIGITS_UPPER = { '0', '1', '2', '3', '4', '5',
+ '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
/**
* Converts an array of characters representing hexadecimal values into an array of bytes of those same values. The
@@ -55,18 +58,21 @@
* @throws DecoderException
* Thrown if an odd number or illegal of characters is supplied
*/
- public static byte[] decodeHex(char[] data) throws Exception {
+ public static byte[] decodeHex(char[] data) throws Exception
+ {
int len = data.length;
- if ((len & 0x01) != 0) {
+ if ((len & 0x01) != 0)
+ {
throw new Exception("Odd number of characters.");
}
byte[] out = new byte[len >> 1];
// two characters form the hex value.
- for (int i = 0, j = 0; j < len; i++) {
+ for (int i = 0, j = 0; j < len; i++)
+ {
int f = toDigit(data[j], j) << 4;
j++;
f = f | toDigit(data[j], j);
@@ -86,7 +92,8 @@
* a byte[] to convert to Hex characters
* @return A char[] containing hexadecimal characters
*/
- public static char[] encodeHex(byte[] data) {
+ public static char[] encodeHex(byte[] data)
+ {
return encodeHex(data, true);
}
@@ -101,7 +108,8 @@
* <code>true</code> converts to lowercase, <code>false</code> to uppercase
* @return A char[] containing hexadecimal characters
*/
- public static char[] encodeHex(byte[] data, boolean toLowerCase) {
+ public static char[] encodeHex(byte[] data, boolean toLowerCase)
+ {
return encodeHex(data, toLowerCase ? DIGITS_LOWER : DIGITS_UPPER);
}
@@ -116,11 +124,13 @@
* the output alphabet
* @return A char[] containing hexadecimal characters
*/
- protected static char[] encodeHex(byte[] data, char[] toDigits) {
+ protected static char[] encodeHex(byte[] data, char[] toDigits)
+ {
int l = data.length;
char[] out = new char[l << 1];
// two characters form the hex value.
- for (int i = 0, j = 0; i < l; i++) {
+ for (int i = 0, j = 0; i < l; i++)
+ {
out[j++] = toDigits[(0xF0 & data[i]) >>> 4];
out[j++] = toDigits[0x0F & data[i]];
}
@@ -135,7 +145,8 @@
* a byte[] to convert to Hex characters
* @return A String containing hexadecimal characters
*/
- public static String encodeHexString(byte[] data) {
+ public static String encodeHexString(byte[] data)
+ {
return new String(encodeHex(data));
}
@@ -150,10 +161,13 @@
* @throws DecoderException
* Thrown if ch is an illegal hex character
*/
- protected static int toDigit(char ch, int index) throws Exception {
+ protected static int toDigit(char ch, int index) throws Exception
+ {
int digit = Character.digit(ch, 16);
- if (digit == -1) {
- throw new Exception("Illegal hexadecimal charcter " + ch + " at index " + index);
+ if (digit == -1)
+ {
+ throw new Exception("Illegal hexadecimal charcter " + ch
+ + " at index " + index);
}
return digit;
}
@@ -163,7 +177,8 @@
/**
* Creates a new codec with the default charset name {@link #DEFAULT_CHARSET_NAME}
*/
- public _Hex() {
+ public _Hex()
+ {
// use default encoding
this.charsetName = DEFAULT_CHARSET_NAME;
}
@@ -174,7 +189,8 @@
* @param csName
* the charset name.
*/
- public _Hex(String csName) {
+ public _Hex(String csName)
+ {
this.charsetName = csName;
}
@@ -190,10 +206,14 @@
* Thrown if an odd number of characters is supplied to this function
* @see #decodeHex(char[])
*/
- public byte[] decode(byte[] array) throws Exception {
- try {
+ public byte[] decode(byte[] array) throws Exception
+ {
+ try
+ {
return decodeHex(new String(array, getCharsetName()).toCharArray());
- } catch (UnsupportedEncodingException e) {
+ }
+ catch (UnsupportedEncodingException e)
+ {
throw new Exception(e.getMessage(), e);
}
}
@@ -211,11 +231,16 @@
* char[]
* @see #decodeHex(char[])
*/
- public Object decode(Object object) throws Exception {
- try {
- char[] charArray = object instanceof String ? ((String) object).toCharArray() : (char[]) object;
+ public Object decode(Object object) throws Exception
+ {
+ try
+ {
+ char[] charArray = object instanceof String ? ((String) object)
+ .toCharArray() : (char[]) object;
return decodeHex(charArray);
- } catch (ClassCastException e) {
+ }
+ catch (ClassCastException e)
+ {
throw new Exception(e.getMessage(), e);
}
}
@@ -237,10 +262,11 @@
* {@link UnsupportedEncodingException} for backward compatibility.
* @see #encodeHex(byte[])
*/
- public byte[] encode(byte[] array) {
+ public byte[] encode(byte[] array)
+ {
return getBytesUnchecked(encodeHexString(array), getCharsetName());
}
-
+
private static byte[] getBytesUnchecked(String string, String charsetName)
{
if (string == null)
@@ -257,7 +283,6 @@
}
}
-
/**
* Converts a String or an array of bytes into an array of characters representing the hexadecimal values of each
* byte in order. The returned array will be double the length of the passed String or array, as it takes two
@@ -274,13 +299,20 @@
* Thrown if the given object is not a String or byte[]
* @see #encodeHex(byte[])
*/
- public Object encode(Object object) throws Exception {
- try {
- byte[] byteArray = object instanceof String ? ((String) object).getBytes(getCharsetName()) : (byte[]) object;
+ public Object encode(Object object) throws Exception
+ {
+ try
+ {
+ byte[] byteArray = object instanceof String ? ((String) object)
+ .getBytes(getCharsetName()) : (byte[]) object;
return encodeHex(byteArray);
- } catch (ClassCastException e) {
+ }
+ catch (ClassCastException e)
+ {
throw new Exception(e.getMessage(), e);
- } catch (UnsupportedEncodingException e) {
+ }
+ catch (UnsupportedEncodingException e)
+ {
throw new Exception(e.getMessage(), e);
}
}
@@ -290,7 +322,8 @@
*
* @return the charset name.
*/
- public String getCharsetName() {
+ public String getCharsetName()
+ {
return this.charsetName;
}
@@ -299,7 +332,8 @@
*
* @return a string representation of the object.
*/
- public String toString() {
+ public String toString()
+ {
return super.toString() + "[charsetName=" + this.charsetName + "]";
}
}
diff --git a/test12/src/main/java/org/apache/myfaces/test/mock/_InitParameterMap.java b/test12/src/main/java/org/apache/myfaces/test/mock/_InitParameterMap.java
index 1ee8e51..5cd02c5 100644
--- a/test12/src/main/java/org/apache/myfaces/test/mock/_InitParameterMap.java
+++ b/test12/src/main/java/org/apache/myfaces/test/mock/_InitParameterMap.java
@@ -23,7 +23,6 @@
import javax.servlet.ServletContext;
-
/**
* ServletContext init parameters as Map.
*
@@ -50,14 +49,14 @@
protected void setAttribute(final String key, final String value)
{
throw new UnsupportedOperationException(
- "Cannot set ServletContext InitParameter");
+ "Cannot set ServletContext InitParameter");
}
@Override
protected void removeAttribute(final String key)
{
throw new UnsupportedOperationException(
- "Cannot remove ServletContext InitParameter");
+ "Cannot remove ServletContext InitParameter");
}
@Override
@@ -66,14 +65,13 @@
{
return _servletContext.getInitParameterNames();
}
-
+
@Override
public void putAll(final Map<? extends String, ? extends String> t)
{
throw new UnsupportedOperationException();
}
-
@Override
public void clear()
{
diff --git a/test12/src/main/java/org/apache/myfaces/test/mock/_RequestHeaderMap.java b/test12/src/main/java/org/apache/myfaces/test/mock/_RequestHeaderMap.java
index 21516cf..90466c1 100644
--- a/test12/src/main/java/org/apache/myfaces/test/mock/_RequestHeaderMap.java
+++ b/test12/src/main/java/org/apache/myfaces/test/mock/_RequestHeaderMap.java
@@ -23,7 +23,6 @@
import javax.servlet.http.HttpServletRequest;
-
/**
* HttpServletRequest headers as Map.
*
@@ -50,14 +49,14 @@
protected void setAttribute(final String key, final String value)
{
throw new UnsupportedOperationException(
- "Cannot set HttpServletRequest Header");
+ "Cannot set HttpServletRequest Header");
}
@Override
protected void removeAttribute(final String key)
{
throw new UnsupportedOperationException(
- "Cannot remove HttpServletRequest Header");
+ "Cannot remove HttpServletRequest Header");
}
@Override
@@ -73,10 +72,9 @@
throw new UnsupportedOperationException();
}
-
@Override
public void clear()
{
throw new UnsupportedOperationException();
- }
+ }
}
diff --git a/test12/src/main/java/org/apache/myfaces/test/mock/_RequestHeaderValuesMap.java b/test12/src/main/java/org/apache/myfaces/test/mock/_RequestHeaderValuesMap.java
index 8538306..2023532 100644
--- a/test12/src/main/java/org/apache/myfaces/test/mock/_RequestHeaderValuesMap.java
+++ b/test12/src/main/java/org/apache/myfaces/test/mock/_RequestHeaderValuesMap.java
@@ -50,7 +50,8 @@
String[] ret = _valueCache.get(key);
if (ret == null)
{
- _valueCache.put(key, ret = toArray(_httpServletRequest.getHeaders(key)));
+ _valueCache.put(key, ret = toArray(_httpServletRequest
+ .getHeaders(key)));
}
return ret;
@@ -59,13 +60,15 @@
@Override
protected void setAttribute(final String key, final String[] value)
{
- throw new UnsupportedOperationException("Cannot set HttpServletRequest HeaderValues");
+ throw new UnsupportedOperationException(
+ "Cannot set HttpServletRequest HeaderValues");
}
@Override
protected void removeAttribute(final String key)
{
- throw new UnsupportedOperationException("Cannot remove HttpServletRequest HeaderValues");
+ throw new UnsupportedOperationException(
+ "Cannot remove HttpServletRequest HeaderValues");
}
@Override
diff --git a/test12/src/main/java/org/apache/myfaces/test/mock/_RequestMap.java b/test12/src/main/java/org/apache/myfaces/test/mock/_RequestMap.java
index 6bb6686..366b689 100644
--- a/test12/src/main/java/org/apache/myfaces/test/mock/_RequestMap.java
+++ b/test12/src/main/java/org/apache/myfaces/test/mock/_RequestMap.java
@@ -23,7 +23,6 @@
import javax.servlet.ServletRequest;
-
/**
* ServletRequest attributes Map.
*
@@ -71,10 +70,9 @@
throw new UnsupportedOperationException();
}
-
@Override
public void clear()
{
throw new UnsupportedOperationException();
- }
+ }
}
diff --git a/test12/src/main/java/org/apache/myfaces/test/mock/_RequestParameterMap.java b/test12/src/main/java/org/apache/myfaces/test/mock/_RequestParameterMap.java
index 0ef21a6..2eecb47 100644
--- a/test12/src/main/java/org/apache/myfaces/test/mock/_RequestParameterMap.java
+++ b/test12/src/main/java/org/apache/myfaces/test/mock/_RequestParameterMap.java
@@ -48,14 +48,14 @@
protected void setAttribute(final String key, final String value)
{
throw new UnsupportedOperationException(
- "Cannot set ServletRequest Parameter");
+ "Cannot set ServletRequest Parameter");
}
@Override
protected void removeAttribute(final String key)
{
throw new UnsupportedOperationException(
- "Cannot remove ServletRequest Parameter");
+ "Cannot remove ServletRequest Parameter");
}
@Override
diff --git a/test12/src/main/java/org/apache/myfaces/test/mock/_RequestParameterValuesMap.java b/test12/src/main/java/org/apache/myfaces/test/mock/_RequestParameterValuesMap.java
index 9503514..fa34704 100644
--- a/test12/src/main/java/org/apache/myfaces/test/mock/_RequestParameterValuesMap.java
+++ b/test12/src/main/java/org/apache/myfaces/test/mock/_RequestParameterValuesMap.java
@@ -48,14 +48,14 @@
protected void setAttribute(final String key, final String[] value)
{
throw new UnsupportedOperationException(
- "Cannot set ServletRequest ParameterValues");
+ "Cannot set ServletRequest ParameterValues");
}
@Override
protected void removeAttribute(final String key)
{
throw new UnsupportedOperationException(
- "Cannot remove ServletRequest ParameterValues");
+ "Cannot remove ServletRequest ParameterValues");
}
@Override
diff --git a/test12/src/main/java/org/apache/myfaces/test/mock/_SessionMap.java b/test12/src/main/java/org/apache/myfaces/test/mock/_SessionMap.java
index 5d2ea43..64f2f47 100644
--- a/test12/src/main/java/org/apache/myfaces/test/mock/_SessionMap.java
+++ b/test12/src/main/java/org/apache/myfaces/test/mock/_SessionMap.java
@@ -24,7 +24,6 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
-
/**
* HttpSession attibutes as Map.
*
@@ -69,7 +68,8 @@
protected Enumeration<String> getAttributeNames()
{
final HttpSession httpSession = _getSession();
- return (httpSession == null) ? _NullEnumeration.instance() : httpSession.getAttributeNames();
+ return (httpSession == null) ? _NullEnumeration.instance()
+ : httpSession.getAttributeNames();
}
@Override
@@ -77,9 +77,9 @@
{
throw new UnsupportedOperationException();
}
-
+
// we can use public void clear() from super-class
-
+
private HttpSession _getSession()
{
return _httpRequest.getSession(false);
diff --git a/test12/src/main/java/org/apache/myfaces/test/mock/lifecycle/ApplyRequestValuesExecutor.java b/test12/src/main/java/org/apache/myfaces/test/mock/lifecycle/ApplyRequestValuesExecutor.java
index 0994882..ad162a1 100644
--- a/test12/src/main/java/org/apache/myfaces/test/mock/lifecycle/ApplyRequestValuesExecutor.java
+++ b/test12/src/main/java/org/apache/myfaces/test/mock/lifecycle/ApplyRequestValuesExecutor.java
@@ -28,13 +28,16 @@
* @author Nikolay Petrov
* @since 1.0.0
*/
-class ApplyRequestValuesExecutor implements PhaseExecutor {
- public boolean execute(FacesContext facesContext) {
- facesContext.getViewRoot().processDecodes(facesContext);
- return false;
- }
+class ApplyRequestValuesExecutor implements PhaseExecutor
+{
+ public boolean execute(FacesContext facesContext)
+ {
+ facesContext.getViewRoot().processDecodes(facesContext);
+ return false;
+ }
- public PhaseId getPhase() {
- return PhaseId.APPLY_REQUEST_VALUES;
- }
+ public PhaseId getPhase()
+ {
+ return PhaseId.APPLY_REQUEST_VALUES;
+ }
}
diff --git a/test12/src/main/java/org/apache/myfaces/test/mock/lifecycle/DefaultRestoreViewSupport.java b/test12/src/main/java/org/apache/myfaces/test/mock/lifecycle/DefaultRestoreViewSupport.java
index 0f7e212..d685d0b 100644
--- a/test12/src/main/java/org/apache/myfaces/test/mock/lifecycle/DefaultRestoreViewSupport.java
+++ b/test12/src/main/java/org/apache/myfaces/test/mock/lifecycle/DefaultRestoreViewSupport.java
@@ -42,7 +42,8 @@
private final Log log = LogFactory.getLog(DefaultRestoreViewSupport.class);
- public void processComponentBinding(FacesContext facesContext, UIComponent component)
+ public void processComponentBinding(FacesContext facesContext,
+ UIComponent component)
{
ValueExpression binding = component.getValueExpression("binding");
if (binding != null)
@@ -62,14 +63,16 @@
ExternalContext externalContext = facesContext.getExternalContext();
Map requestMap = externalContext.getRequestMap();
- String viewId = (String) requestMap.get(JAVAX_SERVLET_INCLUDE_PATH_INFO);
+ String viewId = (String) requestMap
+ .get(JAVAX_SERVLET_INCLUDE_PATH_INFO);
boolean traceEnabled = log.isTraceEnabled();
if (viewId != null)
{
if (traceEnabled)
{
- log.trace("Calculated viewId '" + viewId + "' from request param '" + JAVAX_SERVLET_INCLUDE_PATH_INFO
- + "'");
+ log.trace("Calculated viewId '" + viewId
+ + "' from request param '"
+ + JAVAX_SERVLET_INCLUDE_PATH_INFO + "'");
}
}
else
@@ -77,16 +80,19 @@
viewId = externalContext.getRequestPathInfo();
if (viewId != null && traceEnabled)
{
- log.trace("Calculated viewId '" + viewId + "' from request path info");
+ log.trace("Calculated viewId '" + viewId
+ + "' from request path info");
}
}
if (viewId == null)
{
- viewId = (String) requestMap.get(JAVAX_SERVLET_INCLUDE_SERVLET_PATH);
+ viewId = (String) requestMap
+ .get(JAVAX_SERVLET_INCLUDE_SERVLET_PATH);
if (viewId != null && traceEnabled)
{
- log.trace("Calculated viewId '" + viewId + "' from request param '"
+ log.trace("Calculated viewId '" + viewId
+ + "' from request param '"
+ JAVAX_SERVLET_INCLUDE_SERVLET_PATH + "'");
}
}
@@ -96,7 +102,8 @@
viewId = externalContext.getRequestServletPath();
if (viewId != null && traceEnabled)
{
- log.trace("Calculated viewId '" + viewId + "' from request servlet path");
+ log.trace("Calculated viewId '" + viewId
+ + "' from request servlet path");
}
}
diff --git a/test12/src/main/java/org/apache/myfaces/test/mock/lifecycle/InvokeApplicationExecutor.java b/test12/src/main/java/org/apache/myfaces/test/mock/lifecycle/InvokeApplicationExecutor.java
index 26f0cab..5a2ac10 100644
--- a/test12/src/main/java/org/apache/myfaces/test/mock/lifecycle/InvokeApplicationExecutor.java
+++ b/test12/src/main/java/org/apache/myfaces/test/mock/lifecycle/InvokeApplicationExecutor.java
@@ -28,13 +28,16 @@
* @author Nikolay Petrov
* @since 1.0.0
*/
-class InvokeApplicationExecutor implements PhaseExecutor {
- public boolean execute(FacesContext facesContext) {
- facesContext.getViewRoot().processApplication(facesContext);
- return false;
- }
+class InvokeApplicationExecutor implements PhaseExecutor
+{
+ public boolean execute(FacesContext facesContext)
+ {
+ facesContext.getViewRoot().processApplication(facesContext);
+ return false;
+ }
- public PhaseId getPhase() {
- return PhaseId.INVOKE_APPLICATION;
- }
+ public PhaseId getPhase()
+ {
+ return PhaseId.INVOKE_APPLICATION;
+ }
}
\ No newline at end of file
diff --git a/test12/src/main/java/org/apache/myfaces/test/mock/lifecycle/MockLifecycle.java b/test12/src/main/java/org/apache/myfaces/test/mock/lifecycle/MockLifecycle.java
index 7fd0aed..af4c3e2 100644
--- a/test12/src/main/java/org/apache/myfaces/test/mock/lifecycle/MockLifecycle.java
+++ b/test12/src/main/java/org/apache/myfaces/test/mock/lifecycle/MockLifecycle.java
@@ -32,15 +32,13 @@
* @since 1.0.0
*/
-public class MockLifecycle extends Lifecycle {
-
+public class MockLifecycle extends Lifecycle
+{
// ----------------------------------------------------- Mock Object Methods
-
// ------------------------------------------------------ Instance Variables
-
/**
* <p>List of event listeners for this instance.</p>
*/
@@ -50,126 +48,152 @@
public MockLifecycle()
{
- lifecycleExecutors = new PhaseExecutor[] {
- new RestoreViewExecutor(),
- new ApplyRequestValuesExecutor(),
- new ProcessValidationsExecutor(),
- new UpdateModelValuesExecutor(),
- new InvokeApplicationExecutor()
- };
+ lifecycleExecutors = new PhaseExecutor[] { new RestoreViewExecutor(),
+ new ApplyRequestValuesExecutor(),
+ new ProcessValidationsExecutor(),
+ new UpdateModelValuesExecutor(),
+ new InvokeApplicationExecutor() };
renderExecutor = new RenderResponseExecutor();
}
// ------------------------------------------------------- Lifecycle Methods
-
/** {@inheritDoc} */
- public void addPhaseListener(PhaseListener listener) {
+ public void addPhaseListener(PhaseListener listener)
+ {
- phaseListenerList.add(listener);
+ phaseListenerList.add(listener);
}
-
/** {@inheritDoc} */
- public void execute(FacesContext context) throws FacesException {
+ public void execute(FacesContext context) throws FacesException
+ {
- PhaseListenerManager phaseListenerMgr = new PhaseListenerManager(this, context, getPhaseListeners());
- for(int executorIndex = 0;executorIndex < lifecycleExecutors.length;executorIndex++) {
- if(executePhase(context, lifecycleExecutors[executorIndex], phaseListenerMgr)) {
+ PhaseListenerManager phaseListenerMgr = new PhaseListenerManager(this,
+ context, getPhaseListeners());
+ for (int executorIndex = 0; executorIndex < lifecycleExecutors.length; executorIndex++)
+ {
+ if (executePhase(context, lifecycleExecutors[executorIndex],
+ phaseListenerMgr))
+ {
return;
}
}
}
- private boolean executePhase(FacesContext facesContext, PhaseExecutor executor,
- PhaseListenerManager phaseListenerMgr) throws FacesException {
+ private boolean executePhase(FacesContext facesContext,
+ PhaseExecutor executor, PhaseListenerManager phaseListenerMgr)
+ throws FacesException
+ {
boolean skipFurtherProcessing = false;
- try {
+ try
+ {
phaseListenerMgr.informPhaseListenersBefore(executor.getPhase());
- if(isResponseComplete(facesContext, executor.getPhase(), true)) {
+ if (isResponseComplete(facesContext, executor.getPhase(), true))
+ {
// have to return right away
- return true;
+ return true;
}
- if(shouldRenderResponse(facesContext, executor.getPhase(), true)) {
- skipFurtherProcessing = true;
+ if (shouldRenderResponse(facesContext, executor.getPhase(), true))
+ {
+ skipFurtherProcessing = true;
}
- if(executor.execute(facesContext)) {
- return true;
+ if (executor.execute(facesContext))
+ {
+ return true;
}
- } finally {
+ }
+ finally
+ {
phaseListenerMgr.informPhaseListenersAfter(executor.getPhase());
}
-
if (isResponseComplete(facesContext, executor.getPhase(), false)
- || shouldRenderResponse(facesContext, executor.getPhase(), false)) {
- // since this phase is completed we don't need to return right away even if the response is completed
- skipFurtherProcessing = true;
+ || shouldRenderResponse(facesContext, executor.getPhase(),
+ false))
+ {
+ // since this phase is completed we don't need to return right away even if the response is completed
+ skipFurtherProcessing = true;
}
return skipFurtherProcessing;
}
-
/** {@inheritDoc} */
- public PhaseListener[] getPhaseListeners() {
+ public PhaseListener[] getPhaseListeners()
+ {
- return (PhaseListener[]) phaseListenerList.toArray(new PhaseListener[phaseListenerList.size()]);
+ return (PhaseListener[]) phaseListenerList
+ .toArray(new PhaseListener[phaseListenerList.size()]);
}
-
/** {@inheritDoc} */
- public void removePhaseListener(PhaseListener listener) {
+ public void removePhaseListener(PhaseListener listener)
+ {
- phaseListenerList.remove(listener);
+ phaseListenerList.remove(listener);
}
-
/** {@inheritDoc} */
- public void render(FacesContext context) throws FacesException {
+ public void render(FacesContext context) throws FacesException
+ {
- // if the response is complete we should not be invoking the phase listeners
- if(isResponseComplete(context, renderExecutor.getPhase(), true)) {
- return;
- }
-
- PhaseListenerManager phaseListenerMgr = new PhaseListenerManager(this, context, getPhaseListeners());
-
- try {
- phaseListenerMgr.informPhaseListenersBefore(renderExecutor.getPhase());
- // also possible that one of the listeners completed the response
- if(isResponseComplete(context, renderExecutor.getPhase(), true)) {
+ // if the response is complete we should not be invoking the phase listeners
+ if (isResponseComplete(context, renderExecutor.getPhase(), true))
+ {
return;
- }
+ }
- renderExecutor.execute(context);
- } finally {
- phaseListenerMgr.informPhaseListenersAfter(renderExecutor.getPhase());
- }
+ PhaseListenerManager phaseListenerMgr = new PhaseListenerManager(this,
+ context, getPhaseListeners());
+
+ try
+ {
+ phaseListenerMgr.informPhaseListenersBefore(renderExecutor
+ .getPhase());
+ // also possible that one of the listeners completed the response
+ if (isResponseComplete(context, renderExecutor.getPhase(), true))
+ {
+ return;
+ }
+
+ renderExecutor.execute(context);
+ }
+ finally
+ {
+ phaseListenerMgr.informPhaseListenersAfter(renderExecutor
+ .getPhase());
+ }
}
-
- private boolean isResponseComplete(FacesContext facesContext, PhaseId phase, boolean before) {
- boolean flag = false;
- if (facesContext.getResponseComplete()) {
+
+ private boolean isResponseComplete(FacesContext facesContext,
+ PhaseId phase, boolean before)
+ {
+ boolean flag = false;
+ if (facesContext.getResponseComplete())
+ {
flag = true;
}
return flag;
}
- private boolean shouldRenderResponse(FacesContext facesContext, PhaseId phase, boolean before) {
- boolean flag = false;
- if (facesContext.getRenderResponse()) {
- flag = true;
- }
- return flag;
- }
+ private boolean shouldRenderResponse(FacesContext facesContext,
+ PhaseId phase, boolean before)
+ {
+ boolean flag = false;
+ if (facesContext.getRenderResponse())
+ {
+ flag = true;
+ }
+ return flag;
+ }
}
diff --git a/test12/src/main/java/org/apache/myfaces/test/mock/lifecycle/MockLifecycleFactory.java b/test12/src/main/java/org/apache/myfaces/test/mock/lifecycle/MockLifecycleFactory.java
index aac8694..8a03824 100644
--- a/test12/src/main/java/org/apache/myfaces/test/mock/lifecycle/MockLifecycleFactory.java
+++ b/test12/src/main/java/org/apache/myfaces/test/mock/lifecycle/MockLifecycleFactory.java
@@ -31,60 +31,55 @@
* @since 1.0.0
*/
-public class MockLifecycleFactory extends LifecycleFactory {
-
+public class MockLifecycleFactory extends LifecycleFactory
+{
// ------------------------------------------------------------ Constructors
-
/**
* <p>Return a default instance.</p>
*/
- public MockLifecycleFactory() {
+ public MockLifecycleFactory()
+ {
lifecycles = new HashMap();
lifecycles.put(LifecycleFactory.DEFAULT_LIFECYCLE, new MockLifecycle());
}
-
// ----------------------------------------------------- Mock Object Methods
-
// ------------------------------------------------------ Instance Variables
-
/**
* <p>The set of Lifecycle instances registered with us.</p>
*/
private Map lifecycles = null;
-
// ------------------------------------------------ LifecycleFactory Methods
-
/** {@inheritDoc} */
- public void addLifecycle(String lifecycleId, Lifecycle lifecycle) {
+ public void addLifecycle(String lifecycleId, Lifecycle lifecycle)
+ {
lifecycles.put(lifecycleId, lifecycle);
}
-
/** {@inheritDoc} */
- public Lifecycle getLifecycle(String lifecycleId) {
+ public Lifecycle getLifecycle(String lifecycleId)
+ {
return (Lifecycle) lifecycles.get(lifecycleId);
}
-
/** {@inheritDoc} */
- public Iterator getLifecycleIds() {
+ public Iterator getLifecycleIds()
+ {
return lifecycles.keySet().iterator();
}
-
}
diff --git a/test12/src/main/java/org/apache/myfaces/test/mock/lifecycle/PhaseExecutor.java b/test12/src/main/java/org/apache/myfaces/test/mock/lifecycle/PhaseExecutor.java
index 44be724..54b7402 100644
--- a/test12/src/main/java/org/apache/myfaces/test/mock/lifecycle/PhaseExecutor.java
+++ b/test12/src/main/java/org/apache/myfaces/test/mock/lifecycle/PhaseExecutor.java
@@ -19,7 +19,6 @@
package org.apache.myfaces.test.mock.lifecycle;
-
import javax.faces.context.FacesContext;
import javax.faces.event.PhaseId;
@@ -30,20 +29,21 @@
* @since 1.0.0
*
*/
-interface PhaseExecutor {
-
- /**
- * Executes a phase of the JavaServer(tm) Faces lifecycle, like UpdateModelValues.
- * The <code>execute</code> method is called by the lifecylce implementation's private
- * <code>executePhase</code>.
- * @param facesContext The <code>FacesContext</code> for the current request we are processing
- * @return <code>true</code> if execution should be stopped
- */
- boolean execute(FacesContext facesContext);
-
- /**
- * Returns the <code>PhaseId</code> for which the implemented executor is invoked
- * @return
- */
- PhaseId getPhase();
+interface PhaseExecutor
+{
+
+ /**
+ * Executes a phase of the JavaServer(tm) Faces lifecycle, like UpdateModelValues.
+ * The <code>execute</code> method is called by the lifecylce implementation's private
+ * <code>executePhase</code>.
+ * @param facesContext The <code>FacesContext</code> for the current request we are processing
+ * @return <code>true</code> if execution should be stopped
+ */
+ boolean execute(FacesContext facesContext);
+
+ /**
+ * Returns the <code>PhaseId</code> for which the implemented executor is invoked
+ * @return
+ */
+ PhaseId getPhase();
}
\ No newline at end of file
diff --git a/test12/src/main/java/org/apache/myfaces/test/mock/lifecycle/PhaseListenerManager.java b/test12/src/main/java/org/apache/myfaces/test/mock/lifecycle/PhaseListenerManager.java
index 0aa2f34..7908334 100644
--- a/test12/src/main/java/org/apache/myfaces/test/mock/lifecycle/PhaseListenerManager.java
+++ b/test12/src/main/java/org/apache/myfaces/test/mock/lifecycle/PhaseListenerManager.java
@@ -35,64 +35,87 @@
* @author Stan Silvert
* @since 1.0.0
*/
-class PhaseListenerManager {
-
- private static final Log log = LogFactory.getLog(PhaseListenerManager.class);
-
+class PhaseListenerManager
+{
+
+ private static final Log log = LogFactory
+ .getLog(PhaseListenerManager.class);
+
private Lifecycle lifecycle;
private FacesContext facesContext;
private PhaseListener[] phaseListeners;
-
+
// Tracks success in the beforePhase. Listeners that throw an exception
// in beforePhase or were never called because a previous listener threw
// an exception should not have its afterPhase called
//private Map<PhaseId, boolean[]> listenerSuccessMap = new HashMap<PhaseId, boolean[]>();
private Map listenerSuccessMap = new HashMap();
-
+
/** Creates a new instance of PhaseListenerManager */
- PhaseListenerManager(Lifecycle lifecycle, FacesContext facesContext, PhaseListener[] phaseListeners) {
+ PhaseListenerManager(Lifecycle lifecycle, FacesContext facesContext,
+ PhaseListener[] phaseListeners)
+ {
this.lifecycle = lifecycle;
this.facesContext = facesContext;
this.phaseListeners = phaseListeners;
}
-
- private boolean isListenerForThisPhase(PhaseListener phaseListener, PhaseId phaseId) {
+
+ private boolean isListenerForThisPhase(PhaseListener phaseListener,
+ PhaseId phaseId)
+ {
int listenerPhaseId = phaseListener.getPhaseId().getOrdinal();
- return (listenerPhaseId == PhaseId.ANY_PHASE.getOrdinal() ||
- listenerPhaseId == phaseId.getOrdinal());
+ return (listenerPhaseId == PhaseId.ANY_PHASE.getOrdinal() || listenerPhaseId == phaseId
+ .getOrdinal());
}
-
- void informPhaseListenersBefore(PhaseId phaseId) {
+
+ void informPhaseListenersBefore(PhaseId phaseId)
+ {
boolean[] beforePhaseSuccess = new boolean[phaseListeners.length];
listenerSuccessMap.put(phaseId, beforePhaseSuccess);
-
- for (int i = 0; i < phaseListeners.length; i++) {
+
+ for (int i = 0; i < phaseListeners.length; i++)
+ {
PhaseListener phaseListener = phaseListeners[i];
- if (isListenerForThisPhase(phaseListener, phaseId)) {
- try {
- phaseListener.beforePhase(new PhaseEvent(facesContext, phaseId, lifecycle));
+ if (isListenerForThisPhase(phaseListener, phaseId))
+ {
+ try
+ {
+ phaseListener.beforePhase(new PhaseEvent(facesContext,
+ phaseId, lifecycle));
beforePhaseSuccess[i] = true;
- } catch (Exception e) {
+ }
+ catch (Exception e)
+ {
beforePhaseSuccess[i] = false; // redundant - for clarity
- log.error("Exception in PhaseListener " + phaseId.toString() + " beforePhase.", e);
+ log.error("Exception in PhaseListener "
+ + phaseId.toString() + " beforePhase.", e);
return;
}
}
}
}
- void informPhaseListenersAfter(PhaseId phaseId) {
+ void informPhaseListenersAfter(PhaseId phaseId)
+ {
//boolean[] beforePhaseSuccess = listenerSuccessMap.get(phaseId);
- boolean[] beforePhaseSuccess = (boolean[]) listenerSuccessMap.get(phaseId);
-
- for (int i = phaseListeners.length - 1; i >= 0; i--) {
+ boolean[] beforePhaseSuccess = (boolean[]) listenerSuccessMap
+ .get(phaseId);
+
+ for (int i = phaseListeners.length - 1; i >= 0; i--)
+ {
PhaseListener phaseListener = phaseListeners[i];
- if (isListenerForThisPhase(phaseListener, phaseId)
- && beforePhaseSuccess[i]) {
- try {
- phaseListener.afterPhase(new PhaseEvent(facesContext, phaseId, lifecycle));
- } catch (Exception e) {
- log.error("Exception in PhaseListener " + phaseId.toString() + " afterPhase", e);
+ if (isListenerForThisPhase(phaseListener, phaseId)
+ && beforePhaseSuccess[i])
+ {
+ try
+ {
+ phaseListener.afterPhase(new PhaseEvent(facesContext,
+ phaseId, lifecycle));
+ }
+ catch (Exception e)
+ {
+ log.error("Exception in PhaseListener "
+ + phaseId.toString() + " afterPhase", e);
}
}
}
diff --git a/test12/src/main/java/org/apache/myfaces/test/mock/lifecycle/ProcessValidationsExecutor.java b/test12/src/main/java/org/apache/myfaces/test/mock/lifecycle/ProcessValidationsExecutor.java
index 5168513..1d0b573 100644
--- a/test12/src/main/java/org/apache/myfaces/test/mock/lifecycle/ProcessValidationsExecutor.java
+++ b/test12/src/main/java/org/apache/myfaces/test/mock/lifecycle/ProcessValidationsExecutor.java
@@ -27,13 +27,16 @@
* @author Nikolay Petrov
* @since 1.0.0
*/
-class ProcessValidationsExecutor implements PhaseExecutor {
- public boolean execute(FacesContext facesContext) {
- facesContext.getViewRoot().processValidators(facesContext);
- return false;
- }
+class ProcessValidationsExecutor implements PhaseExecutor
+{
+ public boolean execute(FacesContext facesContext)
+ {
+ facesContext.getViewRoot().processValidators(facesContext);
+ return false;
+ }
- public PhaseId getPhase() {
- return PhaseId.PROCESS_VALIDATIONS;
- }
+ public PhaseId getPhase()
+ {
+ return PhaseId.PROCESS_VALIDATIONS;
+ }
}
\ No newline at end of file
diff --git a/test12/src/main/java/org/apache/myfaces/test/mock/lifecycle/RenderResponseExecutor.java b/test12/src/main/java/org/apache/myfaces/test/mock/lifecycle/RenderResponseExecutor.java
index d5ac11b..867c03e 100644
--- a/test12/src/main/java/org/apache/myfaces/test/mock/lifecycle/RenderResponseExecutor.java
+++ b/test12/src/main/java/org/apache/myfaces/test/mock/lifecycle/RenderResponseExecutor.java
@@ -33,20 +33,26 @@
* @author Nikolay Petrov
* @since 1.0.0
*/
-class RenderResponseExecutor implements PhaseExecutor {
- public boolean execute(FacesContext facesContext) {
- Application application = facesContext.getApplication();
- ViewHandler viewHandler = application.getViewHandler();
+class RenderResponseExecutor implements PhaseExecutor
+{
+ public boolean execute(FacesContext facesContext)
+ {
+ Application application = facesContext.getApplication();
+ ViewHandler viewHandler = application.getViewHandler();
- try {
- viewHandler.renderView(facesContext, facesContext.getViewRoot());
- } catch (IOException e) {
- throw new FacesException(e.getMessage(), e);
+ try
+ {
+ viewHandler.renderView(facesContext, facesContext.getViewRoot());
+ }
+ catch (IOException e)
+ {
+ throw new FacesException(e.getMessage(), e);
+ }
+ return false;
}
- return false;
- }
- public PhaseId getPhase() {
- return PhaseId.RENDER_RESPONSE;
- }
+ public PhaseId getPhase()
+ {
+ return PhaseId.RENDER_RESPONSE;
+ }
}
\ No newline at end of file
diff --git a/test12/src/main/java/org/apache/myfaces/test/mock/lifecycle/RestoreViewExecutor.java b/test12/src/main/java/org/apache/myfaces/test/mock/lifecycle/RestoreViewExecutor.java
index eb92ebf..d613dae 100644
--- a/test12/src/main/java/org/apache/myfaces/test/mock/lifecycle/RestoreViewExecutor.java
+++ b/test12/src/main/java/org/apache/myfaces/test/mock/lifecycle/RestoreViewExecutor.java
@@ -58,13 +58,14 @@
UIViewRoot viewRoot = facesContext.getViewRoot();
RestoreViewSupport restoreViewSupport = getRestoreViewSupport();
-
+
if (viewRoot != null)
{
if (log.isTraceEnabled())
log.trace("View already exists in the FacesContext");
- viewRoot.setLocale(facesContext.getExternalContext().getRequestLocale());
+ viewRoot.setLocale(facesContext.getExternalContext()
+ .getRequestLocale());
restoreViewSupport.processComponentBinding(facesContext, viewRoot);
return false;
}
@@ -80,15 +81,17 @@
viewRoot = viewHandler.restoreView(facesContext, viewId);
if (viewRoot == null)
{
- throw new ViewExpiredException("The expected view was not returned " + "for the view identifier: "
- + viewId, viewId);
+ throw new ViewExpiredException(
+ "The expected view was not returned "
+ + "for the view identifier: " + viewId, viewId);
}
restoreViewSupport.processComponentBinding(facesContext, viewRoot);
}
else
{
if (log.isTraceEnabled())
- log.trace("Request is not a postback. New UIViewRoot will be created");
+ log
+ .trace("Request is not a postback. New UIViewRoot will be created");
viewRoot = viewHandler.createView(facesContext, viewId);
facesContext.renderResponse();
@@ -129,32 +132,36 @@
{
ExternalContext externalContext = facesContext.getExternalContext();
-// if (PortletUtil.isPortletRequest(facesContext))
-// {
-// PortletRequest request = (PortletRequest) externalContext.getRequest();
-// return request.getParameter(MyFacesGenericPortlet.VIEW_ID);
-// }
-//
+ // if (PortletUtil.isPortletRequest(facesContext))
+ // {
+ // PortletRequest request = (PortletRequest) externalContext.getRequest();
+ // return request.getParameter(MyFacesGenericPortlet.VIEW_ID);
+ // }
+ //
String viewId = externalContext.getRequestPathInfo(); // getPathInfo
if (viewId == null)
{
// No extra path info found, so it is propably extension mapping
viewId = externalContext.getRequestServletPath(); // getServletPath
-// DebugUtils.assertError(viewId != null, log,
-// "RequestServletPath is null, cannot determine viewId of current page.");
+ // DebugUtils.assertError(viewId != null, log,
+ // "RequestServletPath is null, cannot determine viewId of current page.");
if (viewId == null)
return null;
// TODO: JSF Spec 2.2.1 - what do they mean by "if the default
// ViewHandler implementation is used..." ?
- String defaultSuffix = externalContext.getInitParameter(ViewHandler.DEFAULT_SUFFIX_PARAM_NAME);
- String suffix = defaultSuffix != null ? defaultSuffix : ViewHandler.DEFAULT_SUFFIX;
-// DebugUtils.assertError(suffix.charAt(0) == '.', log, "Default suffix must start with a dot!");
+ String defaultSuffix = externalContext
+ .getInitParameter(ViewHandler.DEFAULT_SUFFIX_PARAM_NAME);
+ String suffix = defaultSuffix != null ? defaultSuffix
+ : ViewHandler.DEFAULT_SUFFIX;
+ // DebugUtils.assertError(suffix.charAt(0) == '.', log, "Default suffix must start with a dot!");
int dot = viewId.lastIndexOf('.');
if (dot == -1)
{
- log.error("Assumed extension mapping, but there is no extension in " + viewId);
+ log
+ .error("Assumed extension mapping, but there is no extension in "
+ + viewId);
viewId = null;
}
else
diff --git a/test12/src/main/java/org/apache/myfaces/test/mock/lifecycle/RestoreViewSupport.java b/test12/src/main/java/org/apache/myfaces/test/mock/lifecycle/RestoreViewSupport.java
index d233de3..f67d34b 100644
--- a/test12/src/main/java/org/apache/myfaces/test/mock/lifecycle/RestoreViewSupport.java
+++ b/test12/src/main/java/org/apache/myfaces/test/mock/lifecycle/RestoreViewSupport.java
@@ -54,7 +54,8 @@
* @param component
* the root component
*/
- void processComponentBinding(FacesContext facesContext, UIComponent component);
+ void processComponentBinding(FacesContext facesContext,
+ UIComponent component);
/**
* <p>
diff --git a/test12/src/main/java/org/apache/myfaces/test/mock/lifecycle/UpdateModelValuesExecutor.java b/test12/src/main/java/org/apache/myfaces/test/mock/lifecycle/UpdateModelValuesExecutor.java
index f6b3780..b8c24d7 100644
--- a/test12/src/main/java/org/apache/myfaces/test/mock/lifecycle/UpdateModelValuesExecutor.java
+++ b/test12/src/main/java/org/apache/myfaces/test/mock/lifecycle/UpdateModelValuesExecutor.java
@@ -20,7 +20,6 @@
import javax.faces.context.FacesContext;
import javax.faces.event.PhaseId;
-
/**
* Implements the lifecycle as described in Spec. 1.0 PFD Chapter 2
*
@@ -29,13 +28,16 @@
* @author Nikolay Petrov
* @since 1.0.0
*/
-class UpdateModelValuesExecutor implements PhaseExecutor {
- public boolean execute(FacesContext facesContext) {
- facesContext.getViewRoot().processUpdates(facesContext);
- return false;
- }
+class UpdateModelValuesExecutor implements PhaseExecutor
+{
+ public boolean execute(FacesContext facesContext)
+ {
+ facesContext.getViewRoot().processUpdates(facesContext);
+ return false;
+ }
- public PhaseId getPhase() {
- return PhaseId.UPDATE_MODEL_VALUES;
- }
+ public PhaseId getPhase()
+ {
+ return PhaseId.UPDATE_MODEL_VALUES;
+ }
}
\ No newline at end of file
diff --git a/test12/src/test/java/org/apache/myfaces/test/config/ConfigParserTestCase.java b/test12/src/test/java/org/apache/myfaces/test/config/ConfigParserTestCase.java
index 03c8177..473e67c 100644
--- a/test12/src/test/java/org/apache/myfaces/test/config/ConfigParserTestCase.java
+++ b/test12/src/test/java/org/apache/myfaces/test/config/ConfigParserTestCase.java
@@ -32,59 +32,55 @@
/**
* <p>Unit tests for the configuration parser utility class.</p>
*/
-public class ConfigParserTestCase extends AbstractJsfTestCase {
-
+public class ConfigParserTestCase extends AbstractJsfTestCase
+{
// ------------------------------------------------------------ Constructors
-
// Construct a new instance of this test case.
- public ConfigParserTestCase(String name) {
+ public ConfigParserTestCase(String name)
+ {
super(name);
}
-
// ---------------------------------------------------- Overall Test Methods
-
// Set up instance variables required by this test case.
- protected void setUp() throws Exception {
+ protected void setUp() throws Exception
+ {
super.setUp();
parser = new ConfigParser();
}
-
// Return the tests included in this test case.
- public static Test suite() {
+ public static Test suite()
+ {
return (new TestSuite(ConfigParserTestCase.class));
}
-
// Tear down instance variables required by this test case.
- protected void tearDown() throws Exception {
+ protected void tearDown() throws Exception
+ {
parser = null;
super.tearDown();
}
-
// ------------------------------------------------------ Instance Variables
-
// ConfigParser instance under test
ConfigParser parser = null;
-
// ------------------------------------------------- Individual Test Methods
-
// Test access to the platform configuration resources
- public void testPlatform() throws Exception {
+ public void testPlatform() throws Exception
+ {
// Make sure we can acquire a good set of URLs
URL[] urls = parser.getPlatformURLs();
@@ -97,19 +93,20 @@
}
-
// Test a pristine instance
- public void testPristine() {
+ public void testPristine()
+ {
assertNotNull(parser);
}
-
// Test loading a simple configuration resource
- public void testSimple() throws Exception {
+ public void testSimple() throws Exception
+ {
- URL url = this.getClass().getResource("/org/apache/myfaces/test/config/faces-config-1.xml");
+ URL url = this.getClass().getResource(
+ "/org/apache/myfaces/test/config/faces-config-1.xml");
assertNotNull(url);
parser.parse(url);
Iterator items = null;
@@ -117,7 +114,8 @@
items = application.getComponentTypes();
list.clear();
- while (items.hasNext()) {
+ while (items.hasNext())
+ {
list.add(items.next());
}
assertTrue(list.contains("component-type-1"));
@@ -125,7 +123,8 @@
items = application.getConverterIds();
list.clear();
- while (items.hasNext()) {
+ while (items.hasNext())
+ {
list.add(items.next());
}
assertTrue(list.contains("converter-id-1"));
@@ -137,24 +136,25 @@
items = application.getValidatorIds();
list.clear();
- while (items.hasNext()) {
+ while (items.hasNext())
+ {
list.add(items.next());
}
assertTrue(list.contains("validator-id-1"));
assertTrue(list.contains("validator-id-2"));
- Renderer renderer = renderKit.getRenderer("component-family-1", "renderer-type-1");
+ Renderer renderer = renderKit.getRenderer("component-family-1",
+ "renderer-type-1");
assertNotNull(renderer);
assertTrue(renderer instanceof MyRenderer);
-
- renderer = renderKit.getRenderer("component-family-2", "renderer-type-2");
+
+ renderer = renderKit.getRenderer("component-family-2",
+ "renderer-type-2");
assertNotNull(renderer);
assertTrue(renderer instanceof MyRenderer);
-
+
}
-
// --------------------------------------------------------- Private Methods
-
}
diff --git a/test12/src/test/java/org/apache/myfaces/test/config/MyConverter.java b/test12/src/test/java/org/apache/myfaces/test/config/MyConverter.java
index bf19f1e..ea9b27b 100644
--- a/test12/src/test/java/org/apache/myfaces/test/config/MyConverter.java
+++ b/test12/src/test/java/org/apache/myfaces/test/config/MyConverter.java
@@ -24,13 +24,18 @@
/**
* <p>Concrete converter implementation for testing.</p>
*/
-public class MyConverter implements Converter {
+public class MyConverter implements Converter
+{
- public Object getAsObject(FacesContext context, UIComponent component, String value) {
+ public Object getAsObject(FacesContext context, UIComponent component,
+ String value)
+ {
throw new UnsupportedOperationException();
}
- public String getAsString(FacesContext context, UIComponent component, Object value) {
+ public String getAsString(FacesContext context, UIComponent component,
+ Object value)
+ {
throw new UnsupportedOperationException();
}
diff --git a/test12/src/test/java/org/apache/myfaces/test/config/MyRenderer.java b/test12/src/test/java/org/apache/myfaces/test/config/MyRenderer.java
index 20d6745..0df341d 100644
--- a/test12/src/test/java/org/apache/myfaces/test/config/MyRenderer.java
+++ b/test12/src/test/java/org/apache/myfaces/test/config/MyRenderer.java
@@ -22,6 +22,7 @@
/**
* <p>Concrete renderer implementation for testing.</p>
*/
-public class MyRenderer extends Renderer {
-
+public class MyRenderer extends Renderer
+{
+
}
diff --git a/test12/src/test/java/org/apache/myfaces/test/el/MockExpressionFactoryTestCase.java b/test12/src/test/java/org/apache/myfaces/test/el/MockExpressionFactoryTestCase.java
index 5d446e8..a272aaa 100644
--- a/test12/src/test/java/org/apache/myfaces/test/el/MockExpressionFactoryTestCase.java
+++ b/test12/src/test/java/org/apache/myfaces/test/el/MockExpressionFactoryTestCase.java
@@ -30,155 +30,118 @@
/**
* <p>Test case for <code>MockExpressionFactory.</p>
*/
-public class MockExpressionFactoryTestCase extends AbstractJsfTestCase {
-
+public class MockExpressionFactoryTestCase extends AbstractJsfTestCase
+{
// ------------------------------------------------------------ Constructors
-
// Construct a new instance of this test case.
- public MockExpressionFactoryTestCase(String name) {
+ public MockExpressionFactoryTestCase(String name)
+ {
super(name);
}
-
// ---------------------------------------------------- Overall Test Methods
-
// Set up instance variables required by this test case.
- protected void setUp() throws Exception {
+ protected void setUp() throws Exception
+ {
super.setUp();
- factory = (MockExpressionFactory)
- ((MockApplication12) application).getExpressionFactory();
+ factory = (MockExpressionFactory) ((MockApplication12) application)
+ .getExpressionFactory();
}
-
// Return the tests included in this test case.
- public static Test suite() {
+ public static Test suite()
+ {
return (new TestSuite(MockExpressionFactoryTestCase.class));
}
-
// Tear down instance variables required by this test case.
- protected void tearDown() throws Exception {
+ protected void tearDown() throws Exception
+ {
factory = null;
super.tearDown();
}
-
// -------------------------------------------------------- Static Variables
-
/**
* <p>Input values to be converted, of all the interesting types.</p>
*/
- private static final Object[] INPUT_VALUES = {
- (String) null,
- "",
- "1234",
- Boolean.TRUE,
- Boolean.FALSE,
- new Byte((byte) 123),
- new Double(234),
- new Float(345),
- new Integer(456),
- new Long(567),
- new Short((short) 678),
- };
-
+ private static final Object[] INPUT_VALUES = { (String) null, "", "1234",
+ Boolean.TRUE, Boolean.FALSE, new Byte((byte) 123), new Double(234),
+ new Float(345), new Integer(456), new Long(567),
+ new Short((short) 678), };
/**
* <p>Output values when converted to Boolean.</p>
*/
- private static final Boolean[] OUTPUT_BOOLEAN = {
- Boolean.FALSE,
- Boolean.FALSE,
- Boolean.FALSE,
- Boolean.TRUE,
- Boolean.FALSE,
- null,
- null,
- null,
- null,
- null,
- null
- };
-
+ private static final Boolean[] OUTPUT_BOOLEAN = { Boolean.FALSE,
+ Boolean.FALSE, Boolean.FALSE, Boolean.TRUE, Boolean.FALSE, null,
+ null, null, null, null, null };
/**
* <p>Output values when converted to Integer.</p>
*/
- private static final Integer[] OUTPUT_INTEGER = {
- new Integer(0),
- new Integer(0),
- new Integer(1234),
- new Integer(1),
- new Integer(0),
- new Integer(123),
- new Integer(234),
- new Integer(345),
- new Integer(456),
- new Integer(567),
- new Integer(678)
- };
-
+ private static final Integer[] OUTPUT_INTEGER = { new Integer(0),
+ new Integer(0), new Integer(1234), new Integer(1), new Integer(0),
+ new Integer(123), new Integer(234), new Integer(345),
+ new Integer(456), new Integer(567), new Integer(678) };
/**
* <p>Output values when converted to String.</p>
*/
- private static final String[] OUTPUT_STRING = {
- "",
- "",
- "1234",
- "true",
- "false",
- "123",
- "234.0",
- "345.0",
- "456",
- "567",
- "678"
- };
-
+ private static final String[] OUTPUT_STRING = { "", "", "1234", "true",
+ "false", "123", "234.0", "345.0", "456", "567", "678" };
// ------------------------------------------------------ Instance Variables
-
/**
* <p>The expression factory to be tested.</p>
*/
private MockExpressionFactory factory = null;
-
// ------------------------------------------------- Individual Test Methods
-
// Test coercion when expectedType is passed as Boolean.
- public void testCoerceToBoolean() {
+ public void testCoerceToBoolean()
+ {
Object result = null;
- for (int i = 0; i < INPUT_VALUES.length; i++) {
- try {
+ for (int i = 0; i < INPUT_VALUES.length; i++)
+ {
+ try
+ {
result = factory.coerceToType(INPUT_VALUES[i], Boolean.class);
if ((INPUT_VALUES[i] == null)
- || (INPUT_VALUES[i] instanceof String)
- || (INPUT_VALUES[i] instanceof Boolean)) {
+ || (INPUT_VALUES[i] instanceof String)
+ || (INPUT_VALUES[i] instanceof Boolean))
+ {
assertEquals("[" + i + "]", OUTPUT_BOOLEAN[i], result);
- } else {
- fail("[" + i + "] should have thrown IllegalArgumentException");
}
- } catch (IllegalArgumentException e) {
+ else
+ {
+ fail("[" + i
+ + "] should have thrown IllegalArgumentException");
+ }
+ }
+ catch (IllegalArgumentException e)
+ {
if ((INPUT_VALUES[i] == null)
- || (INPUT_VALUES[i] instanceof String)
- || (INPUT_VALUES[i] instanceof Boolean)) {
+ || (INPUT_VALUES[i] instanceof String)
+ || (INPUT_VALUES[i] instanceof Boolean))
+ {
fail("[" + i + "] threw IllegalArgumentException");
- } else {
+ }
+ else
+ {
; // Expected result
}
}
@@ -186,161 +149,194 @@
}
-
// Test coercion when expectedType is passed as null. We should
// get the original object back
- public void testCoerceToNull() {
+ public void testCoerceToNull()
+ {
Object result = null;
- for (int i = 0; i < INPUT_VALUES.length; i++) {
+ for (int i = 0; i < INPUT_VALUES.length; i++)
+ {
result = factory.coerceToType(INPUT_VALUES[i], null);
- if (INPUT_VALUES[i] == null) {
+ if (INPUT_VALUES[i] == null)
+ {
assertNull(result);
- } else {
+ }
+ else
+ {
assertTrue("[" + i + "]", result == INPUT_VALUES[i]);
}
}
}
-
// Test coercion when expectedType is Object. We should
// get the original object back.
- public void testCoerceToObject() {
+ public void testCoerceToObject()
+ {
Object result = null;
- for (int i = 0; i < INPUT_VALUES.length; i++) {
+ for (int i = 0; i < INPUT_VALUES.length; i++)
+ {
result = factory.coerceToType(INPUT_VALUES[i], Object.class);
- if (INPUT_VALUES[i] == null) {
+ if (INPUT_VALUES[i] == null)
+ {
assertNull(result);
- } else {
+ }
+ else
+ {
assertTrue("[" + i + "]", result == INPUT_VALUES[i]);
}
}
}
-
// Test coercion when expectedType is Integer
- public void testCoerceToInteger() {
+ public void testCoerceToInteger()
+ {
Object result = null;
- for (int i = 0; i < INPUT_VALUES.length; i++) {
- try {
+ for (int i = 0; i < INPUT_VALUES.length; i++)
+ {
+ try
+ {
result = factory.coerceToType(INPUT_VALUES[i], Integer.class);
if ((INPUT_VALUES[i] != null)
- && (INPUT_VALUES[i] instanceof Boolean)) {
- fail("[" + i + "] should have thrown IllegalArgumentException");
- } else {
+ && (INPUT_VALUES[i] instanceof Boolean))
+ {
+ fail("[" + i
+ + "] should have thrown IllegalArgumentException");
+ }
+ else
+ {
assertEquals("[" + i + "]", OUTPUT_INTEGER[i], result);
}
- } catch (IllegalArgumentException e) {
+ }
+ catch (IllegalArgumentException e)
+ {
if ((INPUT_VALUES[i] != null)
- && (INPUT_VALUES[i] instanceof Boolean)) {
+ && (INPUT_VALUES[i] instanceof Boolean))
+ {
; // Expected result
- } else {
- fail("[" + i + "] should have thrown IllegalArgumentException");
+ }
+ else
+ {
+ fail("[" + i
+ + "] should have thrown IllegalArgumentException");
}
}
}
}
-
// Test coercion when expectedType is String.
- public void testCoerceToString() {
+ public void testCoerceToString()
+ {
Object result = null;
- for (int i = 0; i < INPUT_VALUES.length; i++) {
+ for (int i = 0; i < INPUT_VALUES.length; i++)
+ {
result = factory.coerceToType(INPUT_VALUES[i], String.class);
assertEquals("[" + i + "]", OUTPUT_STRING[i], result);
}
}
-
// Test ValueExpression that wraps a literal String object and conversion to Integer
- public void testLiteralValueExpressionInteger() {
+ public void testLiteralValueExpressionInteger()
+ {
ELContext context = facesContext.getELContext();
- ValueExpression expr = factory.createValueExpression("123", Integer.class);
+ ValueExpression expr = factory.createValueExpression("123",
+ Integer.class);
assertEquals(Integer.class, expr.getExpectedType());
assertEquals(String.class, expr.getType(context));
assertEquals(new Integer(123), expr.getValue(context));
assertTrue(expr.isLiteralText());
assertTrue(expr.isReadOnly(context));
- try {
+ try
+ {
expr.setValue(context, "234");
fail("Should have thrown PropertyNotWritableException");
- } catch (PropertyNotWritableException e) {
+ }
+ catch (PropertyNotWritableException e)
+ {
; // Expected result
}
}
-
// Test ValueExpression that wraps a literal String object and no conversion
- public void testLiteralValueExpressionNone() {
+ public void testLiteralValueExpressionNone()
+ {
ELContext context = facesContext.getELContext();
- ValueExpression expr = factory.createValueExpression("abc", String.class);
+ ValueExpression expr = factory.createValueExpression("abc",
+ String.class);
assertEquals(String.class, expr.getExpectedType());
assertEquals(String.class, expr.getType(context));
assertEquals("abc", expr.getValue(context));
assertTrue(expr.isLiteralText());
assertTrue(expr.isReadOnly(context));
- try {
+ try
+ {
expr.setValue(context, "def");
fail("Should have thrown PropertyNotWritableException");
- } catch (PropertyNotWritableException e) {
+ }
+ catch (PropertyNotWritableException e)
+ {
; // Expected result
}
}
-
// Test ValueExpression that wraps a literal Integer object and conversion to String
- public void testLiteralValueExpressionString() {
+ public void testLiteralValueExpressionString()
+ {
ELContext context = facesContext.getELContext();
- ValueExpression expr = factory.createValueExpression(new Integer(123), String.class);
+ ValueExpression expr = factory.createValueExpression(new Integer(123),
+ String.class);
assertEquals(String.class, expr.getExpectedType());
assertEquals(Integer.class, expr.getType(context));
assertEquals("123", expr.getValue(context));
assertTrue(expr.isLiteralText());
assertTrue(expr.isReadOnly(context));
- try {
+ try
+ {
expr.setValue(context, new Integer(234));
fail("Should have thrown PropertyNotWritableException");
- } catch (PropertyNotWritableException e) {
+ }
+ catch (PropertyNotWritableException e)
+ {
; // Expected result
}
}
-
// Test ValueExpression
- public void testValueExpressionString() {
+ public void testValueExpressionString()
+ {
request.setAttribute("org.apache.shale.test", new Integer(123));
ELContext context = facesContext.getELContext();
- ValueExpression expr = factory.createValueExpression(context, "#{requestScope['org.apache.shale.test']}", String.class);
+ ValueExpression expr = factory.createValueExpression(context,
+ "#{requestScope['org.apache.shale.test']}", String.class);
Object ref = expr.getValue(context);
assertNotNull(ref);
assertTrue(ref instanceof String);
assertEquals("123", ref);
}
- public void testPristine() {
+ public void testPristine()
+ {
assertNotNull(factory);
}
-
-
}
diff --git a/test12/src/test/java/org/apache/myfaces/test/el/MockValueExpressionTest.java b/test12/src/test/java/org/apache/myfaces/test/el/MockValueExpressionTest.java
index 65beab1..db4e74f 100644
--- a/test12/src/test/java/org/apache/myfaces/test/el/MockValueExpressionTest.java
+++ b/test12/src/test/java/org/apache/myfaces/test/el/MockValueExpressionTest.java
@@ -32,13 +32,13 @@
*/
public class MockValueExpressionTest extends AbstractJsfTestCase
{
-
- public MockValueExpressionTest(String name)
+
+ public MockValueExpressionTest(String name)
{
super(name);
}
- public void testSetValue()
+ public void testSetValue()
{
// set value of #{foo} to BAR via ValueExpression
ELContext elContext = facesContext.getELContext();
@@ -48,7 +48,7 @@
assertEquals("BAR", externalContext.getRequestMap().get("foo"));
}
- public void testGetValue()
+ public void testGetValue()
{
// set value of #{foo} to BAR in request scope
externalContext.getRequestMap().put("foo", "BAR");
diff --git a/test12/src/test/java/org/apache/myfaces/test/mock/MockBean.java b/test12/src/test/java/org/apache/myfaces/test/mock/MockBean.java
index 2e05dda..01f98a8 100644
--- a/test12/src/test/java/org/apache/myfaces/test/mock/MockBean.java
+++ b/test12/src/test/java/org/apache/myfaces/test/mock/MockBean.java
@@ -24,37 +24,51 @@
*
* $Id$
*/
-public class MockBean implements Serializable {
+public class MockBean implements Serializable
+{
private static final long serialVersionUID = 8879968751506858610L;
private String command;
- public String getCommand() {
+
+ public String getCommand()
+ {
return (this.command);
}
- public void setCommand(String command) {
+
+ public void setCommand(String command)
+ {
this.command = command;
}
private String input;
- public String getInput() {
+
+ public String getInput()
+ {
return (this.input);
}
- public void setInput(String input) {
+
+ public void setInput(String input)
+ {
this.input = input;
}
private String output;
- public String getOutput() {
+
+ public String getOutput()
+ {
return (this.output);
}
- public void setOutput(String output) {
+
+ public void setOutput(String output)
+ {
this.output = output;
}
- public String combine() {
- return ((command == null ? "" : command) + ":" +
- (input == null ? "" : input) + ":" +
- (output == null ? "" : output));
+ public String combine()
+ {
+ return ((command == null ? "" : command) + ":"
+ + (input == null ? "" : input) + ":" + (output == null ? ""
+ : output));
}
}
diff --git a/test12/src/test/java/org/apache/myfaces/test/mock/MockHttpSessionTest.java b/test12/src/test/java/org/apache/myfaces/test/mock/MockHttpSessionTest.java
index 014f100..1faa0f3 100644
--- a/test12/src/test/java/org/apache/myfaces/test/mock/MockHttpSessionTest.java
+++ b/test12/src/test/java/org/apache/myfaces/test/mock/MockHttpSessionTest.java
@@ -32,32 +32,32 @@
public class MockHttpSessionTest extends AbstractJsfTestCase
{
- public static Test suite()
+ public static Test suite()
{
return (new TestSuite(MockHttpSessionTest.class));
}
-
+
private MockHttpSession session;
-
+
public MockHttpSessionTest(String name)
{
super(name);
}
-
- protected void setUp() throws Exception
+
+ protected void setUp() throws Exception
{
super.setUp();
-
+
session = new MockHttpSession();
}
- protected void tearDown() throws Exception
+ protected void tearDown() throws Exception
{
super.tearDown();
-
+
session = null;
}
-
+
/**
* Tests if the session is correctly invalidated.
*/
@@ -66,59 +66,59 @@
// first store a value in the session and retrieve it again
session.setAttribute("someAttribute", "someValue");
assertEquals("someValue", session.getAttribute("someAttribute"));
-
+
// invalidate the session
session.invalidate();
-
+
try
{
session.getAttribute("someAttribute");
fail("Session was already invalidated, getAttribute() has to throw an IllegalStateException.");
}
- catch(IllegalStateException e)
+ catch (IllegalStateException e)
{
// expected Exception
}
-
+
try
{
session.setAttribute("someAttribute", "anotherValue");
fail("Session was already invalidated, setAttribute() has to throw an IllegalStateException.");
}
- catch(IllegalStateException e)
+ catch (IllegalStateException e)
{
// expected Exception
}
-
+
try
{
session.removeAttribute("someAttribute");
fail("Session was already invalidated, removeAttribute() has to throw an IllegalStateException.");
}
- catch(IllegalStateException e)
+ catch (IllegalStateException e)
{
// expected Exception
}
-
+
try
{
session.invalidate();
fail("Session was already invalidated, invalidate() has to throw an IllegalStateException.");
}
- catch(IllegalStateException e)
+ catch (IllegalStateException e)
{
// expected Exception
}
-
+
try
{
session.getAttributeNames();
fail("Session was already invalidated, getAttributeNames() has to throw an IllegalStateException.");
}
- catch(IllegalStateException e)
+ catch (IllegalStateException e)
{
// expected Exception
}
}
-
+
}
diff --git a/test12/src/test/java/org/apache/myfaces/test/mock/MockObjectsTestCase.java b/test12/src/test/java/org/apache/myfaces/test/mock/MockObjectsTestCase.java
index 7721a75..93eae8c 100644
--- a/test12/src/test/java/org/apache/myfaces/test/mock/MockObjectsTestCase.java
+++ b/test12/src/test/java/org/apache/myfaces/test/mock/MockObjectsTestCase.java
@@ -29,23 +29,22 @@
* <p>Simple unit tests for Mock Objects that have behavior.</p>
*/
-public class MockObjectsTestCase extends AbstractJsfTestCase {
-
+public class MockObjectsTestCase extends AbstractJsfTestCase
+{
// ------------------------------------------------------------ Constructors
-
// Construct a new instance of this test case.
- public MockObjectsTestCase(String name) {
+ public MockObjectsTestCase(String name)
+ {
super(name);
}
-
// ---------------------------------------------------- Overall Test Methods
-
// Set up instance variables required by this test case.
- protected void setUp() throws Exception {
+ protected void setUp() throws Exception
+ {
super.setUp();
@@ -61,37 +60,34 @@
}
-
// Return the tests included in this test case.
- public static Test suite() {
+ public static Test suite()
+ {
return (new TestSuite(MockObjectsTestCase.class));
}
-
// Tear down instance variables required by this test case.
- protected void tearDown() throws Exception {
-
+ protected void tearDown() throws Exception
+ {
super.tearDown();
}
-
// ------------------------------------------------------ Instance Variables
-
// ------------------------------------------------- Individual Test Methods
-
- public void testMethodBindingGetTypePositive() throws Exception {
+ public void testMethodBindingGetTypePositive() throws Exception
+ {
Class argsString[] = new Class[] { String.class };
Class argsNone[] = new Class[0];
checkMethodBindingGetType("test.getCommand", argsNone, String.class);
- checkMethodBindingGetType("test.setCommand", argsString, null);
+ checkMethodBindingGetType("test.setCommand", argsString, null);
checkMethodBindingGetType("test.getInput", argsNone, String.class);
checkMethodBindingGetType("test.setInput", argsString, null);
checkMethodBindingGetType("test.getOutput", argsNone, String.class);
@@ -100,8 +96,8 @@
}
-
- public void testMethodBindingInvokePositive() throws Exception {
+ public void testMethodBindingInvokePositive() throws Exception
+ {
MockBean bean = (MockBean) request.getAttribute("test");
MethodBinding mb = null;
@@ -124,9 +120,9 @@
}
-
// Positive tests for ValueBinding.getValue()
- public void testValueBindingGetValuePositive() throws Exception {
+ public void testValueBindingGetValuePositive() throws Exception
+ {
// Implicit search
checkValueBindingGetValue("appScopeName", "appScopeValue");
@@ -136,23 +132,18 @@
// Explicit scope search
checkValueBindingGetValue("applicationScope.appScopeName",
- "appScopeValue");
- checkValueBindingGetValue("applicationScope.sameKey",
- "sameKeyAppValue");
- checkValueBindingGetValue("sessionScope.sesScopeName",
- "sesScopeValue");
- checkValueBindingGetValue("sessionScope.sameKey",
- "sameKeySesValue");
- checkValueBindingGetValue("requestScope.reqScopeName",
- "reqScopeValue");
- checkValueBindingGetValue("requestScope.sameKey",
- "sameKeyReqValue");
+ "appScopeValue");
+ checkValueBindingGetValue("applicationScope.sameKey", "sameKeyAppValue");
+ checkValueBindingGetValue("sessionScope.sesScopeName", "sesScopeValue");
+ checkValueBindingGetValue("sessionScope.sameKey", "sameKeySesValue");
+ checkValueBindingGetValue("requestScope.reqScopeName", "reqScopeValue");
+ checkValueBindingGetValue("requestScope.sameKey", "sameKeyReqValue");
}
-
// Positive tests for ValueBinding.putValue()
- public void testValueBindingPutValuePositive() throws Exception {
+ public void testValueBindingPutValuePositive() throws Exception
+ {
ValueBinding vb = null;
@@ -216,34 +207,29 @@
assertEquals("sameKeySesValue", session.getAttribute("sameKey"));
assertEquals("sameKeyNewValue", request.getAttribute("sameKey"));
-
}
-
// --------------------------------------------------------- Private Methods
-
private void checkMethodBindingGetType(String ref, Class params[],
- Class expected) throws Exception {
+ Class expected) throws Exception
+ {
MethodBinding mb = application.createMethodBinding(ref, params);
assertNotNull("MethodBinding[" + ref + "] exists", mb);
- assertEquals("MethodBinding[" + ref + "] type",
- expected,
- mb.getType(facesContext));
+ assertEquals("MethodBinding[" + ref + "] type", expected, mb
+ .getType(facesContext));
}
-
- private void checkValueBindingGetValue(String ref, Object expected) {
+ private void checkValueBindingGetValue(String ref, Object expected)
+ {
ValueBinding vb = application.createValueBinding(ref);
assertNotNull("ValueBinding[" + ref + "] exists", vb);
- assertEquals("ValueBinding[" + ref + "] value",
- expected,
- vb.getValue(facesContext));
+ assertEquals("ValueBinding[" + ref + "] value", expected, vb
+ .getValue(facesContext));
}
-
}
diff --git a/test12/src/test/java/org/apache/myfaces/test/mock/ValueBindingTest.java b/test12/src/test/java/org/apache/myfaces/test/mock/ValueBindingTest.java
index ff49820..569a30a 100644
--- a/test12/src/test/java/org/apache/myfaces/test/mock/ValueBindingTest.java
+++ b/test12/src/test/java/org/apache/myfaces/test/mock/ValueBindingTest.java
@@ -29,52 +29,55 @@
public class ValueBindingTest extends AbstractJsfTestCase
{
- public ValueBindingTest(String name) {
- super(name);
- }
+ public ValueBindingTest(String name)
+ {
+ super(name);
+ }
- protected void setUp() throws Exception
- {
- super.setUp();
- }
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+ }
- protected void tearDown() throws Exception
- {
- super.tearDown();
- }
-
- public static Test suite() {
- return (new TestSuite(ValueBindingTest.class));
- }
-
- public void testRenderButtonWithValueBinding() throws IOException {
- ValueBinding vb= facesContext.getApplication().
- createValueBinding("#{ bean.name }");
+ protected void tearDown() throws Exception
+ {
+ super.tearDown();
+ }
- Bean bean = new Bean();
- bean.setName("Matthias");
-
- facesContext.getExternalContext().getRequestMap().put("bean",
- bean);
-
- assertEquals("Matthias", vb.getValue(facesContext).toString());
-
- vb = facesContext.getApplication().createValueBinding("#{requestScope['bean']}");
-
- Bean copy = (Bean) vb.getValue(facesContext);
- assertNotNull(copy);
- assertTrue(bean == copy);
+ public static Test suite()
+ {
+ return (new TestSuite(ValueBindingTest.class));
+ }
- facesContext.getExternalContext().getRequestMap().put("org.apache.shale.bean",
- bean);
+ public void testRenderButtonWithValueBinding() throws IOException
+ {
+ ValueBinding vb = facesContext.getApplication().createValueBinding(
+ "#{ bean.name }");
- vb = facesContext.getApplication().createValueBinding("#{requestScope['org.apache.shale.bean']}");
-
- copy = (Bean) vb.getValue(facesContext);
- assertNotNull(copy);
- assertTrue(bean == copy);
+ Bean bean = new Bean();
+ bean.setName("Matthias");
+ facesContext.getExternalContext().getRequestMap().put("bean", bean);
- }
+ assertEquals("Matthias", vb.getValue(facesContext).toString());
+
+ vb = facesContext.getApplication().createValueBinding(
+ "#{requestScope['bean']}");
+
+ Bean copy = (Bean) vb.getValue(facesContext);
+ assertNotNull(copy);
+ assertTrue(bean == copy);
+
+ facesContext.getExternalContext().getRequestMap().put(
+ "org.apache.shale.bean", bean);
+
+ vb = facesContext.getApplication().createValueBinding(
+ "#{requestScope['org.apache.shale.bean']}");
+
+ copy = (Bean) vb.getValue(facesContext);
+ assertNotNull(copy);
+ assertTrue(bean == copy);
+
+ }
}
diff --git a/test12/src/test/java/org/apache/myfaces/test/mock/data/Bean.java b/test12/src/test/java/org/apache/myfaces/test/mock/data/Bean.java
index 4df34b6..f590a8b 100644
--- a/test12/src/test/java/org/apache/myfaces/test/mock/data/Bean.java
+++ b/test12/src/test/java/org/apache/myfaces/test/mock/data/Bean.java
@@ -18,27 +18,26 @@
public class Bean
{
- private String name, password;
+ private String name, password;
- public String getName()
- {
- return name;
- }
+ public String getName()
+ {
+ return name;
+ }
- public void setName(String name)
- {
- this.name = name;
- }
+ public void setName(String name)
+ {
+ this.name = name;
+ }
- public String getPassword()
- {
- return password;
- }
+ public String getPassword()
+ {
+ return password;
+ }
- public void setPassword(String password)
- {
- this.password = password;
- }
-
-
+ public void setPassword(String password)
+ {
+ this.password = password;
+ }
+
}
diff --git a/test12/src/test/java/org/apache/myfaces/test/runner/WebXmlParameter.java b/test12/src/test/java/org/apache/myfaces/test/runner/WebXmlParameter.java
index 455fb58..f8ad99b 100644
--- a/test12/src/test/java/org/apache/myfaces/test/runner/WebXmlParameter.java
+++ b/test12/src/test/java/org/apache/myfaces/test/runner/WebXmlParameter.java
@@ -23,8 +23,7 @@
public class WebXmlParameter
{
public static final String PARAMETER_KEY = "PARAMETER";
-
- static final String PARAMETER = WebXmlUtils
- .getInitParameter(PARAMETER_KEY);
+
+ static final String PARAMETER = WebXmlUtils.getInitParameter(PARAMETER_KEY);
}
diff --git a/test20/src/main/java/org/apache/myfaces/test/base/AbstractJsfTestCase.java b/test20/src/main/java/org/apache/myfaces/test/base/AbstractJsfTestCase.java
index adb6e8d..589853d 100644
--- a/test20/src/main/java/org/apache/myfaces/test/base/AbstractJsfTestCase.java
+++ b/test20/src/main/java/org/apache/myfaces/test/base/AbstractJsfTestCase.java
@@ -73,34 +73,36 @@
* @since 1.0.0
*/
-public abstract class AbstractJsfTestCase extends TestCase {
-
+public abstract class AbstractJsfTestCase extends TestCase
+{
// ------------------------------------------------------------ Constructors
-
/**
* <p>Construct a new instance of this test case.</p>
*
* @param name Name of this test case
*/
- public AbstractJsfTestCase(String name) {
+ public AbstractJsfTestCase(String name)
+ {
super(name);
}
-
// ---------------------------------------------------- Overall Test Methods
-
/**
* <p>Set up instance variables required by this test case.</p>
*/
- protected void setUp() throws Exception {
+ protected void setUp() throws Exception
+ {
// Set up a new thread context class loader
- threadContextClassLoader = Thread.currentThread().getContextClassLoader();
- Thread.currentThread().setContextClassLoader(new URLClassLoader(new URL[0],
- this.getClass().getClassLoader()));
+ threadContextClassLoader = Thread.currentThread()
+ .getContextClassLoader();
+ Thread.currentThread()
+ .setContextClassLoader(
+ new URLClassLoader(new URL[0], this.getClass()
+ .getClassLoader()));
// Set up Servlet API Objects
setUpServletObjects();
@@ -112,7 +114,7 @@
setUpJSFObjects();
}
-
+
/**
* <p>Setup JSF object used for the test. By default it calls to the following
* methods in this order:</p>
@@ -128,7 +130,7 @@
*
* @throws Exception
*/
- protected void setUpJSFObjects() throws Exception
+ protected void setUpJSFObjects() throws Exception
{
setUpExternalContext();
setUpLifecycle();
@@ -137,7 +139,7 @@
setUpApplication();
setUpRenderKit();
}
-
+
/**
* <p>Setup servlet objects that will be used for the test:</p>
*
@@ -151,7 +153,7 @@
*
* @throws Exception
*/
- protected void setUpServletObjects() throws Exception
+ protected void setUpServletObjects() throws Exception
{
servletContext = new MockServletContext();
config = new MockServletConfig(servletContext);
@@ -161,28 +163,28 @@
request.setServletContext(servletContext);
response = new MockHttpServletResponse();
}
-
+
/**
* <p>Set JSF factories using FactoryFinder method setFactory.</p>
*
* @throws Exception
*/
- protected void setFactories() throws Exception
+ protected void setFactories() throws Exception
{
FactoryFinder.setFactory(FactoryFinder.APPLICATION_FACTORY,
- "org.apache.myfaces.test.mock.MockApplicationFactory");
+ "org.apache.myfaces.test.mock.MockApplicationFactory");
FactoryFinder.setFactory(FactoryFinder.FACES_CONTEXT_FACTORY,
- "org.apache.myfaces.test.mock.MockFacesContextFactory");
+ "org.apache.myfaces.test.mock.MockFacesContextFactory");
FactoryFinder.setFactory(FactoryFinder.LIFECYCLE_FACTORY,
- "org.apache.myfaces.test.mock.lifecycle.MockLifecycleFactory");
+ "org.apache.myfaces.test.mock.lifecycle.MockLifecycleFactory");
FactoryFinder.setFactory(FactoryFinder.RENDER_KIT_FACTORY,
- "org.apache.myfaces.test.mock.MockRenderKitFactory");
+ "org.apache.myfaces.test.mock.MockRenderKitFactory");
FactoryFinder.setFactory(FactoryFinder.EXCEPTION_HANDLER_FACTORY,
- "org.apache.myfaces.test.mock.MockExceptionHandlerFactory");
+ "org.apache.myfaces.test.mock.MockExceptionHandlerFactory");
FactoryFinder.setFactory(FactoryFinder.PARTIAL_VIEW_CONTEXT_FACTORY,
- "org.apache.myfaces.test.mock.MockPartialViewContextFactory");
+ "org.apache.myfaces.test.mock.MockPartialViewContextFactory");
FactoryFinder.setFactory(FactoryFinder.VISIT_CONTEXT_FACTORY,
- "org.apache.myfaces.test.mock.visit.MockVisitContextFactory");
+ "org.apache.myfaces.test.mock.visit.MockVisitContextFactory");
}
/**
@@ -193,8 +195,8 @@
*/
protected void setUpExternalContext() throws Exception
{
- externalContext =
- new MockExternalContext(servletContext, request, response);
+ externalContext = new MockExternalContext(servletContext, request,
+ response);
}
/**
@@ -205,12 +207,12 @@
*/
protected void setUpLifecycle() throws Exception
{
- lifecycleFactory = (MockLifecycleFactory)
- FactoryFinder.getFactory(FactoryFinder.LIFECYCLE_FACTORY);
- lifecycle = (MockLifecycle)
- lifecycleFactory.getLifecycle(LifecycleFactory.DEFAULT_LIFECYCLE);
+ lifecycleFactory = (MockLifecycleFactory) FactoryFinder
+ .getFactory(FactoryFinder.LIFECYCLE_FACTORY);
+ lifecycle = (MockLifecycle) lifecycleFactory
+ .getLifecycle(LifecycleFactory.DEFAULT_LIFECYCLE);
}
-
+
/**
* Setup the <code>facesContextFactory</code> and <code>facesContext</code>
* variable. Before end, by default it override <code>externalContext</code>
@@ -222,16 +224,14 @@
*/
protected void setUpFacesContext() throws Exception
{
- facesContextFactory = (MockFacesContextFactory)
- FactoryFinder.getFactory(FactoryFinder.FACES_CONTEXT_FACTORY);
- facesContext = (MockFacesContext)
- facesContextFactory.getFacesContext(servletContext,
- request,
- response,
- lifecycle);
+ facesContextFactory = (MockFacesContextFactory) FactoryFinder
+ .getFactory(FactoryFinder.FACES_CONTEXT_FACTORY);
+ facesContext = (MockFacesContext) facesContextFactory.getFacesContext(
+ servletContext, request, response, lifecycle);
if (facesContext.getExternalContext() != null)
{
- externalContext = (MockExternalContext) facesContext.getExternalContext();
+ externalContext = (MockExternalContext) facesContext
+ .getExternalContext();
}
}
@@ -248,7 +248,7 @@
root.setRenderKitId(RenderKitFactory.HTML_BASIC_RENDER_KIT);
facesContext.setViewRoot(root);
}
-
+
/**
* Setup the <code>application</code> variable and before
* the end by default it is assigned to the <code>facesContext</code>
@@ -258,12 +258,12 @@
*/
protected void setUpApplication() throws Exception
{
- ApplicationFactory applicationFactory = (ApplicationFactory)
- FactoryFinder.getFactory(FactoryFinder.APPLICATION_FACTORY);
+ ApplicationFactory applicationFactory = (ApplicationFactory) FactoryFinder
+ .getFactory(FactoryFinder.APPLICATION_FACTORY);
application = (MockApplication) applicationFactory.getApplication();
facesContext.setApplication(application);
}
-
+
/**
* Setup the <code>renderKit</code> variable. This is a good place to use
* <code>ConfigParser</code> to register converters, validators, components
@@ -273,21 +273,24 @@
*/
protected void setUpRenderKit() throws Exception
{
- RenderKitFactory renderKitFactory = (RenderKitFactory)
- FactoryFinder.getFactory(FactoryFinder.RENDER_KIT_FACTORY);
+ RenderKitFactory renderKitFactory = (RenderKitFactory) FactoryFinder
+ .getFactory(FactoryFinder.RENDER_KIT_FACTORY);
renderKit = new MockRenderKit();
- renderKitFactory.addRenderKit(RenderKitFactory.HTML_BASIC_RENDER_KIT, renderKit);
+ renderKitFactory.addRenderKit(RenderKitFactory.HTML_BASIC_RENDER_KIT,
+ renderKit);
}
/**
* <p>Tear down instance variables required by this test case.</p>
*/
- protected void tearDown() throws Exception {
+ protected void tearDown() throws Exception
+ {
application = null;
config = null;
externalContext = null;
- if (facesContext != null) {
+ if (facesContext != null)
+ {
facesContext.release();
}
facesContext = null;
@@ -305,23 +308,21 @@
}
-
// ------------------------------------------------------ Instance Variables
-
// Mock object instances for our tests
- protected MockApplication application = null;
- protected MockServletConfig config = null;
- protected MockExternalContext externalContext = null;
- protected MockFacesContext facesContext = null;
+ protected MockApplication application = null;
+ protected MockServletConfig config = null;
+ protected MockExternalContext externalContext = null;
+ protected MockFacesContext facesContext = null;
protected MockFacesContextFactory facesContextFactory = null;
- protected MockLifecycle lifecycle = null;
- protected MockLifecycleFactory lifecycleFactory = null;
- protected MockRenderKit renderKit = null;
- protected MockHttpServletRequest request = null;
+ protected MockLifecycle lifecycle = null;
+ protected MockLifecycleFactory lifecycleFactory = null;
+ protected MockRenderKit renderKit = null;
+ protected MockHttpServletRequest request = null;
protected MockHttpServletResponse response = null;
- protected MockServletContext servletContext = null;
- protected MockHttpSession session = null;
+ protected MockServletContext servletContext = null;
+ protected MockHttpSession session = null;
// Thread context class loader saved and restored after each test
private ClassLoader threadContextClassLoader = null;
diff --git a/test20/src/main/java/org/apache/myfaces/test/base/junit4/AbstractJsfConfigurableMockTestCase.java b/test20/src/main/java/org/apache/myfaces/test/base/junit4/AbstractJsfConfigurableMockTestCase.java
index 58f9b20..a97c9f5 100644
--- a/test20/src/main/java/org/apache/myfaces/test/base/junit4/AbstractJsfConfigurableMockTestCase.java
+++ b/test20/src/main/java/org/apache/myfaces/test/base/junit4/AbstractJsfConfigurableMockTestCase.java
@@ -75,12 +75,11 @@
* @since 1.0.0
*/
-public abstract class AbstractJsfConfigurableMockTestCase {
-
+public abstract class AbstractJsfConfigurableMockTestCase
+{
// ------------------------------------------------------------ Constructors
-
/**
* <p>Construct a new instance of this test case.</p>
*
@@ -90,20 +89,22 @@
{
}
-
// ---------------------------------------------------- Overall Test Methods
-
/**
* <p>Set up instance variables required by this test case.</p>
*/
@Before
- public void setUp() throws Exception {
+ public void setUp() throws Exception
+ {
// Set up a new thread context class loader
- threadContextClassLoader = Thread.currentThread().getContextClassLoader();
- Thread.currentThread().setContextClassLoader(new URLClassLoader(new URL[0],
- this.getClass().getClassLoader()));
+ threadContextClassLoader = Thread.currentThread()
+ .getContextClassLoader();
+ Thread.currentThread()
+ .setContextClassLoader(
+ new URLClassLoader(new URL[0], this.getClass()
+ .getClassLoader()));
// Set up Servlet API Objects
setUpServletObjects();
@@ -115,7 +116,7 @@
setUpJSFObjects();
}
-
+
/**
* <p>Setup JSF object used for the test. By default it calls to the following
* methods in this order:</p>
@@ -131,7 +132,7 @@
*
* @throws Exception
*/
- protected void setUpJSFObjects() throws Exception
+ protected void setUpJSFObjects() throws Exception
{
setUpExternalContext();
setUpLifecycle();
@@ -140,7 +141,7 @@
setUpApplication();
setUpRenderKit();
}
-
+
/**
* <p>Setup servlet objects that will be used for the test:</p>
*
@@ -154,7 +155,7 @@
*
* @throws Exception
*/
- protected void setUpServletObjects() throws Exception
+ protected void setUpServletObjects() throws Exception
{
servletContext = new MockServletContext();
config = new MockServletConfig(servletContext);
@@ -164,28 +165,28 @@
request.setServletContext(servletContext);
response = new MockHttpServletResponse();
}
-
+
/**
* <p>Set JSF factories using FactoryFinder method setFactory.</p>
*
* @throws Exception
*/
- protected void setFactories() throws Exception
+ protected void setFactories() throws Exception
{
FactoryFinder.setFactory(FactoryFinder.APPLICATION_FACTORY,
- "org.apache.myfaces.test.mock.MockApplicationFactory");
+ "org.apache.myfaces.test.mock.MockApplicationFactory");
FactoryFinder.setFactory(FactoryFinder.FACES_CONTEXT_FACTORY,
- "org.apache.myfaces.test.mock.MockFacesContextFactory");
+ "org.apache.myfaces.test.mock.MockFacesContextFactory");
FactoryFinder.setFactory(FactoryFinder.LIFECYCLE_FACTORY,
- "org.apache.myfaces.test.mock.lifecycle.MockLifecycleFactory");
+ "org.apache.myfaces.test.mock.lifecycle.MockLifecycleFactory");
FactoryFinder.setFactory(FactoryFinder.RENDER_KIT_FACTORY,
- "org.apache.myfaces.test.mock.MockRenderKitFactory");
+ "org.apache.myfaces.test.mock.MockRenderKitFactory");
FactoryFinder.setFactory(FactoryFinder.EXCEPTION_HANDLER_FACTORY,
- "org.apache.myfaces.test.mock.MockExceptionHandlerFactory");
+ "org.apache.myfaces.test.mock.MockExceptionHandlerFactory");
FactoryFinder.setFactory(FactoryFinder.PARTIAL_VIEW_CONTEXT_FACTORY,
- "org.apache.myfaces.test.mock.MockPartialViewContextFactory");
+ "org.apache.myfaces.test.mock.MockPartialViewContextFactory");
FactoryFinder.setFactory(FactoryFinder.VISIT_CONTEXT_FACTORY,
- "org.apache.myfaces.test.mock.visit.MockVisitContextFactory");
+ "org.apache.myfaces.test.mock.visit.MockVisitContextFactory");
}
/**
@@ -196,8 +197,8 @@
*/
protected void setUpExternalContext() throws Exception
{
- externalContext =
- new MockExternalContext(servletContext, request, response);
+ externalContext = new MockExternalContext(servletContext, request,
+ response);
}
/**
@@ -208,12 +209,12 @@
*/
protected void setUpLifecycle() throws Exception
{
- lifecycleFactory = (LifecycleFactory)
- FactoryFinder.getFactory(FactoryFinder.LIFECYCLE_FACTORY);
- lifecycle =
- lifecycleFactory.getLifecycle(LifecycleFactory.DEFAULT_LIFECYCLE);
+ lifecycleFactory = (LifecycleFactory) FactoryFinder
+ .getFactory(FactoryFinder.LIFECYCLE_FACTORY);
+ lifecycle = lifecycleFactory
+ .getLifecycle(LifecycleFactory.DEFAULT_LIFECYCLE);
}
-
+
/**
* Setup the <code>facesContextFactory</code> and <code>facesContext</code>
* variable. Before end, by default it override <code>externalContext</code>
@@ -225,13 +226,10 @@
*/
protected void setUpFacesContext() throws Exception
{
- facesContextFactory = (FacesContextFactory)
- FactoryFinder.getFactory(FactoryFinder.FACES_CONTEXT_FACTORY);
- facesContext = (FacesContext)
- facesContextFactory.getFacesContext(servletContext,
- request,
- response,
- lifecycle);
+ facesContextFactory = (FacesContextFactory) FactoryFinder
+ .getFactory(FactoryFinder.FACES_CONTEXT_FACTORY);
+ facesContext = (FacesContext) facesContextFactory.getFacesContext(
+ servletContext, request, response, lifecycle);
if (facesContext.getExternalContext() != null)
{
externalContext = facesContext.getExternalContext();
@@ -251,7 +249,7 @@
root.setRenderKitId(RenderKitFactory.HTML_BASIC_RENDER_KIT);
facesContext.setViewRoot(root);
}
-
+
/**
* Setup the <code>application</code> variable and before
* the end by default it is assigned to the <code>facesContext</code>
@@ -261,12 +259,12 @@
*/
protected void setUpApplication() throws Exception
{
- ApplicationFactory applicationFactory = (ApplicationFactory)
- FactoryFinder.getFactory(FactoryFinder.APPLICATION_FACTORY);
+ ApplicationFactory applicationFactory = (ApplicationFactory) FactoryFinder
+ .getFactory(FactoryFinder.APPLICATION_FACTORY);
application = applicationFactory.getApplication();
- ((MockFacesContext)facesContext).setApplication(application);
+ ((MockFacesContext) facesContext).setApplication(application);
}
-
+
/**
* Setup the <code>renderKit</code> variable. This is a good place to use
* <code>ConfigParser</code> to register converters, validators, components
@@ -276,22 +274,25 @@
*/
protected void setUpRenderKit() throws Exception
{
- RenderKitFactory renderKitFactory = (RenderKitFactory)
- FactoryFinder.getFactory(FactoryFinder.RENDER_KIT_FACTORY);
+ RenderKitFactory renderKitFactory = (RenderKitFactory) FactoryFinder
+ .getFactory(FactoryFinder.RENDER_KIT_FACTORY);
renderKit = new MockRenderKit();
- renderKitFactory.addRenderKit(RenderKitFactory.HTML_BASIC_RENDER_KIT, renderKit);
+ renderKitFactory.addRenderKit(RenderKitFactory.HTML_BASIC_RENDER_KIT,
+ renderKit);
}
/**
* <p>Tear down instance variables required by this test case.</p>
*/
@After
- public void tearDown() throws Exception {
+ public void tearDown() throws Exception
+ {
application = null;
config = null;
externalContext = null;
- if (facesContext != null) {
+ if (facesContext != null)
+ {
facesContext.release();
}
facesContext = null;
@@ -309,23 +310,21 @@
}
-
// ------------------------------------------------------ Instance Variables
-
// Mock object instances for our tests
- protected Application application = null;
- protected MockServletConfig config = null;
- protected ExternalContext externalContext = null;
- protected FacesContext facesContext = null;
- protected FacesContextFactory facesContextFactory = null;
- protected Lifecycle lifecycle = null;
- protected LifecycleFactory lifecycleFactory = null;
- protected RenderKit renderKit = null;
- protected MockHttpServletRequest request = null;
+ protected Application application = null;
+ protected MockServletConfig config = null;
+ protected ExternalContext externalContext = null;
+ protected FacesContext facesContext = null;
+ protected FacesContextFactory facesContextFactory = null;
+ protected Lifecycle lifecycle = null;
+ protected LifecycleFactory lifecycleFactory = null;
+ protected RenderKit renderKit = null;
+ protected MockHttpServletRequest request = null;
protected MockHttpServletResponse response = null;
- protected MockServletContext servletContext = null;
- protected MockHttpSession session = null;
+ protected MockServletContext servletContext = null;
+ protected MockHttpSession session = null;
// Thread context class loader saved and restored after each test
private ClassLoader threadContextClassLoader = null;
diff --git a/test20/src/main/java/org/apache/myfaces/test/base/junit4/AbstractJsfTestCase.java b/test20/src/main/java/org/apache/myfaces/test/base/junit4/AbstractJsfTestCase.java
index 5948a72..9869512 100644
--- a/test20/src/main/java/org/apache/myfaces/test/base/junit4/AbstractJsfTestCase.java
+++ b/test20/src/main/java/org/apache/myfaces/test/base/junit4/AbstractJsfTestCase.java
@@ -73,12 +73,11 @@
* @since 1.0.0
*/
-public abstract class AbstractJsfTestCase {
-
+public abstract class AbstractJsfTestCase
+{
// ------------------------------------------------------------ Constructors
-
/**
* <p>Construct a new instance of this test case.</p>
*
@@ -88,20 +87,22 @@
{
}
-
// ---------------------------------------------------- Overall Test Methods
-
/**
* <p>Set up instance variables required by this test case.</p>
*/
@Before
- public void setUp() throws Exception {
+ public void setUp() throws Exception
+ {
// Set up a new thread context class loader
- threadContextClassLoader = Thread.currentThread().getContextClassLoader();
- Thread.currentThread().setContextClassLoader(new URLClassLoader(new URL[0],
- this.getClass().getClassLoader()));
+ threadContextClassLoader = Thread.currentThread()
+ .getContextClassLoader();
+ Thread.currentThread()
+ .setContextClassLoader(
+ new URLClassLoader(new URL[0], this.getClass()
+ .getClassLoader()));
// Set up Servlet API Objects
setUpServletObjects();
@@ -113,7 +114,7 @@
setUpJSFObjects();
}
-
+
/**
* <p>Setup JSF object used for the test. By default it calls to the following
* methods in this order:</p>
@@ -129,7 +130,7 @@
*
* @throws Exception
*/
- protected void setUpJSFObjects() throws Exception
+ protected void setUpJSFObjects() throws Exception
{
setUpExternalContext();
setUpLifecycle();
@@ -138,7 +139,7 @@
setUpApplication();
setUpRenderKit();
}
-
+
/**
* <p>Setup servlet objects that will be used for the test:</p>
*
@@ -152,7 +153,7 @@
*
* @throws Exception
*/
- protected void setUpServletObjects() throws Exception
+ protected void setUpServletObjects() throws Exception
{
servletContext = new MockServletContext();
config = new MockServletConfig(servletContext);
@@ -162,28 +163,28 @@
request.setServletContext(servletContext);
response = new MockHttpServletResponse();
}
-
+
/**
* <p>Set JSF factories using FactoryFinder method setFactory.</p>
*
* @throws Exception
*/
- protected void setFactories() throws Exception
+ protected void setFactories() throws Exception
{
FactoryFinder.setFactory(FactoryFinder.APPLICATION_FACTORY,
- "org.apache.myfaces.test.mock.MockApplicationFactory");
+ "org.apache.myfaces.test.mock.MockApplicationFactory");
FactoryFinder.setFactory(FactoryFinder.FACES_CONTEXT_FACTORY,
- "org.apache.myfaces.test.mock.MockFacesContextFactory");
+ "org.apache.myfaces.test.mock.MockFacesContextFactory");
FactoryFinder.setFactory(FactoryFinder.LIFECYCLE_FACTORY,
- "org.apache.myfaces.test.mock.lifecycle.MockLifecycleFactory");
+ "org.apache.myfaces.test.mock.lifecycle.MockLifecycleFactory");
FactoryFinder.setFactory(FactoryFinder.RENDER_KIT_FACTORY,
- "org.apache.myfaces.test.mock.MockRenderKitFactory");
+ "org.apache.myfaces.test.mock.MockRenderKitFactory");
FactoryFinder.setFactory(FactoryFinder.EXCEPTION_HANDLER_FACTORY,
- "org.apache.myfaces.test.mock.MockExceptionHandlerFactory");
+ "org.apache.myfaces.test.mock.MockExceptionHandlerFactory");
FactoryFinder.setFactory(FactoryFinder.PARTIAL_VIEW_CONTEXT_FACTORY,
- "org.apache.myfaces.test.mock.MockPartialViewContextFactory");
+ "org.apache.myfaces.test.mock.MockPartialViewContextFactory");
FactoryFinder.setFactory(FactoryFinder.VISIT_CONTEXT_FACTORY,
- "org.apache.myfaces.test.mock.visit.MockVisitContextFactory");
+ "org.apache.myfaces.test.mock.visit.MockVisitContextFactory");
}
/**
@@ -194,8 +195,8 @@
*/
protected void setUpExternalContext() throws Exception
{
- externalContext =
- new MockExternalContext(servletContext, request, response);
+ externalContext = new MockExternalContext(servletContext, request,
+ response);
}
/**
@@ -206,12 +207,12 @@
*/
protected void setUpLifecycle() throws Exception
{
- lifecycleFactory = (MockLifecycleFactory)
- FactoryFinder.getFactory(FactoryFinder.LIFECYCLE_FACTORY);
- lifecycle = (MockLifecycle)
- lifecycleFactory.getLifecycle(LifecycleFactory.DEFAULT_LIFECYCLE);
+ lifecycleFactory = (MockLifecycleFactory) FactoryFinder
+ .getFactory(FactoryFinder.LIFECYCLE_FACTORY);
+ lifecycle = (MockLifecycle) lifecycleFactory
+ .getLifecycle(LifecycleFactory.DEFAULT_LIFECYCLE);
}
-
+
/**
* Setup the <code>facesContextFactory</code> and <code>facesContext</code>
* variable. Before end, by default it override <code>externalContext</code>
@@ -223,16 +224,14 @@
*/
protected void setUpFacesContext() throws Exception
{
- facesContextFactory = (MockFacesContextFactory)
- FactoryFinder.getFactory(FactoryFinder.FACES_CONTEXT_FACTORY);
- facesContext = (MockFacesContext)
- facesContextFactory.getFacesContext(servletContext,
- request,
- response,
- lifecycle);
+ facesContextFactory = (MockFacesContextFactory) FactoryFinder
+ .getFactory(FactoryFinder.FACES_CONTEXT_FACTORY);
+ facesContext = (MockFacesContext) facesContextFactory.getFacesContext(
+ servletContext, request, response, lifecycle);
if (facesContext.getExternalContext() != null)
{
- externalContext = (MockExternalContext) facesContext.getExternalContext();
+ externalContext = (MockExternalContext) facesContext
+ .getExternalContext();
}
}
@@ -249,7 +248,7 @@
root.setRenderKitId(RenderKitFactory.HTML_BASIC_RENDER_KIT);
facesContext.setViewRoot(root);
}
-
+
/**
* Setup the <code>application</code> variable and before
* the end by default it is assigned to the <code>facesContext</code>
@@ -259,12 +258,12 @@
*/
protected void setUpApplication() throws Exception
{
- ApplicationFactory applicationFactory = (ApplicationFactory)
- FactoryFinder.getFactory(FactoryFinder.APPLICATION_FACTORY);
+ ApplicationFactory applicationFactory = (ApplicationFactory) FactoryFinder
+ .getFactory(FactoryFinder.APPLICATION_FACTORY);
application = (MockApplication) applicationFactory.getApplication();
facesContext.setApplication(application);
}
-
+
/**
* Setup the <code>renderKit</code> variable. This is a good place to use
* <code>ConfigParser</code> to register converters, validators, components
@@ -274,22 +273,25 @@
*/
protected void setUpRenderKit() throws Exception
{
- RenderKitFactory renderKitFactory = (RenderKitFactory)
- FactoryFinder.getFactory(FactoryFinder.RENDER_KIT_FACTORY);
+ RenderKitFactory renderKitFactory = (RenderKitFactory) FactoryFinder
+ .getFactory(FactoryFinder.RENDER_KIT_FACTORY);
renderKit = new MockRenderKit();
- renderKitFactory.addRenderKit(RenderKitFactory.HTML_BASIC_RENDER_KIT, renderKit);
+ renderKitFactory.addRenderKit(RenderKitFactory.HTML_BASIC_RENDER_KIT,
+ renderKit);
}
/**
* <p>Tear down instance variables required by this test case.</p>
*/
@After
- public void tearDown() throws Exception {
+ public void tearDown() throws Exception
+ {
application = null;
config = null;
externalContext = null;
- if (facesContext != null) {
+ if (facesContext != null)
+ {
facesContext.release();
}
facesContext = null;
@@ -307,23 +309,21 @@
}
-
// ------------------------------------------------------ Instance Variables
-
// Mock object instances for our tests
- protected MockApplication application = null;
- protected MockServletConfig config = null;
- protected MockExternalContext externalContext = null;
- protected MockFacesContext facesContext = null;
+ protected MockApplication application = null;
+ protected MockServletConfig config = null;
+ protected MockExternalContext externalContext = null;
+ protected MockFacesContext facesContext = null;
protected MockFacesContextFactory facesContextFactory = null;
- protected MockLifecycle lifecycle = null;
- protected MockLifecycleFactory lifecycleFactory = null;
- protected MockRenderKit renderKit = null;
- protected MockHttpServletRequest request = null;
+ protected MockLifecycle lifecycle = null;
+ protected MockLifecycleFactory lifecycleFactory = null;
+ protected MockRenderKit renderKit = null;
+ protected MockHttpServletRequest request = null;
protected MockHttpServletResponse response = null;
- protected MockServletContext servletContext = null;
- protected MockHttpSession session = null;
+ protected MockServletContext servletContext = null;
+ protected MockHttpSession session = null;
// Thread context class loader saved and restored after each test
private ClassLoader threadContextClassLoader = null;
diff --git a/test20/src/main/java/org/apache/myfaces/test/config/ConfigParser.java b/test20/src/main/java/org/apache/myfaces/test/config/ConfigParser.java
index e071f70..6678382 100644
--- a/test20/src/main/java/org/apache/myfaces/test/config/ConfigParser.java
+++ b/test20/src/main/java/org/apache/myfaces/test/config/ConfigParser.java
@@ -59,54 +59,42 @@
*
* @since 1.0.0
*/
-public class ConfigParser {
-
+public class ConfigParser
+{
// ------------------------------------------------------------ Constructors
-
/** Creates a new instance of ConfigParser */
- public ConfigParser() {
+ public ConfigParser()
+ {
}
-
// ------------------------------------------------------ Manifest Constants
-
/**
* <p>Configuration resource URLs for the JSF RI.</p>
*/
- private static final String[] JSFRI_RESOURCES =
- { "/com/sun/faces/jsf-ri-runtime.xml",
- };
-
+ private static final String[] JSFRI_RESOURCES = { "/com/sun/faces/jsf-ri-runtime.xml", };
/**
* <p>Configuration resource URLs for Apache MyFaces.</p>
*/
- private static final String[] MYFACES_RESOURCES =
- { "/org/apache/myfaces/resource/standard-faces-config.xml",
- };
+ private static final String[] MYFACES_RESOURCES = { "/org/apache/myfaces/resource/standard-faces-config.xml", };
/**
* <p>Configuration resource URLs for Apache MyFaces 1.2.</p>
*/
- private static final String[] MYFACES_RESOURCES12 =
- { "/META-INF/standard-faces-config.xml",
- };
+ private static final String[] MYFACES_RESOURCES12 = { "/META-INF/standard-faces-config.xml", };
// ------------------------------------------------------ Instance Variables
-
/**
* <p>The <code>Digester</code> instance we will use for parsing.</p>
*/
private Digester digester = null;
-
// ------------------------------------------------------- Public Properties
-
/**
* <p>Return the URLs of the platform configuration resources for this
* application. The following platforms are currently supported:</p>
@@ -118,12 +106,15 @@
* <p>If MyFaces (version 1.2), currently under development, does not change
* the name of the configuration resource, it will be supported as well.</p>
*/
- public URL[] getPlatformURLs() {
+ public URL[] getPlatformURLs()
+ {
URL[] urls = translate(JSFRI_RESOURCES);
- if (urls[0] == null) {
+ if (urls[0] == null)
+ {
urls = translate(MYFACES_RESOURCES12);
- if (urls[0] == null) {
+ if (urls[0] == null)
+ {
urls = translate(MYFACES_RESOURCES);
}
}
@@ -131,10 +122,8 @@
}
-
// ---------------------------------------------------------- Public Methods
-
/**
* <p>Parse the specified JavaServer Faces configuration resource, causing
* the appropriate JSF artifacts to be registered with the mock object
@@ -145,25 +134,28 @@
* @exception IOException if an input/output error occurs
* @exception SAXException if a parsing error occurs
*/
- public void parse(URL url) throws IOException, SAXException {
+ public void parse(URL url) throws IOException, SAXException
+ {
// Acquire and configure the Digester instance we will use
Digester digester = digester();
- ApplicationFactory factory = (ApplicationFactory)
- FactoryFinder.getFactory(FactoryFinder.APPLICATION_FACTORY);
+ ApplicationFactory factory = (ApplicationFactory) FactoryFinder
+ .getFactory(FactoryFinder.APPLICATION_FACTORY);
Application application = factory.getApplication();
digester.push(application);
// Perform the required parsing
- try {
+ try
+ {
digester.parse(url);
- } finally {
+ }
+ finally
+ {
digester.clear();
}
}
-
/**
* <p>Parse the specified set of JavaServer Faces configuration resources,
* in the listed order, causing the appropriate JSF artifacts to be registered
@@ -174,182 +166,229 @@
* @exception IOException if an input/output error occurs
* @exception SAXException if a parsing error occurs
*/
- public void parse(URL[] urls) throws IOException, SAXException {
+ public void parse(URL[] urls) throws IOException, SAXException
+ {
- for (int i = 0; i < urls.length; i++) {
+ for (int i = 0; i < urls.length; i++)
+ {
parse(urls[i]);
}
}
-
// --------------------------------------------------------- Private Methods
-
/**
* <p>Return the <code>Digester</code> instance we will use for parsing,
* creating and configuring a new instance if necessary.</p>
*/
- private Digester digester() {
+ private Digester digester()
+ {
- if (this.digester == null) {
+ if (this.digester == null)
+ {
this.digester = new Digester();
digester.addRule("faces-config/component", new ComponentRule());
- digester.addCallMethod
- ("faces-config/component/component-type", "setComponentType", 0);
- digester.addCallMethod
- ("faces-config/component/component-class", "setComponentClass", 0);
+ digester.addCallMethod("faces-config/component/component-type",
+ "setComponentType", 0);
+ digester.addCallMethod("faces-config/component/component-class",
+ "setComponentClass", 0);
digester.addRule("faces-config/converter", new ConverterRule());
- digester.addCallMethod
- ("faces-config/converter/converter-id", "setConverterId", 0);
- digester.addCallMethod
- ("faces-config/converter/converter-class", "setConverterClass", 0);
- digester.addCallMethod
- ("faces-config/converter/converter-for-class", "setConverterForClass", 0);
+ digester.addCallMethod("faces-config/converter/converter-id",
+ "setConverterId", 0);
+ digester.addCallMethod("faces-config/converter/converter-class",
+ "setConverterClass", 0);
+ digester.addCallMethod(
+ "faces-config/converter/converter-for-class",
+ "setConverterForClass", 0);
digester.addRule("faces-config/render-kit", new RenderKitRule());
- digester.addRule("faces-config/render-kit/render-kit-id", new RenderKitIdRule());
- digester.addRule("faces-config/render-kit/renderer", new RendererRule());
- digester.addCallMethod
- ("faces-config/render-kit/renderer/component-family", "setComponentFamily", 0);
- digester.addCallMethod
- ("faces-config/render-kit/renderer/renderer-class", "setRendererClass", 0);
- digester.addCallMethod
- ("faces-config/render-kit/renderer/renderer-type", "setRendererType", 0);
- digester.addRule("faces-config/render-kit/client-behavior-renderer", new ClientBehaviorRendererRule());
- digester.addCallMethod
- ("faces-config/render-kit/client-behavior-renderer/client-behavior-renderer-type", "setClientBehaviorRendererType", 0);
- digester.addCallMethod
- ("faces-config/render-kit/client-behavior-renderer/client-behavior-renderer-class", "setClientBehaviorRendererClass", 0);
+ digester.addRule("faces-config/render-kit/render-kit-id",
+ new RenderKitIdRule());
+ digester.addRule("faces-config/render-kit/renderer",
+ new RendererRule());
+ digester.addCallMethod(
+ "faces-config/render-kit/renderer/component-family",
+ "setComponentFamily", 0);
+ digester.addCallMethod(
+ "faces-config/render-kit/renderer/renderer-class",
+ "setRendererClass", 0);
+ digester.addCallMethod(
+ "faces-config/render-kit/renderer/renderer-type",
+ "setRendererType", 0);
+ digester.addRule(
+ "faces-config/render-kit/client-behavior-renderer",
+ new ClientBehaviorRendererRule());
+ digester
+ .addCallMethod(
+ "faces-config/render-kit/client-behavior-renderer/client-behavior-renderer-type",
+ "setClientBehaviorRendererType", 0);
+ digester
+ .addCallMethod(
+ "faces-config/render-kit/client-behavior-renderer/client-behavior-renderer-class",
+ "setClientBehaviorRendererClass", 0);
digester.addRule("faces-config/validator", new ValidatorRule());
- digester.addCallMethod
- ("faces-config/validator/validator-id", "setValidatorId", 0);
- digester.addCallMethod
- ("faces-config/validator/validator-class", "setValidatorClass", 0);
+ digester.addCallMethod("faces-config/validator/validator-id",
+ "setValidatorId", 0);
+ digester.addCallMethod("faces-config/validator/validator-class",
+ "setValidatorClass", 0);
digester.addRule("faces-config/behavior", new BehaviorRule());
- digester.addCallMethod
- ("faces-config/behavior/behavior-id", "setBehaviorId", 0);
- digester.addCallMethod
- ("faces-config/behavior/behavior-class", "setBehaviorClass", 0);
+ digester.addCallMethod("faces-config/behavior/behavior-id",
+ "setBehaviorId", 0);
+ digester.addCallMethod("faces-config/behavior/behavior-class",
+ "setBehaviorClass", 0);
}
return this.digester;
}
-
/**
* <p>Translate an array of resource names into an array of resource URLs.</p>
*
* @param names Resource names to translate
*/
- private URL[] translate(String[] names) {
+ private URL[] translate(String[] names)
+ {
URL[] results = new URL[names.length];
- for (int i = 0; i < names.length; i++) {
+ for (int i = 0; i < names.length; i++)
+ {
results[i] = this.getClass().getResource(names[i]);
}
return results;
-
+
}
-
// --------------------------------------------------------- Private Classes
-
/**
* <p>Data bean that stores information related to a component.</p>
*/
- class ComponentBean {
+ class ComponentBean
+ {
private String componentClass;
- public String getComponentClass() {
+
+ public String getComponentClass()
+ {
return this.componentClass;
}
- public void setComponentClass(String componentClass) {
+
+ public void setComponentClass(String componentClass)
+ {
this.componentClass = componentClass;
}
private String componentType;
- public String getComponentType() {
+
+ public String getComponentType()
+ {
return this.componentType;
}
- public void setComponentType(String componentType) {
+
+ public void setComponentType(String componentType)
+ {
this.componentType = componentType;
}
}
-
/**
* <p>Digester <code>Rule</code> for processing components.</p>
*/
- class ComponentRule extends Rule {
+ class ComponentRule extends Rule
+ {
- public void begin(String namespace, String name, Attributes attributes) {
+ public void begin(String namespace, String name, Attributes attributes)
+ {
getDigester().push(new ComponentBean());
}
- public void end(String namespace, String name) {
+ public void end(String namespace, String name)
+ {
ComponentBean bean = (ComponentBean) getDigester().pop();
Application application = (Application) getDigester().peek();
- application.addComponent(bean.getComponentType(), bean.getComponentClass());
+ application.addComponent(bean.getComponentType(), bean
+ .getComponentClass());
}
}
-
/**
* <p>Data bean that stores information related to a converter.</p>
*/
- class ConverterBean {
+ class ConverterBean
+ {
private String converterClass;
- public String getConverterClass() {
+
+ public String getConverterClass()
+ {
return this.converterClass;
}
- public void setConverterClass(String converterClass) {
+
+ public void setConverterClass(String converterClass)
+ {
this.converterClass = converterClass;
}
private String converterForClass;
- public String getConverterForClass() {
+
+ public String getConverterForClass()
+ {
return this.converterForClass;
}
- public void setConverterForClass(String converterForClass) {
+
+ public void setConverterForClass(String converterForClass)
+ {
this.converterForClass = converterForClass;
}
private String converterId;
- public String getConverterId() {
+
+ public String getConverterId()
+ {
return this.converterId;
}
- public void setConverterId(String converterId) {
+
+ public void setConverterId(String converterId)
+ {
this.converterId = converterId;
}
}
-
/**
* <p>Digester <code>Rule</code> for processing converers.</p>
*/
- class ConverterRule extends Rule {
+ class ConverterRule extends Rule
+ {
- public void begin(String namespace, String name, Attributes attributes) {
+ public void begin(String namespace, String name, Attributes attributes)
+ {
getDigester().push(new ConverterBean());
}
- public void end(String namespace, String name) {
+ public void end(String namespace, String name)
+ {
ConverterBean bean = (ConverterBean) getDigester().pop();
Application application = (Application) getDigester().peek();
- if (bean.getConverterId() != null) {
- application.addConverter(bean.getConverterId(), bean.getConverterClass());
- } else {
+ if (bean.getConverterId() != null)
+ {
+ application.addConverter(bean.getConverterId(), bean
+ .getConverterClass());
+ }
+ else
+ {
Class clazz = null;
- try {
+ try
+ {
clazz = classForName(bean.getConverterForClass());
- } catch (ClassNotFoundException e) {
- throw new IllegalArgumentException("java.lang.ClassNotFoundException: "
- + bean.getConverterForClass());
+ }
+ catch (ClassNotFoundException e)
+ {
+ throw new IllegalArgumentException(
+ "java.lang.ClassNotFoundException: "
+ + bean.getConverterForClass());
}
application.addConverter(clazz, bean.getConverterClass());
}
@@ -362,48 +401,53 @@
try
{
// Try WebApp ClassLoader first
- return Class.forName(type,
- false, // do not initialize for faster startup
- Thread.currentThread().getContextClassLoader());
+ return Class.forName(type, false, // do not initialize for faster startup
+ Thread.currentThread().getContextClassLoader());
}
catch (ClassNotFoundException ignore)
{
// fallback: Try ClassLoader for ClassUtils (i.e. the myfaces.jar lib)
- return Class.forName(type,
- false, // do not initialize for faster startup
- this.getClass().getClassLoader());
- }
+ return Class.forName(type, false, // do not initialize for faster startup
+ this.getClass().getClassLoader());
+ }
}
-
+
/**
* <p>Digester <code>Rule</code> for processing render kits.</p>
*/
- class RenderKitRule extends Rule {
+ class RenderKitRule extends Rule
+ {
- public void begin(String namespace, String name, Attributes attributes) {
- RenderKitFactory factory = (RenderKitFactory)
- FactoryFinder.getFactory(FactoryFinder.RENDER_KIT_FACTORY);
- getDigester().push(factory.getRenderKit(null, RenderKitFactory.HTML_BASIC_RENDER_KIT));
+ public void begin(String namespace, String name, Attributes attributes)
+ {
+ RenderKitFactory factory = (RenderKitFactory) FactoryFinder
+ .getFactory(FactoryFinder.RENDER_KIT_FACTORY);
+ getDigester().push(
+ factory.getRenderKit(null,
+ RenderKitFactory.HTML_BASIC_RENDER_KIT));
}
- public void end(String namespace, String name) {
+ public void end(String namespace, String name)
+ {
getDigester().pop();
}
}
-
/**
* <p>Digester <code>Rule</code> for processing render kit identifiers.</p>
*/
- class RenderKitIdRule extends Rule {
+ class RenderKitIdRule extends Rule
+ {
- public void body(String namespace, String name, String text) {
+ public void body(String namespace, String name, String text)
+ {
String renderKitId = text.trim();
- RenderKitFactory factory = (RenderKitFactory)
- FactoryFinder.getFactory(FactoryFinder.RENDER_KIT_FACTORY);
+ RenderKitFactory factory = (RenderKitFactory) FactoryFinder
+ .getFactory(FactoryFinder.RENDER_KIT_FACTORY);
RenderKit renderKit = factory.getRenderKit(null, renderKitId);
- if (renderKit == null) {
+ if (renderKit == null)
+ {
renderKit = new MockRenderKit();
factory.addRenderKit(renderKitId, renderKit);
}
@@ -413,105 +457,134 @@
}
-
/**
* <p>Data bean that stores information related to a renderer.</p>
*/
- class RendererBean {
+ class RendererBean
+ {
private String componentFamily;
- public String getComponentFamily() {
+
+ public String getComponentFamily()
+ {
return this.componentFamily;
}
- public void setComponentFamily(String componentFamily) {
+
+ public void setComponentFamily(String componentFamily)
+ {
this.componentFamily = componentFamily;
}
private String rendererClass;
- public String getRendererClass() {
+
+ public String getRendererClass()
+ {
return this.rendererClass;
}
- public void setRendererClass(String rendererClass) {
+
+ public void setRendererClass(String rendererClass)
+ {
this.rendererClass = rendererClass;
}
private String rendererType;
- public String getRendererType() {
+
+ public String getRendererType()
+ {
return this.rendererType;
}
- public void setRendererType(String rendererType) {
+
+ public void setRendererType(String rendererType)
+ {
this.rendererType = rendererType;
}
}
-
/**
* <p>Digester <code>Rule</code> for processing renderers.</p>
*/
- class RendererRule extends Rule {
+ class RendererRule extends Rule
+ {
- public void begin(String namespace, String name, Attributes attributes) {
+ public void begin(String namespace, String name, Attributes attributes)
+ {
getDigester().push(new RendererBean());
}
- public void end(String namespace, String name) {
+ public void end(String namespace, String name)
+ {
RendererBean bean = (RendererBean) getDigester().pop();
RenderKit kit = (RenderKit) getDigester().peek();
Renderer renderer = null;
Class clazz = null;
- try {
+ try
+ {
clazz = classForName(bean.getRendererClass());
renderer = (Renderer) clazz.newInstance();
- } catch (Exception e) {
- throw new IllegalArgumentException("Exception while trying to instantiate"
- + " renderer class '" + bean.getRendererClass() + "' : "
- + e.getMessage());
+ }
+ catch (Exception e)
+ {
+ throw new IllegalArgumentException(
+ "Exception while trying to instantiate"
+ + " renderer class '" + bean.getRendererClass()
+ + "' : " + e.getMessage());
}
kit.addRenderer(bean.getComponentFamily(), bean.getRendererType(),
- renderer);
+ renderer);
}
}
-
/**
* <p>Data bean that stores information related to a validator.</p>
*/
- class ValidatorBean {
+ class ValidatorBean
+ {
private String validatorClass;
- public String getValidatorClass() {
+
+ public String getValidatorClass()
+ {
return this.validatorClass;
}
- public void setValidatorClass(String validatorClass) {
+
+ public void setValidatorClass(String validatorClass)
+ {
this.validatorClass = validatorClass;
}
private String validatorId;
- public String getValidatorId() {
+
+ public String getValidatorId()
+ {
return this.validatorId;
}
- public void setValidatorId(String validatorId) {
+
+ public void setValidatorId(String validatorId)
+ {
this.validatorId = validatorId;
}
}
-
/**
* <p>Digester <code>Rule</code> for processing validators.</p>
*/
- class ValidatorRule extends Rule {
+ class ValidatorRule extends Rule
+ {
- public void begin(String namespace, String name, Attributes attributes) {
+ public void begin(String namespace, String name, Attributes attributes)
+ {
getDigester().push(new ValidatorBean());
}
- public void end(String namespace, String name) {
+ public void end(String namespace, String name)
+ {
ValidatorBean bean = (ValidatorBean) getDigester().pop();
Application application = (Application) getDigester().peek();
- application.addValidator(bean.getValidatorId(), bean.getValidatorClass());
+ application.addValidator(bean.getValidatorId(), bean
+ .getValidatorClass());
}
}
@@ -519,15 +592,16 @@
class ClientBehaviorRendererBean
{
private String clientBehaviorRendererType;
-
+
private String clientBehaviorRendererClass;
-
+
public String getClientBehaviorRendererType()
{
return clientBehaviorRendererType;
}
- public void setClientBehaviorRendererType(String clientBehaviorRendererType)
+ public void setClientBehaviorRendererType(
+ String clientBehaviorRendererType)
{
this.clientBehaviorRendererType = clientBehaviorRendererType;
}
@@ -537,12 +611,13 @@
return clientBehaviorRendererClass;
}
- public void setClientBehaviorRendererClass(String clientBehaviorRendererClass)
+ public void setClientBehaviorRendererClass(
+ String clientBehaviorRendererClass)
{
this.clientBehaviorRendererClass = clientBehaviorRendererClass;
}
}
-
+
class ClientBehaviorRendererRule extends Rule
{
public void begin(String namespace, String name, Attributes attributes)
@@ -550,21 +625,28 @@
getDigester().push(new ClientBehaviorRendererBean());
}
- public void end(String namespace, String name) {
- ClientBehaviorRendererBean bean = (ClientBehaviorRendererBean) getDigester().pop();
+ public void end(String namespace, String name)
+ {
+ ClientBehaviorRendererBean bean = (ClientBehaviorRendererBean) getDigester()
+ .pop();
RenderKit kit = (RenderKit) getDigester().peek();
ClientBehaviorRenderer renderer = null;
Class clazz = null;
- try {
+ try
+ {
clazz = classForName(bean.getClientBehaviorRendererClass());
renderer = (ClientBehaviorRenderer) clazz.newInstance();
- } catch (Exception e) {
- throw new IllegalArgumentException("Exception while trying to instantiate"
- + " client behavior renderer class '" + bean.getClientBehaviorRendererClass() + "' : "
- + e.getMessage());
}
- kit.addClientBehaviorRenderer(bean.getClientBehaviorRendererType(),
- renderer);
+ catch (Exception e)
+ {
+ throw new IllegalArgumentException(
+ "Exception while trying to instantiate"
+ + " client behavior renderer class '"
+ + bean.getClientBehaviorRendererClass()
+ + "' : " + e.getMessage());
+ }
+ kit.addClientBehaviorRenderer(bean.getClientBehaviorRendererType(),
+ renderer);
}
}
@@ -602,7 +684,6 @@
}
-
/**
* <p>Digester <code>Rule</code> for processing behaviors.</p>
*/
@@ -618,7 +699,8 @@
{
BehaviorBean bean = (BehaviorBean) getDigester().pop();
Application application = (Application) getDigester().peek();
- application.addBehavior(bean.getBehaviorId(), bean.getBehaviorClass());
+ application.addBehavior(bean.getBehaviorId(), bean
+ .getBehaviorClass());
}
}
diff --git a/test20/src/main/java/org/apache/myfaces/test/jmock/AbstractJmockJsfTestCase.java b/test20/src/main/java/org/apache/myfaces/test/jmock/AbstractJmockJsfTestCase.java
index e9cf4d3..450969c 100644
--- a/test20/src/main/java/org/apache/myfaces/test/jmock/AbstractJmockJsfTestCase.java
+++ b/test20/src/main/java/org/apache/myfaces/test/jmock/AbstractJmockJsfTestCase.java
@@ -72,34 +72,36 @@
* @since 1.0.0
*/
-public abstract class AbstractJmockJsfTestCase extends MockObjectTestCase {
-
+public abstract class AbstractJmockJsfTestCase extends MockObjectTestCase
+{
// ------------------------------------------------------------ Constructors
-
/**
* <p>Construct a new instance of this test case.</p>
*
* @param name Name of this test case
*/
- public AbstractJmockJsfTestCase(String name) {
+ public AbstractJmockJsfTestCase(String name)
+ {
setName(name);
}
-
// ---------------------------------------------------- Overall Test Methods
-
/**
* <p>Set up instance variables required by this test case.</p>
*/
- protected void setUp() throws Exception {
+ protected void setUp() throws Exception
+ {
// Set up a new thread context class loader
- threadContextClassLoader = Thread.currentThread().getContextClassLoader();
- Thread.currentThread().setContextClassLoader(new URLClassLoader(new URL[0],
- this.getClass().getClassLoader()));
+ threadContextClassLoader = Thread.currentThread()
+ .getContextClassLoader();
+ Thread.currentThread()
+ .setContextClassLoader(
+ new URLClassLoader(new URL[0], this.getClass()
+ .getClassLoader()));
// Set up Servlet API Objects
setUpServletObjects();
@@ -111,7 +113,7 @@
setUpJSFObjects();
}
-
+
/**
* <p>Setup JSF object used for the test. By default it calls to the following
* methods in this order:</p>
@@ -127,7 +129,7 @@
*
* @throws Exception
*/
- protected void setUpJSFObjects() throws Exception
+ protected void setUpJSFObjects() throws Exception
{
setUpExternalContext();
setUpLifecycle();
@@ -136,7 +138,7 @@
setUpApplication();
setUpRenderKit();
}
-
+
/**
* <p>Setup servlet objects that will be used for the test:</p>
*
@@ -150,7 +152,7 @@
*
* @throws Exception
*/
- protected void setUpServletObjects() throws Exception
+ protected void setUpServletObjects() throws Exception
{
servletContext = new MockServletContext();
config = new MockServletConfig(servletContext);
@@ -160,28 +162,28 @@
request.setServletContext(servletContext);
response = new MockHttpServletResponse();
}
-
+
/**
* <p>Set JSF factories using FactoryFinder method setFactory.</p>
*
* @throws Exception
*/
- protected void setFactories() throws Exception
+ protected void setFactories() throws Exception
{
FactoryFinder.setFactory(FactoryFinder.APPLICATION_FACTORY,
- "org.apache.myfaces.test.mock.MockApplicationFactory");
+ "org.apache.myfaces.test.mock.MockApplicationFactory");
FactoryFinder.setFactory(FactoryFinder.FACES_CONTEXT_FACTORY,
- "org.apache.myfaces.test.mock.MockFacesContextFactory");
+ "org.apache.myfaces.test.mock.MockFacesContextFactory");
FactoryFinder.setFactory(FactoryFinder.LIFECYCLE_FACTORY,
- "org.apache.myfaces.test.mock.lifecycle.MockLifecycleFactory");
+ "org.apache.myfaces.test.mock.lifecycle.MockLifecycleFactory");
FactoryFinder.setFactory(FactoryFinder.RENDER_KIT_FACTORY,
- "org.apache.myfaces.test.mock.MockRenderKitFactory");
+ "org.apache.myfaces.test.mock.MockRenderKitFactory");
FactoryFinder.setFactory(FactoryFinder.EXCEPTION_HANDLER_FACTORY,
- "org.apache.myfaces.test.mock.MockExceptionHandlerFactory");
+ "org.apache.myfaces.test.mock.MockExceptionHandlerFactory");
FactoryFinder.setFactory(FactoryFinder.PARTIAL_VIEW_CONTEXT_FACTORY,
- "org.apache.myfaces.test.mock.MockPartialViewContextFactory");
+ "org.apache.myfaces.test.mock.MockPartialViewContextFactory");
FactoryFinder.setFactory(FactoryFinder.VISIT_CONTEXT_FACTORY,
- "org.apache.myfaces.test.mock.visit.MockVisitContextFactory");
+ "org.apache.myfaces.test.mock.visit.MockVisitContextFactory");
}
/**
@@ -192,8 +194,8 @@
*/
protected void setUpExternalContext() throws Exception
{
- externalContext =
- new MockExternalContext(servletContext, request, response);
+ externalContext = new MockExternalContext(servletContext, request,
+ response);
}
/**
@@ -204,12 +206,12 @@
*/
protected void setUpLifecycle() throws Exception
{
- lifecycleFactory = (MockLifecycleFactory)
- FactoryFinder.getFactory(FactoryFinder.LIFECYCLE_FACTORY);
- lifecycle = (MockLifecycle)
- lifecycleFactory.getLifecycle(LifecycleFactory.DEFAULT_LIFECYCLE);
+ lifecycleFactory = (MockLifecycleFactory) FactoryFinder
+ .getFactory(FactoryFinder.LIFECYCLE_FACTORY);
+ lifecycle = (MockLifecycle) lifecycleFactory
+ .getLifecycle(LifecycleFactory.DEFAULT_LIFECYCLE);
}
-
+
/**
* Setup the <code>facesContextFactory</code> and <code>facesContext</code>
* variable. Before end, by default it override <code>externalContext</code>
@@ -221,16 +223,14 @@
*/
protected void setUpFacesContext() throws Exception
{
- facesContextFactory = (MockFacesContextFactory)
- FactoryFinder.getFactory(FactoryFinder.FACES_CONTEXT_FACTORY);
- facesContext = (MockFacesContext)
- facesContextFactory.getFacesContext(servletContext,
- request,
- response,
- lifecycle);
+ facesContextFactory = (MockFacesContextFactory) FactoryFinder
+ .getFactory(FactoryFinder.FACES_CONTEXT_FACTORY);
+ facesContext = (MockFacesContext) facesContextFactory.getFacesContext(
+ servletContext, request, response, lifecycle);
if (facesContext.getExternalContext() != null)
{
- externalContext = (MockExternalContext) facesContext.getExternalContext();
+ externalContext = (MockExternalContext) facesContext
+ .getExternalContext();
}
}
@@ -247,7 +247,7 @@
root.setRenderKitId(RenderKitFactory.HTML_BASIC_RENDER_KIT);
facesContext.setViewRoot(root);
}
-
+
/**
* Setup the <code>application</code> variable and before
* the end by default it is assigned to the <code>facesContext</code>
@@ -257,12 +257,12 @@
*/
protected void setUpApplication() throws Exception
{
- ApplicationFactory applicationFactory = (ApplicationFactory)
- FactoryFinder.getFactory(FactoryFinder.APPLICATION_FACTORY);
+ ApplicationFactory applicationFactory = (ApplicationFactory) FactoryFinder
+ .getFactory(FactoryFinder.APPLICATION_FACTORY);
application = (MockApplication) applicationFactory.getApplication();
facesContext.setApplication(application);
}
-
+
/**
* Setup the <code>renderKit</code> variable. This is a good place to use
* <code>ConfigParser</code> to register converters, validators, components
@@ -272,21 +272,24 @@
*/
protected void setUpRenderKit() throws Exception
{
- RenderKitFactory renderKitFactory = (RenderKitFactory)
- FactoryFinder.getFactory(FactoryFinder.RENDER_KIT_FACTORY);
+ RenderKitFactory renderKitFactory = (RenderKitFactory) FactoryFinder
+ .getFactory(FactoryFinder.RENDER_KIT_FACTORY);
renderKit = new MockRenderKit();
- renderKitFactory.addRenderKit(RenderKitFactory.HTML_BASIC_RENDER_KIT, renderKit);
+ renderKitFactory.addRenderKit(RenderKitFactory.HTML_BASIC_RENDER_KIT,
+ renderKit);
}
/**
* <p>Tear down instance variables required by this test case.</p>
*/
- protected void tearDown() throws Exception {
+ protected void tearDown() throws Exception
+ {
application = null;
config = null;
externalContext = null;
- if (facesContext != null) {
+ if (facesContext != null)
+ {
facesContext.release();
}
facesContext = null;
@@ -304,23 +307,21 @@
}
-
// ------------------------------------------------------ Instance Variables
-
// Mock object instances for our tests
- protected MockApplication application = null;
- protected MockServletConfig config = null;
- protected MockExternalContext externalContext = null;
- protected MockFacesContext facesContext = null;
+ protected MockApplication application = null;
+ protected MockServletConfig config = null;
+ protected MockExternalContext externalContext = null;
+ protected MockFacesContext facesContext = null;
protected MockFacesContextFactory facesContextFactory = null;
- protected MockLifecycle lifecycle = null;
- protected MockLifecycleFactory lifecycleFactory = null;
- protected MockRenderKit renderKit = null;
- protected MockHttpServletRequest request = null;
+ protected MockLifecycle lifecycle = null;
+ protected MockLifecycleFactory lifecycleFactory = null;
+ protected MockRenderKit renderKit = null;
+ protected MockHttpServletRequest request = null;
protected MockHttpServletResponse response = null;
- protected MockServletContext servletContext = null;
- protected MockHttpSession session = null;
+ protected MockServletContext servletContext = null;
+ protected MockHttpSession session = null;
// Thread context class loader saved and restored after each test
private ClassLoader threadContextClassLoader = null;
diff --git a/test20/src/main/java/org/apache/myfaces/test/mock/MockApplication20.java b/test20/src/main/java/org/apache/myfaces/test/mock/MockApplication20.java
index a9f4a4a..b3ecb2e 100644
--- a/test20/src/main/java/org/apache/myfaces/test/mock/MockApplication20.java
+++ b/test20/src/main/java/org/apache/myfaces/test/mock/MockApplication20.java
@@ -50,13 +50,12 @@
public class MockApplication20 extends MockApplication12
{
-
// ------------------------------------------------------------ Constructors
public MockApplication20()
{
super();
-
+
// install the 2.0-ViewHandler-Mock
this.setViewHandler(new MockViewHandler20());
this.setResourceHandler(new MockResourceHandler());
@@ -191,11 +190,11 @@
// ------------------------------------------------------ Instance Variables
private static final Log log = LogFactory.getLog(MockApplication20.class);
-
+
private final Map<Class<? extends SystemEvent>, SystemListenerEntry> _systemEventListenerClassMap = new ConcurrentHashMap<Class<? extends SystemEvent>, SystemListenerEntry>();
-
+
private Map<String, String> _defaultValidatorsIds = new HashMap<String, String>();
-
+
private ProjectStage _projectStage;
private final Map<String, Class<?>> _behaviorClassMap = new ConcurrentHashMap<String, Class<?>>();
@@ -205,7 +204,7 @@
private ResourceHandler _resourceHandler;
// ----------------------------------------------------- Mock Object Methods
-
+
public Map<String, String> getDefaultValidatorInfo()
{
return Collections.unmodifiableMap(_defaultValidatorsIds);
@@ -266,7 +265,7 @@
return event;
}
-
+
private void checkNull(final Object param, final String paramName)
{
if (param == null)
@@ -279,11 +278,14 @@
{
if (param.length() == 0)
{
- throw new NullPointerException("String " + paramName + " cannot be empty.");
+ throw new NullPointerException("String " + paramName
+ + " cannot be empty.");
}
}
- public void publishEvent(FacesContext facesContext, Class<? extends SystemEvent> systemEventClass, Class<?> sourceBaseType, Object source)
+ public void publishEvent(FacesContext facesContext,
+ Class<? extends SystemEvent> systemEventClass,
+ Class<?> sourceBaseType, Object source)
{
checkNull(systemEventClass, "systemEventClass");
checkNull(source, "source");
@@ -294,18 +296,21 @@
if (source instanceof SystemEventListenerHolder)
{
SystemEventListenerHolder holder = (SystemEventListenerHolder) source;
-
+
// If the source argument implements SystemEventListenerHolder, call
// SystemEventListenerHolder.getListenersForEventClass(java.lang.Class) on it, passing the systemEventClass
// argument. If the list is not empty, perform algorithm traverseListenerList on the list.
- event = _traverseListenerList(holder.getListenersForEventClass(systemEventClass), systemEventClass, source,
- event);
+ event = _traverseListenerList(holder
+ .getListenersForEventClass(systemEventClass),
+ systemEventClass, source, event);
}
-
- SystemListenerEntry systemListenerEntry = _systemEventListenerClassMap.get(systemEventClass);
+
+ SystemListenerEntry systemListenerEntry = _systemEventListenerClassMap
+ .get(systemEventClass);
if (systemListenerEntry != null)
{
- systemListenerEntry.publish(systemEventClass, sourceBaseType, source, event);
+ systemListenerEntry.publish(systemEventClass, sourceBaseType,
+ source, event);
}
}
catch (AbortProcessingException e)
@@ -317,7 +322,8 @@
}
}
- public void publishEvent(FacesContext facesContext, Class<? extends SystemEvent> systemEventClass, Object source)
+ public void publishEvent(FacesContext facesContext,
+ Class<? extends SystemEvent> systemEventClass, Object source)
{
publishEvent(facesContext, systemEventClass, source.getClass(), source);
}
@@ -330,7 +336,8 @@
{
FacesContext context = FacesContext.getCurrentInstance();
- String stageName = context.getExternalContext().getInitParameter(ProjectStage.PROJECT_STAGE_PARAM_NAME);
+ String stageName = context.getExternalContext().getInitParameter(
+ ProjectStage.PROJECT_STAGE_PARAM_NAME);
// If a value is found found
if (stageName != null)
@@ -349,14 +356,13 @@
//log.log(Level.SEVERE, "Couldn't discover the current project stage", e);
}
}
-
+
_projectStage = ProjectStage.Production;
}
return _projectStage;
}
-
public void addBehavior(String behaviorId, String behaviorClass)
{
checkNull(behaviorId, "behaviorId");
@@ -364,9 +370,12 @@
checkNull(behaviorClass, "behaviorClass");
checkEmpty(behaviorClass, "behaviorClass");
- try {
+ try
+ {
_behaviorClassMap.put(behaviorId, Class.forName(behaviorClass));
- } catch (ClassNotFoundException ignore) {
+ }
+ catch (ClassNotFoundException ignore)
+ {
}
@@ -385,7 +394,9 @@
final Class<?> behaviorClass = this._behaviorClassMap.get(behaviorId);
if (behaviorClass == null)
{
- throw new FacesException("Could not find any registered behavior-class for behaviorId : " + behaviorId);
+ throw new FacesException(
+ "Could not find any registered behavior-class for behaviorId : "
+ + behaviorId);
}
try
@@ -395,18 +406,22 @@
}
catch (Exception e)
{
- throw new FacesException("Could not instantiate behavior: " + behaviorClass, e);
+ throw new FacesException("Could not instantiate behavior: "
+ + behaviorClass, e);
}
}
@Override
- public void addValidator(String validatorId, String validatorClass) {
+ public void addValidator(String validatorId, String validatorClass)
+ {
super.addValidator(validatorId, validatorClass);
- try {
- _validatorClassMap.put(validatorId,
- Class.forName(validatorClass));
- } catch (ClassNotFoundException ex) {
+ try
+ {
+ _validatorClassMap.put(validatorId, Class.forName(validatorClass));
+ }
+ catch (ClassNotFoundException ex)
+ {
throw new FacesException(ex.getMessage());
}
@@ -416,7 +431,8 @@
{
if (_validatorClassMap.containsKey(validatorId))
{
- _defaultValidatorsIds.put(validatorId, _validatorClassMap.get(validatorId).getName());
+ _defaultValidatorsIds.put(validatorId, _validatorClassMap.get(
+ validatorId).getName());
}
}
@@ -432,13 +448,14 @@
_resourceHandler = resourceHandler;
}
- public void subscribeToEvent(Class<? extends SystemEvent> systemEventClass, SystemEventListener listener)
+ public void subscribeToEvent(Class<? extends SystemEvent> systemEventClass,
+ SystemEventListener listener)
{
subscribeToEvent(systemEventClass, null, listener);
}
- public void subscribeToEvent(Class<? extends SystemEvent> systemEventClass, Class<?> sourceClass,
- SystemEventListener listener)
+ public void subscribeToEvent(Class<? extends SystemEvent> systemEventClass,
+ Class<?> sourceClass, SystemEventListener listener)
{
checkNull(systemEventClass, "systemEventClass");
checkNull(listener, "listener");
@@ -446,29 +463,35 @@
SystemListenerEntry systemListenerEntry;
synchronized (_systemEventListenerClassMap)
{
- systemListenerEntry = _systemEventListenerClassMap.get(systemEventClass);
+ systemListenerEntry = _systemEventListenerClassMap
+ .get(systemEventClass);
if (systemListenerEntry == null)
{
systemListenerEntry = new SystemListenerEntry();
- _systemEventListenerClassMap.put(systemEventClass, systemListenerEntry);
+ _systemEventListenerClassMap.put(systemEventClass,
+ systemListenerEntry);
}
}
systemListenerEntry.addListener(listener, sourceClass);
}
- public void unsubscribeFromEvent(Class<? extends SystemEvent> systemEventClass, SystemEventListener listener)
+ public void unsubscribeFromEvent(
+ Class<? extends SystemEvent> systemEventClass,
+ SystemEventListener listener)
{
unsubscribeFromEvent(systemEventClass, null, listener);
}
- public void unsubscribeFromEvent(Class<? extends SystemEvent> systemEventClass, Class<?> sourceClass,
- SystemEventListener listener)
+ public void unsubscribeFromEvent(
+ Class<? extends SystemEvent> systemEventClass,
+ Class<?> sourceClass, SystemEventListener listener)
{
checkNull(systemEventClass, "systemEventClass");
checkNull(listener, "listener");
- SystemListenerEntry systemListenerEntry = _systemEventListenerClassMap.get(systemEventClass);
+ SystemListenerEntry systemListenerEntry = _systemEventListenerClassMap
+ .get(systemEventClass);
if (systemListenerEntry != null)
{
systemListenerEntry.removeListener(listener, sourceClass);
diff --git a/test20/src/main/java/org/apache/myfaces/test/mock/MockApplicationFactory.java b/test20/src/main/java/org/apache/myfaces/test/mock/MockApplicationFactory.java
index f65c985..bc634b0 100644
--- a/test20/src/main/java/org/apache/myfaces/test/mock/MockApplicationFactory.java
+++ b/test20/src/main/java/org/apache/myfaces/test/mock/MockApplicationFactory.java
@@ -28,80 +28,101 @@
* @since 1.0.0
*/
-public class MockApplicationFactory extends ApplicationFactory {
-
+public class MockApplicationFactory extends ApplicationFactory
+{
// ------------------------------------------------------------ Constructors
-
/**
* <p>Construct a default instance.</p>
*/
- public MockApplicationFactory() {
+ public MockApplicationFactory()
+ {
}
-
// ----------------------------------------------------- Mock Object Methods
-
// ------------------------------------------------------ Instance Variables
-
/**
* <p>The <code>Application</code> instance to be returned by
* this factory.</p>
*/
private Application application = null;
-
// --------------------------------------------- AppolicationFactory Methods
-
/** {@inheritDoc} */
- public Application getApplication() {
+ public Application getApplication()
+ {
- if (this.application == null) {
+ if (this.application == null)
+ {
Class clazz = null;
-
- try {
- clazz = this.getClass().getClassLoader().loadClass
- ("org.apache.myfaces.test.mock.MockApplication20");
+
+ try
+ {
+ clazz = this.getClass().getClassLoader().loadClass(
+ "org.apache.myfaces.test.mock.MockApplication20");
this.application = (MockApplication) clazz.newInstance();
- } catch (NoClassDefFoundError e) {
+ }
+ catch (NoClassDefFoundError e)
+ {
clazz = null; // We are not running in a JSF 1.2 environment
- } catch (ClassNotFoundException e) {
+ }
+ catch (ClassNotFoundException e)
+ {
clazz = null; // Same as above
- } catch (RuntimeException e) {
+ }
+ catch (RuntimeException e)
+ {
throw e;
- } catch (Exception e) {
+ }
+ catch (Exception e)
+ {
throw new FacesException(e);
}
-
+
if (clazz == null)
{
- try {
- clazz = this.getClass().getClassLoader().loadClass
- ("org.apache.myfaces.test.mock.MockApplication12");
+ try
+ {
+ clazz = this.getClass().getClassLoader().loadClass(
+ "org.apache.myfaces.test.mock.MockApplication12");
this.application = (MockApplication) clazz.newInstance();
- } catch (NoClassDefFoundError e) {
+ }
+ catch (NoClassDefFoundError e)
+ {
clazz = null; // We are not running in a JSF 1.2 environment
- } catch (ClassNotFoundException e) {
+ }
+ catch (ClassNotFoundException e)
+ {
clazz = null; // Same as above
- } catch (RuntimeException e) {
+ }
+ catch (RuntimeException e)
+ {
throw e;
- } catch (Exception e) {
+ }
+ catch (Exception e)
+ {
throw new FacesException(e);
}
}
- if (clazz == null) {
- try {
- clazz = this.getClass().getClassLoader().loadClass
- ("org.apache.myfaces.test.mock.MockApplication");
+ if (clazz == null)
+ {
+ try
+ {
+ clazz = this.getClass().getClassLoader().loadClass(
+ "org.apache.myfaces.test.mock.MockApplication");
this.application = (MockApplication) clazz.newInstance();
- } catch (RuntimeException e) {
+ }
+ catch (RuntimeException e)
+ {
throw e;
- } catch (Exception e) {
+ }
+ catch (Exception e)
+ {
throw new FacesException(e);
}
}
@@ -110,13 +131,12 @@
}
-
/** {@inheritDoc} */
- public void setApplication(Application application) {
+ public void setApplication(Application application)
+ {
this.application = application;
}
-
}
diff --git a/test20/src/main/java/org/apache/myfaces/test/mock/MockExceptionHandler.java b/test20/src/main/java/org/apache/myfaces/test/mock/MockExceptionHandler.java
index ac85603..acdf548 100644
--- a/test20/src/main/java/org/apache/myfaces/test/mock/MockExceptionHandler.java
+++ b/test20/src/main/java/org/apache/myfaces/test/mock/MockExceptionHandler.java
@@ -57,7 +57,8 @@
@Override
public Iterable<ExceptionQueuedEvent> getHandledExceptionQueuedEvents()
{
- return handled == null ? Collections.<ExceptionQueuedEvent>emptyList() : handled;
+ return handled == null ? Collections.<ExceptionQueuedEvent> emptyList()
+ : handled;
}
/**
@@ -66,13 +67,17 @@
@Override
public Throwable getRootCause(Throwable t)
{
- if (t == null) {
+ if (t == null)
+ {
throw new NullPointerException("t");
}
- while (t != null) {
+ while (t != null)
+ {
Class<?> clazz = t.getClass();
- if (!clazz.equals(FacesException.class) && !clazz.equals(ELException.class)) {
+ if (!clazz.equals(FacesException.class)
+ && !clazz.equals(ELException.class))
+ {
return t;
}
@@ -88,7 +93,8 @@
@Override
public Iterable<ExceptionQueuedEvent> getUnhandledExceptionQueuedEvents()
{
- return unhandled == null ? Collections.<ExceptionQueuedEvent>emptyList() : unhandled;
+ return unhandled == null ? Collections
+ .<ExceptionQueuedEvent> emptyList() : unhandled;
}
/**
@@ -97,19 +103,23 @@
@Override
public void handle() throws FacesException
{
- if (unhandled != null && !unhandled.isEmpty()) {
- if (handled == null) {
+ if (unhandled != null && !unhandled.isEmpty())
+ {
+ if (handled == null)
+ {
handled = new LinkedList<ExceptionQueuedEvent>();
}
FacesException toThrow = null;
- do {
+ do
+ {
// For each ExceptionEvent in the list
// get the event to handle
ExceptionQueuedEvent event = unhandled.peek();
- try {
+ try
+ {
// call its getContext() method
ExceptionQueuedEventContext context = event.getContext();
@@ -118,7 +128,8 @@
// Upon encountering the first such Exception that is not an instance of
// javax.faces.event.AbortProcessingException
- if (!shouldSkip(exception)) {
+ if (!shouldSkip(exception))
+ {
// set handledAndThrown so that getHandledExceptionQueuedEvent() returns this event
handledAndThrown = event;
@@ -130,22 +141,26 @@
break;
}
}
- catch (Throwable t) {
+ catch (Throwable t)
+ {
// A FacesException must be thrown if a problem occurs while performing
// the algorithm to handle the exception
- throw new FacesException("Could not perform the algorithm to handle the Exception", t);
+ throw new FacesException(
+ "Could not perform the algorithm to handle the Exception",
+ t);
}
- finally {
+ finally
+ {
// if we will throw the Exception or if we just logged it,
// we handled it in either way --> add to handled
handled.add(event);
unhandled.remove(event);
}
- }
- while (!unhandled.isEmpty());
+ } while (!unhandled.isEmpty());
// do we have to throw an Exception?
- if (toThrow != null) {
+ if (toThrow != null)
+ {
throw toThrow;
}
}
@@ -164,9 +179,11 @@
* {@inheritDoc}
*/
@Override
- public void processEvent(SystemEvent exceptionQueuedEvent) throws AbortProcessingException
+ public void processEvent(SystemEvent exceptionQueuedEvent)
+ throws AbortProcessingException
{
- if (unhandled == null) {
+ if (unhandled == null)
+ {
unhandled = new LinkedList<ExceptionQueuedEvent>();
}
@@ -178,7 +195,8 @@
// Let toRethrow be either the result of calling getRootCause() on the Exception,
// or the Exception itself, whichever is non-null
Throwable toRethrow = getRootCause(exception);
- if (toRethrow == null) {
+ if (toRethrow == null)
+ {
toRethrow = exception;
}
@@ -187,7 +205,8 @@
protected FacesException wrap(Throwable exception)
{
- if (exception instanceof FacesException) {
+ if (exception instanceof FacesException)
+ {
return (FacesException) exception;
}
return new FacesException(exception);
diff --git a/test20/src/main/java/org/apache/myfaces/test/mock/MockExternalContext20.java b/test20/src/main/java/org/apache/myfaces/test/mock/MockExternalContext20.java
index 204a7d0..1641048 100644
--- a/test20/src/main/java/org/apache/myfaces/test/mock/MockExternalContext20.java
+++ b/test20/src/main/java/org/apache/myfaces/test/mock/MockExternalContext20.java
@@ -57,21 +57,23 @@
// ------------------------------------------------------ Instance Variables
- private static final String URL_PARAM_SEPERATOR="&";
- private static final String URL_QUERY_SEPERATOR="?";
- private static final String URL_FRAGMENT_SEPERATOR="#";
- private static final String URL_NAME_VALUE_PAIR_SEPERATOR="=";
+ private static final String URL_PARAM_SEPERATOR = "&";
+ private static final String URL_QUERY_SEPERATOR = "?";
+ private static final String URL_FRAGMENT_SEPERATOR = "#";
+ private static final String URL_NAME_VALUE_PAIR_SEPERATOR = "=";
// ----------------------------------------------------- Mock Object Methods
// ------------------------------------------------- ExternalContext Methods
- public String encodeBookmarkableURL(String baseUrl, Map<String,List<String>> parameters)
+ public String encodeBookmarkableURL(String baseUrl,
+ Map<String, List<String>> parameters)
{
return response.encodeURL(encodeURL(baseUrl, parameters));
}
-
- private String encodeURL(String baseUrl, Map<String, List<String>> parameters)
+
+ private String encodeURL(String baseUrl,
+ Map<String, List<String>> parameters)
{
String fragment = null;
String queryString = null;
@@ -81,8 +83,8 @@
int index = baseUrl.indexOf(URL_FRAGMENT_SEPERATOR);
if (index != -1)
{
- fragment = baseUrl.substring(index+1);
- baseUrl = baseUrl.substring(0,index);
+ fragment = baseUrl.substring(index + 1);
+ baseUrl = baseUrl.substring(0, index);
}
//extract the current query string and add the params to the paramMap
@@ -94,7 +96,8 @@
String[] nameValuePairs = queryString.split(URL_PARAM_SEPERATOR);
for (int i = 0; i < nameValuePairs.length; i++)
{
- String[] currentPair = nameValuePairs[i].split(URL_NAME_VALUE_PAIR_SEPERATOR);
+ String[] currentPair = nameValuePairs[i]
+ .split(URL_NAME_VALUE_PAIR_SEPERATOR);
if (currentPair[1] != null)
{
ArrayList<String> value = new ArrayList<String>(1);
@@ -120,7 +123,7 @@
StringBuilder newUrl = new StringBuilder(baseUrl);
//now add the updated param list onto the url
- if (paramMap.size()>0)
+ if (paramMap.size() > 0)
{
boolean isFirstPair = true;
for (Map.Entry<String, List<String>> pair : paramMap.entrySet())
@@ -141,12 +144,16 @@
newUrl.append(URL_NAME_VALUE_PAIR_SEPERATOR);
try
{
- newUrl.append(URLEncoder.encode(value,getResponseCharacterEncoding()));
+ newUrl.append(URLEncoder.encode(value,
+ getResponseCharacterEncoding()));
}
catch (UnsupportedEncodingException e)
{
//shouldn't ever get here
- throw new UnsupportedOperationException("Encoding type=" + getResponseCharacterEncoding() + " not supported", e);
+ throw new UnsupportedOperationException(
+ "Encoding type="
+ + getResponseCharacterEncoding()
+ + " not supported", e);
}
}
}
@@ -161,18 +168,20 @@
return newUrl.toString();
}
- public String encodeRedirectURL(String baseUrl, Map<String,List<String>> parameters)
+ public String encodeRedirectURL(String baseUrl,
+ Map<String, List<String>> parameters)
{
return response.encodeRedirectURL(encodeURL(baseUrl, parameters));
}
-
+
@Override
public String encodePartialActionURL(String url)
{
return ((HttpServletResponse) response).encodeURL(url);
}
- public String getContextName() {
+ public String getContextName()
+ {
return context.getServletContextName();
}
@@ -181,7 +190,8 @@
return context.getRealPath(path);
}
- public void responseSendError(int statusCode, String message) throws IOException
+ public void responseSendError(int statusCode, String message)
+ throws IOException
{
if (message == null)
{
diff --git a/test20/src/main/java/org/apache/myfaces/test/mock/MockFacesContext20.java b/test20/src/main/java/org/apache/myfaces/test/mock/MockFacesContext20.java
index 5f60ba6..d40b714 100644
--- a/test20/src/main/java/org/apache/myfaces/test/mock/MockFacesContext20.java
+++ b/test20/src/main/java/org/apache/myfaces/test/mock/MockFacesContext20.java
@@ -40,22 +40,25 @@
* @since 1.0.0
*
*/
-public class MockFacesContext20 extends MockFacesContext12 {
+public class MockFacesContext20 extends MockFacesContext12
+{
// ------------------------------------------------------------ Constructors
-
- public MockFacesContext20() {
+
+ public MockFacesContext20()
+ {
super();
setCurrentInstance(this);
}
-
- public MockFacesContext20(ExternalContext externalContext) {
+ public MockFacesContext20(ExternalContext externalContext)
+ {
super(externalContext);
}
-
- public MockFacesContext20(ExternalContext externalContext, Lifecycle lifecycle) {
+ public MockFacesContext20(ExternalContext externalContext,
+ Lifecycle lifecycle)
+ {
super(externalContext, lifecycle);
}
@@ -66,7 +69,7 @@
private PhaseId _currentPhaseId = PhaseId.RESTORE_VIEW;
private boolean _postback;
private PartialViewContext _partialViewContext = null;
- private Map<Object,Object> attributes;
+ private Map<Object, Object> attributes;
private boolean _validationFailed = false;
// ----------------------------------------------------- Mock Object Methods
@@ -75,17 +78,17 @@
{
return _postback;
}
-
+
public void setPostback(boolean value)
{
_postback = value;
}
-
+
public PhaseId getCurrentPhaseId()
{
return _currentPhaseId;
}
-
+
public void setCurrentPhaseId(PhaseId _currentPhaseId)
{
this._currentPhaseId = _currentPhaseId;
@@ -95,7 +98,7 @@
{
if (attributes == null)
{
- attributes = new HashMap<Object,Object>();
+ attributes = new HashMap<Object, Object>();
}
return attributes;
}
@@ -105,18 +108,18 @@
if (_partialViewContext == null)
{
//Get through factory finder
- PartialViewContextFactory factory = (PartialViewContextFactory)
- FactoryFinder.getFactory(FactoryFinder.PARTIAL_VIEW_CONTEXT_FACTORY);
+ PartialViewContextFactory factory = (PartialViewContextFactory) FactoryFinder
+ .getFactory(FactoryFinder.PARTIAL_VIEW_CONTEXT_FACTORY);
_partialViewContext = factory.getPartialViewContext(this);
}
return _partialViewContext;
}
-
+
public boolean isProcessingEvents()
{
return _processingEvents;
}
-
+
public void setProcessingEvents(boolean processingEvents)
{
_processingEvents = processingEvents;
@@ -137,11 +140,13 @@
{
if (messages == null)
{
- return Collections.unmodifiableList(Collections.<FacesMessage>emptyList());
+ return Collections.unmodifiableList(Collections
+ .<FacesMessage> emptyList());
}
List<FacesMessage> lst = new ArrayList<FacesMessage>();
- for(List<FacesMessage> curLst : ((Map<String, List<FacesMessage>>) messages).values())
+ for (List<FacesMessage> curLst : ((Map<String, List<FacesMessage>>) messages)
+ .values())
{
lst.addAll(curLst);
}
@@ -154,7 +159,8 @@
{
if (messages == null || !messages.containsKey(clientId))
{
- return Collections.unmodifiableList(Collections.<FacesMessage>emptyList());
+ return Collections.unmodifiableList(Collections
+ .<FacesMessage> emptyList());
}
return ((Map<String, List<FacesMessage>>) messages).get(clientId);
diff --git a/test20/src/main/java/org/apache/myfaces/test/mock/MockFacesContextFactory.java b/test20/src/main/java/org/apache/myfaces/test/mock/MockFacesContextFactory.java
index 5f205f0..1a2e1ec 100644
--- a/test20/src/main/java/org/apache/myfaces/test/mock/MockFacesContextFactory.java
+++ b/test20/src/main/java/org/apache/myfaces/test/mock/MockFacesContextFactory.java
@@ -34,105 +34,125 @@
* @since 1.0.0
*/
-public class MockFacesContextFactory extends FacesContextFactory {
-
+public class MockFacesContextFactory extends FacesContextFactory
+{
// ------------------------------------------------------------ Constructors
-
/**
* <p>Look up the constructor we will use for creating <code>MockFacesContext</code>
* instances.</p>
*/
- public MockFacesContextFactory() {
+ public MockFacesContextFactory()
+ {
Class clazz = null;
// Try to load the 2.0 version of our mock FacesContext class
- try {
- clazz = this.getClass().getClassLoader().loadClass("org.apache.myfaces.test.mock.MockFacesContext20");
+ try
+ {
+ clazz = this.getClass().getClassLoader().loadClass(
+ "org.apache.myfaces.test.mock.MockFacesContext20");
constructor = clazz.getConstructor(facesContextSignature);
jsf20 = true;
- } catch (NoClassDefFoundError e) {
+ }
+ catch (NoClassDefFoundError e)
+ {
// We are not running on JSF 2.0, so go to our fallback
clazz = null;
constructor = null;
- } catch (ClassNotFoundException e) {
+ }
+ catch (ClassNotFoundException e)
+ {
// Same as above
clazz = null;
constructor = null;
- } catch (RuntimeException e) {
+ }
+ catch (RuntimeException e)
+ {
throw e;
- } catch (Exception e) {
+ }
+ catch (Exception e)
+ {
throw new FacesException(e);
- }
-
+ }
+
// Try to load the 1.2 version of our mock FacesContext class
- try {
+ try
+ {
if (clazz == null)
{
- clazz = this.getClass().getClassLoader().loadClass("org.apache.myfaces.test.mock.MockFacesContext12");
+ clazz = this.getClass().getClassLoader().loadClass(
+ "org.apache.myfaces.test.mock.MockFacesContext12");
constructor = clazz.getConstructor(facesContextSignature);
jsf12 = true;
}
- } catch (NoClassDefFoundError e) {
+ }
+ catch (NoClassDefFoundError e)
+ {
// We are not running on JSF 1.2, so go to our fallback
clazz = null;
constructor = null;
- } catch (ClassNotFoundException e) {
+ }
+ catch (ClassNotFoundException e)
+ {
// Same as above
clazz = null;
constructor = null;
- } catch (RuntimeException e) {
+ }
+ catch (RuntimeException e)
+ {
throw e;
- } catch (Exception e) {
+ }
+ catch (Exception e)
+ {
throw new FacesException(e);
}
// Fall back to the 1.1 version if we could not load the 1.2 version
- try {
- if (clazz == null) {
- clazz = this.getClass().getClassLoader().loadClass("org.apache.myfaces.test.mock.MockFacesContext");
+ try
+ {
+ if (clazz == null)
+ {
+ clazz = this.getClass().getClassLoader().loadClass(
+ "org.apache.myfaces.test.mock.MockFacesContext");
constructor = clazz.getConstructor(facesContextSignature);
jsf12 = false;
}
- } catch (RuntimeException e) {
+ }
+ catch (RuntimeException e)
+ {
throw e;
- } catch (Exception e) {
+ }
+ catch (Exception e)
+ {
throw new FacesException(e);
}
}
-
// ----------------------------------------------------- Mock Object Methods
-
// ------------------------------------------------------ Instance Variables
-
/**
* <p>The constructor for creating a <code>FacesContext</code> instance,
* taking an <code>ExternalContext</code> and <code>Lifecycle</code>.</p>
*/
private Constructor constructor = null;
-
/**
* <p>The parameter signature of the ExternalContext constructor we wish to call.</p>
*/
private static Class[] externalContextSignature = new Class[] {
- ServletContext.class, HttpServletRequest.class, HttpServletResponse.class
- };
-
+ ServletContext.class, HttpServletRequest.class,
+ HttpServletResponse.class };
/**
* <p>The parameter signature of the FacesContext constructor we wish to call.</p>
*/
private static Class[] facesContextSignature = new Class[] {
- ExternalContext.class, Lifecycle.class
- };
-
+ ExternalContext.class, Lifecycle.class };
/**
* <p>Flag indicating that we are running in a JSF 1.2 environment.</p>
@@ -143,72 +163,97 @@
* <p>Flag indicating that we are running in a JSF 2.0 environment.</p>
*/
private boolean jsf20 = false;
-
- // --------------------------------------------- FacesContextFactory Methods
+ // --------------------------------------------- FacesContextFactory Methods
/** {@inheritDoc} */
public FacesContext getFacesContext(Object context, Object request,
- Object response,
- Lifecycle lifecycle) throws FacesException {
+ Object response, Lifecycle lifecycle) throws FacesException
+ {
// Select the appropriate MockExternalContext implementation class
Class clazz = MockExternalContext.class;
-
- if (jsf20) {
- try {
- clazz = this.getClass().getClassLoader().loadClass
- ("org.apache.myfaces.test.mock.MockExternalContext20");
- } catch (RuntimeException e) {
+
+ if (jsf20)
+ {
+ try
+ {
+ clazz = this.getClass().getClassLoader().loadClass(
+ "org.apache.myfaces.test.mock.MockExternalContext20");
+ }
+ catch (RuntimeException e)
+ {
throw e;
- } catch (Exception e) {
+ }
+ catch (Exception e)
+ {
throw new FacesException(e);
}
}
-
- if (jsf12) {
- try {
- clazz = this.getClass().getClassLoader().loadClass
- ("org.apache.myfaces.test.mock.MockExternalContext12");
- } catch (RuntimeException e) {
+
+ if (jsf12)
+ {
+ try
+ {
+ clazz = this.getClass().getClassLoader().loadClass(
+ "org.apache.myfaces.test.mock.MockExternalContext12");
+ }
+ catch (RuntimeException e)
+ {
throw e;
- } catch (Exception e) {
+ }
+ catch (Exception e)
+ {
throw new FacesException(e);
}
}
// Select the constructor we wish to call
Constructor mecConstructor = null;
- try {
+ try
+ {
mecConstructor = clazz.getConstructor(externalContextSignature);
- } catch (RuntimeException e) {
+ }
+ catch (RuntimeException e)
+ {
throw e;
- } catch (Exception e) {
+ }
+ catch (Exception e)
+ {
throw new FacesException(e);
}
// Construct an appropriate MockExternalContext instance
MockExternalContext externalContext = null;
- try {
- externalContext = (MockExternalContext) mecConstructor.newInstance
- (new Object[] { context, request, response });
- } catch (RuntimeException e) {
+ try
+ {
+ externalContext = (MockExternalContext) mecConstructor
+ .newInstance(new Object[] { context, request, response });
+ }
+ catch (RuntimeException e)
+ {
throw e;
- } catch (Exception e) {
+ }
+ catch (Exception e)
+ {
throw new FacesException(e);
}
// Construct an appropriate MockFacesContext instance and return it
- try {
- return (MockFacesContext)
- constructor.newInstance(new Object[] { externalContext, lifecycle });
- } catch (RuntimeException e) {
+ try
+ {
+ return (MockFacesContext) constructor.newInstance(new Object[] {
+ externalContext, lifecycle });
+ }
+ catch (RuntimeException e)
+ {
throw e;
- } catch (Exception e) {
+ }
+ catch (Exception e)
+ {
throw new FacesException(e);
}
}
-
}
diff --git a/test20/src/main/java/org/apache/myfaces/test/mock/MockFlash.java b/test20/src/main/java/org/apache/myfaces/test/mock/MockFlash.java
index 0db3127..c13afa0 100644
--- a/test20/src/main/java/org/apache/myfaces/test/mock/MockFlash.java
+++ b/test20/src/main/java/org/apache/myfaces/test/mock/MockFlash.java
@@ -45,20 +45,21 @@
* Key on app map to keep current instance
*/
static protected final String FLASH_INSTANCE = MockFlash.class.getName()
- + ".INSTANCE";
+ + ".INSTANCE";
/**
* Key used to check if there is the current request will be or was redirected
*/
static protected final String FLASH_REDIRECT = MockFlash.class.getName()
- + ".REDIRECT";
+ + ".REDIRECT";
/**
* Key used to check if this request should keep messages (like tomahawk sandbox RedirectTracker.
* Used when post-redirect-get pattern is used)
*/
- static protected final String FLASH_KEEP_MESSAGES = MockFlash.class.getName()
- + ".KEEP_MESSAGES";
+ static protected final String FLASH_KEEP_MESSAGES = MockFlash.class
+ .getName()
+ + ".KEEP_MESSAGES";
static protected final String FLASH_KEEP_MESSAGES_LIST = "KEEPMESSAGESLIST";
@@ -66,19 +67,23 @@
* Session map prefix to flash maps
*/
static protected final String FLASH_SCOPE_CACHE = MockFlash.class.getName()
- + ".SCOPE";
+ + ".SCOPE";
- static protected final String FLASH_CURRENT_MAP_CACHE = MockFlash.class.getName()
- + ".CURRENTMAP.CACHE";
+ static protected final String FLASH_CURRENT_MAP_CACHE = MockFlash.class
+ .getName()
+ + ".CURRENTMAP.CACHE";
- static protected final String FLASH_CURRENT_MAP_KEY = MockFlash.class.getName()
- + ".CURRENTMAP.KEY";
+ static protected final String FLASH_CURRENT_MAP_KEY = MockFlash.class
+ .getName()
+ + ".CURRENTMAP.KEY";
- static protected final String FLASH_POSTBACK_MAP_CACHE = MockFlash.class.getName()
- + ".POSTBACKMAP.CACHE";
+ static protected final String FLASH_POSTBACK_MAP_CACHE = MockFlash.class
+ .getName()
+ + ".POSTBACKMAP.CACHE";
- static protected final String FLASH_POSTBACK_MAP_KEY = MockFlash.class.getName()
- + ".POSTBACKMAP.KEY";
+ static protected final String FLASH_POSTBACK_MAP_KEY = MockFlash.class
+ .getName()
+ + ".POSTBACKMAP.KEY";
static private final char SEPARATOR_CHAR = '.';
@@ -96,11 +101,13 @@
private static long _getSeed()
{
SecureRandom rng;
- try {
+ try
+ {
// try SHA1 first
rng = SecureRandom.getInstance("SHA1PRNG");
}
- catch (NoSuchAlgorithmException e) {
+ catch (NoSuchAlgorithmException e)
+ {
// SHA1 not present, so try the default (which could potentially not be
// cryptographically secure)
rng = new SecureRandom();
@@ -137,8 +144,10 @@
Map<String, Object> applicationMap = context.getApplicationMap();
Flash flash = (Flash) applicationMap.get(FLASH_INSTANCE);
- synchronized (applicationMap) {
- if (flash == null) {
+ synchronized (applicationMap)
+ {
+ if (flash == null)
+ {
flash = new MockFlash();
context.getApplicationMap().put(FLASH_INSTANCE, flash);
}
@@ -152,7 +161,7 @@
*/
@SuppressWarnings("unchecked")
private Map<String, Object> _getMapFromSession(FacesContext context,
- String token, boolean createIfNeeded)
+ String token, boolean createIfNeeded)
{
ExternalContext external = context.getExternalContext();
Object session = external.getSession(true);
@@ -161,11 +170,13 @@
// Synchronize on the session object to ensure that
// we don't ever create two different caches
- synchronized (session) {
+ synchronized (session)
+ {
map = (Map<String, Object>) external.getSessionMap().get(token);
- if ((map == null) && createIfNeeded) {
+ if ((map == null) && createIfNeeded)
+ {
map = new MockSubKeyMap<Object>(context.getExternalContext()
- .getSessionMap(), token);
+ .getSessionMap(), token);
}
}
@@ -186,9 +197,12 @@
@SuppressWarnings("unchecked")
protected Map<String, Object> getCurrentRequestMap(FacesContext context)
{
- Map<String, Object> requestMap = context.getExternalContext().getRequestMap();
- Map<String, Object> map = (Map<String, Object>) requestMap.get(FLASH_CURRENT_MAP_CACHE);
- if (map == null) {
+ Map<String, Object> requestMap = context.getExternalContext()
+ .getRequestMap();
+ Map<String, Object> map = (Map<String, Object>) requestMap
+ .get(FLASH_CURRENT_MAP_CACHE);
+ if (map == null)
+ {
String token = (String) requestMap.get(FLASH_CURRENT_MAP_KEY);
String fullToken = FLASH_SCOPE_CACHE + SEPARATOR_CHAR + token;
map = _getMapFromSession(context, fullToken, true);
@@ -200,11 +214,15 @@
@SuppressWarnings("unchecked")
protected Map<String, Object> getPostbackRequestMap(FacesContext context)
{
- Map<String, Object> requestMap = context.getExternalContext().getRequestMap();
- Map<String, Object> map = (Map<String, Object>) requestMap.get(FLASH_POSTBACK_MAP_CACHE);
- if (map == null) {
+ Map<String, Object> requestMap = context.getExternalContext()
+ .getRequestMap();
+ Map<String, Object> map = (Map<String, Object>) requestMap
+ .get(FLASH_POSTBACK_MAP_CACHE);
+ if (map == null)
+ {
String token = (String) requestMap.get(FLASH_POSTBACK_MAP_KEY);
- if (token == null && isRedirect()) {
+ if (token == null && isRedirect())
+ {
// In post-redirect-get, request values are reset, so we need
// to get the postback key again.
token = _getPostbackMapKey(context.getExternalContext());
@@ -264,11 +282,13 @@
private Map<String, Object> getCurrentPhaseMap()
{
FacesContext facesContext = FacesContext.getCurrentInstance();
- if (PhaseId.RENDER_RESPONSE.equals(facesContext.getCurrentPhaseId()) ||
- !facesContext.isPostback() || isRedirect()) {
+ if (PhaseId.RENDER_RESPONSE.equals(facesContext.getCurrentPhaseId())
+ || !facesContext.isPostback() || isRedirect())
+ {
return getCurrentRequestMap(facesContext);
}
- else {
+ else
+ {
return getPostbackRequestMap(facesContext);
}
}
@@ -290,34 +310,42 @@
@Override
public void doPrePhaseActions(FacesContext facesContext)
{
- Map<String, Object> requestMap = facesContext.getExternalContext().getRequestMap();
+ Map<String, Object> requestMap = facesContext.getExternalContext()
+ .getRequestMap();
- if (PhaseId.RESTORE_VIEW.equals(facesContext.getCurrentPhaseId())) {
+ if (PhaseId.RESTORE_VIEW.equals(facesContext.getCurrentPhaseId()))
+ {
// Generate token and put on requestMap
// It is necessary to set this token always, because on the next request
// it should be possible to change postback map.
String currentToken = _getNextToken();
requestMap.put(FLASH_CURRENT_MAP_KEY, currentToken);
- if (facesContext.isPostback()) {
+ if (facesContext.isPostback())
+ {
//Retore token
- String previousToken = _getPostbackMapKey(facesContext.getExternalContext());
+ String previousToken = _getPostbackMapKey(facesContext
+ .getExternalContext());
- if (previousToken != null) {
+ if (previousToken != null)
+ {
requestMap.put(FLASH_POSTBACK_MAP_KEY, previousToken);
}
}
- if (isKeepMessages()) {
+ if (isKeepMessages())
+ {
restoreMessages(facesContext);
}
}
//
- if (PhaseId.RENDER_RESPONSE.equals(facesContext.getCurrentPhaseId())) {
+ if (PhaseId.RENDER_RESPONSE.equals(facesContext.getCurrentPhaseId()))
+ {
// Put current map on next previous map
// but only if this request is not a redirect
- if (!isRedirect()) {
+ if (!isRedirect())
+ {
_addPostbackMapKey(facesContext.getExternalContext());
}
}
@@ -326,22 +354,29 @@
@Override
public void doPostPhaseActions(FacesContext facesContext)
{
- if (PhaseId.RENDER_RESPONSE.equals(facesContext.getCurrentPhaseId())) {
+ if (PhaseId.RENDER_RESPONSE.equals(facesContext.getCurrentPhaseId()))
+ {
//Remove previous flash from session
- Map<String, Object> requestMap = facesContext.getExternalContext().getRequestMap();
+ Map<String, Object> requestMap = facesContext.getExternalContext()
+ .getRequestMap();
String token = (String) requestMap.get(FLASH_POSTBACK_MAP_KEY);
- if (token != null) {
+ if (token != null)
+ {
_removeAllChildren(facesContext);
}
- if (isKeepMessages()) {
+ if (isKeepMessages())
+ {
saveMessages(facesContext);
}
}
- else if (isRedirect() &&
- (facesContext.getResponseComplete() || facesContext.getRenderResponse())) {
- if (isKeepMessages()) {
+ else if (isRedirect()
+ && (facesContext.getResponseComplete() || facesContext
+ .getRenderResponse()))
+ {
+ if (isKeepMessages())
+ {
saveMessages(facesContext);
}
}
@@ -363,27 +398,37 @@
{
List<MessageEntry> messageList = null;
- Iterator<String> iterClientIds = facesContext.getClientIdsWithMessages();
- while (iterClientIds.hasNext()) {
+ Iterator<String> iterClientIds = facesContext
+ .getClientIdsWithMessages();
+ while (iterClientIds.hasNext())
+ {
String clientId = (String) iterClientIds.next();
- Iterator<FacesMessage> iterMessages = facesContext.getMessages(clientId);
+ Iterator<FacesMessage> iterMessages = facesContext
+ .getMessages(clientId);
- while (iterMessages.hasNext()) {
+ while (iterMessages.hasNext())
+ {
FacesMessage message = iterMessages.next();
- if (messageList == null) {
+ if (messageList == null)
+ {
messageList = new ArrayList<MessageEntry>();
}
messageList.add(new MessageEntry(clientId, message));
}
}
- if (messageList != null) {
- if (isRedirect()) {
- getPostbackRequestMap(facesContext).put(FLASH_KEEP_MESSAGES_LIST, messageList);
+ if (messageList != null)
+ {
+ if (isRedirect())
+ {
+ getPostbackRequestMap(facesContext).put(
+ FLASH_KEEP_MESSAGES_LIST, messageList);
}
- else {
- getCurrentRequestMap(facesContext).put(FLASH_KEEP_MESSAGES_LIST, messageList);
+ else
+ {
+ getCurrentRequestMap(facesContext).put(
+ FLASH_KEEP_MESSAGES_LIST, messageList);
}
}
}
@@ -391,22 +436,24 @@
protected void restoreMessages(FacesContext facesContext)
{
Map<String, Object> postbackMap = getPostbackRequestMap(facesContext);
- List<MessageEntry> messageList = (List<MessageEntry>)
- postbackMap.get(FLASH_KEEP_MESSAGES_LIST);
+ List<MessageEntry> messageList = (List<MessageEntry>) postbackMap
+ .get(FLASH_KEEP_MESSAGES_LIST);
- if (messageList != null) {
+ if (messageList != null)
+ {
Iterator iterMessages = messageList.iterator();
- while (iterMessages.hasNext()) {
+ while (iterMessages.hasNext())
+ {
MessageEntry message = (MessageEntry) iterMessages.next();
- facesContext.addMessage((String) message.clientId, (FacesMessage) message.message);
+ facesContext.addMessage((String) message.clientId,
+ (FacesMessage) message.message);
}
postbackMap.remove(FLASH_KEEP_MESSAGES_LIST);
}
}
-
//private void _addPreviousToken
/**
@@ -416,14 +463,18 @@
{
String token = null;
Object response = externalContext.getResponse();
- if (response instanceof HttpServletResponse) {
+ if (response instanceof HttpServletResponse)
+ {
//Use a cookie
- Cookie cookie = (Cookie) externalContext.getRequestCookieMap().get(FLASH_POSTBACK_MAP_KEY);
- if (cookie != null) {
+ Cookie cookie = (Cookie) externalContext.getRequestCookieMap().get(
+ FLASH_POSTBACK_MAP_KEY);
+ if (cookie != null)
+ {
token = cookie.getValue();
}
}
- else {
+ else
+ {
//Use HttpSession or PortletSession object
Map<String, Object> sessionMap = externalContext.getSessionMap();
token = (String) sessionMap.get(FLASH_POSTBACK_MAP_KEY);
@@ -439,14 +490,14 @@
private void _addPostbackMapKey(ExternalContext externalContext)
{
Object response = externalContext.getResponse();
- String token = (String) externalContext.getRequestMap().get(FLASH_CURRENT_MAP_KEY);
+ String token = (String) externalContext.getRequestMap().get(
+ FLASH_CURRENT_MAP_KEY);
//Use HttpSession or PortletSession object
Map<String, Object> sessionMap = externalContext.getSessionMap();
sessionMap.put(FLASH_POSTBACK_MAP_KEY, token);
}
-
/**
* For check if there is a redirect we to take into accout this points:
* <p/>
@@ -462,16 +513,19 @@
ExternalContext externalContext = facesContext.getExternalContext();
Map<String, Object> requestMap = externalContext.getRequestMap();
Boolean redirect = (Boolean) requestMap.get(FLASH_REDIRECT);
- if (redirect == null) {
+ if (redirect == null)
+ {
Object response = externalContext.getResponse();
- if (response instanceof HttpServletResponse) {
+ if (response instanceof HttpServletResponse)
+ {
// Request values are lost after a redirect. We can create a
// temporal cookie to pass the params between redirect calls.
// It is better than use HttpSession object, because this cookie
// is never sent by the server.
Cookie cookie = (Cookie) externalContext.getRequestCookieMap()
- .get(FLASH_REDIRECT);
- if (cookie != null) {
+ .get(FLASH_REDIRECT);
+ if (cookie != null)
+ {
redirect = Boolean.TRUE;
HttpServletResponse httpResponse = (HttpServletResponse) response;
// A redirect happened, so it is safe to remove the cookie, setting
@@ -482,24 +536,28 @@
httpResponse.addCookie(cookie);
requestMap.put(FLASH_REDIRECT, redirect);
}
- else {
+ else
+ {
redirect = Boolean.FALSE;
}
}
- else {
+ else
+ {
// Note that on portlet world we can't create cookies,
// so we are forced to use the session map. Anyway,
// according to the Bridge implementation(for example see
// org.apache.myfaces.portlet.faces.bridge.BridgeImpl)
// session object is created at start faces request
Map<String, Object> sessionMap = externalContext
- .getSessionMap();
+ .getSessionMap();
redirect = (Boolean) sessionMap.get(FLASH_REDIRECT);
- if (redirect != null) {
+ if (redirect != null)
+ {
sessionMap.remove(FLASH_REDIRECT);
requestMap.put(FLASH_REDIRECT, redirect);
}
- else {
+ else
+ {
redirect = Boolean.FALSE;
}
}
@@ -515,9 +573,11 @@
Map<String, Object> requestMap = externalContext.getRequestMap();
Boolean previousRedirect = (Boolean) requestMap.get(FLASH_REDIRECT);
- previousRedirect = (previousRedirect == null) ? Boolean.FALSE : previousRedirect;
+ previousRedirect = (previousRedirect == null) ? Boolean.FALSE
+ : previousRedirect;
- if (!previousRedirect.booleanValue() && redirect) {
+ if (!previousRedirect.booleanValue() && redirect)
+ {
// This request contains a redirect. This condition is in general
// triggered by a NavigationHandler. After a redirect all request scope
// values get lost, so in order to preserve this value we need to
@@ -536,7 +596,8 @@
public void keep(String key)
{
FacesContext facesContext = FacesContext.getCurrentInstance();
- Map<String, Object> requestMap = facesContext.getExternalContext().getRequestMap();
+ Map<String, Object> requestMap = facesContext.getExternalContext()
+ .getRequestMap();
Object value = requestMap.get(key);
getCurrentRequestMap(facesContext).put(key, value);
}
@@ -547,7 +608,8 @@
@Override
public void putNow(String key, Object value)
{
- FacesContext.getCurrentInstance().getExternalContext().getRequestMap().put(key, value);
+ FacesContext.getCurrentInstance().getExternalContext().getRequestMap()
+ .put(key, value);
}
@Override
@@ -557,16 +619,19 @@
ExternalContext externalContext = facesContext.getExternalContext();
Map<String, Object> requestMap = externalContext.getRequestMap();
Boolean keepMessages = (Boolean) requestMap.get(FLASH_KEEP_MESSAGES);
- if (keepMessages == null) {
+ if (keepMessages == null)
+ {
Object response = externalContext.getResponse();
- if (response instanceof HttpServletResponse) {
+ if (response instanceof HttpServletResponse)
+ {
// Request values are lost after a redirect. We can create a
// temporal cookie to pass the params between redirect calls.
// It is better than use HttpSession object, because this cookie
// is never sent by the server.
Cookie cookie = (Cookie) externalContext.getRequestCookieMap()
- .get(FLASH_KEEP_MESSAGES);
- if (cookie != null) {
+ .get(FLASH_KEEP_MESSAGES);
+ if (cookie != null)
+ {
keepMessages = Boolean.TRUE;
HttpServletResponse httpResponse = (HttpServletResponse) response;
// It is safe to remove the cookie, setting
@@ -577,24 +642,28 @@
httpResponse.addCookie(cookie);
requestMap.put(FLASH_KEEP_MESSAGES, keepMessages);
}
- else {
+ else
+ {
keepMessages = Boolean.FALSE;
}
}
- else {
+ else
+ {
// Note that on portlet world we can't create cookies,
// so we are forced to use the session map. Anyway,
// according to the Bridge implementation(for example see
// org.apache.myfaces.portlet.faces.bridge.BridgeImpl)
// session object is created at start faces request
Map<String, Object> sessionMap = externalContext
- .getSessionMap();
+ .getSessionMap();
keepMessages = (Boolean) sessionMap.get(FLASH_KEEP_MESSAGES);
- if (keepMessages != null) {
+ if (keepMessages != null)
+ {
sessionMap.remove(FLASH_KEEP_MESSAGES);
requestMap.put(FLASH_KEEP_MESSAGES, keepMessages);
}
- else {
+ else
+ {
keepMessages = Boolean.FALSE;
}
}
@@ -613,11 +682,15 @@
ExternalContext externalContext = facesContext.getExternalContext();
Map<String, Object> requestMap = externalContext.getRequestMap();
- Boolean previousKeepMessages = (Boolean) requestMap.get(FLASH_KEEP_MESSAGES);
- previousKeepMessages = (previousKeepMessages == null) ? Boolean.FALSE : previousKeepMessages;
+ Boolean previousKeepMessages = (Boolean) requestMap
+ .get(FLASH_KEEP_MESSAGES);
+ previousKeepMessages = (previousKeepMessages == null) ? Boolean.FALSE
+ : previousKeepMessages;
- if (!previousKeepMessages.booleanValue() && keepMessages) {
- externalContext.getSessionMap().put(FLASH_KEEP_MESSAGES, keepMessages);
+ if (!previousKeepMessages.booleanValue() && keepMessages)
+ {
+ externalContext.getSessionMap().put(FLASH_KEEP_MESSAGES,
+ keepMessages);
}
requestMap.put(FLASH_KEEP_MESSAGES, keepMessages);
}
@@ -644,14 +717,17 @@
public Object get(Object key)
{
- if (key == null) {
+ if (key == null)
+ {
return null;
}
- if ("keepMessages".equals(key)) {
+ if ("keepMessages".equals(key))
+ {
return isKeepMessages();
}
- else if ("redirect".equals(key)) {
+ else if ("redirect".equals(key))
+ {
return isRedirect();
}
@@ -659,7 +735,8 @@
Map<String, Object> postbackMap = getPostbackRequestMap(context);
Object returnValue = null;
- if (postbackMap != null) {
+ if (postbackMap != null)
+ {
returnValue = postbackMap.get(key);
}
@@ -678,21 +755,25 @@
public Object put(String key, Object value)
{
- if (key == null) {
+ if (key == null)
+ {
return null;
}
- if ("keepMessages".equals(key)) {
+ if ("keepMessages".equals(key))
+ {
Boolean booleanValue = convertToBoolean(value);
this.setKeepMessages(booleanValue);
return booleanValue;
}
- else if ("redirect".equals(key)) {
+ else if ("redirect".equals(key))
+ {
Boolean booleanValue = convertToBoolean(value);
this.setRedirect(booleanValue);
return booleanValue;
}
- else {
+ else
+ {
Object returnValue = getCurrentPhaseMap().put(key, value);
return returnValue;
}
@@ -701,10 +782,12 @@
private Boolean convertToBoolean(Object value)
{
Boolean booleanValue;
- if (value instanceof Boolean) {
+ if (value instanceof Boolean)
+ {
booleanValue = (Boolean) value;
}
- else {
+ else
+ {
booleanValue = Boolean.parseBoolean(value.toString());
}
return booleanValue;
diff --git a/test20/src/main/java/org/apache/myfaces/test/mock/MockPartialViewContext.java b/test20/src/main/java/org/apache/myfaces/test/mock/MockPartialViewContext.java
index 5851207..a6153ca 100644
--- a/test20/src/main/java/org/apache/myfaces/test/mock/MockPartialViewContext.java
+++ b/test20/src/main/java/org/apache/myfaces/test/mock/MockPartialViewContext.java
@@ -62,22 +62,28 @@
@Override
public boolean isAjaxRequest()
{
- if (_ajaxRequest == null) {
- String requestType = _facesContext.getExternalContext().
- getRequestHeaderMap().get(FACES_REQUEST);
- _ajaxRequest = (requestType != null && PARTIAL_AJAX.equals(requestType));
+ if (_ajaxRequest == null)
+ {
+ String requestType = _facesContext.getExternalContext()
+ .getRequestHeaderMap().get(FACES_REQUEST);
+ _ajaxRequest = (requestType != null && PARTIAL_AJAX
+ .equals(requestType));
}
return _ajaxRequest;
}
@Override
- public boolean isExecuteAll() {
+ public boolean isExecuteAll()
+ {
- if (isAjaxRequest()) {
- String executeMode = _facesContext.getExternalContext().
- getRequestParameterMap().get(
- PartialViewContext.PARTIAL_EXECUTE_PARAM_NAME);
- if (PartialViewContext.ALL_PARTIAL_PHASE_CLIENT_IDS.equals(executeMode)) {
+ if (isAjaxRequest())
+ {
+ String executeMode = _facesContext.getExternalContext()
+ .getRequestParameterMap().get(
+ PartialViewContext.PARTIAL_EXECUTE_PARAM_NAME);
+ if (PartialViewContext.ALL_PARTIAL_PHASE_CLIENT_IDS
+ .equals(executeMode))
+ {
return true;
}
}
@@ -85,62 +91,80 @@
}
@Override
- public boolean isPartialRequest() {
+ public boolean isPartialRequest()
+ {
- if (_partialRequest == null) {
- String requestType = _facesContext.getExternalContext().
- getRequestHeaderMap().get(FACES_REQUEST);
- _partialRequest = (requestType != null && PARTIAL_PROCESS.equals(requestType));
+ if (_partialRequest == null)
+ {
+ String requestType = _facesContext.getExternalContext()
+ .getRequestHeaderMap().get(FACES_REQUEST);
+ _partialRequest = (requestType != null && PARTIAL_PROCESS
+ .equals(requestType));
}
- return isAjaxRequest() || _partialRequest;
+ return isAjaxRequest() || _partialRequest;
}
@Override
- public boolean isRenderAll() {
+ public boolean isRenderAll()
+ {
- if (_renderAll == null) {
- if (isAjaxRequest()) {
- String executeMode = _facesContext.getExternalContext().
- getRequestParameterMap().get(
- PartialViewContext.PARTIAL_RENDER_PARAM_NAME);
- if (PartialViewContext.ALL_PARTIAL_PHASE_CLIENT_IDS.equals(executeMode)) {
+ if (_renderAll == null)
+ {
+ if (isAjaxRequest())
+ {
+ String executeMode = _facesContext.getExternalContext()
+ .getRequestParameterMap().get(
+ PartialViewContext.PARTIAL_RENDER_PARAM_NAME);
+ if (PartialViewContext.ALL_PARTIAL_PHASE_CLIENT_IDS
+ .equals(executeMode))
+ {
_renderAll = true;
}
}
- if (_renderAll == null) {
+ if (_renderAll == null)
+ {
_renderAll = false;
}
}
return _renderAll;
}
-
@Override
- public void setPartialRequest(boolean isPartialRequest) {
+ public void setPartialRequest(boolean isPartialRequest)
+ {
_partialRequest = isPartialRequest;
}
@Override
- public void setRenderAll(boolean renderAll) {
+ public void setRenderAll(boolean renderAll)
+ {
_renderAll = renderAll;
}
@Override
- public Collection<String> getExecuteIds() {
+ public Collection<String> getExecuteIds()
+ {
- if (_executeClientIds == null) {
- String executeMode = _facesContext.getExternalContext().
- getRequestParameterMap().get(
- PartialViewContext.PARTIAL_EXECUTE_PARAM_NAME);
+ if (_executeClientIds == null)
+ {
+ String executeMode = _facesContext.getExternalContext()
+ .getRequestParameterMap().get(
+ PartialViewContext.PARTIAL_EXECUTE_PARAM_NAME);
- if (executeMode != null && !"".equals(executeMode) &&
+ if (executeMode != null
+ && !"".equals(executeMode)
+ &&
//!PartialViewContext.NO_PARTIAL_PHASE_CLIENT_IDS.equals(executeMode) &&
- !PartialViewContext.ALL_PARTIAL_PHASE_CLIENT_IDS.equals(executeMode)) {
-
- String[] clientIds = splitShortString(_replaceTabOrEnterCharactersWithSpaces(executeMode), ' ');
+ !PartialViewContext.ALL_PARTIAL_PHASE_CLIENT_IDS
+ .equals(executeMode))
+ {
+
+ String[] clientIds = splitShortString(
+ _replaceTabOrEnterCharactersWithSpaces(executeMode),
+ ' ');
//The collection must be mutable
List<String> tempList = new ArrayList<String>();
@@ -154,22 +178,24 @@
// The "javax.faces.source" parameter needs to be added to the list of
// execute ids if missing (otherwise, we'd never execute an action associated
// with, e.g., a button).
-
- String source = _facesContext.getExternalContext().getRequestParameterMap().get
- (SOURCE_PARAM_NAME);
-
+
+ String source = _facesContext.getExternalContext()
+ .getRequestParameterMap().get(SOURCE_PARAM_NAME);
+
if (source != null)
{
source = source.trim();
-
- if (!tempList.contains (source))
+
+ if (!tempList.contains(source))
{
- tempList.add (source);
+ tempList.add(source);
}
}
-
+
_executeClientIds = tempList;
- } else {
+ }
+ else
+ {
_executeClientIds = new ArrayList<String>();
}
}
@@ -177,18 +203,24 @@
}
@Override
- public Collection<String> getRenderIds() {
+ public Collection<String> getRenderIds()
+ {
- if (_renderClientIds == null) {
- String renderMode = _facesContext.getExternalContext().
- getRequestParameterMap().get(
- PartialViewContext.PARTIAL_RENDER_PARAM_NAME);
+ if (_renderClientIds == null)
+ {
+ String renderMode = _facesContext.getExternalContext()
+ .getRequestParameterMap().get(
+ PartialViewContext.PARTIAL_RENDER_PARAM_NAME);
- if (renderMode != null && !"".equals(renderMode) &&
+ if (renderMode != null
+ && !"".equals(renderMode)
+ &&
//!PartialViewContext.NO_PARTIAL_PHASE_CLIENT_IDS.equals(renderMode) &&
- !PartialViewContext.ALL_PARTIAL_PHASE_CLIENT_IDS.equals(renderMode))
+ !PartialViewContext.ALL_PARTIAL_PHASE_CLIENT_IDS
+ .equals(renderMode))
{
- String[] clientIds = splitShortString(_replaceTabOrEnterCharactersWithSpaces(renderMode), ' ');
+ String[] clientIds = splitShortString(
+ _replaceTabOrEnterCharactersWithSpaces(renderMode), ' ');
//The collection must be mutable
List<String> tempList = new ArrayList<String>();
@@ -200,12 +232,16 @@
}
}
_renderClientIds = tempList;
- } else {
+ }
+ else
+ {
_renderClientIds = new ArrayList<String>();
-
- if (PartialViewContext.ALL_PARTIAL_PHASE_CLIENT_IDS.equals (renderMode))
+
+ if (PartialViewContext.ALL_PARTIAL_PHASE_CLIENT_IDS
+ .equals(renderMode))
{
- _renderClientIds.add (PartialResponseWriter.RENDER_ALL_MARKER);
+ _renderClientIds
+ .add(PartialResponseWriter.RENDER_ALL_MARKER);
}
}
}
@@ -213,8 +249,10 @@
}
@Override
- public PartialResponseWriter getPartialResponseWriter() {
- if (_partialResponseWriter == null) {
+ public PartialResponseWriter getPartialResponseWriter()
+ {
+ if (_partialResponseWriter == null)
+ {
ResponseWriter responseWriter = _facesContext.getResponseWriter();
if (responseWriter == null)
{
@@ -223,13 +261,18 @@
// ResponseWriter from the RenderKit and then wrap if necessary.
try
{
- responseWriter = _facesContext.getRenderKit().createResponseWriter(
- _facesContext.getExternalContext().getResponseOutputWriter(), "text/xml",
- _facesContext.getExternalContext().getRequestCharacterEncoding());
+ responseWriter = _facesContext.getRenderKit()
+ .createResponseWriter(
+ _facesContext.getExternalContext()
+ .getResponseOutputWriter(),
+ "text/xml",
+ _facesContext.getExternalContext()
+ .getRequestCharacterEncoding());
}
catch (IOException e)
{
- throw new IllegalStateException("Cannot create Partial Response Writer",e);
+ throw new IllegalStateException(
+ "Cannot create Partial Response Writer", e);
}
}
// It is possible that the RenderKit return a PartialResponseWriter instance when
@@ -240,18 +283,21 @@
}
else
{
- _partialResponseWriter = new PartialResponseWriter(responseWriter);
+ _partialResponseWriter = new PartialResponseWriter(
+ responseWriter);
}
}
return _partialResponseWriter;
}
@Override
- public void processPartial(PhaseId phaseId) {
+ public void processPartial(PhaseId phaseId)
+ {
UIViewRoot viewRoot = _facesContext.getViewRoot();
- VisitContext visitCtx = VisitContext.createVisitContext(_facesContext, null, null);
+ VisitContext visitCtx = VisitContext.createVisitContext(_facesContext,
+ null, null);
viewRoot.visitTree(visitCtx, new MockVisitCallback());
}
@@ -274,8 +320,9 @@
// Step 1: how many substrings?
// We exchange double scan time for less memory allocation
- for (int pos = str.indexOf(separator);
- pos >= 0; pos = str.indexOf(separator, pos + 1)) {
+ for (int pos = str.indexOf(separator); pos >= 0; pos = str.indexOf(
+ separator, pos + 1))
+ {
lastTokenIndex++;
}
@@ -285,9 +332,9 @@
int oldPos = 0;
// Step 3: retrieve substrings
- for (
- int pos = str.indexOf(separator), i = 0; pos >= 0;
- pos = str.indexOf(separator, (oldPos = (pos + 1)))) {
+ for (int pos = str.indexOf(separator), i = 0; pos >= 0; pos = str
+ .indexOf(separator, (oldPos = (pos + 1))))
+ {
list[i++] = str.substring(oldPos, pos);
}
@@ -299,12 +346,14 @@
private String _replaceTabOrEnterCharactersWithSpaces(String mode)
{
StringBuilder builder = new StringBuilder(mode.length());
- for (int i = 0; i < mode.length(); i++) {
- if (mode.charAt(i) == '\t' ||
- mode.charAt(i) == '\n') {
+ for (int i = 0; i < mode.length(); i++)
+ {
+ if (mode.charAt(i) == '\t' || mode.charAt(i) == '\n')
+ {
builder.append(' ');
}
- else {
+ else
+ {
builder.append(mode.charAt(i));
}
}
diff --git a/test20/src/main/java/org/apache/myfaces/test/mock/MockResponseStateManager.java b/test20/src/main/java/org/apache/myfaces/test/mock/MockResponseStateManager.java
index 505899b..903aa22 100644
--- a/test20/src/main/java/org/apache/myfaces/test/mock/MockResponseStateManager.java
+++ b/test20/src/main/java/org/apache/myfaces/test/mock/MockResponseStateManager.java
@@ -25,17 +25,16 @@
// ------------------------------------------------------------ Constructors
// ------------------------------------------------------ Instance Variables
-
+
private static final int TREE_PARAM = 0;
private static final int STATE_PARAM = 1;
private static final int VIEWID_PARAM = 2;
private static final String ZIP_CHARSET = "ISO-8859-1";
-
// ----------------------------------------------------- Mock Object Methods
// -------------------------------------------------- ResponseStateManager Methods
-
+
public Object getState(FacesContext facesContext, String viewId)
{
Object[] savedState = getSavedState(facesContext);
@@ -47,7 +46,8 @@
return new Object[] { savedState[TREE_PARAM], savedState[STATE_PARAM] };
}
- public Object getTreeStructureToRestore(FacesContext facesContext, String viewId)
+ public Object getTreeStructureToRestore(FacesContext facesContext,
+ String viewId)
{
// Although this method won't be called anymore,
// it has been kept for backward compatibility.
@@ -75,17 +75,19 @@
public boolean isPostback(FacesContext context)
{
- return context.getExternalContext().getRequestParameterMap().containsKey(ResponseStateManager.VIEW_STATE_PARAM);
+ return context.getExternalContext().getRequestParameterMap()
+ .containsKey(ResponseStateManager.VIEW_STATE_PARAM);
}
- public void writeState(FacesContext facescontext, SerializedView serializedview)
- throws IOException
+ public void writeState(FacesContext facescontext,
+ SerializedView serializedview) throws IOException
{
ResponseWriter responseWriter = facescontext.getResponseWriter();
Object[] savedState = new Object[3];
- if (facescontext.getApplication().getStateManager().isSavingStateInClient(facescontext))
+ if (facescontext.getApplication().getStateManager()
+ .isSavingStateInClient(facescontext))
{
Object treeStruct = serializedview.getStructure();
Object compStates = serializedview.getState();
@@ -122,10 +124,11 @@
writeRenderKitIdField(facescontext, responseWriter);
}
- private void writeViewStateField(FacesContext facesContext, ResponseWriter responseWriter, Object savedState)
- throws IOException
+ private void writeViewStateField(FacesContext facesContext,
+ ResponseWriter responseWriter, Object savedState)
+ throws IOException
{
-
+
String serializedState = construct(facesContext, savedState);
responseWriter.startElement("input", null);
responseWriter.writeAttribute("type", "hidden", null);
@@ -133,23 +136,28 @@
responseWriter.writeAttribute("value", serializedState, null);
responseWriter.endElement("input");
}
-
- private void writeRenderKitIdField(FacesContext facesContext, ResponseWriter responseWriter) throws IOException
+ private void writeRenderKitIdField(FacesContext facesContext,
+ ResponseWriter responseWriter) throws IOException
{
-
- String defaultRenderKitId = facesContext.getApplication().getDefaultRenderKitId();
- if (defaultRenderKitId != null && !RenderKitFactory.HTML_BASIC_RENDER_KIT.equals(defaultRenderKitId))
+
+ String defaultRenderKitId = facesContext.getApplication()
+ .getDefaultRenderKitId();
+ if (defaultRenderKitId != null
+ && !RenderKitFactory.HTML_BASIC_RENDER_KIT
+ .equals(defaultRenderKitId))
{
responseWriter.startElement("input", null);
responseWriter.writeAttribute("type", "hidden", null);
- responseWriter.writeAttribute("name", ResponseStateManager.RENDER_KIT_ID_PARAM, null);
+ responseWriter.writeAttribute("name",
+ ResponseStateManager.RENDER_KIT_ID_PARAM, null);
responseWriter.writeAttribute("value", defaultRenderKitId, null);
responseWriter.endElement("input");
}
}
-
- private String construct(FacesContext facesContext, Object savedState) throws IOException
+
+ private String construct(FacesContext facesContext, Object savedState)
+ throws IOException
{
byte[] bytes = null;
ByteArrayOutputStream baos = null;
@@ -169,7 +177,7 @@
{
oos.close();
}
- catch(IOException e)
+ catch (IOException e)
{
}
finally
@@ -183,7 +191,7 @@
{
baos.close();
}
- catch(IOException e)
+ catch (IOException e)
{
}
finally
@@ -194,19 +202,20 @@
}
return new String(new _Hex().encode(bytes), ZIP_CHARSET);
}
-
- private Object reconstruct(FacesContext facesContext, String encodedState) throws IOException
+
+ private Object reconstruct(FacesContext facesContext, String encodedState)
+ throws IOException
{
byte[] bytes = encodedState.getBytes(ZIP_CHARSET);
-
+
ByteArrayInputStream input = null;
ObjectInputStream s = null;
Object object = null;
-
+
try
{
input = new ByteArrayInputStream(bytes);
- s = new ObjectInputStream(input);
+ s = new ObjectInputStream(input);
object = s.readObject();
}
catch (ClassNotFoundException e)
@@ -221,7 +230,7 @@
{
s.close();
}
- catch(IOException e)
+ catch (IOException e)
{
}
finally
@@ -235,7 +244,7 @@
{
input.close();
}
- catch(IOException e)
+ catch (IOException e)
{
}
finally
@@ -247,31 +256,34 @@
return object;
}
- private Object[] getSavedState(FacesContext facesContext) {
- Object encodedState =
- facesContext.getExternalContext().
- getRequestParameterMap().get(VIEW_STATE_PARAM);
- if(encodedState==null || (((String) encodedState).length() == 0)) {
+ private Object[] getSavedState(FacesContext facesContext)
+ {
+ Object encodedState = facesContext.getExternalContext()
+ .getRequestParameterMap().get(VIEW_STATE_PARAM);
+ if (encodedState == null || (((String) encodedState).length() == 0))
+ {
return null;
}
Object[] savedState = null;
-
+
try
{
- savedState = (Object[])reconstruct(facesContext, (String)encodedState);
+ savedState = (Object[]) reconstruct(facesContext,
+ (String) encodedState);
}
- catch(IOException e)
+ catch (IOException e)
{
- facesContext.getExternalContext().log("Cannot reconstruct view state", e);
+ facesContext.getExternalContext().log(
+ "Cannot reconstruct view state", e);
}
if (savedState == null)
{
return null;
}
-
- String restoredViewId = (String)savedState[VIEWID_PARAM];
+
+ String restoredViewId = (String) savedState[VIEWID_PARAM];
if (restoredViewId == null)
{
@@ -279,26 +291,26 @@
}
return savedState;
}
-
+
public String getViewState(FacesContext facesContext, Object state)
{
if (state == null)
{
return null;
}
-
+
Object treeStruct = null;
Object compStates = null;
-
+
if (state instanceof SerializedView)
{
- SerializedView view = (SerializedView)state;
+ SerializedView view = (SerializedView) state;
treeStruct = view.getStructure();
compStates = view.getState();
}
else if (state instanceof Object[])
{
- Object[] structureAndState = (Object[])state;
+ Object[] structureAndState = (Object[]) state;
if (structureAndState.length == 2)
{
@@ -307,17 +319,20 @@
}
else
{
- throw new FacesException("The state should be an array of Object[] of lenght 2");
+ throw new FacesException(
+ "The state should be an array of Object[] of lenght 2");
}
}
else
{
- throw new FacesException("The state should be an array of Object[] of lenght 2, or a SerializedView instance");
+ throw new FacesException(
+ "The state should be an array of Object[] of lenght 2, or a SerializedView instance");
}
-
+
Object[] savedState = new Object[3];
- if (facesContext.getApplication().getStateManager().isSavingStateInClient(facesContext))
+ if (facesContext.getApplication().getStateManager()
+ .isSavingStateInClient(facesContext))
{
if (treeStruct != null)
{
@@ -346,9 +361,9 @@
{
return construct(facesContext, savedState);
}
- catch(IOException e)
+ catch (IOException e)
{
throw new RuntimeException(e);
}
- }
+ }
}
diff --git a/test20/src/main/java/org/apache/myfaces/test/mock/MockSubKeyMap.java b/test20/src/main/java/org/apache/myfaces/test/mock/MockSubKeyMap.java
index 4c3ece2..6813de4 100644
--- a/test20/src/main/java/org/apache/myfaces/test/mock/MockSubKeyMap.java
+++ b/test20/src/main/java/org/apache/myfaces/test/mock/MockSubKeyMap.java
@@ -40,19 +40,23 @@
{
public MockSubKeyMap(Map<String, Object> base, String prefix)
{
- if (base == null) {
+ if (base == null)
+ {
throw new NullPointerException();
}
- if (prefix == null) {
+ if (prefix == null)
+ {
throw new NullPointerException();
}
// Optimize the scenario where we're wrapping another SubKeyMap
- if (base instanceof MockSubKeyMap) {
+ if (base instanceof MockSubKeyMap)
+ {
_base = ((MockSubKeyMap) base)._base;
_prefix = ((MockSubKeyMap) base)._prefix + prefix;
}
- else {
+ else
+ {
_base = base;
_prefix = prefix;
}
@@ -88,7 +92,8 @@
@Override
public boolean containsKey(Object key)
{
- if (!(key instanceof String)) {
+ if (!(key instanceof String))
+ {
return false;
}
@@ -98,7 +103,8 @@
@Override
public Set<Map.Entry<String, V>> entrySet()
{
- if (_entrySet == null) {
+ if (_entrySet == null)
+ {
_entrySet = new Entries<V>();
}
return _entrySet;
@@ -106,7 +112,8 @@
private String _getBaseKey(Object key)
{
- if (key == null) {
+ if (key == null)
+ {
throw new NullPointerException();
}
// Yes, I want a ClassCastException if it's not a String
@@ -116,8 +123,10 @@
private List<String> _gatherKeys()
{
List<String> list = new ArrayList<String>();
- for (String key : _base.keySet()) {
- if (key != null && key.startsWith(_prefix)) {
+ for (String key : _base.keySet())
+ {
+ if (key != null && key.startsWith(_prefix))
+ {
list.add(key);
}
}
@@ -150,8 +159,10 @@
public int size()
{
int size = 0;
- for (String key : _base.keySet()) {
- if (key != null && key.startsWith(_prefix)) {
+ for (String key : _base.keySet())
+ {
+ if (key != null && key.startsWith(_prefix))
+ {
size++;
}
}
@@ -163,11 +174,13 @@
public boolean isEmpty()
{
Iterator<String> keys = _base.keySet().iterator();
- while (keys.hasNext()) {
+ while (keys.hasNext())
+ {
String key = keys.next();
// Short-circuit: the default implementation would always
// need to iterate to find the total size.
- if (key != null && key.startsWith(_prefix)) {
+ if (key != null && key.startsWith(_prefix))
+ {
return false;
}
}
@@ -179,9 +192,11 @@
public void clear()
{
Iterator<String> keys = _base.keySet().iterator();
- while (keys.hasNext()) {
+ while (keys.hasNext())
+ {
String key = keys.next();
- if (key != null && key.startsWith(_prefix)) {
+ if (key != null && key.startsWith(_prefix))
+ {
keys.remove();
}
}
@@ -209,7 +224,8 @@
public void remove()
{
- if (_currentKey == null) {
+ if (_currentKey == null)
+ {
throw new IllegalStateException();
}
@@ -231,7 +247,8 @@
public String getKey()
{
- if (_key == null) {
+ if (_key == null)
+ {
_key = _baseKey.substring(_prefix.length());
}
return _key;
@@ -251,12 +268,13 @@
@Override
public boolean equals(Object o)
{
- if (!(o instanceof Map.Entry)) {
+ if (!(o instanceof Map.Entry))
+ {
return false;
}
Map.Entry<String, V> e = (Map.Entry<String, V>) o;
return _equals(getKey(), e.getKey())
- && _equals(getValue(), e.getValue());
+ && _equals(getValue(), e.getValue());
}
@Override
@@ -265,7 +283,7 @@
Object key = getKey();
Object value = getValue();
return ((key == null) ? 0 : key.hashCode())
- ^ ((value == null) ? 0 : value.hashCode());
+ ^ ((value == null) ? 0 : value.hashCode());
}
private String _baseKey;
@@ -274,7 +292,8 @@
static private boolean _equals(Object a, Object b)
{
- if (a == null) {
+ if (a == null)
+ {
return b == null;
}
return a.equals(b);
diff --git a/test20/src/main/java/org/apache/myfaces/test/mock/MockViewHandler20.java b/test20/src/main/java/org/apache/myfaces/test/mock/MockViewHandler20.java
index a875d29..3384f26 100644
--- a/test20/src/main/java/org/apache/myfaces/test/mock/MockViewHandler20.java
+++ b/test20/src/main/java/org/apache/myfaces/test/mock/MockViewHandler20.java
@@ -41,11 +41,12 @@
{
// the standard impl only calls getActionURL(context, viewId)
// but we want to include the parameters too
-
+
String actionEncodedViewId = getActionURL(context, viewId);
ExternalContext externalContext = context.getExternalContext();
- String bookmarkEncodedURL = externalContext.encodeBookmarkableURL(actionEncodedViewId, parameters);
+ String bookmarkEncodedURL = externalContext.encodeBookmarkableURL(
+ actionEncodedViewId, parameters);
return externalContext.encodeActionURL(bookmarkEncodedURL);
}
-
+
}
diff --git a/test20/src/main/java/org/apache/myfaces/test/mock/resource/MockClassLoaderResourceLoader.java b/test20/src/main/java/org/apache/myfaces/test/mock/resource/MockClassLoaderResourceLoader.java
index aa20c3d..bc38e07 100644
--- a/test20/src/main/java/org/apache/myfaces/test/mock/resource/MockClassLoaderResourceLoader.java
+++ b/test20/src/main/java/org/apache/myfaces/test/mock/resource/MockClassLoaderResourceLoader.java
@@ -31,7 +31,7 @@
public class MockClassLoaderResourceLoader extends MockResourceLoader
{
private ClassLoader _classLoader;
-
+
public MockClassLoaderResourceLoader(ClassLoader loader, String prefix)
{
super(prefix);
@@ -49,11 +49,13 @@
{
if (getPrefix() != null && !"".equals(getPrefix()))
{
- return getClassLoader().getResourceAsStream(getPrefix() + '/' + resourceMeta.getResourceIdentifier());
+ return getClassLoader().getResourceAsStream(
+ getPrefix() + '/' + resourceMeta.getResourceIdentifier());
}
else
{
- return getClassLoader().getResourceAsStream(resourceMeta.getResourceIdentifier());
+ return getClassLoader().getResourceAsStream(
+ resourceMeta.getResourceIdentifier());
}
}
@@ -62,11 +64,13 @@
{
if (getPrefix() != null && !"".equals(getPrefix()))
{
- return getClassLoader().getResource(getPrefix() + '/' + resourceMeta.getResourceIdentifier());
+ return getClassLoader().getResource(
+ getPrefix() + '/' + resourceMeta.getResourceIdentifier());
}
else
{
- return getClassLoader().getResource(resourceMeta.getResourceIdentifier());
+ return getClassLoader().getResource(
+ resourceMeta.getResourceIdentifier());
}
}
@@ -77,10 +81,12 @@
}
@Override
- public MockResourceMeta createResourceMeta(String prefix, String libraryName, String libraryVersion,
- String resourceName, String resourceVersion)
+ public MockResourceMeta createResourceMeta(String prefix,
+ String libraryName, String libraryVersion, String resourceName,
+ String resourceVersion)
{
- return new MockResourceMeta(prefix, libraryName, libraryVersion, resourceName, resourceVersion);
+ return new MockResourceMeta(prefix, libraryName, libraryVersion,
+ resourceName, resourceVersion);
}
/**
@@ -93,7 +99,7 @@
{
return _classLoader;
}
-
+
public void setClassLoader(ClassLoader loader)
{
_classLoader = loader;
@@ -104,7 +110,8 @@
{
if (getPrefix() != null && !"".equals(getPrefix()))
{
- URL url = getClassLoader().getResource(getPrefix() + '/' + libraryName);
+ URL url = getClassLoader().getResource(
+ getPrefix() + '/' + libraryName);
if (url != null)
{
return true;
diff --git a/test20/src/main/java/org/apache/myfaces/test/mock/resource/MockExternalContextResourceLoader.java b/test20/src/main/java/org/apache/myfaces/test/mock/resource/MockExternalContextResourceLoader.java
index 6dd8e77..c7026cf 100644
--- a/test20/src/main/java/org/apache/myfaces/test/mock/resource/MockExternalContextResourceLoader.java
+++ b/test20/src/main/java/org/apache/myfaces/test/mock/resource/MockExternalContextResourceLoader.java
@@ -42,14 +42,16 @@
*
* Used on getLibraryVersion to filter resource directories
**/
- protected static Pattern VERSION_CHECKER = Pattern.compile("/\\p{Digit}+(_\\p{Digit}*)*/");
+ protected static Pattern VERSION_CHECKER = Pattern
+ .compile("/\\p{Digit}+(_\\p{Digit}*)*/");
/**
* It checks version like this: /1.js, /1_0.js, /1_0_0.js, /100_100.js
*
* Used on getResourceVersion to filter resources
**/
- protected static Pattern RESOURCE_VERSION_CHECKER = Pattern.compile("/\\p{Digit}+(_\\p{Digit}*)*\\..*");
+ protected static Pattern RESOURCE_VERSION_CHECKER = Pattern
+ .compile("/\\p{Digit}+(_\\p{Digit}*)*\\..*");
public MockExternalContextResourceLoader(String prefix)
{
@@ -58,7 +60,8 @@
protected Set<String> getResourcePaths(String path)
{
- return FacesContext.getCurrentInstance().getExternalContext().getResourcePaths(getPrefix() + '/' + path);
+ return FacesContext.getCurrentInstance().getExternalContext()
+ .getResourcePaths(getPrefix() + '/' + path);
}
@Override
@@ -88,7 +91,8 @@
{
resourceVersion = version;
}
- else if (getVersionComparator().compare(resourceVersion, version) < 0)
+ else if (getVersionComparator().compare(resourceVersion,
+ version) < 0)
{
resourceVersion = version;
}
@@ -129,7 +133,8 @@
{
libraryVersion = version;
}
- else if (getVersionComparator().compare(libraryVersion, version) < 0)
+ else if (getVersionComparator().compare(libraryVersion,
+ version) < 0)
{
libraryVersion = version;
}
@@ -144,8 +149,10 @@
{
try
{
- return FacesContext.getCurrentInstance().getExternalContext().getResource(
- getPrefix() + '/' + resourceMeta.getResourceIdentifier());
+ return FacesContext.getCurrentInstance().getExternalContext()
+ .getResource(
+ getPrefix() + '/'
+ + resourceMeta.getResourceIdentifier());
}
catch (MalformedURLException e)
{
@@ -156,15 +163,19 @@
@Override
public InputStream getResourceInputStream(MockResourceMeta resourceMeta)
{
- return FacesContext.getCurrentInstance().getExternalContext().getResourceAsStream(
- getPrefix() + '/' + resourceMeta.getResourceIdentifier());
+ return FacesContext.getCurrentInstance().getExternalContext()
+ .getResourceAsStream(
+ getPrefix() + '/'
+ + resourceMeta.getResourceIdentifier());
}
@Override
- public MockResourceMeta createResourceMeta(String prefix, String libraryName, String libraryVersion,
- String resourceName, String resourceVersion)
+ public MockResourceMeta createResourceMeta(String prefix,
+ String libraryName, String libraryVersion, String resourceName,
+ String resourceVersion)
{
- return new MockResourceMeta(prefix, libraryName, libraryVersion, resourceName, resourceVersion);
+ return new MockResourceMeta(prefix, libraryName, libraryVersion,
+ resourceName, resourceVersion);
}
@Override
@@ -174,9 +185,9 @@
{
try
{
- URL url =
- FacesContext.getCurrentInstance().getExternalContext().getResource(
- getPrefix() + '/' + libraryName);
+ URL url = FacesContext.getCurrentInstance()
+ .getExternalContext().getResource(
+ getPrefix() + '/' + libraryName);
if (url != null)
{
return true;
@@ -192,7 +203,8 @@
try
{
- URL url = FacesContext.getCurrentInstance().getExternalContext().getResource(libraryName);
+ URL url = FacesContext.getCurrentInstance()
+ .getExternalContext().getResource(libraryName);
if (url != null)
{
diff --git a/test20/src/main/java/org/apache/myfaces/test/mock/resource/MockResource.java b/test20/src/main/java/org/apache/myfaces/test/mock/resource/MockResource.java
index ff1a3b3..bf12887 100644
--- a/test20/src/main/java/org/apache/myfaces/test/mock/resource/MockResource.java
+++ b/test20/src/main/java/org/apache/myfaces/test/mock/resource/MockResource.java
@@ -39,9 +39,10 @@
private MockResourceMeta _resourceMeta;
private MockResourceLoader _resourceLoader;
private MockResourceHandlerSupport _resourceHandlerSupport;
-
- public MockResource(MockResourceMeta resourceMeta,
- MockResourceLoader resourceLoader, MockResourceHandlerSupport support, String contentType)
+
+ public MockResource(MockResourceMeta resourceMeta,
+ MockResourceLoader resourceLoader,
+ MockResourceHandlerSupport support, String contentType)
{
_resourceMeta = resourceMeta;
_resourceLoader = resourceLoader;
@@ -50,16 +51,16 @@
setResourceName(resourceMeta.getResourceName());
setContentType(contentType);
}
-
+
public MockResourceLoader getResourceLoader()
{
return _resourceLoader;
- }
-
+ }
+
@Override
public InputStream getInputStream() throws IOException
{
- return getResourceLoader().getResourceInputStream(_resourceMeta);
+ return getResourceLoader().getResourceInputStream(_resourceMeta);
}
@Override
@@ -68,16 +69,17 @@
String path;
if (_resourceHandlerSupport.isExtensionMapping())
{
- path = ResourceHandler.RESOURCE_IDENTIFIER + '/' +
- getResourceName() + _resourceHandlerSupport.getMapping();
+ path = ResourceHandler.RESOURCE_IDENTIFIER + '/'
+ + getResourceName() + _resourceHandlerSupport.getMapping();
}
else
{
- String mapping = _resourceHandlerSupport.getMapping();
- path = ResourceHandler.RESOURCE_IDENTIFIER + '/' + getResourceName();
+ String mapping = _resourceHandlerSupport.getMapping();
+ path = ResourceHandler.RESOURCE_IDENTIFIER + '/'
+ + getResourceName();
path = (mapping == null) ? path : mapping + path;
}
-
+
return path;
}
diff --git a/test20/src/main/java/org/apache/myfaces/test/mock/resource/MockResourceHandler.java b/test20/src/main/java/org/apache/myfaces/test/mock/resource/MockResourceHandler.java
index 06931b8..428ab3c 100644
--- a/test20/src/main/java/org/apache/myfaces/test/mock/resource/MockResourceHandler.java
+++ b/test20/src/main/java/org/apache/myfaces/test/mock/resource/MockResourceHandler.java
@@ -49,33 +49,37 @@
private boolean _resourceRequest;
private MockResourceHandlerSupport resourceHandlerSupport;
-
+
private ClassLoader _classLoader;
public MockResourceHandler()
{
_classLoader = getContextClassLoader();
- resourceHandlerSupport = new MockResourceHandlerSupport(true, ".jsf",_classLoader);
+ resourceHandlerSupport = new MockResourceHandlerSupport(true, ".jsf",
+ _classLoader);
}
-
+
public MockResourceHandler(ClassLoader classLoader)
{
if (classLoader == null)
_classLoader = getContextClassLoader();
else
_classLoader = classLoader;
-
- resourceHandlerSupport = new MockResourceHandlerSupport(true, ".jsf",_classLoader);
+
+ resourceHandlerSupport = new MockResourceHandlerSupport(true, ".jsf",
+ _classLoader);
}
-
- public MockResourceHandler(boolean extensionMapping, String mapping, ClassLoader classLoader)
+
+ public MockResourceHandler(boolean extensionMapping, String mapping,
+ ClassLoader classLoader)
{
if (classLoader == null)
_classLoader = getContextClassLoader();
else
_classLoader = classLoader;
-
- resourceHandlerSupport = new MockResourceHandlerSupport(extensionMapping, mapping,_classLoader);
+
+ resourceHandlerSupport = new MockResourceHandlerSupport(
+ extensionMapping, mapping, _classLoader);
}
@Override
@@ -91,14 +95,16 @@
}
@Override
- public Resource createResource(String resourceName, String libraryName, String contentType)
+ public Resource createResource(String resourceName, String libraryName,
+ String contentType)
{
Resource resource = null;
-
+
if (contentType == null)
{
//Resolve contentType using ExternalContext.getMimeType
- contentType = FacesContext.getCurrentInstance().getExternalContext().getMimeType(resourceName);
+ contentType = FacesContext.getCurrentInstance()
+ .getExternalContext().getMimeType(resourceName);
}
for (MockResourceLoader loader : getResourceHandlerSupport()
@@ -116,21 +122,22 @@
}
return resource;
}
-
+
/**
* This method try to create a ResourceMeta for a specific resource
* loader. If no library, or resource is found, just return null,
* so the algorithm in createResource can continue checking with the
* next registered ResourceLoader.
*/
- protected MockResourceMeta deriveResourceMeta(MockResourceLoader resourceLoader,
- String resourceName, String libraryName)
+ protected MockResourceMeta deriveResourceMeta(
+ MockResourceLoader resourceLoader, String resourceName,
+ String libraryName)
{
String localePrefix = getLocalePrefixForLocateResource();
String resourceVersion = null;
String libraryVersion = null;
MockResourceMeta resourceId = null;
-
+
//1. Try to locate resource in a localized path
if (localePrefix != null)
{
@@ -141,34 +148,37 @@
if (null != libraryVersion)
{
- String pathToResource = localePrefix + '/'
- + libraryName + '/' + libraryVersion + '/'
- + resourceName;
+ String pathToResource = localePrefix + '/' + libraryName
+ + '/' + libraryVersion + '/' + resourceName;
resourceVersion = resourceLoader
.getResourceVersion(pathToResource);
}
else
{
- String pathToResource = localePrefix + '/'
- + libraryName + '/' + resourceName;
+ String pathToResource = localePrefix + '/' + libraryName
+ + '/' + resourceName;
resourceVersion = resourceLoader
.getResourceVersion(pathToResource);
}
- if (!(resourceVersion != null && MockResourceLoader.VERSION_INVALID.equals(resourceVersion)))
+ if (!(resourceVersion != null && MockResourceLoader.VERSION_INVALID
+ .equals(resourceVersion)))
{
- resourceId = resourceLoader.createResourceMeta(localePrefix, libraryName,
- libraryVersion, resourceName, resourceVersion);
+ resourceId = resourceLoader.createResourceMeta(
+ localePrefix, libraryName, libraryVersion,
+ resourceName, resourceVersion);
}
}
else
{
resourceVersion = resourceLoader
- .getResourceVersion(localePrefix + '/'+ resourceName);
- if (!(resourceVersion != null && MockResourceLoader.VERSION_INVALID.equals(resourceVersion)))
- {
- resourceId = resourceLoader.createResourceMeta(localePrefix, null, null,
- resourceName, resourceVersion);
+ .getResourceVersion(localePrefix + '/' + resourceName);
+ if (!(resourceVersion != null && MockResourceLoader.VERSION_INVALID
+ .equals(resourceVersion)))
+ {
+ resourceId = resourceLoader.createResourceMeta(
+ localePrefix, null, null, resourceName,
+ resourceVersion);
}
}
@@ -179,9 +189,9 @@
{
resourceId = null;
}
- }
+ }
}
-
+
//2. Try to localize resource in a non localized path
if (resourceId == null)
{
@@ -198,27 +208,29 @@
}
else
{
- String pathToResource = (libraryName + '/'
- + resourceName);
+ String pathToResource = (libraryName + '/' + resourceName);
resourceVersion = resourceLoader
.getResourceVersion(pathToResource);
}
- if (!(resourceVersion != null && MockResourceLoader.VERSION_INVALID.equals(resourceVersion)))
- {
- resourceId = resourceLoader.createResourceMeta(null, libraryName,
- libraryVersion, resourceName, resourceVersion);
+ if (!(resourceVersion != null && MockResourceLoader.VERSION_INVALID
+ .equals(resourceVersion)))
+ {
+ resourceId = resourceLoader.createResourceMeta(null,
+ libraryName, libraryVersion, resourceName,
+ resourceVersion);
}
}
else
{
resourceVersion = resourceLoader
.getResourceVersion(resourceName);
-
- if (!(resourceVersion != null && MockResourceLoader.VERSION_INVALID.equals(resourceVersion)))
- {
- resourceId = resourceLoader.createResourceMeta(null, null, null,
- resourceName, resourceVersion);
+
+ if (!(resourceVersion != null && MockResourceLoader.VERSION_INVALID
+ .equals(resourceVersion)))
+ {
+ resourceId = resourceLoader.createResourceMeta(null, null,
+ null, resourceName, resourceVersion);
}
}
@@ -229,19 +241,21 @@
{
resourceId = null;
}
- }
+ }
}
-
+
return resourceId;
- }
+ }
@Override
public String getRendererTypeForResourceName(String resourceName)
{
- if (resourceName.endsWith(".js")) {
+ if (resourceName.endsWith(".js"))
+ {
return "javax.faces.resource.Script";
}
- else if (resourceName.endsWith(".css")) {
+ else if (resourceName.endsWith(".css"))
+ {
return "javax.faces.resource.Stylesheet";
}
return null;
@@ -266,19 +280,24 @@
String pathToLib;
- if (localePrefix != null) {
+ if (localePrefix != null)
+ {
//Check with locale
pathToLib = localePrefix + '/' + libraryName;
}
- else {
+ else
+ {
pathToLib = libraryName;
}
- try {
- URL url = FacesContext.getCurrentInstance().getExternalContext().getResource("/" + pathToLib);
+ try
+ {
+ URL url = FacesContext.getCurrentInstance().getExternalContext()
+ .getResource("/" + pathToLib);
return (url != null);
}
- catch (MalformedURLException e) {
+ catch (MalformedURLException e)
+ {
return false;
}
}
@@ -290,18 +309,23 @@
String bundleName = context.getApplication().getMessageBundle();
- if (null != bundleName) {
+ if (null != bundleName)
+ {
Locale locale = context.getApplication().getViewHandler()
- .calculateLocale(context);
+ .calculateLocale(context);
- ResourceBundle bundle = ResourceBundle
- .getBundle(bundleName, locale, getContextClassLoader());
+ ResourceBundle bundle = ResourceBundle.getBundle(bundleName,
+ locale, getContextClassLoader());
- if (bundle != null) {
- try {
- localePrefix = bundle.getString(ResourceHandler.LOCALE_PREFIX);
+ if (bundle != null)
+ {
+ try
+ {
+ localePrefix = bundle
+ .getString(ResourceHandler.LOCALE_PREFIX);
}
- catch (MissingResourceException e) {
+ catch (MissingResourceException e)
+ {
// Ignore it and return null
}
}
@@ -317,22 +341,29 @@
*/
static ClassLoader getContextClassLoader()
{
- if (System.getSecurityManager() != null) {
- try {
- ClassLoader cl = AccessController.doPrivileged(new PrivilegedExceptionAction<ClassLoader>()
- {
- public ClassLoader run() throws PrivilegedActionException
- {
- return Thread.currentThread().getContextClassLoader();
- }
- });
+ if (System.getSecurityManager() != null)
+ {
+ try
+ {
+ ClassLoader cl = AccessController
+ .doPrivileged(new PrivilegedExceptionAction<ClassLoader>()
+ {
+ public ClassLoader run()
+ throws PrivilegedActionException
+ {
+ return Thread.currentThread()
+ .getContextClassLoader();
+ }
+ });
return cl;
}
- catch (PrivilegedActionException pae) {
+ catch (PrivilegedActionException pae)
+ {
throw new FacesException(pae);
}
}
- else {
+ else
+ {
return Thread.currentThread().getContextClassLoader();
}
}
diff --git a/test20/src/main/java/org/apache/myfaces/test/mock/resource/MockResourceHandlerSupport.java b/test20/src/main/java/org/apache/myfaces/test/mock/resource/MockResourceHandlerSupport.java
index 49d4ae4..85d2a14 100644
--- a/test20/src/main/java/org/apache/myfaces/test/mock/resource/MockResourceHandlerSupport.java
+++ b/test20/src/main/java/org/apache/myfaces/test/mock/resource/MockResourceHandlerSupport.java
@@ -16,7 +16,6 @@
*/
package org.apache.myfaces.test.mock.resource;
-
/**
* Store additional info used by MockResource and MockResourceHandler
*
@@ -37,25 +36,32 @@
{
_extensionMapping = true;
_mapping = ".jsf";
- _resourceLoaders = new MockResourceLoader[]{ new MockExternalContextResourceLoader("/resources"),
- new MockClassLoaderResourceLoader(MockResourceHandler.getContextClassLoader(), "META-INF/resources")};
+ _resourceLoaders = new MockResourceLoader[] {
+ new MockExternalContextResourceLoader("/resources"),
+ new MockClassLoaderResourceLoader(MockResourceHandler
+ .getContextClassLoader(), "META-INF/resources") };
}
-
+
public MockResourceHandlerSupport(boolean extensionMapping, String mapping)
{
super();
_extensionMapping = extensionMapping;
_mapping = mapping;
- _resourceLoaders = new MockResourceLoader[]{ new MockExternalContextResourceLoader("/resources"),
- new MockClassLoaderResourceLoader(MockResourceHandler.getContextClassLoader(), "META-INF/resources")};
+ _resourceLoaders = new MockResourceLoader[] {
+ new MockExternalContextResourceLoader("/resources"),
+ new MockClassLoaderResourceLoader(MockResourceHandler
+ .getContextClassLoader(), "META-INF/resources") };
}
- public MockResourceHandlerSupport(boolean extensionMapping, String mapping, ClassLoader classLoader)
+ public MockResourceHandlerSupport(boolean extensionMapping, String mapping,
+ ClassLoader classLoader)
{
_extensionMapping = extensionMapping;
_mapping = mapping;
- _resourceLoaders = new MockResourceLoader[]{ new MockExternalContextResourceLoader("/resources"),
- new MockClassLoaderResourceLoader(classLoader, "META-INF/resources")};
+ _resourceLoaders = new MockResourceLoader[] {
+ new MockExternalContextResourceLoader("/resources"),
+ new MockClassLoaderResourceLoader(classLoader,
+ "META-INF/resources") };
}
public MockResourceHandlerSupport(boolean extensionMapping, String mapping,
@@ -76,7 +82,7 @@
{
return _extensionMapping;
}
-
+
public void setExtensionMapping(boolean extensionMapping)
{
_extensionMapping = extensionMapping;
@@ -91,12 +97,12 @@
{
return _mapping;
}
-
+
public void setMapping(String prefix)
{
_mapping = prefix;
}
-
+
/**
* Return an array of resource loaders used to find resources
* using the standard. The order of ResourceLoaders define
@@ -106,7 +112,7 @@
*/
public MockResourceLoader[] getResourceLoaders()
{
- return _resourceLoaders;
+ return _resourceLoaders;
}
public void setResourceLoaders(MockResourceLoader[] resourceLoaders)
diff --git a/test20/src/main/java/org/apache/myfaces/test/mock/resource/MockResourceLoader.java b/test20/src/main/java/org/apache/myfaces/test/mock/resource/MockResourceLoader.java
index e6f2b7d..33ba348 100644
--- a/test20/src/main/java/org/apache/myfaces/test/mock/resource/MockResourceLoader.java
+++ b/test20/src/main/java/org/apache/myfaces/test/mock/resource/MockResourceLoader.java
@@ -32,11 +32,11 @@
*/
public abstract class MockResourceLoader
{
-
+
public static final String VERSION_INVALID = "INVALID";
-
+
private String _prefix;
-
+
public MockResourceLoader(String prefix)
{
_prefix = prefix;
@@ -56,13 +56,15 @@
*/
public abstract URL getResourceURL(MockResourceMeta resourceMeta);
- public abstract InputStream getResourceInputStream(MockResourceMeta resourceMeta);
-
- public abstract MockResourceMeta createResourceMeta(String prefix, String libraryName, String libraryVersion,
- String resourceName, String resourceVersion);
-
+ public abstract InputStream getResourceInputStream(
+ MockResourceMeta resourceMeta);
+
+ public abstract MockResourceMeta createResourceMeta(String prefix,
+ String libraryName, String libraryVersion, String resourceName,
+ String resourceVersion);
+
public abstract boolean libraryExists(String libraryName);
-
+
private Comparator<String> _versionComparator = null;
protected Comparator<String> getVersionComparator()
@@ -143,7 +145,7 @@
return n1 - n2;
}
}
-
+
public String getPrefix()
{
return _prefix;
diff --git a/test20/src/main/java/org/apache/myfaces/test/mock/resource/MockResourceMeta.java b/test20/src/main/java/org/apache/myfaces/test/mock/resource/MockResourceMeta.java
index cfedc7f..e6447b3 100644
--- a/test20/src/main/java/org/apache/myfaces/test/mock/resource/MockResourceMeta.java
+++ b/test20/src/main/java/org/apache/myfaces/test/mock/resource/MockResourceMeta.java
@@ -27,15 +27,15 @@
*/
public class MockResourceMeta
{
-
+
private final String _prefix;
private final String _libraryName;
private final String _libraryVersion;
private final String _resourceName;
private final String _resourceVersion;
-
- public MockResourceMeta(String prefix, String libraryName, String libraryVersion,
- String resourceName, String resourceVersion)
+
+ public MockResourceMeta(String prefix, String libraryName,
+ String libraryVersion, String resourceName, String resourceVersion)
{
_prefix = prefix;
_libraryName = libraryName;
@@ -47,12 +47,12 @@
public String getLibraryName()
{
return _libraryName;
- }
-
+ }
+
public String getResourceName()
{
return _resourceName;
- }
+ }
public String getLocalePrefix()
{
@@ -68,7 +68,7 @@
{
return _resourceVersion;
}
-
+
public String getResourceIdentifier()
{
StringBuilder builder = new StringBuilder();
@@ -80,28 +80,32 @@
}
if (_libraryName != null)
{
- if (firstSlashAdded) builder.append('/');
+ if (firstSlashAdded)
+ builder.append('/');
builder.append(_libraryName);
firstSlashAdded = true;
}
if (_libraryVersion != null)
{
- if (firstSlashAdded) builder.append('/');
+ if (firstSlashAdded)
+ builder.append('/');
builder.append(_libraryVersion);
firstSlashAdded = true;
}
if (_resourceName != null)
{
- if (firstSlashAdded) builder.append('/');
+ if (firstSlashAdded)
+ builder.append('/');
builder.append(_resourceName);
firstSlashAdded = true;
}
if (_resourceVersion != null)
{
- if (firstSlashAdded) builder.append('/');
+ if (firstSlashAdded)
+ builder.append('/');
builder.append(_resourceVersion);
- builder.append(
- _resourceName.substring(_resourceName.lastIndexOf('.')));
+ builder.append(_resourceName.substring(_resourceName
+ .lastIndexOf('.')));
firstSlashAdded = true;
}
diff --git a/test20/src/main/java/org/apache/myfaces/test/mock/resource/MockSimpleResource.java b/test20/src/main/java/org/apache/myfaces/test/mock/resource/MockSimpleResource.java
index 8ded1e2..71a598a 100644
--- a/test20/src/main/java/org/apache/myfaces/test/mock/resource/MockSimpleResource.java
+++ b/test20/src/main/java/org/apache/myfaces/test/mock/resource/MockSimpleResource.java
@@ -59,7 +59,9 @@
* @param resourceVersion resource version if any
* @param documentRoot parent folder of resource directories. Must not be <code>null</code>
*/
- public MockSimpleResource(String prefix, String libraryName, String libraryVersion, String resourceName, String resourceVersion, File documentRoot)
+ public MockSimpleResource(String prefix, String libraryName,
+ String libraryVersion, String resourceName, String resourceVersion,
+ File documentRoot)
{
_prefix = prefix;
_libraryName = libraryName;
@@ -68,7 +70,8 @@
_resourceVersion = resourceVersion;
_documentRoot = documentRoot;
- if (_documentRoot == null) {
+ if (_documentRoot == null)
+ {
throw new IllegalArgumentException("documentRoot must not be null");
}
}
@@ -90,7 +93,7 @@
{
return _libraryName;
}
-
+
@Override
public void setLibraryName(String libraryName)
{
@@ -100,8 +103,8 @@
@Override
public InputStream getInputStream() throws IOException
{
- MockServletContext servletContext = (MockServletContext)
- FacesContext.getCurrentInstance().getExternalContext().getContext();
+ MockServletContext servletContext = (MockServletContext) FacesContext
+ .getCurrentInstance().getExternalContext().getContext();
servletContext.setDocumentRoot(_documentRoot);
return servletContext.getResourceAsStream(buildResourcePath());
}
@@ -121,13 +124,16 @@
@Override
public URL getURL()
{
- MockServletContext servletContext = (MockServletContext)
- FacesContext.getCurrentInstance().getExternalContext().getContext();
+ MockServletContext servletContext = (MockServletContext) FacesContext
+ .getCurrentInstance().getExternalContext().getContext();
servletContext.setDocumentRoot(_documentRoot);
- try {
+ try
+ {
return servletContext.getResource(buildResourcePath());
- } catch (MalformedURLException e) {
+ }
+ catch (MalformedURLException e)
+ {
return null;
}
}
@@ -143,38 +149,47 @@
StringBuilder builder = new StringBuilder();
builder.append('/');
boolean firstSlashAdded = false;
- if (_prefix != null && _prefix.length() > 0) {
+ if (_prefix != null && _prefix.length() > 0)
+ {
builder.append(_prefix);
firstSlashAdded = true;
}
- if (_libraryName != null) {
- if (firstSlashAdded) {
+ if (_libraryName != null)
+ {
+ if (firstSlashAdded)
+ {
builder.append('/');
}
builder.append(_libraryName);
firstSlashAdded = true;
}
- if (_libraryVersion != null) {
- if (firstSlashAdded) {
+ if (_libraryVersion != null)
+ {
+ if (firstSlashAdded)
+ {
builder.append('/');
}
builder.append(_libraryVersion);
firstSlashAdded = true;
}
- if (_resourceName != null) {
- if (firstSlashAdded) {
+ if (_resourceName != null)
+ {
+ if (firstSlashAdded)
+ {
builder.append('/');
}
builder.append(_resourceName);
firstSlashAdded = true;
}
- if (_resourceVersion != null) {
- if (firstSlashAdded) {
+ if (_resourceVersion != null)
+ {
+ if (firstSlashAdded)
+ {
builder.append('/');
}
builder.append(_resourceVersion);
- builder.append(
- _resourceName.substring(_resourceName.lastIndexOf('.')));
+ builder.append(_resourceName.substring(_resourceName
+ .lastIndexOf('.')));
}
return builder.toString();
diff --git a/test20/src/main/java/org/apache/myfaces/test/mock/resource/MockSimpleResourceHandler.java b/test20/src/main/java/org/apache/myfaces/test/mock/resource/MockSimpleResourceHandler.java
index 98cb477..cc4e8c5 100644
--- a/test20/src/main/java/org/apache/myfaces/test/mock/resource/MockSimpleResourceHandler.java
+++ b/test20/src/main/java/org/apache/myfaces/test/mock/resource/MockSimpleResourceHandler.java
@@ -53,14 +53,16 @@
* <p/>
* Used on getLibraryVersion to filter resource directories
*/
- protected static Pattern VERSION_CHECKER = Pattern.compile("/\\p{Digit}+(_\\p{Digit}*)*/");
+ protected static Pattern VERSION_CHECKER = Pattern
+ .compile("/\\p{Digit}+(_\\p{Digit}*)*/");
/**
* It checks version like this: /1.js, /1_0.js, /1_0_0.js, /100_100.js
* <p/>
* Used on getResourceVersion to filter resources
*/
- protected static Pattern RESOURCE_VERSION_CHECKER = Pattern.compile("/\\p{Digit}+(_\\p{Digit}*)*\\..*");
+ protected static Pattern RESOURCE_VERSION_CHECKER = Pattern
+ .compile("/\\p{Digit}+(_\\p{Digit}*)*\\..*");
private File _documentRoot;
@@ -69,14 +71,16 @@
*/
public MockSimpleResourceHandler(File documentRoot)
{
- if (documentRoot == null) {
+ if (documentRoot == null)
+ {
throw new NullPointerException("documentRoot must not be null");
}
_documentRoot = documentRoot;
- ((MockServletContext) FacesContext.getCurrentInstance().getExternalContext().getContext())
- .setDocumentRoot(_documentRoot);
+ ((MockServletContext) FacesContext.getCurrentInstance()
+ .getExternalContext().getContext())
+ .setDocumentRoot(_documentRoot);
}
@Override
@@ -92,32 +96,36 @@
}
@Override
- public Resource createResource(String resourceName, String libraryName, String contentType)
+ public Resource createResource(String resourceName, String libraryName,
+ String contentType)
{
String prefix = getLocalePrefixForLocateResource();
String libraryVersion = getLibraryVersion(prefix + "/" + libraryName);
String pathToResource;
- if (null != libraryVersion) {
- pathToResource = prefix + '/'
- + libraryName + '/' + libraryVersion + '/'
- + resourceName;
+ if (null != libraryVersion)
+ {
+ pathToResource = prefix + '/' + libraryName + '/' + libraryVersion
+ + '/' + resourceName;
}
- else {
- pathToResource = prefix + '/'
- + libraryName + '/' + resourceName;
+ else
+ {
+ pathToResource = prefix + '/' + libraryName + '/' + resourceName;
}
- return new MockSimpleResource(prefix, libraryName, libraryVersion, resourceName, getResourceVersion(pathToResource), _documentRoot);
+ return new MockSimpleResource(prefix, libraryName, libraryVersion,
+ resourceName, getResourceVersion(pathToResource), _documentRoot);
}
@Override
public String getRendererTypeForResourceName(String resourceName)
{
- if (resourceName.endsWith(".js")) {
+ if (resourceName.endsWith(".js"))
+ {
return "javax.faces.resource.Script";
}
- else if (resourceName.endsWith(".css")) {
+ else if (resourceName.endsWith(".css"))
+ {
return "javax.faces.resource.Stylesheet";
}
return null;
@@ -136,26 +144,31 @@
//on request map so the first time is calculated it remains
//alive until the end of the request
Boolean value = (Boolean) facesContext.getExternalContext()
- .getRequestMap().get(IS_RESOURCE_REQUEST);
+ .getRequestMap().get(IS_RESOURCE_REQUEST);
- if (value != null && value.booleanValue()) {
+ if (value != null && value.booleanValue())
+ {
//return the saved value
return value.booleanValue();
}
- else {
+ else
+ {
// assuming that we don't have servlet mapping
- String resourceBasePath = facesContext.getExternalContext().getRequestPathInfo();
+ String resourceBasePath = facesContext.getExternalContext()
+ .getRequestPathInfo();
if (resourceBasePath != null
- && resourceBasePath
- .startsWith(ResourceHandler.RESOURCE_IDENTIFIER)) {
+ && resourceBasePath
+ .startsWith(ResourceHandler.RESOURCE_IDENTIFIER))
+ {
facesContext.getExternalContext().getRequestMap().put(
- IS_RESOURCE_REQUEST, Boolean.TRUE);
+ IS_RESOURCE_REQUEST, Boolean.TRUE);
return true;
}
- else {
+ else
+ {
facesContext.getExternalContext().getRequestMap().put(
- IS_RESOURCE_REQUEST, Boolean.FALSE);
+ IS_RESOURCE_REQUEST, Boolean.FALSE);
return false;
}
}
@@ -168,19 +181,24 @@
String pathToLib;
- if (localePrefix != null) {
+ if (localePrefix != null)
+ {
//Check with locale
pathToLib = localePrefix + '/' + libraryName;
}
- else {
+ else
+ {
pathToLib = libraryName;
}
- try {
- URL url = FacesContext.getCurrentInstance().getExternalContext().getResource("/" + pathToLib);
+ try
+ {
+ URL url = FacesContext.getCurrentInstance().getExternalContext()
+ .getResource("/" + pathToLib);
return (url != null);
}
- catch (MalformedURLException e) {
+ catch (MalformedURLException e)
+ {
return false;
}
}
@@ -192,18 +210,23 @@
String bundleName = context.getApplication().getMessageBundle();
- if (null != bundleName) {
+ if (null != bundleName)
+ {
Locale locale = context.getApplication().getViewHandler()
- .calculateLocale(context);
+ .calculateLocale(context);
- ResourceBundle bundle = ResourceBundle
- .getBundle(bundleName, locale, getContextClassLoader());
+ ResourceBundle bundle = ResourceBundle.getBundle(bundleName,
+ locale, getContextClassLoader());
- if (bundle != null) {
- try {
- localePrefix = bundle.getString(ResourceHandler.LOCALE_PREFIX);
+ if (bundle != null)
+ {
+ try
+ {
+ localePrefix = bundle
+ .getString(ResourceHandler.LOCALE_PREFIX);
}
- catch (MissingResourceException e) {
+ catch (MissingResourceException e)
+ {
// Ignore it and return null
}
}
@@ -220,48 +243,61 @@
*/
private static ClassLoader getContextClassLoader()
{
- if (System.getSecurityManager() != null) {
- try {
- ClassLoader cl = AccessController.doPrivileged(new PrivilegedExceptionAction<ClassLoader>()
- {
- public ClassLoader run() throws PrivilegedActionException
- {
- return Thread.currentThread().getContextClassLoader();
- }
- });
+ if (System.getSecurityManager() != null)
+ {
+ try
+ {
+ ClassLoader cl = AccessController
+ .doPrivileged(new PrivilegedExceptionAction<ClassLoader>()
+ {
+ public ClassLoader run()
+ throws PrivilegedActionException
+ {
+ return Thread.currentThread()
+ .getContextClassLoader();
+ }
+ });
return cl;
}
- catch (PrivilegedActionException pae) {
+ catch (PrivilegedActionException pae)
+ {
throw new FacesException(pae);
}
}
- else {
+ else
+ {
return Thread.currentThread().getContextClassLoader();
}
}
private String getLibraryVersion(String path)
{
- ExternalContext context = FacesContext.getCurrentInstance().getExternalContext();
+ ExternalContext context = FacesContext.getCurrentInstance()
+ .getExternalContext();
String libraryVersion = null;
Set<String> libraryPaths = context.getResourcePaths("/" + path);
- if (null != libraryPaths && !libraryPaths.isEmpty()) {
+ if (null != libraryPaths && !libraryPaths.isEmpty())
+ {
// Look in the libraryPaths for versioned libraries.
// If one or more versioned libraries are found, take
// the one with the "highest" version number as the value
// of libraryVersion. If no versioned libraries
// are found, let libraryVersion remain null.
- for (String libraryPath : libraryPaths) {
+ for (String libraryPath : libraryPaths)
+ {
String version = libraryPath.substring(path.length());
- if (VERSION_CHECKER.matcher(version).matches()) {
+ if (VERSION_CHECKER.matcher(version).matches())
+ {
version = version.substring(1, version.length() - 1);
- if (libraryVersion == null) {
+ if (libraryVersion == null)
+ {
libraryVersion = version;
}
- else if (compareVersion(libraryVersion, version) < 0) {
+ else if (compareVersion(libraryVersion, version) < 0)
+ {
libraryVersion = version;
}
}
@@ -280,42 +316,52 @@
boolean p1 = true;
boolean p2 = true;
- while (n1 == n2 && (p1 || p2)) {
+ while (n1 == n2 && (p1 || p2))
+ {
int i1 = o1.indexOf('_');
int i2 = o2.indexOf('_');
- if (i1 < 0) {
- if (o1.length() > 0) {
+ if (i1 < 0)
+ {
+ if (o1.length() > 0)
+ {
p1 = false;
n1 = Integer.valueOf(o1);
o1 = "";
}
- else {
+ else
+ {
p1 = false;
n1 = 0;
}
}
- else {
+ else
+ {
n1 = Integer.valueOf(o1.substring(0, i1));
o1 = o1.substring(i1 + 1);
}
- if (i2 < 0) {
- if (o2.length() > 0) {
+ if (i2 < 0)
+ {
+ if (o2.length() > 0)
+ {
p2 = false;
n2 = Integer.valueOf(o2);
o2 = "";
}
- else {
+ else
+ {
p2 = false;
n2 = 0;
}
}
- else {
+ else
+ {
n2 = Integer.valueOf(o2.substring(0, i2));
o2 = o2.substring(i2 + 1);
}
}
- if (n1 == n2) {
+ if (n1 == n2)
+ {
return s1.length() - s2.length();
}
return n1 - n2;
@@ -323,26 +369,32 @@
private String getResourceVersion(String path)
{
- ExternalContext context = FacesContext.getCurrentInstance().getExternalContext();
+ ExternalContext context = FacesContext.getCurrentInstance()
+ .getExternalContext();
String resourceVersion = null;
Set<String> resourcePaths = context.getResourcePaths("/" + path);
- if (null != resourcePaths && !resourcePaths.isEmpty()) {
+ if (null != resourcePaths && !resourcePaths.isEmpty())
+ {
// resourceVersion = // execute the comment
// Look in the resourcePaths for versioned resources.
// If one or more versioned resources are found, take
// the one with the "highest" version number as the value
// of resourceVersion. If no versioned libraries
// are found, let resourceVersion remain null.
- for (String resourcePath : resourcePaths) {
+ for (String resourcePath : resourcePaths)
+ {
String version = resourcePath.substring(path.length());
- if (RESOURCE_VERSION_CHECKER.matcher(version).matches()) {
+ if (RESOURCE_VERSION_CHECKER.matcher(version).matches())
+ {
version = version.substring(1, version.lastIndexOf('.'));
- if (resourceVersion == null) {
+ if (resourceVersion == null)
+ {
resourceVersion = version;
}
- else if (compareVersion(resourceVersion, version) < 0) {
+ else if (compareVersion(resourceVersion, version) < 0)
+ {
resourceVersion = version;
}
}
diff --git a/test20/src/main/java/org/apache/myfaces/test/mock/visit/FullVisitContext.java b/test20/src/main/java/org/apache/myfaces/test/mock/visit/FullVisitContext.java
index 2555982..343667e 100644
--- a/test20/src/main/java/org/apache/myfaces/test/mock/visit/FullVisitContext.java
+++ b/test20/src/main/java/org/apache/myfaces/test/mock/visit/FullVisitContext.java
@@ -42,107 +42,105 @@
public class FullVisitContext extends VisitContext
{
- /**
- * Creates a FullVisitorContext instance.
- * @param facesContext the FacesContext for the current request
- * @throws NullPointerException if {@code facesContext}
- * is {@code null}
- */
- public FullVisitContext(FacesContext facesContext)
- {
- this(facesContext, null);
- }
-
- /**
- * Creates a FullVisitorContext instance with the specified
- * hints.
- *
- * @param facesContext the FacesContext for the current request
- * @param hints a the VisitHints for this visit
- * @param phaseId PhaseId, if any that visit is ocurring under
- * @throws NullPointerException if {@code facesContext}
- * is {@code null}
- * @throws IllegalArgumentException if the phaseId is specified and
- * hints does not contain VisitHint.EXECUTE_LIFECYCLE
- */
- public FullVisitContext(
- FacesContext facesContext,
- Set<VisitHint> hints)
- {
- if (facesContext == null)
- throw new NullPointerException();
-
- _facesContext = facesContext;
-
- // Copy and store hints - ensure unmodifiable and non-empty
- EnumSet<VisitHint> hintsEnumSet = ((hints == null) || (hints.isEmpty()))
- ? EnumSet.noneOf(VisitHint.class)
- : EnumSet.copyOf(hints);
-
- _hints = Collections.unmodifiableSet(hintsEnumSet);
- }
-
- /**
- * @see VisitContext#getFacesContext VisitContext.getFacesContext()
- */
- @Override
- public FacesContext getFacesContext()
- {
- return _facesContext;
- }
-
- /**
- * @see VisitContext#getIdsToVisit VisitContext.getIdsToVisit()
- */
- @Override
- public Collection<String> getIdsToVisit()
- {
- // We always visits all ids
- return ALL_IDS;
- }
-
- /**
- * @see VisitContext#getSubtreeIdsToVisit VisitContext.getSubtreeIdsToVisit()
- */
- @Override
- public Collection<String> getSubtreeIdsToVisit(UIComponent component)
- {
- // Make sure component is a NamingContainer
- if (!(component instanceof NamingContainer))
+ /**
+ * Creates a FullVisitorContext instance.
+ * @param facesContext the FacesContext for the current request
+ * @throws NullPointerException if {@code facesContext}
+ * is {@code null}
+ */
+ public FullVisitContext(FacesContext facesContext)
{
- throw new IllegalArgumentException("Component is not a NamingContainer: " + component);
+ this(facesContext, null);
}
- // We always visits all ids
- return ALL_IDS;
- }
+ /**
+ * Creates a FullVisitorContext instance with the specified
+ * hints.
+ *
+ * @param facesContext the FacesContext for the current request
+ * @param hints a the VisitHints for this visit
+ * @param phaseId PhaseId, if any that visit is ocurring under
+ * @throws NullPointerException if {@code facesContext}
+ * is {@code null}
+ * @throws IllegalArgumentException if the phaseId is specified and
+ * hints does not contain VisitHint.EXECUTE_LIFECYCLE
+ */
+ public FullVisitContext(FacesContext facesContext, Set<VisitHint> hints)
+ {
+ if (facesContext == null)
+ throw new NullPointerException();
- /**
- * @see VisitContext#getHints VisitContext.getHints
- */
- @Override
- public Set<VisitHint> getHints()
- {
- return _hints;
- }
+ _facesContext = facesContext;
- /**
- * @see VisitContext#invokeVisitCallback VisitContext.invokeVisitCallback()
- */
- @Override
- public VisitResult invokeVisitCallback(
- UIComponent component,
- VisitCallback callback)
- {
- // Nothing interesting here - just invoke the callback.
- // (PartialVisitContext.invokeVisitCallback() does all of the
- // interesting work.)
- return callback.visit(this, component);
- }
+ // Copy and store hints - ensure unmodifiable and non-empty
+ EnumSet<VisitHint> hintsEnumSet = ((hints == null) || (hints.isEmpty())) ? EnumSet
+ .noneOf(VisitHint.class)
+ : EnumSet.copyOf(hints);
- // The FacesContext for this request
- private final FacesContext _facesContext;
+ _hints = Collections.unmodifiableSet(hintsEnumSet);
+ }
- // Our visit hints
- private final Set<VisitHint> _hints;
+ /**
+ * @see VisitContext#getFacesContext VisitContext.getFacesContext()
+ */
+ @Override
+ public FacesContext getFacesContext()
+ {
+ return _facesContext;
+ }
+
+ /**
+ * @see VisitContext#getIdsToVisit VisitContext.getIdsToVisit()
+ */
+ @Override
+ public Collection<String> getIdsToVisit()
+ {
+ // We always visits all ids
+ return ALL_IDS;
+ }
+
+ /**
+ * @see VisitContext#getSubtreeIdsToVisit VisitContext.getSubtreeIdsToVisit()
+ */
+ @Override
+ public Collection<String> getSubtreeIdsToVisit(UIComponent component)
+ {
+ // Make sure component is a NamingContainer
+ if (!(component instanceof NamingContainer))
+ {
+ throw new IllegalArgumentException(
+ "Component is not a NamingContainer: " + component);
+ }
+
+ // We always visits all ids
+ return ALL_IDS;
+ }
+
+ /**
+ * @see VisitContext#getHints VisitContext.getHints
+ */
+ @Override
+ public Set<VisitHint> getHints()
+ {
+ return _hints;
+ }
+
+ /**
+ * @see VisitContext#invokeVisitCallback VisitContext.invokeVisitCallback()
+ */
+ @Override
+ public VisitResult invokeVisitCallback(UIComponent component,
+ VisitCallback callback)
+ {
+ // Nothing interesting here - just invoke the callback.
+ // (PartialVisitContext.invokeVisitCallback() does all of the
+ // interesting work.)
+ return callback.visit(this, component);
+ }
+
+ // The FacesContext for this request
+ private final FacesContext _facesContext;
+
+ // Our visit hints
+ private final Set<VisitHint> _hints;
}
\ No newline at end of file
diff --git a/test20/src/main/java/org/apache/myfaces/test/mock/visit/MockVisitContext.java b/test20/src/main/java/org/apache/myfaces/test/mock/visit/MockVisitContext.java
index 0b39136..147495f 100644
--- a/test20/src/main/java/org/apache/myfaces/test/mock/visit/MockVisitContext.java
+++ b/test20/src/main/java/org/apache/myfaces/test/mock/visit/MockVisitContext.java
@@ -49,16 +49,17 @@
public MockVisitContext(FacesContext facesContext, Set<VisitHint> hints)
{
- if (facesContext == null) {
+ if (facesContext == null)
+ {
throw new NullPointerException();
}
_facesContext = facesContext;
// Copy and store hints - ensure unmodifiable and non-empty
- EnumSet<VisitHint> hintsEnumSet = ((hints == null) || (hints.isEmpty()))
- ? EnumSet.noneOf(VisitHint.class)
- : EnumSet.copyOf(hints);
+ EnumSet<VisitHint> hintsEnumSet = ((hints == null) || (hints.isEmpty())) ? EnumSet
+ .noneOf(VisitHint.class)
+ : EnumSet.copyOf(hints);
_hints = Collections.unmodifiableSet(hintsEnumSet);
}
@@ -85,15 +86,18 @@
public Collection<String> getSubtreeIdsToVisit(UIComponent component)
{
// Make sure component is a NamingContainer
- if (!(component instanceof NamingContainer)) {
- throw new IllegalArgumentException("Component is not a NamingContainer: " + component);
+ if (!(component instanceof NamingContainer))
+ {
+ throw new IllegalArgumentException(
+ "Component is not a NamingContainer: " + component);
}
return ALL_IDS;
}
@Override
- public VisitResult invokeVisitCallback(UIComponent component, VisitCallback callback)
+ public VisitResult invokeVisitCallback(UIComponent component,
+ VisitCallback callback)
{
return callback.visit(this, component);
}
diff --git a/test20/src/main/java/org/apache/myfaces/test/mock/visit/MockVisitContextFactory.java b/test20/src/main/java/org/apache/myfaces/test/mock/visit/MockVisitContextFactory.java
index 3d438e2..af23470 100644
--- a/test20/src/main/java/org/apache/myfaces/test/mock/visit/MockVisitContextFactory.java
+++ b/test20/src/main/java/org/apache/myfaces/test/mock/visit/MockVisitContextFactory.java
@@ -36,11 +36,15 @@
{
@Override
- public VisitContext getVisitContext(FacesContext context, Collection<String> ids, Set<VisitHint> hints)
+ public VisitContext getVisitContext(FacesContext context,
+ Collection<String> ids, Set<VisitHint> hints)
{
- if (ids == null || ids.isEmpty()) {
+ if (ids == null || ids.isEmpty())
+ {
return new FullVisitContext(context, hints);
- } else {
+ }
+ else
+ {
return new PartialVisitContext(context, ids, hints);
}
}
diff --git a/test20/src/main/java/org/apache/myfaces/test/mock/visit/PartialVisitContext.java b/test20/src/main/java/org/apache/myfaces/test/mock/visit/PartialVisitContext.java
index 928cbce..e089a3a 100644
--- a/test20/src/main/java/org/apache/myfaces/test/mock/visit/PartialVisitContext.java
+++ b/test20/src/main/java/org/apache/myfaces/test/mock/visit/PartialVisitContext.java
@@ -49,414 +49,411 @@
public class PartialVisitContext extends VisitContext
{
- /**
- * Creates a PartialVisitorContext instance.
- * @param facesContext the FacesContext for the current request
- * @param clientIds the client ids of the components to visit
- * @throws NullPointerException if {@code facesContext}
- * is {@code null}
- */
- public PartialVisitContext(
- FacesContext facesContext,
- Collection<String> clientIds)
- {
- this(facesContext, clientIds, null);
- }
-
- /**
- * Creates a PartialVisitorContext instance with the specified hints.
- * @param facesContext the FacesContext for the current request
- * @param clientIds the client ids of the components to visit
- * @param hints a the VisitHints for this visit
- * @throws NullPointerException if {@code facesContext}
- * is {@code null}
- * @throws IllegalArgumentException if the phaseId is specified and
- * hints does not contain VisitHint.EXECUTE_LIFECYCLE
- */
- public PartialVisitContext(FacesContext facesContext,
- Collection<String> clientIds,
- Set<VisitHint> hints)
- {
- if (facesContext == null)
- throw new NullPointerException();
-
- _facesContext = facesContext;
-
- // Copy the client ids into a HashSet to allow for quick lookups.
- Set<String> clientIdSet = (clientIds == null)
- ? new HashSet<String>()
- : new HashSet<String>(clientIds);
-
- // Initialize our various collections
- // We maintain 4 collections:
- //
- // 1. clientIds: contains all of the client ids to visit
- // 2. ids: contains just ids (not client ids) to visit.
- // We use this to optimize our check to see whether a
- // particular component is in the visit set (ie. to
- // avoid having to compute the client id).
- // 3. subtreeClientIds: contains client ids to visit broken
- // out by naming container subtree. (Needed by
- // getSubtreeIdsToVisit()).
- // 4. unvisitedClientIds: contains the client ids to visit that
- // have not yet been visited.
- //
- // We populate these now.
- //
- // Note that we use default HashSet/Map initial capacities, though
- // perhaps we could pick more intelligent defaults.
-
- // Initialize unvisitedClientIds collection
- _unvisitedClientIds = new HashSet<String>();
-
- // Initialize ids collection
- _ids = new HashSet<String>();
-
- // Intialize subtreeClientIds collection
- _subtreeClientIds = new HashMap<String, Collection<String>>();
-
- // Initialize the clientIds collection. Note that we proxy
- // this collection so that we can trap adds/removes and sync
- // up all of the other collections.
- _clientIds = new CollectionProxy<String>(new HashSet<String>());
-
- // Finally, populate the clientIds collection. This has the
- // side effect of populating all of the other collections.
- _clientIds.addAll(clientIdSet);
-
- // Copy and store hints - ensure unmodifiable and non-empty
- EnumSet<VisitHint> hintsEnumSet = ((hints == null) || (hints.isEmpty()))
- ? EnumSet.noneOf(VisitHint.class)
- : EnumSet.copyOf(hints);
-
- _hints = Collections.unmodifiableSet(hintsEnumSet);
- }
-
- /**
- * @see VisitContext#getFacesContext VisitContext.getFacesContext()
- */
- @Override
- public FacesContext getFacesContext()
- {
- return _facesContext;
- }
-
- /**
- * @see VisitContext#getHints VisitContext.getHints
- */
- @Override
- public Set<VisitHint> getHints()
- {
- return _hints;
- }
-
- /**
- * @see VisitContext#getIdsToVisit VisitContext.getIdsToVisit()
- */
- @Override
- public Collection<String> getIdsToVisit()
- {
- // We just return our clientIds collection. This is
- // the modifiable (but proxied) collection of all of
- // the client ids to visit.
- return _clientIds;
- }
-
- /**
- * @see VisitContext#getSubtreeIdsToVisit VisitContext.getSubtreeIdsToVisit()
- */
- @Override
- public Collection<String> getSubtreeIdsToVisit(UIComponent component)
- {
- // Make sure component is a NamingContainer
- if (!(component instanceof NamingContainer))
+ /**
+ * Creates a PartialVisitorContext instance.
+ * @param facesContext the FacesContext for the current request
+ * @param clientIds the client ids of the components to visit
+ * @throws NullPointerException if {@code facesContext}
+ * is {@code null}
+ */
+ public PartialVisitContext(FacesContext facesContext,
+ Collection<String> clientIds)
{
- throw new IllegalArgumentException("Component is not a NamingContainer: " + component);
+ this(facesContext, clientIds, null);
}
- String clientId = component.getClientId(getFacesContext());
- Collection<String> ids = _subtreeClientIds.get(clientId);
-
- if (ids == null)
- return Collections.emptyList();
- else
- return Collections.unmodifiableCollection(ids);
- }
-
- /**
- * @see VisitContext#invokeVisitCallback VisitContext.invokeVisitCallback()
- */
- @Override
- public VisitResult invokeVisitCallback(
- UIComponent component,
- VisitCallback callback)
- {
- // First sure that we should visit this component - ie.
- // that this component is represented in our id set.
- String clientId = _getVisitId(component);
-
- if (clientId == null)
+ /**
+ * Creates a PartialVisitorContext instance with the specified hints.
+ * @param facesContext the FacesContext for the current request
+ * @param clientIds the client ids of the components to visit
+ * @param hints a the VisitHints for this visit
+ * @throws NullPointerException if {@code facesContext}
+ * is {@code null}
+ * @throws IllegalArgumentException if the phaseId is specified and
+ * hints does not contain VisitHint.EXECUTE_LIFECYCLE
+ */
+ public PartialVisitContext(FacesContext facesContext,
+ Collection<String> clientIds, Set<VisitHint> hints)
{
- // Not visiting this component, but allow visit to
- // continue into this subtree in case we've got
- // visit targets there.
- return VisitResult.ACCEPT;
+ if (facesContext == null)
+ throw new NullPointerException();
+
+ _facesContext = facesContext;
+
+ // Copy the client ids into a HashSet to allow for quick lookups.
+ Set<String> clientIdSet = (clientIds == null) ? new HashSet<String>()
+ : new HashSet<String>(clientIds);
+
+ // Initialize our various collections
+ // We maintain 4 collections:
+ //
+ // 1. clientIds: contains all of the client ids to visit
+ // 2. ids: contains just ids (not client ids) to visit.
+ // We use this to optimize our check to see whether a
+ // particular component is in the visit set (ie. to
+ // avoid having to compute the client id).
+ // 3. subtreeClientIds: contains client ids to visit broken
+ // out by naming container subtree. (Needed by
+ // getSubtreeIdsToVisit()).
+ // 4. unvisitedClientIds: contains the client ids to visit that
+ // have not yet been visited.
+ //
+ // We populate these now.
+ //
+ // Note that we use default HashSet/Map initial capacities, though
+ // perhaps we could pick more intelligent defaults.
+
+ // Initialize unvisitedClientIds collection
+ _unvisitedClientIds = new HashSet<String>();
+
+ // Initialize ids collection
+ _ids = new HashSet<String>();
+
+ // Intialize subtreeClientIds collection
+ _subtreeClientIds = new HashMap<String, Collection<String>>();
+
+ // Initialize the clientIds collection. Note that we proxy
+ // this collection so that we can trap adds/removes and sync
+ // up all of the other collections.
+ _clientIds = new CollectionProxy<String>(new HashSet<String>());
+
+ // Finally, populate the clientIds collection. This has the
+ // side effect of populating all of the other collections.
+ _clientIds.addAll(clientIdSet);
+
+ // Copy and store hints - ensure unmodifiable and non-empty
+ EnumSet<VisitHint> hintsEnumSet = ((hints == null) || (hints.isEmpty())) ? EnumSet
+ .noneOf(VisitHint.class)
+ : EnumSet.copyOf(hints);
+
+ _hints = Collections.unmodifiableSet(hintsEnumSet);
}
- // If we made it this far, the component matches one of
- // client ids, so perform the visit.
- VisitResult result = callback.visit(this, component);
-
- // Remove the component from our "unvisited" collection
- _unvisitedClientIds.remove(clientId);
-
- // If the unvisited collection is now empty, we are done.
- // Return VisitResult.COMPLETE to terminate the visit.
- if (_unvisitedClientIds.isEmpty())
- return VisitResult.COMPLETE;
- else
+ /**
+ * @see VisitContext#getFacesContext VisitContext.getFacesContext()
+ */
+ @Override
+ public FacesContext getFacesContext()
{
- // Otherwise, just return the callback's result
- return result;
+ return _facesContext;
}
- }
-
- // Called by CollectionProxy to notify PartialVisitContext that
- // an new id has been added.
- private void _idAdded(String clientId)
- {
- // An id to visit has been added, update our other
- // collections to reflect this.
-
- // Update the ids collection
- _ids.add(_getIdFromClientId(clientId));
-
- // Update the unvisited ids collection
- _unvisitedClientIds.add(clientId);
-
- // Update the subtree ids collection
- _addSubtreeClientId(clientId);
- }
-
- // Called by CollectionProxy to notify PartialVisitContext that
- // an id has been removed
- private void _idRemoved(String clientId)
- {
- // An id to visit has been removed, update our other
- // collections to reflect this. Note that we don't
- // update the ids collection, since we ids (non-client ids)
- // may not be unique.
-
- // Update the unvisited ids collection
- _unvisitedClientIds.remove(clientId);
-
- // Update the subtree ids collection
- _removeSubtreeClientId(clientId);
- }
-
- // Tests whether the specified component should be visited.
- // If so, returns its client id. If not, returns null.
- private String _getVisitId(UIComponent component)
- {
- // We first check to see whether the component's id
- // is in our id collection. We do this before checking
- // for the full client id because getting the full client id
- // is more expensive than just getting the local id.
- String id = component.getId();
-
- if ((id != null) && !_ids.contains(id))
- return null;
-
- // The id was a match - now check the client id.
- // note that client id should never be null (should be
- // generated even if id is null, so asserting this.)
- String clientId = component.getClientId(getFacesContext());
- assert(clientId != null);
-
- return _clientIds.contains(clientId) ? clientId : null;
- }
-
-
-
- // Converts an client id into a plain old id by ripping
- // out the trailing id segmetn.
- private String _getIdFromClientId(String clientId)
- {
- final char separator = UINamingContainer.getSeparatorChar(_facesContext);
- int lastIndex = clientId.lastIndexOf(separator);
-
- String id = null;
-
- if (lastIndex < 0)
+ /**
+ * @see VisitContext#getHints VisitContext.getHints
+ */
+ @Override
+ public Set<VisitHint> getHints()
{
- id = clientId;
+ return _hints;
}
- else if (lastIndex < (clientId.length() - 1))
+
+ /**
+ * @see VisitContext#getIdsToVisit VisitContext.getIdsToVisit()
+ */
+ @Override
+ public Collection<String> getIdsToVisit()
{
- id = clientId.substring(lastIndex + 1);
+ // We just return our clientIds collection. This is
+ // the modifiable (but proxied) collection of all of
+ // the client ids to visit.
+ return _clientIds;
}
- else
+
+ /**
+ * @see VisitContext#getSubtreeIdsToVisit VisitContext.getSubtreeIdsToVisit()
+ */
+ @Override
+ public Collection<String> getSubtreeIdsToVisit(UIComponent component)
{
- // TODO log warning for trailing colon case
- }
-
- return id;
- }
-
-
- // Given a single client id, populate the subtree map with all possible
- // subtree client ids
- private void _addSubtreeClientId(String clientId)
- {
- // Loop over the client id and find the substring corresponding to
- // each ancestor NamingContainer client id. For each ancestor
- // NamingContainer, add an entry into the map for the full client
- // id.
- final char separator = UINamingContainer.getSeparatorChar(_facesContext);
-
- int length = clientId.length();
-
- for (int i = 0; i < length; i++)
- {
- if (clientId.charAt(i) == separator)
- {
- // We found an ancestor NamingContainer client id - add
- // an entry to the map.
- String namingContainerClientId = clientId.substring(0, i);
-
- // Check to see whether we've already ids under this
- // NamingContainer client id. If not, create the
- // Collection for this NamingContainer client id and
- // stash it away in our map
- Collection<String> c = _subtreeClientIds.get(namingContainerClientId);
-
- if (c == null)
+ // Make sure component is a NamingContainer
+ if (!(component instanceof NamingContainer))
{
- // TODO: smarter initial size?
- c = new ArrayList<String>();
- _subtreeClientIds.put(namingContainerClientId, c);
+ throw new IllegalArgumentException(
+ "Component is not a NamingContainer: " + component);
}
- // Stash away the client id
- c.add(clientId);
- }
- }
- }
+ String clientId = component.getClientId(getFacesContext());
+ Collection<String> ids = _subtreeClientIds.get(clientId);
- // Given a single client id, remove any entries corresponding
- // entries from our subtree collections
- private void _removeSubtreeClientId(String clientId)
- {
- // Loop through each entry in the map and check to see whether
- // the client id to remove should be contained in the corresponding
- // collection - ie. whether the key (the NamingContainer client id)
- // is present at the start of the client id to remove.
- for (String key : _subtreeClientIds.keySet())
- {
- if (clientId.startsWith(key))
- {
- // If the clientId starts with the key, we should
- // have an entry for this clientId in the corresponding
- // collection. Remove it.
- Collection<String> ids = _subtreeClientIds.get(key);
- ids.remove(clientId);
- }
- }
- }
-
- // Little proxy collection implementation. We proxy the id
- // collection so that we can detect modifications and update
- // our internal state when ids to visit are added or removed.
- private class CollectionProxy<E extends String> extends AbstractCollection<E>
- {
- private CollectionProxy(Collection<E> wrapped)
- {
- _wrapped = wrapped;
+ if (ids == null)
+ return Collections.emptyList();
+ else
+ return Collections.unmodifiableCollection(ids);
}
+ /**
+ * @see VisitContext#invokeVisitCallback VisitContext.invokeVisitCallback()
+ */
@Override
- public int size()
+ public VisitResult invokeVisitCallback(UIComponent component,
+ VisitCallback callback)
{
- return _wrapped.size();
+ // First sure that we should visit this component - ie.
+ // that this component is represented in our id set.
+ String clientId = _getVisitId(component);
+
+ if (clientId == null)
+ {
+ // Not visiting this component, but allow visit to
+ // continue into this subtree in case we've got
+ // visit targets there.
+ return VisitResult.ACCEPT;
+ }
+
+ // If we made it this far, the component matches one of
+ // client ids, so perform the visit.
+ VisitResult result = callback.visit(this, component);
+
+ // Remove the component from our "unvisited" collection
+ _unvisitedClientIds.remove(clientId);
+
+ // If the unvisited collection is now empty, we are done.
+ // Return VisitResult.COMPLETE to terminate the visit.
+ if (_unvisitedClientIds.isEmpty())
+ return VisitResult.COMPLETE;
+ else
+ {
+ // Otherwise, just return the callback's result
+ return result;
+ }
}
- @Override
- public Iterator<E> iterator()
+ // Called by CollectionProxy to notify PartialVisitContext that
+ // an new id has been added.
+ private void _idAdded(String clientId)
{
- return new IteratorProxy<E>(_wrapped.iterator());
+ // An id to visit has been added, update our other
+ // collections to reflect this.
+
+ // Update the ids collection
+ _ids.add(_getIdFromClientId(clientId));
+
+ // Update the unvisited ids collection
+ _unvisitedClientIds.add(clientId);
+
+ // Update the subtree ids collection
+ _addSubtreeClientId(clientId);
}
- @Override
- public boolean add(E o)
+ // Called by CollectionProxy to notify PartialVisitContext that
+ // an id has been removed
+ private void _idRemoved(String clientId)
{
- boolean added = _wrapped.add(o);
+ // An id to visit has been removed, update our other
+ // collections to reflect this. Note that we don't
+ // update the ids collection, since we ids (non-client ids)
+ // may not be unique.
- if (added)
- {
- _idAdded(o);
- }
+ // Update the unvisited ids collection
+ _unvisitedClientIds.remove(clientId);
- return added;
+ // Update the subtree ids collection
+ _removeSubtreeClientId(clientId);
}
- private final Collection<E> _wrapped;
- }
-
- // Little proxy iterator implementation used by CollectionProxy
- // so that we can catch removes.
- private class IteratorProxy<E extends String> implements Iterator<E>
- {
- private IteratorProxy(Iterator<E> wrapped)
+ // Tests whether the specified component should be visited.
+ // If so, returns its client id. If not, returns null.
+ private String _getVisitId(UIComponent component)
{
- _wrapped = wrapped;
+ // We first check to see whether the component's id
+ // is in our id collection. We do this before checking
+ // for the full client id because getting the full client id
+ // is more expensive than just getting the local id.
+ String id = component.getId();
+
+ if ((id != null) && !_ids.contains(id))
+ return null;
+
+ // The id was a match - now check the client id.
+ // note that client id should never be null (should be
+ // generated even if id is null, so asserting this.)
+ String clientId = component.getClientId(getFacesContext());
+ assert (clientId != null);
+
+ return _clientIds.contains(clientId) ? clientId : null;
}
- public boolean hasNext()
+ // Converts an client id into a plain old id by ripping
+ // out the trailing id segmetn.
+ private String _getIdFromClientId(String clientId)
{
- return _wrapped.hasNext();
+ final char separator = UINamingContainer
+ .getSeparatorChar(_facesContext);
+ int lastIndex = clientId.lastIndexOf(separator);
+
+ String id = null;
+
+ if (lastIndex < 0)
+ {
+ id = clientId;
+ }
+ else if (lastIndex < (clientId.length() - 1))
+ {
+ id = clientId.substring(lastIndex + 1);
+ }
+ else
+ {
+ // TODO log warning for trailing colon case
+ }
+
+ return id;
}
- public E next()
+ // Given a single client id, populate the subtree map with all possible
+ // subtree client ids
+ private void _addSubtreeClientId(String clientId)
{
- _current = _wrapped.next();
-
- return _current;
+ // Loop over the client id and find the substring corresponding to
+ // each ancestor NamingContainer client id. For each ancestor
+ // NamingContainer, add an entry into the map for the full client
+ // id.
+ final char separator = UINamingContainer
+ .getSeparatorChar(_facesContext);
+
+ int length = clientId.length();
+
+ for (int i = 0; i < length; i++)
+ {
+ if (clientId.charAt(i) == separator)
+ {
+ // We found an ancestor NamingContainer client id - add
+ // an entry to the map.
+ String namingContainerClientId = clientId.substring(0, i);
+
+ // Check to see whether we've already ids under this
+ // NamingContainer client id. If not, create the
+ // Collection for this NamingContainer client id and
+ // stash it away in our map
+ Collection<String> c = _subtreeClientIds
+ .get(namingContainerClientId);
+
+ if (c == null)
+ {
+ // TODO: smarter initial size?
+ c = new ArrayList<String>();
+ _subtreeClientIds.put(namingContainerClientId, c);
+ }
+
+ // Stash away the client id
+ c.add(clientId);
+ }
+ }
}
- public void remove()
+ // Given a single client id, remove any entries corresponding
+ // entries from our subtree collections
+ private void _removeSubtreeClientId(String clientId)
{
- if (_current != null)
- {
- _idRemoved(_current);
- }
-
- _wrapped.remove();
+ // Loop through each entry in the map and check to see whether
+ // the client id to remove should be contained in the corresponding
+ // collection - ie. whether the key (the NamingContainer client id)
+ // is present at the start of the client id to remove.
+ for (String key : _subtreeClientIds.keySet())
+ {
+ if (clientId.startsWith(key))
+ {
+ // If the clientId starts with the key, we should
+ // have an entry for this clientId in the corresponding
+ // collection. Remove it.
+ Collection<String> ids = _subtreeClientIds.get(key);
+ ids.remove(clientId);
+ }
+ }
}
- private final Iterator<E> _wrapped;
+ // Little proxy collection implementation. We proxy the id
+ // collection so that we can detect modifications and update
+ // our internal state when ids to visit are added or removed.
+ private class CollectionProxy<E extends String> extends
+ AbstractCollection<E>
+ {
+ private CollectionProxy(Collection<E> wrapped)
+ {
+ _wrapped = wrapped;
+ }
- private E _current = null;
- }
+ @Override
+ public int size()
+ {
+ return _wrapped.size();
+ }
- // The client ids to visit
- private final Collection<String> _clientIds;
+ @Override
+ public Iterator<E> iterator()
+ {
+ return new IteratorProxy<E>(_wrapped.iterator());
+ }
- // The ids to visit
- private final Collection<String> _ids;
+ @Override
+ public boolean add(E o)
+ {
+ boolean added = _wrapped.add(o);
- // The client ids that have yet to be visited
- private final Collection<String> _unvisitedClientIds;
+ if (added)
+ {
+ _idAdded(o);
+ }
- // This map contains the information needed by getIdsToVisit().
- // The keys in this map are NamingContainer client ids. The values
- // are collections containing all of the client ids to visit within
- // corresponding naming container.
- private final Map<String,Collection<String>> _subtreeClientIds;
+ return added;
+ }
- // The FacesContext for this request
- private final FacesContext _facesContext;
+ private final Collection<E> _wrapped;
+ }
- // Our visit hints
- private final Set<VisitHint> _hints;
+ // Little proxy iterator implementation used by CollectionProxy
+ // so that we can catch removes.
+ private class IteratorProxy<E extends String> implements Iterator<E>
+ {
+ private IteratorProxy(Iterator<E> wrapped)
+ {
+ _wrapped = wrapped;
+ }
+
+ public boolean hasNext()
+ {
+ return _wrapped.hasNext();
+ }
+
+ public E next()
+ {
+ _current = _wrapped.next();
+
+ return _current;
+ }
+
+ public void remove()
+ {
+ if (_current != null)
+ {
+ _idRemoved(_current);
+ }
+
+ _wrapped.remove();
+ }
+
+ private final Iterator<E> _wrapped;
+
+ private E _current = null;
+ }
+
+ // The client ids to visit
+ private final Collection<String> _clientIds;
+
+ // The ids to visit
+ private final Collection<String> _ids;
+
+ // The client ids that have yet to be visited
+ private final Collection<String> _unvisitedClientIds;
+
+ // This map contains the information needed by getIdsToVisit().
+ // The keys in this map are NamingContainer client ids. The values
+ // are collections containing all of the client ids to visit within
+ // corresponding naming container.
+ private final Map<String, Collection<String>> _subtreeClientIds;
+
+ // The FacesContext for this request
+ private final FacesContext _facesContext;
+
+ // Our visit hints
+ private final Set<VisitHint> _hints;
}
\ No newline at end of file
diff --git a/test20/src/test/java/org/apache/myfaces/test/config/ConfigParserTestCase.java b/test20/src/test/java/org/apache/myfaces/test/config/ConfigParserTestCase.java
index 1aab275..98ec51f 100644
--- a/test20/src/test/java/org/apache/myfaces/test/config/ConfigParserTestCase.java
+++ b/test20/src/test/java/org/apache/myfaces/test/config/ConfigParserTestCase.java
@@ -37,10 +37,8 @@
public class ConfigParserTestCase extends AbstractJsfTestCase
{
-
// ------------------------------------------------------------ Constructors
-
// Construct a new instance of this test case.
public ConfigParserTestCase(String name)
@@ -48,10 +46,8 @@
super(name);
}
-
// ---------------------------------------------------- Overall Test Methods
-
// Set up instance variables required by this test case.
protected void setUp() throws Exception
@@ -63,7 +59,6 @@
}
-
// Return the tests included in this test case.
public static Test suite()
@@ -73,7 +68,6 @@
}
-
// Tear down instance variables required by this test case.
protected void tearDown() throws Exception
@@ -84,10 +78,8 @@
}
-
// ------------------------------------------------------ Instance Variables
-
// ConfigParser instance under test
ConfigParser parser = null;
@@ -95,9 +87,9 @@
// ------------------------------------------------- Individual Test Methods
-
// Test access to the platform configuration resources
- public void testPlatform() throws Exception {
+ public void testPlatform() throws Exception
+ {
// Make sure we can acquire a good set of URLs
URL[] urls = parser.getPlatformURLs();
@@ -110,22 +102,21 @@
}
-
// Test a pristine instance
- public void testPristine() {
+ public void testPristine()
+ {
assertNotNull(parser);
}
-
// Test loading a simple configuration resource
@SuppressWarnings("unchecked")
public void testSimple() throws Exception
{
-
- URL url = this.getClass().getResource("/org/apache/myfaces/test/config/faces-config-1.xml");
+ URL url = this.getClass().getResource(
+ "/org/apache/myfaces/test/config/faces-config-1.xml");
assertNotNull(url);
parser.parse(url);
Iterator items;
@@ -133,7 +124,8 @@
items = application20.getComponentTypes();
list.clear();
- while (items.hasNext()) {
+ while (items.hasNext())
+ {
list.add(items.next());
}
assertTrue(list.contains("component-type-1"));
@@ -141,7 +133,8 @@
items = application.getConverterIds();
list.clear();
- while (items.hasNext()) {
+ while (items.hasNext())
+ {
list.add(items.next());
}
assertTrue(list.contains("converter-id-1"));
@@ -153,41 +146,48 @@
items = application.getValidatorIds();
list.clear();
- while (items.hasNext()) {
+ while (items.hasNext())
+ {
list.add(items.next());
}
assertTrue(list.contains("validator-id-1"));
assertTrue(list.contains("validator-id-2"));
- Renderer renderer = renderKit.getRenderer("component-family-1", "renderer-type-1");
+ Renderer renderer = renderKit.getRenderer("component-family-1",
+ "renderer-type-1");
assertNotNull(renderer);
assertTrue(renderer instanceof MyRenderer);
-
- renderer = renderKit.getRenderer("component-family-2", "renderer-type-2");
+
+ renderer = renderKit.getRenderer("component-family-2",
+ "renderer-type-2");
assertNotNull(renderer);
assertTrue(renderer instanceof MyRenderer);
-
+
items = application20.getBehaviorIds();
list.clear();
- while (items.hasNext()) {
+ while (items.hasNext())
+ {
list.add(items.next());
}
assertTrue(list.contains("behavior-1"));
assertTrue(list.contains("behavior-2"));
-
+
items = renderKit.getClientBehaviorRendererTypes();
list.clear();
- while (items.hasNext()) {
+ while (items.hasNext())
+ {
list.add(items.next());
}
assertTrue(list.contains("client-behavior-renderer-1"));
assertTrue(list.contains("client-behavior-renderer-2"));
-
- ClientBehaviorRenderer clientBehaviorRenderer1 = renderKit.getClientBehaviorRenderer("client-behavior-renderer-1");
+
+ ClientBehaviorRenderer clientBehaviorRenderer1 = renderKit
+ .getClientBehaviorRenderer("client-behavior-renderer-1");
assertNotNull(clientBehaviorRenderer1);
assertTrue(clientBehaviorRenderer1 instanceof MyClientBehaviorRenderer);
- ClientBehaviorRenderer clientBehaviorRenderer2 = renderKit.getClientBehaviorRenderer("client-behavior-renderer-2");
+ ClientBehaviorRenderer clientBehaviorRenderer2 = renderKit
+ .getClientBehaviorRenderer("client-behavior-renderer-2");
assertNotNull(clientBehaviorRenderer2);
assertTrue(clientBehaviorRenderer2 instanceof MyClientBehaviorRenderer);
}
diff --git a/test20/src/test/java/org/apache/myfaces/test/config/MyBehavior.java b/test20/src/test/java/org/apache/myfaces/test/config/MyBehavior.java
index 0c6a183..c41d7e3 100644
--- a/test20/src/test/java/org/apache/myfaces/test/config/MyBehavior.java
+++ b/test20/src/test/java/org/apache/myfaces/test/config/MyBehavior.java
@@ -23,6 +23,6 @@
{
public void broadcast(BehaviorEvent event)
{
-
+
}
}
diff --git a/test20/src/test/java/org/apache/myfaces/test/config/MyConverter.java b/test20/src/test/java/org/apache/myfaces/test/config/MyConverter.java
index 0d8137d..f928ef4 100644
--- a/test20/src/test/java/org/apache/myfaces/test/config/MyConverter.java
+++ b/test20/src/test/java/org/apache/myfaces/test/config/MyConverter.java
@@ -24,13 +24,18 @@
/**
* <p>Concrete converter implementation for testing.</p>
*/
-public class MyConverter implements Converter {
+public class MyConverter implements Converter
+{
- public Object getAsObject(FacesContext context, UIComponent component, String value) {
+ public Object getAsObject(FacesContext context, UIComponent component,
+ String value)
+ {
throw new UnsupportedOperationException();
}
- public String getAsString(FacesContext context, UIComponent component, Object value) {
+ public String getAsString(FacesContext context, UIComponent component,
+ Object value)
+ {
throw new UnsupportedOperationException();
}
diff --git a/test20/src/test/java/org/apache/myfaces/test/config/MyRenderer.java b/test20/src/test/java/org/apache/myfaces/test/config/MyRenderer.java
index 20d6745..0df341d 100644
--- a/test20/src/test/java/org/apache/myfaces/test/config/MyRenderer.java
+++ b/test20/src/test/java/org/apache/myfaces/test/config/MyRenderer.java
@@ -22,6 +22,7 @@
/**
* <p>Concrete renderer implementation for testing.</p>
*/
-public class MyRenderer extends Renderer {
-
+public class MyRenderer extends Renderer
+{
+
}
diff --git a/test20/src/test/java/org/apache/myfaces/test/config/MyValidator.java b/test20/src/test/java/org/apache/myfaces/test/config/MyValidator.java
index d1f9f97..f7c9131 100644
--- a/test20/src/test/java/org/apache/myfaces/test/config/MyValidator.java
+++ b/test20/src/test/java/org/apache/myfaces/test/config/MyValidator.java
@@ -25,7 +25,8 @@
/**
* <p>Concrete validator implementation for testing.</p>
*/
-public class MyValidator implements Validator {
+public class MyValidator implements Validator
+{
public void validate(FacesContext context, UIComponent component,
Object value) throws ValidatorException
diff --git a/test20/src/test/java/org/apache/myfaces/test/mock/MockApplication20TestCase.java b/test20/src/test/java/org/apache/myfaces/test/mock/MockApplication20TestCase.java
index bd56e68..ecd7b5d 100644
--- a/test20/src/test/java/org/apache/myfaces/test/mock/MockApplication20TestCase.java
+++ b/test20/src/test/java/org/apache/myfaces/test/mock/MockApplication20TestCase.java
@@ -69,9 +69,10 @@
String behaviorId = "BehaviorBaseId";
_application.addBehavior(behaviorId,
- "javax.faces.component.behavior.BehaviorBase");
+ "javax.faces.component.behavior.BehaviorBase");
- assertTrue("Behavior not added", _application.getBehaviorIds().hasNext());
+ assertTrue("Behavior not added", _application.getBehaviorIds()
+ .hasNext());
assertEquals(behaviorId, _application.getBehaviorIds().next());
Behavior createdBehavior = _application.createBehavior(behaviorId);
@@ -87,6 +88,7 @@
assertTrue(_application.getValidatorIds().hasNext());
_application.addDefaultValidatorId(validatorId);
- assertTrue(_application.getDefaultValidatorInfo().containsKey(validatorId));
+ assertTrue(_application.getDefaultValidatorInfo().containsKey(
+ validatorId));
}
}
diff --git a/test20/src/test/java/org/apache/myfaces/test/mock/MockExternalContext20TestCase.java b/test20/src/test/java/org/apache/myfaces/test/mock/MockExternalContext20TestCase.java
index 8b8483d..f97591e 100644
--- a/test20/src/test/java/org/apache/myfaces/test/mock/MockExternalContext20TestCase.java
+++ b/test20/src/test/java/org/apache/myfaces/test/mock/MockExternalContext20TestCase.java
@@ -67,8 +67,8 @@
valueList.add("value1");
parameters.put("param1", valueList);
- assertEquals("http://localhost:8080?param1=value1",
- _context.encodeBookmarkableURL("http://localhost:8080", parameters));
+ assertEquals("http://localhost:8080?param1=value1", _context
+ .encodeBookmarkableURL("http://localhost:8080", parameters));
}
public void testEncodeRedirectURL()
@@ -78,8 +78,8 @@
valueList.add("value1");
parameters.put("param1", valueList);
- assertEquals("http://localhost:8080?param1=value1",
- _context.encodeRedirectURL("http://localhost:8080", parameters));
+ assertEquals("http://localhost:8080?param1=value1", _context
+ .encodeRedirectURL("http://localhost:8080", parameters));
}
public void testGetContextName()
@@ -90,15 +90,15 @@
public void testResponseSendError() throws Exception
{
_context.responseSendError(404, "not found");
- assertEquals(404,
- ((MockHttpServletResponse) _context.getResponse()).getStatus());
+ assertEquals(404, ((MockHttpServletResponse) _context.getResponse())
+ .getStatus());
}
public void testResponseHeader() throws Exception
{
_context.setResponseHeader("header1", "value1");
- assertEquals("value1",
- ((MockHttpServletResponse) _context.getResponse()).getHeader("header1"));
+ assertEquals("value1", ((MockHttpServletResponse) _context
+ .getResponse()).getHeader("header1"));
}
public void testGetRequestScheme()
diff --git a/test20/src/test/java/org/apache/myfaces/test/mock/MockFacesContext20TestCase.java b/test20/src/test/java/org/apache/myfaces/test/mock/MockFacesContext20TestCase.java
index ede945c..fb0319f 100644
--- a/test20/src/test/java/org/apache/myfaces/test/mock/MockFacesContext20TestCase.java
+++ b/test20/src/test/java/org/apache/myfaces/test/mock/MockFacesContext20TestCase.java
@@ -81,7 +81,8 @@
assertTrue(messageList.contains(message1));
assertTrue(messageList.contains(message2));
- List<FacesMessage> messageListClientId = _context.getMessageList("clientid1");
+ List<FacesMessage> messageListClientId = _context
+ .getMessageList("clientid1");
assertEquals(1, messageListClientId.size());
assertTrue(messageListClientId.contains(message1));
}
diff --git a/test20/src/test/java/org/apache/myfaces/test/mock/MockPartialViewContextTestCase.java b/test20/src/test/java/org/apache/myfaces/test/mock/MockPartialViewContextTestCase.java
index 72d3647..15c6864 100644
--- a/test20/src/test/java/org/apache/myfaces/test/mock/MockPartialViewContextTestCase.java
+++ b/test20/src/test/java/org/apache/myfaces/test/mock/MockPartialViewContextTestCase.java
@@ -62,7 +62,8 @@
FacesContext facesContext = FacesContext.getCurrentInstance();
PartialViewContextFactory factory = new MockPartialViewContextFactory();
- PartialViewContext pvContext = factory.getPartialViewContext(facesContext);
+ PartialViewContext pvContext = factory
+ .getPartialViewContext(facesContext);
assertFalse(pvContext.isAjaxRequest());
externalContext.addRequestHeader("Faces-Request", "partial/ajax");
diff --git a/test20/src/test/java/org/apache/myfaces/test/mock/MockResourceTestCase.java b/test20/src/test/java/org/apache/myfaces/test/mock/MockResourceTestCase.java
index bf74832..4e18a73 100644
--- a/test20/src/test/java/org/apache/myfaces/test/mock/MockResourceTestCase.java
+++ b/test20/src/test/java/org/apache/myfaces/test/mock/MockResourceTestCase.java
@@ -34,67 +34,84 @@
/**
* Test case for resource handling
*/
-public class MockResourceTestCase extends AbstractJsfTestCase {
+public class MockResourceTestCase extends AbstractJsfTestCase
+{
private File _documentRoot;
- public MockResourceTestCase(String name) {
+ public MockResourceTestCase(String name)
+ {
super(name);
}
// Set up instance variables required by this test case.
- protected void setUp() throws Exception {
+ protected void setUp() throws Exception
+ {
super.setUp();
- _documentRoot = new File("src/test/resources/org/apache/myfaces/test/mock/resources");
+ _documentRoot = new File(
+ "src/test/resources/org/apache/myfaces/test/mock/resources");
}
// Return the tests included in this test case.
- public static Test suite() {
+ public static Test suite()
+ {
return (new TestSuite(MockResourceTestCase.class));
}
// Tear down instance variables required by this test case.
- protected void tearDown() throws Exception {
+ protected void tearDown() throws Exception
+ {
super.tearDown();
}
- public void testGetResource() throws Exception {
+ public void testGetResource() throws Exception
+ {
- Resource resource = new MockSimpleResource(null, "testlib", null, "testfile.js", null, _documentRoot);
+ Resource resource = new MockSimpleResource(null, "testlib", null,
+ "testfile.js", null, _documentRoot);
URL resourceUrl = resource.getURL();
assertNotNull("Could not find resource", resourceUrl);
- assertTrue(resourceUrl.toString().endsWith("org/apache/myfaces/test/mock/resources/testlib/testfile.js"));
+ assertTrue(resourceUrl.toString().endsWith(
+ "org/apache/myfaces/test/mock/resources/testlib/testfile.js"));
}
- public void testGetNotExistingResource() throws Exception {
+ public void testGetNotExistingResource() throws Exception
+ {
- Resource resource = new MockSimpleResource(null, "testlib", null, "notexisting.js", null, _documentRoot);
+ Resource resource = new MockSimpleResource(null, "testlib", null,
+ "notexisting.js", null, _documentRoot);
assertNull(resource.getURL());
}
- public void testGetAsStream() throws Exception {
- Resource resource = new MockSimpleResource(null, "testlib", null, "testfile.js", null, _documentRoot);
+ public void testGetAsStream() throws Exception
+ {
+ Resource resource = new MockSimpleResource(null, "testlib", null,
+ "testfile.js", null, _documentRoot);
InputStream stream = resource.getInputStream();
assertNotNull(stream);
assertTrue(stream.read() != -1);
}
- public void testCreateResource() throws Exception {
+ public void testCreateResource() throws Exception
+ {
ResourceHandler handler = new MockSimpleResourceHandler(_documentRoot);
Resource resource = handler.createResource("testfile.js", "testlib");
assertNotNull("resource could not be created", resource);
- assertTrue(resource.getURL().toString().endsWith("org/apache/myfaces/test/mock/resources/testlib/testfile.js"));
+ assertTrue(resource.getURL().toString().endsWith(
+ "org/apache/myfaces/test/mock/resources/testlib/testfile.js"));
}
- public void testResourceHandler() throws Exception {
- ResourceHandler handler = new MockSimpleResourceHandler(_documentRoot);
+ public void testResourceHandler() throws Exception
+ {
+ ResourceHandler handler = new MockSimpleResourceHandler(_documentRoot);
assertTrue(handler.libraryExists("testlib"));
assertFalse(handler.libraryExists("notexistinglib"));
- assertEquals("javax.faces.resource.Script", handler.getRendererTypeForResourceName("testfile.js"));
+ assertEquals("javax.faces.resource.Script", handler
+ .getRendererTypeForResourceName("testfile.js"));
}
}
diff --git a/test20/src/test/java/org/apache/myfaces/test/mock/MockVisitTestCase.java b/test20/src/test/java/org/apache/myfaces/test/mock/MockVisitTestCase.java
index d7555cc..21f50ab 100644
--- a/test20/src/test/java/org/apache/myfaces/test/mock/MockVisitTestCase.java
+++ b/test20/src/test/java/org/apache/myfaces/test/mock/MockVisitTestCase.java
@@ -66,11 +66,13 @@
{
FacesContext facesContext = FacesContext.getCurrentInstance();
VisitContextFactory factory = new MockVisitContextFactory();
- VisitContext visitContext = factory.getVisitContext(facesContext, null, null);
+ VisitContext visitContext = factory.getVisitContext(facesContext, null,
+ null);
VisitCallback callback = new MockVisitCallback();
UIComponent component = facesContext.getViewRoot();
- assertEquals(VisitResult.ACCEPT, visitContext.invokeVisitCallback(component, callback));
+ assertEquals(VisitResult.ACCEPT, visitContext.invokeVisitCallback(
+ component, callback));
}
}