KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > boot > DefaultPropertyDefinitionTest


1 package com.sslexplorer.boot;
2
3 /*
4  * SSL-Explorer
5  *
6  * Copyright (C) 2003-2006 3SP LTD. All Rights Reserved
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2 of
11  * the License, or (at your option) any later version.
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public
18  * License along with this program; if not, write to the Free Software
19  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20  */

21             
22
23 import org.junit.Assert;
24 import org.junit.Test;
25
26 import com.sslexplorer.boot.CodedException;
27 import com.sslexplorer.boot.DefaultPropertyDefinition;
28
29 /**
30  * Tests {@link DefaultPropertyDefinition}.
31  *
32  * @author Brett Smith <a HREF="mailto: brett@3sp.com">&lt;brett@3sp.com&gt;</a>
33  */

34 public class DefaultPropertyDefinitionTest {
35
36     /**
37      */

38     @Test
39     public void constructors() {
40
41         DefaultPropertyDefinition def1 = new DefaultPropertyDefinition(
42             DefaultPropertyDefinition.TYPE_BOOLEAN,
43             "con1", "on,off", 10, "true", 50, true);
44         
45         Assert.assertEquals(DefaultPropertyDefinition.TYPE_BOOLEAN, def1.getType());
46         Assert.assertEquals("con1", def1.getName());
47         Assert.assertEquals("on,off", def1.getTypeMeta());
48         Assert.assertEquals(10, def1.getCategory());
49         Assert.assertEquals("true", def1.getDefaultValue());
50         Assert.assertEquals(50, def1.getSortOrder());
51         Assert.assertEquals("properties", def1.getMessageResourcesKey());
52         Assert.assertEquals(null, def1.getValidationString());
53         Assert.assertEquals(true, def1.isHidden());
54
55         DefaultPropertyDefinition def2 = new DefaultPropertyDefinition(
56             DefaultPropertyDefinition.TYPE_BOOLEAN,
57             "con2", "on,off", 10, "true", 50, "test", true);
58         
59         Assert.assertEquals(DefaultPropertyDefinition.TYPE_BOOLEAN, def2.getType());
60         Assert.assertEquals("con2", def2.getName());
61         Assert.assertEquals("on,off", def2.getTypeMeta());
62         Assert.assertEquals(10, def2.getCategory());
63         Assert.assertEquals("true", def2.getDefaultValue());
64         Assert.assertEquals(50, def2.getSortOrder());
65         Assert.assertEquals("test", def2.getMessageResourcesKey());
66         Assert.assertEquals(null, def2.getValidationString());
67         Assert.assertEquals(true, def2.isHidden());
68
69         DefaultPropertyDefinition def3 = new DefaultPropertyDefinition(
70             DefaultPropertyDefinition.TYPE_BOOLEAN,
71             "con3", "on,off", 10, "true", 50, true, null);
72         
73         Assert.assertEquals(DefaultPropertyDefinition.TYPE_BOOLEAN, def3.getType());
74         Assert.assertEquals("con3", def3.getName());
75         Assert.assertEquals("on,off", def3.getTypeMeta());
76         Assert.assertEquals(10, def3.getCategory());
77         Assert.assertEquals("true", def3.getDefaultValue());
78         Assert.assertEquals(50, def3.getSortOrder());
79         Assert.assertEquals("properties", def3.getMessageResourcesKey());
80         Assert.assertEquals(null, def3.getValidationString());
81         Assert.assertEquals(true, def3.isHidden());
82
83         DefaultPropertyDefinition def4 = new DefaultPropertyDefinition(
84             DefaultPropertyDefinition.TYPE_BOOLEAN,
85             "con4", "on,off", 10, "true", 50, "test", true, null);
86         
87         Assert.assertEquals(DefaultPropertyDefinition.TYPE_BOOLEAN, def4.getType());
88         Assert.assertEquals("con4", def4.getName());
89         Assert.assertEquals("on,off", def4.getTypeMeta());
90         Assert.assertEquals(10, def4.getCategory());
91         Assert.assertEquals("true", def4.getDefaultValue());
92         Assert.assertEquals(50, def4.getSortOrder());
93         Assert.assertEquals("test", def4.getMessageResourcesKey());
94         Assert.assertEquals(null, def4.getValidationString());
95         Assert.assertEquals(true, def4.isHidden());
96
97     }
98
99     /**
100      */

101     @Test
102     public void defaultBooleanPropertyDefinitionWithNoValidator() {
103         DefaultPropertyDefinition def = new DefaultPropertyDefinition(
104             DefaultPropertyDefinition.TYPE_BOOLEAN,
105             "bool1", "on,off", 10, "true", 50, "test", true, "com.sslexplorer.input.validators.BooleanValidator");
106         try {
107             def.validate("true", getClass().getClassLoader());
108         }
109         catch(CodedException ce) {
110             Assert.fail("Validation failed when it shouldn't.");
111         }
112     }
113
114     /**
115      */

116     @Test
117     public void defaultIntegerPropertyDefinitionWithDefaultValidator() {
118         DefaultPropertyDefinition def = new DefaultPropertyDefinition(
119             DefaultPropertyDefinition.TYPE_INTEGER,
120             "int1", "", 10, "5", 50, "test", true, "com.sslexplorer.input.validators.IntegerValidator");
121         try {
122             def.validate("10", getClass().getClassLoader());
123         }
124         catch(CodedException ce) {
125             Assert.fail("Validation failed when it shouldn't.");
126         }
127         try {
128             def.validate("10000000000000", getClass().getClassLoader());
129             Assert.fail("Validation didn't fail when it should.");
130         }
131         catch(CodedException ce) {
132         }
133     }
134 }
Popular Tags