You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tiles.apache.org by ap...@apache.org on 2009/10/29 15:14:49 UTC

svn commit: r830956 - in /tiles/sandbox/trunk/tiles3/tiles-api/src: main/java/org/apache/tiles/ main/java/org/apache/tiles/access/ test/java/org/apache/tiles/

Author: apetrelli
Date: Thu Oct 29 14:14:48 2009
New Revision: 830956

URL: http://svn.apache.org/viewvc?rev=830956&view=rev
Log:
TILESSB-10
Removed some useless non-deprecated methods.

TILESSB-11
Completed tests for Attribute and ArrayStack

Added:
    tiles/sandbox/trunk/tiles3/tiles-api/src/test/java/org/apache/tiles/ArrayStackTest.java   (with props)
Modified:
    tiles/sandbox/trunk/tiles3/tiles-api/src/main/java/org/apache/tiles/Attribute.java
    tiles/sandbox/trunk/tiles3/tiles-api/src/main/java/org/apache/tiles/Definition.java
    tiles/sandbox/trunk/tiles3/tiles-api/src/main/java/org/apache/tiles/access/TilesAccess.java
    tiles/sandbox/trunk/tiles3/tiles-api/src/test/java/org/apache/tiles/AttributeTest.java

Modified: tiles/sandbox/trunk/tiles3/tiles-api/src/main/java/org/apache/tiles/Attribute.java
URL: http://svn.apache.org/viewvc/tiles/sandbox/trunk/tiles3/tiles-api/src/main/java/org/apache/tiles/Attribute.java?rev=830956&r1=830955&r2=830956&view=diff
==============================================================================
--- tiles/sandbox/trunk/tiles3/tiles-api/src/main/java/org/apache/tiles/Attribute.java (original)
+++ tiles/sandbox/trunk/tiles3/tiles-api/src/main/java/org/apache/tiles/Attribute.java Thu Oct 29 14:14:48 2009
@@ -257,7 +257,7 @@
 
     /** {@inheritDoc} */
     @Override
-	public String toString() {
+    public String toString() {
         if (value != null) {
             return value.toString();
         }
@@ -285,18 +285,6 @@
     }
 
     /**
-     * Sets the body of this attribute.
-     *
-     * @param body The attribute body.
-     */
-    // FIXME Is it necessary?
-    public void setBody(String body) {
-        if (body != null && body.length() != 0) {
-            setValue(body);
-        }
-    }
-
-    /**
      * Inherits an attribute, i.e. overwrites null properties with the ones
      * provided by the attribute.
      *

Modified: tiles/sandbox/trunk/tiles3/tiles-api/src/main/java/org/apache/tiles/Definition.java
URL: http://svn.apache.org/viewvc/tiles/sandbox/trunk/tiles3/tiles-api/src/main/java/org/apache/tiles/Definition.java?rev=830956&r1=830955&r2=830956&view=diff
==============================================================================
--- tiles/sandbox/trunk/tiles3/tiles-api/src/main/java/org/apache/tiles/Definition.java (original)
+++ tiles/sandbox/trunk/tiles3/tiles-api/src/main/java/org/apache/tiles/Definition.java Thu Oct 29 14:14:48 2009
@@ -147,7 +147,7 @@
      * @return A string representation of the content of this definition.
      */
     @Override
-	public String toString() {
+    public String toString() {
         return "{name="
             + name
             + ", template="

Modified: tiles/sandbox/trunk/tiles3/tiles-api/src/main/java/org/apache/tiles/access/TilesAccess.java
URL: http://svn.apache.org/viewvc/tiles/sandbox/trunk/tiles3/tiles-api/src/main/java/org/apache/tiles/access/TilesAccess.java?rev=830956&r1=830955&r2=830956&view=diff
==============================================================================
--- tiles/sandbox/trunk/tiles3/tiles-api/src/main/java/org/apache/tiles/access/TilesAccess.java (original)
+++ tiles/sandbox/trunk/tiles3/tiles-api/src/main/java/org/apache/tiles/access/TilesAccess.java Thu Oct 29 14:14:48 2009
@@ -20,11 +20,8 @@
  */
 package org.apache.tiles.access;
 
-import java.lang.reflect.Method;
-
 import org.apache.tiles.TilesApplicationContext;
 import org.apache.tiles.TilesContainer;
-import org.apache.tiles.reflect.ClassUtil;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -50,26 +47,6 @@
         "org.apache.tiles.CONTAINER";
 
     /**
-     * The name of the attribute to get the {@link TilesApplicationContext} from
-     * a context.
-     */
-    private static final String CONTEXT_ATTRIBUTE =
-        "org.apache.tiles.APPLICATION_CONTEXT";
-
-    /**
-     * Finds and returns the default Tiles container object, if it was
-     * previously initialized.
-     *
-     * @param context The (application) context object to use.
-     * @return The container if it has been configured previously, otherwise
-     * <code>null</code>.
-     * @see #setContainer(Object, TilesContainer)
-     */
-    public static TilesContainer getContainer(Object context) {
-        return (TilesContainer) getAttribute(context, CONTAINER_ATTRIBUTE);
-    }
-
-    /**
      * Configures the default container to be used in the application.
      *
      * @param context The Tiles application context object to use.
@@ -112,32 +89,4 @@
             context.getApplicationScope().put(key, container);
         }
     }
-
-    /**
-     * Returns the Tiles application context object.
-     *
-     * @param context The (application) context to use.
-     * @return The required Tiles application context.
-     */
-    public static TilesApplicationContext getApplicationContext(Object context) {
-        TilesContainer container = getContainer(context);
-        if (container != null) {
-            return container.getApplicationContext();
-        }
-        return (TilesApplicationContext) getAttribute(context, CONTEXT_ATTRIBUTE);
-    }
-
-    /**
-     * Returns an attribute from a context.
-     *
-     * @param context The context object to use.
-     * @param attributeName The name of the attribute to search for.
-     * @return The object, that is the value of the specified attribute.
-     */
-    private static Object getAttribute(Object context, String attributeName) {
-        Class<?> contextClass = context.getClass();
-        Method attrMethod = ClassUtil.getForcedAccessibleMethod(
-                contextClass, "getAttribute", String.class);
-        return ClassUtil.invokeMethod(context, attrMethod, attributeName);
-    }
 }

Added: tiles/sandbox/trunk/tiles3/tiles-api/src/test/java/org/apache/tiles/ArrayStackTest.java
URL: http://svn.apache.org/viewvc/tiles/sandbox/trunk/tiles3/tiles-api/src/test/java/org/apache/tiles/ArrayStackTest.java?rev=830956&view=auto
==============================================================================
--- tiles/sandbox/trunk/tiles3/tiles-api/src/test/java/org/apache/tiles/ArrayStackTest.java (added)
+++ tiles/sandbox/trunk/tiles3/tiles-api/src/test/java/org/apache/tiles/ArrayStackTest.java Thu Oct 29 14:14:48 2009
@@ -0,0 +1,145 @@
+/*
+ * $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;
+
+import static org.junit.Assert.*;
+
+import java.util.EmptyStackException;
+
+import org.junit.Test;
+
+/**
+ * Tests {@link ArrayStack}.
+ *
+ * @version $Rev$ $Date$
+ */
+public class ArrayStackTest {
+
+    /**
+     * The stack size.
+     */
+    private static final int STACK_SIZE = 3;
+
+    /**
+     * Test method for {@link org.apache.tiles.ArrayStack#empty()}.
+     */
+    @Test
+    public void testEmpty() {
+        ArrayStack<Object> stack = new ArrayStack<Object>();
+        assertTrue(stack.empty());
+        stack.add(new Integer(1));
+        assertFalse(stack.empty());
+    }
+
+    /**
+     * Test method for {@link org.apache.tiles.ArrayStack#peek()}.
+     */
+    @Test
+    public void testPeek() {
+        ArrayStack<Object> stack = new ArrayStack<Object>(1);
+        assertTrue(stack.empty());
+        stack.add(new Integer(1));
+        assertEquals(1, stack.peek());
+        assertFalse(stack.empty());
+    }
+
+    /**
+     * Test method for {@link org.apache.tiles.ArrayStack#peek()}.
+     */
+    @Test(expected = EmptyStackException.class)
+    public void testPeekException() {
+        ArrayStack<Object> stack = new ArrayStack<Object>(1);
+        assertTrue(stack.empty());
+        stack.peek();
+    }
+
+    /**
+     * Test method for {@link org.apache.tiles.ArrayStack#peek(int)}.
+     */
+    @Test
+    public void testPeekInt() {
+        ArrayStack<Object> stack = new ArrayStack<Object>(1);
+        stack.add(new Integer(1));
+        stack.add(new Integer(2));
+        assertEquals(2, stack.peek(0));
+        assertEquals(1, stack.peek(1));
+    }
+
+    /**
+     * Test method for {@link org.apache.tiles.ArrayStack#peek(int)}.
+     */
+    @Test(expected = EmptyStackException.class)
+    public void testPeekIntException() {
+        ArrayStack<Object> stack = new ArrayStack<Object>(1);
+        stack.add(new Integer(1));
+        stack.add(new Integer(2));
+        stack.peek(2);
+    }
+
+    /**
+     * Test method for {@link org.apache.tiles.ArrayStack#pop()}.
+     */
+    @Test
+    public void testPop() {
+        ArrayStack<Object> stack = new ArrayStack<Object>(1);
+        assertTrue(stack.empty());
+        stack.add(new Integer(1));
+        assertEquals(1, stack.pop());
+        assertTrue(stack.empty());
+    }
+
+    /**
+     * Test method for {@link org.apache.tiles.ArrayStack#pop()}.
+     */
+    @Test(expected = EmptyStackException.class)
+    public void testPopException() {
+        ArrayStack<Object> stack = new ArrayStack<Object>(1);
+        assertTrue(stack.empty());
+        stack.pop();
+    }
+
+    /**
+     * Test method for {@link org.apache.tiles.ArrayStack#push(java.lang.Object)}.
+     */
+    @Test
+    public void testPush() {
+        ArrayStack<Object> stack = new ArrayStack<Object>();
+        assertTrue(stack.empty());
+        stack.push(new Integer(1));
+        assertFalse(stack.empty());
+    }
+
+    /**
+     * Test method for {@link org.apache.tiles.ArrayStack#search(java.lang.Object)}.
+     */
+    @Test
+    public void testSearch() {
+        ArrayStack<Object> stack = new ArrayStack<Object>(1);
+        stack.add(null);
+        stack.add(new Integer(1));
+        stack.add(new Integer(2));
+        assertEquals(1, stack.search(2));
+        assertEquals(2, stack.search(1));
+        assertEquals(STACK_SIZE, stack.search(null));
+        assertEquals(-1, stack.search(STACK_SIZE));
+    }
+}

Propchange: tiles/sandbox/trunk/tiles3/tiles-api/src/test/java/org/apache/tiles/ArrayStackTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: tiles/sandbox/trunk/tiles3/tiles-api/src/test/java/org/apache/tiles/ArrayStackTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Modified: tiles/sandbox/trunk/tiles3/tiles-api/src/test/java/org/apache/tiles/AttributeTest.java
URL: http://svn.apache.org/viewvc/tiles/sandbox/trunk/tiles3/tiles-api/src/test/java/org/apache/tiles/AttributeTest.java?rev=830956&r1=830955&r2=830956&view=diff
==============================================================================
--- tiles/sandbox/trunk/tiles3/tiles-api/src/test/java/org/apache/tiles/AttributeTest.java (original)
+++ tiles/sandbox/trunk/tiles3/tiles-api/src/test/java/org/apache/tiles/AttributeTest.java Thu Oct 29 14:14:48 2009
@@ -20,18 +20,193 @@
  */
 package org.apache.tiles;
 
-import junit.framework.TestCase;
+import static org.apache.tiles.CompareUtil.*;
+import static org.junit.Assert.*;
+
+import java.util.HashSet;
+import java.util.LinkedHashSet;
+import java.util.Set;
+
+import org.junit.Test;
 
 /**
  * Tests {@link Attribute}.
  *
  * @version $Rev$ $Date$
  */
-public class AttributeTest extends TestCase {
+public class AttributeTest {
+
+
+    /**
+     * Tests {@link Attribute#createTemplateAttribute(String)}.
+     */
+    @Test
+    public void testCreateTemplateAttribute1() {
+        Attribute attribute = Attribute.createTemplateAttribute("/my/template.jsp");
+        assertEquals("/my/template.jsp", attribute.getValue());
+        assertEquals("template", attribute.getRenderer());
+    }
+
+    /**
+     * Tests {@link Attribute#createTemplateAttributeWithExpression(String)}.
+     */
+    @Test
+    public void testCreateTemplateAttribute2() {
+        Attribute attribute = Attribute.createTemplateAttributeWithExpression("my.expression");
+        assertEquals("template", attribute.getRenderer());
+        assertEquals("my.expression", attribute.getExpressionObject().getExpression());
+        assertNull(attribute.getExpressionObject().getLanguage());
+    }
+
+    /**
+     * Tests {@link Attribute#Attribute()}.
+     */
+    @Test
+    public void testAttribute() {
+        Attribute attribute = new Attribute();
+        assertNull(attribute.getValue());
+    }
+
+    /**
+     * Tests {@link Attribute#Attribute(Object)}.
+     */
+    @Test
+    public void testAttributeObject() {
+        Attribute attribute = new Attribute("my.value");
+        assertEquals("my.value", attribute.getValue());
+        assertNull(attribute.getRenderer());
+    }
+
+    /**
+     * Tests {@link Attribute#Attribute(Object, String)}.
+     */
+    @Test
+    public void testAttributeObjectString() {
+        Attribute attribute = new Attribute("my.value", "role1,role2");
+        assertEquals("my.value", attribute.getValue());
+        assertNull(attribute.getRenderer());
+        Set<String> roles = new HashSet<String>();
+        roles.add("role1");
+        roles.add("role2");
+        assertEquals(roles, attribute.getRoles());
+    }
+
+    /**
+     * Tests {@link Attribute#Attribute(Object, Expression, String, String)}.
+     */
+    @Test
+    public void testAttributeComplete() {
+        Expression expression = new Expression("my.expression", "MYLANG");
+        Attribute attribute = new Attribute("my.value", expression, "role1,role2", "myrenderer");
+        assertEquals("my.value", attribute.getValue());
+        assertEquals("myrenderer", attribute.getRenderer());
+        Set<String> roles = new HashSet<String>();
+        roles.add("role1");
+        roles.add("role2");
+        assertEquals(roles, attribute.getRoles());
+        assertEquals("my.expression", attribute.getExpressionObject().getExpression());
+        assertEquals("MYLANG", attribute.getExpressionObject().getLanguage());
+    }
+
+    /**
+     * Tests {@link Attribute#Attribute(Attribute)}.
+     */
+    @Test
+    public void testAttributeCopy() {
+        Expression expression = new Expression("my.expression", "MYLANG");
+        Attribute attribute = new Attribute("my.value", expression, "role1,role2", "myrenderer");
+        attribute = new Attribute(attribute);
+        assertEquals("my.value", attribute.getValue());
+        assertEquals("myrenderer", attribute.getRenderer());
+        Set<String> roles = new HashSet<String>();
+        roles.add("role1");
+        roles.add("role2");
+        assertEquals(roles, attribute.getRoles());
+        assertEquals("my.expression", attribute.getExpressionObject().getExpression());
+        assertEquals("MYLANG", attribute.getExpressionObject().getLanguage());
+
+        attribute = new Attribute("my.value", null, "role1,role2", "myrenderer");
+        attribute = new Attribute(attribute);
+        assertEquals("my.value", attribute.getValue());
+        assertEquals("myrenderer", attribute.getRenderer());
+        roles = new HashSet<String>();
+        roles.add("role1");
+        roles.add("role2");
+        assertEquals(roles, attribute.getRoles());
+        assertNull(attribute.getExpressionObject());
+    }
+
+    /**
+     * Tests {@link Attribute#equals(Object)}.
+     */
+    @Test
+    public void testEquals() {
+        Expression expression = new Expression("my.expression", "MYLANG");
+        Attribute attribute = new Attribute("my.value", expression, "role1,role2", "myrenderer");
+        Attribute attribute2 = new Attribute(attribute);
+        assertTrue(attribute.equals(attribute2));
+        attribute2.setRenderer("anotherRenderer");
+        assertFalse(attribute.equals(attribute2));
+        attribute2 = new Attribute(attribute);
+        attribute2.setRole("otherrole");
+        assertFalse(attribute.equals(attribute2));
+        attribute2 = new Attribute(attribute);
+        attribute2.setExpressionObject(new Expression("another.expression", "MYLANG"));
+        assertFalse(attribute.equals(attribute2));
+        attribute2 = new Attribute(attribute);
+        attribute2.setValue("anothervalue");
+        assertFalse(attribute.equals(attribute2));
+    }
+
+    /**
+     * Tests {@link Attribute#getRole()} and {@link Attribute#setRole(String)}.
+     */
+    @Test
+    public void testGetRole() {
+        Attribute attribute = new Attribute("my.value");
+        assertNull(attribute.getRole());
+        Set<String> roles = new LinkedHashSet<String>();
+        attribute.setRoles(roles);
+        assertNull(attribute.getRole());
+        roles.add("role1");
+        roles.add("role2");
+        assertEquals("role1,role2", attribute.getRole());
+    }
+
+    /**
+     * Tests {@link Attribute#hashCode()}.
+     */
+    @Test
+    public void testHashCode() {
+        Expression expression = new Expression("my.expression", "MYLANG");
+        Attribute attribute = new Attribute("my.value", expression, "role1,role2", "myrenderer");
+        Set<String> roles = new HashSet<String>();
+        roles.add("role1");
+        roles.add("role2");
+        assertEquals(nullSafeHashCode("my.value")
+                + nullSafeHashCode(expression) + nullSafeHashCode(roles)
+                + nullSafeHashCode("myrenderer"), attribute.hashCode());
+    }
+
+    /**
+     * Tests {@link Attribute#toString()}.
+     */
+    @Test
+    public void testToString() {
+        Expression expression = new Expression("my.expression", "MYLANG");
+        Attribute attribute = new Attribute("my.value", expression, "role1,role2", "myrenderer");
+        Set<String> roles = new HashSet<String>();
+        roles.add("role1");
+        roles.add("role2");
+        assertEquals("my.value", attribute.toString());
+        attribute.setValue(null);
+        assertNull(attribute.toString());
+    }
 
     /**
      * Test method for {@link org.apache.tiles.Attribute#inherit(org.apache.tiles.Attribute)}.
      */
+    @Test
     public void testInherit() {
         Attribute attribute = new Attribute(null, (Expression) null, null, (String) null);
         Attribute parentAttribute = new Attribute("value", Expression
@@ -42,13 +217,32 @@
         assertEquals("language", attribute.getExpressionObject().getLanguage());
         assertEquals("role", attribute.getRole());
         assertEquals("renderer", attribute.getRenderer());
+        Expression expression = new Expression(null, "MYLANG");
+        attribute = new Attribute(null, expression, null, (String) null);
+        attribute.setRoles(new HashSet<String>());
+        attribute.inherit(parentAttribute);
+        assertEquals("value", attribute.getValue());
+        assertEquals("expression", attribute.getExpressionObject().getExpression());
+        assertEquals("language", attribute.getExpressionObject().getLanguage());
+        assertEquals("role", attribute.getRole());
+        assertEquals("renderer", attribute.getRenderer());
+    }
 
-        attribute = new Attribute("myvalue", Expression.createExpression(
-                "myexpression", "mylanguage"), "myrole", (String) "myrenderer");
-        assertEquals("myvalue", attribute.getValue());
-        assertEquals("myexpression", attribute.getExpressionObject().getExpression());
-        assertEquals("mylanguage", attribute.getExpressionObject().getLanguage());
-        assertEquals("myrole", attribute.getRole());
+    /**
+     * Tests {@link Attribute#clone()}.
+     */
+    @Test
+    public void testClone() {
+        Expression expression = new Expression("my.expression", "MYLANG");
+        Attribute attribute = new Attribute("my.value", expression, "role1,role2", "myrenderer");
+        attribute = attribute.clone();
+        assertEquals("my.value", attribute.getValue());
         assertEquals("myrenderer", attribute.getRenderer());
+        Set<String> roles = new HashSet<String>();
+        roles.add("role1");
+        roles.add("role2");
+        assertEquals(roles, attribute.getRoles());
+        assertEquals("my.expression", attribute.getExpressionObject().getExpression());
+        assertEquals("MYLANG", attribute.getExpressionObject().getLanguage());
     }
 }