Author: alexsmirnov
Date: 2007-10-22 20:15:54 -0400 (Mon, 22 Oct 2007)
New Revision: 3477
Added:
trunk/extensions/portlet/src/test/java/javax/
trunk/extensions/portlet/src/test/java/javax/portlet/
trunk/extensions/portlet/src/test/java/javax/portlet/faces/
trunk/extensions/portlet/src/test/java/javax/portlet/faces/GenericPortletTest.java
trunk/extensions/portlet/src/test/java/javax/portlet/faces/MockBridge.java
trunk/extensions/portlet/src/test/java/org/ajax4jsf/portlet/IteratorEnumeration.java
trunk/extensions/portlet/src/test/java/org/ajax4jsf/portlet/MockPortletConfig.java
trunk/extensions/portlet/src/test/resources/
Modified:
trunk/extensions/portlet/src/main/java/javax/portlet/faces/GenericFacesPortlet.java
trunk/extensions/portlet/src/test/java/org/ajax4jsf/portlet/AbstractAjax4jsfPortletTestCase.java
trunk/extensions/portlet/src/test/java/org/ajax4jsf/portlet/MockPortletContext.java
trunk/extensions/portlet/src/test/java/org/ajax4jsf/portlet/MockPortletRequest.java
Log:
Create jUnit tests for a GenericFacesServlet
Modified:
trunk/extensions/portlet/src/main/java/javax/portlet/faces/GenericFacesPortlet.java
===================================================================
---
trunk/extensions/portlet/src/main/java/javax/portlet/faces/GenericFacesPortlet.java 2007-10-23
00:15:11 UTC (rev 3476)
+++
trunk/extensions/portlet/src/main/java/javax/portlet/faces/GenericFacesPortlet.java 2007-10-23
00:15:54 UTC (rev 3477)
@@ -42,6 +42,42 @@
super.init(config);
bridgeClassName = this.getPortletContext().getInitParameter(
BRIDGE_CLASS);
+ if (bridgeClassName == null) {
+ ClassLoader loader = getClassLoader();
+ InputStream stream = loader
+ .getResourceAsStream(BRIDGE_SERVICE_CLASSPATH);
+ if (null != stream) {
+ try {
+ BufferedReader reader = null;
+ try {
+ reader = new BufferedReader(new InputStreamReader(
+ stream, "UTF-8"));
+ } catch (UnsupportedEncodingException e) {
+ reader = new BufferedReader(new InputStreamReader(
+ stream));
+ }
+ bridgeClassName = reader.readLine();
+ if (null != bridgeClassName) {
+ bridgeClassName.trim();
+ }
+ } catch (IOException e) {
+ // Ignore
+ } catch (SecurityException e) {
+ // Ignore
+ } finally {
+ if (null != stream) {
+ try {
+ stream.close();
+ } catch (IOException e) {
+ // Ignore
+ }
+ }
+ }
+ }
+ }
+ if (null == bridgeClassName) {
+ bridgeClassName = DEFAULT_BRIDGE_CLASS;
+ }
String renderPolicy =
this.getPortletConfig().getInitParameter(Bridge.BRIDGE_PACKAGE_PREFIX +
Bridge.RENDER_POLICY);
if (renderPolicy != null)
@@ -120,42 +156,6 @@
* @return
*/
public String getBrigeClassName() {
- if (bridgeClassName == null) {
- ClassLoader loader = getClassLoader();
- InputStream stream = loader
- .getResourceAsStream(BRIDGE_SERVICE_CLASSPATH);
- if (null != stream) {
- try {
- BufferedReader reader = null;
- try {
- reader = new BufferedReader(new InputStreamReader(
- stream, "UTF-8"));
- } catch (UnsupportedEncodingException e) {
- reader = new BufferedReader(new InputStreamReader(
- stream));
- }
- bridgeClassName = reader.readLine();
- if (null != bridgeClassName) {
- bridgeClassName.trim();
- }
- } catch (IOException e) {
- // Ignore
- } catch (SecurityException e) {
- // Ignore
- } finally {
- if (null != stream) {
- try {
- stream.close();
- } catch (IOException e) {
- // Ignore
- }
- }
- }
- }
- }
- if (null == bridgeClassName) {
- bridgeClassName = DEFAULT_BRIDGE_CLASS;
- }
return bridgeClassName;
}
Added: trunk/extensions/portlet/src/test/java/javax/portlet/faces/GenericPortletTest.java
===================================================================
--- trunk/extensions/portlet/src/test/java/javax/portlet/faces/GenericPortletTest.java
(rev 0)
+++
trunk/extensions/portlet/src/test/java/javax/portlet/faces/GenericPortletTest.java 2007-10-23
00:15:54 UTC (rev 3477)
@@ -0,0 +1,346 @@
+/**
+ *
+ */
+package javax.portlet.faces;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URLClassLoader;
+
+import javax.portlet.PortletException;
+import javax.portlet.PortletMode;
+import javax.portlet.RenderRequest;
+import javax.portlet.RenderResponse;
+
+import org.ajax4jsf.portlet.AbstractAjax4jsfPortletTestCase;
+import org.ajax4jsf.portlet.AjaxFacesPortlet;
+
+import junit.framework.TestCase;
+
+/**
+ * @author asmirnov
+ *
+ */
+public class GenericPortletTest extends AbstractAjax4jsfPortletTestCase {
+
+ private final class GenericFacesPortletExtension extends
+ GenericFacesPortlet {
+ boolean editProcessed = false;
+ boolean viewProcessed = false;
+ boolean helpProcessed = false;
+
+ @Override
+ protected void doEdit(RenderRequest request, RenderResponse response)
+ throws PortletException, IOException {
+ editProcessed = true;
+ }
+
+ @Override
+ protected void doView(RenderRequest request, RenderResponse response)
+ throws PortletException, IOException {
+ viewProcessed = true;
+ }
+
+ @Override
+ protected void doHelp(RenderRequest request, RenderResponse response)
+ throws PortletException, IOException {
+ helpProcessed = true;
+ }
+ }
+
+ /**
+ * @param name
+ */
+ public GenericPortletTest(String name) {
+ super(name);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see junit.framework.TestCase#setUp()
+ */
+ public void setUp() throws Exception {
+ super.setUp();
+ MockBridge.actionCount = 0;
+ MockBridge.destroyCount = 0;
+ MockBridge.initCount = 0;
+ MockBridge.responseCount = 0;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see junit.framework.TestCase#tearDown()
+ */
+ public void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ /**
+ * Test method for {@link javax.portlet.faces.GenericFacesPortlet#destroy()}.
+ *
+ * @throws PortletException
+ * @throws IOException
+ */
+ public void testDestroy() throws PortletException, IOException {
+ setupActionRequest();
+ GenericFacesPortlet portlet = new GenericFacesPortlet();
+ portletContext.setInitParameter("javax.portlet.faces.BridgeClassName",
+ MockBridge.class.getName());
+ portlet.init(portletConfig);
+ MockBridge facesPortletBrige = (MockBridge) portlet
+ .getFacesPortletBrige();
+ assertEquals(true, facesPortletBrige.isInitialized());
+ assertEquals(1, MockBridge.initCount);
+ portlet.destroy();
+ assertEquals(1, MockBridge.destroyCount);
+ assertEquals(false, facesPortletBrige.isInitialized());
+
+ }
+
+ /**
+ * Test method for
+ * {@link javax.portlet.faces.GenericFacesPortlet#init(javax.portlet.PortletConfig)}.
+ *
+ * @throws PortletException
+ */
+ public void testInitPortletConfig() throws PortletException {
+ portletConfig.addInitParameter(
+ "javax.portlet.faces.preserveActionParams", "true");
+ portletConfig.addInitParameter("javax.portlet.faces.renderPolicy",
+ Bridge.BridgeRenderPolicy.NEVER_DELEGATE.toString());
+ portletConfig.setPortletName("foo");
+ GenericFacesPortlet portlet = new GenericFacesPortlet();
+ portlet.init(portletConfig);
+ assertEquals(AjaxFacesPortlet.class.getName(), portlet
+ .getBrigeClassName());
+ assertEquals(Boolean.TRUE, portletContext
+ .getAttribute("javax.portlet.faces.foo.preserveActionParams"));
+ assertEquals(Bridge.BridgeRenderPolicy.NEVER_DELEGATE, portletContext
+ .getAttribute("javax.portlet.faces.foo.renderPolicy"));
+ }
+
+ /**
+ * Test method for
+ * {@link
javax.portlet.faces.GenericFacesPortlet#doDispatch(javax.portlet.RenderRequest,
javax.portlet.RenderResponse)}.
+ * @throws PortletException
+ * @throws IOException
+ */
+ public void testDoDispatchRenderRequestRenderResponse() throws PortletException,
IOException {
+ setupRenderRequest();
+ GenericFacesPortletExtension portlet = new GenericFacesPortletExtension();
+ portletContext.setInitParameter("javax.portlet.faces.BridgeClassName",
+ MockBridge.class.getName());
+ portletConfig.addInitParameter(
+ "javax.portlet.faces.defaultViewId.view", "index.jsf");
+ portlet.init(portletConfig);
+ portlet.doDispatch(renderRequest, renderResponse);
+ assertEquals(0, MockBridge.responseCount);
+ assertFalse(portlet.helpProcessed);
+ assertFalse(portlet.editProcessed);
+ assertTrue(portlet.viewProcessed);
+ }
+
+ /**
+ * Test method for
+ * {@link
javax.portlet.faces.GenericFacesPortlet#doDispatch(javax.portlet.RenderRequest,
javax.portlet.RenderResponse)}.
+ * @throws PortletException
+ * @throws IOException
+ */
+ public void testDoDispatchRenderRequestRenderResponseEdit() throws PortletException,
IOException {
+ setupRenderRequest();
+ GenericFacesPortletExtension portlet = new GenericFacesPortletExtension();
+ portletContext.setInitParameter("javax.portlet.faces.BridgeClassName",
+ MockBridge.class.getName());
+ portletConfig.addInitParameter(
+ "javax.portlet.faces.defaultViewId.edit", "index.jsf");
+ renderRequest.mode = PortletMode.EDIT;
+ portlet.init(portletConfig);
+ portlet.doDispatch(renderRequest, renderResponse);
+ assertEquals(0, MockBridge.responseCount);
+ assertFalse(portlet.helpProcessed);
+ assertTrue(portlet.editProcessed);
+ assertFalse(portlet.viewProcessed);
+ }
+ /**
+ * Test method for
+ * {@link
javax.portlet.faces.GenericFacesPortlet#doDispatch(javax.portlet.RenderRequest,
javax.portlet.RenderResponse)}.
+ * @throws PortletException
+ * @throws IOException
+ */
+ public void testDoDispatchRenderRequestRenderResponseHelp() throws PortletException,
IOException {
+ setupRenderRequest();
+ GenericFacesPortletExtension portlet = new GenericFacesPortletExtension();
+ portletContext.setInitParameter("javax.portlet.faces.BridgeClassName",
+ MockBridge.class.getName());
+ portletConfig.addInitParameter(
+ "javax.portlet.faces.defaultViewId.view", "index.jsf");
+ renderRequest.mode = PortletMode.HELP;
+ portlet.init(portletConfig);
+ portlet.doDispatch(renderRequest, renderResponse);
+ assertEquals(0, MockBridge.responseCount);
+ assertTrue(portlet.helpProcessed);
+ assertFalse(portlet.editProcessed);
+ assertFalse(portlet.viewProcessed);
+ }
+ /**
+ * Test method for
+ * {@link javax.portlet.faces.GenericFacesPortlet#doEdit(javax.portlet.RenderRequest,
javax.portlet.RenderResponse)}.
+ * @throws IOException
+ * @throws PortletException
+ */
+ public void testDoEditRenderRequestRenderResponse() throws PortletException, IOException
{
+ setupRenderRequest();
+ GenericFacesPortlet portlet = new GenericFacesPortlet();
+ portletContext.setInitParameter("javax.portlet.faces.BridgeClassName",
+ MockBridge.class.getName());
+ portletConfig.addInitParameter(
+ "javax.portlet.faces.defaultViewId.view", "index.jsf");
+ renderRequest.mode = PortletMode.EDIT;
+ portlet.init(portletConfig);
+ portlet.doDispatch(renderRequest, renderResponse);
+ assertEquals(0, MockBridge.responseCount);
+ }
+
+ /**
+ * Test method for
+ * {@link javax.portlet.faces.GenericFacesPortlet#doHelp(javax.portlet.RenderRequest,
javax.portlet.RenderResponse)}.
+ */
+ public void testDoHelpRenderRequestRenderResponse() {
+ // fail("Not yet implemented");
+ }
+
+ /**
+ * Test method for
+ * {@link javax.portlet.faces.GenericFacesPortlet#doView(javax.portlet.RenderRequest,
javax.portlet.RenderResponse)}.
+ * @throws PortletException
+ * @throws IOException
+ */
+ public void testDoViewRenderRequestRenderResponse() throws PortletException, IOException
{
+ setupRenderRequest();
+ GenericFacesPortlet portlet = new GenericFacesPortlet();
+ portletContext.setInitParameter("javax.portlet.faces.BridgeClassName",
+ MockBridge.class.getName());
+ portletConfig.addInitParameter(
+ "javax.portlet.faces.defaultViewId.view", "index.jsf");
+ portlet.init(portletConfig);
+ portlet.doDispatch(renderRequest, renderResponse);
+ assertEquals(1, MockBridge.responseCount);
+ }
+
+ /**
+ * Test method for
+ * {@link
javax.portlet.faces.GenericFacesPortlet#processAction(javax.portlet.ActionRequest,
javax.portlet.ActionResponse)}.
+ *
+ * @throws PortletException
+ * @throws IOException
+ */
+ public void testProcessActionActionRequestActionResponse()
+ throws PortletException, IOException {
+ setupActionRequest();
+ GenericFacesPortlet portlet = new GenericFacesPortlet();
+ portletContext.setInitParameter("javax.portlet.faces.BridgeClassName",
+ MockBridge.class.getName());
+ portletConfig.addInitParameter(
+ "javax.portlet.faces.defaultViewId.view", "index.jsf");
+ portlet.init(portletConfig);
+ portlet.processAction(actionRequest, actionResponse);
+ assertEquals(1, MockBridge.actionCount);
+ }
+
+ /**
+ * Test method for
+ * {@link javax.portlet.faces.GenericFacesPortlet#getBrigeClassName()}.
+ *
+ * @throws PortletException
+ */
+ public void testGetBrigeClassName() throws PortletException {
+ setupActionRequest();
+ GenericFacesPortlet portlet = new GenericFacesPortlet();
+ portletContext.setInitParameter("javax.portlet.faces.BridgeClassName",
+ MockBridge.class.getName());
+ portletContext.setInitParameter(
+ "javax.portlet.faces.defaultViewId.view", "index.jsf");
+ portlet.init(portletConfig);
+ assertEquals(MockBridge.class.getName(), portlet.getBrigeClassName());
+ }
+
+ /**
+ * Test method for
+ * {@link javax.portlet.faces.GenericFacesPortlet#getBrigeClassName()}.
+ *
+ * @throws PortletException
+ */
+ public void testGetBrigeClassName1() throws PortletException {
+ setupActionRequest();
+ GenericFacesPortlet portlet = new GenericFacesPortlet();
+ portlet.init(portletConfig);
+ assertEquals(AjaxFacesPortlet.class.getName(), portlet
+ .getBrigeClassName());
+ }
+
+ /**
+ * Test method for
+ * {@link javax.portlet.faces.GenericFacesPortlet#getBrigeClassName()}.
+ *
+ * @throws PortletException
+ */
+ public void testGetBrigeClassName2() throws PortletException {
+ ClassLoader loader = Thread.currentThread().getContextClassLoader();
+ ClassLoader testLoader = new ClassLoader(loader) {
+ @Override
+ public InputStream getResourceAsStream(String name) {
+ if ("META-INF/services/javax.portlet.faces.Bridge".equals(name)) {
+ return new ByteArrayInputStream("foo.bar.Bridge".getBytes());
+ }
+ return super.getResourceAsStream(name);
+ }
+ };
+ try {
+ Thread.currentThread().setContextClassLoader(testLoader);
+ setupActionRequest();
+ GenericFacesPortlet portlet = new GenericFacesPortlet();
+ portlet.init(portletConfig);
+ assertEquals("foo.bar.Bridge", portlet.getBrigeClassName());
+
+ } finally {
+ Thread.currentThread().setContextClassLoader(loader);
+ }
+ }
+
+ /**
+ * Test method for
+ * {@link
javax.portlet.faces.GenericFacesPortlet#getDefaultViewId(javax.portlet.PortletRequest,
javax.portlet.PortletMode)}.
+ * @throws PortletException
+ */
+ public void testGetDefaultViewId() throws PortletException {
+ setupActionRequest();
+ GenericFacesPortlet portlet = new GenericFacesPortlet();
+ portletContext.setInitParameter("javax.portlet.faces.BridgeClassName",
+ MockBridge.class.getName());
+ portletConfig.addInitParameter(
+ "javax.portlet.faces.defaultViewId.view", "index.jsf");
+ portlet.init(portletConfig);
+ assertEquals("index.jsf", portlet.getDefaultViewId(actionRequest,
actionRequest.getPortletMode()));
+ }
+
+ /**
+ * Test method for
+ * {@link javax.portlet.faces.GenericFacesPortlet#getFacesPortletBrige()}.
+ *
+ * @throws PortletException
+ */
+ public void testGetFacesPortletBrige() throws PortletException {
+ setupActionRequest();
+ GenericFacesPortlet portlet = new GenericFacesPortlet();
+ portletContext.setInitParameter("javax.portlet.faces.BridgeClassName",
+ MockBridge.class.getName());
+ portlet.init(portletConfig);
+ MockBridge facesPortletBrige = (MockBridge) portlet
+ .getFacesPortletBrige();
+ assertEquals(true, facesPortletBrige.isInitialized());
+ }
+
+}
Property changes on:
trunk/extensions/portlet/src/test/java/javax/portlet/faces/GenericPortletTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Date Revision Author
Added: trunk/extensions/portlet/src/test/java/javax/portlet/faces/MockBridge.java
===================================================================
--- trunk/extensions/portlet/src/test/java/javax/portlet/faces/MockBridge.java
(rev 0)
+++ trunk/extensions/portlet/src/test/java/javax/portlet/faces/MockBridge.java 2007-10-23
00:15:54 UTC (rev 3477)
@@ -0,0 +1,107 @@
+/**
+ *
+ */
+package javax.portlet.faces;
+
+import javax.portlet.ActionRequest;
+import javax.portlet.ActionResponse;
+import javax.portlet.PortletConfig;
+import javax.portlet.PortletException;
+import javax.portlet.RenderRequest;
+import javax.portlet.RenderResponse;
+
+/**
+ * @author asmirnov
+ *
+ */
+public class MockBridge implements Bridge {
+
+ private boolean initialized = false;
+ private boolean actionProcessed = false;
+ private boolean responseProcessed = false;
+
+ static int initCount = 0;
+ static int actionCount = 0;
+ static int responseCount = 0;
+ static int destroyCount = 0;
+
+ /* (non-Javadoc)
+ * @see javax.portlet.faces.Bridge#destroy()
+ */
+ public void destroy() {
+ if(this.initialized == false){
+ throw new IllegalStateException("bridge not initialized");
+ }
+ this.initialized=false;
+ destroyCount++;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.portlet.faces.Bridge#doFacesRequest(javax.portlet.ActionRequest,
javax.portlet.ActionResponse)
+ */
+ public void doFacesRequest(ActionRequest request, ActionResponse response)
+ throws BridgeException {
+ if(null == request || null == response){
+ throw new NullPointerException();
+ }
+ if(this.initialized == false){
+ throw new IllegalStateException("bridge not initialized");
+ }
+ if(null == request.getAttribute("javax.portlet.faces.defaultViewId")){
+ throw new BridgeDefaultViewNotSpecifiedException();
+ }
+ this.actionProcessed=true;
+ actionCount++;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.portlet.faces.Bridge#doFacesRequest(javax.portlet.RenderRequest,
javax.portlet.RenderResponse)
+ */
+ public void doFacesRequest(RenderRequest request, RenderResponse response)
+ throws BridgeException {
+ if(null == request || null == response){
+ throw new NullPointerException();
+ }
+ if(this.initialized == false){
+ throw new IllegalStateException("bridge not initialized");
+ }
+ if(null == request.getAttribute("javax.portlet.faces.defaultViewId")){
+ throw new BridgeDefaultViewNotSpecifiedException();
+ }
+ this.responseProcessed=true;
+ responseCount++;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.portlet.faces.Bridge#init(javax.portlet.PortletConfig)
+ */
+ public void init(PortletConfig config) throws PortletException {
+ if(null == config){
+ throw new NullPointerException();
+ }
+ this.initialized=true;
+ initCount++;
+ }
+
+ /**
+ * @return the initialized
+ */
+ protected boolean isInitialized() {
+ return initialized;
+ }
+
+ /**
+ * @return the actionProcessed
+ */
+ protected boolean isActionProcessed() {
+ return actionProcessed;
+ }
+
+ /**
+ * @return the responseProcessed
+ */
+ protected boolean isResponseProcessed() {
+ return responseProcessed;
+ }
+
+}
Property changes on:
trunk/extensions/portlet/src/test/java/javax/portlet/faces/MockBridge.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Date Revision Author
Modified:
trunk/extensions/portlet/src/test/java/org/ajax4jsf/portlet/AbstractAjax4jsfPortletTestCase.java
===================================================================
---
trunk/extensions/portlet/src/test/java/org/ajax4jsf/portlet/AbstractAjax4jsfPortletTestCase.java 2007-10-23
00:15:11 UTC (rev 3476)
+++
trunk/extensions/portlet/src/test/java/org/ajax4jsf/portlet/AbstractAjax4jsfPortletTestCase.java 2007-10-23
00:15:54 UTC (rev 3477)
@@ -16,6 +16,7 @@
protected MockPortletContext portletContext;
protected MockRenderRequest renderRequest;
protected MockRenderResponse renderResponse;
+ protected MockPortletConfig portletConfig;
public AbstractAjax4jsfPortletTestCase(String name) {
super(name);
@@ -23,6 +24,8 @@
public void setUp() throws Exception {
super.setUp();
+ portletContext = new MockPortletContext();
+ portletConfig = new MockPortletConfig(portletContext);
}
public void tearDown() throws Exception {
@@ -32,6 +35,7 @@
renderRequest = null;
renderResponse = null;
portletContext = null;
+ portletConfig = null;
}
/**
@@ -40,7 +44,6 @@
protected void setupActionRequest() {
actionRequest = new MockActionRequest();
actionResponse = new MockActionResponse();
- portletContext = new MockPortletContext();
externalContext.setRequest(actionRequest);
externalContext.setResponse(actionResponse);
}
@@ -51,7 +54,6 @@
protected void setupRenderRequest() {
renderRequest = new MockRenderRequest();
renderResponse = new MockRenderResponse();
- portletContext = new MockPortletContext();
externalContext.setRequest(renderRequest);
externalContext.setResponse(renderResponse);
}
Added:
trunk/extensions/portlet/src/test/java/org/ajax4jsf/portlet/IteratorEnumeration.java
===================================================================
--- trunk/extensions/portlet/src/test/java/org/ajax4jsf/portlet/IteratorEnumeration.java
(rev 0)
+++
trunk/extensions/portlet/src/test/java/org/ajax4jsf/portlet/IteratorEnumeration.java 2007-10-23
00:15:54 UTC (rev 3477)
@@ -0,0 +1,23 @@
+/**
+ *
+ */
+package org.ajax4jsf.portlet;
+
+import java.util.Enumeration;
+import java.util.Iterator;
+
+final class IteratorEnumeration implements Enumeration {
+ private Iterator<String> iterator;
+
+ public IteratorEnumeration(Iterator<String> iterator) {
+ this.iterator=iterator;
+ }
+
+ public boolean hasMoreElements() {
+ return iterator.hasNext();
+ }
+
+ public Object nextElement() {
+ return iterator.next();
+ }
+}
\ No newline at end of file
Property changes on:
trunk/extensions/portlet/src/test/java/org/ajax4jsf/portlet/IteratorEnumeration.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Date Revision Author
Added: trunk/extensions/portlet/src/test/java/org/ajax4jsf/portlet/MockPortletConfig.java
===================================================================
--- trunk/extensions/portlet/src/test/java/org/ajax4jsf/portlet/MockPortletConfig.java
(rev 0)
+++
trunk/extensions/portlet/src/test/java/org/ajax4jsf/portlet/MockPortletConfig.java 2007-10-23
00:15:54 UTC (rev 3477)
@@ -0,0 +1,82 @@
+/**
+ *
+ */
+package org.ajax4jsf.portlet;
+
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Locale;
+import java.util.Map;
+import java.util.ResourceBundle;
+
+import javax.portlet.PortletConfig;
+import javax.portlet.PortletContext;
+
+/**
+ * @author asmirnov
+ *
+ */
+public class MockPortletConfig implements PortletConfig {
+
+ private final PortletContext context;
+
+ private Map<String, String> parameters;
+
+ private String portletName="generic";
+
+
+ /* (non-Javadoc)
+ * @see javax.portlet.PortletConfig#getInitParameter(java.lang.String)
+ */
+ public String getInitParameter(String arg0) {
+
+ return parameters.get(arg0);
+ }
+
+ /* (non-Javadoc)
+ * @see javax.portlet.PortletConfig#getInitParameterNames()
+ */
+ public Enumeration getInitParameterNames() {
+ return new IteratorEnumeration(parameters.keySet().iterator());
+ }
+
+ /* (non-Javadoc)
+ * @see javax.portlet.PortletConfig#getPortletContext()
+ */
+ public PortletContext getPortletContext() {
+ return context;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.portlet.PortletConfig#getPortletName()
+ */
+ public String getPortletName() {
+ // TODO Auto-generated method stub
+ return this.portletName;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.portlet.PortletConfig#getResourceBundle(java.util.Locale)
+ */
+ public ResourceBundle getResourceBundle(Locale arg0) {
+ return ResourceBundle.getBundle("javax.portlet.faces.bundle", arg0);
+ }
+
+ /**
+ * @param portletName the portletName to set
+ */
+ public void setPortletName(String name) {
+ this.portletName = name;
+ }
+
+ public void addInitParameter(String name, String value){
+ this.parameters.put(name, value);
+ }
+
+ public MockPortletConfig(PortletContext context) {
+ super();
+ this.context = context;
+ parameters = new HashMap<String, String>();
+ }
+
+}
Property changes on:
trunk/extensions/portlet/src/test/java/org/ajax4jsf/portlet/MockPortletConfig.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Date Revision Author
Modified:
trunk/extensions/portlet/src/test/java/org/ajax4jsf/portlet/MockPortletContext.java
===================================================================
---
trunk/extensions/portlet/src/test/java/org/ajax4jsf/portlet/MockPortletContext.java 2007-10-23
00:15:11 UTC (rev 3476)
+++
trunk/extensions/portlet/src/test/java/org/ajax4jsf/portlet/MockPortletContext.java 2007-10-23
00:15:54 UTC (rev 3477)
@@ -8,6 +8,8 @@
import java.net.URL;
import java.util.Collections;
import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Map;
import java.util.Set;
import javax.portlet.PortletContext;
import javax.portlet.PortletRequestDispatcher;
@@ -19,38 +21,43 @@
public class MockPortletContext implements PortletContext {
public static final String PORTLET_INIT_VALUE = "portlet_init_value";
public static final String INIT_PARAMETER = "init_parameter";
+
+ private Map<String, String> initParameters;
+
+ private Map<String, Object> attributes;
+
+ public MockPortletContext() {
+ initParameters = new HashMap<String, String>();
+ initParameters.put(INIT_PARAMETER, PORTLET_INIT_VALUE);
+ attributes = new HashMap<String, Object>();
+ }
/* (non-Javadoc)
* @see javax.portlet.PortletContext#getAttribute(java.lang.String)
*/
public Object getAttribute(String arg0) {
- // TODO Auto-generated method stub
- return null;
+ return attributes.get(arg0);
}
/* (non-Javadoc)
* @see javax.portlet.PortletContext#getAttributeNames()
*/
public Enumeration getAttributeNames() {
- // TODO Auto-generated method stub
- return null;
+ return Collections.enumeration(attributes.keySet());
}
/* (non-Javadoc)
* @see javax.portlet.PortletContext#getInitParameter(java.lang.String)
*/
public String getInitParameter(String arg0) {
- if (INIT_PARAMETER.equals(arg0)) {
- return PORTLET_INIT_VALUE;
- }
- return null;
+ return initParameters.get(arg0);
}
/* (non-Javadoc)
* @see javax.portlet.PortletContext#getInitParameterNames()
*/
public Enumeration getInitParameterNames() {
- return Collections.enumeration(Collections.singleton(INIT_PARAMETER));
+ return Collections.enumeration(initParameters.keySet());
}
/* (non-Javadoc)
@@ -58,7 +65,7 @@
*/
public int getMajorVersion() {
// TODO Auto-generated method stub
- return 0;
+ return 1;
}
/* (non-Javadoc)
@@ -159,13 +166,17 @@
* @see javax.portlet.PortletContext#removeAttribute(java.lang.String)
*/
public void removeAttribute(String arg0) {
- // TODO Auto-generated method stub
+ attributes.remove(arg0);
}
/* (non-Javadoc)
* @see javax.portlet.PortletContext#setAttribute(java.lang.String,
java.lang.Object)
*/
public void setAttribute(String arg0, Object arg1) {
- // TODO Auto-generated method stub
+ attributes.put(arg0, arg1);
}
+
+ public void setInitParameter(String name, String value) {
+ initParameters.put(name, value);
+ }
}
Modified:
trunk/extensions/portlet/src/test/java/org/ajax4jsf/portlet/MockPortletRequest.java
===================================================================
---
trunk/extensions/portlet/src/test/java/org/ajax4jsf/portlet/MockPortletRequest.java 2007-10-23
00:15:11 UTC (rev 3476)
+++
trunk/extensions/portlet/src/test/java/org/ajax4jsf/portlet/MockPortletRequest.java 2007-10-23
00:15:54 UTC (rev 3477)
@@ -29,6 +29,9 @@
public static final String PARAMETER_VALUE1 = "value1";
public static final String PARAMETER = "parameter";
public Map parameters = new HashMap();
+ public Map attributes = new HashMap();
+ public PortletMode mode = PortletMode.VIEW;
+ public WindowState windowState = WindowState.NORMAL;
public MockPortletRequest() {
parameters.put(PARAMETER, new String[]{PARAMETER_VALUE1,PARAMETER_VALUE2});
@@ -38,7 +41,7 @@
*/
public Object getAttribute(String arg0) {
// TODO Auto-generated method stub
- return null;
+ return attributes.get(arg0);
}
/* (non-Javadoc)
@@ -46,7 +49,7 @@
*/
public Enumeration getAttributeNames() {
// TODO Auto-generated method stub
- return null;
+ return Collections.enumeration(attributes.keySet());
}
/* (non-Javadoc)
@@ -128,7 +131,7 @@
*/
public PortletMode getPortletMode() {
// TODO Auto-generated method stub
- return null;
+ return mode;
}
/* (non-Javadoc)
@@ -231,8 +234,7 @@
* @see javax.portlet.PortletRequest#getServerPort()
*/
public int getServerPort() {
- // TODO Auto-generated method stub
- return 0;
+ return 80;
}
/* (non-Javadoc)
@@ -247,8 +249,7 @@
* @see javax.portlet.PortletRequest#getWindowState()
*/
public WindowState getWindowState() {
- // TODO Auto-generated method stub
- return null;
+ return windowState;
}
/* (non-Javadoc)
@@ -295,13 +296,13 @@
* @see javax.portlet.PortletRequest#removeAttribute(java.lang.String)
*/
public void removeAttribute(String arg0) {
- // TODO Auto-generated method stub
+ attributes.remove(arg0);
}
/* (non-Javadoc)
* @see javax.portlet.PortletRequest#setAttribute(java.lang.String,
java.lang.Object)
*/
public void setAttribute(String arg0, Object arg1) {
- // TODO Auto-generated method stub
+ attributes.put(arg0, arg1);
}
}