You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tapestry.apache.org by hl...@apache.org on 2007/01/16 03:58:42 UTC

svn commit: r496578 [2/2] - in /tapestry/tapestry5/tapestry-core/trunk/src: main/java/org/apache/tapestry/ main/java/org/apache/tapestry/corelib/base/ main/java/org/apache/tapestry/corelib/components/ main/java/org/apache/tapestry/internal/services/ ma...

Added: tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/app1/pages/ToDoList.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/app1/pages/ToDoList.java?view=auto&rev=496578
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/app1/pages/ToDoList.java (added)
+++ tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/app1/pages/ToDoList.java Mon Jan 15 18:58:40 2007
@@ -0,0 +1,49 @@
+// Copyright 2007 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.integration.app1.pages;
+
+import org.apache.tapestry.annotations.Component;
+import org.apache.tapestry.annotations.ComponentClass;
+import org.apache.tapestry.annotations.Inject;
+import org.apache.tapestry.corelib.components.Form;
+import org.apache.tapestry.integration.app1.data.ToDoItem;
+import org.apache.tapestry.integration.app1.services.ToDoDatabase;
+
+@ComponentClass
+public class ToDoList
+{
+    @Inject
+    private ToDoDatabase _database;
+
+    private ToDoItem _item;
+
+    @Component
+    private Form _form;
+
+    public ToDoItem getItem()
+    {
+        return _item;
+    }
+
+    public void setItem(ToDoItem item)
+    {
+        _item = item;
+    }
+
+    public ToDoDatabase getDatabase()
+    {
+        return _database;
+    }
+}

Modified: tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/app1/services/AppModule.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/app1/services/AppModule.java?view=diff&rev=496578&r1=496577&r2=496578
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/app1/services/AppModule.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/app1/services/AppModule.java Mon Jan 15 18:58:40 2007
@@ -87,4 +87,9 @@
     {
         configuration.add("tapestry.supported-locales", "en,fr");
     }
+
+    public ToDoDatabase buildToDoDatabase()
+    {
+        return new ToDoDatabaseImpl();
+    }
 }

Added: tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/app1/services/ToDoDatabase.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/app1/services/ToDoDatabase.java?view=auto&rev=496578
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/app1/services/ToDoDatabase.java (added)
+++ tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/app1/services/ToDoDatabase.java Mon Jan 15 18:58:40 2007
@@ -0,0 +1,37 @@
+// Copyright 2007 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.integration.app1.services;
+
+import java.util.List;
+
+import org.apache.tapestry.integration.app1.data.ToDoItem;
+
+public interface ToDoDatabase
+{
+    /** Adds an item to the database, first assigning a unique id to the item. */
+    void add(ToDoItem item);
+
+    /** Finds all items, sorted ascending by each item's order property. */
+    List<ToDoItem> findAll();
+
+    /**
+     * Updates an existing item.
+     * 
+     * @param item
+     * @throws RuntimeException
+     *             if the item does not exist
+     */
+    void update(ToDoItem item);
+}

Added: tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/app1/services/ToDoDatabaseImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/app1/services/ToDoDatabaseImpl.java?view=auto&rev=496578
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/app1/services/ToDoDatabaseImpl.java (added)
+++ tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/app1/services/ToDoDatabaseImpl.java Mon Jan 15 18:58:40 2007
@@ -0,0 +1,96 @@
+// Copyright 2007 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.integration.app1.services;
+
+import static org.apache.tapestry.ioc.internal.util.CollectionFactory.newList;
+import static org.apache.tapestry.ioc.internal.util.CollectionFactory.newMap;
+
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.tapestry.integration.app1.data.ToDoItem;
+
+/**
+ * We clone everything that comes in or goes out. This does a reasonable job of simulating an
+ * external database. We just use cloned copies of objects to represent data that's been marshalled
+ * into tables and columns.
+ */
+public class ToDoDatabaseImpl implements ToDoDatabase
+{
+    private long _nextId = 1000;
+
+    private final Map<Long, ToDoItem> _items = newMap();
+
+    public ToDoDatabaseImpl()
+    {
+        // A couple of items to get us started:
+
+        add("Ditch Struts", 1);
+        add("Eliminate JSF", 2);
+        add("Conquer Rife", 3);
+    }
+
+    private void add(String title, int order)
+    {
+        ToDoItem item = new ToDoItem();
+
+        item.setTitle(title);
+        item.setOrder(order);
+
+        add(item);
+    }
+
+    public void add(ToDoItem item)
+    {
+        long id = _nextId++;
+
+        item.setId(id);
+
+        _items.put(id, item.clone());
+    }
+
+    public List<ToDoItem> findAll()
+    {
+        List<ToDoItem> result = newList();
+
+        for (ToDoItem item : _items.values())
+            result.add(item.clone());
+
+        Comparator<ToDoItem> comparator = new Comparator<ToDoItem>()
+        {
+            public int compare(ToDoItem o1, ToDoItem o2)
+            {
+                return o1.getOrder() - o2.getOrder();
+            }
+        };
+
+        Collections.sort(result, comparator);
+
+        return result;
+    }
+
+    public void update(ToDoItem item)
+    {
+        long id = item.getId();
+
+        if (!_items.containsKey(id))
+            throw new RuntimeException(String.format("ToDoItem #%d not found.", id));
+
+        _items.put(id, item.clone());
+    }
+
+}

Modified: tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/AssetDispatcherTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/AssetDispatcherTest.java?view=diff&rev=496578&r1=496577&r2=496578
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/AssetDispatcherTest.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/AssetDispatcherTest.java Mon Jan 15 18:58:40 2007
@@ -19,6 +19,7 @@
 
 import javax.servlet.http.HttpServletResponse;
 
+import org.apache.tapestry.TapestryConstants;
 import org.apache.tapestry.internal.test.InternalBaseTestCase;
 import org.apache.tapestry.ioc.Resource;
 import org.apache.tapestry.ioc.internal.util.ClasspathResource;
@@ -30,7 +31,7 @@
 
 public class AssetDispatcherTest extends InternalBaseTestCase
 {
-    private static final String SMILEY_CLIENT_URL = "/asset/app1/pages/smiley.png";
+    private static final String SMILEY_CLIENT_URL = "/assets/app1/pages/smiley.png";
 
     private static final String SMILEY_PATH = "org/apache/tapestry/integration/app1/pages/smiley.png";
 
@@ -89,7 +90,7 @@
         ResourceCache cache = newResourceCache();
         ResourceStreamer streamer = newResourceStreamer();
 
-        String clientURL = "/asset/app1/pages/smiley_png";
+        String clientURL = "/assets/app1/pages/smiley_png";
         String resourcePath = "org/apache/tapestry/integration/app1/pages/smiley_png";
 
         train_getPath(request, clientURL);
@@ -118,7 +119,7 @@
         ResourceCache cache = newResourceCache();
         ResourceStreamer streamer = newResourceStreamer();
 
-        String clientURL = "/asset/app1/pages/smiley.WRONG.png";
+        String clientURL = "/assets/app1/pages/smiley.WRONG.png";
         String resourcePath = "org/apache/tapestry/integration/app1/pages/smiley.WRONG.png";
 
         train_getPath(request, clientURL);
@@ -149,7 +150,7 @@
         ResourceCache cache = newResourceCache();
         ResourceStreamer streamer = newResourceStreamer();
 
-        String clientURL = "/asset/app1/pages/smiley.RIGHT.png";
+        String clientURL = TapestryConstants.ASSET_PATH_PREFIX + "app1/pages/smiley.RIGHT.png";
         String resourcePath = "org/apache/tapestry/integration/app1/pages/smiley.RIGHT.png";
 
         train_getPath(request, clientURL);

Modified: tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/ClasspathAssetAliasManagerImplTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/ClasspathAssetAliasManagerImplTest.java?view=diff&rev=496578&r1=496577&r2=496578
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/ClasspathAssetAliasManagerImplTest.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/ClasspathAssetAliasManagerImplTest.java Mon Jan 15 18:58:40 2007
@@ -18,6 +18,7 @@
 
 import java.util.Map;
 
+import org.apache.tapestry.TapestryConstants;
 import org.apache.tapestry.internal.test.InternalBaseTestCase;
 import org.apache.tapestry.services.ClasspathAssetAliasManager;
 import org.apache.tapestry.services.Request;
@@ -50,7 +51,8 @@
         ClasspathAssetAliasManager manager = new ClasspathAssetAliasManagerImpl(request,
                 configuration());
 
-        assertEquals(manager.toClientURL(resourcePath), "/ctx" + expectedClientURL);
+        assertEquals(manager.toClientURL(resourcePath), "/ctx"
+                + TapestryConstants.ASSET_PATH_PREFIX + expectedClientURL);
 
         verify();
     }
@@ -60,11 +62,11 @@
     {
         return new Object[][]
         {
-        { "foo/bar/Baz.txt", "/asset/foo/bar/Baz.txt" },
-        { "com/example/mylib/Foo.bar", "/asset/mylib/Foo.bar" },
-        { "com/example/mylib/nested/Foo.bar", "/asset/mylib/nested/Foo.bar" },
-        { "org/apache/tapestry/internal/Foo.bar", "/asset/tapestry-internal/Foo.bar" },
-        { "org/apache/tapestry/Foo.bar", "/asset/tapestry/Foo.bar" }, };
+        { "foo/bar/Baz.txt", "foo/bar/Baz.txt" },
+        { "com/example/mylib/Foo.bar", "mylib/Foo.bar" },
+        { "com/example/mylib/nested/Foo.bar", "mylib/nested/Foo.bar" },
+        { "org/apache/tapestry/internal/Foo.bar", "tapestry-internal/Foo.bar" },
+        { "org/apache/tapestry/Foo.bar", "tapestry/Foo.bar" }, };
     }
 
     @Test(dataProvider = "to_resource_path_data")
@@ -84,7 +86,7 @@
         for (Object[] pair : data)
         {
             Object buffer = pair[0];
-            pair[0] = pair[1];
+            pair[0] = TapestryConstants.ASSET_PATH_PREFIX + pair[1];
             pair[1] = buffer;
         }
 

Modified: tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/MarkupWriterImplTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/MarkupWriterImplTest.java?view=diff&rev=496578&r1=496577&r2=496578
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/MarkupWriterImplTest.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/MarkupWriterImplTest.java Mon Jan 15 18:58:40 2007
@@ -31,6 +31,32 @@
         w.write("fail!");
     }
 
+    @Test
+    public void write_whitespace_before_start_of_root_element_is_ignored()
+    {
+        MarkupWriter w = new MarkupWriterImpl(new XMLMarkupModel(), null);
+
+        w.write("  ");
+
+        w.element("root");
+        w.end();
+
+        assertEquals(w.toString(), "<root/>");
+    }
+
+    @Test
+    public void write_whitespace_after_end_of_root_element_is_ignored()
+    {
+        MarkupWriter w = new MarkupWriterImpl(new XMLMarkupModel(), null);
+
+        w.element("root");
+        w.end();
+
+        w.write("  ");
+
+        assertEquals(w.toString(), "<root/>");
+    }
+
     @Test(expectedExceptions = IllegalStateException.class)
     public void comment_with_no_current_element()
     {

Modified: tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/NoOpCookieSource.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/NoOpCookieSource.java?view=diff&rev=496578&r1=496577&r2=496578
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/NoOpCookieSource.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/NoOpCookieSource.java Mon Jan 15 18:58:40 2007
@@ -1,3 +1,17 @@
+// Copyright 2007 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.internal.services;
 
 import org.apache.tapestry.services.Cookies;

Modified: tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/RenderQueueImplTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/RenderQueueImplTest.java?view=diff&rev=496578&r1=496577&r2=496578
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/RenderQueueImplTest.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/RenderQueueImplTest.java Mon Jan 15 18:58:40 2007
@@ -12,85 +12,89 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-package org.apache.tapestry.internal.services;
-
-import org.apache.commons.logging.Log;
-import org.apache.tapestry.MarkupWriter;
-import org.apache.tapestry.internal.test.InternalBaseTestCase;
-import org.apache.tapestry.runtime.RenderCommand;
-import org.apache.tapestry.runtime.RenderQueue;
-import org.testng.annotations.Test;
-
-public class RenderQueueImplTest extends InternalBaseTestCase
-{
-    @Test
-    public void run_commands()
-    {
-        final RenderCommand command2 = newMock(RenderCommand.class);
-        RenderCommand command1 = new RenderCommand()
-        {
-            public void render(MarkupWriter writer, RenderQueue queue)
-            {
-                queue.push(command2);
-            }
-        };
-
-        Log log = newLog();
-        MarkupWriter writer = newMarkupWriter();
-        RenderQueueImpl queue = new RenderQueueImpl(log);
-
-        command2.render(writer, queue);
-
-        replay();
-
-        queue.push(command1);
-        queue.run(writer);
-
-        verify();
-    }
-
-    @Test
-    public void command_failed()
-    {
-        final RuntimeException t = new RuntimeException("Oops.");
-
-        RenderCommand rc = new RenderCommand()
-        {
-
-            public void render(MarkupWriter writer, RenderQueue queue)
-            {
-                throw t;
-            }
-
-            @Override
-            public String toString()
-            {
-                return "FailedCommand";
-            }
-        };
-
-        Log log = newLog();
-        MarkupWriter writer = newMarkupWriter();
-
-        log.error("Render queue error in FailedCommand: Oops.", t);
-
-        replay();
-
-        RenderQueueImpl queue = new RenderQueueImpl(log);
-
-        queue.push(rc);
-
-        try
-        {
-            queue.run(writer);
-            unreachable();
-        }
-        catch (RuntimeException ex)
-        {
-            assertSame(ex, t);
-        }
-
-        verify();
-    }
-
-}
+package org.apache.tapestry.internal.services;
+
+import org.apache.commons.logging.Log;
+import org.apache.tapestry.MarkupWriter;
+import org.apache.tapestry.internal.test.InternalBaseTestCase;
+import org.apache.tapestry.runtime.RenderCommand;
+import org.apache.tapestry.runtime.RenderQueue;
+import org.testng.annotations.Test;
+
+public class RenderQueueImplTest extends InternalBaseTestCase
+{
+    @Test
+    public void run_commands()
+    {
+        final RenderCommand command2 = newMock(RenderCommand.class);
+        RenderCommand command1 = new RenderCommand()
+        {
+            public void render(MarkupWriter writer, RenderQueue queue)
+            {
+                queue.push(command2);
+            }
+        };
+
+        Log log = newLog();
+        MarkupWriter writer = newMarkupWriter();
+        RenderQueueImpl queue = new RenderQueueImpl(log);
+
+        expect(log.isDebugEnabled()).andReturn(false).atLeastOnce();
+
+        command2.render(writer, queue);
+
+        replay();
+
+        queue.push(command1);
+        queue.run(writer);
+
+        verify();
+    }
+
+    @Test
+    public void command_failed()
+    {
+        final RuntimeException t = new RuntimeException("Oops.");
+
+        RenderCommand rc = new RenderCommand()
+        {
+
+            public void render(MarkupWriter writer, RenderQueue queue)
+            {
+                throw t;
+            }
+
+            @Override
+            public String toString()
+            {
+                return "FailedCommand";
+            }
+        };
+
+        Log log = newLog();
+        MarkupWriter writer = newMarkupWriter();
+
+        expect(log.isDebugEnabled()).andReturn(false).atLeastOnce();
+
+        log.error("Render queue error in FailedCommand: Oops.", t);
+
+        replay();
+
+        RenderQueueImpl queue = new RenderQueueImpl(log);
+
+        queue.push(rc);
+
+        try
+        {
+            queue.run(writer);
+            unreachable();
+        }
+        catch (RuntimeException ex)
+        {
+            assertSame(ex, t);
+        }
+
+        verify();
+    }
+
+}

Modified: tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/structure/ComponentPageElementImplTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/structure/ComponentPageElementImplTest.java?view=diff&rev=496578&r1=496577&r2=496578
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/structure/ComponentPageElementImplTest.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/structure/ComponentPageElementImplTest.java Mon Jan 15 18:58:40 2007
@@ -337,7 +337,7 @@
             cpe.getEmbeddedElement("unknown");
             unreachable();
         }
-        catch (IllegalArgumentException ex)
+        catch (TapestryException ex)
         {
             assertEquals(ex.getMessage(), "Component " + component.getClass().getName()
                     + " does not contain an embedded component with id 'unknown'.");
@@ -425,7 +425,7 @@
             cpe.getMixinByClassName("foo.Baz");
             unreachable();
         }
-        catch (IllegalArgumentException ex)
+        catch (TapestryException ex)
         {
             assertTrue(ex.getMessage().endsWith(" does not contain a mixin of type foo.Baz."));
         }

Modified: tapestry/tapestry5/tapestry-core/trunk/src/test/resources/log4j.properties
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/resources/log4j.properties?view=diff&rev=496578&r1=496577&r2=496578
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/test/resources/log4j.properties (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/test/resources/log4j.properties Mon Jan 15 18:58:40 2007
@@ -30,3 +30,5 @@
 log4j.category.org.apache.tapestry.integration.app1=error
 log4j.category.org.apache.tapestry.corelib=error
 
+log4j.category.org.apache.tapestry.integration.app1.pages.ToDoList=debug
+