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.renderkit.css;
21  
22  import org.apache.myfaces.tobago.component.RendererTypes;
23  import org.apache.myfaces.tobago.component.UIIn;
24  import org.apache.myfaces.tobago.component.Visual;
25  import org.apache.myfaces.tobago.context.Markup;
26  import org.apache.myfaces.tobago.internal.config.AbstractTobagoTestBase;
27  import org.apache.myfaces.tobago.util.ComponentUtils;
28  import org.junit.Assert;
29  import org.junit.Test;
30  
31  import javax.faces.component.UIComponent;
32  
33  public class ClassesUnitTest extends AbstractTobagoTestBase {
34  
35    @Test
36    public void testSimple() {
37      final UIIn in = (UIIn) ComponentUtils.createComponent(
38          getFacesContext(), UIIn.COMPONENT_TYPE, RendererTypes.In, "in");
39      Assert.assertEquals("tobago-in-simple", Classes.create(in, "simple").getName());
40    }
41  
42    @Test
43    public void testFull() {
44      final UIIn in = (UIIn) ComponentUtils.createComponent(
45          getFacesContext(), UIIn.COMPONENT_TYPE, RendererTypes.In, "in");
46      Assert.assertEquals("tobago-in", Classes.create(in).getName());
47    }
48  
49    @Test
50    public void testDisabled() {
51      final UIIn in = (UIIn) ComponentUtils.createComponent(
52          getFacesContext(), UIIn.COMPONENT_TYPE, RendererTypes.In, "in");
53      in.setDisabled(true);
54      updateMarkup(in);
55      Assert.assertEquals("tobago-in tobago-in-markup-disabled", Classes.create(in).getName());
56    }
57  
58    @Test
59    public void testReadonly() {
60      final UIIn in = (UIIn) ComponentUtils.createComponent(
61          getFacesContext(), UIIn.COMPONENT_TYPE, RendererTypes.In, "in");
62      in.setReadonly(true);
63      updateMarkup(in);
64      Assert.assertEquals("tobago-in tobago-in-markup-readonly", Classes.create(in).getName());
65    }
66  
67    @Test
68    public void testDisabledReadonly() {
69      final UIIn in = (UIIn) ComponentUtils.createComponent(
70          getFacesContext(), UIIn.COMPONENT_TYPE, RendererTypes.In, "in");
71      in.setDisabled(true);
72      in.setReadonly(true);
73      updateMarkup(in);
74      Assert.assertEquals(
75          "tobago-in tobago-in-markup-disabled tobago-in-markup-readonly", Classes.create(in).getName());
76    }
77  
78    @Test
79    public void testError() {
80      final UIIn in = (UIIn) ComponentUtils.createComponent(
81          getFacesContext(), UIIn.COMPONENT_TYPE, RendererTypes.In, "in");
82      in.setValid(false);
83      updateMarkup(in);
84      Assert.assertEquals("tobago-in tobago-in-markup-error", Classes.create(in).getName());
85    }
86  
87    @Test
88    public void testMarkup() {
89      final UIIn in = (UIIn) ComponentUtils.createComponent(
90          getFacesContext(), UIIn.COMPONENT_TYPE, RendererTypes.In, "in");
91      in.setMarkup(Markup.valueOf("important"));
92      updateMarkup(in);
93      Assert.assertEquals("tobago-in tobago-in-markup-important", Classes.create(in).getName());
94    }
95  
96    @Test
97    public void testSub() {
98      final UIIn in = (UIIn) ComponentUtils.createComponent(
99          getFacesContext(), UIIn.COMPONENT_TYPE, RendererTypes.In, "in");
100     Assert.assertEquals("tobago-in-sub", Classes.create(in, "sub").getName());
101   }
102 
103   @Test
104   public void testMixed() {
105     final UIIn in = (UIIn) ComponentUtils.createComponent(
106         getFacesContext(), UIIn.COMPONENT_TYPE, RendererTypes.In, "in");
107     in.setDisabled(true);
108     in.setReadonly(true);
109     in.setValid(false);
110     in.setMarkup(Markup.valueOf("important,deleted"));
111     updateMarkup(in);
112     Assert.assertEquals("tobago-in-sub tobago-in-sub-markup-important tobago-in-sub-markup-deleted "
113         + "tobago-in-sub-markup-disabled tobago-in-sub-markup-readonly tobago-in-sub-markup-error",
114         Classes.create(in, "sub").getName());
115   }
116 
117   private void updateMarkup(final UIComponent component) {
118     final Visual m = (Visual) component;
119     m.setMarkup(ComponentUtils.updateMarkup(component, m.getMarkup()));
120   }
121 
122 }