KickJava   Java API By Example, From Geeks To Geeks.

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


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

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

33 public class XMLPropertyDefinitionTest {
34
35     /**
36      * @throws JDOMException
37      */

38     @Test
39     public void fromXMLElement() throws JDOMException {
40         Element el = new Element("definition");
41         el.setAttribute("name", "def1");;
42         el.setAttribute("type", String.valueOf(XMLPropertyDefinition.TYPE_INTEGER));
43         el.setAttribute("typeMeta", "");
44         el.setAttribute("category", "15");
45         el.setAttribute("defaultValue", "20");
46         el.setAttribute("sortOrder", "50");
47         el.setAttribute("validation", "com.sslexplorer.input.validators.IntegerValidator");
48         
49         XMLPropertyDefinition def1 = new XMLPropertyDefinition(el);
50         
51         Assert.assertEquals(DefaultPropertyDefinition.TYPE_INTEGER, def1.getType());
52         Assert.assertEquals("def1", def1.getName());
53         Assert.assertEquals("", def1.getTypeMeta());
54         Assert.assertEquals(15, def1.getCategory());
55         Assert.assertEquals("20", def1.getDefaultValue());
56         Assert.assertEquals(50, def1.getSortOrder());
57         Assert.assertEquals("properties", def1.getMessageResourcesKey());
58         Assert.assertNotNull(def1.getValidationString());
59         Assert.assertEquals(false, def1.isHidden());
60         
61         try {
62             def1.validate("20", getClass().getClassLoader());
63         }
64         catch(CodedException ce) {
65             Assert.fail("Validation failed when it shouldn't.");
66         }
67         try {
68             def1.validate("10000000000000", getClass().getClassLoader());
69             Assert.fail("Validation didn't fail when it should.");
70         }
71         catch(CodedException ce) {
72         }
73
74         el.setAttribute("messageResourcesKey", "test");
75         el.setAttribute("hidden", "true");
76         el.setAttribute("validation", "com.sslexplorer.input.validators.IntegerValidator(minValue=10,maxValue=100)");
77         
78         XMLPropertyDefinition def2 = new XMLPropertyDefinition(el);
79
80         Assert.assertEquals("test", def2.getMessageResourcesKey());
81         Assert.assertEquals(true, def2.isHidden());
82         Assert.assertEquals("com.sslexplorer.input.validators.IntegerValidator(minValue=10,maxValue=100)", def2.getValidationString());
83
84         try {
85             def2.validate("20", getClass().getClassLoader());
86         }
87         catch(CodedException ce) {
88             Assert.fail("Validation failed when it shouldn't.");
89         }
90         try {
91             def2.validate("101", getClass().getClassLoader());
92             Assert.fail("Validation didn't fail when it should.");
93         }
94         catch(CodedException ce) {
95         }
96     }
97 }
Popular Tags