Line 0
Link Here
|
|
|
1 |
/* |
2 |
* Licensed to the Apache Software Foundation (ASF) under one or more |
3 |
* contributor license agreements. See the NOTICE file distributed with |
4 |
* this work for additional information regarding copyright ownership. |
5 |
* The ASF licenses this file to You under the Apache License, Version 2.0 |
6 |
* (the "License"); you may not use this file except in compliance with |
7 |
* the License. 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.functions; |
20 |
|
21 |
import static org.junit.Assert.assertEquals; |
22 |
|
23 |
import java.util.Collection; |
24 |
import java.util.LinkedList; |
25 |
|
26 |
import org.apache.jmeter.engine.util.CompoundVariable; |
27 |
import org.apache.jmeter.junit.JMeterTestCase; |
28 |
import org.apache.jmeter.samplers.SampleResult; |
29 |
import org.apache.jmeter.threads.JMeterContext; |
30 |
import org.apache.jmeter.threads.JMeterContextService; |
31 |
import org.apache.jmeter.threads.JMeterVariables; |
32 |
import org.junit.Before; |
33 |
import org.junit.Test; |
34 |
/** |
35 |
* |
36 |
* Test IsPropDefined Function |
37 |
* |
38 |
* @see IsPropDefined |
39 |
* @author orim |
40 |
* |
41 |
*/ |
42 |
|
43 |
public class TestIsPropDefined extends JMeterTestCase { |
44 |
protected AbstractFunction isPropDefined; |
45 |
|
46 |
private SampleResult result; |
47 |
|
48 |
private Collection<CompoundVariable> params; |
49 |
|
50 |
private JMeterVariables vars; |
51 |
|
52 |
private JMeterContext jmctx; |
53 |
|
54 |
@Before |
55 |
public void setUp() { |
56 |
isPropDefined = new IsPropDefined(); |
57 |
result = new SampleResult(); |
58 |
jmctx = JMeterContextService.getContext(); |
59 |
String data = "dummy data"; |
60 |
result.setResponseData(data, null); |
61 |
vars = new JMeterVariables(); |
62 |
jmctx.setVariables(vars); |
63 |
jmctx.setPreviousResult(result); |
64 |
params = new LinkedList<>(); |
65 |
} |
66 |
|
67 |
@Test |
68 |
public void testParameterCountIsPropDefined() throws Exception { |
69 |
checkInvalidParameterCounts(isPropDefined, 1, 1); |
70 |
} |
71 |
|
72 |
@Test |
73 |
public void testIsPropDefined() throws Exception { |
74 |
params.add(new CompoundVariable("file.encoding")); |
75 |
isPropDefined.setParameters(params); |
76 |
String returnValue = isPropDefined.execute(result, null); |
77 |
assertEquals("true", returnValue); |
78 |
} |
79 |
|
80 |
@Test |
81 |
public void testIsPropNotDefined() throws Exception { |
82 |
params.add(new CompoundVariable("emptyProperty")); |
83 |
isPropDefined.setParameters(params); |
84 |
String returnValue = isPropDefined.execute(result, null); |
85 |
assertEquals("false", returnValue); |
86 |
} |
87 |
|
88 |
@Test |
89 |
public void testIsPropNotDefinedOnlyVarDefined() throws Exception { |
90 |
vars.put("emptyProperty", "emptyPropertyValue"); |
91 |
params.add(new CompoundVariable("emptyProperty")); |
92 |
isPropDefined.setParameters(params); |
93 |
String returnValue = isPropDefined.execute(result, null); |
94 |
assertEquals("false", returnValue); |
95 |
} |
96 |
|
97 |
@Test(expected = InvalidVariableException.class) |
98 |
public void testIsPropDefinedError() throws Exception { |
99 |
isPropDefined.setParameters(params); |
100 |
isPropDefined.execute(result, null); |
101 |
} |
102 |
|
103 |
} |