001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: *
017: */
018:
019: package org.apache.jmeter.samplers;
020:
021: import java.text.SimpleDateFormat;
022:
023: import org.apache.jmeter.junit.JMeterTestCase;
024:
025: // Extends JMeterTest case because it needs access to JMeter properties
026: public class TestSampleSaveConfiguration extends JMeterTestCase {
027: public TestSampleSaveConfiguration(String name) {
028: super (name);
029: }
030:
031: public void testClone() throws Exception {
032: SampleSaveConfiguration a = new SampleSaveConfiguration();
033: a.setUrl(false);
034: a.setAssertions(true);
035: a.setDefaultDelimiter();
036: a.setDefaultTimeStampFormat();
037: a.setDataType(true);
038: assertFalse(a.saveUrl());
039: assertNotNull(a.getDelimiter());
040: assertTrue(a.saveAssertions());
041: assertTrue(a.saveDataType());
042:
043: // Original and clone should be equal
044: SampleSaveConfiguration cloneA = (SampleSaveConfiguration) a
045: .clone();
046: assertNotSame(a, cloneA);
047: assertEquals(a, cloneA);
048: assertTrue(a.equals(cloneA));
049: assertTrue(cloneA.equals(a));
050: assertEquals(a.hashCode(), cloneA.hashCode());
051:
052: // Change the original
053: a.setUrl(true);
054: assertFalse(a.equals(cloneA));
055: assertFalse(cloneA.equals(a));
056: assertFalse(a.hashCode() == cloneA.hashCode());
057:
058: // Change the original back again
059: a.setUrl(false);
060: assertEquals(a, cloneA);
061: assertTrue(a.equals(cloneA));
062: assertTrue(cloneA.equals(a));
063: assertEquals(a.hashCode(), cloneA.hashCode());
064: }
065:
066: public void testEqualsAndHashCode() throws Exception {
067: SampleSaveConfiguration a = new SampleSaveConfiguration();
068: a.setUrl(false);
069: a.setAssertions(true);
070: a.setDefaultDelimiter();
071: a.setDefaultTimeStampFormat();
072: a.setDataType(true);
073: SampleSaveConfiguration b = new SampleSaveConfiguration();
074: b.setUrl(false);
075: b.setAssertions(true);
076: b.setDefaultDelimiter();
077: b.setDefaultTimeStampFormat();
078: b.setDataType(true);
079:
080: // a and b should be equal
081: assertEquals(a, b);
082: assertTrue(a.equals(b));
083: assertTrue(b.equals(a));
084: assertEquals(a.hashCode(), b.hashCode());
085: assertEquals(a.saveUrl(), b.saveUrl());
086: assertEquals(a.saveAssertions(), b.saveAssertions());
087: assertEquals(a.getDelimiter(), b.getDelimiter());
088: assertEquals(a.saveDataType(), b.saveDataType());
089:
090: a.setAssertions(false);
091: // a and b should not be equal
092: assertFalse(a.equals(b));
093: assertFalse(b.equals(a));
094: assertFalse(a.hashCode() == b.hashCode());
095: assertFalse(a.saveAssertions() == b.saveAssertions());
096: }
097:
098: public void testFalse() throws Exception {
099: SampleSaveConfiguration a = new SampleSaveConfiguration(false);
100: SampleSaveConfiguration b = new SampleSaveConfiguration(false);
101: assertTrue("Hash codes should be equal", a.hashCode() == b
102: .hashCode());
103: assertTrue("Objects should be equal", a.equals(b));
104: assertTrue("Objects should be equal", b.equals(a));
105: }
106:
107: public void testTrue() throws Exception {
108: SampleSaveConfiguration a = new SampleSaveConfiguration(true);
109: SampleSaveConfiguration b = new SampleSaveConfiguration(true);
110: assertTrue("Hash codes should be equal", a.hashCode() == b
111: .hashCode());
112: assertTrue("Objects should be equal", a.equals(b));
113: assertTrue("Objects should be equal", b.equals(a));
114: }
115:
116: public void testFalseTrue() throws Exception {
117: SampleSaveConfiguration a = new SampleSaveConfiguration(false);
118: SampleSaveConfiguration b = new SampleSaveConfiguration(true);
119: assertFalse("Hash codes should not be equal", a.hashCode() == b
120: .hashCode());
121: assertFalse("Objects should not be equal", a.equals(b));
122: assertFalse("Objects should not be equal", b.equals(a));
123: }
124:
125: public void testFormatter() throws Exception {
126: SampleSaveConfiguration a = new SampleSaveConfiguration(false);
127: SampleSaveConfiguration b = new SampleSaveConfiguration(false);
128: a.setFormatter(null);
129: assertTrue("Hash codes should be equal", a.hashCode() == b
130: .hashCode());
131: assertTrue("Objects should be equal", a.equals(b));
132: assertTrue("Objects should be equal", b.equals(a));
133: b.setFormatter(null);
134: assertTrue("Hash codes should be equal", a.hashCode() == b
135: .hashCode());
136: assertTrue("Objects should be equal", a.equals(b));
137: assertTrue("Objects should be equal", b.equals(a));
138: a.setFormatter(new SimpleDateFormat());
139: b.setFormatter(new SimpleDateFormat());
140: assertTrue("Hash codes should be equal", a.hashCode() == b
141: .hashCode());
142: assertTrue("Objects should be equal", a.equals(b));
143: assertTrue("Objects should be equal", b.equals(a));
144: }
145:
146: }
|