[GitHub] jmeter pull request #436: Bug 62959 - Ability to create a Test plan from a c...

2018-11-27 Thread pmouawad
GitHub user pmouawad opened a pull request:

https://github.com/apache/jmeter/pull/436

Bug 62959 - Ability to create a Test plan from a cURL command

POC contributed by https://ubikloadpack.com

## Description
This is a POC for Bug 62959 - Ability to create a Test plan from a Curl 
command

## Motivation and Context

See:

- https://bz.apache.org/bugzilla/show_bug.cgi?id=62959

## How Has This Been Tested?

Unit test included  + Manual testing.

Still it's not intended to be merged unless marked as alpha

## Screenshots (if appropriate):

Copy to clipboard this or use any URL in FF or Chrome and in network panel 
select export to cURL :

`
curl 'http://jmeter.apache.org/' -H 'Proxy-Connection: keep-alive' -H 
'Proxy-Authorization: Basic X/' -H 'Upgrade-Insecure-Requests: 1' -H 
'User-Agent: Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) 
AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Mobile 
Safari/537.36' -H 'Accept: 
text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8'
 -H 'Accept-Encoding: gzip, deflate' -H 'Accept-Language: 
en-US,en;q=0.9,fr;q=0.8' --compressed

`
Then select Help > Import from cURL:

https://user-images.githubusercontent.com/3127467/49117269-6e0f8480-f2a0-11e8-923a-9a3da56da3f8.png;>

A Test plan for HTTP is created:

https://user-images.githubusercontent.com/3127467/49117312-867f9f00-f2a0-11e8-9acb-8f80ff460225.png;>

Note that this is a POC, possible changes:

- Propose an text area where use can paste cURL command and then import
- If Test plan is empty a new one is created
- Otherwise, if it contains a Thread Group,  the HTTP Request will be 
created under the selected element if Controller or Thread Group

## Types of changes

- New feature (non-breaking change which adds functionality)

## Checklist:


- [x ] My code follows the [code style][style-guide] of this project.
- [ ] I have updated the documentation accordingly => Will do in future

[style-guide]: https://wiki.apache.org/jmeter/CodeStyleGuidelines


You can merge this pull request into a Git repository by running:

$ git pull https://github.com/ubikloadpack/jmeter BUG-62959

Alternatively you can review and apply these changes as the patch at:

https://github.com/apache/jmeter/pull/436.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

This closes #436


commit e2a2fd8c625b789908e3bcf12c1c753753326375
Author: pmouawad 
Date:   2018-11-27T22:53:52Z

Bug 62959 - Ability to create a Test plan from a cURL command

POC contributed by https://ubikloadpack.com




---


[GitHub] jmeter pull request #431: Class#newInstance deprecation with Java 9

2018-11-27 Thread FSchumacher
Github user FSchumacher closed the pull request at:

https://github.com/apache/jmeter/pull/431


---


[GitHub] jmeter issue #431: Class#newInstance deprecation with Java 9

2018-11-27 Thread FSchumacher
Github user FSchumacher commented on the issue:

https://github.com/apache/jmeter/pull/431
  
> According to 
https://docs.oracle.com/javase/9/docs/api/java/lang/Class.html
> It should be replaced by
> ` clazz.getDeclaredConstructor().newInstance()`
> see also 
https://stackoverflow.com/questions/53257073/java-9-replace-class-newinstance

Thanks for the info, I read the same article before I started and then made 
such a mess :) I prepared a new pull request #435 and will close this one.


---


[GitHub] jmeter pull request #435: Get rid of deprecated new instance calls

2018-11-27 Thread FSchumacher
GitHub user FSchumacher opened a pull request:

https://github.com/apache/jmeter/pull/435

Get rid of deprecated new instance calls

## Description
This basically is an update to #431 

Get rid of calls to `Class#newInstance()` by replacing them with 
`Class#getDeclaredConstructor()#newInstance()`

And while I edited the classes I cleaned them up a bit, when eclipse showed 
warnings. I think those snippets should be committed separately, but I left 
them in here, so that they can be discussed if necessary.

## Motivation and Context
Java 9 deprecates Class#newInstance(). 

## How Has This Been Tested?
Tests should run when github merges this for testing.

## Screenshots (if appropriate):

## Types of changes

- cleanup

## Checklist:


- [x] My code follows the [code style][style-guide] of this project.

[style-guide]: https://wiki.apache.org/jmeter/CodeStyleGuidelines


You can merge this pull request into a Git repository by running:

$ git pull https://github.com/FSchumacher/jmeter 
get-rid-of-deprecated-newInstance-calls

Alternatively you can review and apply these changes as the patch at:

https://github.com/apache/jmeter/pull/435.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

This closes #435


commit 9dabe9afee1af634f731226caede65c2b1fcac74
Author: Felix Schumacher 
Date:   2018-11-27T19:11:02Z

Use StringUtils.isNotBlank to make intent clearer

commit 5db20ea5a86fed37e3bb523df86bb48fceb69fe4
Author: Felix Schumacher 
Date:   2018-11-27T19:15:06Z

Replace deprecated newInstance calls

commit 9ea1b7b469892bd761083f22da33183f06f53a97
Author: Felix Schumacher 
Date:   2018-11-27T19:16:09Z

Use log format string

commit c21bbd2a0776dab9cf20e19b574a503cc7df7ffc
Author: Felix Schumacher 
Date:   2018-11-27T19:21:08Z

Get rid of deprecated newInstance call

commit c4a32b8a92b63aacd23785f6c8292f0aeaf4a72d
Author: Felix Schumacher 
Date:   2018-11-27T19:25:45Z

Get rid of deprecated newInstance call

Clarify the thrown exceptions of the createThinkTime method, while we
are here

commit 90ac82643bb8ceb56184c0037fac18eee1232d23
Author: Felix Schumacher 
Date:   2018-11-27T19:27:55Z

Get rid of deprecated newInstance call

commit dc04575bf94388ccf1eaef3d88a82ced10643ed2
Author: Felix Schumacher 
Date:   2018-11-27T19:30:49Z

Get rid of deprecated newInstance call

commit 99dfb4999d5528d087256c7b95edf26fd8402b9d
Author: Felix Schumacher 
Date:   2018-11-27T19:32:32Z

Use log format strings

commit 632a30f999d70fc6436f6f9b6b46fa390f941175
Author: Felix Schumacher 
Date:   2018-11-27T19:35:34Z

Simplify code.

With the introduction of varargs this can be written simpler. We don't
have to construct arrays here anymore.

commit 59646b49f1dc4d8c92b9691c957678dd688e583a
Author: Felix Schumacher 
Date:   2018-11-27T19:36:19Z

Use Java conventions for names of parameters

commit 100bf933a31fa61e19b310f83d2d8ead5469a983
Author: Felix Schumacher 
Date:   2018-11-27T19:37:53Z

Use StringUtils#isNotBlank to make intent clearer

commit 08413fb9a3c4730773cbff6eccbbdb5b262f33c3
Author: Felix Schumacher 
Date:   2018-11-27T19:40:46Z

Get rid of deprecated newInstance call

commit f10891f630e1539c71f42b4ce786465a332c4e45
Author: Felix Schumacher 
Date:   2018-11-27T19:48:25Z

Extract code to create BackendListenerClient from a classname

commit e4e23ed9e546eb85c7e258124142d4a54e0a73ff
Author: Felix Schumacher 
Date:   2018-11-27T19:56:51Z

Extract code into private methods to make intent clearer

commit 78f08709d44f10ec2871ab4120f3b805fba4d021
Author: Felix Schumacher 
Date:   2018-11-27T19:59:23Z

Use StringUtils.isNotBlank to make intent of code clearer

commit 2d41ba0abd738c02b9188136cfb4b04715698ce7
Author: Felix Schumacher 
Date:   2018-11-27T20:02:22Z

Get rid of deprecated newInstance call

commit cc882dfb64d1f354ed6bfc4204271ccdee75229f
Author: Felix Schumacher 
Date:   2018-11-27T20:04:38Z

Get rid of deprecated newInstance calls

commit 3e7030da36783fd140c3a3a7ba33ae4615c2b865
Author: Felix Schumacher 
Date:   2018-11-27T20:06:23Z

Get rid of deprecated newInstance calls

commit ee0536082eadb703f97f304420dc4d18e5aaa1d8
Author: Felix Schumacher 
Date:   2018-11-27T20:07:07Z

Use log string formats

commit d78b7c490611483d8717126c8f56279f7f2212ef
Author: Felix Schumacher 
Date:   2018-11-27T20:11:23Z

Get rid of deprecated newInstance call

commit 39b104c6a31b22727b23faa7dcedeb56a8e2e4e1
Author: Felix Schumacher 
Date:   2018-11-27T20:12:49Z

Get rid of deprecated newInstance call

commit 92530c4ae1e5d5755d2b5e4c988b8acf3bb3f380
Author: Felix Schumacher 
Date:   2018-11-27T20:14:20Z

Get rid of deprecated newInstance call

commit 9f74643e9169748a045299e2cf4ee948d7ce9547
Author: Felix Schumacher 
Date: 

[GitHub] jmeter pull request #432: Bug 62870 / Templates : Add ability to provide par...

2018-11-27 Thread asfgit
Github user asfgit closed the pull request at:

https://github.com/apache/jmeter/pull/432


---


[GitHub] jmeter pull request #432: Bug 62870 / Templates : Add ability to provide par...

2018-11-27 Thread FSchumacher
Github user FSchumacher commented on a diff in the pull request:

https://github.com/apache/jmeter/pull/432#discussion_r236800696
  
--- Diff: src/core/org/apache/jmeter/gui/action/SelectTemplatesDialog.java 
---
@@ -137,67 +160,138 @@ private void checkDirtyAndLoad(final ActionEvent 
actionEvent)
 if (template == null) {
 return;
 }
+
templateList.setValues(TemplateManager.getInstance().reset().getTemplateNames());
 // reload the templates before loading
+
 final boolean isTestPlan = template.isTestPlan();
 // Check if the user wants to drop any changes
-if (isTestPlan) {
-ActionRouter.getInstance().doActionNow(new 
ActionEvent(actionEvent.getSource(), actionEvent.getID(), 
ActionNames.CHECK_DIRTY));
-GuiPackage guiPackage = GuiPackage.getInstance();
-if (guiPackage.isDirty()) {
-// Check if the user wants to create from template
-int response = 
JOptionPane.showConfirmDialog(GuiPackage.getInstance().getMainFrame(),
-
JMeterUtils.getResString("cancel_new_from_template"), // $NON-NLS-1$
-JMeterUtils.getResString("template_load?"),  // 
$NON-NLS-1$
-JOptionPane.YES_NO_CANCEL_OPTION,
-JOptionPane.QUESTION_MESSAGE);
-if(response == JOptionPane.YES_OPTION) {
-ActionRouter.getInstance().doActionNow(new 
ActionEvent(actionEvent.getSource(), actionEvent.getID(), ActionNames.SAVE));
-}
-if (response == JOptionPane.CLOSED_OPTION || response == 
JOptionPane.CANCEL_OPTION) {
-return; // Don't clear the plan
-}
-}
+if (isTestPlan && !checkDirty(actionEvent)) {
+return;
 }
 ActionRouter.getInstance().doActionNow(new 
ActionEvent(actionEvent.getSource(), actionEvent.getID(), 
ActionNames.STOP_THREAD));
 final File parent = template.getParent();
-final File fileToCopy = parent != null 
+File fileToCopy = parent != null 
   ? new File(parent, template.getFileName())
-  : new File(JMeterUtils.getJMeterHome(), 
template.getFileName());   
-Load.loadProjectFile(actionEvent, fileToCopy, !isTestPlan, false);
-this.setVisible(false);
+  : new File(JMeterUtils.getJMeterHome(), 
template.getFileName());
+replaceTemplateParametersAndLoad(actionEvent, template, 
isTestPlan, fileToCopy);
+}
+
+/**
+ * @param actionEvent {@link ActionEvent}
+ * @param template {@link Template} definition
+ * @param isTestPlan If it's a full test plan or a part
+ * @param templateFile Template file to load
+ */
+void replaceTemplateParametersAndLoad(final ActionEvent actionEvent, 
final Template template,
+final boolean isTestPlan, File templateFile) {
+File temporaryGeneratedFile = null;
+try {
+// handle customized templates (the .jmx.fmkr files)
+if (template.getParameters() != null && 
!template.getParameters().isEmpty()) {
+File jmxFile = new File(templateFile.getAbsolutePath());
+Map userParameters = getUserParameters();
+Configuration templateCfg = 
TemplateUtil.getTemplateConfig();
+try {
+temporaryGeneratedFile = 
File.createTempFile(template.getName(), ".output");
+templateFile = temporaryGeneratedFile;
+TemplateUtil.processTemplate(jmxFile, 
temporaryGeneratedFile, templateCfg, userParameters);
+} catch (IOException | TemplateException ex) {
+log.error("Error generating output file {} from 
template {}", temporaryGeneratedFile, jmxFile, ex);
+return;
+}
+}
+Load.loadProjectFile(actionEvent, templateFile, !isTestPlan, 
false);
+this.dispose();
+} finally {
+if (temporaryGeneratedFile != null && 
!temporaryGeneratedFile.delete()) {
+log.warn("Could not delete generated output file {} from 
template {}", temporaryGeneratedFile, templateFile);
+}
+}
+}
+
+/**
+ * @param actionEvent {@link ActionEvent}
+ * @return true if plan is not dirty or has been saved 
+ */
+boolean checkDirty(final ActionEvent actionEvent) {
--- End diff --

Any reason for not using `private`?


---


[GitHub] jmeter pull request #432: Bug 62870 / Templates : Add ability to provide par...

2018-11-27 Thread FSchumacher
Github user FSchumacher commented on a diff in the pull request:

https://github.com/apache/jmeter/pull/432#discussion_r236801357
  
--- Diff: src/core/org/apache/jmeter/gui/action/SelectTemplatesDialog.java 
---
@@ -137,67 +160,138 @@ private void checkDirtyAndLoad(final ActionEvent 
actionEvent)
 if (template == null) {
 return;
 }
+
templateList.setValues(TemplateManager.getInstance().reset().getTemplateNames());
 // reload the templates before loading
+
 final boolean isTestPlan = template.isTestPlan();
 // Check if the user wants to drop any changes
-if (isTestPlan) {
-ActionRouter.getInstance().doActionNow(new 
ActionEvent(actionEvent.getSource(), actionEvent.getID(), 
ActionNames.CHECK_DIRTY));
-GuiPackage guiPackage = GuiPackage.getInstance();
-if (guiPackage.isDirty()) {
-// Check if the user wants to create from template
-int response = 
JOptionPane.showConfirmDialog(GuiPackage.getInstance().getMainFrame(),
-
JMeterUtils.getResString("cancel_new_from_template"), // $NON-NLS-1$
-JMeterUtils.getResString("template_load?"),  // 
$NON-NLS-1$
-JOptionPane.YES_NO_CANCEL_OPTION,
-JOptionPane.QUESTION_MESSAGE);
-if(response == JOptionPane.YES_OPTION) {
-ActionRouter.getInstance().doActionNow(new 
ActionEvent(actionEvent.getSource(), actionEvent.getID(), ActionNames.SAVE));
-}
-if (response == JOptionPane.CLOSED_OPTION || response == 
JOptionPane.CANCEL_OPTION) {
-return; // Don't clear the plan
-}
-}
+if (isTestPlan && !checkDirty(actionEvent)) {
+return;
 }
 ActionRouter.getInstance().doActionNow(new 
ActionEvent(actionEvent.getSource(), actionEvent.getID(), 
ActionNames.STOP_THREAD));
 final File parent = template.getParent();
-final File fileToCopy = parent != null 
+File fileToCopy = parent != null 
   ? new File(parent, template.getFileName())
-  : new File(JMeterUtils.getJMeterHome(), 
template.getFileName());   
-Load.loadProjectFile(actionEvent, fileToCopy, !isTestPlan, false);
-this.setVisible(false);
+  : new File(JMeterUtils.getJMeterHome(), 
template.getFileName());
+replaceTemplateParametersAndLoad(actionEvent, template, 
isTestPlan, fileToCopy);
+}
+
+/**
+ * @param actionEvent {@link ActionEvent}
+ * @param template {@link Template} definition
+ * @param isTestPlan If it's a full test plan or a part
+ * @param templateFile Template file to load
+ */
+void replaceTemplateParametersAndLoad(final ActionEvent actionEvent, 
final Template template,
+final boolean isTestPlan, File templateFile) {
+File temporaryGeneratedFile = null;
+try {
+// handle customized templates (the .jmx.fmkr files)
+if (template.getParameters() != null && 
!template.getParameters().isEmpty()) {
+File jmxFile = new File(templateFile.getAbsolutePath());
+Map userParameters = getUserParameters();
+Configuration templateCfg = 
TemplateUtil.getTemplateConfig();
+try {
+temporaryGeneratedFile = 
File.createTempFile(template.getName(), ".output");
+templateFile = temporaryGeneratedFile;
+TemplateUtil.processTemplate(jmxFile, 
temporaryGeneratedFile, templateCfg, userParameters);
+} catch (IOException | TemplateException ex) {
+log.error("Error generating output file {} from 
template {}", temporaryGeneratedFile, jmxFile, ex);
+return;
+}
+}
+Load.loadProjectFile(actionEvent, templateFile, !isTestPlan, 
false);
+this.dispose();
+} finally {
+if (temporaryGeneratedFile != null && 
!temporaryGeneratedFile.delete()) {
+log.warn("Could not delete generated output file {} from 
template {}", temporaryGeneratedFile, templateFile);
+}
+}
+}
+
+/**
+ * @param actionEvent {@link ActionEvent}
+ * @return true if plan is not dirty or has been saved 
--- End diff --

Somehow I think a method `checkDirty` would return `true` if plan is 
*dirty* and has not been saved. Can you think of a better name?


---


[GitHub] jmeter issue #432: Bug 62870 / Templates : Add ability to provide parameters

2018-11-27 Thread pmouawad
Github user pmouawad commented on the issue:

https://github.com/apache/jmeter/pull/432
  
Hello,
I'll be merging it today.

Regards


---