PageRenderTime 55ms 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/CompositeComponentAttributeTestCase.java

https://gitlab.com/essere.lab.public/qualitas.class-corpus
Java | 601 lines | 390 code | 105 blank | 106 comment | 1 complexity | d11372409458bf7959fef0f25911faf5 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 java.beans.BeanDescriptor;
  21. import java.beans.FeatureDescriptor;
  22. import java.beans.PropertyDescriptor;
  23. import java.io.StringWriter;
  24. import java.util.Map;
  25. import javax.el.MethodExpression;
  26. import javax.el.ValueExpression;
  27. import javax.faces.application.ProjectStage;
  28. import javax.faces.component.UICommand;
  29. import javax.faces.component.UIComponent;
  30. import javax.faces.component.UIForm;
  31. import javax.faces.component.UIInput;
  32. import javax.faces.component.UINamingContainer;
  33. import javax.faces.component.UIViewRoot;
  34. import javax.faces.component.html.HtmlCommandButton;
  35. import javax.faces.component.html.HtmlOutputText;
  36. import javax.faces.event.ActionEvent;
  37. import javax.faces.event.ValueChangeEvent;
  38. import org.apache.myfaces.test.mock.MockResponseWriter;
  39. import org.apache.myfaces.test.utils.HtmlCheckAttributesUtil;
  40. import org.apache.myfaces.test.utils.HtmlRenderedAttr;
  41. import org.apache.myfaces.view.facelets.FaceletTestCase;
  42. import org.apache.myfaces.view.facelets.bean.DummyBean;
  43. import org.apache.myfaces.view.facelets.bean.HelloWorld;
  44. import org.junit.Assert;
  45. import org.junit.Test;
  46. public class CompositeComponentAttributeTestCase extends FaceletTestCase
  47. {
  48. @Override
  49. protected void setupComponents() throws Exception
  50. {
  51. super.setupComponents();
  52. application.addComponent(CompositeTestComponent.class.getName(),
  53. CompositeTestComponent.class.getName());
  54. }
  55. /**
  56. * Test simple attribute resolution (not set, default, normal use case).
  57. *
  58. * @throws Exception
  59. */
  60. @Test
  61. public void testSimpleCompositeAttribute() throws Exception
  62. {
  63. MockAttributeBean bean = new MockAttributeBean();
  64. facesContext.getExternalContext().getRequestMap().put("bean",
  65. bean);
  66. UIViewRoot root = facesContext.getViewRoot();
  67. vdl.buildView(facesContext, root, "testSimpleAttributeVE.xhtml");
  68. UIComponent panelGroup1 = root.findComponent("testGroup1");
  69. Assert.assertNotNull(panelGroup1);
  70. CompositeTestComponent compositeComponent1 = (CompositeTestComponent) panelGroup1.getChildren().get(0);
  71. Assert.assertNotNull(compositeComponent1);
  72. UIComponent facet1 = compositeComponent1.getFacet(UIComponent.COMPOSITE_FACET_NAME);
  73. Assert.assertNotNull(facet1);
  74. HtmlOutputText text1 = (HtmlOutputText) facet1.findComponent("text");
  75. Assert.assertNotNull(text1);
  76. HtmlCommandButton button1 = (HtmlCommandButton) facet1.findComponent("button");
  77. Assert.assertNotNull(button1);
  78. compositeComponent1.pushComponentToEL(facesContext, compositeComponent1);
  79. facet1.pushComponentToEL(facesContext, facet1);
  80. text1.pushComponentToEL(facesContext, text1);
  81. //set on tag
  82. Assert.assertEquals(bean.getStyleClass(), text1.getStyleClass());
  83. //set as default
  84. Assert.assertEquals(bean.getStyle(), text1.getStyle());
  85. Assert.assertEquals(bean.getJavaProperty(), text1.getValue());
  86. text1.popComponentFromEL(facesContext);
  87. button1.pushComponentToEL(facesContext, button1);
  88. MethodExpression method = button1.getActionExpression();
  89. Assert.assertEquals(bean.doSomethingFunny("xysj"), method.invoke(facesContext.getELContext(), new Object[]{"xysj"}));
  90. button1.popComponentFromEL(facesContext);
  91. facet1.popComponentFromEL(facesContext);
  92. compositeComponent1.popComponentFromEL(facesContext);
  93. StringWriter sw = new StringWriter();
  94. MockResponseWriter mrw = new MockResponseWriter(sw);
  95. facesContext.setResponseWriter(mrw);
  96. compositeComponent1.encodeAll(facesContext);
  97. sw.flush();
  98. HtmlRenderedAttr[] attrs = new HtmlRenderedAttr[]{
  99. new HtmlRenderedAttr("style")
  100. };
  101. HtmlCheckAttributesUtil.checkRenderedAttributes(attrs, sw.toString());
  102. }
  103. /**
  104. * Test simple attribute resolution (not set, default, normal use case).
  105. *
  106. * @throws Exception
  107. */
  108. @Test
  109. public void testSimpleCompositeAttributeInsertChildren() throws Exception
  110. {
  111. MockAttributeBean bean = new MockAttributeBean();
  112. facesContext.getExternalContext().getRequestMap().put("bean",
  113. bean);
  114. UIViewRoot root = facesContext.getViewRoot();
  115. vdl.buildView(facesContext, root, "testSimpleAttributeVEInsertChildren.xhtml");
  116. UIComponent panelGroup1 = root.findComponent("testGroup1");
  117. Assert.assertNotNull(panelGroup1);
  118. CompositeTestComponent compositeComponent1 = (CompositeTestComponent) panelGroup1.getChildren().get(0);
  119. Assert.assertNotNull(compositeComponent1);
  120. UIComponent facet1 = compositeComponent1.getFacet(UIComponent.COMPOSITE_FACET_NAME);
  121. Assert.assertNotNull(facet1);
  122. UIComponent compositeComponent2 = facet1.getChildren().get(0);
  123. Assert.assertNotNull(compositeComponent2);
  124. UIComponent facet2 = compositeComponent2.getFacet(UIComponent.COMPOSITE_FACET_NAME);
  125. Assert.assertNotNull(facet2);
  126. HtmlOutputText text1 = (HtmlOutputText) facet2.findComponent("text");
  127. Assert.assertNotNull(text1);
  128. HtmlCommandButton button1 = (HtmlCommandButton) facet2.findComponent("button");
  129. Assert.assertNotNull(button1);
  130. compositeComponent1.pushComponentToEL(facesContext, compositeComponent1);
  131. facet1.pushComponentToEL(facesContext, facet1);
  132. text1.pushComponentToEL(facesContext, text1);
  133. //set on tag
  134. Assert.assertEquals(bean.getStyleClass(), text1.getStyleClass());
  135. //set as default
  136. Assert.assertEquals(bean.getStyle(), text1.getStyle());
  137. Assert.assertEquals(bean.getJavaProperty(), text1.getValue());
  138. text1.popComponentFromEL(facesContext);
  139. button1.pushComponentToEL(facesContext, button1);
  140. MethodExpression method = button1.getActionExpression();
  141. Assert.assertEquals(bean.doSomethingFunny("xysj"), method.invoke(facesContext.getELContext(), new Object[]{"xysj"}));
  142. button1.popComponentFromEL(facesContext);
  143. facet1.popComponentFromEL(facesContext);
  144. compositeComponent1.popComponentFromEL(facesContext);
  145. StringWriter sw = new StringWriter();
  146. MockResponseWriter mrw = new MockResponseWriter(sw);
  147. facesContext.setResponseWriter(mrw);
  148. compositeComponent1.encodeAll(facesContext);
  149. sw.flush();
  150. HtmlRenderedAttr[] attrs = new HtmlRenderedAttr[]{
  151. new HtmlRenderedAttr("style")
  152. };
  153. HtmlCheckAttributesUtil.checkRenderedAttributes(attrs, sw.toString());
  154. }
  155. @Test
  156. public void testSimpleMethodInvocation() throws Exception
  157. {
  158. DummyBean dummyBean = new DummyBean();
  159. facesContext.getExternalContext().getRequestMap().put("dummyBean",
  160. dummyBean);
  161. UIViewRoot root = facesContext.getViewRoot();
  162. vdl.buildView(facesContext, root, "testSimpleMethodInvocation.xhtml");
  163. UIComponent panelGroup1 = root.findComponent("testGroup1");
  164. Assert.assertNotNull(panelGroup1);
  165. UINamingContainer compositeComponent1 = (UINamingContainer) panelGroup1.getChildren().get(0);
  166. Assert.assertNotNull(compositeComponent1);
  167. UIComponent facet1 = compositeComponent1.getFacet(UIComponent.COMPOSITE_FACET_NAME);
  168. Assert.assertNotNull(facet1);
  169. UINamingContainer compositeComponent2 = (UINamingContainer) facet1.getChildren().get(0);
  170. Assert.assertNotNull(compositeComponent2);
  171. UIComponent facet2 = compositeComponent2.getFacet(UIComponent.COMPOSITE_FACET_NAME);
  172. Assert.assertNotNull(facet2);
  173. UIForm form = (UIForm) facet2.findComponent("mainForm");
  174. Assert.assertNotNull(form);
  175. UICommand button1 = (UICommand) form.findComponent("button1");
  176. Assert.assertNotNull(button1);
  177. UICommand button2 = (UICommand) form.findComponent("button2");
  178. Assert.assertNotNull(button2);
  179. UICommand button3 = (UICommand) form.findComponent("button3");
  180. Assert.assertNotNull(button3);
  181. UIInput text1 = (UIInput) form.findComponent("text1");
  182. Assert.assertNotNull(text1);
  183. UIInput text2 = (UIInput) form.findComponent("text2");
  184. Assert.assertNotNull(text2);
  185. compositeComponent1.pushComponentToEL(facesContext, compositeComponent1);
  186. facet1.pushComponentToEL(facesContext, facet1);
  187. compositeComponent2.pushComponentToEL(facesContext, compositeComponent2);
  188. facet2.pushComponentToEL(facesContext, facet2);
  189. form.pushComponentToEL(facesContext, form);
  190. button1.pushComponentToEL(facesContext, button1);
  191. button1.getActionExpression().invoke(facesContext.getELContext(), new Object[]{});
  192. button1.popComponentFromEL(facesContext);
  193. button2.pushComponentToEL(facesContext, button2);
  194. button2.getActionListeners()[0].processAction(new ActionEvent(button2));
  195. button2.popComponentFromEL(facesContext);
  196. button3.pushComponentToEL(facesContext, button3);
  197. button3.getActionExpression().invoke(facesContext.getELContext(), new Object[]{});
  198. button3.popComponentFromEL(facesContext);
  199. text1.pushComponentToEL(facesContext, text1);
  200. text1.getValidators()[0].validate(facesContext, text1, "");
  201. text1.popComponentFromEL(facesContext);
  202. text2.pushComponentToEL(facesContext, text2);
  203. text2.getValueChangeListeners()[0].processValueChange(new ValueChangeEvent(text2, "old", "new"));
  204. text2.popComponentFromEL(facesContext);
  205. form.popComponentFromEL(facesContext);
  206. facet2.popComponentFromEL(facesContext);
  207. compositeComponent2.popComponentFromEL(facesContext);
  208. facet1.popComponentFromEL(facesContext);
  209. compositeComponent1.popComponentFromEL(facesContext);
  210. StringWriter sw = new StringWriter();
  211. MockResponseWriter mrw = new MockResponseWriter(sw);
  212. facesContext.setResponseWriter(mrw);
  213. compositeComponent1.encodeAll(facesContext);
  214. sw.flush();
  215. String resp = sw.toString();
  216. }
  217. @Test
  218. public void testCompositeActionMethodInvocation() throws Exception
  219. {
  220. HelloWorld helloWorld = new HelloWorld();
  221. facesContext.getExternalContext().getRequestMap().put("helloWorldBean",
  222. helloWorld);
  223. UIViewRoot root = facesContext.getViewRoot();
  224. vdl.buildView(facesContext, root, "testCompositeActionMethodInvocation.xhtml");
  225. UIComponent form = root.findComponent("testForm1");
  226. Assert.assertNotNull(form);
  227. UINamingContainer compositeComponent = (UINamingContainer) form.getChildren().get(0);
  228. Assert.assertNotNull(compositeComponent);
  229. UINamingContainer compositeComponent2 = (UINamingContainer) compositeComponent.findComponent("button1");
  230. Assert.assertNotNull(compositeComponent2);
  231. UICommand button = (UICommand) compositeComponent2.findComponent("button2");
  232. Assert.assertNotNull(button);
  233. Assert.assertNotNull(button.getActionExpression());
  234. Assert.assertEquals("success", button.getActionExpression().invoke(facesContext.getELContext(), null));
  235. Assert.assertEquals(1, button.getActionListeners().length);
  236. //StringWriter sw = new StringWriter();
  237. //MockResponseWriter mrw = new MockResponseWriter(sw);
  238. //facesContext.setResponseWriter(mrw);
  239. //root.encodeAll(facesContext);
  240. //sw.flush();
  241. //System.out.print(sw.toString());
  242. }
  243. /**
  244. * Tests if unspecified attributes on <composite:interface>, <composite:attribute>
  245. * and <composite:facet> are handled correctly.
  246. * @throws Exception
  247. */
  248. @Test
  249. @SuppressWarnings("unchecked")
  250. public void testUnspecifiedAttributes() throws Exception
  251. {
  252. UIViewRoot root = facesContext.getViewRoot();
  253. vdl.buildView(facesContext, root, "testInterfaceDescriptorAttributes.xhtml");
  254. // get the composite component and its BeanInfo
  255. UIComponent composite = root.findComponent("panel").getChildren().get(0);
  256. CompositeComponentBeanInfo beanInfo =
  257. (CompositeComponentBeanInfo) composite.getAttributes()
  258. .get(UIComponent.BEANINFO_KEY);
  259. Assert.assertNotNull(beanInfo);
  260. // get the <composite:interface> descriptor and check the unspecified attribute
  261. BeanDescriptor interfaceDescriptor = beanInfo.getBeanDescriptor();
  262. _checkUnspecifiedAttribute(interfaceDescriptor,
  263. "unspecifiedInterfaceAttribute", "unspecifiedInterfaceValue");
  264. // check <composite:attribute>
  265. Assert.assertEquals("Expecting one <composite:attribute>",
  266. 1, beanInfo.getPropertyDescriptors().length);
  267. PropertyDescriptor attributeDescriptor = beanInfo.getPropertyDescriptors()[0];
  268. _checkUnspecifiedAttribute(attributeDescriptor,
  269. "unspecifiedAttributeAttribute", "unspecifiedAttributeValue");
  270. // check <composite:facet>
  271. Map<String, PropertyDescriptor> facetPropertyDescriptorMap =
  272. (Map<String, PropertyDescriptor>) interfaceDescriptor.getValue(UIComponent.FACETS_KEY);
  273. Assert.assertNotNull(facetPropertyDescriptorMap);
  274. PropertyDescriptor facetDescriptor = facetPropertyDescriptorMap.get("facet");
  275. _checkUnspecifiedAttribute(facetDescriptor,
  276. "unspecifiedFacetAttribute", "unspecifiedFacetValue");
  277. }
  278. /**
  279. * Assertions for testUnspecifiedAttributes()
  280. * @param descriptor
  281. * @param attributeName
  282. * @param attributeValue
  283. */
  284. private void _checkUnspecifiedAttribute(FeatureDescriptor descriptor,
  285. final String attributeName, final String attributeValue)
  286. {
  287. Object value = descriptor.getValue(attributeName);
  288. Assert.assertTrue("Unspecified attributes must be stored as a ValueExpression",
  289. value instanceof ValueExpression);
  290. Assert.assertEquals(attributeValue,
  291. ((ValueExpression) value).getValue(facesContext.getELContext()));
  292. }
  293. /**
  294. * The "displayName", "shortDescription", "expert", "hidden", and "preferred"
  295. * attributes are only exposed, if ProjectStage equals Development. This test
  296. * case tests exactly this case.
  297. * @throws Exception
  298. */
  299. @Test
  300. public void testDevelopmentValuesDevelopmentStage() throws Exception
  301. {
  302. _testDevelopmentValues(ProjectStage.Development);
  303. }
  304. /**
  305. * The "displayName", "shortDescription", "expert", "hidden", and "preferred"
  306. * attributes are only exposed, if ProjectStage equals Development. This test
  307. * case tests the case when ProjectStage equals Production, thus the values
  308. * must not be exposed.
  309. * @throws Exception
  310. */
  311. @Test
  312. public void testDevelopmentValuesProductionStage() throws Exception
  313. {
  314. _testDevelopmentValues(ProjectStage.Production);
  315. }
  316. /**
  317. * Generic test code for testDevelopmentValuesDevelopmentStage()
  318. * and testDevelopmentValuesProductionStage().
  319. * @param stage
  320. * @throws Exception
  321. */
  322. @SuppressWarnings("unchecked")
  323. private void _testDevelopmentValues(ProjectStage stage) throws Exception
  324. {
  325. final boolean development = stage.equals(ProjectStage.Development);
  326. // set ProjectStage accordingly
  327. setProjectStage(stage);
  328. UIViewRoot root = facesContext.getViewRoot();
  329. vdl.buildView(facesContext, root, "testInterfaceDescriptorAttributes.xhtml");
  330. // get the composite component and its BeanInfo
  331. UIComponent composite = root.findComponent("panel").getChildren().get(0);
  332. CompositeComponentBeanInfo beanInfo =
  333. (CompositeComponentBeanInfo) composite.getAttributes()
  334. .get(UIComponent.BEANINFO_KEY);
  335. Assert.assertNotNull(beanInfo);
  336. // check <composite:interface>
  337. BeanDescriptor interfaceDescriptor = beanInfo.getBeanDescriptor();
  338. _checkDevelopmentValues(interfaceDescriptor, "interfaceDisplayName",
  339. "interfaceShortDescription", development);
  340. // check <composite:attribute>
  341. Assert.assertEquals("Expecting one <composite:attribute>",
  342. 1, beanInfo.getPropertyDescriptors().length);
  343. PropertyDescriptor attributeDescriptor = beanInfo.getPropertyDescriptors()[0];
  344. _checkDevelopmentValues(attributeDescriptor, "attributeDisplayName",
  345. "attributeShortDescription", development);
  346. // check <composite:facet>
  347. Map<String, PropertyDescriptor> facetPropertyDescriptorMap =
  348. (Map<String, PropertyDescriptor>) interfaceDescriptor.getValue(UIComponent.FACETS_KEY);
  349. Assert.assertNotNull(facetPropertyDescriptorMap);
  350. PropertyDescriptor facetDescriptor = facetPropertyDescriptorMap.get("facet");
  351. _checkDevelopmentValues(facetDescriptor, "facetDisplayName",
  352. "facetShortDescription", development);
  353. }
  354. /**
  355. * Assertions for _testDevelopmentValues()
  356. * @param descriptor
  357. * @param displayName
  358. * @param shortDescription
  359. * @param development
  360. */
  361. private void _checkDevelopmentValues(FeatureDescriptor descriptor,
  362. String displayName, String shortDescription,
  363. final boolean development)
  364. {
  365. boolean booleanPropertiesValue;
  366. // set values for assertions depending on the ProjectStage
  367. if (development)
  368. {
  369. // if we have ProjectStage == Development, all values
  370. // will be set to true in the composite component facelet file
  371. booleanPropertiesValue = true;
  372. // displayName and shortDescription must equal the given values
  373. }
  374. else
  375. {
  376. // standard value of all boolean properties is false
  377. booleanPropertiesValue = false;
  378. // getDisplayName()'s default value is the return from getName()
  379. displayName = descriptor.getName();
  380. // getShortDescription()'s default value is the return from getDisplayName()
  381. shortDescription = displayName;
  382. }
  383. // Assertions
  384. Assert.assertEquals(displayName, descriptor.getDisplayName());
  385. Assert.assertEquals(shortDescription, descriptor.getShortDescription());
  386. Assert.assertEquals(booleanPropertiesValue, descriptor.isExpert());
  387. Assert.assertEquals(booleanPropertiesValue, descriptor.isHidden());
  388. Assert.assertEquals(booleanPropertiesValue, descriptor.isPreferred());
  389. }
  390. @Test
  391. public void testSimpleActionTargetAttributeName() throws Exception
  392. {
  393. MockAttributeBean bean = new MockAttributeBean();
  394. facesContext.getExternalContext().getRequestMap().put("bean",
  395. bean);
  396. UIViewRoot root = facesContext.getViewRoot();
  397. vdl.buildView(facesContext, root, "testActionTargetAttributeName.xhtml");
  398. UIComponent panelGroup1 = root.findComponent("mainForm:testGroup1");
  399. Assert.assertNotNull(panelGroup1);
  400. UINamingContainer compositeComponent1 = (UINamingContainer) panelGroup1.findComponent("cc1");
  401. Assert.assertNotNull(compositeComponent1);
  402. UIComponent facet1 = compositeComponent1.getFacet(UIComponent.COMPOSITE_FACET_NAME);
  403. Assert.assertNotNull(facet1);
  404. HtmlCommandButton button1 = (HtmlCommandButton) facet1.findComponent("submitButton");
  405. Assert.assertNotNull(button1);
  406. HtmlCommandButton button2 = (HtmlCommandButton) facet1.findComponent("cancelAction");
  407. Assert.assertNotNull(button2);
  408. compositeComponent1.pushComponentToEL(facesContext, compositeComponent1);
  409. facet1.pushComponentToEL(facesContext, facet1);
  410. button1.pushComponentToEL(facesContext, button1);
  411. MethodExpression method = button1.getActionExpression();
  412. Assert.assertEquals("testActionMethodTypeSubmit", method.invoke(facesContext.getELContext(), null));
  413. Assert.assertEquals(1, button1.getActionListeners().length);
  414. button1.getActionListeners()[0].processAction(new ActionEvent(button1));
  415. Assert.assertTrue(bean.isSubmitActionListenerCalled());
  416. button1.popComponentFromEL(facesContext);
  417. button2.pushComponentToEL(facesContext, button2);
  418. method = button2.getActionExpression();
  419. Assert.assertEquals(bean.cancelAction(), method.invoke(facesContext.getELContext(), null));
  420. Assert.assertEquals(1, button2.getActionListeners().length);
  421. button2.getActionListeners()[0].processAction(new ActionEvent(button2));
  422. Assert.assertTrue(bean.isCancelActionListenerCalled());
  423. button2.popComponentFromEL(facesContext);
  424. facet1.popComponentFromEL(facesContext);
  425. compositeComponent1.popComponentFromEL(facesContext);
  426. StringWriter sw = new StringWriter();
  427. MockResponseWriter mrw = new MockResponseWriter(sw);
  428. facesContext.setResponseWriter(mrw);
  429. compositeComponent1.encodeAll(facesContext);
  430. sw.flush();
  431. /*
  432. HtmlRenderedAttr[] attrs = new HtmlRenderedAttr[]{
  433. new HtmlRenderedAttr("style")
  434. };
  435. HtmlCheckAttributesUtil.checkRenderedAttributes(attrs, sw.toString());
  436. */
  437. }
  438. @Test
  439. public void testCompositeActionTargetAttributeName() throws Exception
  440. {
  441. MockAttributeBean bean = new MockAttributeBean();
  442. facesContext.getExternalContext().getRequestMap().put("bean",
  443. bean);
  444. UIViewRoot root = facesContext.getViewRoot();
  445. vdl.buildView(facesContext, root, "testCompositeActionTargetAttributeName.xhtml");
  446. UIComponent panelGroup1 = root.findComponent("mainForm:testGroup1");
  447. Assert.assertNotNull(panelGroup1);
  448. UINamingContainer compositeComponent1 = (UINamingContainer) panelGroup1.findComponent("cc1");
  449. Assert.assertNotNull(compositeComponent1);
  450. UIComponent facet1 = compositeComponent1.getFacet(UIComponent.COMPOSITE_FACET_NAME);
  451. Assert.assertNotNull(facet1);
  452. UINamingContainer compositeComponent2 = (UINamingContainer) facet1.getChildren().get(0);
  453. Assert.assertNotNull(compositeComponent2);
  454. UIComponent facet2 = compositeComponent2.getFacet(UIComponent.COMPOSITE_FACET_NAME);
  455. Assert.assertNotNull(facet2);
  456. HtmlCommandButton button1 = (HtmlCommandButton) facet2.findComponent("submitButton");
  457. Assert.assertNotNull(button1);
  458. HtmlCommandButton button2 = (HtmlCommandButton) facet2.findComponent("cancelAction");
  459. Assert.assertNotNull(button2);
  460. compositeComponent1.pushComponentToEL(facesContext, compositeComponent1);
  461. facet1.pushComponentToEL(facesContext, facet1);
  462. compositeComponent2.pushComponentToEL(facesContext, compositeComponent2);
  463. facet2.pushComponentToEL(facesContext, facet1);
  464. button1.pushComponentToEL(facesContext, button1);
  465. MethodExpression method = button1.getActionExpression();
  466. Assert.assertEquals("testActionMethodTypeSubmit", method.invoke(facesContext.getELContext(), null));
  467. Assert.assertEquals(1, button1.getActionListeners().length);
  468. button1.getActionListeners()[0].processAction(new ActionEvent(button1));
  469. Assert.assertTrue(bean.isSubmitActionListenerCalled());
  470. button1.popComponentFromEL(facesContext);
  471. button2.pushComponentToEL(facesContext, button2);
  472. method = button2.getActionExpression();
  473. Assert.assertEquals(bean.cancelAction(), method.invoke(facesContext.getELContext(), null));
  474. Assert.assertEquals(1, button2.getActionListeners().length);
  475. button2.getActionListeners()[0].processAction(new ActionEvent(button2));
  476. Assert.assertTrue(bean.isCancelActionListenerCalled());
  477. button2.popComponentFromEL(facesContext);
  478. facet2.popComponentFromEL(facesContext);
  479. compositeComponent2.popComponentFromEL(facesContext);
  480. facet1.popComponentFromEL(facesContext);
  481. compositeComponent1.popComponentFromEL(facesContext);
  482. StringWriter sw = new StringWriter();
  483. MockResponseWriter mrw = new MockResponseWriter(sw);
  484. facesContext.setResponseWriter(mrw);
  485. compositeComponent1.encodeAll(facesContext);
  486. sw.flush();
  487. /*
  488. HtmlRenderedAttr[] attrs = new HtmlRenderedAttr[]{
  489. new HtmlRenderedAttr("style")
  490. };
  491. HtmlCheckAttributesUtil.checkRenderedAttributes(attrs, sw.toString());
  492. */
  493. }
  494. }