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