Author: apetrelli
Date: Sun Jun 6 11:05:32 2010
New Revision: 951854
URL: http://svn.apache.org/viewvc?rev=951854&view=rev
Log:
TILESSB-11
Complete test coverage for tiles-mvel.
Added:
tiles/sandbox/trunk/tiles3/tiles-mvel/src/main/java/org/apache/tiles/mvel/ReadOnlyVariableResolverFactory.java
(with props)
tiles/sandbox/trunk/tiles3/tiles-mvel/src/test/java/org/apache/tiles/mvel/ReadOnlyVariableResolverFactoryTest.java
(with props)
tiles/sandbox/trunk/tiles3/tiles-mvel/src/test/java/org/apache/tiles/mvel/ReadOnlyVariableResolverTest.java
(with props)
Modified:
tiles/sandbox/trunk/tiles3/tiles-mvel/pom.xml
tiles/sandbox/trunk/tiles3/tiles-mvel/src/main/java/org/apache/tiles/mvel/ScopeVariableResolverFactory.java
tiles/sandbox/trunk/tiles3/tiles-mvel/src/main/java/org/apache/tiles/mvel/TilesContextBeanVariableResolverFactory.java
tiles/sandbox/trunk/tiles3/tiles-mvel/src/main/java/org/apache/tiles/mvel/TilesContextVariableResolverFactory.java
tiles/sandbox/trunk/tiles3/tiles-mvel/src/test/java/org/apache/tiles/mvel/MVELAttributeEvaluatorTest.java
tiles/sandbox/trunk/tiles3/tiles-mvel/src/test/java/org/apache/tiles/mvel/ScopeVariableResolverFactoryTest.java
tiles/sandbox/trunk/tiles3/tiles-mvel/src/test/java/org/apache/tiles/mvel/TilesContextBeanVariableResolverFactoryTest.java
tiles/sandbox/trunk/tiles3/tiles-mvel/src/test/java/org/apache/tiles/mvel/TilesContextVariableResolverFactoryTest.java
Modified: tiles/sandbox/trunk/tiles3/tiles-mvel/pom.xml
URL:
http://svn.apache.org/viewvc/tiles/sandbox/trunk/tiles3/tiles-mvel/pom.xml?rev=951854&r1=951853&r2=951854&view=diff
==============================================================================
--- tiles/sandbox/trunk/tiles3/tiles-mvel/pom.xml (original)
+++ tiles/sandbox/trunk/tiles3/tiles-mvel/pom.xml Sun Jun 6 11:05:32 2010
@@ -36,7 +36,7 @@
<description>Tiles MVEL support: Classes and tag libraries to use MVEL as an
expression language in attribute expressions.</description>
<properties>
- <tiles.osgi.symbolicName>org.apache.tiles.mvel</tiles.osgi.symbolicName>
+ <tiles.osgi.symbolicName>org.apache.tiles.mvel</tiles.osgi.symbolicName>
</properties>
<build>
@@ -103,14 +103,8 @@
</dependency>
<dependency>
<groupId>org.easymock</groupId>
- <artifactId>easymock</artifactId>
- <version>2.5.1</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.easymock</groupId>
<artifactId>easymockclassextension</artifactId>
- <version>2.4</version>
+ <version>2.5.2</version>
<scope>test</scope>
</dependency>
<dependency>
Added:
tiles/sandbox/trunk/tiles3/tiles-mvel/src/main/java/org/apache/tiles/mvel/ReadOnlyVariableResolverFactory.java
URL:
http://svn.apache.org/viewvc/tiles/sandbox/trunk/tiles3/tiles-mvel/src/main/java/org/apache/tiles/mvel/ReadOnlyVariableResolverFactory.java?rev=951854&view=auto
==============================================================================
---
tiles/sandbox/trunk/tiles3/tiles-mvel/src/main/java/org/apache/tiles/mvel/ReadOnlyVariableResolverFactory.java
(added)
+++
tiles/sandbox/trunk/tiles3/tiles-mvel/src/main/java/org/apache/tiles/mvel/ReadOnlyVariableResolverFactory.java
Sun Jun 6 11:05:32 2010
@@ -0,0 +1,123 @@
+package org.apache.tiles.mvel;
+
+import java.util.HashMap;
+
+import org.apache.tiles.context.TilesRequestContextHolder;
+import org.mvel2.UnresolveablePropertyException;
+import org.mvel2.integration.VariableResolver;
+import org.mvel2.integration.impl.BaseVariableResolverFactory;
+
+public abstract class ReadOnlyVariableResolverFactory extends
+ BaseVariableResolverFactory {
+
+ /**
+ * The Tiles request holder.
+ */
+ protected TilesRequestContextHolder requestHolder;
+
+ /**
+ * Constructor.
+ *
+ * @param requestHolder The Tiles request holder.
+ * @since 3..0
+ */
+ public ReadOnlyVariableResolverFactory(TilesRequestContextHolder
requestHolder) {
+ this.requestHolder = requestHolder;
+ variableResolvers = new HashMap<String, VariableResolver>();
+ }
+
+ /** {...@inheritdoc} */
+ public VariableResolver createVariable(String name, Object value) {
+ if (nextFactory != null) {
+ return nextFactory.createVariable(name, value);
+ }
+ throw new UnsupportedOperationException("This variable resolver
factory is read only");
+ }
+
+ /** {...@inheritdoc} */
+ public VariableResolver createVariable(String name, Object value,
+ Class<?> type) {
+ variableResolvers = new HashMap<String, VariableResolver>();
+ if (nextFactory != null) {
+ return nextFactory.createVariable(name, value, type);
+ }
+ throw new UnsupportedOperationException("This variable resolver
factory is read only");
+ }
+
+ /** {...@inheritdoc} */
+ public boolean isResolveable(String name) {
+ return isTarget(name) || isNextResolveable(name);
+ }
+
+ /** {...@inheritdoc} */
+ @Override
+ public VariableResolver getVariableResolver(String name) {
+ if (isResolveable(name)) {
+ if (variableResolvers != null &&
variableResolvers.containsKey(name)) {
+ return variableResolvers.get(name);
+ } else if (isTarget(name)) {
+ VariableResolver variableResolver =
createVariableResolver(name);
+ variableResolvers.put(name, variableResolver);
+ return variableResolver;
+ } else if (nextFactory != null) {
+ return nextFactory.getVariableResolver(name);
+ }
+ }
+
+ throw new UnresolveablePropertyException("unable to resolve variable
'" + name + "'");
+ }
+
+ /**
+ * Creates a variable resolver.
+ *
+ * @param name The name of the property.
+ * @return The variable resolver.
+ * @since 3.0.0
+ */
+ public abstract VariableResolver createVariableResolver(String name);
+
+ /**
+ * Base variable resolver.
+ *
+ * @version $Rev$ $Date$
+ * @since 3.0.0
+ */
+ public abstract static class ReadOnlyVariableResolver implements
VariableResolver {
+
+ /**
+ * The name of the property.
+ */
+ protected String name;
+
+ /**
+ * Constructor.
+ *
+ * @param name The name of the property.
+ * @since 2.2.0
+ */
+ public ReadOnlyVariableResolver(String name) {
+ this.name = name;
+ }
+
+ /** {...@inheritdoc} */
+ public int getFlags() {
+ return 0;
+ }
+
+ /** {...@inheritdoc} */
+ public String getName() {
+ return name;
+ }
+
+ /** {...@inheritdoc} */
+ @SuppressWarnings("unchecked")
+ public void setStaticType(Class type) {
+ // Does nothing for the moment.
+ }
+
+ /** {...@inheritdoc} */
+ public void setValue(Object value) {
+ throw new UnsupportedOperationException("This resolver is
read-only");
+ }
+ }
+}
Propchange:
tiles/sandbox/trunk/tiles3/tiles-mvel/src/main/java/org/apache/tiles/mvel/ReadOnlyVariableResolverFactory.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
tiles/sandbox/trunk/tiles3/tiles-mvel/src/main/java/org/apache/tiles/mvel/ReadOnlyVariableResolverFactory.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Modified:
tiles/sandbox/trunk/tiles3/tiles-mvel/src/main/java/org/apache/tiles/mvel/ScopeVariableResolverFactory.java
URL:
http://svn.apache.org/viewvc/tiles/sandbox/trunk/tiles3/tiles-mvel/src/main/java/org/apache/tiles/mvel/ScopeVariableResolverFactory.java?rev=951854&r1=951853&r2=951854&view=diff
==============================================================================
---
tiles/sandbox/trunk/tiles3/tiles-mvel/src/main/java/org/apache/tiles/mvel/ScopeVariableResolverFactory.java
(original)
+++
tiles/sandbox/trunk/tiles3/tiles-mvel/src/main/java/org/apache/tiles/mvel/ScopeVariableResolverFactory.java
Sun Jun 6 11:05:32 2010
@@ -21,14 +21,11 @@
package org.apache.tiles.mvel;
-import java.util.HashMap;
import java.util.Map;
import org.apache.tiles.context.TilesRequestContextHolder;
import org.apache.tiles.request.Request;
-import org.mvel2.UnresolveablePropertyException;
import org.mvel2.integration.VariableResolver;
-import org.mvel2.integration.impl.BaseVariableResolverFactory;
/**
* Resolves beans stored in request, session and application scopes.
@@ -37,12 +34,7 @@ import org.mvel2.integration.impl.BaseVa
* @since 2.2.0
*/
public class ScopeVariableResolverFactory extends
- BaseVariableResolverFactory {
-
- /**
- * The Tiles request holder.
- */
- private TilesRequestContextHolder requestHolder;
+ ReadOnlyVariableResolverFactory {
/**
* Constructor.
@@ -51,49 +43,13 @@ public class ScopeVariableResolverFactor
* @since 2.2.0
*/
public ScopeVariableResolverFactory(TilesRequestContextHolder
requestHolder) {
- this.requestHolder = requestHolder;
- variableResolvers = new HashMap<String, VariableResolver>();
- }
-
- /** {...@inheritdoc} */
- public VariableResolver createVariable(String name, Object value) {
- if (nextFactory != null) {
- return nextFactory.createVariable(name, value);
- }
- throw new UnsupportedOperationException("This variable resolver
factory is read only");
- }
-
- /** {...@inheritdoc} */
- public VariableResolver createVariable(String name, Object value,
- Class<?> type) {
- variableResolvers = new HashMap<String, VariableResolver>();
- if (nextFactory != null) {
- return nextFactory.createVariable(name, value, type);
- }
- throw new UnsupportedOperationException("This variable resolver
factory is read only");
- }
-
- /** {...@inheritdoc} */
- public boolean isResolveable(String name) {
- return isTarget(name) || isNextResolveable(name);
+ super(requestHolder);
}
/** {...@inheritdoc} */
@Override
- public VariableResolver getVariableResolver(String name) {
- if (isResolveable(name)) {
- if (variableResolvers != null &&
variableResolvers.containsKey(name)) {
- return variableResolvers.get(name);
- } else if (isTarget(name)) {
- VariableResolver variableResolver = new
ScopeVariableResolver(name);
- variableResolvers.put(name, variableResolver);
- return variableResolver;
- } else if (nextFactory != null) {
- return nextFactory.getVariableResolver(name);
- }
- }
-
- throw new UnresolveablePropertyException("unable to resolve variable
'" + name + "'");
+ public VariableResolver createVariableResolver(String name) {
+ return new ScopeVariableResolver(name);
}
/** {...@inheritdoc} */
@@ -116,12 +72,7 @@ public class ScopeVariableResolverFactor
* @version $Rev$ $Date$
* @since 2.2.0
*/
- private class ScopeVariableResolver implements VariableResolver {
-
- /**
- * The name of the attribute.
- */
- private String name;
+ private class ScopeVariableResolver extends ReadOnlyVariableResolver {
/**
* Constructor.
@@ -130,17 +81,7 @@ public class ScopeVariableResolverFactor
* @since 2.2.0
*/
public ScopeVariableResolver(String name) {
- this.name = name;
- }
-
- /** {...@inheritdoc} */
- public int getFlags() {
- return 0;
- }
-
- /** {...@inheritdoc} */
- public String getName() {
- return name;
+ super(name);
}
/** {...@inheritdoc} */
@@ -154,16 +95,5 @@ public class ScopeVariableResolverFactor
Request request = requestHolder.getTilesRequestContext();
return request.getContext(name.substring(0, name.length() - 5));
}
-
- /** {...@inheritdoc} */
- @SuppressWarnings("unchecked")
- public void setStaticType(Class type) {
- // Does nothing for the moment.
- }
-
- /** {...@inheritdoc} */
- public void setValue(Object value) {
- throw new UnsupportedOperationException("This resolver is
read-only");
- }
}
}
Modified:
tiles/sandbox/trunk/tiles3/tiles-mvel/src/main/java/org/apache/tiles/mvel/TilesContextBeanVariableResolverFactory.java
URL:
http://svn.apache.org/viewvc/tiles/sandbox/trunk/tiles3/tiles-mvel/src/main/java/org/apache/tiles/mvel/TilesContextBeanVariableResolverFactory.java?rev=951854&r1=951853&r2=951854&view=diff
==============================================================================
---
tiles/sandbox/trunk/tiles3/tiles-mvel/src/main/java/org/apache/tiles/mvel/TilesContextBeanVariableResolverFactory.java
(original)
+++
tiles/sandbox/trunk/tiles3/tiles-mvel/src/main/java/org/apache/tiles/mvel/TilesContextBeanVariableResolverFactory.java
Sun Jun 6 11:05:32 2010
@@ -21,13 +21,9 @@
package org.apache.tiles.mvel;
-import java.util.HashMap;
-
import org.apache.tiles.context.TilesRequestContextHolder;
import org.apache.tiles.request.Request;
-import org.mvel2.UnresolveablePropertyException;
import org.mvel2.integration.VariableResolver;
-import org.mvel2.integration.impl.BaseVariableResolverFactory;
/**
* Resolves beans stored in request, session and application scopes.
@@ -36,12 +32,7 @@ import org.mvel2.integration.impl.BaseVa
* @since 2.2.0
*/
public class TilesContextBeanVariableResolverFactory extends
- BaseVariableResolverFactory {
-
- /**
- * The Tiles request holder.
- */
- private TilesRequestContextHolder requestHolder;
+ ReadOnlyVariableResolverFactory {
/**
* Constructor.
@@ -50,49 +41,13 @@ public class TilesContextBeanVariableRes
* @since 2.2.0
*/
public TilesContextBeanVariableResolverFactory(TilesRequestContextHolder
requestHolder) {
- this.requestHolder = requestHolder;
- variableResolvers = new HashMap<String, VariableResolver>();
- }
-
- /** {...@inheritdoc} */
- public VariableResolver createVariable(String name, Object value) {
- if (nextFactory != null) {
- return nextFactory.createVariable(name, value);
- }
- throw new UnsupportedOperationException("This variable resolver
factory is read only");
- }
-
- /** {...@inheritdoc} */
- public VariableResolver createVariable(String name, Object value,
- Class<?> type) {
- variableResolvers = new HashMap<String, VariableResolver>();
- if (nextFactory != null) {
- return nextFactory.createVariable(name, value, type);
- }
- throw new UnsupportedOperationException("This variable resolver
factory is read only");
- }
-
- /** {...@inheritdoc} */
- public boolean isResolveable(String name) {
- return isTarget(name) || isNextResolveable(name);
+ super(requestHolder);
}
/** {...@inheritdoc} */
@Override
- public VariableResolver getVariableResolver(String name) {
- if (isResolveable(name)) {
- if (variableResolvers != null &&
variableResolvers.containsKey(name)) {
- return variableResolvers.get(name);
- } else if (isTarget(name)) {
- VariableResolver variableResolver = new
TilesContextBeanVariableResolver(name);
- variableResolvers.put(name, variableResolver);
- return variableResolver;
- } else if (nextFactory != null) {
- return nextFactory.getVariableResolver(name);
- }
- }
-
- throw new UnresolveablePropertyException("unable to resolve variable
'" + name + "'");
+ public VariableResolver createVariableResolver(String name) {
+ return new TilesContextBeanVariableResolver(name);
}
/** {...@inheritdoc} */
@@ -112,12 +67,7 @@ public class TilesContextBeanVariableRes
* @version $Rev$ $Date$
* @since 2.2.0
*/
- private class TilesContextBeanVariableResolver implements VariableResolver
{
-
- /**
- * The name of the attribute.
- */
- private String name;
+ private class TilesContextBeanVariableResolver extends
ReadOnlyVariableResolver {
/**
* Constructor.
@@ -126,17 +76,7 @@ public class TilesContextBeanVariableRes
* @since 2.2.0
*/
public TilesContextBeanVariableResolver(String name) {
- this.name = name;
- }
-
- /** {...@inheritdoc} */
- public int getFlags() {
- return 0;
- }
-
- /** {...@inheritdoc} */
- public String getName() {
- return name;
+ super(name);
}
/** {...@inheritdoc} */
@@ -160,16 +100,5 @@ public class TilesContextBeanVariableRes
}
return null;
}
-
- /** {...@inheritdoc} */
- @SuppressWarnings("unchecked")
- public void setStaticType(Class type) {
- // Does nothing for the moment.
- }
-
- /** {...@inheritdoc} */
- public void setValue(Object value) {
- throw new UnsupportedOperationException("This resolver is
read-only");
- }
}
}
Modified:
tiles/sandbox/trunk/tiles3/tiles-mvel/src/main/java/org/apache/tiles/mvel/TilesContextVariableResolverFactory.java
URL:
http://svn.apache.org/viewvc/tiles/sandbox/trunk/tiles3/tiles-mvel/src/main/java/org/apache/tiles/mvel/TilesContextVariableResolverFactory.java?rev=951854&r1=951853&r2=951854&view=diff
==============================================================================
---
tiles/sandbox/trunk/tiles3/tiles-mvel/src/main/java/org/apache/tiles/mvel/TilesContextVariableResolverFactory.java
(original)
+++
tiles/sandbox/trunk/tiles3/tiles-mvel/src/main/java/org/apache/tiles/mvel/TilesContextVariableResolverFactory.java
Sun Jun 6 11:05:32 2010
@@ -24,7 +24,6 @@ package org.apache.tiles.mvel;
import java.beans.PropertyDescriptor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
-import java.util.HashMap;
import org.apache.tiles.context.TilesRequestContextHolder;
import org.apache.tiles.reflect.CannotAccessMethodException;
@@ -32,7 +31,6 @@ import org.apache.tiles.request.Applicat
import org.apache.tiles.request.Request;
import org.apache.tiles.util.CombinedBeanInfo;
import org.mvel2.integration.VariableResolver;
-import org.mvel2.integration.impl.BaseVariableResolverFactory;
/**
* Resolves {...@link org.apache.tiles.request.Request} and
@@ -42,12 +40,7 @@ import org.mvel2.integration.impl.BaseVa
* @since 2.2.0
*/
public class TilesContextVariableResolverFactory extends
- BaseVariableResolverFactory {
-
- /**
- * The Tiles request holder.
- */
- private TilesRequestContextHolder requestHolder;
+ ReadOnlyVariableResolverFactory {
/**
* Beaninfo about {...@link org.apache.tiles.request.Request} and
@@ -63,48 +56,31 @@ public class TilesContextVariableResolve
* @since 2.2.0
*/
public TilesContextVariableResolverFactory(TilesRequestContextHolder
requestHolder) {
- this.requestHolder = requestHolder;
- variableResolvers = new HashMap<String, VariableResolver>();
- for (PropertyDescriptor descriptor : requestBeanInfo
- .getMappedDescriptors(Request.class).values()) {
- String descriptorName = descriptor.getName();
- variableResolvers.put(descriptorName, new
RequestVariableResolver(descriptorName));
- }
- for (PropertyDescriptor descriptor : requestBeanInfo
- .getMappedDescriptors(ApplicationContext.class).values()) {
- String descriptorName = descriptor.getName();
- variableResolvers.put(descriptorName, new
ApplicationVariableResolver(descriptorName));
- }
+ super(requestHolder);
}
/** {...@inheritdoc} */
- public VariableResolver createVariable(String name, Object value) {
- if (nextFactory != null) {
- return nextFactory.createVariable(name, value);
- }
- throw new UnsupportedOperationException("This variable resolver
factory is read only");
- }
-
- /** {...@inheritdoc} */
- public VariableResolver createVariable(String name, Object value,
- Class<?> type) {
- if (nextFactory != null) {
- return nextFactory.createVariable(name, value, type);
- }
- throw new UnsupportedOperationException("This variable resolver
factory is read only");
+ public boolean isTarget(String name) {
+ return requestBeanInfo.getMappedDescriptors(Request.class).containsKey(
+ name)
+ || requestBeanInfo.getMappedDescriptors(
+ ApplicationContext.class).containsKey(name);
}
/** {...@inheritdoc} */
- public boolean isResolveable(String name) {
- if (variableResolvers.containsKey(name)) {
- return true;
+ @Override
+ public VariableResolver createVariableResolver(String name) {
+ VariableResolver resolver = null;
+ PropertyDescriptor descriptor =
requestBeanInfo.getMappedDescriptors(Request.class).get(name);
+ if (descriptor != null) {
+ resolver = new RequestVariableResolver(name, descriptor);
+ } else {
+ descriptor =
requestBeanInfo.getMappedDescriptors(ApplicationContext.class).get(name);
+ if (descriptor != null) {
+ resolver = new ApplicationVariableResolver(name, descriptor);
+ }
}
- return isNextResolveable(name);
- }
-
- /** {...@inheritdoc} */
- public boolean isTarget(String name) {
- return variableResolvers.containsKey(name);
+ return resolver;
}
/**
@@ -113,12 +89,7 @@ public class TilesContextVariableResolve
* @version $Rev$ $Date$
* @since 2.2.0
*/
- private class RequestVariableResolver implements VariableResolver {
-
- /**
- * The name of the property.
- */
- private String name;
+ private class RequestVariableResolver extends ReadOnlyVariableResolver {
/**
* The property descriptor.
@@ -131,20 +102,9 @@ public class TilesContextVariableResolve
* @param name The name of the property.
* @since 2.2.0
*/
- public RequestVariableResolver(String name) {
- this.name = name;
- descriptor = requestBeanInfo.getMappedDescriptors(
- Request.class).get(name);
- }
-
- /** {...@inheritdoc} */
- public int getFlags() {
- return 0;
- }
-
- /** {...@inheritdoc} */
- public String getName() {
- return name;
+ public RequestVariableResolver(String name, PropertyDescriptor
descriptor) {
+ super(name);
+ this.descriptor = descriptor;
}
/** {...@inheritdoc} */
@@ -173,17 +133,6 @@ public class TilesContextVariableResolve
e);
}
}
-
- /** {...@inheritdoc} */
- @SuppressWarnings("unchecked")
- public void setStaticType(Class type) {
- // Does nothing for the moment.
- }
-
- /** {...@inheritdoc} */
- public void setValue(Object value) {
- throw new UnsupportedOperationException("This resolver is
read-only");
- }
}
/**
@@ -193,14 +142,7 @@ public class TilesContextVariableResolve
* @version $Rev$ $Date$
* @since 2.2.0
*/
- private class ApplicationVariableResolver implements VariableResolver {
-
- /**
- * The name of the property.
- *
- * @since 2.2.0
- */
- private String name;
+ private class ApplicationVariableResolver extends ReadOnlyVariableResolver
{
/**
* The property descriptor.
@@ -215,20 +157,9 @@ public class TilesContextVariableResolve
* @param name The name of the property.
* @since 2.2.0
*/
- public ApplicationVariableResolver(String name) {
- this.name = name;
- descriptor = requestBeanInfo.getMappedDescriptors(
- ApplicationContext.class).get(name);
- }
-
- /** {...@inheritdoc} */
- public int getFlags() {
- return 0;
- }
-
- /** {...@inheritdoc} */
- public String getName() {
- return name;
+ public ApplicationVariableResolver(String name, PropertyDescriptor
descriptor) {
+ super(name);
+ this.descriptor = descriptor;
}
/** {...@inheritdoc} */
@@ -258,16 +189,5 @@ public class TilesContextVariableResolve
e);
}
}
-
- /** {...@inheritdoc} */
- @SuppressWarnings("unchecked")
- public void setStaticType(Class type) {
- // Does nothing for the moment.
- }
-
- /** {...@inheritdoc} */
- public void setValue(Object value) {
- throw new UnsupportedOperationException("This resolver is
read-only");
- }
}
}
Modified:
tiles/sandbox/trunk/tiles3/tiles-mvel/src/test/java/org/apache/tiles/mvel/MVELAttributeEvaluatorTest.java
URL:
http://svn.apache.org/viewvc/tiles/sandbox/trunk/tiles3/tiles-mvel/src/test/java/org/apache/tiles/mvel/MVELAttributeEvaluatorTest.java?rev=951854&r1=951853&r2=951854&view=diff
==============================================================================
---
tiles/sandbox/trunk/tiles3/tiles-mvel/src/test/java/org/apache/tiles/mvel/MVELAttributeEvaluatorTest.java
(original)
+++
tiles/sandbox/trunk/tiles3/tiles-mvel/src/test/java/org/apache/tiles/mvel/MVELAttributeEvaluatorTest.java
Sun Jun 6 11:05:32 2010
@@ -20,20 +20,19 @@
*/
package org.apache.tiles.mvel;
+import static org.easymock.classextension.EasyMock.*;
+import static org.junit.Assert.*;
+
import java.util.HashMap;
import java.util.Map;
-import junit.framework.TestCase;
-
import org.apache.tiles.Attribute;
import org.apache.tiles.Expression;
import org.apache.tiles.context.TilesRequestContextHolder;
-import org.apache.tiles.mvel.MVELAttributeEvaluator;
-import org.apache.tiles.mvel.TilesContextBeanVariableResolverFactory;
-import org.apache.tiles.mvel.TilesContextVariableResolverFactory;
import org.apache.tiles.request.ApplicationContext;
import org.apache.tiles.request.Request;
-import org.easymock.EasyMock;
+import org.junit.Before;
+import org.junit.Test;
import org.mvel2.integration.VariableResolverFactory;
/**
@@ -41,7 +40,7 @@ import org.mvel2.integration.VariableRes
*
* @version $Rev$ $Date$$
*/
-public class MVELAttributeEvaluatorTest extends TestCase {
+public class MVELAttributeEvaluatorTest {
/**
* The evaluator to test.
@@ -53,10 +52,13 @@ public class MVELAttributeEvaluatorTest
*/
private Request request;
- /** {...@inheritdoc} */
- @Override
- protected void setUp() throws Exception {
- super.setUp();
+ private ApplicationContext applicationContext;
+
+ /**
+ * Sets up the test.
+ */
+ @Before
+ public void setUp() {
TilesRequestContextHolder requestHolder = new
TilesRequestContextHolder();
VariableResolverFactory variableResolverFactory = new
ScopeVariableResolverFactory(
requestHolder);
@@ -75,26 +77,35 @@ public class MVELAttributeEvaluatorTest
sessionScope.put("object2", new Integer(1));
applicationScope.put("object3", new Float(2.0));
requestScope.put("paulaBean", new PaulaBean());
- request = EasyMock.createMock(Request.class);
- EasyMock.expect(request.getContext("request")).andReturn(requestScope)
+ request = createMock(Request.class);
+ expect(request.getContext("request")).andReturn(requestScope)
.anyTimes();
- EasyMock.expect(request.getContext("session")).andReturn(sessionScope)
+ expect(request.getContext("session")).andReturn(sessionScope)
.anyTimes();
-
EasyMock.expect(request.getContext("application")).andReturn(applicationScope)
+ expect(request.getContext("application")).andReturn(applicationScope)
.anyTimes();
- EasyMock.expect(request.getAvailableScopes()).andReturn(
+ expect(request.getAvailableScopes()).andReturn(
new String[] { "request", "session", "application"
}).anyTimes();
- ApplicationContext applicationContext = EasyMock
- .createMock(ApplicationContext.class);
- EasyMock.expect(request.getApplicationContext()).andReturn(
+ applicationContext = createMock(ApplicationContext.class);
+ expect(request.getApplicationContext()).andReturn(
applicationContext).anyTimes();
- EasyMock.replay(request, applicationContext);
+ replay(request, applicationContext);
+ }
+
+ /**
+ * Tests {...@link MVELAttributeEvaluator#evaluate(String, Request)}.
+ */
+ @Test(expected=IllegalArgumentException.class)
+ public void testEvaluateNull() {
+ evaluator.evaluate((String) null, request);
+ verify(request, applicationContext);
}
/**
* Tests
* {...@link MVELAttributeEvaluator#evaluate(Attribute, Request)}.
*/
+ @Test
public void testEvaluate() {
Attribute attribute = new Attribute();
attribute.setExpressionObject(new Expression("requestScope.object1"));
@@ -127,11 +138,13 @@ public class MVELAttributeEvaluatorTest
attribute.setValue("object1");
assertEquals("The value has been evaluated", "object1", evaluator
.evaluate(attribute, request));
+ verify(request, applicationContext);
}
/**
* Tests {...@link MVELAttributeEvaluator#evaluate(String, Request)}.
*/
+ @Test
public void testEvaluateString() {
String expression = "requestScope.object1";
assertEquals("The value is not correct", "value", evaluator.evaluate(
@@ -157,6 +170,7 @@ public class MVELAttributeEvaluatorTest
expression = "'String literal'";
assertEquals("The value is not correct", "String literal", evaluator
.evaluate(expression, request));
+ verify(request, applicationContext);
}
/**
Added:
tiles/sandbox/trunk/tiles3/tiles-mvel/src/test/java/org/apache/tiles/mvel/ReadOnlyVariableResolverFactoryTest.java
URL:
http://svn.apache.org/viewvc/tiles/sandbox/trunk/tiles3/tiles-mvel/src/test/java/org/apache/tiles/mvel/ReadOnlyVariableResolverFactoryTest.java?rev=951854&view=auto
==============================================================================
---
tiles/sandbox/trunk/tiles3/tiles-mvel/src/test/java/org/apache/tiles/mvel/ReadOnlyVariableResolverFactoryTest.java
(added)
+++
tiles/sandbox/trunk/tiles3/tiles-mvel/src/test/java/org/apache/tiles/mvel/ReadOnlyVariableResolverFactoryTest.java
Sun Jun 6 11:05:32 2010
@@ -0,0 +1,166 @@
+package org.apache.tiles.mvel;
+
+import static org.easymock.EasyMock.*;
+import static org.easymock.classextension.EasyMock.*;
+import static org.junit.Assert.*;
+
+import org.apache.tiles.context.TilesRequestContextHolder;
+import org.apache.tiles.request.ApplicationContext;
+import org.apache.tiles.request.Request;
+import org.junit.Before;
+import org.junit.Test;
+import org.mvel2.UnresolveablePropertyException;
+import org.mvel2.integration.VariableResolver;
+import org.mvel2.integration.VariableResolverFactory;
+
+
+public class ReadOnlyVariableResolverFactoryTest {
+
+ /**
+ * The Tiles request.
+ */
+ private Request request;
+
+ /**
+ * The Tiles application context.
+ */
+ private ApplicationContext applicationContext;
+
+ /**
+ * The object to test.
+ */
+ private ReadOnlyVariableResolverFactory factory;
+
+ /**
+ * Sets up the object.
+ */
+ @Before
+ public void setUp() {
+ request = createMock(Request.class);
+ expect(request.getAvailableScopes()).andReturn(new String[]{"request",
+ "session", "application"}).anyTimes();
+ TilesRequestContextHolder holder = new TilesRequestContextHolder();
+ holder.setTilesRequestContext(request);
+ applicationContext = createMock(ApplicationContext.class);
+ factory =
createMockBuilder(ReadOnlyVariableResolverFactory.class).withConstructor(holder).createMock();
+ }
+
+ /**
+ * Test method for {...@link
ScopeVariableResolverFactory#createVariable(String, Object)}.
+ */
+ @Test(expected = UnsupportedOperationException.class)
+ public void testCreateVariableStringObject() {
+ replay(factory, request, applicationContext);
+ try {
+ factory.createVariable("myName", "myValue");
+ } finally {
+ verify(factory, request, applicationContext);
+ }
+ }
+
+ /**
+ * Test method for {...@link
ScopeVariableResolverFactory#createVariable(String, Object)}.
+ */
+ @Test
+ public void testCreateVariableStringObjectNextFactory() {
+ VariableResolverFactory nextFactory =
createMock(VariableResolverFactory.class);
+ VariableResolver resolver = createMock(VariableResolver.class);
+
+ expect(nextFactory.createVariable("myName",
"myValue")).andReturn(resolver);
+
+ replay(factory, request, applicationContext, nextFactory, resolver);
+ factory.setNextFactory(nextFactory);
+ assertEquals(resolver, factory.createVariable("myName", "myValue"));
+ verify(factory, request, applicationContext, nextFactory, resolver);
+ }
+
+ /**
+ * Test method for {...@link
ScopeVariableResolverFactory#createVariable(String, Object, Class)}.
+ */
+ @Test(expected = UnsupportedOperationException.class)
+ public void testCreateVariableStringObjectClassOfQ() {
+ replay(factory, request, applicationContext);
+ try {
+ factory.createVariable("myName", "myValue", String.class);
+ } finally {
+ verify(factory, request, applicationContext);
+ }
+ }
+
+ /**
+ * Test method for {...@link
ScopeVariableResolverFactory#createVariable(String, Object, Class)}.
+ */
+ @Test
+ public void testCreateVariableStringObjectClassNextFactory() {
+ VariableResolverFactory nextFactory =
createMock(VariableResolverFactory.class);
+ VariableResolver resolver = createMock(VariableResolver.class);
+
+ expect(nextFactory.createVariable("myName", "myValue",
String.class)).andReturn(resolver);
+
+ replay(factory, request, applicationContext, nextFactory, resolver);
+ factory.setNextFactory(nextFactory);
+ assertEquals(resolver, factory.createVariable("myName", "myValue",
String.class));
+ verify(factory, request, applicationContext, nextFactory, resolver);
+ }
+
+ /**
+ * Test method for {...@link
ScopeVariableResolverFactory#isResolveable(String)}.
+ */
+ @Test
+ public void testIsResolveable() {
+ expect(factory.isTarget("whatever")).andReturn(true);
+
+ replay(factory, request, applicationContext);
+ assertTrue(factory.isResolveable("whatever"));
+ verify(factory, request, applicationContext);
+ }
+
+ /**
+ * Test method for {...@link
ScopeVariableResolverFactory#getVariableResolver(String)}.
+ */
+ @Test
+ public void testGetVariableResolver() {
+ VariableResolverFactory nextFactory =
createMock(VariableResolverFactory.class);
+ VariableResolver nextResolver = createMock(VariableResolver.class);
+ VariableResolver requestResolver = createMock(VariableResolver.class);
+ VariableResolver applicationResolver =
createMock(VariableResolver.class);
+
expect(nextFactory.getVariableResolver("other")).andReturn(nextResolver);
+ expect(nextFactory.isResolveable("other")).andReturn(true);
+ expect(factory.isTarget("requestScope")).andReturn(true).anyTimes();
+
expect(factory.isTarget("applicationScope")).andReturn(true).anyTimes();
+ expect(factory.isTarget("other")).andReturn(false).anyTimes();
+
expect(factory.createVariableResolver("requestScope")).andReturn(requestResolver);
+
expect(factory.createVariableResolver("applicationScope")).andReturn(applicationResolver);
+
+ replay(factory, request, applicationContext, nextFactory,
nextResolver, requestResolver, applicationResolver);
+ factory.setNextFactory(nextFactory);
+ VariableResolver resolver =
factory.getVariableResolver("requestScope");
+ assertEquals(requestResolver, resolver);
+ resolver = factory.getVariableResolver("requestScope"); // again to
test caching
+ assertEquals(requestResolver, resolver);
+ resolver = factory.getVariableResolver("applicationScope");
+ assertEquals(applicationResolver, resolver);
+ resolver = factory.getVariableResolver("other");
+ assertEquals(nextResolver, resolver);
+ verify(factory, request, applicationContext, nextFactory,
nextResolver, requestResolver, applicationResolver);
+ }
+
+ /**
+ * Test method for {...@link
ScopeVariableResolverFactory#getVariableResolver(String)}.
+ */
+ @Test(expected=UnresolveablePropertyException.class)
+ public void testGetVariableResolverNotResolvable() {
+ VariableResolverFactory nextFactory =
createMock(VariableResolverFactory.class);
+
+ expect(factory.isTarget("other")).andReturn(false).anyTimes();
+ expect(nextFactory.isResolveable("other")).andReturn(false);
+
+ replay(factory, request, applicationContext, nextFactory);
+ try {
+ factory.setNextFactory(nextFactory);
+ factory.getVariableResolver("other");
+ } finally {
+ verify(factory, request, applicationContext, nextFactory);
+ }
+ }
+}
Propchange:
tiles/sandbox/trunk/tiles3/tiles-mvel/src/test/java/org/apache/tiles/mvel/ReadOnlyVariableResolverFactoryTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
tiles/sandbox/trunk/tiles3/tiles-mvel/src/test/java/org/apache/tiles/mvel/ReadOnlyVariableResolverFactoryTest.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added:
tiles/sandbox/trunk/tiles3/tiles-mvel/src/test/java/org/apache/tiles/mvel/ReadOnlyVariableResolverTest.java
URL:
http://svn.apache.org/viewvc/tiles/sandbox/trunk/tiles3/tiles-mvel/src/test/java/org/apache/tiles/mvel/ReadOnlyVariableResolverTest.java?rev=951854&view=auto
==============================================================================
---
tiles/sandbox/trunk/tiles3/tiles-mvel/src/test/java/org/apache/tiles/mvel/ReadOnlyVariableResolverTest.java
(added)
+++
tiles/sandbox/trunk/tiles3/tiles-mvel/src/test/java/org/apache/tiles/mvel/ReadOnlyVariableResolverTest.java
Sun Jun 6 11:05:32 2010
@@ -0,0 +1,70 @@
+/**
+ *
+ */
+package org.apache.tiles.mvel;
+
+import static org.easymock.classextension.EasyMock.*;
+import static org.junit.Assert.*;
+
+import
org.apache.tiles.mvel.ReadOnlyVariableResolverFactory.ReadOnlyVariableResolver;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Tests {...@link ReadOnlyVariableResolver}.
+ *
+ * @version $Rev$ $Date$
+ */
+public class ReadOnlyVariableResolverTest {
+
+ private ReadOnlyVariableResolver resolver;
+
+ /**
+ * Sets up the test.
+ */
+ @Before
+ public void setUp() {
+ resolver =
createMockBuilder(ReadOnlyVariableResolver.class).withConstructor("name").createMock();
+ }
+
+ /**
+ * Test method for {...@link
org.apache.tiles.mvel.ReadOnlyVariableResolverFactory.ReadOnlyVariableResolver#getFlags()}.
+ */
+ @Test
+ public void testGetFlags() {
+ replay(resolver);
+ assertEquals(0, resolver.getFlags());
+ verify(resolver);
+ }
+
+ /**
+ * Test method for {...@link
org.apache.tiles.mvel.ReadOnlyVariableResolverFactory.ReadOnlyVariableResolver#getName()}.
+ */
+ @Test
+ public void testGetName() {
+ replay(resolver);
+ assertEquals("name", resolver.getName());
+ verify(resolver);
+ }
+
+ /**
+ * Test method for {...@link
org.apache.tiles.mvel.ReadOnlyVariableResolverFactory.ReadOnlyVariableResolver#setStaticType(java.lang.Class)}.
+ */
+ @Test
+ public void testSetStaticType() {
+ replay(resolver);
+ resolver.setStaticType(Object.class);
+ verify(resolver);
+ }
+
+ /**
+ * Test method for {...@link
org.apache.tiles.mvel.ReadOnlyVariableResolverFactory.ReadOnlyVariableResolver#setValue(java.lang.Object)}.
+ */
+ @Test(expected=UnsupportedOperationException.class)
+ public void testSetValue() {
+ replay(resolver);
+ resolver.setValue("whatever");
+ verify(resolver);
+ }
+
+}
Propchange:
tiles/sandbox/trunk/tiles3/tiles-mvel/src/test/java/org/apache/tiles/mvel/ReadOnlyVariableResolverTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
tiles/sandbox/trunk/tiles3/tiles-mvel/src/test/java/org/apache/tiles/mvel/ReadOnlyVariableResolverTest.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Modified:
tiles/sandbox/trunk/tiles3/tiles-mvel/src/test/java/org/apache/tiles/mvel/ScopeVariableResolverFactoryTest.java
URL:
http://svn.apache.org/viewvc/tiles/sandbox/trunk/tiles3/tiles-mvel/src/test/java/org/apache/tiles/mvel/ScopeVariableResolverFactoryTest.java?rev=951854&r1=951853&r2=951854&view=diff
==============================================================================
---
tiles/sandbox/trunk/tiles3/tiles-mvel/src/test/java/org/apache/tiles/mvel/ScopeVariableResolverFactoryTest.java
(original)
+++
tiles/sandbox/trunk/tiles3/tiles-mvel/src/test/java/org/apache/tiles/mvel/ScopeVariableResolverFactoryTest.java
Sun Jun 6 11:05:32 2010
@@ -1,12 +1,8 @@
package org.apache.tiles.mvel;
-import static org.easymock.EasyMock.expect;
-import static org.easymock.classextension.EasyMock.createMock;
-import static org.easymock.classextension.EasyMock.replay;
-import static org.easymock.classextension.EasyMock.verify;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import static org.easymock.EasyMock.*;
+import static org.easymock.classextension.EasyMock.*;
+import static org.junit.Assert.*;
import java.util.HashMap;
import java.util.Map;
@@ -14,7 +10,6 @@ import java.util.Map;
import org.apache.tiles.context.TilesRequestContextHolder;
import org.apache.tiles.request.ApplicationContext;
import org.apache.tiles.request.Request;
-import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.mvel2.integration.VariableResolver;
@@ -44,7 +39,7 @@ public class ScopeVariableResolverFactor
public void setUp() {
request = createMock(Request.class);
expect(request.getAvailableScopes()).andReturn(new String[]{"request",
- "session", "application"}).anyTimes();
+ "session", "application"}).anyTimes();
TilesRequestContextHolder holder = new TilesRequestContextHolder();
holder.setTilesRequestContext(request);
applicationContext = createMock(ApplicationContext.class);
@@ -52,45 +47,7 @@ public class ScopeVariableResolverFactor
}
/**
- * Tears down the object.
- */
- @After
- public void tearDown() {
- verify(request, applicationContext);
- }
-
- /**
- * Test method for {...@link
TilesContextVariableResolverFactory#createVariable(String, Object)}.
- */
- @Test(expected = UnsupportedOperationException.class)
- public void testCreateVariableStringObject() {
- replay(request, applicationContext);
- factory.createVariable("myName", "myValue");
- }
-
- /**
- * Test method for {...@link
TilesContextVariableResolverFactory#createVariable(String, Object, Class)}.
- */
- @Test(expected = UnsupportedOperationException.class)
- public void testCreateVariableStringObjectClassOfQ() {
- replay(request, applicationContext);
- factory.createVariable("myName", "myValue", String.class);
- }
-
- /**
- * Test method for {...@link
TilesContextVariableResolverFactory#isResolveable(String)}.
- */
- @Test
- public void testIsResolveable() {
- replay(request, applicationContext);
- assertFalse(factory.isResolveable("header"));
- assertTrue(factory.isResolveable("requestScope"));
- assertTrue(factory.isResolveable("applicationScope"));
- assertFalse(factory.isResolveable("blah"));
- }
-
- /**
- * Test method for {...@link
TilesContextVariableResolverFactory#isTarget(String)}.
+ * Test method for {...@link
ScopeVariableResolverFactory#isTarget(String)}.
*/
@Test
public void testIsTarget() {
@@ -99,25 +56,33 @@ public class ScopeVariableResolverFactor
assertTrue(factory.isTarget("requestScope"));
assertTrue(factory.isTarget("applicationScope"));
assertFalse(factory.isTarget("blah"));
+ verify(request, applicationContext);
}
/**
- * Test method for {...@link
org.mvel2.integration.impl.BaseVariableResolverFactory#getVariableResolver(String)}.
+ * Test method for {...@link
ScopeVariableResolverFactory#createVariableResolver(String)}.
*/
@Test
- public void testGetVariableResolver() {
+ public void testCreateVariableResolver() {
Map<String, Object> requestScope = new HashMap<String, Object>();
requestScope.put("one", 1);
- expect(request.getContext("request")).andReturn(requestScope);
+ expect(request.getContext("request")).andReturn(requestScope).times(2);
Map<String, Object> applicationScope = new HashMap<String, Object>();
applicationScope.put("two", 2);
expect(request.getContext("application")).andReturn(applicationScope);
- replay(request, applicationContext);
- VariableResolver resolver =
factory.getVariableResolver("requestScope");
+ replay(request, applicationContext);
+ VariableResolver resolver =
factory.createVariableResolver("requestScope");
+ assertEquals(0, resolver.getFlags());
+ assertEquals("requestScope", resolver.getName());
+ assertEquals(Map.class, resolver.getType());
assertEquals(requestScope, resolver.getValue());
- resolver = factory.getVariableResolver("applicationScope");
+ resolver.setStaticType(Object.class); // To complete coverage
+ assertEquals(Map.class, resolver.getType());
+ resolver = factory.createVariableResolver("requestScope"); // again to
test caching
+ assertEquals(requestScope, resolver.getValue());
+ resolver = factory.createVariableResolver("applicationScope");
assertEquals(applicationScope, resolver.getValue());
+ verify(request, applicationContext);
}
-
}
Modified:
tiles/sandbox/trunk/tiles3/tiles-mvel/src/test/java/org/apache/tiles/mvel/TilesContextBeanVariableResolverFactoryTest.java
URL:
http://svn.apache.org/viewvc/tiles/sandbox/trunk/tiles3/tiles-mvel/src/test/java/org/apache/tiles/mvel/TilesContextBeanVariableResolverFactoryTest.java?rev=951854&r1=951853&r2=951854&view=diff
==============================================================================
---
tiles/sandbox/trunk/tiles3/tiles-mvel/src/test/java/org/apache/tiles/mvel/TilesContextBeanVariableResolverFactoryTest.java
(original)
+++
tiles/sandbox/trunk/tiles3/tiles-mvel/src/test/java/org/apache/tiles/mvel/TilesContextBeanVariableResolverFactoryTest.java
Sun Jun 6 11:05:32 2010
@@ -21,19 +21,17 @@
package org.apache.tiles.mvel;
-import static org.junit.Assert.*;
import static org.easymock.EasyMock.*;
+import static org.junit.Assert.*;
import java.util.HashMap;
import java.util.Map;
import org.apache.tiles.context.TilesRequestContextHolder;
-import org.apache.tiles.mvel.TilesContextBeanVariableResolverFactory;
import org.apache.tiles.request.ApplicationContext;
import org.apache.tiles.request.Request;
import org.junit.Before;
import org.junit.Test;
-import org.mvel2.UnresolveablePropertyException;
import org.mvel2.integration.VariableResolver;
/**
@@ -82,58 +80,10 @@ public class TilesContextBeanVariableRes
}
/**
- * Test method for {...@link
TilesContextBeanVariableResolverFactory#createVariable(String, Object)}.
- */
- @Test(expected = UnsupportedOperationException.class)
- public void testCreateVariableStringObject() {
- replay(request, applicationContext);
- factory.createVariable("myName", "myValue");
- verify(request, applicationContext);
- }
-
- /**
- * Test method for {...@link
TilesContextBeanVariableResolverFactory#createVariable(String, Object, Class)}.
- */
- @Test(expected = UnsupportedOperationException.class)
- public void testCreateVariableStringObjectClassOfQ() {
- replay(request, applicationContext);
- factory.createVariable("myName", "myValue", String.class);
- verify(request, applicationContext);
- }
-
- /**
- * Test method for {...@link
TilesContextBeanVariableResolverFactory#isResolveable(String)}.
- */
- @Test
- public void testIsResolveable() {
- Map<String, Object> requestScope = new HashMap<String, Object>();
- requestScope.put("one", 1);
- expect(request.getContext("request")).andReturn(requestScope).times(
- EXPECTED_REQUEST_CALLS);
- Map<String, Object> applicationScope = new HashMap<String, Object>();
- applicationScope.put("two", 2);
- Map<String, Object> sessionScope = new HashMap<String, Object>();
- sessionScope.put("three", "three");
- expect(request.getContext("session")).andReturn(sessionScope).times(
- EXPECTED_SESSION_CALLS);
- expect(request.getAvailableScopes()).andReturn(
- new String[] { "request", "session",
"application" })
- .anyTimes();
-
expect(request.getContext("application")).andReturn(applicationScope).anyTimes();
- replay(request, applicationContext);
-
- assertTrue(factory.isResolveable("one"));
- assertTrue(factory.isResolveable("two"));
- assertTrue(factory.isResolveable("three"));
- assertFalse(factory.isResolveable("four"));
- verify(request, applicationContext);
- }
-
- /**
- * Test method for {...@link
TilesContextBeanVariableResolverFactory#getVariableResolver(String)}.
+ * Test method for {...@link
TilesContextBeanVariableResolverFactory#createVariableResolver(String)}.
*/
@Test
- public void testGetVariableResolverString() {
+ public void testCreateVariableResolver() {
Map<String, Object> requestScope = new HashMap<String, Object>();
requestScope.put("one", 1);
expect(request.getContext("request")).andReturn(requestScope).anyTimes();
@@ -142,44 +92,26 @@ public class TilesContextBeanVariableRes
Map<String, Object> sessionScope = new HashMap<String, Object>();
sessionScope.put("three", "three");
expect(request.getContext("session")).andReturn(sessionScope).anyTimes();
- expect(request.getAvailableScopes()).andReturn(
- new String[] { "request", "session",
"application" })
- .anyTimes();
+ expect(request.getAvailableScopes()).andReturn(
+ new String[] { "request", "session", "application" })
+ .anyTimes();
expect(request.getContext("application")).andReturn(applicationScope).anyTimes();
replay(request, applicationContext);
- VariableResolver resolver = factory.getVariableResolver("one");
+ VariableResolver resolver = factory.createVariableResolver("one");
assertEquals(1, resolver.getValue());
- resolver = factory.getVariableResolver("two");
+ assertEquals(Integer.class, resolver.getType());
+ resolver = factory.createVariableResolver("two");
assertEquals(2, resolver.getValue());
- resolver = factory.getVariableResolver("three");
+ resolver = factory.createVariableResolver("three");
assertEquals("three", resolver.getValue());
+ resolver = factory.createVariableResolver("four");
+ assertEquals(Object.class, resolver.getType());
+ assertNull(resolver.getValue());
verify(request, applicationContext);
}
/**
- * Test method for {...@link
TilesContextBeanVariableResolverFactory#getVariableResolver(String)}.
- */
- @Test(expected = UnresolveablePropertyException.class)
- public void testGetVariableResolverStringException() {
- Map<String, Object> requestScope = new HashMap<String, Object>();
- requestScope.put("one", 1);
-
expect(request.getContext("request")).andReturn(requestScope).anyTimes();
- Map<String, Object> applicationScope = new HashMap<String, Object>();
- applicationScope.put("two", 2);
- Map<String, Object> sessionScope = new HashMap<String, Object>();
- sessionScope.put("three", "three");
-
expect(request.getContext("session")).andReturn(sessionScope).anyTimes();
- expect(request.getAvailableScopes()).andReturn(
- new String[] { "request", "session",
"application" })
- .anyTimes();
-
expect(request.getContext("application")).andReturn(applicationScope).anyTimes();
- replay(request, applicationContext);
-
- factory.getVariableResolver("four");
- }
-
- /**
* Test method for {...@link
TilesContextBeanVariableResolverFactory#isTarget(String)}.
*/
@Test
@@ -194,9 +126,9 @@ public class TilesContextBeanVariableRes
sessionScope.put("three", "three");
expect(request.getContext("session")).andReturn(sessionScope).times(
EXPECTED_SESSION_CALLS);
- expect(request.getAvailableScopes()).andReturn(
- new String[] { "request", "session",
"application" })
- .anyTimes();
+ expect(request.getAvailableScopes()).andReturn(
+ new String[] { "request", "session", "application" })
+ .anyTimes();
expect(request.getContext("application")).andReturn(applicationScope).anyTimes();
replay(request, applicationContext);
Modified:
tiles/sandbox/trunk/tiles3/tiles-mvel/src/test/java/org/apache/tiles/mvel/TilesContextVariableResolverFactoryTest.java
URL:
http://svn.apache.org/viewvc/tiles/sandbox/trunk/tiles3/tiles-mvel/src/test/java/org/apache/tiles/mvel/TilesContextVariableResolverFactoryTest.java?rev=951854&r1=951853&r2=951854&view=diff
==============================================================================
---
tiles/sandbox/trunk/tiles3/tiles-mvel/src/test/java/org/apache/tiles/mvel/TilesContextVariableResolverFactoryTest.java
(original)
+++
tiles/sandbox/trunk/tiles3/tiles-mvel/src/test/java/org/apache/tiles/mvel/TilesContextVariableResolverFactoryTest.java
Sun Jun 6 11:05:32 2010
@@ -79,36 +79,6 @@ public class TilesContextVariableResolve
}
/**
- * Test method for {...@link
TilesContextVariableResolverFactory#createVariable(String, Object)}.
- */
- @Test(expected = UnsupportedOperationException.class)
- public void testCreateVariableStringObject() {
- replay(request, applicationContext);
- factory.createVariable("myName", "myValue");
- }
-
- /**
- * Test method for {...@link
TilesContextVariableResolverFactory#createVariable(String, Object, Class)}.
- */
- @Test(expected = UnsupportedOperationException.class)
- public void testCreateVariableStringObjectClassOfQ() {
- replay(request, applicationContext);
- factory.createVariable("myName", "myValue", String.class);
- }
-
- /**
- * Test method for {...@link
TilesContextVariableResolverFactory#isResolveable(String)}.
- */
- @Test
- public void testIsResolveable() {
- replay(request, applicationContext);
- assertTrue(factory.isResolveable("header"));
- assertFalse(factory.isResolveable("requestScope"));
- assertTrue(factory.isResolveable("applicationScope"));
- assertFalse(factory.isResolveable("blah"));
- }
-
- /**
* Test method for {...@link
TilesContextVariableResolverFactory#isTarget(String)}.
*/
@Test
@@ -121,20 +91,29 @@ public class TilesContextVariableResolve
}
/**
- * Test method for {...@link
org.mvel2.integration.impl.BaseVariableResolverFactory#getVariableResolver(String)}.
+ * Test method for {...@link
TilesContextVariableResolverFactory#createVariableResolver(String)}.
*/
+ @SuppressWarnings("unchecked")
@Test
- public void testGetVariableResolver() {
+ public void testCreateVariableResolver() {
+ Map<String, String> header = createMock(Map.class);
Map<String, Object> requestScope = new HashMap<String, Object>();
requestScope.put("one", 1);
Map<String, Object> applicationScope = new HashMap<String, Object>();
applicationScope.put("two", 2);
+
expect(request.getApplicationContext()).andReturn(applicationContext);
expect(applicationContext.getApplicationScope()).andReturn(applicationScope);
- replay(request, applicationContext);
+ expect(request.getHeader()).andReturn(header);
+
+ replay(request, applicationContext, header);
- VariableResolver resolver =
factory.getVariableResolver("applicationScope");
+ VariableResolver resolver = factory.createVariableResolver("header");
+ assertEquals(Map.class, resolver.getType());
+ assertEquals(header, resolver.getValue());
+ resolver = factory.createVariableResolver("applicationScope");
assertEquals(applicationScope, resolver.getValue());
- verify(request, applicationContext);
+ assertEquals(Map.class, resolver.getType());
+ verify(header);
}
}