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 Date Convert Function |
37 |
* |
38 |
* @author orim |
39 |
* |
40 |
*/ |
41 |
public class TestDateConvert extends JMeterTestCase { |
42 |
|
43 |
protected AbstractFunction dateConvert; |
44 |
|
45 |
private SampleResult result; |
46 |
|
47 |
private Collection<CompoundVariable> params; |
48 |
|
49 |
private JMeterVariables vars; |
50 |
|
51 |
private JMeterContext jmctx; |
52 |
|
53 |
@Before |
54 |
public void setUp() { |
55 |
dateConvert = new DateConvert(); |
56 |
result = new SampleResult(); |
57 |
jmctx = JMeterContextService.getContext(); |
58 |
String data = "dummy data"; |
59 |
result.setResponseData(data, null); |
60 |
vars = new JMeterVariables(); |
61 |
jmctx.setVariables(vars); |
62 |
jmctx.setPreviousResult(result); |
63 |
params = new LinkedList<>(); |
64 |
} |
65 |
|
66 |
@Test |
67 |
public void testParameterCount512() throws Exception { |
68 |
checkInvalidParameterCounts(dateConvert, 3, 4); |
69 |
} |
70 |
|
71 |
@Test |
72 |
public void testDateConvert() throws Exception { |
73 |
params.add(new CompoundVariable("2017-01-02")); |
74 |
params.add(new CompoundVariable("yyyy-mm-dd")); |
75 |
params.add(new CompoundVariable("dd-mm-yyyy")); |
76 |
dateConvert.setParameters(params); |
77 |
String returnValue = dateConvert.execute(result, null); |
78 |
assertEquals("02-01-2017", returnValue); |
79 |
} |
80 |
|
81 |
@Test |
82 |
public void testDateConvertWithVariable() throws Exception { |
83 |
params.add(new CompoundVariable("2017-01-02")); |
84 |
params.add(new CompoundVariable("yyyy-mm-dd")); |
85 |
params.add(new CompoundVariable("dd-mm-yyyy")); |
86 |
params.add(new CompoundVariable("varName")); |
87 |
dateConvert.setParameters(params); |
88 |
dateConvert.execute(result, null); |
89 |
assertEquals("02-01-2017", vars.get("varName")); |
90 |
} |
91 |
|
92 |
@Test(expected = InvalidVariableException.class) |
93 |
public void testDateConvertError() throws Exception { |
94 |
params.add(new CompoundVariable("2017-01-02")); |
95 |
params.add(new CompoundVariable("yyyy-mm-dd")); |
96 |
dateConvert.setParameters(params); |
97 |
dateConvert.execute(result, null); |
98 |
} |
99 |
|
100 |
public void testDateConvertErrorFormat() throws Exception { |
101 |
params.add(new CompoundVariable("2017-01-02")); |
102 |
params.add(new CompoundVariable("yyyy-mm-dd")); |
103 |
params.add(new CompoundVariable("abcd")); |
104 |
dateConvert.setParameters(params); |
105 |
assertEquals(dateConvert.execute(result, null), null); |
106 |
} |
107 |
} |