示例#1
0
  private JPanel makeParameterPanel() {
    expressionField =
        new JLabeledTextField(JMeterUtils.getResString("expression_field")); // $NON-NLS-1$
    attributeField =
        new JLabeledTextField(JMeterUtils.getResString("attribute_field")); // $NON-NLS-1$
    defaultField =
        new JLabeledTextField(JMeterUtils.getResString("default_value_field")); // $NON-NLS-1$
    refNameField = new JLabeledTextField(JMeterUtils.getResString("ref_name_field")); // $NON-NLS-1$
    matchNumberField =
        new JLabeledTextField(JMeterUtils.getResString("match_num_field")); // $NON-NLS-1$

    JPanel panel = new JPanel(new GridBagLayout());
    GridBagConstraints gbc = new GridBagConstraints();
    initConstraints(gbc);
    addField(panel, refNameField, gbc);
    resetContraints(gbc);
    addField(panel, expressionField, gbc);
    resetContraints(gbc);
    addField(panel, attributeField, gbc);
    resetContraints(gbc);
    addField(panel, matchNumberField, gbc);
    resetContraints(gbc);
    gbc.weighty = 1;
    addField(panel, defaultField, gbc);
    return panel;
  }
  private JPanel createGraphTitlePane() {
    JPanel titleNamePane = new JPanel(new BorderLayout());
    syncWithName.setFont(new Font("SansSerif", Font.PLAIN, 10));
    titleNamePane.add(graphTitle, BorderLayout.CENTER);
    titleNamePane.add(syncWithName, BorderLayout.EAST);

    JPanel titleStylePane = new JPanel();
    titleStylePane.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 5));
    titleStylePane.add(
        GuiUtils.createLabelCombo(
            JMeterUtils.getResString("aggregate_graph_font"), // $NON-NLS-1$
            titleFontNameList));
    titleFontNameList.setSelectedIndex(0); // default: sans serif
    titleStylePane.add(
        GuiUtils.createLabelCombo(
            JMeterUtils.getResString("aggregate_graph_size"), // $NON-NLS-1$
            titleFontSizeList));
    titleFontSizeList.setSelectedItem(StatGraphProperties.fontSize[6]); // default: 16
    titleStylePane.add(
        GuiUtils.createLabelCombo(
            JMeterUtils.getResString("aggregate_graph_style"), // $NON-NLS-1$
            titleFontStyleList));
    titleFontStyleList.setSelectedItem(JMeterUtils.getResString("fontstyle.bold")); // default: bold

    JPanel titlePane = new JPanel(new BorderLayout());
    titlePane.setBorder(
        BorderFactory.createTitledBorder(
            BorderFactory.createEtchedBorder(),
            JMeterUtils.getResString("aggregate_graph_title_group"))); // $NON-NLS-1$
    titlePane.add(titleNamePane, BorderLayout.NORTH);
    titlePane.add(titleStylePane, BorderLayout.SOUTH);
    return titlePane;
  }
示例#3
0
  /**
   * Test whether an XPath is valid. It seems the Xalan has no easy way to check, so this creates a
   * dummy test document, then tries to evaluate the xpath against it.
   *
   * @param xpathString XPath String to validate
   * @param showDialog weather to show a dialog
   * @return returns true if valid, valse otherwise.
   */
  public static boolean validXPath(String xpathString, boolean showDialog) {
    String ret = null;
    boolean success = true;
    Document testDoc = null;
    try {
      testDoc = XPathUtil.makeDocumentBuilder(false, false, false, false).newDocument();
      Element el = testDoc.createElement("root"); // $NON-NLS-1$
      testDoc.appendChild(el);
      XPathUtil.validateXPath(testDoc, xpathString);
    } catch (IllegalArgumentException e) {
      log.warn(e.getLocalizedMessage());
      success = false;
      ret = e.getLocalizedMessage();
    } catch (ParserConfigurationException e) {
      success = false;
      ret = e.getLocalizedMessage();
    } catch (TransformerException e) {
      success = false;
      ret = e.getLocalizedMessage();
    }

    if (showDialog) {
      JOptionPane.showMessageDialog(
          null,
          (success) ? JMeterUtils.getResString("xpath_assertion_valid") : ret, // $NON-NLS-1$
          (success)
              ? JMeterUtils.getResString("xpath_assertion_valid")
              : JMeterUtils //$NON-NLS-1$
                  .getResString("xpath_assertion_failed"),
          (success)
              ? JOptionPane.INFORMATION_MESSAGE // $NON-NLS-1$
              : JOptionPane.ERROR_MESSAGE);
    }
    return success;
  }
示例#4
0
 @Override
 public void mouseReleased(MouseEvent e) {
   if (dragging && isValidDragAction(draggedNodes, getCurrentNode())) {
     dragging = false;
     JPopupMenu dragNdrop = new JPopupMenu();
     JMenuItem item = new JMenuItem(JMeterUtils.getResString("insert_before")); // $NON-NLS-1$
     item.addActionListener(actionHandler);
     item.setActionCommand(ReportDragNDrop.INSERT_BEFORE);
     dragNdrop.add(item);
     item = new JMenuItem(JMeterUtils.getResString("insert_after")); // $NON-NLS-1$
     item.addActionListener(actionHandler);
     item.setActionCommand(ReportDragNDrop.INSERT_AFTER);
     dragNdrop.add(item);
     item = new JMenuItem(JMeterUtils.getResString("add_as_child")); // $NON-NLS-1$
     item.addActionListener(actionHandler);
     item.setActionCommand(ReportDragNDrop.ADD);
     dragNdrop.add(item);
     dragNdrop.addSeparator();
     item = new JMenuItem(JMeterUtils.getResString("cancel")); // $NON-NLS-1$
     dragNdrop.add(item);
     displayPopUp(e, dragNdrop);
   } else {
     ReportGuiPackage.getInstance().getMainFrame().repaint();
   }
   dragging = false;
 }
示例#5
0
  /**
   * Create the XPath task pane
   *
   * @return XPath task pane
   */
  private JPanel createXpathExtractorTasksPanel() {
    Box xpathActionPanel = Box.createVerticalBox();

    Box selectorAndButton = Box.createHorizontalBox();

    Border margin = new EmptyBorder(5, 5, 0, 5);
    xpathActionPanel.setBorder(margin);
    xpathExpressionField =
        new JLabeledTextField(JMeterUtils.getResString("xpath_tester_field")); // $NON-NLS-1$

    JButton xpathTester =
        new JButton(JMeterUtils.getResString("xpath_tester_button_test")); // $NON-NLS-1$
    xpathTester.setActionCommand(XPATH_TESTER_COMMAND);
    xpathTester.addActionListener(this);

    selectorAndButton.add(xpathExpressionField);
    selectorAndButton.add(xpathTester);

    xpathActionPanel.add(selectorAndButton);
    xpathActionPanel.add(xmlConfPanel);
    xpathActionPanel.add(getFragment);

    xpathResultField = new JTextArea();
    xpathResultField.setEditable(false);
    xpathResultField.setLineWrap(true);
    xpathResultField.setWrapStyleWord(true);

    JPanel xpathTasksPanel = new JPanel(new BorderLayout(0, 5));
    xpathTasksPanel.add(xpathActionPanel, BorderLayout.NORTH);
    xpathTasksPanel.add(GuiUtils.makeScrollPane(xpathResultField), BorderLayout.CENTER);

    return xpathTasksPanel;
  }
示例#6
0
  static {
    if (NONPROXY_HOSTS.length() > 0) {
      StringTokenizer s = new StringTokenizer(NONPROXY_HOSTS, "|"); // $NON-NLS-1$
      while (s.hasMoreTokens()) {
        String t = s.nextToken();
        if (t.indexOf('*') == 0) { // e.g. *.apache.org // $NON-NLS-1$
          nonProxyHostSuffix.add(t.substring(1));
        } else {
          nonProxyHostFull.add(t); // e.g. www.apache.org
        }
      }
    }
    nonProxyHostSuffixSize = nonProxyHostSuffix.size();

    InetAddress inet = null;
    String localHostOrIP = JMeterUtils.getPropDefault("httpclient.localaddress", ""); // $NON-NLS-1$
    if (localHostOrIP.length() > 0) {
      try {
        inet = InetAddress.getByName(localHostOrIP);
        log.info("Using localAddress " + inet.getHostAddress());
      } catch (UnknownHostException e) {
        log.warn(e.getLocalizedMessage());
      }
    } else {
      // Get hostname
      localHostOrIP = JMeterUtils.getLocalHostName();
    }
    localAddress = inet;
    localHost = localHostOrIP;
    log.info("Local host = " + localHost);
  }
示例#7
0
 private void populateTemplatePage() {
   String selectedTemplate = templateList.getText();
   Template template = TemplateManager.getInstance().getTemplateByName(selectedTemplate);
   helpDoc.setText(template.getDescription());
   applyTemplateButton.setText(
       template.isTestPlan()
           ? JMeterUtils.getResString("template_create_from")
           : JMeterUtils.getResString("template_merge_from"));
 }
示例#8
0
 /** {@inheritDoc} */
 @Override
 public void setupTabPane() {
   // Add xpath tester pane
   if (rightSide.indexOfTab(JMeterUtils.getResString("xpath_tester_title")) < 0) { // $NON-NLS-1$
     rightSide.addTab(
         JMeterUtils.getResString("xpath_tester_title"), xmlWithXPathPane); // $NON-NLS-1$
   }
   clearData();
 }
 /**
  * Get the text for the value as the translation of the resource name.
  *
  * @param value value for which to get the translation
  * @param column index which column message parameters should be used
  * @param row not used
  * @return the text
  */
 protected String getText(Object value, int row, int column) {
   if (value == null) {
     return "";
   }
   if (columnsMsgParameters != null && columnsMsgParameters[column] != null) {
     return MessageFormat.format(
         JMeterUtils.getResString(value.toString()), columnsMsgParameters[column]);
   } else {
     return JMeterUtils.getResString(value.toString());
   }
 }
 private void actionMakeGraph() {
   if (model.getRowCount() > 1) {
     makeGraph();
     tabbedGraph.setSelectedIndex(1);
   } else {
     JOptionPane.showMessageDialog(
         null,
         JMeterUtils.getResString("aggregate_graph_no_values_to_graph"), // $NON-NLS-1$
         JMeterUtils.getResString("aggregate_graph_no_values_to_graph"), // $NON-NLS-1$
         JOptionPane.WARNING_MESSAGE);
   }
 }
示例#11
0
 /** Create a new TestPlanGui. */
 public TestPlanGui() {
   browseJar =
       new FileListPanel(
           JMeterUtils.getResString("test_plan_classpath_browse"),
           ".jar"); // $NON-NLS-1$ $NON-NLS-2$
   argsPanel =
       new ArgumentsPanel(JMeterUtils.getResString("user_defined_variables")); // $NON-NLS-1$
   serializedMode = new JCheckBox(JMeterUtils.getResString("testplan.serialized")); // $NON-NLS-1$
   functionalMode = new JCheckBox(JMeterUtils.getResString("functional_mode")); // $NON-NLS-1$
   tearDownOnShutdown =
       new JCheckBox(JMeterUtils.getResString("teardown_on_shutdown")); // $NON-NLS-1$
   init();
 }
  /** Inits the GUI. */
  private void init() {
    setLayout(new BorderLayout(0, 10));
    setBorder(makeBorder());

    add(makeTitlePanel(), BorderLayout.NORTH);

    JPanel mainPanel = new JPanel(new BorderLayout());

    // USER_INPUT
    VerticalPanel assertionPanel = new VerticalPanel();
    assertionPanel.setBorder(
        BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "XML Schema"));

    // doctype
    HorizontalPanel xmlSchemaPanel = new HorizontalPanel();

    xmlSchemaPanel.add(
        new JLabel(JMeterUtils.getResString("xmlschema_assertion_label"))); // $NON-NLS-1$

    xmlSchema = new JTextField(26);
    xmlSchemaPanel.add(xmlSchema);

    assertionPanel.add(xmlSchemaPanel);

    mainPanel.add(assertionPanel, BorderLayout.NORTH);
    add(mainPanel, BorderLayout.CENTER);
  }
示例#13
0
 /**
  * Create a panel allowing the user to define variables for the test.
  *
  * @return a panel for user-defined variables
  */
 private JPanel createVariablePanel() {
   argsPanel =
       new ArgumentsPanel(
           JMeterUtils.getResString("user_defined_variables"), // $NON-NLS-1$
           Color.white);
   return argsPanel;
 }
 /**
  * Method is called by the JMeterEngine class when a test run is started. Zeroes
  * numberOfActiveThreads. Saves current time in a field and in the JMeter property "TESTSTART.MS"
  */
 public static synchronized void startTest() {
   if (testStart == 0) {
     numberOfActiveThreads = 0;
     testStart = System.currentTimeMillis();
     JMeterUtils.setProperty("TESTSTART.MS", Long.toString(testStart)); // $NON-NLS-1$
   }
 }
  /** Create the GUI components and layout. */
  private void init() { // called from ctor, so must not be overridable
    menuBar = new ReportMenuBar();
    setJMenuBar(menuBar);

    JPanel all = new JPanel(new BorderLayout());
    all.add(createToolBar(), BorderLayout.NORTH);

    JSplitPane treeAndMain = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);

    treePanel = createTreePanel();
    treeAndMain.setLeftComponent(treePanel);

    mainPanel = createMainPanel();
    treeAndMain.setRightComponent(mainPanel);

    treeAndMain.setResizeWeight(.2);
    treeAndMain.setContinuousLayout(true);
    all.add(treeAndMain, BorderLayout.CENTER);

    getContentPane().add(all);

    tree.setSelectionRow(1);
    addWindowListener(new WindowHappenings());

    setTitle(DEFAULT_TITLE);
    setIconImage(JMeterUtils.getImage("jmeter.jpg").getImage()); // $NON-NLS-1$
  }
 @Override
 public void add(final SampleResult res) {
   final String sampleLabel = res.getSampleLabel();
   // Sampler selection
   if (columnSelection.isSelected() && pattern != null) {
     matcher = pattern.matcher(sampleLabel);
   }
   if ((matcher == null) || (matcher.find())) {
     JMeterUtils.runSafe(
         new Runnable() {
           @Override
           public void run() {
             SamplingStatCalculator row = null;
             synchronized (lock) {
               row = tableRows.get(sampleLabel);
               if (row == null) {
                 row = new SamplingStatCalculator(sampleLabel);
                 tableRows.put(row.getLabel(), row);
                 model.insertRow(row, model.getRowCount() - 1);
               }
             }
             row.addSample(res);
             tableRows.get(TOTAL_ROW_LABEL).addSample(res);
             model.fireTableDataChanged();
           }
         });
   }
 }
 @Override
 public void add(final SampleResult res) {
   JMeterUtils.runSafe(
       new Runnable() {
         @Override
         public void run() {
           if (isSampleIncluded(res)) {
             SamplingStatCalculator row = null;
             final String sampleLabel = res.getSampleLabel(useGroupName.isSelected());
             synchronized (lock) {
               row = tableRows.get(sampleLabel);
               if (row == null) {
                 row = new SamplingStatCalculator(sampleLabel);
                 tableRows.put(row.getLabel(), row);
                 model.insertRow(row, model.getRowCount() - 1);
               }
             }
             /*
              * Synch is needed because multiple threads can update the
              * counts.
              */
             synchronized (row) {
               row.addSample(res);
             }
             SamplingStatCalculator tot = tableRows.get(TOTAL_ROW_LABEL);
             synchronized (tot) {
               tot.addSample(res);
             }
             model.fireTableDataChanged();
           }
         }
       });
 }
示例#18
0
  private List<MatchResult> processMatches(
      Pattern pattern, String regex, SampleResult result, int matchNumber, JMeterVariables vars) {
    if (log.isDebugEnabled()) {
      log.debug("Regex = " + regex);
    }

    Perl5Matcher matcher = JMeterUtils.getMatcher();
    List<MatchResult> matches = new ArrayList<MatchResult>();
    int found = 0;

    if (isScopeVariable()) {
      String inputString = vars.get(getVariableName());
      if (inputString == null) {
        log.warn(
            "No variable '"
                + getVariableName()
                + "' found to process by RegexExtractor '"
                + getName()
                + "', skipping processing");
        return Collections.emptyList();
      }
      matchStrings(matchNumber, matcher, pattern, matches, found, inputString);
    } else {
      List<SampleResult> sampleList = getSampleList(result);
      for (SampleResult sr : sampleList) {
        String inputString = getInputString(sr);
        found = matchStrings(matchNumber, matcher, pattern, matches, found, inputString);
        if (matchNumber > 0 && found == matchNumber) { // no need to process further
          break;
        }
      }
    }
    return matches;
  }
示例#19
0
  public void process() {
    Sampler sampler = JMeterContextService.getContext().getCurrentSampler();
    SampleResult responseText = JMeterContextService.getContext().getPreviousResult();
    if (responseText == null) {
      return;
    }
    initRegex(getArgumentName());
    String text = new String(responseText.getResponseData());
    Perl5Matcher matcher = JMeterUtils.getMatcher();
    String value = "";
    if (matcher.contains(text, case1)) {
      MatchResult result = matcher.getMatch();
      value = result.group(1);
    } else if (matcher.contains(text, case2)) {
      MatchResult result = matcher.getMatch();
      value = result.group(1);
    } else if (matcher.contains(text, case3)) {
      MatchResult result = matcher.getMatch();
      value = result.group(1);
    } else if (matcher.contains(text, case4)) {
      MatchResult result = matcher.getMatch();
      value = result.group(1);
    }

    modify((HTTPSampler) sampler, value);
  }
/** Base class for SampleSender implementations */
public abstract class AbstractSampleSender implements SampleSender {

  // Note: this is an instance field (and is not transient), so is created by the JMeter client
  // and propagated to the server instance by RMI.
  // [a static field would be recreated on the server, and would pick up the server properties]
  private final boolean isClientConfigured =
      JMeterUtils.getPropDefault("sample_sender_client_configured", true); // $NON-NLS-1$

  /**
   * @return boolean indicates how SampleSender configuration is done, true means use client
   *     properties and send to servers, false means use server configurations
   */
  public boolean isClientConfigured() {
    return isClientConfigured;
  }

  /** */
  public AbstractSampleSender() {
    super();
  }

  @Override
  public void testEnded() {
    // Not used
  }
}
示例#21
0
  private void init() { // called from ctor, so must not be overridable
    setLayout(new BorderLayout(10, 10));
    setBorder(makeBorder());
    setBackground(Color.white);

    JPanel pane = new JPanel();
    pane.setLayout(new BorderLayout(10, 10));
    pane.setBackground(Color.white);
    pane.add(this.getNamePanel(), BorderLayout.NORTH);

    VerticalPanel options = new VerticalPanel(Color.white);
    yAxisLabel.setBackground(Color.white);

    JLabel xLabel = new JLabel(JMeterUtils.getResString("report_chart_x_axis"));
    HorizontalPanel xpanel = new HorizontalPanel(Color.white);
    xLabel.setBorder(new EmptyBorder(5, 2, 5, 2));
    xItems.setBackground(Color.white);
    xItems.setValues(AbstractTable.xitems);
    xpanel.add(xLabel);
    xpanel.add(xItems);
    options.add(xpanel);

    JLabel xALabel = new JLabel(JMeterUtils.getResString("report_chart_x_axis_label"));
    HorizontalPanel xApanel = new HorizontalPanel(Color.white);
    xALabel.setBorder(new EmptyBorder(5, 2, 5, 2));
    xAxisLabel.setBackground(Color.white);
    xAxisLabel.setValues(AbstractChart.X_LABELS);
    xApanel.add(xALabel);
    xApanel.add(xAxisLabel);
    options.add(xApanel);

    JLabel yLabel = new JLabel(JMeterUtils.getResString("report_chart_y_axis"));
    HorizontalPanel ypanel = new HorizontalPanel(Color.white);
    yLabel.setBorder(new EmptyBorder(5, 2, 5, 2));
    yItems.setBackground(Color.white);
    yItems.setValues(AbstractTable.items);
    ypanel.add(yLabel);
    ypanel.add(yItems);
    options.add(ypanel);
    options.add(yAxisLabel);
    options.add(caption);
    options.add(urls);

    add(pane, BorderLayout.NORTH);
    add(options, BorderLayout.CENTER);
  }
 /**
  * @param keys I18N keys
  * @return labels
  */
 static String[] getLabels(String[] keys) {
   String[] labels = new String[keys.length];
   for (int i = 0; i < labels.length; i++) {
     labels[i] =
         MessageFormat.format(JMeterUtils.getResString(keys[i]), COLUMNS_MSG_PARAMETERS[i]);
   }
   return labels;
 }
示例#23
0
  /**
   * Negated chechbox
   *
   * @return JCheckBox
   */
  public JCheckBox getNegatedCheckBox() {
    if (negated == null) {
      negated =
          new JCheckBox(JMeterUtils.getResString("xpath_assertion_negate"), false); // $NON-NLS-1$
    }

    return negated;
  }
  /**
   * Create pane for legend settings
   *
   * @return Legend pane
   */
  private JPanel createLegendPane() {
    JPanel legendPanel = new JPanel();
    legendPanel.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0));
    legendPanel.setBorder(
        BorderFactory.createTitledBorder(
            BorderFactory.createEtchedBorder(),
            JMeterUtils.getResString("aggregate_graph_legend"))); // $NON-NLS-1$

    legendPanel.add(
        GuiUtils.createLabelCombo(
            JMeterUtils.getResString("aggregate_graph_legend_placement"), // $NON-NLS-1$
            legendPlacementList));
    legendPlacementList.setSelectedItem(
        JMeterUtils.getResString("aggregate_graph_legend.placement.bottom")); // default: bottom
    legendPanel.add(
        GuiUtils.createLabelCombo(
            JMeterUtils.getResString("aggregate_graph_font"), // $NON-NLS-1$
            fontNameList));
    fontNameList.setSelectedIndex(0); // default: sans serif
    legendPanel.add(
        GuiUtils.createLabelCombo(
            JMeterUtils.getResString("aggregate_graph_size"), // $NON-NLS-1$
            fontSizeList));
    fontSizeList.setSelectedItem(StatGraphProperties.fontSize[2]); // default: 10
    legendPanel.add(
        GuiUtils.createLabelCombo(
            JMeterUtils.getResString("aggregate_graph_style"), // $NON-NLS-1$
            fontStyleList));
    fontStyleList.setSelectedItem(JMeterUtils.getResString("fontstyle.normal")); // default: normal

    return legendPanel;
  }
示例#25
0
  private JPanel createResetPanel() {
    resetInterpreter =
        new JCheckBox(JMeterUtils.getResString("bsh_script_reset_interpreter")); // $NON-NLS-1$
    resetInterpreter.setName(BeanShellAssertion.PARAMETERS);

    JPanel resetInterpreterPanel = new JPanel(new BorderLayout());
    resetInterpreterPanel.add(resetInterpreter, BorderLayout.WEST);
    return resetInterpreterPanel;
  }
 /**
  * Show a dialog indicating that JMeter threads are stopping on a particular host.
  *
  * @param host the host where JMeter threads are stopping
  */
 public void showStoppingMessage(String host) {
   stoppingMessage =
       new JDialog(this, JMeterUtils.getResString("stopping_test_title"), true); // $NON-NLS-1$
   JLabel stopLabel =
       new JLabel(JMeterUtils.getResString("stopping_test") + ": " + host); // $NON-NLS-1$
   stopLabel.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
   stoppingMessage.getContentPane().add(stopLabel);
   stoppingMessage.pack();
   ComponentUtil.centerComponentInComponent(this, stoppingMessage);
   SwingUtilities.invokeLater(
       new Runnable() {
         public void run() {
           if (stoppingMessage != null) {
             stoppingMessage.setVisible(true);
           }
         }
       });
 }
示例#27
0
 /**
  * Check if existing Test Plan has been modified and ask user what he wants to do if test plan is
  * dirty
  *
  * @param actionEvent {@link ActionEvent}
  */
 private void checkDirtyAndLoad(final ActionEvent actionEvent) throws HeadlessException {
   final String selectedTemplate = templateList.getText();
   final Template template = TemplateManager.getInstance().getTemplateByName(selectedTemplate);
   if (template == null) {
     return;
   }
   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
       }
     }
   }
   ActionRouter.getInstance()
       .doActionNow(
           new ActionEvent(actionEvent.getSource(), actionEvent.getID(), ActionNames.STOP_THREAD));
   final File parent = template.getParent();
   final File fileToCopy =
       parent != null
           ? new File(parent, template.getFileName())
           : new File(JMeterUtils.getJMeterHome(), template.getFileName());
   Load.loadProjectFile(actionEvent, fileToCopy, !isTestPlan, false);
   this.setVisible(false);
 }
示例#28
0
  private Component makeExtractorPanel() {
    JPanel panel = new HorizontalPanel();
    panel.setBorder(
        BorderFactory.createTitledBorder(
            JMeterUtils.getResString("html_extractor_type"))); // $NON-NLS-1$

    DefaultComboBoxModel m = new DefaultComboBoxModel();
    for (String s : HtmlExtractor.getImplementations()) {
      m.addElement(s);
    }
    m.addElement(USE_DEFAULT_EXTRACTOR_IMPL);
    extractorImplName = new JComboBox(m);
    extractorImplName.setSelectedItem(HtmlExtractor.DEFAULT_EXTRACTOR);
    JLabel label2 = new JLabel(JMeterUtils.getResString("html_extractor_type")); // $NON-NLS-1$
    label2.setLabelFor(extractorImplName);
    panel.add(label2);
    panel.add(extractorImplName);
    return panel;
  }
 /**
  * Create pane for Y Axis options
  *
  * @return Y Axis pane
  */
 private JPanel createGraphYAxisPane() {
   JPanel yAxisPane = new JPanel();
   yAxisPane.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0));
   yAxisPane.setBorder(
       BorderFactory.createTitledBorder(
           BorderFactory.createEtchedBorder(),
           JMeterUtils.getResString("aggregate_graph_yaxis_group"))); // $NON-NLS-1$
   yAxisPane.add(maxValueYAxisLabel);
   return yAxisPane;
 }
示例#30
0
  /** {@inheritDoc} */
  @Override
  public synchronized String execute(SampleResult previousResult, Sampler currentSampler)
      throws InvalidVariableException {

    if (bshInterpreter == null) // did we find BeanShell?
    {
      throw new InvalidVariableException("BeanShell not found");
    }

    JMeterContext jmctx = JMeterContextService.getContext();
    JMeterVariables vars = jmctx.getVariables();

    String script = ((CompoundVariable) values[0]).execute();
    String varName = ""; // $NON-NLS-1$
    if (values.length > 1) {
      varName = ((CompoundVariable) values[1]).execute().trim();
    }

    String resultStr = ""; // $NON-NLS-1$

    log.debug("Script=" + script);

    try {

      // Pass in some variables
      if (currentSampler != null) {
        bshInterpreter.set("Sampler", currentSampler); // $NON-NLS-1$
      }

      if (previousResult != null) {
        bshInterpreter.set("SampleResult", previousResult); // $NON-NLS-1$
      }

      // Allow access to context and variables directly
      bshInterpreter.set("ctx", jmctx); // $NON-NLS-1$
      bshInterpreter.set("vars", vars); // $NON-NLS-1$
      bshInterpreter.set("props", JMeterUtils.getJMeterProperties()); // $NON-NLS-1$
      bshInterpreter.set("threadName", Thread.currentThread().getName()); // $NON-NLS-1$

      // Execute the script
      Object bshOut = bshInterpreter.eval(script);
      if (bshOut != null) {
        resultStr = bshOut.toString();
      }
      if (vars != null && varName.length() > 0) { // vars will be null on TestPlan
        vars.put(varName, resultStr);
      }
    } catch (Exception ex) // Mainly for bsh.EvalError
    {
      log.warn("Error running BSH script", ex);
    }

    log.debug("Output=" + resultStr);
    return resultStr;
  }