KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > jmeter > engine > util > PackageTest


1 // $Header: /home/cvs/jakarta-jmeter/src/core/org/apache/jmeter/engine/util/PackageTest.java,v 1.6 2004/02/22 19:15:09 sebb 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 /*
20  * Created on Jul 25, 2003
21  */

22 package org.apache.jmeter.engine.util;
23
24 import java.util.HashMap JavaDoc;
25 import java.util.Map JavaDoc;
26
27 import junit.framework.TestCase;
28
29 import org.apache.jmeter.samplers.SampleResult;
30 import org.apache.jmeter.testelement.property.JMeterProperty;
31 import org.apache.jmeter.testelement.property.StringProperty;
32 import org.apache.jmeter.threads.JMeterContext;
33 import org.apache.jmeter.threads.JMeterContextService;
34 import org.apache.jmeter.threads.JMeterVariables;
35
36 public class PackageTest extends TestCase
37 {
38     Map JavaDoc variables;
39     SampleResult result;
40     ReplaceStringWithFunctions transformer;
41     /**
42     * @param arg0
43     */

44     public PackageTest(String JavaDoc arg0)
45     {
46         super(arg0);
47         // TODO Auto-generated constructor stub
48
}
49
50     private JMeterContext jmctx = null;
51     
52     public void setUp()
53     {
54         jmctx =JMeterContextService.getContext();
55         variables = new HashMap JavaDoc();
56         variables.put("my_regex", ".*");
57         variables.put("server", "jakarta.apache.org");
58         result = new SampleResult();
59         result.setResponseData(
60             "<html>hello world</html> costs: $3.47,$5.67".getBytes());
61         transformer =
62             new ReplaceStringWithFunctions(new CompoundVariable(), variables);
63         jmctx.setVariables(new JMeterVariables());
64         jmctx.setSamplingStarted(true);
65         jmctx.setPreviousResult(result);
66         jmctx.getVariables().put(
67             "server",
68             "jakarta.apache.org");
69         jmctx.getVariables().put("my_regex", ".*");
70     }
71
72     public void testFunctionParse1() throws Exception JavaDoc
73     {
74         StringProperty prop =
75             new StringProperty(
76                 "date",
77                 "${__javaScript((new Date().getDate() / 100).toString()."
78                     + "substr(${__javaScript(1+1,d\\,ay)}\\,2),heute)}");
79         JMeterProperty newProp = transformer.transformValue(prop);
80         newProp.setRunningVersion(true);
81         assertEquals(
82             "org.apache.jmeter.testelement.property.FunctionProperty",
83             newProp.getClass().getName());
84         newProp.recoverRunningVersion(null);
85         assertTrue(Integer.parseInt(newProp.getStringValue()) > -1);
86         assertEquals(
87             "2",
88             jmctx.getVariables().getObject("d,ay"));
89     }
90
91     public void testParseExample1() throws Exception JavaDoc
92     {
93         StringProperty prop =
94             new StringProperty(
95                 "html",
96                 "${__regexFunction(<html>(.*)</html>,$1$)}");
97         JMeterProperty newProp = transformer.transformValue(prop);
98         newProp.setRunningVersion(true);
99         assertEquals(
100             "org.apache.jmeter.testelement.property.FunctionProperty",
101             newProp.getClass().getName());
102         assertEquals("hello world", newProp.getStringValue());
103     }
104
105     public void testParseExample2() throws Exception JavaDoc
106     {
107         StringProperty prop =
108             new StringProperty(
109                 "html",
110                 "It should say:\\${${__regexFunction(<html>(.*)</html>,$1$)}}");
111         JMeterProperty newProp = transformer.transformValue(prop);
112         newProp.setRunningVersion(true);
113         assertEquals(
114             "org.apache.jmeter.testelement.property.FunctionProperty",
115             newProp.getClass().getName());
116         assertEquals("It should say:${hello world}", newProp.getStringValue());
117     }
118
119     public void testParseExample3() throws Exception JavaDoc
120     {
121         StringProperty prop =
122             new StringProperty(
123                 "html",
124                 "${__regexFunction(<html>(.*)</html>,$1$)}"
125                     + "${__regexFunction(<html>(.*o)(.*o)(.*)</html>,"
126                     + "$1$$3$)}");
127         JMeterProperty newProp = transformer.transformValue(prop);
128         newProp.setRunningVersion(true);
129         assertEquals(
130             "org.apache.jmeter.testelement.property.FunctionProperty",
131             newProp.getClass().getName());
132         assertEquals("hello worldhellorld", newProp.getStringValue());
133     }
134
135     public void testParseExample4() throws Exception JavaDoc
136     {
137         StringProperty prop =
138             new StringProperty("html", "${non-existing function}");
139         JMeterProperty newProp = transformer.transformValue(prop);
140         newProp.setRunningVersion(true);
141         assertEquals(
142             "org.apache.jmeter.testelement.property.FunctionProperty",
143             newProp.getClass().getName());
144         assertEquals("${non-existing function}", newProp.getStringValue());
145     }
146
147     public void testParseExample6() throws Exception JavaDoc
148     {
149         StringProperty prop = new StringProperty("html", "${server}");
150         JMeterProperty newProp = transformer.transformValue(prop);
151         newProp.setRunningVersion(true);
152         assertEquals(
153             "org.apache.jmeter.testelement.property.FunctionProperty",
154             newProp.getClass().getName());
155         assertEquals("jakarta.apache.org", newProp.getStringValue());
156     }
157
158     public void testParseExample5() throws Exception JavaDoc
159     {
160         StringProperty prop = new StringProperty("html", "");
161         JMeterProperty newProp = transformer.transformValue(prop);
162         newProp.setRunningVersion(true);
163         assertEquals(
164             "org.apache.jmeter.testelement.property.StringProperty",
165             newProp.getClass().getName());
166         assertEquals("", newProp.getStringValue());
167     }
168
169     public void testParseExample7() throws Exception JavaDoc
170     {
171         StringProperty prop =
172             new StringProperty(
173                 "html",
174                 "${__regexFunction(\\<([a-z]*)\\>,$1$)}");
175         JMeterProperty newProp = transformer.transformValue(prop);
176         newProp.setRunningVersion(true);
177         assertEquals(
178             "org.apache.jmeter.testelement.property.FunctionProperty",
179             newProp.getClass().getName());
180         assertEquals("html", newProp.getStringValue());
181     }
182
183     public void testParseExample8() throws Exception JavaDoc
184     {
185         StringProperty prop =
186             new StringProperty(
187                 "html",
188                 "${__regexFunction((\\\\$\\d+\\.\\d+),$1$)}");
189         JMeterProperty newProp = transformer.transformValue(prop);
190         newProp.setRunningVersion(true);
191         assertEquals(
192             "org.apache.jmeter.testelement.property.FunctionProperty",
193             newProp.getClass().getName());
194         assertEquals("$3.47", newProp.getStringValue());
195     }
196
197     public void testParseExample9() throws Exception JavaDoc
198     {
199         StringProperty prop =
200             new StringProperty(
201                 "html",
202                 "${__regexFunction(([$]\\d+\\.\\d+),$1$)}");
203         JMeterProperty newProp = transformer.transformValue(prop);
204         newProp.setRunningVersion(true);
205         assertEquals(
206             "org.apache.jmeter.testelement.property.FunctionProperty",
207             newProp.getClass().getName());
208         assertEquals("$3.47", newProp.getStringValue());
209     }
210
211     public void testParseExample10() throws Exception JavaDoc
212     {
213         StringProperty prop =
214             new StringProperty(
215                 "html",
216                 "${__regexFunction(\\ "
217                     + "(\\\\\\$\\d+\\.\\d+\\,\\\\$\\d+\\.\\d+),$1$)}");
218         JMeterProperty newProp = transformer.transformValue(prop);
219         newProp.setRunningVersion(true);
220         assertEquals(
221             "org.apache.jmeter.testelement.property.FunctionProperty",
222             newProp.getClass().getName());
223         assertEquals("$3.47,$5.67", newProp.getStringValue());
224     }
225
226     public void testNestedExample1() throws Exception JavaDoc
227     {
228         StringProperty prop =
229             new StringProperty(
230                 "html",
231                 "${__regexFunction(<html>(${my_regex})</html>,"
232                     + "$1$)}${__regexFunction(<html>(.*o)(.*o)(.*)"
233                     + "</html>,$1$$3$)}");
234         JMeterProperty newProp = transformer.transformValue(prop);
235         newProp.setRunningVersion(true);
236         assertEquals(
237             "org.apache.jmeter.testelement.property.FunctionProperty",
238             newProp.getClass().getName());
239         assertEquals("hello worldhellorld", newProp.getStringValue());
240     }
241
242     public void testNestedExample2() throws Exception JavaDoc
243     {
244         StringProperty prop =
245             new StringProperty(
246                 "html",
247                 "${__regexFunction(<html>(${my_regex})</html>,$1$)}");
248         JMeterProperty newProp = transformer.transformValue(prop);
249         newProp.setRunningVersion(true);
250         assertEquals(
251             "org.apache.jmeter.testelement.property.FunctionProperty",
252             newProp.getClass().getName());
253         assertEquals("hello world", newProp.getStringValue());
254     }
255
256 }
257
Popular Tags