1 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 33 public class XMLPropertyDefinitionTest { 34 35 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 |