Save This Page
Home » jakarta-jmeter-2.3.4_src » org.apache.jmeter.testelement.property » [javadoc | source]
    1   // $Header: /home/cvs/jakarta-jmeter/src/core/org/apache/jmeter/testelement/property/PackageTest.java,v 1.4 2005/07/12 20:50:25 mstover1 Exp $
    2   /*
    3    * Copyright 2003-2004 The Apache Software Foundation.
    4    *
    5    * Licensed under the Apache License, Version 2.0 (the "License");
    6    * you may not use this file except in compliance with the License.
    7    * You may obtain a copy of the License at
    8    *
    9    *   http://www.apache.org/licenses/LICENSE-2.0
   10    *
   11    * Unless required by applicable law or agreed to in writing, software
   12    * distributed under the License is distributed on an "AS IS" BASIS,
   13    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   14    * See the License for the specific language governing permissions and
   15    * limitations under the License.
   16    * 
   17    */
   18   
   19   package org.apache.jmeter.testelement.property;
   20   
   21   import junit.framework.TestCase;
   22   
   23   import org.apache.jmeter.config.LoginConfig;
   24   
   25   /**
   26    * Class for testing the property package.
   27    */
   28   public class PackageTest extends TestCase {
   29   
   30   	public PackageTest(String name) {
   31   		super(name);
   32   	}
   33   
   34   	public void testStringProperty() throws Exception {
   35   		StringProperty prop = new StringProperty("name", "value");
   36   		prop.setRunningVersion(true);
   37   		prop.setObjectValue("new Value");
   38   		assertEquals("new Value", prop.getStringValue());
   39   		prop.recoverRunningVersion(null);
   40   		assertEquals("value", prop.getStringValue());
   41   		prop.setObjectValue("new Value");
   42   		prop.setObjectValue("2nd Value");
   43   		assertEquals("2nd Value", prop.getStringValue());
   44   		prop.recoverRunningVersion(null);
   45   		assertEquals("value", prop.getStringValue());
   46   	}
   47   
   48   	public void testElementProperty() throws Exception {
   49   		LoginConfig config = new LoginConfig();
   50   		config.setUsername("username");
   51   		config.setPassword("password");
   52   		TestElementProperty prop = new TestElementProperty("name", config);
   53   		prop.setRunningVersion(true);
   54   		config = new LoginConfig();
   55   		config.setUsername("user2");
   56   		config.setPassword("pass2");
   57   		prop.setObjectValue(config);
   58   		assertEquals("user2=pass2", prop.getStringValue());
   59   		prop.recoverRunningVersion(null);
   60   		assertEquals("username=password", prop.getStringValue());
   61   		config = new LoginConfig();
   62   		config.setUsername("user2");
   63   		config.setPassword("pass2");
   64   		prop.setObjectValue(config);
   65   		config = new LoginConfig();
   66   		config.setUsername("user3");
   67   		config.setPassword("pass3");
   68   		prop.setObjectValue(config);
   69   		assertEquals("user3=pass3", prop.getStringValue());
   70   		prop.recoverRunningVersion(null);
   71   		assertEquals("username=password", prop.getStringValue());
   72   	}
   73   
   74   	private void checkEquals(JMeterProperty jp1, JMeterProperty jp2) {
   75   		assertEquals(jp1, jp2);
   76   		assertEquals(jp2, jp1);
   77   		assertEquals(jp1, jp1);
   78   		assertEquals(jp2, jp2);
   79   		assertEquals(jp1.hashCode(), jp2.hashCode());
   80   
   81   	}
   82   
   83   	private void checkNotEquals(JMeterProperty jp1, JMeterProperty jp2) {
   84   		assertEquals(jp1, jp1);
   85   		assertEquals(jp2, jp2);
   86   		assertFalse(jp1.equals(jp2));
   87   		assertFalse(jp2.equals(jp1));
   88   		// Not an absolute requirement:
   89   		if (jp1.hashCode() == jp2.hashCode()) {
   90   			System.out.println("Expected different hashCodes for " + jp1.getClass().getName());
   91   
   92   		}
   93   
   94   	}
   95   
   96   	public void testBooleanEquality() throws Exception {
   97   		BooleanProperty jpn1 = new BooleanProperty();
   98   		BooleanProperty jpn2 = new BooleanProperty();
   99   		BooleanProperty jp1 = new BooleanProperty("name1", true);
  100   		BooleanProperty jp2 = new BooleanProperty("name1", true);
  101   		BooleanProperty jp3 = new BooleanProperty("name2", true);
  102   		BooleanProperty jp4 = new BooleanProperty("name2", false);
  103   		checkEquals(jpn1, jpn2);
  104   		checkNotEquals(jpn1, jp1);
  105   		checkNotEquals(jpn1, jp2);
  106   		checkEquals(jp1, jp2);
  107   		checkNotEquals(jp1, jp3);
  108   		checkNotEquals(jp2, jp3);
  109   		checkNotEquals(jp3, jp4);
  110   	}
  111   
  112   	public void testDoubleEquality() throws Exception {
  113   		DoubleProperty jpn1 = new DoubleProperty();
  114   		DoubleProperty jpn2 = new DoubleProperty();
  115   		DoubleProperty jp1 = new DoubleProperty("name1", 123.4);
  116   		DoubleProperty jp2 = new DoubleProperty("name1", 123.4);
  117   		DoubleProperty jp3 = new DoubleProperty("name2", -123.4);
  118   		DoubleProperty jp4 = new DoubleProperty("name2", 123.4);
  119   		DoubleProperty jp5 = new DoubleProperty("name2", Double.NEGATIVE_INFINITY);
  120   		DoubleProperty jp6 = new DoubleProperty("name2", Double.NEGATIVE_INFINITY);
  121   		DoubleProperty jp7 = new DoubleProperty("name2", Double.POSITIVE_INFINITY);
  122   		DoubleProperty jp8 = new DoubleProperty("name2", Double.POSITIVE_INFINITY);
  123   		DoubleProperty jp9 = new DoubleProperty("name2", Double.NaN);
  124   		DoubleProperty jp10 = new DoubleProperty("name2", Double.NaN);
  125   		DoubleProperty jp11 = new DoubleProperty("name1", Double.NaN);
  126   		DoubleProperty jp12 = new DoubleProperty("name1", Double.MIN_VALUE);
  127   		DoubleProperty jp13 = new DoubleProperty("name2", Double.MIN_VALUE);
  128   		DoubleProperty jp14 = new DoubleProperty("name2", Double.MIN_VALUE);
  129   		DoubleProperty jp15 = new DoubleProperty("name1", Double.MAX_VALUE);
  130   		DoubleProperty jp16 = new DoubleProperty("name2", Double.MAX_VALUE);
  131   		DoubleProperty jp17 = new DoubleProperty("name2", Double.MAX_VALUE);
  132   		checkEquals(jpn1, jpn2);
  133   		checkNotEquals(jpn1, jp1);
  134   		checkNotEquals(jpn1, jp2);
  135   		checkEquals(jp1, jp2);
  136   		checkNotEquals(jp1, jp3);
  137   		checkNotEquals(jp2, jp3);
  138   		checkNotEquals(jp3, jp4);
  139   		checkEquals(jp5, jp6);
  140   		checkNotEquals(jp3, jp6);
  141   		checkEquals(jp7, jp8);
  142   		checkNotEquals(jp4, jp7);
  143   		checkNotEquals(jp8, jp9);
  144   		checkEquals(jp9, jp10);
  145   		checkNotEquals(jp10, jp11);
  146   		checkNotEquals(jp5, jp10);
  147   		checkNotEquals(jp12, jp14);
  148   		checkEquals(jp13, jp14);
  149   		checkNotEquals(jp15, jp16);
  150   		checkEquals(jp16, jp17);
  151   	}
  152   
  153   	public void testFloatEquality() throws Exception {
  154   		FloatProperty jp1 = new FloatProperty("name1", 123.4f);
  155   		FloatProperty jp2 = new FloatProperty("name1", 123.4f);
  156   		FloatProperty jp3 = new FloatProperty("name2", -123.4f);
  157   		FloatProperty jp4 = new FloatProperty("name2", 123.4f);
  158   		FloatProperty jp5 = new FloatProperty("name2", Float.NEGATIVE_INFINITY);
  159   		FloatProperty jp6 = new FloatProperty("name2", Float.NEGATIVE_INFINITY);
  160   		FloatProperty jp7 = new FloatProperty("name2", Float.POSITIVE_INFINITY);
  161   		FloatProperty jp8 = new FloatProperty("name2", Float.POSITIVE_INFINITY);
  162   		FloatProperty jp9 = new FloatProperty("name2", Float.NaN);
  163   		FloatProperty jp10 = new FloatProperty("name2", Float.NaN);
  164   		FloatProperty jp11 = new FloatProperty("name1", Float.NaN);
  165   		FloatProperty jp12 = new FloatProperty("name1", Float.MIN_VALUE);
  166   		FloatProperty jp13 = new FloatProperty("name2", Float.MIN_VALUE);
  167   		FloatProperty jp14 = new FloatProperty("name2", Float.MIN_VALUE);
  168   		FloatProperty jp15 = new FloatProperty("name1", Float.MAX_VALUE);
  169   		FloatProperty jp16 = new FloatProperty("name2", Float.MAX_VALUE);
  170   		FloatProperty jp17 = new FloatProperty("name2", Float.MAX_VALUE);
  171   		checkEquals(jp1, jp2);
  172   		checkNotEquals(jp1, jp3);
  173   		checkNotEquals(jp2, jp3);
  174   		checkNotEquals(jp3, jp4);
  175   		checkEquals(jp5, jp6);
  176   		checkNotEquals(jp3, jp6);
  177   		checkEquals(jp7, jp8);
  178   		checkNotEquals(jp4, jp7);
  179   		checkNotEquals(jp8, jp9);
  180   		checkEquals(jp9, jp10);
  181   		checkNotEquals(jp10, jp11);
  182   		checkNotEquals(jp5, jp10);
  183   		checkNotEquals(jp12, jp14);
  184   		checkEquals(jp13, jp14);
  185   		checkNotEquals(jp15, jp16);
  186   		checkEquals(jp16, jp17);
  187   	}
  188   
  189   	public void testIntegerEquality() throws Exception {
  190   		IntegerProperty jp1 = new IntegerProperty("name1", 123);
  191   		IntegerProperty jp2 = new IntegerProperty("name1", 123);
  192   		IntegerProperty jp3 = new IntegerProperty("name2", -123);
  193   		IntegerProperty jp4 = new IntegerProperty("name2", 123);
  194   		IntegerProperty jp5 = new IntegerProperty("name2", Integer.MIN_VALUE);
  195   		IntegerProperty jp6 = new IntegerProperty("name2", Integer.MIN_VALUE);
  196   		IntegerProperty jp7 = new IntegerProperty("name2", Integer.MAX_VALUE);
  197   		IntegerProperty jp8 = new IntegerProperty("name2", Integer.MAX_VALUE);
  198   		IntegerProperty jp9 = new IntegerProperty("name1", Integer.MIN_VALUE);
  199   		IntegerProperty jp10 = new IntegerProperty("name1", Integer.MAX_VALUE);
  200   		checkEquals(jp1, jp2);
  201   		checkNotEquals(jp1, jp3);
  202   		checkNotEquals(jp2, jp3);
  203   		checkNotEquals(jp3, jp4);
  204   		checkEquals(jp5, jp6);
  205   		checkNotEquals(jp3, jp6);
  206   		checkEquals(jp7, jp8);
  207   		checkNotEquals(jp4, jp7);
  208   		checkNotEquals(jp9, jp5);
  209   		checkNotEquals(jp10, jp7);
  210   		checkNotEquals(jp9, jp10);
  211   		try {
  212   			new IntegerProperty(null);
  213   			fail("Should have generated an Illegal Argument Exception");
  214   		} catch (IllegalArgumentException e) {
  215   		}
  216   		try {
  217   			new IntegerProperty(null, 0);
  218   			fail("Should have generated an Illegal Argument Exception");
  219   		} catch (IllegalArgumentException e) {
  220   		}
  221   	}
  222   
  223   	public void testLongEquality() throws Exception {
  224   		LongProperty jp1 = new LongProperty("name1", 123);
  225   		LongProperty jp2 = new LongProperty("name1", 123);
  226   		LongProperty jp3 = new LongProperty("name2", -123);
  227   		LongProperty jp4 = new LongProperty("name2", 123);
  228   		LongProperty jp5 = new LongProperty("name2", Long.MIN_VALUE);
  229   		LongProperty jp6 = new LongProperty("name2", Long.MIN_VALUE);
  230   		LongProperty jp7 = new LongProperty("name2", Long.MAX_VALUE);
  231   		LongProperty jp8 = new LongProperty("name2", Long.MAX_VALUE);
  232   		LongProperty jp9 = new LongProperty("name1", Long.MIN_VALUE);
  233   		LongProperty jp10 = new LongProperty("name1", Long.MAX_VALUE);
  234   		checkEquals(jp1, jp2);
  235   		checkNotEquals(jp1, jp3);
  236   		checkNotEquals(jp2, jp3);
  237   		checkNotEquals(jp3, jp4);
  238   		checkEquals(jp5, jp6);
  239   		checkNotEquals(jp3, jp6);
  240   		checkEquals(jp7, jp8);
  241   		checkNotEquals(jp4, jp7);
  242   		checkNotEquals(jp9, jp5);
  243   		checkNotEquals(jp10, jp7);
  244   		checkNotEquals(jp9, jp10);
  245   		try {
  246   			new LongProperty(null, 0L);
  247   			fail("Should have generated an Illegal Argument Exception");
  248   		} catch (IllegalArgumentException e) {
  249   		}
  250   	}
  251   
  252   	public void testMapEquality() throws Exception {
  253   		try {
  254   			new MapProperty(null, null);
  255   			fail("Should have generated an Illegal Argument Exception");
  256   		} catch (IllegalArgumentException e) {
  257   		}
  258   
  259   	}
  260   
  261   	public void testNullEquality() throws Exception {
  262   		NullProperty jpn1 = new NullProperty();
  263   		NullProperty jpn2 = new NullProperty();
  264   		try {
  265   			new NullProperty(null);
  266   			fail("Should have generated an Illegal Argument Exception");
  267   		} catch (IllegalArgumentException e) {
  268   		}
  269   		NullProperty jp1 = new NullProperty("name1");
  270   		NullProperty jp2 = new NullProperty("name1");
  271   		NullProperty jp3 = new NullProperty("name2");
  272   		NullProperty jp4 = new NullProperty("name2");
  273   		checkEquals(jpn1, jpn2);
  274   		checkNotEquals(jpn1, jp1);
  275   		checkEquals(jp1, jp2);
  276   		checkNotEquals(jp1, jp3);
  277   		checkNotEquals(jp2, jp3);
  278   		checkEquals(jp3, jp4);
  279   	}
  280   
  281   	public void testStringEquality() throws Exception {
  282   		StringProperty jpn1 = new StringProperty();
  283   		StringProperty jpn2 = new StringProperty();
  284   		StringProperty jp1 = new StringProperty("name1", "value1");
  285   		StringProperty jp2 = new StringProperty("name1", "value1");
  286   		StringProperty jp3 = new StringProperty("name2", "value1");
  287   		StringProperty jp4 = new StringProperty("name2", "value2");
  288   		StringProperty jp5 = new StringProperty("name1", null);
  289   		StringProperty jp6 = new StringProperty("name1", null);
  290   		StringProperty jp7 = new StringProperty("name2", null);
  291   		checkEquals(jpn1, jpn2);
  292   		checkNotEquals(jpn1, jp1);
  293   		checkEquals(jp1, jp2);
  294   		checkNotEquals(jp1, jp3);
  295   		checkNotEquals(jp2, jp3);
  296   		checkNotEquals(jp3, jp4);
  297   		checkEquals(jp5, jp6);
  298   		checkNotEquals(jp3, jp5);
  299   		checkNotEquals(jp6, jp7);
  300   		try {
  301   			new StringProperty(null, "");
  302   			fail("Should have generated an Illegal Argument Exception");
  303   		} catch (IllegalArgumentException e) {
  304   		}
  305   		try {
  306   			new StringProperty(null, null);
  307   			fail("Should have generated an Illegal Argument Exception");
  308   		} catch (IllegalArgumentException e) {
  309   		}
  310   
  311   	}
  312   }

Save This Page
Home » jakarta-jmeter-2.3.4_src » org.apache.jmeter.testelement.property » [javadoc | source]