Author: hlship
Date: Fri Oct  7 06:51:01 2005
New Revision: 307126

URL: http://svn.apache.org/viewcvs?rev=307126&view=rev
Log:
Continue revving Virtual Library for Tapestry 4.0

Added:
    
jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/OperationsUser.java
    
jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/services/
    
jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/services/ErrorPresenter.java
    
jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/services/ErrorPresenterImpl.java
    
jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/services/RemoteCallback.java
    
jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/services/RemoteTemplate.java
    
jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/services/RemoteTemplateImpl.java
    jakarta/tapestry/trunk/examples/Vlib/src/test/org/
    jakarta/tapestry/trunk/examples/Vlib/src/test/org/apache/
    jakarta/tapestry/trunk/examples/Vlib/src/test/org/apache/tapestry/
    jakarta/tapestry/trunk/examples/Vlib/src/test/org/apache/tapestry/vlib/
    
jakarta/tapestry/trunk/examples/Vlib/src/test/org/apache/tapestry/vlib/services/
    
jakarta/tapestry/trunk/examples/Vlib/src/test/org/apache/tapestry/vlib/services/ErrorPresenterTest.java
    
jakarta/tapestry/trunk/examples/Vlib/src/test/org/apache/tapestry/vlib/services/RemoteTemplateTest.java
Modified:
    jakarta/tapestry/trunk/.classpath
    jakarta/tapestry/trunk/examples/Vlib/src/context/WEB-INF/BookLink.html
    jakarta/tapestry/trunk/examples/Vlib/src/context/WEB-INF/PersonLink.html
    jakarta/tapestry/trunk/examples/Vlib/src/context/WEB-INF/hivemodule.xml
    
jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/components/Borrow.java

Modified: jakarta/tapestry/trunk/.classpath
URL: 
http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/.classpath?rev=307126&r1=307125&r2=307126&view=diff
==============================================================================
Binary files - no diff available.

Modified: jakarta/tapestry/trunk/examples/Vlib/src/context/WEB-INF/BookLink.html
URL: 
http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/examples/Vlib/src/context/WEB-INF/BookLink.html?rev=307126&r1=307125&r2=307126&view=diff
==============================================================================
--- jakarta/tapestry/trunk/examples/Vlib/src/context/WEB-INF/BookLink.html 
(original)
+++ jakarta/tapestry/trunk/examples/Vlib/src/context/WEB-INF/BookLink.html Fri 
Oct  7 06:51:01 2005
@@ -1,4 +1,4 @@
 <span jwcid="$content$">
 <a href="#" jwcid="link"><span jwcid="@Insert" value="ognl:book.title"/></a>
-<span jwcid="@Conditional" condition="ognl:newlyAdded"><img 
src="images/new.png" width="27" height="12" border="0" alt="New"></span>
+<span jwcid="@If" condition="ognl:newlyAdded"><img src="images/new.png" 
width="27" height="12" border="0" alt="New"/></span>
 </span>

Modified: 
jakarta/tapestry/trunk/examples/Vlib/src/context/WEB-INF/PersonLink.html
URL: 
http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/examples/Vlib/src/context/WEB-INF/PersonLink.html?rev=307126&r1=307125&r2=307126&view=diff
==============================================================================
--- jakarta/tapestry/trunk/examples/Vlib/src/context/WEB-INF/PersonLink.html 
(original)
+++ jakarta/tapestry/trunk/examples/Vlib/src/context/WEB-INF/PersonLink.html 
Fri Oct  7 06:51:01 2005
@@ -1,11 +1,13 @@
 <span jwcid="$content$">
 
-<span jwcid="@Conditional" condition="ognl:! omit">
+    <span jwcid="@If" condition="ognl:omit">
+        &nbsp;
+    </span>
+    
+<span jwcid="@Else">
 <a jwcid="link"><span jwcid="@Insert" value="ognl:name">Joe User</span></a>
 </span>
 
-<span jwcid="@Conditional" condition="ognl:omit">
-&nbsp;
-</span>
+
 
 </span>

Modified: 
jakarta/tapestry/trunk/examples/Vlib/src/context/WEB-INF/hivemodule.xml
URL: 
http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/examples/Vlib/src/context/WEB-INF/hivemodule.xml?rev=307126&r1=307125&r2=307126&view=diff
==============================================================================
--- jakarta/tapestry/trunk/examples/Vlib/src/context/WEB-INF/hivemodule.xml 
(original)
+++ jakarta/tapestry/trunk/examples/Vlib/src/context/WEB-INF/hivemodule.xml Fri 
Oct  7 06:51:01 2005
@@ -15,7 +15,7 @@
    limitations under the License.

 -->

 

-<module id="vlib" version="4.0.0">

+<module id="vlib" version="4.0.0" package="org.apache.tapestry.vlib.services">

     

     <contribution configuration-id="tapestry.url.ServiceEncoders">

         <direct-service-encoder id="direct" stateless-extension="direct" 
stateful-extension="sdirect"/>

@@ -23,5 +23,35 @@
         <page-service-encoder id="external" extension="external" 
service="external"/>    

         <asset-encoder id="asset" path="/assets/"/>

         <extension-encoder id="ext" extension="svc" after="*"/>

-    </contribution>    

+    </contribution>

+     

+    <service-point id="Operations" 
interface="org.apache.tapestry.vlib.ejb.IOperations">

+        

+        EJB for the majority of operations needed by the presentation tier.

+        
+        <invoke-factory service-id="hivemind.lib.EJBProxyFactory">
+            <construct 
home-interface="org.apache.tapestry.vlib.ejb.IOperationsHome" 

+                jndi-name="vlib/Operations"/> 
+        </invoke-factory>
+    </service-point>

+    

+    <service-point id="RemoteTemplate">
+        Used to process and recover from remote exceptions while

+        executing a block of code.

+        

+        <invoke-factory>
+            <construct class="RemoteTemplateImpl">
+                <set-object property="coordinator" 
value="service:hivemind.lib.RemoteExceptionCoordinator"/>
+            </construct>
+        </invoke-factory>

+    </service-point>

+    

+    <service-point id="ErrorPresenter">
+        

+        Activates the Home or MyLibrary page to report an error.

+        

+        <create-instance class="ErrorPresenterImpl"/>

+        
+    </service-point>

+     

 </module>

Added: 
jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/OperationsUser.java
URL: 
http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/OperationsUser.java?rev=307126&view=auto
==============================================================================
--- 
jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/OperationsUser.java
 (added)
+++ 
jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/OperationsUser.java
 Fri Oct  7 06:51:01 2005
@@ -0,0 +1,40 @@
+// 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.vlib;

+

+import org.apache.tapestry.annotations.InjectObject;

+import org.apache.tapestry.vlib.ejb.IOperations;

+import org.apache.tapestry.vlib.services.ErrorPresenter;

+import org.apache.tapestry.vlib.services.RemoteTemplate;

+

+/**

+ * Interface for pages and components that need to use the

+ * [EMAIL PROTECTED] org.apache.tapestry.vlib.ejb.IOperations} EJB. Acts as a 
mixin, using annotations to

+ * inject supporting properties into the page or component.

+ * 

+ * @author Howard M. Lewis Ship

+ * @since 4.0

+ */

+public interface OperationsUser

+{

+    @InjectObject("service:vlib.Operations")

+    public abstract IOperations getOperations();

+

+    @InjectObject("service:vlib.RemoteTemplate")

+    public abstract RemoteTemplate getRemoteTemplate();

+

+    @InjectObject("service:vlib.ErrorPresenter")

+    public abstract ErrorPresenter getErrorPresenter();

+}


Modified: 
jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/components/Borrow.java
URL: 
http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/components/Borrow.java?rev=307126&r1=307125&r2=307126&view=diff
==============================================================================
--- 
jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/components/Borrow.java
 (original)
+++ 
jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/components/Borrow.java
 Fri Oct  7 06:51:01 2005
@@ -26,12 +26,12 @@
 import org.apache.tapestry.annotations.InjectState;
 import org.apache.tapestry.annotations.Message;
 import org.apache.tapestry.annotations.Parameter;
-import org.apache.tapestry.vlib.VirtualLibraryEngine;
+import org.apache.tapestry.vlib.OperationsUser;
 import org.apache.tapestry.vlib.Visit;
 import org.apache.tapestry.vlib.ejb.Book;
 import org.apache.tapestry.vlib.ejb.BorrowException;
-import org.apache.tapestry.vlib.ejb.IOperations;
 import org.apache.tapestry.vlib.pages.Home;
+import org.apache.tapestry.vlib.services.RemoteCallback;
 
 /**
  * Implements the Borrow link that appears on many pages. <table border=1>
@@ -58,7 +58,7 @@
  * @author Howard Lewis Ship
  */
 
-public abstract class Borrow extends BaseComponent
+public abstract class Borrow extends BaseComponent implements OperationsUser
 {
     @Parameter(required = true)
     public abstract Book getBook();
@@ -94,41 +94,38 @@
         return visit.isLoggedInUser(book.getHolderId());
     }
 
-    public IPage borrow(IRequestCycle cycle, Integer bookPK)
+    public IPage borrow(final IRequestCycle cycle, final Integer bookId)
     {
-        Visit visit = getVisit();
-        Home home = getHome();
-
-        VirtualLibraryEngine vengine = (VirtualLibraryEngine) 
cycle.getEngine();
+        final Visit visit = getVisit();
+        final Home home = getHome();
 
-        int i = 0;
-        while (true)
+        RemoteCallback callback = new RemoteCallback()
         {
-            try
-            {
-                IOperations bean = vengine.getOperations();
-                Book book = bean.borrowBook(bookPK, visit.getUserId());
-
-                home.setMessage(borrowedBook(book.getTitle()));
-
-                break;
-            }
-            catch (BorrowException ex)
+            public Object remoteCallback() throws RemoteException
             {
-                vengine.presentError(ex.getMessage(), cycle);
-                return null;
+                try
+                {
+                    Book book = getOperations().borrowBook(bookId, 
visit.getUserId());
+
+                    home.setMessage(borrowedBook(book.getTitle()));
+
+                    return null;
+                }
+                catch (BorrowException ex)
+                {
+                    getErrorPresenter().presentError(ex.getMessage(), cycle);
+
+                    return null;
+                }
+                catch (FinderException ex)
+                {
+                    throw new ApplicationRuntimeException("Unable to find book 
or user.", ex);
+                }
             }
-            catch (FinderException ex)
-            {
-                throw new ApplicationRuntimeException("Unable to find book or 
user. ", ex);
-            }
-            catch (RemoteException ex)
-            {
-                vengine.rmiFailure("Remote exception borrowing book.", ex, 
i++);
-            }
-        }
+        };
+
+        getRemoteTemplate().doRemote(callback, "Error borrowing book.");
 
         return home;
     }
-
 }

Added: 
jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/services/ErrorPresenter.java
URL: 
http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/services/ErrorPresenter.java?rev=307126&view=auto
==============================================================================
--- 
jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/services/ErrorPresenter.java
 (added)
+++ 
jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/services/ErrorPresenter.java
 Fri Oct  7 06:51:01 2005
@@ -0,0 +1,28 @@
+// 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.vlib.services;

+

+import org.apache.tapestry.IRequestCycle;

+

+/**

+ * Contains logic used to present an error to the user; smart about which page 
to move to.

+ * 

+ * @author Howard M. Lewis Ship

+ * @since 4.0

+ */

+public interface ErrorPresenter

+{

+    void presentError(String message, IRequestCycle cycle);

+}


Added: 
jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/services/ErrorPresenterImpl.java
URL: 
http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/services/ErrorPresenterImpl.java?rev=307126&view=auto
==============================================================================
--- 
jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/services/ErrorPresenterImpl.java
 (added)
+++ 
jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/services/ErrorPresenterImpl.java
 Fri Oct  7 06:51:01 2005
@@ -0,0 +1,48 @@
+// 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.vlib.services;

+

+import org.apache.tapestry.IEngine;

+import org.apache.tapestry.IRequestCycle;

+import org.apache.tapestry.vlib.IErrorProperty;

+import org.apache.tapestry.vlib.Visit;

+

+/**

+ * Implementation of [EMAIL PROTECTED] 
org.apache.tapestry.vlib.services.ErrorPresenter}.

+ * 

+ * @author Howard M. Lewis Ship

+ * @since 4.0

+ */

+public class ErrorPresenterImpl implements ErrorPresenter

+{

+    public void presentError(String message, IRequestCycle cycle)

+    {

+        IEngine engine = cycle.getEngine();

+

+        String pageName = "Home";

+        // Get, but don't create, the visit.

+        Visit visit = (Visit) engine.getVisit();

+

+        if (visit != null && visit.isUserLoggedIn())

+            pageName = "MyLibrary";

+

+        IErrorProperty page = (IErrorProperty) cycle.getPage(pageName);

+

+        page.setError(message);

+

+        cycle.activate(page);

+    }

+

+}


Added: 
jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/services/RemoteCallback.java
URL: 
http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/services/RemoteCallback.java?rev=307126&view=auto
==============================================================================
--- 
jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/services/RemoteCallback.java
 (added)
+++ 
jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/services/RemoteCallback.java
 Fri Oct  7 06:51:01 2005
@@ -0,0 +1,34 @@
+// 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.vlib.services;

+

+import java.rmi.RemoteException;

+

+/**

+ * Callback interface used when performing

+ * 

+ * @author Howard M. Lewis Ship

+ * @since 4.0

+ */

+public interface RemoteCallback

+{

+    /**

+     * Invoked by [EMAIL PROTECTED] RemoteTemplate}.

+     * 

+     * @return

+     * @throws RemoteException

+     */

+    Object remoteCallback() throws RemoteException;

+}


Added: 
jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/services/RemoteTemplate.java
URL: 
http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/services/RemoteTemplate.java?rev=307126&view=auto
==============================================================================
--- 
jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/services/RemoteTemplate.java
 (added)
+++ 
jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/services/RemoteTemplate.java
 Fri Oct  7 06:51:01 2005
@@ -0,0 +1,34 @@
+// 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.vlib.services;

+

+/**

+ * Used to execute a [EMAIL PROTECTED] 
org.apache.tapestry.vlib.services.RemoteCallback}.

+ * 

+ * @author Howard M. Lewis Ship

+ */

+public interface RemoteTemplate

+{

+    /**

+     * Executes the callback within a retry loop; consumes any 
RemoteExceptions.

+     * 

+     * @param callback

+     *            the callback to execute

+     * @param errorMessage

+     *            used when the callback fails

+     * @return the return value of the callback

+     */

+    Object doRemote(RemoteCallback callback, String errorMessage);

+}


Added: 
jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/services/RemoteTemplateImpl.java
URL: 
http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/services/RemoteTemplateImpl.java?rev=307126&view=auto
==============================================================================
--- 
jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/services/RemoteTemplateImpl.java
 (added)
+++ 
jakarta/tapestry/trunk/examples/Vlib/src/java/org/apache/tapestry/vlib/services/RemoteTemplateImpl.java
 Fri Oct  7 06:51:01 2005
@@ -0,0 +1,61 @@
+// 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.vlib.services;

+

+import java.rmi.RemoteException;

+

+import org.apache.hivemind.ApplicationRuntimeException;

+import org.apache.hivemind.lib.RemoteExceptionCoordinator;

+

+/**

+ * Handles remote exceptions and retries.

+ * 

+ * @author Howard M. Lewis Ship

+ * @since 4.0

+ */

+public class RemoteTemplateImpl implements RemoteTemplate

+{

+    private final static int MAX_ATTEMPTS = 2;

+

+    private RemoteExceptionCoordinator _coordinator;

+

+    public Object doRemote(RemoteCallback callback, String errorMessage)

+    {

+        int attempt = 1;

+

+        while (true)

+        {

+            try

+            {

+                return callback.remoteCallback();

+            }

+            catch (RemoteException ex)

+            {

+                _coordinator.fireRemoteExceptionDidOccur(callback, ex);

+

+                if (attempt++ < MAX_ATTEMPTS)

+                    continue;

+

+                throw new ApplicationRuntimeException(errorMessage, ex);

+            }

+

+        }

+    }

+

+    public void setCoordinator(RemoteExceptionCoordinator coordinator)

+    {

+        _coordinator = coordinator;

+    }

+}


Added: 
jakarta/tapestry/trunk/examples/Vlib/src/test/org/apache/tapestry/vlib/services/ErrorPresenterTest.java
URL: 
http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/examples/Vlib/src/test/org/apache/tapestry/vlib/services/ErrorPresenterTest.java?rev=307126&view=auto
==============================================================================
--- 
jakarta/tapestry/trunk/examples/Vlib/src/test/org/apache/tapestry/vlib/services/ErrorPresenterTest.java
 (added)
+++ 
jakarta/tapestry/trunk/examples/Vlib/src/test/org/apache/tapestry/vlib/services/ErrorPresenterTest.java
 Fri Oct  7 06:51:01 2005
@@ -0,0 +1,116 @@
+// 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.vlib.services;

+

+import org.apache.hivemind.test.HiveMindTestCase;

+import org.apache.tapestry.IEngine;

+import org.apache.tapestry.IPage;

+import org.apache.tapestry.IRequestCycle;

+import org.apache.tapestry.vlib.IErrorProperty;

+import org.apache.tapestry.vlib.Visit;

+

+/**

+ * Tests for [EMAIL PROTECTED] 
org.apache.tapestry.vlib.services.ErrorPresenterImpl}.

+ * 

+ * @author Howard M. Lewis Ship

+ * @since 4.0

+ */

+public class ErrorPresenterTest extends HiveMindTestCase

+{

+

+    protected void trainGetPage(IRequestCycle cycle, String pageName, IPage 
page)

+    {

+        cycle.getPage(pageName);

+        setReturnValue(cycle, page);

+    }

+

+    protected void trainGetVisit(IEngine engine, Object visit)

+    {

+        engine.getVisit();

+        setReturnValue(engine, visit);

+    }

+

+    protected void trainGetEngine(IRequestCycle cycle, IEngine engine)

+    {

+        cycle.getEngine();

+        setReturnValue(cycle, engine);

+    }

+

+    public void testLoggedOut()

+    {

+        IRequestCycle cycle = newCycle();

+        IEngine engine = newEngine();

+        IErrorProperty page = newPage();

+

+        trainGetEngine(cycle, engine);

+

+        trainGetVisit(engine, null);

+

+        trainGetPage(cycle, "Home", page);

+

+        page.setError("An error.");

+

+        cycle.activate(page);

+

+        replayControls();

+

+        new ErrorPresenterImpl().presentError("An error.", cycle);

+

+        verifyControls();

+    }

+

+    private IErrorProperty newPage()

+    {

+        return (IErrorProperty) newMock(IErrorProperty.class);

+    }

+

+    private IEngine newEngine()

+    {

+        return (IEngine) newMock(IEngine.class);

+    }

+

+    private IRequestCycle newCycle()

+    {

+        return (IRequestCycle) newMock(IRequestCycle.class);

+    }

+

+    public void testLoggedIn()

+    {

+

+        IRequestCycle cycle = newCycle();

+        IEngine engine = newEngine();

+        IErrorProperty page = newPage();

+        Visit visit = (Visit) newMock(Visit.class);

+

+        trainGetEngine(cycle, engine);

+

+        trainGetVisit(engine, visit);

+

+        visit.isUserLoggedIn();

+        setReturnValue(visit, true);

+

+        trainGetPage(cycle, "MyLibrary", page);

+

+        page.setError("An error.");

+

+        cycle.activate(page);

+

+        replayControls();

+

+        new ErrorPresenterImpl().presentError("An error.", cycle);

+

+        verifyControls();

+    }

+}


Added: 
jakarta/tapestry/trunk/examples/Vlib/src/test/org/apache/tapestry/vlib/services/RemoteTemplateTest.java
URL: 
http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/examples/Vlib/src/test/org/apache/tapestry/vlib/services/RemoteTemplateTest.java?rev=307126&view=auto
==============================================================================
--- 
jakarta/tapestry/trunk/examples/Vlib/src/test/org/apache/tapestry/vlib/services/RemoteTemplateTest.java
 (added)
+++ 
jakarta/tapestry/trunk/examples/Vlib/src/test/org/apache/tapestry/vlib/services/RemoteTemplateTest.java
 Fri Oct  7 06:51:01 2005
@@ -0,0 +1,110 @@
+// 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.vlib.services;

+

+import java.rmi.RemoteException;

+

+import org.apache.hivemind.ApplicationRuntimeException;

+import org.apache.hivemind.lib.RemoteExceptionCoordinator;

+import org.apache.hivemind.test.HiveMindTestCase;

+

+/**

+ * Tests for [EMAIL PROTECTED] 
org.apache.tapestry.vlib.services.RemoteTemplateImpl}.

+ * 

+ * @author Howard M. Lewis Ship

+ * @since 4.0

+ */

+public class RemoteTemplateTest extends HiveMindTestCase

+{

+    public void testSuccess()

+    {

+        RemoteTemplate rt = new RemoteTemplateImpl();

+        RemoteCallback callback = new RemoteCallback()

+        {

+            public Object remoteCallback() throws RemoteException

+            {

+                return "flintstone";

+            }

+        };

+

+        Object actual = rt.doRemote(callback, "my error message");

+

+        assertEquals("flintstone", actual);

+    }

+

+    public void testSuccessAfterRetry() throws Exception

+    {

+        RemoteCallback callback = (RemoteCallback) 
newMock(RemoteCallback.class);

+        RemoteExceptionCoordinator coordinator = (RemoteExceptionCoordinator) 
newMock(RemoteExceptionCoordinator.class);

+

+        Throwable t = new RemoteException();

+

+        callback.remoteCallback();

+        setThrowable(callback, t);

+

+        coordinator.fireRemoteExceptionDidOccur(callback, t);

+

+        callback.remoteCallback();

+        setReturnValue(callback, "rubble");

+

+        replayControls();

+

+        RemoteTemplateImpl rt = new RemoteTemplateImpl();

+

+        rt.setCoordinator(coordinator);

+

+        assertEquals("rubble", rt.doRemote(callback, "my error message"));

+

+        verifyControls();

+    }

+

+    public void testFailure() throws Exception

+    {

+        RemoteCallback callback = (RemoteCallback) 
newMock(RemoteCallback.class);

+        RemoteExceptionCoordinator coordinator = (RemoteExceptionCoordinator) 
newMock(RemoteExceptionCoordinator.class);

+

+        Throwable t1 = new RemoteException();

+        Throwable t2 = new RemoteException();

+

+        callback.remoteCallback();

+        setThrowable(callback, t1);

+

+        coordinator.fireRemoteExceptionDidOccur(callback, t1);

+

+        callback.remoteCallback();

+        setThrowable(callback, t2);

+

+        coordinator.fireRemoteExceptionDidOccur(callback, t2);

+

+        replayControls();

+

+        RemoteTemplateImpl rt = new RemoteTemplateImpl();

+

+        rt.setCoordinator(coordinator);

+

+        try

+        {

+            rt.doRemote(callback, "error message");

+            unreachable();

+        }

+        catch (ApplicationRuntimeException ex)

+        {

+            assertEquals("error message", ex.getMessage());

+            assertSame(t2, ex.getRootCause());

+        }

+

+        verifyControls();

+    }

+}




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to