Author: maksimkaszynski
Date: 2008-03-12 09:06:40 -0400 (Wed, 12 Mar 2008)
New Revision: 6748
Added:
trunk/framework/test/src/main/java/org/ajax4jsf/tests/AbstractJspTestCase.java
trunk/framework/test/src/main/java/org/ajax4jsf/tests/Condition.java
trunk/framework/test/src/main/java/org/ajax4jsf/tests/MockELContext2.java
trunk/framework/test/src/main/java/org/ajax4jsf/tests/MockMethodExpression.java
Modified:
trunk/framework/test/src/main/java/org/ajax4jsf/tests/AbstractAjax4JsfTestCase.java
Log:
updated tests
Modified:
trunk/framework/test/src/main/java/org/ajax4jsf/tests/AbstractAjax4JsfTestCase.java
===================================================================
---
trunk/framework/test/src/main/java/org/ajax4jsf/tests/AbstractAjax4JsfTestCase.java 2008-03-12
13:06:18 UTC (rev 6747)
+++
trunk/framework/test/src/main/java/org/ajax4jsf/tests/AbstractAjax4JsfTestCase.java 2008-03-12
13:06:40 UTC (rev 6748)
@@ -35,6 +35,8 @@
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
+import javax.el.ELContext;
+import javax.el.ExpressionFactory;
import javax.faces.FacesException;
import javax.faces.FactoryFinder;
import javax.faces.component.UIComponent;
@@ -85,6 +87,14 @@
private File tmpRoot = null;
+ protected ELContext elContext;
+
+ protected ExpressionFactory expressionFactory;
+
+ public static final void evaluate(Condition condition) {
+ String message = condition.getMessage();
+ assertTrue(message, condition.isConditionTrue());
+ }
/**
* @param name
*/
@@ -182,6 +192,8 @@
externalContext = new MockExternalContext(externalContext);
facesContext.setExternalContext(externalContext);
+ elContext = facesContext.getELContext();
+ expressionFactory = application.getExpressionFactory();
}
protected WebClient createWebClient() {
@@ -273,6 +285,8 @@
*/
public void tearDown() throws Exception {
// This method MUST BE OVERRIDEN in any subclasses - since Junit see for it in class
for call
+ expressionFactory = null;
+ elContext = null;
super.tearDown();
vcpRenderKit = null;
// Thread.currentThread().setContextClassLoader(threadContextClassLoader);
@@ -284,6 +298,7 @@
InternetResourceBuilder.setInstance(null);
deleteRecursively(tmpRoot);
+
}
// Protected configurations URL's
Added: trunk/framework/test/src/main/java/org/ajax4jsf/tests/AbstractJspTestCase.java
===================================================================
--- trunk/framework/test/src/main/java/org/ajax4jsf/tests/AbstractJspTestCase.java
(rev 0)
+++
trunk/framework/test/src/main/java/org/ajax4jsf/tests/AbstractJspTestCase.java 2008-03-12
13:06:40 UTC (rev 6748)
@@ -0,0 +1,114 @@
+/**
+ *
+ */
+package org.ajax4jsf.tests;
+
+import java.io.IOException;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import javax.el.ELContext;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.jsp.PageContext;
+
+/**
+ * @author Administrator
+ *
+ */
+public abstract class AbstractJspTestCase extends AbstractAjax4JsfTestCase {
+
+ protected PageContext pageContext = null;
+
+ /**
+ * @param name
+ */
+ public AbstractJspTestCase(String name) {
+ super(name);
+ }
+
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+ pageContext = new MockPageContext() {
+
+ private final int[] SCOPE_ORDER = {PAGE_SCOPE, REQUEST_SCOPE, SESSION_SCOPE,
APPLICATION_SCOPE};
+
+ private Map<String, Object> attributes =
+ new HashMap<String, Object>();
+
+ @Override
+ public ELContext getELContext() {
+ return elContext;
+ }
+
+ @Override
+ public Object findAttribute(String name) {
+ Object value = null;
+ for(int i = 0; i < SCOPE_ORDER.length && value == null; i++) {
+ value = getScope(SCOPE_ORDER[i]).get(name);
+ }
+ return value;
+ }
+
+ @Override
+ public int getAttributesScope(String name) {
+ Object value = null;
+ int i = 0;
+ for(; i < SCOPE_ORDER.length && value == null; i++) {
+ value = getScope(SCOPE_ORDER[i]).get(name);
+ }
+ return value == null ? 0 :SCOPE_ORDER[i];
+ }
+
+
+ @Override
+ public Enumeration<String> getAttributeNamesInScope(int scope) {
+ Map<String, Object> scopeMap = getScope(scope);
+ final Iterator<String> iterator = scopeMap.keySet().iterator();
+ return new Enumeration<String>() {
+ public boolean hasMoreElements() {
+ return iterator.hasNext();
+ }
+ public String nextElement() {
+ // TODO Auto-generated method stub
+ return iterator.next();
+ }
+ };
+ }
+
+ @Override
+ public ServletRequest getRequest() {
+ return request;
+ }
+ @Override
+ public Object getAttribute(String name) {
+ return getScope(PAGE_SCOPE).get(name);
+ }
+
+ @Override
+ public Object getAttribute(String name, int scope) {
+ return getScope(scope).get(name);
+ }
+
+ @SuppressWarnings("unchecked")
+ private Map<String, Object> getScope(int scopeName) {
+ switch(scopeName) {
+ case APPLICATION_SCOPE: return externalContext.getApplicationMap();
+ case SESSION_SCOPE: return externalContext.getSessionMap();
+ case REQUEST_SCOPE: return externalContext.getRequestMap();
+ default: return attributes;
+ }
+ }
+ };
+ }
+
+
+ @Override
+ public void tearDown() throws Exception {
+ pageContext = null;
+ super.tearDown();
+ }
+}
Added: trunk/framework/test/src/main/java/org/ajax4jsf/tests/Condition.java
===================================================================
--- trunk/framework/test/src/main/java/org/ajax4jsf/tests/Condition.java
(rev 0)
+++ trunk/framework/test/src/main/java/org/ajax4jsf/tests/Condition.java 2008-03-12
13:06:40 UTC (rev 6748)
@@ -0,0 +1,45 @@
+/**
+ *
+ */
+package org.ajax4jsf.tests;
+
+/**
+ * @author Administrator
+ *
+ */
+public class Condition {
+ private boolean conditionTrue;
+
+ private String message;
+
+ public Condition(String message) {
+ super();
+ this.message = message;
+ }
+
+ public String getMessage() {
+ return message;
+ }
+
+ public void setMessage(String message) {
+ this.message = message;
+ }
+
+ public boolean isConditionTrue() {
+ return conditionTrue;
+ }
+
+ public void setTrue() {
+ setCondition(true);
+ }
+
+ public void setFalse(){
+ setCondition(false);
+ }
+ public void setCondition(boolean conditionTrue) {
+ this.conditionTrue = conditionTrue;
+ }
+
+
+
+}
Added: trunk/framework/test/src/main/java/org/ajax4jsf/tests/MockELContext2.java
===================================================================
--- trunk/framework/test/src/main/java/org/ajax4jsf/tests/MockELContext2.java
(rev 0)
+++ trunk/framework/test/src/main/java/org/ajax4jsf/tests/MockELContext2.java 2008-03-12
13:06:40 UTC (rev 6748)
@@ -0,0 +1,55 @@
+/**
+ *
+ */
+package org.ajax4jsf.tests;
+
+import javax.el.ELContext;
+import javax.el.ELResolver;
+import javax.el.FunctionMapper;
+import javax.el.VariableMapper;
+import javax.faces.context.FacesContext;
+
+import com.sun.facelets.FaceletContext;
+
+/**
+ * @author Administrator
+ *
+ */
+public class MockELContext2 extends ELContext {
+
+ private FacesContext faces;
+ /**
+ *
+ */
+ public MockELContext2(FacesContext context) {
+ faces = context;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.el.ELContext#getELResolver()
+ */
+ @Override
+ public ELResolver getELResolver() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.el.ELContext#getFunctionMapper()
+ */
+ @Override
+ public FunctionMapper getFunctionMapper() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.el.ELContext#getVariableMapper()
+ */
+ @Override
+ public VariableMapper getVariableMapper() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
Added: trunk/framework/test/src/main/java/org/ajax4jsf/tests/MockMethodExpression.java
===================================================================
--- trunk/framework/test/src/main/java/org/ajax4jsf/tests/MockMethodExpression.java
(rev 0)
+++
trunk/framework/test/src/main/java/org/ajax4jsf/tests/MockMethodExpression.java 2008-03-12
13:06:40 UTC (rev 6748)
@@ -0,0 +1,105 @@
+/**
+ *
+ */
+package org.ajax4jsf.tests;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.el.ELContext;
+import javax.el.MethodExpression;
+import javax.el.MethodInfo;
+
+/**
+ * @author Administrator
+ *
+ */
+@SuppressWarnings("serial")
+public class MockMethodExpression extends MethodExpression {
+
+ public static interface MethodExpressionInvocationResult {
+ public Object invoke(ELContext context, Object ... arguments);
+ }
+
+ //private Class<?> returnType;
+ private MethodExpressionInvocationResult result;
+ private String expressionString;
+ private List<Object[]> invocationArgs = new ArrayList<Object[]>();
+
+
+
+
+ public MockMethodExpression(String expressionString, Class<?> returnType,
+ MethodExpressionInvocationResult result) {
+ super();
+ this.expressionString = expressionString;
+ //this.returnType = returnType;
+ this.result = result;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.el.MethodExpression#getMethodInfo(javax.el.ELContext)
+ */
+ @Override
+ public MethodInfo getMethodInfo(ELContext context) {
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.el.MethodExpression#invoke(javax.el.ELContext, java.lang.Object[])
+ */
+ @Override
+ public Object invoke(ELContext context, Object[] params) {
+ invocationArgs.add(params);
+ Object returnValue = null;
+ if (result != null) {
+ returnValue = result.invoke(context, params);
+ }
+ return returnValue;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.el.Expression#equals(java.lang.Object)
+ */
+ @Override
+ public boolean equals(Object obj) {
+ if (obj instanceof MethodExpression) {
+ MethodExpression expression = (MethodExpression) obj;
+ return expressionString != null && expression.getExpressionString() != null
&& expressionString.equals(expression.getExpressionString());
+ }
+ return false;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.el.Expression#getExpressionString()
+ */
+ @Override
+ public String getExpressionString() {
+ return expressionString;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.el.Expression#hashCode()
+ */
+ @Override
+ public int hashCode() {
+ return expressionString == null ? 0 : expressionString.hashCode();
+ }
+
+ /* (non-Javadoc)
+ * @see javax.el.Expression#isLiteralText()
+ */
+ @Override
+ public boolean isLiteralText() {
+ // TODO Auto-generated method stub
+ return expressionString != null && !(expressionString.contains("${")
|| expressionString.contains("#{"));
+ }
+
+ public List<Object[]> getInvocationArgs() {
+ return invocationArgs;
+ }
+
+ public void reset() {
+ invocationArgs.clear();
+ }
+}
Show replies by date