Author: alexsmirnov
Date: 2007-04-13 21:46:02 -0400 (Fri, 13 Apr 2007)
New Revision: 86
Added:
trunk/a4j-portlet/src/test/java/org/ajax4jsf/portlet/context/ContextAttributesMapTest.java
trunk/a4j-portlet/src/test/java/org/ajax4jsf/portlet/context/PortletExternalContextTest.java
Modified:
trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/context/FacesContextFactoryImpl.java
trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/context/PortletContextImpl.java
trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/context/ServletContextImpl.java
trunk/a4j-portlet/src/test/java/org/ajax4jsf/portlet/MockPortletRequest.java
trunk/a4j-portlet/src/test/java/org/ajax4jsf/portlet/context/FacesContextImplTest.java
Log:
Continue contexts testing.
Modified:
trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/context/FacesContextFactoryImpl.java
===================================================================
---
trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/context/FacesContextFactoryImpl.java 2007-04-14
00:39:00 UTC (rev 85)
+++
trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/context/FacesContextFactoryImpl.java 2007-04-14
01:46:02 UTC (rev 86)
@@ -126,11 +126,11 @@
if ((context instanceof PortletContext)
&& (request instanceof PortletRequest)
&& (response instanceof PortletResponse)) {
- externalContext = new PortletContextImpl(context, request, response);
+ externalContext = new PortletContextImpl((PortletContext)context,
(PortletRequest)request, (PortletResponse)response);
} else if ((context instanceof ServletContext)
&& (request instanceof HttpServletRequest)
&& (response instanceof HttpServletResponse)) {
- externalContext = new ServletContextImpl(context, request, response);
+ externalContext = new ServletContextImpl((ServletContext)context,
(HttpServletRequest)request, (HttpServletResponse)response);
} else {
throw new FacesException(
"Unsupported environment. Only servlet or portlet is allowed");
Modified:
trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/context/PortletContextImpl.java
===================================================================
---
trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/context/PortletContextImpl.java 2007-04-14
00:39:00 UTC (rev 85)
+++
trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/context/PortletContextImpl.java 2007-04-14
01:46:02 UTC (rev 86)
@@ -31,7 +31,7 @@
*
*/
public class PortletContextImpl extends AbstractExternalContext {
- public PortletContextImpl(Object context, Object request, Object response) {
+ public PortletContextImpl(PortletContext context, PortletRequest request,
PortletResponse response) {
super(context, request, response);
}
Modified:
trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/context/ServletContextImpl.java
===================================================================
---
trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/context/ServletContextImpl.java 2007-04-14
00:39:00 UTC (rev 85)
+++
trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/context/ServletContextImpl.java 2007-04-14
01:46:02 UTC (rev 86)
@@ -34,7 +34,7 @@
* @param request
* @param response
*/
- public ServletContextImpl(Object context, Object request, Object response) {
+ public ServletContextImpl(ServletContext context, HttpServletRequest request,
HttpServletResponse response) {
super(context, request, response);
}
Modified: trunk/a4j-portlet/src/test/java/org/ajax4jsf/portlet/MockPortletRequest.java
===================================================================
---
trunk/a4j-portlet/src/test/java/org/ajax4jsf/portlet/MockPortletRequest.java 2007-04-14
00:39:00 UTC (rev 85)
+++
trunk/a4j-portlet/src/test/java/org/ajax4jsf/portlet/MockPortletRequest.java 2007-04-14
01:46:02 UTC (rev 86)
@@ -4,7 +4,10 @@
package org.ajax4jsf.portlet;
import java.security.Principal;
+import java.util.Collection;
+import java.util.Collections;
import java.util.Enumeration;
+import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import javax.portlet.PortalContext;
@@ -19,6 +22,15 @@
*
*/
public class MockPortletRequest implements PortletRequest {
+
+ public static final String PARAMETER_VALUE2 = "value2";
+ public static final String PARAMETER_VALUE1 = "value1";
+ public static final String PARAMETER = "paremeter";
+ public Map parameters = new HashMap();
+
+ public MockPortletRequest() {
+ parameters.put(PARAMETER, new String[]{PARAMETER_VALUE1,PARAMETER_VALUE2});
+ }
/* (non-Javadoc)
* @see javax.portlet.PortletRequest#getAttribute(java.lang.String)
*/
@@ -67,36 +79,38 @@
return null;
}
+
/* (non-Javadoc)
* @see javax.portlet.PortletRequest#getParameter(java.lang.String)
*/
- public String getParameter(String arg0) {
- // TODO Auto-generated method stub
- return null;
+ public String getParameter(String name) {
+ String result = null;
+ String[] vals = (String[]) parameters.get(name);
+ if(null != vals){
+ result = vals[0];
+ }
+ return result;
}
/* (non-Javadoc)
* @see javax.portlet.PortletRequest#getParameterMap()
*/
public Map getParameterMap() {
- // TODO Auto-generated method stub
- return null;
+ return parameters;
}
/* (non-Javadoc)
* @see javax.portlet.PortletRequest#getParameterNames()
*/
public Enumeration getParameterNames() {
- // TODO Auto-generated method stub
- return null;
+ return Collections.enumeration(Collections.singleton(PARAMETER));
}
/* (non-Javadoc)
* @see javax.portlet.PortletRequest#getParameterValues(java.lang.String)
*/
public String[] getParameterValues(String arg0) {
- // TODO Auto-generated method stub
- return null;
+ return (String[]) parameters.get(arg0);
}
/* (non-Javadoc)
Added:
trunk/a4j-portlet/src/test/java/org/ajax4jsf/portlet/context/ContextAttributesMapTest.java
===================================================================
---
trunk/a4j-portlet/src/test/java/org/ajax4jsf/portlet/context/ContextAttributesMapTest.java
(rev 0)
+++
trunk/a4j-portlet/src/test/java/org/ajax4jsf/portlet/context/ContextAttributesMapTest.java 2007-04-14
01:46:02 UTC (rev 86)
@@ -0,0 +1,100 @@
+/**
+ *
+ */
+package org.ajax4jsf.portlet.context;
+
+import java.util.HashMap;
+import java.util.Map;
+import junit.framework.TestCase;
+
+/**
+ * @author asmirnov
+ *
+ */
+public class ContextAttributesMapTest extends TestCase {
+
+ private Map backend = new HashMap();
+ /**
+ * @param name
+ */
+ public ContextAttributesMapTest(String name) {
+ super(name);
+ }
+
+ /* (non-Javadoc)
+ * @see junit.framework.TestCase#setUp()
+ */
+ protected void setUp() throws Exception {
+ super.setUp();
+ }
+
+ /* (non-Javadoc)
+ * @see junit.framework.TestCase#tearDown()
+ */
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ /**
+ * Test method for {@link
org.ajax4jsf.portlet.context.ContextAttributesMap#remove(java.lang.Object)}.
+ */
+ public final void testRemoveObject() {
+ fail("Not yet implemented");
+ }
+
+ /**
+ * Test method for {@link
org.ajax4jsf.portlet.context.ContextAttributesMap#get(java.lang.Object)}.
+ */
+ public final void testGetObject() {
+ fail("Not yet implemented");
+ }
+
+ /**
+ * Test method for {@link
org.ajax4jsf.portlet.context.ContextAttributesMap#put(java.lang.Object,
java.lang.Object)}.
+ */
+ public final void testPutObjectObject() {
+ fail("Not yet implemented");
+ }
+
+ /**
+ * Test method for {@link org.ajax4jsf.portlet.context.ContextMap#clear()}.
+ */
+ public final void testClear() {
+ fail("Not yet implemented");
+ }
+
+ /**
+ * Test method for {@link org.ajax4jsf.portlet.context.ContextMap#entrySet()}.
+ */
+ public final void testEntrySet() {
+ fail("Not yet implemented");
+ }
+
+ /**
+ * Test method for {@link org.ajax4jsf.portlet.context.ContextMap#keySet()}.
+ */
+ public final void testKeySet() {
+ fail("Not yet implemented");
+ }
+
+ /**
+ * Test method for {@link org.ajax4jsf.portlet.context.ContextMap#values()}.
+ */
+ public final void testValues() {
+ fail("Not yet implemented");
+ }
+
+ /**
+ * Test method for {@link java.util.AbstractMap#containsValue(java.lang.Object)}.
+ */
+ public final void testContainsValue() {
+ fail("Not yet implemented");
+ }
+
+ /**
+ * Test method for {@link java.util.AbstractMap#containsKey(java.lang.Object)}.
+ */
+ public final void testContainsKey() {
+ fail("Not yet implemented");
+ }
+}
Modified:
trunk/a4j-portlet/src/test/java/org/ajax4jsf/portlet/context/FacesContextImplTest.java
===================================================================
---
trunk/a4j-portlet/src/test/java/org/ajax4jsf/portlet/context/FacesContextImplTest.java 2007-04-14
00:39:00 UTC (rev 85)
+++
trunk/a4j-portlet/src/test/java/org/ajax4jsf/portlet/context/FacesContextImplTest.java 2007-04-14
01:46:02 UTC (rev 86)
@@ -3,7 +3,10 @@
*/
package org.ajax4jsf.portlet.context;
+import java.util.Iterator;
import javax.el.ELContext;
+import javax.faces.application.FacesMessage;
+import javax.faces.application.FacesMessage.Severity;
import javax.faces.context.FacesContext;
import org.ajax4jsf.tests.AbstractAjax4JsfTestCase;
@@ -12,6 +15,7 @@
*
*/
public class FacesContextImplTest extends AbstractAjax4JsfTestCase {
+ private static final String ID0 = "_id0";
protected FacesContextImpl portalFacesContext;
protected ServletContextImpl servletContextImpl;
@@ -86,41 +90,65 @@
* Test method for {@link
org.ajax4jsf.portlet.context.FacesContextImpl#getApplication()}.
*/
public void testGetApplication() {
- fail("Not yet implemented");
+ assertSame(application,portalFacesContext.getApplication());
}
/**
* Test method for {@link
org.ajax4jsf.portlet.context.FacesContextImpl#getClientIdsWithMessages()}.
*/
public void testGetClientIdsWithMessages() {
- fail("Not yet implemented");
+ portalFacesContext.addMessage(ID0, new FacesMessage());
+ Iterator clientIdsWithMessages = portalFacesContext.getClientIdsWithMessages();
+ assertTrue(clientIdsWithMessages.hasNext());
+ assertEquals(ID0, clientIdsWithMessages.next());
+ assertFalse(clientIdsWithMessages.hasNext());
}
/**
* Test method for {@link
org.ajax4jsf.portlet.context.FacesContextImpl#getMaximumSeverity()}.
*/
public void testGetMaximumSeverity() {
- fail("Not yet implemented");
+ assertNull(portalFacesContext.getMaximumSeverity());
+ portalFacesContext.addMessage(ID0, new FacesMessage());
+ Severity maximumSeverity = portalFacesContext.getMaximumSeverity();
+ assertEquals(0,maximumSeverity.compareTo(FacesMessage.SEVERITY_INFO));
+ portalFacesContext.addMessage("_id1", new
FacesMessage(FacesMessage.SEVERITY_ERROR,"error","error detail"));
+ maximumSeverity = portalFacesContext.getMaximumSeverity();
+ assertEquals(0,maximumSeverity.compareTo(FacesMessage.SEVERITY_ERROR));
}
/**
* Test method for {@link
org.ajax4jsf.portlet.context.FacesContextImpl#getMessages()}.
*/
public void testGetMessages() {
- fail("Not yet implemented");
+ FacesMessage facesMessage = new FacesMessage();
+ portalFacesContext.addMessage(ID0, facesMessage);
+ Iterator messages = portalFacesContext.getMessages();
+ assertTrue(messages.hasNext());
+ assertSame(facesMessage, messages.next());
+ assertFalse(messages.hasNext());
}
/**
* Test method for {@link
org.ajax4jsf.portlet.context.FacesContextImpl#getMessages(java.lang.String)}.
*/
public void testGetMessagesString() {
- fail("Not yet implemented");
+ FacesMessage facesMessage = new FacesMessage();
+ portalFacesContext.addMessage(ID0, facesMessage);
+ portalFacesContext.addMessage("_id1", new FacesMessage());
+ Iterator messages = portalFacesContext.getMessages(ID0);
+ assertTrue(messages.hasNext());
+ assertSame(facesMessage, messages.next());
+ assertFalse(messages.hasNext());
}
/**
* Test method for {@link
org.ajax4jsf.portlet.context.FacesContextImpl#getRenderKit()}.
*/
public void testGetRenderKit() {
- fail("Not yet implemented");
+ portalFacesContext.setViewRoot(null);
+ assertNull(portalFacesContext.getRenderKit());
+ portalFacesContext.setViewRoot(facesContext.getViewRoot());
+ assertSame(renderKit, portalFacesContext.getRenderKit());
}
}
Added:
trunk/a4j-portlet/src/test/java/org/ajax4jsf/portlet/context/PortletExternalContextTest.java
===================================================================
---
trunk/a4j-portlet/src/test/java/org/ajax4jsf/portlet/context/PortletExternalContextTest.java
(rev 0)
+++
trunk/a4j-portlet/src/test/java/org/ajax4jsf/portlet/context/PortletExternalContextTest.java 2007-04-14
01:46:02 UTC (rev 86)
@@ -0,0 +1,159 @@
+/**
+ *
+ */
+package org.ajax4jsf.portlet.context;
+
+import javax.portlet.PortletResponse;
+import org.ajax4jsf.portlet.MockActionRequest;
+import org.ajax4jsf.portlet.MockActionResponse;
+import org.ajax4jsf.portlet.MockPortletContext;
+import org.ajax4jsf.tests.AbstractAjax4JsfTestCase;
+
+/**
+ * @author asmirnov
+ *
+ */
+public class PortletExternalContextTest extends AbstractAjax4JsfTestCase {
+ private PortletContextImpl portletContextImpl;
+ private FacesContextImpl portalFacesContext;
+ private MockPortletContext portletContext;
+ private MockActionRequest portletRequest;
+ private MockActionResponse portletResponse;
+
+ /**
+ * @param arg0
+ */
+ public PortletExternalContextTest(String arg0) {
+ super(arg0);
+ }
+
+ /* (non-Javadoc)
+ * @see org.ajax4jsf.tests.AbstractAjax4JsfTestCase#setUp()
+ */
+ public void setUp() throws Exception {
+ super.setUp();
+ portletContext=new MockPortletContext();
+ portletRequest = new MockActionRequest();
+ portletResponse = new MockActionResponse();
+ portletContextImpl = new
PortletContextImpl(portletContext,portletRequest,portletResponse);
+ portalFacesContext = new FacesContextImpl(portletContextImpl,lifecycle);
+ portalFacesContext.setViewRoot(facesContext.getViewRoot());
+ }
+
+ /* (non-Javadoc)
+ * @see org.ajax4jsf.tests.AbstractAjax4JsfTestCase#tearDown()
+ */
+ public void tearDown() throws Exception {
+ super.tearDown();
+ portletContextImpl = null;
+ portalFacesContext = null;
+ portletContext = null;
+ portletRequest = null;
+ portletResponse = null;
+ }
+
+ /**
+ * Test method for {@link
org.ajax4jsf.portlet.context.PortletContextImpl#getRequestParameterValuesMap()}.
+ */
+ public final void testGetRequestParameterValuesMap() {
+ fail("Not yet implemented");
+ }
+
+ /**
+ * Test method for {@link
org.ajax4jsf.portlet.context.PortletContextImpl#getInitParameter(java.lang.String)}.
+ */
+ public final void testGetInitParameterString() {
+ fail("Not yet implemented");
+ }
+
+ /**
+ * Test method for {@link
org.ajax4jsf.portlet.context.PortletContextImpl#getRequestLocales()}.
+ */
+ public final void testGetRequestLocales() {
+ fail("Not yet implemented");
+ }
+
+ /**
+ * Test method for {@link
org.ajax4jsf.portlet.context.PortletContextImpl#getSession(boolean)}.
+ */
+ public final void testGetSessionBoolean() {
+ fail("Not yet implemented");
+ }
+
+ /**
+ * Test method for {@link
org.ajax4jsf.portlet.context.AbstractExternalContext#getApplicationMap()}.
+ */
+ public final void testGetApplicationMap() {
+ fail("Not yet implemented");
+ }
+
+ /**
+ * Test method for {@link
org.ajax4jsf.portlet.context.AbstractExternalContext#getInitParameterMap()}.
+ */
+ public final void testGetInitParameterMap() {
+ fail("Not yet implemented");
+ }
+
+ /**
+ * Test method for {@link
org.ajax4jsf.portlet.context.AbstractExternalContext#setRequest(java.lang.Object)}.
+ */
+ public final void testSetRequestObject() {
+ fail("Not yet implemented");
+ }
+
+ /**
+ * Test method for {@link
org.ajax4jsf.portlet.context.AbstractExternalContext#getRequestCookieMap()}.
+ */
+ public final void testGetRequestCookieMap() {
+ fail("Not yet implemented");
+ }
+
+ /**
+ * Test method for {@link
org.ajax4jsf.portlet.context.AbstractExternalContext#getRequestHeaderMap()}.
+ */
+ public final void testGetRequestHeaderMap() {
+ fail("Not yet implemented");
+ }
+
+ /**
+ * Test method for {@link
org.ajax4jsf.portlet.context.AbstractExternalContext#getRequestHeaderValuesMap()}.
+ */
+ public final void testGetRequestHeaderValuesMap() {
+ fail("Not yet implemented");
+ }
+
+ /**
+ * Test method for {@link
org.ajax4jsf.portlet.context.AbstractExternalContext#getRequestMap()}.
+ */
+ public final void testGetRequestMap() {
+ fail("Not yet implemented");
+ }
+
+ /**
+ * Test method for {@link
org.ajax4jsf.portlet.context.AbstractExternalContext#getRequestParameterMap()}.
+ */
+ public final void testGetRequestParameterMap() {
+ fail("Not yet implemented");
+ }
+
+ /**
+ * Test method for {@link
org.ajax4jsf.portlet.context.AbstractExternalContext#getRequestParameterNames()}.
+ */
+ public final void testGetRequestParameterNames() {
+ fail("Not yet implemented");
+ }
+
+ /**
+ * Test method for {@link
org.ajax4jsf.portlet.context.AbstractExternalContext#setResponse(java.lang.Object)}.
+ */
+ public final void testSetResponseObject() {
+ fail("Not yet implemented");
+ }
+
+ /**
+ * Test method for {@link
org.ajax4jsf.portlet.context.AbstractExternalContext#getSessionMap()}.
+ */
+ public final void testGetSessionMap() {
+ fail("Not yet implemented");
+ }
+}