Author: apetrelli
Date: Wed Jan 16 11:49:39 2008
New Revision: 612556
URL: http://svn.apache.org/viewvc?rev=612556&view=rev
Log:
TILES-208
Added cascaded attributes support in AttributeContext and BasicAttributeContext.
Added:
tiles/framework/trunk/tiles-core/src/test/java/org/apache/tiles/context/BasicAttributeContextTest.java
(with props)
Modified:
tiles/framework/trunk/tiles-api/src/main/java/org/apache/tiles/AttributeContext.java
tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/context/BasicAttributeContext.java
Modified:
tiles/framework/trunk/tiles-api/src/main/java/org/apache/tiles/AttributeContext.java
URL:
http://svn.apache.org/viewvc/tiles/framework/trunk/tiles-api/src/main/java/org/apache/tiles/AttributeContext.java?rev=612556&r1=612555&r2=612556&view=diff
==============================================================================
---
tiles/framework/trunk/tiles-api/src/main/java/org/apache/tiles/AttributeContext.java
(original)
+++
tiles/framework/trunk/tiles-api/src/main/java/org/apache/tiles/AttributeContext.java
Wed Jan 16 11:49:39 2008
@@ -22,6 +22,7 @@
import java.util.Map;
import java.util.Iterator;
+import java.util.Set;
/**
* Encapsulation of the current state of execution.
@@ -46,7 +47,7 @@
void addMissing(Map<String, Attribute> defaultAttributes);
/**
- * Retrieve the named attribute.
+ * Retrieve the named attribute, either cascaded or not.
*
* @param name key name for the attribute.
* @return Attribute associated with the given name.
@@ -54,19 +55,68 @@
Attribute getAttribute(String name);
/**
+ * Retrieve the attribute that has been defined in this context (i.e. not
+ * cascaded).
+ *
+ * @param name key name for the attribute.
+ * @return Attribute The local attribute associated with the given name, if
+ * present, or <code>null</code> otherwise.
+ */
+ Attribute getLocalAttribute(String name);
+
+ /**
+ * Retrieve the attribute that has been cascaded at upper levels.
+ *
+ * @param name key name for the attribute.
+ * @return Attribute The cascaded attribute associated with the given name,
+ * if present, or <code>null</code> otherwise.
+ */
+ Attribute getCascadedAttribute(String name);
+
+ /**
* Iterator of all attribute names.
*
* @return iterator of all names.
*/
+ @Deprecated
Iterator<String> getAttributeNames();
/**
- * Add the specified attribute.
+ * Returns the names of the local attributes, i.e. the one that have not
+ * been cascaded.
+ *
+ * @return The local attribute names.
+ */
+ Set<String> getLocalAttributeNames();
+
+ /**
+ * Returns the names of the cascaded attributes.
+ *
+ * @return The cascaded attribute names.
+ */
+ Set<String> getCascadedAttributeNames();
+
+ /**
+ * Add the specified attribute. The attribute value will be available only
+ * in the current context, i.e. it is like calling
+ * [EMAIL PROTECTED] AttributeContext#putAttribute(String, Attribute,
boolean)} with
+ * <code>cascade = false</code>.
*
* @param name name of the attribute
* @param value value of the attribute
*/
void putAttribute(String name, Attribute value);
+
+ /**
+ * Add the specified attribute.
+ *
+ * @param name name of the attribute
+ * @param value value of the attribute
+ * @param cascade If <code>true</code>, the attribute value will be
+ * available in all nested contexts. If <code>false</code>, it will be
+ * available only in the current context.
+ */
+ void putAttribute(String name, Attribute value, boolean cascade);
/**
* Clear the attributes.
Modified:
tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/context/BasicAttributeContext.java
URL:
http://svn.apache.org/viewvc/tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/context/BasicAttributeContext.java?rev=612556&r1=612555&r2=612556&view=diff
==============================================================================
---
tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/context/BasicAttributeContext.java
(original)
+++
tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/context/BasicAttributeContext.java
Wed Jan 16 11:49:39 2008
@@ -24,6 +24,7 @@
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
@@ -51,6 +52,11 @@
private Map<String, Attribute> attributes = null;
/**
+ * Cascaded template attributes.
+ */
+ private Map<String, Attribute> cascadedAttributes = null;
+
+ /**
* Constructor.
*/
public BasicAttributeContext() {
@@ -76,15 +82,31 @@
* @param context The constructor to copy.
*/
public BasicAttributeContext(AttributeContext context) {
- this.attributes = new HashMap<String, Attribute>();
- Iterator<String> names = context.getAttributeNames();
- while (names.hasNext()) {
- String name = names.next();
- attributes.put(name, context.getAttribute(name));
+ if (context instanceof BasicAttributeContext) {
+ copyBasicAttributeContext((BasicAttributeContext) context);
+ } else {
+ this.attributes = new HashMap<String, Attribute>();
+ this.cascadedAttributes = new HashMap<String, Attribute>();
+ for (String name : context.getLocalAttributeNames()) {
+ attributes.put(name, context.getLocalAttribute(name));
+ }
+ for (String name : context.getCascadedAttributeNames()) {
+ cascadedAttributes
+ .put(name, context.getCascadedAttribute(name));
+ }
}
}
/**
+ * Copy constructor.
+ *
+ * @param context The constructor to copy.
+ */
+ public BasicAttributeContext(BasicAttributeContext context) {
+ copyBasicAttributeContext(context);
+ }
+
+ /**
* Add all attributes to this context.
* Copies all of the mappings from the specified attribute map to this
context.
* New attribute mappings will replace any mappings that this context had
for any of the keys
@@ -120,24 +142,38 @@
if (attributes == null) {
attributes = new HashMap<String, Attribute>(defaultAttributes);
- return;
+ if (cascadedAttributes == null || cascadedAttributes.isEmpty()) {
+ return;
+ }
}
Set<Map.Entry<String, Attribute>> entries =
defaultAttributes.entrySet();
for (Map.Entry<String, Attribute> entry : entries) {
- if (!attributes.containsKey(entry.getKey())) {
+ String key = entry.getKey();
+ if (!attributes.containsKey(key)
+ && (cascadedAttributes == null || cascadedAttributes
+ .containsKey(key))) {
attributes.put(entry.getKey(), entry.getValue());
}
}
}
- /**
- * Get an attribute from context.
- *
- * @param name Name of the attribute.
- * @return <{Attribute}>
- */
+ /** [EMAIL PROTECTED] */
public Attribute getAttribute(String name) {
+ Attribute retValue = null;
+ if (attributes != null) {
+ retValue = attributes.get(name);
+ }
+
+ if (retValue == null && cascadedAttributes != null) {
+ retValue = cascadedAttributes.get(name);
+ }
+
+ return retValue;
+ }
+
+ /** [EMAIL PROTECTED] */
+ public Attribute getLocalAttribute(String name) {
if (attributes == null) {
return null;
}
@@ -145,25 +181,55 @@
return attributes.get(name);
}
- /**
- * Get names of all attributes.
- *
- * @return <{Attribute}>
- */
+ /** [EMAIL PROTECTED] */
+ public Attribute getCascadedAttribute(String name) {
+ if (cascadedAttributes == null) {
+ return null;
+ }
+
+ return cascadedAttributes.get(name);
+ }
+
+ /** [EMAIL PROTECTED] */
public Iterator<String> getAttributeNames() {
- if (attributes == null) {
+ Set<String> attributeSet = null;
+
+ if (attributes != null && !attributes.isEmpty()) {
+ attributeSet = new HashSet<String>(attributes
+ .keySet());
+ if (cascadedAttributes != null && !cascadedAttributes.isEmpty()) {
+ attributeSet.addAll(cascadedAttributes.keySet());
+ }
+ } else if (cascadedAttributes != null &&
!cascadedAttributes.isEmpty()) {
+ attributeSet = new HashSet<String>(cascadedAttributes.keySet());
+ }
+
+ if (attributeSet != null) {
+ return attributeSet.iterator();
+ } else {
return new ArrayList<String>().iterator();
}
+ }
- return attributes.keySet().iterator();
+ /** [EMAIL PROTECTED] */
+ public Set<String> getLocalAttributeNames() {
+ if (attributes != null && !attributes.isEmpty()) {
+ return attributes.keySet();
+ } else {
+ return null;
+ }
}
- /**
- * Put a new attribute to context.
- *
- * @param name Name of the attribute.
- * @param value Value of the attribute.
- */
+ /** [EMAIL PROTECTED] */
+ public Set<String> getCascadedAttributeNames() {
+ if (cascadedAttributes != null && !cascadedAttributes.isEmpty()) {
+ return cascadedAttributes.keySet();
+ } else {
+ return null;
+ }
+ }
+
+ /** [EMAIL PROTECTED] */
public void putAttribute(String name, Attribute value) {
if (attributes == null) {
attributes = new HashMap<String, Attribute>();
@@ -172,6 +238,23 @@
attributes.put(name, value);
}
+ /** [EMAIL PROTECTED] */
+ public void putAttribute(String name, Attribute value, boolean cascade) {
+ Map<String, Attribute> mapToUse;
+ if (cascade) {
+ if (cascadedAttributes == null) {
+ cascadedAttributes = new HashMap<String, Attribute>();
+ }
+ mapToUse = cascadedAttributes;
+ } else {
+ if (attributes == null) {
+ attributes = new HashMap<String, Attribute>();
+ }
+ mapToUse = attributes;
+ }
+ mapToUse.put(name, value);
+ }
+
/**
* Get attribute context from request.
*
@@ -234,5 +317,22 @@
/** [EMAIL PROTECTED] */
public void clear() {
attributes.clear();
+ cascadedAttributes.clear();
+ }
+
+ /**
+ * Copies a BasicAttributeContext in an easier way.
+ *
+ * @param context The context to copy.
+ */
+ private void copyBasicAttributeContext(BasicAttributeContext context) {
+ if (context.attributes != null && !context.attributes.isEmpty()) {
+ attributes = new HashMap<String, Attribute>(context.attributes);
+ }
+ if (context.cascadedAttributes != null
+ && !context.cascadedAttributes.isEmpty()) {
+ cascadedAttributes = new HashMap<String, Attribute>(
+ context.cascadedAttributes);
+ }
}
}
Added:
tiles/framework/trunk/tiles-core/src/test/java/org/apache/tiles/context/BasicAttributeContextTest.java
URL:
http://svn.apache.org/viewvc/tiles/framework/trunk/tiles-core/src/test/java/org/apache/tiles/context/BasicAttributeContextTest.java?rev=612556&view=auto
==============================================================================
---
tiles/framework/trunk/tiles-core/src/test/java/org/apache/tiles/context/BasicAttributeContextTest.java
(added)
+++
tiles/framework/trunk/tiles-core/src/test/java/org/apache/tiles/context/BasicAttributeContextTest.java
Wed Jan 16 11:49:39 2008
@@ -0,0 +1,330 @@
+/*
+ * $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.context;
+
+import java.util.HashMap;
+import java.util.LinkedHashSet;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.tiles.Attribute;
+import org.apache.tiles.AttributeContext;
+import org.easymock.EasyMock;
+
+import junit.framework.TestCase;
+
+/**
+ * Tests <code>BasicAttributeContext</code>.
+ *
+ * @version $Rev$ $Date$
+ */
+public class BasicAttributeContextTest extends TestCase {
+
+ /**
+ * Tests [EMAIL PROTECTED] BasicAttributeContext#BasicAttributeContext()}.
+ */
+ public void testBasicAttributeContext() {
+ AttributeContext context = new BasicAttributeContext();
+ assertNull("There are some spurious attributes", context
+ .getLocalAttributeNames());
+ assertNull("There are some spurious attributes", context
+ .getCascadedAttributeNames());
+ }
+
+ /**
+ * Tests [EMAIL PROTECTED]
BasicAttributeContext#BasicAttributeContext(Map)}.
+ */
+ public void testBasicAttributeContextMapOfStringAttribute() {
+ Map<String, Attribute> name2attrib = new HashMap<String, Attribute>();
+ Attribute attribute = new Attribute("Value 1");
+ name2attrib.put("name1", attribute);
+ attribute = new Attribute("Value 2");
+ name2attrib.put("name2", attribute);
+ AttributeContext context = new BasicAttributeContext(name2attrib);
+ attribute = context.getAttribute("name1");
+ assertNotNull("Attribute name1 not found", attribute);
+ assertEquals("Attribute name1 has not been set correctly", "Value 1",
+ attribute.getValue());
+ attribute = context.getAttribute("name2");
+ assertNotNull("Attribute name2 not found", attribute);
+ assertEquals("Attribute name2 has not been set correctly", "Value 2",
+ attribute.getValue());
+ }
+
+ /**
+ * Tests
+ * [EMAIL PROTECTED]
BasicAttributeContext#BasicAttributeContext(AttributeContext)}.
+ */
+ public void testBasicAttributeContextAttributeContext() {
+ Set<String> localAttributes = new LinkedHashSet<String>();
+ Set<String> cascadedAttributes = new LinkedHashSet<String>();
+ localAttributes.add("local1");
+ localAttributes.add("local2");
+ cascadedAttributes.add("cascaded1");
+ cascadedAttributes.add("cascaded2");
+ AttributeContext toCopy = EasyMock.createMock(AttributeContext.class);
+ EasyMock.expect(toCopy.getLocalAttributeNames()).andReturn(
+ localAttributes);
+ EasyMock.expect(toCopy.getLocalAttribute("local1")).andReturn(
+ new Attribute("value1")).anyTimes();
+ EasyMock.expect(toCopy.getLocalAttribute("local2")).andReturn(
+ new Attribute("value2")).anyTimes();
+ EasyMock.expect(toCopy.getCascadedAttributeNames()).andReturn(
+ cascadedAttributes);
+ EasyMock.expect(toCopy.getCascadedAttribute("cascaded1")).andReturn(
+ new Attribute("value3")).anyTimes();
+ EasyMock.expect(toCopy.getCascadedAttribute("cascaded2")).andReturn(
+ new Attribute("value4")).anyTimes();
+ EasyMock.replay(toCopy);
+ BasicAttributeContext context = new BasicAttributeContext(toCopy);
+ Attribute attribute = context.getLocalAttribute("local1");
+ assertNotNull("Attribute local1 not found", attribute);
+ assertEquals("Attribute local1 has not been set correctly", "value1",
+ attribute.getValue());
+ attribute = context.getLocalAttribute("local2");
+ assertNotNull("Attribute local2 not found", attribute);
+ assertEquals("Attribute local2 has not been set correctly", "value2",
+ attribute.getValue());
+ attribute = context.getCascadedAttribute("cascaded1");
+ assertNotNull("Attribute cascaded1 not found", attribute);
+ assertEquals("Attribute cascaded1 has not been set correctly",
+ "value3", attribute.getValue());
+ attribute = context.getCascadedAttribute("cascaded2");
+ assertNotNull("Attribute cascaded2 not found", attribute);
+ assertEquals("Attribute cascaded2 has not been set correctly",
+ "value4", attribute.getValue());
+ }
+
+ /**
+ * Tests
+ * [EMAIL PROTECTED]
BasicAttributeContext#BasicAttributeContext(BasicAttributeContext)}.
+ */
+ public void testBasicAttributeContextBasicAttributeContext() {
+ AttributeContext toCopy = new BasicAttributeContext();
+ toCopy.putAttribute("name1", new Attribute("value1"), false);
+ toCopy.putAttribute("name2", new Attribute("value2"), true);
+ AttributeContext context = new BasicAttributeContext(toCopy);
+ Attribute attribute = context.getLocalAttribute("name1");
+ assertNotNull("Attribute name1 not found", attribute);
+ assertEquals("Attribute name1 has not been set correctly", "value1",
+ attribute.getValue());
+ attribute = context.getCascadedAttribute("name2");
+ assertNotNull("Attribute name2 not found", attribute);
+ assertEquals("Attribute name2 has not been set correctly", "value2",
+ attribute.getValue());
+ }
+
+ /**
+ * Tests [EMAIL PROTECTED] BasicAttributeContext#addAll(Map)}.
+ */
+ public void testAddAll() {
+ AttributeContext context = new BasicAttributeContext();
+ Map<String, Attribute> name2attrib = new HashMap<String, Attribute>();
+ Attribute attribute = new Attribute("Value 1");
+ name2attrib.put("name1", attribute);
+ attribute = new Attribute("Value 2");
+ name2attrib.put("name2", attribute);
+ context.addAll(name2attrib);
+ attribute = context.getAttribute("name1");
+ assertNotNull("Attribute name1 not found", attribute);
+ assertEquals("Attribute name1 has not been set correctly", "Value 1",
+ attribute.getValue());
+ attribute = context.getAttribute("name2");
+ assertNotNull("Attribute name2 not found", attribute);
+ assertEquals("Attribute name2 has not been set correctly", "Value 2",
+ attribute.getValue());
+ }
+
+ /**
+ * Tests [EMAIL PROTECTED] BasicAttributeContext#addMissing(Map)}.
+ */
+ public void testAddMissing() {
+ Map<String, Attribute> name2attrib = new HashMap<String, Attribute>();
+ Attribute attribute = new Attribute("Value 1");
+ name2attrib.put("name1", attribute);
+ attribute = new Attribute("Value 2");
+ name2attrib.put("name2", attribute);
+ AttributeContext context = new BasicAttributeContext(name2attrib);
+ name2attrib.remove("name2");
+ name2attrib.put("name1", new Attribute("Value 1a"));
+ name2attrib.put("name3", new Attribute("Value 3"));
+ context.addMissing(name2attrib);
+ attribute = context.getAttribute("name1");
+ assertNotNull("Attribute name1 not found", attribute);
+ assertEquals("Attribute name1 has not been set correctly", "Value 1",
+ attribute.getValue());
+ attribute = context.getAttribute("name2");
+ assertNotNull("Attribute name2 not found", attribute);
+ assertEquals("Attribute name2 has not been set correctly", "Value 2",
+ attribute.getValue());
+ attribute = context.getAttribute("name3");
+ assertNotNull("Attribute name3 not found", attribute);
+ assertEquals("Attribute name3 has not been set correctly", "Value 3",
+ attribute.getValue());
+ }
+
+ /**
+ * Tests [EMAIL PROTECTED] BasicAttributeContext#getAttribute(String)}.
+ */
+ public void testGetAttribute() {
+ AttributeContext context = new BasicAttributeContext();
+ context.putAttribute("name1", new Attribute("value1"), false);
+ context.putAttribute("name2", new Attribute("value2"), true);
+ context.putAttribute("name3", new Attribute("value3a"), true);
+ context.putAttribute("name3", new Attribute("value3"), false);
+ Attribute attribute = context.getAttribute("name1");
+ assertNotNull("Attribute name1 not found", attribute);
+ assertEquals("Attribute name1 has not been set correctly", "value1",
+ attribute.getValue());
+ attribute = context.getAttribute("name2");
+ assertNotNull("Attribute name2 not found", attribute);
+ assertEquals("Attribute name2 has not been set correctly", "value2",
+ attribute.getValue());
+ attribute = context.getAttribute("name3");
+ assertNotNull("Attribute name3 not found", attribute);
+ assertEquals("Attribute name3 has not been set correctly", "value3",
+ attribute.getValue());
+ }
+
+ /**
+ * Tests [EMAIL PROTECTED]
BasicAttributeContext#getLocalAttribute(String)}.
+ */
+ public void testGetLocalAttribute() {
+ AttributeContext context = new BasicAttributeContext();
+ context.putAttribute("name1", new Attribute("value1"), false);
+ context.putAttribute("name2", new Attribute("value2"), true);
+ context.putAttribute("name3", new Attribute("value3a"), true);
+ context.putAttribute("name3", new Attribute("value3"), false);
+ Attribute attribute = context.getLocalAttribute("name1");
+ assertNotNull("Attribute name1 not found", attribute);
+ assertEquals("Attribute name1 has not been set correctly", "value1",
+ attribute.getValue());
+ attribute = context.getLocalAttribute("name2");
+ assertNull("Attribute name2 found", attribute);
+ attribute = context.getLocalAttribute("name3");
+ assertNotNull("Attribute name3 not found", attribute);
+ assertEquals("Attribute name3 has not been set correctly", "value3",
+ attribute.getValue());
+ }
+
+ /**
+ * Tests [EMAIL PROTECTED]
BasicAttributeContext#getCascadedAttribute(String)}.
+ */
+ public void testGetCascadedAttribute() {
+ AttributeContext context = new BasicAttributeContext();
+ context.putAttribute("name1", new Attribute("value1"), false);
+ context.putAttribute("name2", new Attribute("value2"), true);
+ context.putAttribute("name3", new Attribute("value3a"), true);
+ context.putAttribute("name3", new Attribute("value3"), false);
+ Attribute attribute = context.getCascadedAttribute("name1");
+ assertNull("Attribute name1 found", attribute);
+ attribute = context.getCascadedAttribute("name2");
+ assertNotNull("Attribute name2 not found", attribute);
+ assertEquals("Attribute name2 has not been set correctly", "value2",
+ attribute.getValue());
+ attribute = context.getCascadedAttribute("name3");
+ assertNotNull("Attribute name3 not found", attribute);
+ assertEquals("Attribute name3 has not been set correctly", "value3a",
+ attribute.getValue());
+ }
+
+ /**
+ * Tests [EMAIL PROTECTED] BasicAttributeContext#getLocalAttributeNames()}.
+ */
+ public void testGetLocalAttributeNames() {
+ AttributeContext context = new BasicAttributeContext();
+ context.putAttribute("name1", new Attribute("value1"), false);
+ context.putAttribute("name2", new Attribute("value2"), true);
+ context.putAttribute("name3", new Attribute("value3a"), true);
+ context.putAttribute("name3", new Attribute("value3"), false);
+ Set<String> names = context.getLocalAttributeNames();
+ assertTrue("Attribute name1 is not present", names.contains("name1"));
+ assertFalse("Attribute name2 is present", names.contains("name2"));
+ assertTrue("Attribute name3 is not present", names.contains("name3"));
+ }
+
+ /**
+ * Tests [EMAIL PROTECTED]
BasicAttributeContext#getCascadedAttributeNames()}.
+ */
+ public void testGetCascadedAttributeNames() {
+ AttributeContext context = new BasicAttributeContext();
+ context.putAttribute("name1", new Attribute("value1"), false);
+ context.putAttribute("name2", new Attribute("value2"), true);
+ context.putAttribute("name3", new Attribute("value3a"), true);
+ context.putAttribute("name3", new Attribute("value3"), false);
+ Set<String> names = context.getCascadedAttributeNames();
+ assertFalse("Attribute name1 is present", names.contains("name1"));
+ assertTrue("Attribute name2 is not present", names.contains("name2"));
+ assertTrue("Attribute name3 is not present", names.contains("name3"));
+ }
+
+ /**
+ * Tests [EMAIL PROTECTED] BasicAttributeContext#putAttribute(String,
Attribute)}.
+ */
+ public void testPutAttributeStringAttribute() {
+ AttributeContext context = new BasicAttributeContext();
+ context.putAttribute("name1", new Attribute("value1"));
+ Attribute attribute = context.getLocalAttribute("name1");
+ assertNotNull("Attribute name1 not found", attribute);
+ assertEquals("Attribute name1 has not been set correctly", "value1",
+ attribute.getValue());
+ attribute = context.getCascadedAttribute("name1");
+ assertNull("Attribute name1 found", attribute);
+ }
+
+ /**
+ * Tests
+ * [EMAIL PROTECTED] BasicAttributeContext#putAttribute(String, Attribute,
boolean)}.
+ */
+ public void testPutAttributeStringAttributeBoolean() {
+ AttributeContext context = new BasicAttributeContext();
+ context.putAttribute("name1", new Attribute("value1"), false);
+ context.putAttribute("name2", new Attribute("value2"), true);
+ Attribute attribute = context.getLocalAttribute("name1");
+ assertNotNull("Attribute name1 not found", attribute);
+ assertEquals("Attribute name1 has not been set correctly", "value1",
+ attribute.getValue());
+ attribute = context.getCascadedAttribute("name1");
+ assertNull("Attribute name1 found", attribute);
+ attribute = context.getCascadedAttribute("name2");
+ assertNotNull("Attribute name2 not found", attribute);
+ assertEquals("Attribute name2 has not been set correctly", "value2",
+ attribute.getValue());
+ attribute = context.getLocalAttribute("name2");
+ assertNull("Attribute name2 found", attribute);
+ }
+
+ /**
+ * Tests [EMAIL PROTECTED] BasicAttributeContext#clear()}.
+ */
+ public void testClear() {
+ AttributeContext context = new BasicAttributeContext();
+ context.putAttribute("name1", new Attribute("value1"), false);
+ context.putAttribute("name2", new Attribute("value2"), true);
+ context.clear();
+ Set<String> names = context.getLocalAttributeNames();
+ assertTrue("There are local attributes", names == null
+ || names.isEmpty());
+ names = context.getCascadedAttributeNames();
+ assertTrue("There are cascaded attributes", names == null
+ || names.isEmpty());
+ }
+}
Propchange:
tiles/framework/trunk/tiles-core/src/test/java/org/apache/tiles/context/BasicAttributeContextTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
tiles/framework/trunk/tiles-core/src/test/java/org/apache/tiles/context/BasicAttributeContextTest.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL