PageRenderTime 49ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/projects/myfaces_core-2.1.10/src/myfaces-core-module-2.1.10/impl/src/test/java/org/apache/myfaces/view/facelets/tag/composite/CompositeComponentClientBehaviorTestCase.java

https://gitlab.com/essere.lab.public/qualitas.class-corpus
Java | 274 lines | 154 code | 50 blank | 70 comment | 0 complexity | 495017cb056a5450570b4af0a1d27b03 MD5 | raw file
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing,
  13. * software distributed under the License is distributed on an
  14. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15. * KIND, either express or implied. See the License for the
  16. * specific language governing permissions and limitations
  17. * under the License.
  18. */
  19. package org.apache.myfaces.view.facelets.tag.composite;
  20. import javax.faces.component.UICommand;
  21. import javax.faces.component.UIComponent;
  22. import javax.faces.component.UINamingContainer;
  23. import javax.faces.component.UIViewRoot;
  24. import org.apache.myfaces.view.facelets.FaceletTestCase;
  25. import org.apache.myfaces.view.facelets.bean.HelloWorld;
  26. import org.junit.Assert;
  27. import org.junit.Test;
  28. public class CompositeComponentClientBehaviorTestCase extends FaceletTestCase
  29. {
  30. @Test
  31. public void testSimpleClientBehavior() throws Exception
  32. {
  33. HelloWorld helloWorld = new HelloWorld();
  34. facesContext.getExternalContext().getRequestMap().put("helloWorldBean",
  35. helloWorld);
  36. UIViewRoot root = facesContext.getViewRoot();
  37. vdl.buildView(facesContext, root, "testSimpleClientBehavior.xhtml");
  38. UIComponent form = root.findComponent("testForm1");
  39. Assert.assertNotNull(form);
  40. UINamingContainer compositeComponent = (UINamingContainer) form.getChildren().get(0);
  41. Assert.assertNotNull(compositeComponent);
  42. UICommand button = (UICommand) compositeComponent.findComponent("button");
  43. Assert.assertNotNull(button);
  44. Assert.assertNotNull(button.getClientBehaviors().get("action"));
  45. Assert.assertEquals(1, button.getClientBehaviors().get("action").size());
  46. //StringWriter sw = new StringWriter();
  47. //MockResponseWriter mrw = new MockResponseWriter(sw);
  48. //facesContext.setResponseWriter(mrw);
  49. //root.encodeAll(facesContext);
  50. //sw.flush();
  51. //System.out.print(sw.toString());
  52. }
  53. @Test
  54. public void testSimpleClientBehaviorDefault() throws Exception
  55. {
  56. HelloWorld helloWorld = new HelloWorld();
  57. facesContext.getExternalContext().getRequestMap().put("helloWorldBean",
  58. helloWorld);
  59. UIViewRoot root = facesContext.getViewRoot();
  60. vdl.buildView(facesContext, root, "testSimpleClientBehaviorDefault.xhtml");
  61. UIComponent form = root.findComponent("testForm1");
  62. Assert.assertNotNull(form);
  63. UINamingContainer compositeComponent = (UINamingContainer) form.getChildren().get(0);
  64. Assert.assertNotNull(compositeComponent);
  65. UICommand button = (UICommand) compositeComponent.findComponent("button");
  66. Assert.assertNotNull(button);
  67. Assert.assertNotNull(button.getClientBehaviors().get("dblclick"));
  68. Assert.assertEquals(1, button.getClientBehaviors().get("dblclick").size());
  69. //StringWriter sw = new StringWriter();
  70. //MockResponseWriter mrw = new MockResponseWriter(sw);
  71. //facesContext.setResponseWriter(mrw);
  72. //root.encodeAll(facesContext);
  73. //sw.flush();
  74. //System.out.print(sw.toString());
  75. }
  76. @Test
  77. public void testSimpleClientBehaviorDefaultNoEvent() throws Exception
  78. {
  79. HelloWorld helloWorld = new HelloWorld();
  80. facesContext.getExternalContext().getRequestMap().put("helloWorldBean",
  81. helloWorld);
  82. UIViewRoot root = facesContext.getViewRoot();
  83. vdl.buildView(facesContext, root, "testSimpleClientBehaviorDefaultNoEvent.xhtml");
  84. UIComponent form = root.findComponent("testForm1");
  85. Assert.assertNotNull(form);
  86. UINamingContainer compositeComponent = (UINamingContainer) form.getChildren().get(0);
  87. Assert.assertNotNull(compositeComponent);
  88. UICommand button = (UICommand) compositeComponent.findComponent("button");
  89. Assert.assertNotNull(button);
  90. Assert.assertNotNull(button.getClientBehaviors().get("action"));
  91. Assert.assertEquals(1, button.getClientBehaviors().get("action").size());
  92. //StringWriter sw = new StringWriter();
  93. //MockResponseWriter mrw = new MockResponseWriter(sw);
  94. //facesContext.setResponseWriter(mrw);
  95. //root.encodeAll(facesContext);
  96. //sw.flush();
  97. //System.out.print(sw.toString());
  98. }
  99. @Test
  100. public void testSimpleClientBehaviorAjaxWrap() throws Exception
  101. {
  102. HelloWorld helloWorld = new HelloWorld();
  103. facesContext.getExternalContext().getRequestMap().put("helloWorldBean",
  104. helloWorld);
  105. UIViewRoot root = facesContext.getViewRoot();
  106. vdl.buildView(facesContext, root, "testSimpleClientBehaviorAjaxWrap.xhtml");
  107. UIComponent form = root.findComponent("testForm1");
  108. Assert.assertNotNull(form);
  109. UINamingContainer compositeComponent = (UINamingContainer) form.getChildren().get(0);
  110. Assert.assertNotNull(compositeComponent);
  111. UICommand button = (UICommand) compositeComponent.findComponent("button");
  112. Assert.assertNotNull(button);
  113. Assert.assertNotNull(button.getClientBehaviors().get("action"));
  114. Assert.assertEquals(1, button.getClientBehaviors().get("action").size());
  115. //StringWriter sw = new StringWriter();
  116. //MockResponseWriter mrw = new MockResponseWriter(sw);
  117. //facesContext.setResponseWriter(mrw);
  118. //root.encodeAll(facesContext);
  119. //sw.flush();
  120. //System.out.print(sw.toString());
  121. }
  122. @Test
  123. public void testSimpleClientBehaviorDefaultAjaxWrap() throws Exception
  124. {
  125. HelloWorld helloWorld = new HelloWorld();
  126. facesContext.getExternalContext().getRequestMap().put("helloWorldBean",
  127. helloWorld);
  128. UIViewRoot root = facesContext.getViewRoot();
  129. vdl.buildView(facesContext, root, "testSimpleClientBehaviorDefaultAjaxWrap.xhtml");
  130. UIComponent form = root.findComponent("testForm1");
  131. Assert.assertNotNull(form);
  132. UINamingContainer compositeComponent = (UINamingContainer) form.getChildren().get(0);
  133. Assert.assertNotNull(compositeComponent);
  134. UICommand button = (UICommand) compositeComponent.findComponent("button");
  135. Assert.assertNotNull(button);
  136. Assert.assertNotNull(button.getClientBehaviors().get("dblclick"));
  137. Assert.assertEquals(1, button.getClientBehaviors().get("dblclick").size());
  138. //StringWriter sw = new StringWriter();
  139. //MockResponseWriter mrw = new MockResponseWriter(sw);
  140. //facesContext.setResponseWriter(mrw);
  141. //root.encodeAll(facesContext);
  142. //sw.flush();
  143. //System.out.print(sw.toString());
  144. }
  145. @Test
  146. public void testSimpleClientBehaviorDefaultNoEventAjaxWrap() throws Exception
  147. {
  148. HelloWorld helloWorld = new HelloWorld();
  149. facesContext.getExternalContext().getRequestMap().put("helloWorldBean",
  150. helloWorld);
  151. UIViewRoot root = facesContext.getViewRoot();
  152. vdl.buildView(facesContext, root, "testSimpleClientBehaviorDefaultNoEventAjaxWrap.xhtml");
  153. UIComponent form = root.findComponent("testForm1");
  154. Assert.assertNotNull(form);
  155. UINamingContainer compositeComponent = (UINamingContainer) form.getChildren().get(0);
  156. Assert.assertNotNull(compositeComponent);
  157. UICommand button = (UICommand) compositeComponent.findComponent("button");
  158. Assert.assertNotNull(button);
  159. Assert.assertNotNull(button.getClientBehaviors().get("action"));
  160. Assert.assertEquals(1, button.getClientBehaviors().get("action").size());
  161. //StringWriter sw = new StringWriter();
  162. //MockResponseWriter mrw = new MockResponseWriter(sw);
  163. //facesContext.setResponseWriter(mrw);
  164. //root.encodeAll(facesContext);
  165. //sw.flush();
  166. //System.out.print(sw.toString());
  167. }
  168. @Test
  169. public void testCompositeClientBehavior() throws Exception
  170. {
  171. HelloWorld helloWorld = new HelloWorld();
  172. facesContext.getExternalContext().getRequestMap().put("helloWorldBean",
  173. helloWorld);
  174. UIViewRoot root = facesContext.getViewRoot();
  175. vdl.buildView(facesContext, root, "testCompositeClientBehavior.xhtml");
  176. UIComponent form = root.findComponent("testForm1");
  177. Assert.assertNotNull(form);
  178. UINamingContainer compositeComponent = (UINamingContainer) form.getChildren().get(0);
  179. Assert.assertNotNull(compositeComponent);
  180. UINamingContainer compositeComponent2 = (UINamingContainer) compositeComponent.findComponent("button3");
  181. Assert.assertNotNull(compositeComponent2);
  182. UICommand button = (UICommand) compositeComponent2.findComponent("button");
  183. Assert.assertNotNull(button);
  184. //One added in testCompositeActionSource, the other one
  185. //inside compositeActionSource.xhtml
  186. Assert.assertNotNull(button.getClientBehaviors().get("action"));
  187. Assert.assertEquals(1, button.getClientBehaviors().get("action").size());
  188. //StringWriter sw = new StringWriter();
  189. //MockResponseWriter mrw = new MockResponseWriter(sw);
  190. //facesContext.setResponseWriter(mrw);
  191. //root.encodeAll(facesContext);
  192. //sw.flush();
  193. //System.out.print(sw.toString());
  194. }
  195. @Test
  196. public void testCompositeDoubleClientBehavior() throws Exception
  197. {
  198. HelloWorld helloWorld = new HelloWorld();
  199. facesContext.getExternalContext().getRequestMap().put("helloWorldBean",
  200. helloWorld);
  201. UIViewRoot root = facesContext.getViewRoot();
  202. vdl.buildView(facesContext, root, "testCompositeDoubleClientBehavior.xhtml");
  203. UIComponent form = root.findComponent("testForm1");
  204. Assert.assertNotNull(form);
  205. UINamingContainer compositeComponent = (UINamingContainer) form.getChildren().get(0);
  206. Assert.assertNotNull(compositeComponent);
  207. UINamingContainer compositeComponent2 = (UINamingContainer) compositeComponent.findComponent("compositeClientBehavior");
  208. Assert.assertNotNull(compositeComponent2);
  209. UINamingContainer compositeComponent3 = (UINamingContainer) compositeComponent2.findComponent("button3");
  210. Assert.assertNotNull(compositeComponent3);
  211. UICommand button = (UICommand) compositeComponent3.findComponent("button");
  212. Assert.assertNotNull(button);
  213. //One added in testCompositeActionSource, the other one
  214. //inside compositeActionSource.xhtml
  215. Assert.assertNotNull(button.getClientBehaviors().get("action"));
  216. Assert.assertEquals(1, button.getClientBehaviors().get("action").size());
  217. //StringWriter sw = new StringWriter();
  218. //MockResponseWriter mrw = new MockResponseWriter(sw);
  219. //facesContext.setResponseWriter(mrw);
  220. //root.encodeAll(facesContext);
  221. //sw.flush();
  222. //System.out.print(sw.toString());
  223. }
  224. }