Skip to content

Commit

Permalink
add checkbox for cookies to add or not to add
Browse files Browse the repository at this point in the history
  • Loading branch information
besessener committed May 14, 2024
1 parent 2f825d4 commit 4838570
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
15 changes: 9 additions & 6 deletions src/main/java/de/qytera/jmeterharimporter/HARImportDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public class HARImportDialog implements MenuCreator, ActionListener {
private final JButton importButton;
private final JCheckBox addTimerCheckbox;
private final JCheckBox addHeaderCheckbox;
private final JCheckBox addCookiesCheckbox;

/**
* Maps hosts to their corresponding checkboxes.
Expand Down Expand Up @@ -104,16 +105,19 @@ public HARImportDialog() {
optionsPanelBorder.setTitleJustification(TitledBorder.DEFAULT_JUSTIFICATION);
optionsPanelBorder.setTitlePosition(TitledBorder.DEFAULT_POSITION);
optionsPanel.setBorder(optionsPanelBorder);
optionsPanel.setLayout(new BorderLayout(0, 0));
optionsPanel.setMinimumSize(new Dimension(MINIMUM_DIALOG_WIDTH, MINIMUM_ELEMENT_HEIGHT * 2));
optionsPanel.setPreferredSize(new Dimension(MINIMUM_DIALOG_WIDTH, MINIMUM_ELEMENT_HEIGHT * 2));
optionsPanel.setLayout(new BoxLayout(optionsPanel, BoxLayout.Y_AXIS));
optionsPanel.setMinimumSize(new Dimension(MINIMUM_DIALOG_WIDTH, MINIMUM_ELEMENT_HEIGHT * 3));
optionsPanel.setPreferredSize(new Dimension(MINIMUM_DIALOG_WIDTH, MINIMUM_ELEMENT_HEIGHT * 3));

addTimerCheckbox = new JCheckBox("Add Waiting Time");
addTimerCheckbox = new JCheckBox("Add Recorded Waiting Time");
optionsPanel.add(addTimerCheckbox);

addHeaderCheckbox = new JCheckBox("Add Recorded Headers");
optionsPanel.add(addHeaderCheckbox);

addCookiesCheckbox = new JCheckBox("Add Recorded Cookies");
optionsPanel.add(addCookiesCheckbox);

gbc.gridx = 0;
gbc.gridy = 2;
gbc.weightx = 0.0;
Expand Down Expand Up @@ -221,8 +225,7 @@ public String getDescription() {
importer.ignoreHost(host);
}
});
addHeaderCheckbox.setSelected(true);
importer.addNewThreadGroupWithSamplers(addTimerCheckbox.isSelected(), addHeaderCheckbox.isSelected());
importer.addNewThreadGroupWithSamplers(addTimerCheckbox.isSelected(), addHeaderCheckbox.isSelected(), addCookiesCheckbox.isSelected());
importDialog.dispose();
});
}
Expand Down
13 changes: 9 additions & 4 deletions src/main/java/de/qytera/jmeterharimporter/HARImporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public void ignoreHost(String host) {
* @return the root node of the JMeter tree
*/
public JMeterTreeNode addNewThreadGroupWithSamplers() {
return addNewThreadGroupWithSamplers(true, true);
return addNewThreadGroupWithSamplers(true, true, true);
}

/**
Expand All @@ -110,9 +110,10 @@ public JMeterTreeNode addNewThreadGroupWithSamplers() {
*
* @param shouldAddThinkTime whether to add think time between the requests
* @param shouldAddHeader whether to add the recorded headers to the requests
* @param shouldAddCookies whether to add the recorded cookies to the requests
* @return the root node of the JMeter tree
*/
public JMeterTreeNode addNewThreadGroupWithSamplers(Boolean shouldAddThinkTime, Boolean shouldAddHeader) {
public JMeterTreeNode addNewThreadGroupWithSamplers(Boolean shouldAddThinkTime, Boolean shouldAddHeader, Boolean shouldAddCookies) {
try {
// Get the root node of the JMeter tree
JMeterTreeNode root = (JMeterTreeNode) this.guiPackage.getTreeModel().getRoot();
Expand Down Expand Up @@ -151,10 +152,14 @@ public JMeterTreeNode addNewThreadGroupWithSamplers(Boolean shouldAddThinkTime,
transactionControllerNodeSub);

// add the header manager
addComponent(createHeaderManager(harRequest), httpSamplerNode);
if (shouldAddHeader) {
addComponent(createHeaderManager(harRequest), httpSamplerNode);
}

// add the cookie manager
addComponent(createCookieManager(harRequest), httpSamplerNode);
if (shouldAddCookies) {
addComponent(createCookieManager(harRequest), httpSamplerNode);
}

// add body
if (harRequest.getPostData() != null && harRequest.getPostData().getText() != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public void testHARImporter_timer() {
@Test
public void testHARImporter_no_timer() {
HARImporter harImporter = new HARImporter("src/test/resources/get-www.randomnumberapi.com.har");
threadGroupNode = harImporter.addNewThreadGroupWithSamplers(false, false);
threadGroupNode = harImporter.addNewThreadGroupWithSamplers(false, false, false);

String[] timerDelays = { "0", "8293" };

Expand Down Expand Up @@ -116,7 +116,7 @@ public void testHARImporter_header() {
@Test
public void testHARImporter_no_header() {
HARImporter harImporter = new HARImporter("src/test/resources/get-www.randomnumberapi.com.har");
threadGroupNode = harImporter.addNewThreadGroupWithSamplers(false, false);
threadGroupNode = harImporter.addNewThreadGroupWithSamplers(false, false, false);

boolean isHeaderAvailable = true;

Expand Down

0 comments on commit 4838570

Please sign in to comment.