1 45 package org.exolab.jms.net.util; 46 47 import junit.framework.TestCase; 48 49 50 56 public class SSLPropertiesTest extends TestCase { 57 58 final String keyStore = "keyStore"; 59 final String keyStorePassword = "keyStorePassword"; 60 final String keyStoreType = "JKS"; 61 final String trustStore = "trustStore"; 62 final String trustStorePassword = "trustStorePassword"; 63 final String trustStoreType = "PCKS12"; 64 65 66 71 public SSLPropertiesTest(String name) { 72 super(name); 73 } 74 75 78 public void testAccessors() { 79 SSLProperties properties = populate(keyStore, keyStorePassword, 80 keyStoreType, trustStore, 81 trustStorePassword, trustStoreType); 82 83 assertEquals(keyStore, properties.getKeyStore()); 84 assertEquals(keyStorePassword, properties.getKeyStorePassword()); 85 assertEquals(keyStoreType, properties.getKeyStoreType()); 86 assertEquals(trustStore, properties.getTrustStore()); 87 assertEquals(trustStorePassword, properties.getTrustStorePassword()); 88 assertEquals(trustStoreType, properties.getTrustStoreType()); 89 } 90 91 94 public void testIsEmpty() { 95 SSLProperties properties = new SSLProperties(); 96 assertTrue(properties.isEmpty()); 97 98 properties.setKeyStore("foo"); 99 assertFalse(properties.isEmpty()); 100 101 properties = new SSLProperties(); 102 properties.setKeyStorePassword("bar"); 103 assertFalse(properties.isEmpty()); 104 105 properties = new SSLProperties(); 106 properties.setKeyStoreType("JKS"); 107 assertFalse(properties.isEmpty()); 108 109 properties = new SSLProperties(); 110 properties.setTrustStore("foo"); 111 assertFalse(properties.isEmpty()); 112 113 properties = new SSLProperties(); 114 properties.setTrustStorePassword("bar"); 115 assertFalse(properties.isEmpty()); 116 117 properties = new SSLProperties(); 118 properties.setTrustStoreType("PCKS12"); 119 assertFalse(properties.isEmpty()); 120 } 121 122 125 public void testEquals() { 126 127 SSLProperties empty = new SSLProperties(); 128 assertEquals(empty, empty); 129 130 SSLProperties ssl1 = populate(keyStore, keyStorePassword, keyStoreType, 131 trustStore, trustStorePassword, 132 trustStoreType); 133 assertFalse(ssl1.equals(empty)); 134 135 SSLProperties ssl2 = populate(keyStore, keyStorePassword, keyStoreType, 136 trustStore, trustStorePassword, 137 trustStoreType); 138 assertEquals(ssl1, ssl2); 139 140 SSLProperties ssl3 = populate(null, keyStorePassword, keyStoreType, 141 trustStore, trustStorePassword, 142 trustStoreType); 143 assertFalse(ssl1.equals(ssl3)); 144 145 SSLProperties ssl4 = populate(keyStore, null, keyStoreType, 146 trustStore, trustStorePassword, 147 trustStoreType); 148 assertFalse(ssl1.equals(ssl4)); 149 150 SSLProperties ssl5 = populate(keyStore, keyStorePassword, null, 151 trustStore, trustStorePassword, 152 trustStoreType); 153 assertFalse(ssl1.equals(ssl5)); 154 155 SSLProperties ssl6 = populate(keyStore, keyStorePassword, 156 keyStoreType, null, trustStorePassword, 157 trustStoreType); 158 assertFalse(ssl1.equals(ssl6)); 159 160 SSLProperties ssl7 = populate(keyStore, keyStorePassword, keyStoreType, 161 trustStore, null, trustStoreType); 162 assertFalse(ssl1.equals(ssl7)); 163 164 SSLProperties ssl8 = populate(keyStore, keyStorePassword, keyStoreType, 165 trustStore, trustStorePassword, null); 166 assertFalse(ssl1.equals(ssl8)); 167 } 168 169 174 public void testProperties() throws Exception { 175 final String prefix = "org.exolab.jms.net.https."; 176 SSLProperties ssl1 = populate(keyStore, keyStorePassword, keyStoreType, 177 trustStore, trustStorePassword, 178 trustStoreType); 179 180 Properties properties = new Properties(prefix); 181 ssl1.export(properties); 182 183 SSLProperties ssl2 = new SSLProperties(properties); 184 assertEquals(ssl1, ssl2); 185 186 assertEquals(keyStore, ssl2.getKeyStore()); 187 assertEquals(keyStorePassword, ssl2.getKeyStorePassword()); 188 assertEquals(keyStoreType, ssl2.getKeyStoreType()); 189 assertEquals(trustStore, ssl2.getTrustStore()); 190 assertEquals(trustStorePassword, ssl2.getTrustStorePassword()); 191 assertEquals(trustStoreType, ssl2.getTrustStoreType()); 192 } 193 194 205 private SSLProperties populate(String keyStore, String keyStorePassword, 206 String keyStoreType, String trustStore, 207 String trustStorePassword, 208 String trustStoreType) { 209 SSLProperties result = new SSLProperties(); 210 result.setKeyStore(keyStore); 211 result.setKeyStorePassword(keyStorePassword); 212 result.setKeyStoreType(keyStoreType); 213 result.setTrustStore(trustStore); 214 result.setTrustStorePassword(trustStorePassword); 215 result.setTrustStoreType(trustStoreType); 216 return result; 217 } 218 219 } 220 | Popular Tags |