You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tapestry.apache.org by an...@apache.org on 2006/08/11 17:24:01 UTC
svn commit: r430806 - in /tapestry/tapestry4/trunk/tapestry-framework/src:
java/org/apache/tapestry/html/ test/org/apache/tapestry/html/
Author: andyhot
Date: Fri Aug 11 08:24:00 2006
New Revision: 430806
URL: http://svn.apache.org/viewvc?rev=430806&view=rev
Log:
More tests
Added:
tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/html/TestRelation.java
Modified:
tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/html/Relation.java
tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/html/RelationBean.java
tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/html/TestShell.java
Modified: tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/html/Relation.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/html/Relation.java?rev=430806&r1=430805&r2=430806&view=diff
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/html/Relation.java (original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/html/Relation.java Fri Aug 11 08:24:00 2006
@@ -24,7 +24,8 @@
* relationship between documents (typically a stylesheet) to
* the HTML response.
*
- * @author andyhot
+ * @author Andreas Andreou
+ * @since 4.1.1
*/
public abstract class Relation extends AbstractComponent
{
Modified: tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/html/RelationBean.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/html/RelationBean.java?rev=430806&r1=430805&r2=430806&view=diff
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/html/RelationBean.java (original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/html/RelationBean.java Fri Aug 11 08:24:00 2006
@@ -16,7 +16,8 @@
/**
* Defines a relationship between two documents.
*
- * @author andyhot
+ * @author Andreas Andreou
+ * @since 4.1.1
*/
public class RelationBean
{
Added: tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/html/TestRelation.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/html/TestRelation.java?rev=430806&view=auto
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/html/TestRelation.java (added)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/html/TestRelation.java Fri Aug 11 08:24:00 2006
@@ -0,0 +1,124 @@
+// Copyright 2005 The Apache Software Foundation
+//
+// Licensed 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.tapestry.html;
+
+import static org.easymock.EasyMock.expect;
+import static org.testng.Assert.assertEquals;
+
+import org.apache.hivemind.ApplicationRuntimeException;
+import org.apache.hivemind.Location;
+import org.apache.tapestry.BaseComponentTestCase;
+import org.apache.tapestry.IMarkupWriter;
+import org.apache.tapestry.IRequestCycle;
+import org.testng.annotations.Test;
+
+/**
+ * Tests for the {@link org.apache.tapestry.html.Relation} component.
+ *
+ * @author Andreas Andreou
+ * @since 4.1.1
+ */
+@Test
+public class TestRelation extends BaseComponentTestCase
+{
+
+ /**
+ * Test that Relation does nothing when the entire page is rewinding
+ */
+
+ public void testRewinding()
+ {
+ IMarkupWriter writer = newWriter();
+
+ IRequestCycle cycle = newCycle(true);
+
+ Relation relation = newInstance(Relation.class, null);
+
+ replay();
+
+ relation.render(writer, cycle);
+
+ verify();
+ }
+
+ /**
+ * Test that exception is thrown when Shell is missing
+ */
+ public void testShellMissing()
+ {
+ IMarkupWriter writer = newWriter();
+
+ IRequestCycle cycle = newCycle(false);
+
+ Location componentLocation = newMock(Location.class);
+
+ Relation relation = newInstance(Relation.class,
+ new Object[] {"location", componentLocation});
+
+ trainGetShellFromCycle(cycle, null);
+
+ replay();
+
+ try
+ {
+ relation.render(writer, cycle);
+ unreachable();
+ }
+ catch (ApplicationRuntimeException ex)
+ {
+ assertEquals(ex.getLocation(), componentLocation);
+ }
+
+ verify();
+ }
+
+ /**
+ * Test that exception is thrown for invalid href parameter
+ */
+ public void testInvalidHrefParameter()
+ {
+ IMarkupWriter writer = newWriter();
+
+ IRequestCycle cycle = newCycle(false);
+
+ Location componentLocation = newMock(Location.class);
+
+ Relation relation = newInstance(Relation.class, new Object[]
+ {"location", componentLocation, "href", null});
+
+ Shell shell = newInstance(Shell.class, null);
+
+ trainGetShellFromCycle(cycle, shell);
+
+ replay();
+
+ try
+ {
+ relation.render(writer, cycle);
+ unreachable();
+ }
+ catch (ApplicationRuntimeException ex)
+ {
+ assertEquals(ex.getLocation(), componentLocation);
+ }
+
+ verify();
+ }
+
+ protected void trainGetShellFromCycle(IRequestCycle cycle, Shell shell)
+ {
+ expect(cycle.getAttribute(Shell.SHELL_ATTRIBUTE)).andReturn(shell);
+ }
+}
\ No newline at end of file
Modified: tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/html/TestShell.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/html/TestShell.java?rev=430806&r1=430805&r2=430806&view=diff
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/html/TestShell.java (original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/html/TestShell.java Fri Aug 11 08:24:00 2006
@@ -14,12 +14,16 @@
package org.apache.tapestry.html;
+import static org.easymock.EasyMock.expect;
+import static org.testng.Assert.assertEquals;
+
+import java.util.List;
+
import org.apache.tapestry.BaseComponentTestCase;
import org.apache.tapestry.IMarkupWriter;
import org.apache.tapestry.IRender;
import org.apache.tapestry.IRequestCycle;
import org.apache.tapestry.NestedMarkupWriter;
-import org.apache.tapestry.test.Creator;
import org.testng.annotations.Test;
/**
@@ -31,7 +35,6 @@
@Test
public class TestShell extends BaseComponentTestCase
{
- private Creator _creator = new Creator();
/**
* Test that Shell does very little when the entire page is rewinding (which itself is a
@@ -46,7 +49,7 @@
IRequestCycle cycle = newCycle(true, writer);
IRender body = newRender();
- Shell shell = (Shell) _creator.newInstance(Shell.class);
+ Shell shell = newInstance(Shell.class, null);
shell.addBody(body);
trainStoreShellInCycle(cycle, shell);
@@ -61,11 +64,24 @@
verify();
}
+
+ public void testAddRelation()
+ {
+ Shell shell = newInstance(Shell.class, null);
+ RelationBean css1 = new RelationBean();
+ css1.setHref("temp");
+ RelationBean css2 = new RelationBean();
+ css2.setHref("temp");
+ shell.addRelation(css1);
+ shell.addRelation(css2);
+
+ List all = shell.getRelations();
+ assertEquals(all.size(), 1);
+ }
protected void trainStoreShellInCycle(IRequestCycle cycle, Shell shell)
{
- cycle.getAttribute(Shell.SHELL_ATTRIBUTE);
- setReturnValue(null);
+ expect(cycle.getAttribute(Shell.SHELL_ATTRIBUTE)).andReturn(null);
cycle.setAttribute(Shell.SHELL_ATTRIBUTE, shell);
}