1 18 19 package org.apache.jmeter.testelement.property; 20 21 import junit.framework.TestCase; 22 23 import org.apache.jmeter.config.LoginConfig; 24 25 28 public class PackageTest extends TestCase 29 { 30 31 public PackageTest(String name) 32 { 33 super(name); 34 } 35 36 public void testStringProperty() throws Exception 37 { 38 StringProperty prop = new StringProperty("name","value"); 39 prop.setRunningVersion(true); 40 prop.setObjectValue("new Value"); 41 assertEquals("new Value",prop.getStringValue()); 42 prop.recoverRunningVersion(null); 43 assertEquals("value",prop.getStringValue()); 44 prop.setObjectValue("new Value"); 45 prop.setObjectValue("2nd Value"); 46 assertEquals("2nd Value",prop.getStringValue()); 47 prop.recoverRunningVersion(null); 48 assertEquals("value",prop.getStringValue()); 49 } 50 51 public void testElementProperty() throws Exception 52 { 53 LoginConfig config = new LoginConfig(); 54 config.setUsername("username"); 55 config.setPassword("password"); 56 TestElementProperty prop = new TestElementProperty("name",config); 57 prop.setRunningVersion(true); 58 config = new LoginConfig(); 59 config.setUsername("user2"); 60 config.setPassword("pass2"); 61 prop.setObjectValue(config); 62 assertEquals("user2=pass2",prop.getStringValue()); 63 prop.recoverRunningVersion(null); 64 assertEquals("username=password",prop.getStringValue()); 65 config = new LoginConfig(); 66 config.setUsername("user2"); 67 config.setPassword("pass2"); 68 prop.setObjectValue(config); 69 config = new LoginConfig(); 70 config.setUsername("user3"); 71 config.setPassword("pass3"); 72 prop.setObjectValue(config); 73 assertEquals("user3=pass3",prop.getStringValue()); 74 prop.recoverRunningVersion(null); 75 assertEquals("username=password",prop.getStringValue()); 76 } 77 private void checkEquals(JMeterProperty jp1, JMeterProperty jp2) 78 { 79 assertEquals(jp1,jp2); 80 assertEquals(jp2,jp1); 81 assertEquals(jp1,jp1); 82 assertEquals(jp2,jp2); 83 assertEquals(jp1.hashCode(),jp2.hashCode()); 84 85 } 86 private void checkNotEquals(JMeterProperty jp1, JMeterProperty jp2) 87 { 88 assertEquals(jp1,jp1); 89 assertEquals(jp2,jp2); 90 assertFalse(jp1.equals(jp2)); 91 assertFalse(jp2.equals(jp1)); 92 if (jp1.hashCode()==jp2.hashCode()) 94 { 95 System.out.println("Expected different hashCodes for "+jp1.getClass().getName()); 96 97 } 98 99 } 100 public void testBooleanEquality() throws Exception 101 { 102 BooleanProperty jpn1 = new BooleanProperty(); 103 BooleanProperty jpn2 = new BooleanProperty(); 104 BooleanProperty jp1 = new BooleanProperty("name1",true); 105 BooleanProperty jp2 = new BooleanProperty("name1",true); 106 BooleanProperty jp3 = new BooleanProperty("name2",true); 107 BooleanProperty jp4 = new BooleanProperty("name2",false); 108 checkEquals(jpn1,jpn2); 109 checkNotEquals(jpn1,jp1); 110 checkNotEquals(jpn1,jp2); 111 checkEquals(jp1,jp2); 112 checkNotEquals(jp1,jp3); 113 checkNotEquals(jp2,jp3); 114 checkNotEquals(jp3,jp4); 115 } 116 public void testDoubleEquality() throws Exception 117 { 118 DoubleProperty jpn1 = new DoubleProperty(); 119 DoubleProperty jpn2 = new DoubleProperty(); 120 DoubleProperty jp1 = new DoubleProperty("name1",123.4); 121 DoubleProperty jp2 = new DoubleProperty("name1",123.4); 122 DoubleProperty jp3 = new DoubleProperty("name2",-123.4); 123 DoubleProperty jp4 = new DoubleProperty("name2",123.4); 124 DoubleProperty jp5 = new DoubleProperty("name2",Double.NEGATIVE_INFINITY); 125 DoubleProperty jp6 = new DoubleProperty("name2",Double.NEGATIVE_INFINITY); 126 DoubleProperty jp7 = new DoubleProperty("name2",Double.POSITIVE_INFINITY); 127 DoubleProperty jp8 = new DoubleProperty("name2",Double.POSITIVE_INFINITY); 128 DoubleProperty jp9 = new DoubleProperty("name2",Double.NaN); 129 DoubleProperty jp10 = new DoubleProperty("name2",Double.NaN); 130 DoubleProperty jp11 = new DoubleProperty("name1",Double.NaN); 131 DoubleProperty jp12 = new DoubleProperty("name1",Double.MIN_VALUE); 132 DoubleProperty jp13 = new DoubleProperty("name2",Double.MIN_VALUE); 133 DoubleProperty jp14 = new DoubleProperty("name2",Double.MIN_VALUE); 134 DoubleProperty jp15 = new DoubleProperty("name1",Double.MAX_VALUE); 135 DoubleProperty jp16 = new DoubleProperty("name2",Double.MAX_VALUE); 136 DoubleProperty jp17 = new DoubleProperty("name2",Double.MAX_VALUE); 137 checkEquals(jpn1,jpn2); 138 checkNotEquals(jpn1,jp1); 139 checkNotEquals(jpn1,jp2); 140 checkEquals(jp1,jp2); 141 checkNotEquals(jp1,jp3); 142 checkNotEquals(jp2,jp3); 143 checkNotEquals(jp3,jp4); 144 checkEquals(jp5,jp6); 145 checkNotEquals(jp3,jp6); 146 checkEquals(jp7,jp8); 147 checkNotEquals(jp4,jp7); 148 checkNotEquals(jp8,jp9); 149 checkEquals(jp9,jp10); 150 checkNotEquals(jp10,jp11); 151 checkNotEquals(jp5,jp10); 152 checkNotEquals(jp12,jp14); 153 checkEquals(jp13,jp14); 154 checkNotEquals(jp15,jp16); 155 checkEquals(jp16,jp17); 156 } 157 public void testFloatEquality() throws Exception 158 { 159 FloatProperty jp1 = new FloatProperty("name1",123.4f); 160 FloatProperty jp2 = new FloatProperty("name1",123.4f); 161 FloatProperty jp3 = new FloatProperty("name2",-123.4f); 162 FloatProperty jp4 = new FloatProperty("name2",123.4f); 163 FloatProperty jp5 = new FloatProperty("name2",Float.NEGATIVE_INFINITY); 164 FloatProperty jp6 = new FloatProperty("name2",Float.NEGATIVE_INFINITY); 165 FloatProperty jp7 = new FloatProperty("name2",Float.POSITIVE_INFINITY); 166 FloatProperty jp8 = new FloatProperty("name2",Float.POSITIVE_INFINITY); 167 FloatProperty jp9 = new FloatProperty("name2",Float.NaN); 168 FloatProperty jp10 = new FloatProperty("name2",Float.NaN); 169 FloatProperty jp11 = new FloatProperty("name1",Float.NaN); 170 FloatProperty jp12 = new FloatProperty("name1",Float.MIN_VALUE); 171 FloatProperty jp13 = new FloatProperty("name2",Float.MIN_VALUE); 172 FloatProperty jp14 = new FloatProperty("name2",Float.MIN_VALUE); 173 FloatProperty jp15 = new FloatProperty("name1",Float.MAX_VALUE); 174 FloatProperty jp16 = new FloatProperty("name2",Float.MAX_VALUE); 175 FloatProperty jp17 = new FloatProperty("name2",Float.MAX_VALUE); 176 checkEquals(jp1,jp2); 177 checkNotEquals(jp1,jp3); 178 checkNotEquals(jp2,jp3); 179 checkNotEquals(jp3,jp4); 180 checkEquals(jp5,jp6); 181 checkNotEquals(jp3,jp6); 182 checkEquals(jp7,jp8); 183 checkNotEquals(jp4,jp7); 184 checkNotEquals(jp8,jp9); 185 checkEquals(jp9,jp10); 186 checkNotEquals(jp10,jp11); 187 checkNotEquals(jp5,jp10); 188 checkNotEquals(jp12,jp14); 189 checkEquals(jp13,jp14); 190 checkNotEquals(jp15,jp16); 191 checkEquals(jp16,jp17); 192 } 193 194 public void testIntegerEquality() throws Exception 195 { 196 IntegerProperty jp1 = new IntegerProperty("name1",123); 197 IntegerProperty jp2 = new IntegerProperty("name1",123); 198 IntegerProperty jp3 = new IntegerProperty("name2",-123); 199 IntegerProperty jp4 = new IntegerProperty("name2",123); 200 IntegerProperty jp5 = new IntegerProperty("name2",Integer.MIN_VALUE); 201 IntegerProperty jp6 = new IntegerProperty("name2",Integer.MIN_VALUE); 202 IntegerProperty jp7 = new IntegerProperty("name2",Integer.MAX_VALUE); 203 IntegerProperty jp8 = new IntegerProperty("name2",Integer.MAX_VALUE); 204 IntegerProperty jp9 = new IntegerProperty("name1",Integer.MIN_VALUE); 205 IntegerProperty jp10 = new IntegerProperty("name1",Integer.MAX_VALUE); 206 checkEquals(jp1,jp2); 207 checkNotEquals(jp1,jp3); 208 checkNotEquals(jp2,jp3); 209 checkNotEquals(jp3,jp4); 210 checkEquals(jp5,jp6); 211 checkNotEquals(jp3,jp6); 212 checkEquals(jp7,jp8); 213 checkNotEquals(jp4,jp7); 214 checkNotEquals(jp9,jp5); 215 checkNotEquals(jp10,jp7); 216 checkNotEquals(jp9,jp10); 217 try { 218 new IntegerProperty(null); 219 fail("Should have generated an Illegal Argument Exception"); 220 } catch (IllegalArgumentException e) { } 221 try { 222 new IntegerProperty(null,0); 223 fail("Should have generated an Illegal Argument Exception"); 224 } catch (IllegalArgumentException e) { } 225 } 226 227 public void testLongEquality() throws Exception 228 { 229 LongProperty jp1 = new LongProperty("name1",123); 230 LongProperty jp2 = new LongProperty("name1",123); 231 LongProperty jp3 = new LongProperty("name2",-123); 232 LongProperty jp4 = new LongProperty("name2",123); 233 LongProperty jp5 = new LongProperty("name2",Long.MIN_VALUE); 234 LongProperty jp6 = new LongProperty("name2",Long.MIN_VALUE); 235 LongProperty jp7 = new LongProperty("name2",Long.MAX_VALUE); 236 LongProperty jp8 = new LongProperty("name2",Long.MAX_VALUE); 237 LongProperty jp9 = new LongProperty("name1",Long.MIN_VALUE); 238 LongProperty jp10 = new LongProperty("name1",Long.MAX_VALUE); 239 checkEquals(jp1,jp2); 240 checkNotEquals(jp1,jp3); 241 checkNotEquals(jp2,jp3); 242 checkNotEquals(jp3,jp4); 243 checkEquals(jp5,jp6); 244 checkNotEquals(jp3,jp6); 245 checkEquals(jp7,jp8); 246 checkNotEquals(jp4,jp7); 247 checkNotEquals(jp9,jp5); 248 checkNotEquals(jp10,jp7); 249 checkNotEquals(jp9,jp10); 250 try { 251 new LongProperty(null,0L); 252 fail("Should have generated an Illegal Argument Exception"); 253 } catch (IllegalArgumentException e) { } 254 } 255 256 public void testMapEquality() throws Exception 257 { 258 try { 259 new MapProperty(null,null); 260 fail("Should have generated an Illegal Argument Exception"); 261 } catch (IllegalArgumentException e) { } 262 263 } 264 265 public void testNullEquality() throws Exception 266 { 267 NullProperty jpn1 = new NullProperty(); 268 NullProperty jpn2 = new NullProperty(); 269 try { 270 new NullProperty(null); 271 fail("Should have generated an Illegal Argument Exception"); 272 } catch (IllegalArgumentException e) { } 273 NullProperty jp1 = new NullProperty("name1"); 274 NullProperty jp2 = new NullProperty("name1"); 275 NullProperty jp3 = new NullProperty("name2"); 276 NullProperty jp4 = new NullProperty("name2"); 277 checkEquals(jpn1,jpn2); 278 checkNotEquals(jpn1,jp1); 279 checkEquals(jp1,jp2); 280 checkNotEquals(jp1,jp3); 281 checkNotEquals(jp2,jp3); 282 checkEquals(jp3,jp4); 283 } 284 public void testStringEquality() throws Exception 285 { 286 StringProperty jpn1 = new StringProperty(); 287 StringProperty jpn2 = new StringProperty(); 288 StringProperty jp1 = new StringProperty("name1","value1"); 289 StringProperty jp2 = new StringProperty("name1","value1"); 290 StringProperty jp3 = new StringProperty("name2","value1"); 291 StringProperty jp4 = new StringProperty("name2","value2"); 292 StringProperty jp5 = new StringProperty("name1",null); 293 StringProperty jp6 = new StringProperty("name1",null); 294 StringProperty jp7 = new StringProperty("name2",null); 295 checkEquals(jpn1,jpn2); 296 checkNotEquals(jpn1,jp1); 297 checkEquals(jp1,jp2); 298 checkNotEquals(jp1,jp3); 299 checkNotEquals(jp2,jp3); 300 checkNotEquals(jp3,jp4); 301 checkEquals(jp5,jp6); 302 checkNotEquals(jp3,jp5); 303 checkNotEquals(jp6,jp7); 304 try { 305 new StringProperty(null,""); 306 fail("Should have generated an Illegal Argument Exception"); 307 } catch (IllegalArgumentException e) { } 308 try { 309 new StringProperty(null,null); 310 fail("Should have generated an Illegal Argument Exception"); 311 } catch (IllegalArgumentException e) { } 312 313 } 314 } 315 | Popular Tags |