1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.myfaces.commons.converter;
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.myfaces.test.base.AbstractJsfTestCase;
29
30
31
32
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
73 public void testIntegerOnly()
74 {
75 UIInput input = new UIInput();
76 input.setId("txt_test");
77
78 converter.setIntegerOnly(true);
79
80 try {
81 String inValue = "29991";
82 Object value = converter.getAsObject(facesContext, input, inValue);
83 assertEquals((Long) value, Long.valueOf(29991));
84 }catch (ConverterException exception) {
85 fail();
86 }
87 }
88 }