1 15 package org.apache.tapestry.callback; 16 17 import org.apache.hivemind.ApplicationRuntimeException; 18 import org.apache.tapestry.IExternalPage; 19 import org.apache.tapestry.IPage; 20 import org.apache.tapestry.IRequestCycle; 21 import org.apache.tapestry.components.BaseComponentTestCase; 22 import org.easymock.MockControl; 23 24 30 public class TestExternalCallback extends BaseComponentTestCase 31 { 32 private IExternalPage newExternalPage() 33 { 34 return (IExternalPage) newMock(IExternalPage.class); 35 } 36 37 private IExternalPage newExternalPage(String pageName) 38 { 39 MockControl control = newControl(IExternalPage.class); 40 IExternalPage page = (IExternalPage) control.getMock(); 41 42 page.getPageName(); 43 control.setReturnValue(pageName); 44 45 return page; 46 } 47 48 public void testByName() 49 { 50 Object [] parameters = 51 { "param1", "param2" }; 52 53 IExternalPage page = newExternalPage(); 54 IRequestCycle cycle = newCycle("Fred", page); 55 56 cycle.activate(page); 57 58 page.activateExternalPage(parameters, cycle); 59 60 replayControls(); 61 62 ExternalCallback callback = new ExternalCallback("Fred", parameters); 63 64 assertEquals("ExternalCallback[Fred/param1, param2]", callback.toString()); 65 66 callback.performCallback(cycle); 67 68 verifyControls(); 69 } 70 71 public void testByNameNoParameters() 72 { 73 IExternalPage page = newExternalPage(); 74 IRequestCycle cycle = newCycle("Fred", page); 75 76 cycle.activate(page); 77 78 page.activateExternalPage(null, cycle); 79 80 replayControls(); 81 82 ExternalCallback callback = new ExternalCallback("Fred", null); 83 84 assertEquals("ExternalCallback[Fred]", callback.toString()); 85 86 callback.performCallback(cycle); 87 88 verifyControls(); 89 } 90 91 public void testByPage() 92 { 93 Object [] parameters = 94 { "param1", "param2" }; 95 96 IExternalPage page = newExternalPage("Barney"); 97 IRequestCycle cycle = newCycle("Barney", page); 98 99 cycle.activate(page); 100 101 page.activateExternalPage(parameters, cycle); 102 103 replayControls(); 104 105 ExternalCallback callback = new ExternalCallback(page, parameters); 106 107 assertEquals("ExternalCallback[Barney/param1, param2]", callback.toString()); 108 109 callback.performCallback(cycle); 110 111 verifyControls(); 112 } 113 114 public void testNotExternalPage() 115 { 116 IPage page = newPage(); 117 IRequestCycle cycle = newCycle("Barney", page); 118 119 replayControls(); 120 121 ExternalCallback callback = new ExternalCallback("Barney", null); 122 123 try 124 { 125 callback.performCallback(cycle); 126 } 127 catch (ApplicationRuntimeException ex) 128 { 129 assertEquals( 130 "Page Barney does not implement the IExternalPage interface, and may not be used with the external service.", 131 ex.getMessage()); 132 } 133 134 verifyControls(); 135 } 136 } 137 | Popular Tags |