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.custom.convertNumber;
20  
21  import javax.faces.application.FacesMessage;
22  import javax.faces.component.UIInput;
23  import javax.faces.convert.ConverterException;
24  
25  import junit.framework.Test;
26  import junit.framework.TestSuite;
27  
28  import org.apache.shale.test.base.AbstractJsfTestCase;
29  
30  /**
31   * @author cagatay (latest modification by $Author: skitching $)
32   * @version $Revision: 673833 $ $Date: 2008-07-03 16:58:05 -0500 (Thu, 03 Jul 2008) $
33   */
34  public class TypedNumberConverterTest extends AbstractJsfTestCase{
35      
36      private TypedNumberConverter converter;
37      
38      public TypedNumberConverterTest(String testName) {
39          super(testName);
40      }
41      
42      public void setUp() throws Exception{
43          super.setUp();
44          converter = new TypedNumberConverter();
45      }
46      
47      public void tearDown() throws Exception{
48          super.tearDown();
49          converter = null; 
50      }
51      
52      public static Test suite() {
53          return new TestSuite(TypedNumberConverterTest.class);
54      }
55      
56      public void testSeverityLevelOfMessageShouldBeErrorInCaseConversionFails() {
57          UIInput input = new UIInput();
58          input.setId("txt_test");
59          
60          converter.setIntegerOnly(true);
61          
62          try {
63              converter.getAsObject(facesContext, input, "test_invalid_input");
64              
65              fail();
66          }catch (ConverterException exception) {
67              FacesMessage facesMessage = exception.getFacesMessage();
68              assertEquals(FacesMessage.SEVERITY_ERROR, facesMessage.getSeverity());
69          }
70          
71      }
72  }