01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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: * Package to test FileServer methods
21: */package org.apache.jmeter.config;
22:
23: import java.io.IOException;
24:
25: import org.apache.jmeter.junit.JMeterTestCase;
26: import org.apache.jmeter.services.FileServer;
27: import org.apache.jmeter.threads.JMeterContext;
28: import org.apache.jmeter.threads.JMeterContextService;
29: import org.apache.jmeter.threads.JMeterVariables;
30:
31: public class TestCVSDataSet extends JMeterTestCase {
32:
33: public TestCVSDataSet() {
34: super ();
35: }
36:
37: public TestCVSDataSet(String arg0) {
38: super (arg0);
39: }
40:
41: public void tearDown() throws IOException {
42: FileServer.getFileServer().closeFiles();
43: }
44:
45: public void testopen() throws Exception {
46: JMeterContext jmcx = JMeterContextService.getContext();
47: jmcx.setVariables(new JMeterVariables());
48: JMeterVariables threadVars = jmcx.getVariables();
49: threadVars.put("b", "value");
50:
51: CSVDataSet csv = new CSVDataSet();
52: csv.setFilename("No.such.filename");
53: csv.setVariableNames("a,b,c");
54: csv.setDelimiter(",");
55: csv.iterationStart(null);
56: assertNull(threadVars.get("a"));
57: assertEquals("value", threadVars.get("b"));
58: assertNull(threadVars.get("c"));
59:
60: csv = new CSVDataSet();
61: csv.setFilename("testfiles/testempty.csv");
62: csv.setVariableNames("a,b,c");
63: csv.setDelimiter(",");
64:
65: csv.iterationStart(null);
66: assertEquals("", threadVars.get("a"));
67: assertEquals("b1", threadVars.get("b"));
68: assertEquals("c1", threadVars.get("c"));
69:
70: csv.iterationStart(null);
71: assertEquals("a2", threadVars.get("a"));
72: assertEquals("", threadVars.get("b"));
73: assertEquals("c2", threadVars.get("c"));
74:
75: csv.iterationStart(null);
76: assertEquals("a3", threadVars.get("a"));
77: assertEquals("b3", threadVars.get("b"));
78: assertEquals("", threadVars.get("c"));
79:
80: csv.iterationStart(null);
81: assertEquals("a4", threadVars.get("a"));
82: assertEquals("b4", threadVars.get("b"));
83: assertEquals("c4", threadVars.get("c"));
84:
85: csv.iterationStart(null); // Restart file
86: assertEquals("", threadVars.get("a"));
87: assertEquals("b1", threadVars.get("b"));
88: assertEquals("c1", threadVars.get("c"));
89: }
90: }
|