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

(-)bin/jmeter.properties (+7 lines)
Lines 208-213 Link Here
208
208
209
209
210
#---------------------------------------------------------------------------
210
#---------------------------------------------------------------------------
211
# JMX Save automatically before run
212
#---------------------------------------------------------------------------
213
#Enable auto saving of the .jmx file before start run a test plan
214
#When enabled, before the run the .jmx will be saved and also backed up to the directory pointed
215
save_automatically_before_run=false
216
217
#---------------------------------------------------------------------------
211
# JMX Backup configuration
218
# JMX Backup configuration
212
#---------------------------------------------------------------------------
219
#---------------------------------------------------------------------------
213
#Enable auto backups of the .jmx file when a test plan is saved.
220
#Enable auto backups of the .jmx file when a test plan is saved.
(-)src/core/org/apache/jmeter/gui/action/AbstractAction.java (-14 / +15 lines)
Lines 22-29 Link Here
22
import java.io.File;
22
import java.io.File;
23
import java.text.MessageFormat;
23
import java.text.MessageFormat;
24
import java.util.Iterator;
24
import java.util.Iterator;
25
import java.util.Set;
26
27
import javax.swing.JOptionPane;
25
import javax.swing.JOptionPane;
28
26
29
import org.apache.jmeter.exceptions.IllegalUserActionException;
27
import org.apache.jmeter.exceptions.IllegalUserActionException;
Lines 50-55 Link Here
50
                            "resultcollector.action_if_file_exists", 
48
                            "resultcollector.action_if_file_exists", 
51
                            ActionOnFile.ASK.name()));
49
                            ActionOnFile.ASK.name()));
52
    
50
    
51
    private static final String SAVE_BEFORE_RUN = "save_automatically_before_run"; // $NON-NLS-1$
52
    
53
    /**
53
    /**
54
     * @see Command#doAction(ActionEvent)
54
     * @see Command#doAction(ActionEvent)
55
     */
55
     */
Lines 58-77 Link Here
58
    }
58
    }
59
59
60
    /**
60
    /**
61
     * check if should save before run
61
     * @param e the event that led to the call of this method
62
     * @param e the event that led to the call of this method
62
     */
63
     */
63
    protected void popupShouldSave(ActionEvent e) {
64
	protected void popupShouldSave(ActionEvent e) {
64
        log.debug("popupShouldSave");
65
		log.debug("popupShouldSave");
65
        if (GuiPackage.getInstance().getTestPlanFile() == null) {
66
		if (GuiPackage.getInstance().getTestPlanFile() == null) {
66
            if (JOptionPane.showConfirmDialog(GuiPackage.getInstance().getMainFrame(),
67
			if (JOptionPane.showConfirmDialog(GuiPackage.getInstance().getMainFrame(), JMeterUtils.getResString("should_save"), //$NON-NLS-1$
67
                    JMeterUtils.getResString("should_save"),  //$NON-NLS-1$
68
					JMeterUtils.getResString("warning"), //$NON-NLS-1$
68
                    JMeterUtils.getResString("warning"),  //$NON-NLS-1$
69
					JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE) == JOptionPane.YES_OPTION) {
69
                    JOptionPane.YES_NO_OPTION,
70
				ActionRouter.getInstance().doActionNow(new ActionEvent(e.getSource(), e.getID(), ActionNames.SAVE));
70
                    JOptionPane.QUESTION_MESSAGE) == JOptionPane.YES_OPTION) {
71
			}
71
                ActionRouter.getInstance().doActionNow(new ActionEvent(e.getSource(), e.getID(),ActionNames.SAVE));
72
		} else if (JMeterUtils.getPropDefault(SAVE_BEFORE_RUN, false)) {
72
            }
73
			ActionRouter.getInstance().doActionNow(new ActionEvent(e.getSource(), e.getID(), ActionNames.SAVE));
73
        }
74
		}
74
    }
75
	}
75
    
76
    
76
    /**
77
    /**
77
     * @param tree where check if listener has existing file
78
     * @param tree where check if listener has existing file
(-)src/core/org/apache/jmeter/gui/action/ActionNames.java (+1 lines)
Lines 108-113 Link Here
108
    public static final String VALIDATE_TG      = "validate_tg"; //$NON-NLS-1$
108
    public static final String VALIDATE_TG      = "validate_tg"; //$NON-NLS-1$
109
    public static final String ZOOM_IN          = "zoom_in"; //$NON-NLS-1$
109
    public static final String ZOOM_IN          = "zoom_in"; //$NON-NLS-1$
110
    public static final String ZOOM_OUT         = "zoom_out"; //$NON-NLS-1$
110
    public static final String ZOOM_OUT         = "zoom_out"; //$NON-NLS-1$
111
    public static final String SAVE_BEFORE_RUN         = "save_before_run"; //$NON-NLS-1$
111
112
112
    // Prevent instantiation
113
    // Prevent instantiation
113
    private ActionNames() {}
114
    private ActionNames() {}
(-)src/core/org/apache/jmeter/gui/action/SaveBeforeRun.java (+55 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.gui.action;
20
21
import java.awt.event.ActionEvent;
22
import java.util.HashSet;
23
import java.util.Set;
24
import org.apache.jmeter.util.JMeterUtils;
25
/**
26
 * 
27
 * Save Before Run Action
28
 * 
29
 * To save test plan before GUI execution
30
 * 
31
 * @author orim
32
 *
33
 */
34
public class SaveBeforeRun extends AbstractAction {
35
	private static final Set<String> commands = new HashSet<>();
36
	private static final String SAVE_BEFORE_RUN = "save_automatically_before_run"; // $NON-NLS-1$
37
38
	static {
39
		commands.add(ActionNames.SAVE_BEFORE_RUN);
40
	}
41
42
	@Override
43
	public Set<String> getActionNames() {
44
		return commands;
45
	}
46
47
	@Override
48
	public void doAction(ActionEvent e) {
49
		if (ActionNames.SAVE_BEFORE_RUN.equals(e.getActionCommand())) {
50
			boolean saveBeforeRunPropertyBefore = JMeterUtils.getPropDefault(SAVE_BEFORE_RUN, false);
51
			// toggle boolean property value
52
			JMeterUtils.setProperty(SAVE_BEFORE_RUN, saveBeforeRunPropertyBefore ? " false" : "true");
53
		}
54
	}
55
}
(-)src/core/org/apache/jmeter/gui/util/JMeterMenuBar.java (-1 / +6 lines)
Lines 369-375 Link Here
369
        JMenuItem zoomIn = makeMenuItemRes("menu_zoom_in", ActionNames.ZOOM_IN); //$NON-NLS-1$
369
        JMenuItem zoomIn = makeMenuItemRes("menu_zoom_in", ActionNames.ZOOM_IN); //$NON-NLS-1$
370
        optionsMenu.add(zoomIn);
370
        optionsMenu.add(zoomIn);
371
        JMenuItem zoomOut = makeMenuItemRes("menu_zoom_out", ActionNames.ZOOM_OUT); //$NON-NLS-1$
371
        JMenuItem zoomOut = makeMenuItemRes("menu_zoom_out", ActionNames.ZOOM_OUT); //$NON-NLS-1$
372
        optionsMenu.add(zoomOut);
372
        optionsMenu.add(zoomOut);        
373
        JCheckBoxMenuItem saveBeforeRun = makeCheckBoxMenuItemRes("menu_save_before_run", ActionNames.SAVE_BEFORE_RUN); //$NON-NLS-1$        
374
        if (guiInstance != null) {
375
            guiInstance.setMenuItemLoggerPanel(saveBeforeRun);
376
        }
377
        optionsMenu.add(saveBeforeRun);
373
378
374
        addPluginsMenuItems(optionsMenu, menuCreators, MENU_LOCATION.OPTIONS);
379
        addPluginsMenuItems(optionsMenu, menuCreators, MENU_LOCATION.OPTIONS);
375
    }
380
    }
(-)src/core/org/apache/jmeter/resources/messages.properties (+1 lines)
Lines 689-694 Link Here
689
menu_pre_processors=Pre Processors
689
menu_pre_processors=Pre Processors
690
menu_recent=Open Recent
690
menu_recent=Open Recent
691
menu_response_based_modifiers=Response Based Modifiers
691
menu_response_based_modifiers=Response Based Modifiers
692
menu_save_before_run=Save Automatically Before Run
692
menu_search=Search
693
menu_search=Search
693
menu_search_reset=Reset Search
694
menu_search_reset=Reset Search
694
menu_tables=Table
695
menu_tables=Table
(-)test/src/org/apache/jmeter/functions/TestDigestFunction.java (+124 lines)
Line 0 Link Here
1
package org.apache.jmeter.functions;
2
3
import static org.junit.Assert.assertEquals;
4
5
import java.util.Collection;
6
import java.util.LinkedList;
7
8
import org.apache.jmeter.engine.util.CompoundVariable;
9
import org.apache.jmeter.junit.JMeterTestCase;
10
import org.apache.jmeter.samplers.SampleResult;
11
import org.apache.jmeter.threads.JMeterContext;
12
import org.apache.jmeter.threads.JMeterContextService;
13
import org.apache.jmeter.threads.JMeterVariables;
14
import org.junit.Before;
15
import org.junit.Test;
16
/**
17
 * Test Digest function
18
 * 
19
 * Add Tests with Sha1 and Sha512
20
 * 
21
 * @author orim
22
 *
23
 */
24
public class TestDigestFunction extends JMeterTestCase {
25
	protected AbstractFunction digest;	
26
27
    private SampleResult result;
28
29
    private Collection<CompoundVariable> params;
30
31
    private JMeterVariables vars;
32
33
    private JMeterContext jmctx;
34
35
    @Before
36
    public void setUp() {
37
    	digest = new DigestEncode();
38
        result = new SampleResult();
39
        jmctx = JMeterContextService.getContext();
40
        String data = "dummy data";
41
        result.setResponseData(data, null);
42
        vars = new JMeterVariables();
43
        jmctx.setVariables(vars);
44
        jmctx.setPreviousResult(result);
45
        params = new LinkedList<>();
46
    }
47
    
48
    
49
    @Test
50
    public void testParameterCount512() throws Exception {
51
    	checkInvalidParameterCounts(digest, 2, 5);
52
    }   
53
    
54
    @Test
55
    public void testSha512() throws Exception {
56
    	params.add(new CompoundVariable("SHA-512"));
57
    	params.add(new CompoundVariable("nofile"));
58
    	params.add(new CompoundVariable("nofile"));
59
    	digest.setParameters(params);
60
    	String returnValue = digest.execute(result, null);
61
    	assertEquals("0a76f7cd4f3cd9bec27146c32a8cad3de865a48d07ff6a2a40f18f2b3307fef4d0de695d14c90234bd453b375aa2974ba17743564bc782ad1d6cf8b3f4db72a4", returnValue);
62
    }      
63
    
64
    @Test
65
    public void testSha1() throws Exception {
66
    	params.add(new CompoundVariable("SHA-1"));    	
67
    	params.add(new CompoundVariable("nofile"));    	
68
    	digest.setParameters(params);
69
    	String returnValue = digest.execute(result, null);
70
    	assertEquals("4ea2ced10057872be25371cfe638d3b096c58f2f", returnValue);
71
    }
72
    
73
    @Test
74
    public void testSha1Variable() throws Exception {
75
    	params.add(new CompoundVariable("SHA-1"));    	
76
    	params.add(new CompoundVariable("nofile"));  
77
    	params.add(new CompoundVariable(""));  
78
    	params.add(new CompoundVariable("true"));
79
    	params.add(new CompoundVariable("newVar"));  	
80
    	digest.setParameters(params);
81
    	String returnValue = digest.execute(result, null);
82
    	assertEquals("4EA2CED10057872BE25371CFE638D3B096C58F2F", returnValue);
83
    }
84
85
    @Test
86
    public void testSha512Variable() throws Exception {    	
87
    	params.add(new CompoundVariable("SHA-512"));
88
    	params.add(new CompoundVariable("nofile"));  
89
    	params.add(new CompoundVariable(""));  
90
    	params.add(new CompoundVariable("true"));
91
    	params.add(new CompoundVariable("newVar"));
92
        digest.setParameters(params);
93
        String returnValue = digest.execute(result, null);
94
        assertEquals("58DA94D45A97B35B31D7F76D2EBAC184BC4BDA512B966CDBE43FDE1CAE1CFAF89617082CA89928FB5DC1C75D60B93ADB5631F518F970CA6DCC196E1AFC678B8C", returnValue);
95
    }
96
    
97
    @Test
98
    public void testSha512Error() throws Exception {
99
    	params.add(new CompoundVariable("nofile"));		
100
    	boolean isFailed = false;
101
    	try {
102
    		digest.setParameters(params);
103
    		digest.execute(result, null);
104
    	} catch (InvalidVariableException e) {
105
    		// expect failure
106
    		isFailed = true;
107
    	}
108
    	assertEquals(isFailed, true);
109
    }
110
    
111
    @Test
112
	public void testSha1Error() throws Exception {
113
		boolean isFailed = false;
114
		try {
115
	    	params.add(new CompoundVariable("SHA-1"));    	
116
			digest.setParameters(params);
117
			digest.execute(result, null);
118
		} catch (InvalidVariableException e) {
119
			// expect failure
120
			isFailed = true;
121
		}
122
		assertEquals(isFailed, true);
123
	}
124
}

Return to bug 61731