View Javadoc
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  
20  package org.apache.myfaces.tobago.internal.renderkit.renderer;
21  
22  import org.apache.myfaces.tobago.component.RendererTypes;
23  import org.apache.myfaces.tobago.component.Tags;
24  import org.apache.myfaces.tobago.component.UIBadge;
25  import org.apache.myfaces.tobago.component.UIButton;
26  import org.apache.myfaces.tobago.component.UIButtons;
27  import org.apache.myfaces.tobago.component.UILink;
28  import org.apache.myfaces.tobago.component.UISeparator;
29  import org.apache.myfaces.tobago.util.ComponentUtils;
30  import org.junit.Assert;
31  import org.junit.jupiter.api.Test;
32  
33  import java.io.IOException;
34  
35  public class ButtonsRendererUnitTest extends RendererTestBase {
36  
37    @Test
38    public void separatorInsideButtons() throws IOException {
39      final UIButtons l = (UIButtons) ComponentUtils.createComponent(
40          facesContext, Tags.buttons.componentType(), RendererTypes.Buttons, "list");
41      final UIButton c = (UIButton) ComponentUtils.createComponent(
42          facesContext, Tags.button.componentType(), RendererTypes.Button, "id");
43      c.setLabel("button");
44      l.getChildren().add(c);
45  
46      final UILink sub1 = (UILink) ComponentUtils.createComponent(
47          facesContext, Tags.link.componentType(), RendererTypes.Link, "sub1");
48      sub1.setLabel("sub1");
49      final UISeparator separator1 = (UISeparator) ComponentUtils.createComponent(
50          facesContext, Tags.separator.componentType(), RendererTypes.Separator, "separator1");
51      final UILink sub2 = (UILink) ComponentUtils.createComponent(
52          facesContext, Tags.link.componentType(), RendererTypes.Link, "sub2");
53      sub2.setLabel("sub2");
54      final UISeparator separator2 = (UISeparator) ComponentUtils.createComponent(
55          facesContext, Tags.separator.componentType(), RendererTypes.Separator, "separator2");
56      final UILink sub3 = (UILink) ComponentUtils.createComponent(
57          facesContext, Tags.link.componentType(), RendererTypes.Link, "sub3");
58      sub3.setLabel("sub3");
59  
60      c.getChildren().add(sub1);
61      c.getChildren().add(separator1);
62      c.getChildren().add(sub2);
63      c.getChildren().add(separator2);
64      c.getChildren().add(sub3);
65  
66      l.getChildren().add(c);
67  
68      l.encodeAll(facesContext);
69  
70      Assert.assertEquals(loadHtml("renderer/buttons/separator-inside-buttons.html"), formattedResult());
71    }
72  
73    @Test
74    public void badgeInsideButtons() throws IOException {
75      final UIButtons l = (UIButtons) ComponentUtils.createComponent(
76          facesContext, Tags.buttons.componentType(), RendererTypes.Buttons, "list");
77      final UIBadge b = (UIBadge) ComponentUtils.createComponent(
78          facesContext, Tags.badge.componentType(), RendererTypes.Badge, "badge");
79      final UIButton c = (UIButton) ComponentUtils.createComponent(
80          facesContext, Tags.button.componentType(), RendererTypes.Button, "id");
81      c.setLabel("button");
82  
83      l.getChildren().add(b);
84      l.getChildren().add(c);
85  
86      l.encodeAll(facesContext);
87  
88      Assert.assertEquals(loadHtml("renderer/buttons/badge-inside-buttons.html"), formattedResult());
89    }
90  
91  }