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  package org.apache.myfaces.trinidad.component.core.data;
20  
21  import java.io.IOException;
22  
23  import java.util.ArrayList;
24  import java.util.List;
25  
26  import org.apache.myfaces.trinidad.component.UIComponentTestCase;
27  import org.apache.myfaces.trinidad.event.RangeChangeEvent;
28  import org.apache.myfaces.trinidad.event.RangeChangeListener;
29  
30  import junit.framework.Test;
31  import junit.framework.TestSuite;
32  import junit.textui.TestRunner;
33  
34  /**
35   * Unit tests for CoreSelectRangeChoiceBar
36   *
37   */
38  public class CoreSelectRangeChoiceBarTest extends UIComponentTestCase
39  {
40    /**
41     * Creates a new CoreSelectRangeChoiceBarTest.
42     *
43     * @param testName  the unit test name
44     */
45    public CoreSelectRangeChoiceBarTest(
46      String testName)
47    {
48      super(testName);
49    }
50    
51    @Override
52    protected void setUp() throws Exception
53    {
54      super.setUp();
55    }
56    
57    @Override
58    protected void tearDown() throws Exception
59    {
60      super.tearDown();
61    }
62    
63    public static Test suite()
64    {
65      return new TestSuite(CoreSelectRangeChoiceBarTest.class);
66    }
67  
68    /**
69     * Tests the initial values for the component attributes.
70     */
71    public void testInitialAttributeValues()
72    {
73      CoreSelectRangeChoiceBar component = new CoreSelectRangeChoiceBar();
74      assertEquals(true, component.isRendered());
75      assertEquals(25, component.getRows());
76      assertEquals(0, component.getFirst());
77      assertEquals(false, component.isShowAll());
78      //assertEquals(-1, component.getMaximum());    
79    }
80  
81    /**
82     * Tests the transparency of the component attribute by comparing
83     * bean accessor and mutator methods with attribute map accessor
84     * and mutator methods.
85     */
86    public void testAttributeTransparency()
87    {
88      CoreSelectRangeChoiceBar component = new CoreSelectRangeChoiceBar();
89  
90      doTestAttributeTransparency(component, "rendered",
91                                  Boolean.TRUE, Boolean.FALSE);
92      doTestAttributeTransparency(component, "showAll", Boolean.TRUE, Boolean.FALSE);
93      doTestAttributeTransparency(component, "immediate",
94                                  Boolean.TRUE, Boolean.FALSE);
95      doTestAttributeTransparency(component, "rows",
96                                  new Integer(1), new Integer(5));
97      doTestAttributeTransparency(component, "first",
98                                  new Integer(1), new Integer(5));                                 
99    }
100 
101 
102   /**
103    * Tests the apply-request-values lifecycle phase.
104    */
105   public void testApplyRequestValues()
106   {
107     CoreSelectRangeChoiceBar component = new CoreSelectRangeChoiceBar();
108     doTestApplyRequestValues(component);
109 
110     component = new CoreSelectRangeChoiceBar();
111     component.setRendered(false);
112     doTestApplyRequestValues(component);
113   }
114 
115   /**
116    * Tests the process-validations lifecycle phase.
117    */
118   public void testProcessValidations()
119   {
120     CoreSelectRangeChoiceBar component = new CoreSelectRangeChoiceBar();
121     doTestProcessValidations(component);
122   }
123 
124   /**
125    * Tests the update-model-values lifecycle phase.
126    */
127   public void testUpdateModelValues()
128   {
129     CoreSelectRangeChoiceBar component = new CoreSelectRangeChoiceBar();
130     doTestUpdateModelValues(component);
131   }
132 
133 
134   private class MockRangeChangeListener implements RangeChangeListener
135   {
136     public List<RangeChangeEvent> list()
137     {
138       return _list;
139     }
140 
141     public void processRangeChange(RangeChangeEvent event)
142     {
143       _list.add(event);
144     }
145 
146     private List<RangeChangeEvent> _list = new ArrayList<RangeChangeEvent>();
147   }
148 
149   /**
150    * Tests the invoke-application lifecycle phase.
151    */
152   public void testInvokeApplication()
153   {
154     MockRangeChangeListener listener = new MockRangeChangeListener();
155 
156     CoreSelectRangeChoiceBar component = new CoreSelectRangeChoiceBar();
157     component.addRangeChangeListener(listener);
158     RangeChangeEvent event = new RangeChangeEvent(component, 0, 9, 10, 19);
159 
160     doTestInvokeApplication(component, event);
161 
162     assertEquals(listener.list().size(), 1);
163     assertEquals(listener.list().get(0), event);
164   }
165 
166   /**
167    * Tests the render-response lifecycle phase.
168    *
169    * @throws IOException  when test fails
170    */
171   public void testRenderResponse() throws IOException
172   {
173     CoreSelectRangeChoiceBar component = new CoreSelectRangeChoiceBar();
174     doTestRenderResponse(component);
175   }
176   
177   public static void main(String[] args)
178   {
179     TestRunner.run(CoreSelectRangeChoiceBarTest.class);
180 
181   }  
182 }