Author: apetrelli
Date: Fri Nov 26 19:54:10 2010
New Revision: 1039535
URL: http://svn.apache.org/viewvc?rev=1039535&view=rev
Log:
TILESSB-11
Completed tests for tiles-autotag-velocity-runtime.
Added:
tiles/sandbox/trunk/tiles-autotag/tiles-autotag-velocity-runtime/src/test/java/org/apache/tiles/autotag/velocity/runtime/BodyDirectiveTest.java
- copied, changed from r982374,
tiles/sandbox/trunk/tiles-autotag/tiles-autotag-velocity-runtime/src/test/java/org/apache/tiles/autotag/velocity/runtime/BodyBlockDirectiveTest.java
tiles/sandbox/trunk/tiles-autotag/tiles-autotag-velocity-runtime/src/test/java/org/apache/tiles/autotag/velocity/runtime/BodylessDirectiveTest.java
(with props)
tiles/sandbox/trunk/tiles-autotag/tiles-autotag-velocity-runtime/src/test/java/org/apache/tiles/autotag/velocity/runtime/VelocityModelBodyTest.java
(with props)
tiles/sandbox/trunk/tiles-autotag/tiles-autotag-velocity-runtime/src/test/java/org/apache/tiles/autotag/velocity/runtime/VelocityUtilTest.java
(with props)
Removed:
tiles/sandbox/trunk/tiles-autotag/tiles-autotag-velocity-runtime/src/test/java/org/apache/tiles/autotag/velocity/runtime/BodyBlockDirectiveTest.java
Modified:
tiles/sandbox/trunk/tiles-autotag/tiles-autotag-velocity-runtime/pom.xml
tiles/sandbox/trunk/tiles-autotag/tiles-autotag-velocity-runtime/src/main/java/org/apache/tiles/autotag/velocity/runtime/BodyDirective.java
tiles/sandbox/trunk/tiles-autotag/tiles-autotag-velocity-runtime/src/main/java/org/apache/tiles/autotag/velocity/runtime/BodylessDirective.java
tiles/sandbox/trunk/tiles-autotag/tiles-autotag-velocity-runtime/src/main/java/org/apache/tiles/autotag/velocity/runtime/VelocityUtil.java
Modified:
tiles/sandbox/trunk/tiles-autotag/tiles-autotag-velocity-runtime/pom.xml
URL:
http://svn.apache.org/viewvc/tiles/sandbox/trunk/tiles-autotag/tiles-autotag-velocity-runtime/pom.xml?rev=1039535&r1=1039534&r2=1039535&view=diff
==============================================================================
--- tiles/sandbox/trunk/tiles-autotag/tiles-autotag-velocity-runtime/pom.xml
(original)
+++ tiles/sandbox/trunk/tiles-autotag/tiles-autotag-velocity-runtime/pom.xml
Fri Nov 26 19:54:10 2010
@@ -33,14 +33,14 @@
</dependency>
<dependency>
<groupId>org.easymock</groupId>
- <artifactId>easymockclassextension</artifactId>
- <version>2.5.2</version>
+ <artifactId>easymock</artifactId>
+ <version>3.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
- <version>4.8.1</version>
+ <version>4.8.2</version>
<scope>test</scope>
</dependency>
</dependencies>
Modified:
tiles/sandbox/trunk/tiles-autotag/tiles-autotag-velocity-runtime/src/main/java/org/apache/tiles/autotag/velocity/runtime/BodyDirective.java
URL:
http://svn.apache.org/viewvc/tiles/sandbox/trunk/tiles-autotag/tiles-autotag-velocity-runtime/src/main/java/org/apache/tiles/autotag/velocity/runtime/BodyDirective.java?rev=1039535&r1=1039534&r2=1039535&view=diff
==============================================================================
---
tiles/sandbox/trunk/tiles-autotag/tiles-autotag-velocity-runtime/src/main/java/org/apache/tiles/autotag/velocity/runtime/BodyDirective.java
(original)
+++
tiles/sandbox/trunk/tiles-autotag/tiles-autotag-velocity-runtime/src/main/java/org/apache/tiles/autotag/velocity/runtime/BodyDirective.java
Fri Nov 26 19:54:10 2010
@@ -44,7 +44,7 @@ import org.apache.velocity.tools.view.Vi
* body.
*
* @version $Rev$ $Date$
- * @since 2.2.2
+ * @since 3.0.0
*/
public abstract class BodyDirective extends Directive {
Modified:
tiles/sandbox/trunk/tiles-autotag/tiles-autotag-velocity-runtime/src/main/java/org/apache/tiles/autotag/velocity/runtime/BodylessDirective.java
URL:
http://svn.apache.org/viewvc/tiles/sandbox/trunk/tiles-autotag/tiles-autotag-velocity-runtime/src/main/java/org/apache/tiles/autotag/velocity/runtime/BodylessDirective.java?rev=1039535&r1=1039534&r2=1039535&view=diff
==============================================================================
---
tiles/sandbox/trunk/tiles-autotag/tiles-autotag-velocity-runtime/src/main/java/org/apache/tiles/autotag/velocity/runtime/BodylessDirective.java
(original)
+++
tiles/sandbox/trunk/tiles-autotag/tiles-autotag-velocity-runtime/src/main/java/org/apache/tiles/autotag/velocity/runtime/BodylessDirective.java
Fri Nov 26 19:54:10 2010
@@ -42,7 +42,7 @@ import org.apache.velocity.tools.view.Vi
* body.
*
* @version $Rev$ $Date$
- * @since 2.2.2
+ * @since 3.0.0
*/
public abstract class BodylessDirective extends Directive {
Modified:
tiles/sandbox/trunk/tiles-autotag/tiles-autotag-velocity-runtime/src/main/java/org/apache/tiles/autotag/velocity/runtime/VelocityUtil.java
URL:
http://svn.apache.org/viewvc/tiles/sandbox/trunk/tiles-autotag/tiles-autotag-velocity-runtime/src/main/java/org/apache/tiles/autotag/velocity/runtime/VelocityUtil.java?rev=1039535&r1=1039534&r2=1039535&view=diff
==============================================================================
---
tiles/sandbox/trunk/tiles-autotag/tiles-autotag-velocity-runtime/src/main/java/org/apache/tiles/autotag/velocity/runtime/VelocityUtil.java
(original)
+++
tiles/sandbox/trunk/tiles-autotag/tiles-autotag-velocity-runtime/src/main/java/org/apache/tiles/autotag/velocity/runtime/VelocityUtil.java
Fri Nov 26 19:54:10 2010
@@ -21,14 +21,9 @@
package org.apache.tiles.autotag.velocity.runtime;
-import java.io.IOException;
-import java.io.StringWriter;
-import java.io.Writer;
import java.util.Map;
import org.apache.velocity.context.InternalContextAdapter;
-import org.apache.velocity.runtime.Renderable;
-import org.apache.velocity.runtime.parser.node.ASTBlock;
import org.apache.velocity.runtime.parser.node.ASTMap;
import org.apache.velocity.runtime.parser.node.Node;
@@ -36,98 +31,24 @@ import org.apache.velocity.runtime.parse
* Utilities for Velocity usage in Tiles.
*
* @version $Rev$ $Date$
- * @since 2.2.0
+ * @since 3.0.0
*/
public final class VelocityUtil {
/**
- * A renderable object that does not render anything.
- *
- * @since 2.2.0
- */
- public static final Renderable EMPTY_RENDERABLE;
-
- static {
- EMPTY_RENDERABLE = new Renderable() {
-
- @Override
- public String toString() {
- return "";
- }
-
- public boolean render(InternalContextAdapter context, Writer
writer) {
- // Does nothing, really!
- return true;
- }
- };
- }
-
- /**
* Private constructor to avoid instantiation.
*/
private VelocityUtil() {
}
/**
- * Null-safe conversion from Boolean to boolean.
- *
- * @param obj The Boolean object.
- * @param defaultValue This value will be returned if <code>obj</code> is
null.
- * @return The boolean value of <code>obj</code> or, if null,
<code>defaultValue</code>.
- * @since 2.2.0
- */
- public static boolean toSimpleBoolean(Boolean obj, boolean defaultValue) {
- return obj != null ? obj : defaultValue;
- }
-
- /**
- * Evaluates the body (child node at position 1) and returns it as a
string.
- *
- * @param context The Velocity context.
- * @param node The node to use.
- * @return The evaluated body.
- * @throws IOException If something goes wrong.
- * @since 2.2.2
- */
- public static String getBodyAsString(InternalContextAdapter context, Node
node)
- throws IOException {
- ASTBlock block = (ASTBlock) node.jjtGetChild(1);
- StringWriter stringWriter = new StringWriter();
- block.render(context, stringWriter);
- stringWriter.close();
- String body = stringWriter.toString();
- if (body != null) {
- body = body.replaceAll("^\\s*|\\s*$", "");
- if (body.length() <= 0) {
- body = null;
- }
- }
- return body;
- }
-
- /**
- * Evaluates the body writing in the passed writer.
- *
- * @param context The Velocity context.
- * @param writer The writer to write into.
- * @param node The node to use.
- * @throws IOException If something goes wrong.
- * @since 2.2.2
- */
- public static void evaluateBody(InternalContextAdapter context, Writer
writer,
- Node node) throws IOException {
- ASTBlock block = (ASTBlock) node.jjtGetChild(1);
- block.render(context, writer);
- }
-
- /**
* Extracts the parameters from the directives, by getting the child at
* position 0 supposing it is a map.
*
* @param context The Velocity context.
* @param node The node to use.
* @return The extracted parameters.
- * @since 2.2.2
+ * @since 3.0.0
*/
@SuppressWarnings("unchecked")
public static Map<String, Object> getParameters(InternalContextAdapter
context,
Copied:
tiles/sandbox/trunk/tiles-autotag/tiles-autotag-velocity-runtime/src/test/java/org/apache/tiles/autotag/velocity/runtime/BodyDirectiveTest.java
(from r982374,
tiles/sandbox/trunk/tiles-autotag/tiles-autotag-velocity-runtime/src/test/java/org/apache/tiles/autotag/velocity/runtime/BodyBlockDirectiveTest.java)
URL:
http://svn.apache.org/viewvc/tiles/sandbox/trunk/tiles-autotag/tiles-autotag-velocity-runtime/src/test/java/org/apache/tiles/autotag/velocity/runtime/BodyDirectiveTest.java?p2=tiles/sandbox/trunk/tiles-autotag/tiles-autotag-velocity-runtime/src/test/java/org/apache/tiles/autotag/velocity/runtime/BodyDirectiveTest.java&p1=tiles/sandbox/trunk/tiles-autotag/tiles-autotag-velocity-runtime/src/test/java/org/apache/tiles/autotag/velocity/runtime/BodyBlockDirectiveTest.java&r1=982374&r2=1039535&rev=1039535&view=diff
==============================================================================
---
tiles/sandbox/trunk/tiles-autotag/tiles-autotag-velocity-runtime/src/test/java/org/apache/tiles/autotag/velocity/runtime/BodyBlockDirectiveTest.java
(original)
+++
tiles/sandbox/trunk/tiles-autotag/tiles-autotag-velocity-runtime/src/test/java/org/apache/tiles/autotag/velocity/runtime/BodyDirectiveTest.java
Fri Nov 26 19:54:10 2010
@@ -22,12 +22,10 @@
package org.apache.tiles.autotag.velocity.runtime;
import static org.easymock.EasyMock.*;
-import static org.easymock.classextension.EasyMock.*;
import static org.junit.Assert.*;
import java.io.IOException;
import java.io.Writer;
-import java.lang.reflect.Method;
import java.util.Map;
import javax.servlet.ServletContext;
@@ -51,7 +49,7 @@ import org.junit.Test;
*
* @version $Rev$ $Date$
*/
-public class BodyBlockDirectiveTest {
+public class BodyDirectiveTest {
/**
* The directive to test.
@@ -63,7 +61,7 @@ public class BodyBlockDirectiveTest {
*/
@Before
public void setUp() {
- directive = createMock(BodyDirective.class, new Method[0]);
+ directive = createMockBuilder(BodyDirective.class).createMock();
}
/**
Added:
tiles/sandbox/trunk/tiles-autotag/tiles-autotag-velocity-runtime/src/test/java/org/apache/tiles/autotag/velocity/runtime/BodylessDirectiveTest.java
URL:
http://svn.apache.org/viewvc/tiles/sandbox/trunk/tiles-autotag/tiles-autotag-velocity-runtime/src/test/java/org/apache/tiles/autotag/velocity/runtime/BodylessDirectiveTest.java?rev=1039535&view=auto
==============================================================================
---
tiles/sandbox/trunk/tiles-autotag/tiles-autotag-velocity-runtime/src/test/java/org/apache/tiles/autotag/velocity/runtime/BodylessDirectiveTest.java
(added)
+++
tiles/sandbox/trunk/tiles-autotag/tiles-autotag-velocity-runtime/src/test/java/org/apache/tiles/autotag/velocity/runtime/BodylessDirectiveTest.java
Fri Nov 26 19:54:10 2010
@@ -0,0 +1,113 @@
+/*
+ * $Id$
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tiles.autotag.velocity.runtime;
+
+import static org.easymock.EasyMock.*;
+import static org.junit.Assert.*;
+
+import java.io.IOException;
+import java.io.Writer;
+import java.util.Map;
+
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.tiles.request.ApplicationContext;
+import org.apache.tiles.request.util.ApplicationAccess;
+import org.apache.tiles.request.velocity.VelocityRequest;
+import org.apache.velocity.context.InternalContextAdapter;
+import org.apache.velocity.runtime.directive.DirectiveConstants;
+import org.apache.velocity.runtime.parser.node.ASTMap;
+import org.apache.velocity.runtime.parser.node.Node;
+import org.apache.velocity.tools.view.ViewToolContext;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Tests {...@link BodylessDirective}.
+ *
+ * @version $Rev$ $Date$
+ */
+public class BodylessDirectiveTest {
+
+ /**
+ * The directive to test.
+ */
+ private BodylessDirective directive;
+
+ /**
+ * @throws java.lang.Exception
+ */
+ @Before
+ public void setUp() {
+ directive = createMockBuilder(BodylessDirective.class).createMock();
+ }
+
+ /**
+ * Test method for {...@link
org.apache.tiles.velocity.template.BlockDirective#getType()}.
+ */
+ @Test
+ public void testGetType() {
+ replay(directive);
+ assertEquals(DirectiveConstants.LINE, directive.getType());
+ verify(directive);
+ }
+
+ /**
+ * Test method for {...@link BlockDirective#render(InternalContextAdapter,
Writer, Node)}.
+ * @throws IOException If something goes wrong.
+ */
+ @SuppressWarnings("unchecked")
+ @Test
+ public void testRenderInternalContextAdapterWriterNode() throws
IOException {
+ InternalContextAdapter context =
createMock(InternalContextAdapter.class);
+ Writer writer = createMock(Writer.class);
+ Node node = createMock(Node.class);
+ ViewToolContext viewContext = createMock(ViewToolContext.class);
+ HttpServletRequest request = createMock(HttpServletRequest.class);
+ HttpServletResponse response = createMock(HttpServletResponse.class);
+ ServletContext servletContext = createMock(ServletContext.class);
+ ASTMap astMap = createMock(ASTMap.class);
+ Map<String, Object> params = createMock(Map.class);
+ ApplicationContext applicationContext =
createMock(ApplicationContext.class);
+
+ expect(context.getInternalUserContext()).andReturn(viewContext);
+ expect(viewContext.getRequest()).andReturn(request);
+ expect(viewContext.getResponse()).andReturn(response);
+ expect(viewContext.getServletContext()).andReturn(servletContext);
+ expect(node.jjtGetChild(0)).andReturn(astMap);
+ expect(astMap.value(context)).andReturn(params);
+
expect(servletContext.getAttribute(ApplicationAccess.APPLICATION_CONTEXT_ATTRIBUTE))
+ .andReturn(applicationContext);
+
+ directive.execute(eq(params), isA(VelocityRequest.class));
+
+ replay(directive, context, writer, node, viewContext,
+ applicationContext, servletContext, request, response, astMap,
+ params);
+ directive.render(context, writer, node);
+ verify(directive, context, writer, node, viewContext,
+ applicationContext, servletContext, request, response, astMap,
+ params);
+ }
+}
Propchange:
tiles/sandbox/trunk/tiles-autotag/tiles-autotag-velocity-runtime/src/test/java/org/apache/tiles/autotag/velocity/runtime/BodylessDirectiveTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
tiles/sandbox/trunk/tiles-autotag/tiles-autotag-velocity-runtime/src/test/java/org/apache/tiles/autotag/velocity/runtime/BodylessDirectiveTest.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added:
tiles/sandbox/trunk/tiles-autotag/tiles-autotag-velocity-runtime/src/test/java/org/apache/tiles/autotag/velocity/runtime/VelocityModelBodyTest.java
URL:
http://svn.apache.org/viewvc/tiles/sandbox/trunk/tiles-autotag/tiles-autotag-velocity-runtime/src/test/java/org/apache/tiles/autotag/velocity/runtime/VelocityModelBodyTest.java?rev=1039535&view=auto
==============================================================================
---
tiles/sandbox/trunk/tiles-autotag/tiles-autotag-velocity-runtime/src/test/java/org/apache/tiles/autotag/velocity/runtime/VelocityModelBodyTest.java
(added)
+++
tiles/sandbox/trunk/tiles-autotag/tiles-autotag-velocity-runtime/src/test/java/org/apache/tiles/autotag/velocity/runtime/VelocityModelBodyTest.java
Fri Nov 26 19:54:10 2010
@@ -0,0 +1,48 @@
+/**
+ *
+ */
+package org.apache.tiles.autotag.velocity.runtime;
+
+import static org.easymock.EasyMock.*;
+
+import java.io.IOException;
+import java.io.Writer;
+
+import org.apache.velocity.context.InternalContextAdapter;
+import org.apache.velocity.exception.MethodInvocationException;
+import org.apache.velocity.exception.ParseErrorException;
+import org.apache.velocity.exception.ResourceNotFoundException;
+import org.apache.velocity.runtime.parser.node.ASTBlock;
+import org.junit.Test;
+
+/**
+ * Tests {...@link VelocityModelBody}.
+ *
+ * @version $Rev$ $Date$
+ */
+public class VelocityModelBodyTest {
+
+ /**
+ * Test method for {...@link
org.apache.tiles.autotag.velocity.runtime.VelocityModelBody#evaluate(java.io.Writer)}.
+ * @throws IOException If something goes wrong.
+ * @throws ParseErrorException If something goes wrong.
+ * @throws ResourceNotFoundException If something goes wrong.
+ * @throws MethodInvocationException If something goes wrong.
+ */
+ @Test
+ public void testEvaluateWriter() throws MethodInvocationException,
ResourceNotFoundException, ParseErrorException, IOException {
+ InternalContextAdapter internalContextAdapter =
createMock(InternalContextAdapter.class);
+ ASTBlock body = createMock(ASTBlock.class);
+ Writer writer = createMock(Writer.class);
+ expect(body.render(internalContextAdapter, writer)).andReturn(true);
+
+ replay(internalContextAdapter, body, writer);
+ VelocityModelBody modelBody =
createMockBuilder(VelocityModelBody.class)
+ .withConstructor(internalContextAdapter, body, writer)
+ .createMock();
+ replay(modelBody);
+ modelBody.evaluate(writer);
+ verify(internalContextAdapter, body, writer, modelBody);
+ }
+
+}
Propchange:
tiles/sandbox/trunk/tiles-autotag/tiles-autotag-velocity-runtime/src/test/java/org/apache/tiles/autotag/velocity/runtime/VelocityModelBodyTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
tiles/sandbox/trunk/tiles-autotag/tiles-autotag-velocity-runtime/src/test/java/org/apache/tiles/autotag/velocity/runtime/VelocityModelBodyTest.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added:
tiles/sandbox/trunk/tiles-autotag/tiles-autotag-velocity-runtime/src/test/java/org/apache/tiles/autotag/velocity/runtime/VelocityUtilTest.java
URL:
http://svn.apache.org/viewvc/tiles/sandbox/trunk/tiles-autotag/tiles-autotag-velocity-runtime/src/test/java/org/apache/tiles/autotag/velocity/runtime/VelocityUtilTest.java?rev=1039535&view=auto
==============================================================================
---
tiles/sandbox/trunk/tiles-autotag/tiles-autotag-velocity-runtime/src/test/java/org/apache/tiles/autotag/velocity/runtime/VelocityUtilTest.java
(added)
+++
tiles/sandbox/trunk/tiles-autotag/tiles-autotag-velocity-runtime/src/test/java/org/apache/tiles/autotag/velocity/runtime/VelocityUtilTest.java
Fri Nov 26 19:54:10 2010
@@ -0,0 +1,53 @@
+/**
+ *
+ */
+package org.apache.tiles.autotag.velocity.runtime;
+
+import static org.easymock.EasyMock.*;
+import static org.junit.Assert.*;
+
+import java.util.Map;
+
+import org.apache.velocity.context.InternalContextAdapter;
+import org.apache.velocity.runtime.parser.node.ASTMap;
+import org.apache.velocity.runtime.parser.node.Node;
+import org.junit.Test;
+
+/**
+ * Tests {...@link VelocityUtil}.
+ *
+ * @version $Rev$ $Date$
+ */
+public class VelocityUtilTest {
+
+ /**
+ * Test method for {...@link
org.apache.tiles.autotag.velocity.runtime.VelocityUtil#getParameters(org.apache.velocity.context.InternalContextAdapter,
org.apache.velocity.runtime.parser.node.Node)}.
+ */
+ @Test
+ public void testGetParameters() {
+ InternalContextAdapter context =
createMock(InternalContextAdapter.class);
+ Node node = createMock(Node.class);
+ ASTMap astMap = createMock(ASTMap.class);
+ @SuppressWarnings("unchecked")
+ Map<String, Object> params = createMock(Map.class);
+
+ expect(node.jjtGetChild(0)).andReturn(astMap);
+ expect(astMap.value(context)).andReturn(params);
+
+ replay(context, node, astMap, params);
+ assertSame(params, VelocityUtil.getParameters(context, node));
+ verify(context, node, astMap, params);
+ }
+
+ /**
+ * Test method for {...@link
org.apache.tiles.autotag.velocity.runtime.VelocityUtil#getObject(java.lang.Object,
java.lang.Object)}.
+ */
+ @Test
+ public void testGetObject() {
+ assertEquals(new Integer(1), VelocityUtil.getObject(new Integer(1),
new Integer(2)));
+ assertEquals(new Integer(1), VelocityUtil.getObject(new Integer(1),
null));
+ assertEquals(new Integer(2), VelocityUtil.getObject(null, new
Integer(2)));
+ assertNull(VelocityUtil.getObject(null, null));
+ }
+
+}
Propchange:
tiles/sandbox/trunk/tiles-autotag/tiles-autotag-velocity-runtime/src/test/java/org/apache/tiles/autotag/velocity/runtime/VelocityUtilTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
tiles/sandbox/trunk/tiles-autotag/tiles-autotag-velocity-runtime/src/test/java/org/apache/tiles/autotag/velocity/runtime/VelocityUtilTest.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL