| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
package org.seasar.teeda.core.unit; |
| 17 | |
|
| 18 | |
import java.util.Locale; |
| 19 | |
|
| 20 | |
import javax.faces.FactoryFinder; |
| 21 | |
import javax.faces.component.UIViewRoot; |
| 22 | |
import javax.faces.internal.ConverterResource; |
| 23 | |
import javax.faces.internal.FacesConfigOptions; |
| 24 | |
import javax.faces.internal.NormalConverterBuilderImpl; |
| 25 | |
import javax.faces.internal.NormalValidatorBuilderImpl; |
| 26 | |
import javax.faces.internal.ValidatorResource; |
| 27 | |
import javax.faces.lifecycle.LifecycleFactory; |
| 28 | |
import javax.faces.render.RenderKitFactory; |
| 29 | |
|
| 30 | |
import org.seasar.framework.unit.S2FrameworkTestCase; |
| 31 | |
import org.seasar.teeda.core.application.navigation.NavigationResource; |
| 32 | |
import org.seasar.teeda.core.managedbean.ManagedBeanFactory; |
| 33 | |
import org.seasar.teeda.core.managedbean.impl.ManagedBeanFactoryImpl; |
| 34 | |
import org.seasar.teeda.core.managedbean.impl.ManagedBeanScopeSaverImpl; |
| 35 | |
import org.seasar.teeda.core.mock.MockApplication; |
| 36 | |
import org.seasar.teeda.core.mock.MockApplicationFactory; |
| 37 | |
import org.seasar.teeda.core.mock.MockApplicationImpl; |
| 38 | |
import org.seasar.teeda.core.mock.MockExternalContext; |
| 39 | |
import org.seasar.teeda.core.mock.MockExternalContextImpl; |
| 40 | |
import org.seasar.teeda.core.mock.MockFacesContext; |
| 41 | |
import org.seasar.teeda.core.mock.MockFacesContextFactory; |
| 42 | |
import org.seasar.teeda.core.mock.MockFacesContextImpl; |
| 43 | |
import org.seasar.teeda.core.mock.MockLifecycle; |
| 44 | |
import org.seasar.teeda.core.mock.MockLifecycleFactory; |
| 45 | |
import org.seasar.teeda.core.mock.MockLifecycleImpl; |
| 46 | |
import org.seasar.teeda.core.mock.MockNavigationHandler; |
| 47 | |
import org.seasar.teeda.core.mock.MockPhaseListener; |
| 48 | |
import org.seasar.teeda.core.mock.MockPropertyResolver; |
| 49 | |
import org.seasar.teeda.core.mock.MockRenderKit; |
| 50 | |
import org.seasar.teeda.core.mock.MockRenderKitFactory; |
| 51 | |
import org.seasar.teeda.core.mock.MockRenderKitImpl; |
| 52 | |
import org.seasar.teeda.core.mock.MockRenderer; |
| 53 | |
import org.seasar.teeda.core.mock.MockStateManager; |
| 54 | |
import org.seasar.teeda.core.mock.MockUIComponent; |
| 55 | |
import org.seasar.teeda.core.mock.MockVariableResolver; |
| 56 | |
import org.seasar.teeda.core.mock.MockViewHandler; |
| 57 | |
import org.seasar.teeda.core.mock.MockViewHandlerImpl; |
| 58 | |
import org.seasar.teeda.core.scope.impl.S2ScopeTranslator; |
| 59 | |
import org.seasar.teeda.core.scope.impl.ScopeManagerImpl; |
| 60 | |
|
| 61 | |
|
| 62 | |
|
| 63 | |
|
| 64 | |
|
| 65 | |
|
| 66 | |
public abstract class TeedaTestCase extends S2FrameworkTestCase { |
| 67 | |
|
| 68 | |
private MockExternalContext externalContext; |
| 69 | |
|
| 70 | |
private MockApplication application; |
| 71 | |
|
| 72 | |
private MockFacesContext facesContext; |
| 73 | |
|
| 74 | |
private MockLifecycle lifecycle; |
| 75 | |
|
| 76 | |
private MockRenderKit renderKit; |
| 77 | |
|
| 78 | |
private MockPhaseListener phaseListener; |
| 79 | |
|
| 80 | |
private MockNavigationHandler navigationHandler; |
| 81 | |
|
| 82 | |
private MockPropertyResolver propertyResolver; |
| 83 | |
|
| 84 | |
private MockVariableResolver variableResolver; |
| 85 | |
|
| 86 | |
private MockViewHandler viewHandler; |
| 87 | |
|
| 88 | |
private MockStateManager stateManager; |
| 89 | |
|
| 90 | 1271 | public TeedaTestCase() { |
| 91 | 1271 | setWarmDeploy(false); |
| 92 | 1271 | } |
| 93 | |
|
| 94 | |
public TeedaTestCase(String name) { |
| 95 | 68 | super(name); |
| 96 | 68 | setWarmDeploy(false); |
| 97 | 68 | } |
| 98 | |
|
| 99 | |
protected void setUpContainer() throws Throwable { |
| 100 | 1339 | super.setUpContainer(); |
| 101 | 1339 | externalContext = new MockExternalContextImpl(getServletContext(), |
| 102 | |
getRequest(), getResponse()); |
| 103 | 1339 | application = new MockApplicationImpl(); |
| 104 | 1339 | navigationHandler = new MockNavigationHandler(); |
| 105 | 1339 | application.setNavigationHandler(navigationHandler); |
| 106 | 1339 | propertyResolver = new MockPropertyResolver(); |
| 107 | 1339 | application.setPropertyResolver(propertyResolver); |
| 108 | 1339 | variableResolver = new MockVariableResolver(); |
| 109 | 1339 | application.setVariableResolver(variableResolver); |
| 110 | 1339 | viewHandler = new MockViewHandlerImpl(); |
| 111 | 1339 | application.setViewHandler(viewHandler); |
| 112 | 1339 | stateManager = new MockStateManager(); |
| 113 | 1339 | application.setStateManager(stateManager); |
| 114 | |
|
| 115 | 1339 | facesContext = new MockFacesContextImpl(externalContext, application); |
| 116 | 1339 | UIViewRoot viewRoot = new UIViewRoot(); |
| 117 | 1339 | viewRoot.setRenderKitId(RenderKitFactory.HTML_BASIC_RENDER_KIT); |
| 118 | 1339 | viewRoot.setLocale(Locale.getDefault()); |
| 119 | 1339 | facesContext.setViewRoot(viewRoot); |
| 120 | 1339 | renderKit = new MockRenderKitImpl(); |
| 121 | |
|
| 122 | |
|
| 123 | 1339 | MockRenderer renderer = new MockRenderer(); |
| 124 | 1339 | renderKit.addRenderer(MockUIComponent.COMPONENT_FAMILY, |
| 125 | |
MockUIComponent.COMPONENT_TYPE, renderer); |
| 126 | |
|
| 127 | 1339 | lifecycle = new MockLifecycleImpl(); |
| 128 | 1339 | phaseListener = new MockPhaseListener(); |
| 129 | 1339 | lifecycle.addPhaseListener(phaseListener); |
| 130 | 1339 | initFactories(); |
| 131 | 1339 | setFactories(); |
| 132 | 1339 | ValidatorResource.setValidatorBuilder(new NormalValidatorBuilderImpl( |
| 133 | |
getContainer())); |
| 134 | 1339 | ConverterResource.setConverterBuilder(new NormalConverterBuilderImpl( |
| 135 | |
getContainer())); |
| 136 | 1339 | } |
| 137 | |
|
| 138 | |
protected void initFactories() { |
| 139 | 1339 | FactoryFinder.setFactory(FactoryFinder.APPLICATION_FACTORY, |
| 140 | |
"org.seasar.teeda.core.mock.MockApplicationFactory"); |
| 141 | |
|
| 142 | 1339 | FactoryFinder.setFactory(FactoryFinder.FACES_CONTEXT_FACTORY, |
| 143 | |
"org.seasar.teeda.core.mock.MockFacesContextFactory"); |
| 144 | |
|
| 145 | 1339 | FactoryFinder.setFactory(FactoryFinder.LIFECYCLE_FACTORY, |
| 146 | |
"org.seasar.teeda.core.mock.MockLifecycleFactory"); |
| 147 | |
|
| 148 | 1339 | FactoryFinder.setFactory(FactoryFinder.RENDER_KIT_FACTORY, |
| 149 | |
"org.seasar.teeda.core.mock.MockRenderKitFactory"); |
| 150 | 1339 | } |
| 151 | |
|
| 152 | |
protected void setFactories() { |
| 153 | 1339 | setApplicationFactory(); |
| 154 | 1339 | setFacesContextFactory(); |
| 155 | 1339 | setLifecycleFactory(); |
| 156 | 1339 | setRenderKitFactory(); |
| 157 | 1339 | setManagedBeanFactory(); |
| 158 | 1339 | } |
| 159 | |
|
| 160 | |
protected void setApplicationFactory() { |
| 161 | 1407 | MockApplicationFactory appFactory = (MockApplicationFactory) FactoryFinder |
| 162 | |
.getFactory(FactoryFinder.APPLICATION_FACTORY); |
| 163 | 1407 | appFactory.setApplication(application); |
| 164 | 1407 | } |
| 165 | |
|
| 166 | |
protected void setFacesContextFactory() { |
| 167 | 1344 | MockFacesContextFactory facesContextFactory = (MockFacesContextFactory) FactoryFinder |
| 168 | |
.getFactory(FactoryFinder.FACES_CONTEXT_FACTORY); |
| 169 | 1344 | facesContextFactory.setFacesContext(facesContext); |
| 170 | 1344 | } |
| 171 | |
|
| 172 | |
protected void setLifecycleFactory() { |
| 173 | 1339 | MockLifecycleFactory lifecycleFactory = (MockLifecycleFactory) FactoryFinder |
| 174 | |
.getFactory(FactoryFinder.LIFECYCLE_FACTORY); |
| 175 | 1339 | lifecycleFactory.addLifecycle(LifecycleFactory.DEFAULT_LIFECYCLE, |
| 176 | |
lifecycle); |
| 177 | 1339 | } |
| 178 | |
|
| 179 | |
protected void setRenderKitFactory() { |
| 180 | 1340 | MockRenderKitFactory renderKitFactory = (MockRenderKitFactory) FactoryFinder |
| 181 | |
.getFactory(FactoryFinder.RENDER_KIT_FACTORY); |
| 182 | 1340 | renderKitFactory.addRenderKit(RenderKitFactory.HTML_BASIC_RENDER_KIT, |
| 183 | |
renderKit); |
| 184 | 1340 | } |
| 185 | |
|
| 186 | |
protected void setManagedBeanFactory() { |
| 187 | 1344 | getContainer().register(ManagedBeanFactoryImpl.class); |
| 188 | 1339 | getContainer().register(ManagedBeanScopeSaverImpl.class); |
| 189 | 1339 | getContainer().register(ScopeManagerImpl.class); |
| 190 | 1339 | getContainer().register(S2ScopeTranslator.class); |
| 191 | 1339 | } |
| 192 | |
|
| 193 | |
protected ManagedBeanFactory getManagedBeanFactory() { |
| 194 | 11 | return (ManagedBeanFactory) getContainer().getComponent( |
| 195 | |
ManagedBeanFactory.class); |
| 196 | |
} |
| 197 | |
|
| 198 | |
protected String getResponseText() { |
| 199 | 6 | return getResponse().getResponseString(); |
| 200 | |
} |
| 201 | |
|
| 202 | |
protected void tearDownContainer() throws Throwable { |
| 203 | 1339 | externalContext = null; |
| 204 | 1339 | application = null; |
| 205 | 1339 | if (facesContext != null) { |
| 206 | 1339 | facesContext.release(); |
| 207 | |
} |
| 208 | 1339 | facesContext = null; |
| 209 | 1339 | renderKit = null; |
| 210 | 1339 | phaseListener = null; |
| 211 | 1339 | navigationHandler = null; |
| 212 | 1339 | FactoryFinder.releaseFactories(); |
| 213 | 1339 | NavigationResource.removeAll(); |
| 214 | 1339 | ValidatorResource.removeAll(); |
| 215 | 1339 | ConverterResource.removeAll(); |
| 216 | 1339 | FacesConfigOptions.clear(); |
| 217 | 1339 | super.tearDownContainer(); |
| 218 | 1339 | } |
| 219 | |
|
| 220 | |
|
| 221 | |
|
| 222 | |
|
| 223 | |
protected static void success() { |
| 224 | 83 | assertTrue(true); |
| 225 | 83 | } |
| 226 | |
|
| 227 | |
protected static void notDoneYet() { |
| 228 | 0 | fail("This test is not done yet."); |
| 229 | 0 | } |
| 230 | |
|
| 231 | |
public MockApplication getApplication() { |
| 232 | 193 | return application; |
| 233 | |
} |
| 234 | |
|
| 235 | |
public void setApplication(MockApplication application) { |
| 236 | 68 | this.application = application; |
| 237 | 68 | setApplicationFactory(); |
| 238 | 68 | facesContext.setApplication(this.application); |
| 239 | 68 | } |
| 240 | |
|
| 241 | |
public MockExternalContext getExternalContext() { |
| 242 | 104 | return externalContext; |
| 243 | |
} |
| 244 | |
|
| 245 | |
public void setExternalContext(MockExternalContext externalContext) { |
| 246 | 0 | this.externalContext = externalContext; |
| 247 | 0 | } |
| 248 | |
|
| 249 | |
public MockFacesContext getFacesContext() { |
| 250 | 959 | return facesContext; |
| 251 | |
} |
| 252 | |
|
| 253 | |
public void setFacesContext(MockFacesContext facesContext) { |
| 254 | 5 | this.facesContext = facesContext; |
| 255 | 5 | setFacesContextFactory(); |
| 256 | 5 | } |
| 257 | |
|
| 258 | |
public MockLifecycle getLifecycle() { |
| 259 | 30 | return lifecycle; |
| 260 | |
} |
| 261 | |
|
| 262 | |
public void setLifecycle(MockLifecycle lifecycle) { |
| 263 | 0 | this.lifecycle = lifecycle; |
| 264 | 0 | setLifecycleFactory(); |
| 265 | 0 | } |
| 266 | |
|
| 267 | |
public MockRenderKit getRenderKit() { |
| 268 | 6 | return renderKit; |
| 269 | |
} |
| 270 | |
|
| 271 | |
public void setRenderKit(MockRenderKit renderKit) { |
| 272 | 1 | this.renderKit = renderKit; |
| 273 | 1 | setRenderKitFactory(); |
| 274 | 1 | } |
| 275 | |
|
| 276 | |
public MockPropertyResolver getPropertyResolver() { |
| 277 | 2 | return propertyResolver; |
| 278 | |
} |
| 279 | |
|
| 280 | |
public void setPropertyResolver(MockPropertyResolver propertyResolver) { |
| 281 | 3 | this.propertyResolver = propertyResolver; |
| 282 | 3 | application.setPropertyResolver(propertyResolver); |
| 283 | 3 | } |
| 284 | |
|
| 285 | |
public MockVariableResolver getVariableResolver() { |
| 286 | 45 | return variableResolver; |
| 287 | |
} |
| 288 | |
|
| 289 | |
public void setVariableResolver(MockVariableResolver variableResolver) { |
| 290 | 0 | this.variableResolver = variableResolver; |
| 291 | 0 | application.setVariableResolver(variableResolver); |
| 292 | 0 | } |
| 293 | |
|
| 294 | |
public MockViewHandler getViewHandler() { |
| 295 | 2 | return viewHandler; |
| 296 | |
} |
| 297 | |
|
| 298 | |
public void setViewHandler(MockViewHandler viewHandler) { |
| 299 | 1 | this.viewHandler = viewHandler; |
| 300 | 1 | application.setViewHandler(viewHandler); |
| 301 | 1 | } |
| 302 | |
|
| 303 | |
|
| 304 | |
|
| 305 | |
|
| 306 | |
public MockStateManager getStateManager() { |
| 307 | 0 | return stateManager; |
| 308 | |
} |
| 309 | |
|
| 310 | |
|
| 311 | |
|
| 312 | |
|
| 313 | |
public void setStateManager(MockStateManager stateManager) { |
| 314 | 0 | this.stateManager = stateManager; |
| 315 | 0 | } |
| 316 | |
|
| 317 | |
} |