Author: nbelaevski
Date: 2009-07-20 19:18:35 -0400 (Mon, 20 Jul 2009)
New Revision: 14969
Added:
root/framework/trunk/impl/src/test/java/org/ajax4jsf/context/
root/framework/trunk/impl/src/test/java/org/ajax4jsf/context/InitParametersTest.java
Log:
InitParametersTest added
Copied:
root/framework/trunk/impl/src/test/java/org/ajax4jsf/context/InitParametersTest.java (from
rev 14967,
root/framework/trunk/legacy-tests/src/test/java/org/ajax4jsf/context/InitParametersTest.java)
===================================================================
--- root/framework/trunk/impl/src/test/java/org/ajax4jsf/context/InitParametersTest.java
(rev 0)
+++
root/framework/trunk/impl/src/test/java/org/ajax4jsf/context/InitParametersTest.java 2009-07-20
23:18:35 UTC (rev 14969)
@@ -0,0 +1,130 @@
+/**
+ *
+ */
+package org.ajax4jsf.context;
+
+import javax.faces.FacesException;
+
+import org.ajax4jsf.application.AjaxStateManager;
+import org.richfaces.test.AbstractFacesTest;
+
+/**
+ * @author asmirnov
+ *
+ */
+public class InitParametersTest extends AbstractFacesTest {
+
+ private static final String STRING_PARAM = "init";
+ private static final int INT_PARAM = 367;
+ private static final String NO = "no";
+ private static final String TRUE = "true";
+ private static final String ORG_AJAX4JSF_STRING = "org.ajax4jsf.STRING";
+ private static final String ORG_AJAX4JSF_INT = "org.ajax4jsf.INT";
+ private static final String ORG_AJAX4JSF_FALSE = "org.ajax4jsf.FALSE";
+ private static final String ORG_AJAX4JSF_TRUE = "org.ajax4jsf.TRUE";
+
+ /* (non-Javadoc)
+ * @see org.ajax4jsf.tests.AbstractAjax4JsfTestCase#setUp()
+ */
+ public void setUp() throws Exception {
+ super.setUp();
+ setupFacesRequest();
+ }
+
+ @Override
+ protected void setupJsfInitParameters() {
+ super.setupJsfInitParameters();
+
+ facesServer.addInitParameter(ORG_AJAX4JSF_TRUE, TRUE);
+ facesServer.addInitParameter(ORG_AJAX4JSF_FALSE, NO);
+ facesServer.addInitParameter(ORG_AJAX4JSF_INT, String.valueOf(INT_PARAM));
+ facesServer.addInitParameter(ORG_AJAX4JSF_STRING, STRING_PARAM);
+ }
+
+ /* (non-Javadoc)
+ * @see org.ajax4jsf.tests.AbstractAjax4JsfTestCase#tearDown()
+ */
+ public void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ /**
+ * Test method for {@link
org.ajax4jsf.context.ContextInitParameters#getNumbersOfViewsInSession(javax.faces.context.FacesContext)}.
+ */
+ public void testGetNumbersOfViewsInSession() {
+ assertEquals(AjaxStateManager.DEFAULT_NUMBER_OF_VIEWS,
ContextInitParameters.getNumbersOfViewsInSession(facesContext));
+ }
+
+ /**
+ * Test method for {@link
org.ajax4jsf.context.ContextInitParameters#getNumbersOfLogicalViews(javax.faces.context.FacesContext)}.
+ */
+ public void testGetNumbersOfLogicalViews() {
+ assertEquals(AjaxStateManager.DEFAULT_NUMBER_OF_VIEWS,
ContextInitParameters.getNumbersOfLogicalViews(facesContext));
+ }
+
+ /**
+ * Test method for {@link
org.ajax4jsf.context.ContextInitParameters#getInteger(javax.faces.context.FacesContext,
java.lang.String[], int)}.
+ */
+ public void testGetInteger() {
+ String[] params = {"foo.bar",ORG_AJAX4JSF_INT};
+ int value = ContextInitParameters.getInteger(facesContext, params, 12);
+ assertEquals(INT_PARAM, value);
+ String[] params2 = {"foo.bar"};
+ value = ContextInitParameters.getInteger(facesContext, params2, 12);
+ assertEquals(12, value);
+ String[] params3 = {"foo.bar",ORG_AJAX4JSF_STRING};
+ try {
+ value = ContextInitParameters.getInteger(facesContext, params3, 12);
+ } catch (FacesException e) {
+ return;
+ }
+ assertFalse("No exception on invalid parameter",true);
+ }
+
+ /**
+ * Test method for {@link
org.ajax4jsf.context.ContextInitParameters#getString(javax.faces.context.FacesContext,
java.lang.String[], java.lang.String)}.
+ */
+ public void testGetString() {
+ String[] params = {"foo.bar",ORG_AJAX4JSF_STRING};
+ String value = ContextInitParameters.getString(facesContext, params, "foo");
+ assertEquals(STRING_PARAM, value);
+ String[] params2 = {"foo.bar"};
+ value = ContextInitParameters.getString(facesContext, params2, "foo");
+ assertEquals("foo", value);
+ }
+
+ /**
+ * Test method for {@link
org.ajax4jsf.context.ContextInitParameters#getBoolean(javax.faces.context.FacesContext,
java.lang.String[], boolean)}.
+ */
+ public void testGetBoolean() {
+ String[] params = {"foo.bar",ORG_AJAX4JSF_TRUE};
+ boolean value = ContextInitParameters.getBoolean(facesContext, params, false);
+ assertTrue(value);
+ String[] params2 = {"foo.bar"};
+ value = ContextInitParameters.getBoolean(facesContext, params2, true);
+ assertTrue(value);
+ String[] params3 = {"foo.bar",ORG_AJAX4JSF_FALSE};
+ value = ContextInitParameters.getBoolean(facesContext, params3, true);
+ assertFalse(value);
+ String[] params4 = {"foo.bar",ORG_AJAX4JSF_STRING};
+ try {
+ value = ContextInitParameters.getBoolean(facesContext, params4, false);
+ } catch (FacesException e) {
+ return;
+ }
+ assertFalse("No exception on invalid parameter",true);
+ }
+
+ /**
+ * Test method for {@link
org.ajax4jsf.context.ContextInitParameters#getInitParameter(javax.faces.context.FacesContext,
java.lang.String[])}.
+ */
+ public void testGetInitParameter() {
+ String[] params = {"foo.bar",ORG_AJAX4JSF_STRING};
+ String value = ContextInitParameters.getInitParameter(facesContext, params);
+ assertEquals(STRING_PARAM, value);
+ String[] params2 = {"foo.bar"};
+ value = ContextInitParameters.getInitParameter(facesContext, params2);
+ assertNull(value);
+ }
+
+}