1 package com.sslexplorer.boot; 2 3 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 34 public class DefaultPropertyDefinitionTest { 35 36 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 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 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 |