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