View | Details | Raw Unified | Return to bug 55099
Collapse All | Expand All

(-)src/core/org/apache/jmeter/reporters/ResultSaver.java (+5 lines)
Lines 185-190 Link Here
185
        File out = new File(fileName);
185
        File out = new File(fileName);
186
        FileOutputStream pw = null;
186
        FileOutputStream pw = null;
187
        try {
187
        try {
188
            File parent = out.getParentFile();
189
            if (parent != null && !parent.exists()) {
190
                log.debug("create parent directories");
191
                parent.mkdirs(); 
192
            }
188
            pw = new FileOutputStream(out);
193
            pw = new FileOutputStream(out);
189
            JOrphanUtils.write(s.getResponseData(), pw); // chunk the output if necessary
194
            JOrphanUtils.write(s.getResponseData(), pw); // chunk the output if necessary
190
        } catch (FileNotFoundException e1) {
195
        } catch (FileNotFoundException e1) {
(-)test/src/org/apache/jmeter/reporters/ResultSaverTest.java (+64 lines)
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.reporters;
20
21
import java.io.File;
22
23
import org.apache.jmeter.junit.JMeterTestCase;
24
import org.apache.jmeter.samplers.SampleEvent;
25
import org.apache.jmeter.samplers.SampleResult;
26
import org.junit.Test;
27
28
public class ResultSaverTest extends JMeterTestCase {
29
30
    @Test
31
    public void testSampleOccurred() {
32
        SampleResult sampleResult = new SampleResult();
33
        sampleResult.setResultFileName("testcase");
34
        sampleResult.setContentType("text/html");
35
        SampleEvent event = new SampleEvent(sampleResult, "");
36
        
37
        ResultSaver resultSaver = new ResultSaver("test case");
38
        resultSaver.clear();
39
40
        // save a new file with default parameters
41
        resultSaver.sampleOccurred(event);
42
        
43
        // save a new file in a new directory - no suffix, no auto_number
44
        resultSaver.setProperty(ResultSaver.FILENAME, "resultsavertestdirectory/mytestfile.txt");
45
        resultSaver.setProperty(ResultSaver.SKIP_AUTO_NUMBER, true);
46
        resultSaver.setProperty(ResultSaver.SKIP_SUFFIX, true);
47
        resultSaver.setProperty(ResultSaver.ADD_TIMESTAMP, false);
48
        
49
        resultSaver.sampleOccurred(event);
50
        assertTrue(new File("resultsavertestdirectory/mytestfile.txt").exists());
51
        
52
        // save a new file in an existing directory
53
        resultSaver.setProperty(ResultSaver.FILENAME, "resultsavertestdirectory/mytestfile2.txt");
54
        resultSaver.sampleOccurred(event);
55
        assertTrue(new File("resultsavertestdirectory/mytestfile2.txt").exists());
56
57
        // save a new file 
58
        resultSaver.setProperty(ResultSaver.FILENAME, "resultsavertestdirectory/anotherlevel/mytestfile3.txt");
59
        resultSaver.sampleOccurred(event);
60
        assertTrue(new File("resultsavertestdirectory/anotherlevel/mytestfile3.txt").exists());
61
        
62
    }
63
64
}

Return to bug 55099