jmeter-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pmoua...@apache.org
Subject svn commit: r1447503 - in /jmeter/trunk: src/components/org/apache/jmeter/extractor/ src/components/org/apache/jmeter/visualizers/ src/core/org/apache/jmeter/resources/ xdocs/
Date Mon, 18 Feb 2013 21:13:37 GMT
Author: pmouawad
Date: Mon Feb 18 21:13:37 2013
New Revision: 1447503

URL: http://svn.apache.org/r1447503
Log:
Bug 54576 - View Results Tree : Add a CSS/JQuery Tester
Bugzilla Id: 54576

Added:
    jmeter/trunk/src/components/org/apache/jmeter/visualizers/RenderAsCssJQuery.java   (with
props)
Modified:
    jmeter/trunk/src/components/org/apache/jmeter/extractor/HtmlExtractor.java
    jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties
    jmeter/trunk/src/core/org/apache/jmeter/resources/messages_fr.properties
    jmeter/trunk/xdocs/changes.xml

Modified: jmeter/trunk/src/components/org/apache/jmeter/extractor/HtmlExtractor.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/components/org/apache/jmeter/extractor/HtmlExtractor.java?rev=1447503&r1=1447502&r2=1447503&view=diff
==============================================================================
--- jmeter/trunk/src/components/org/apache/jmeter/extractor/HtmlExtractor.java (original)
+++ jmeter/trunk/src/components/org/apache/jmeter/extractor/HtmlExtractor.java Mon Feb 18
21:13:37 2013
@@ -197,19 +197,27 @@ public class HtmlExtractor extends Abstr
     }
     
     /**
+     * @param impl Extractor implementation
+     * @return Extractor
+     */
+    public static final Extractor getExtractorImpl(String impl) {
+        boolean useDefaultExtractor = DEFAULT_EXTRACTOR.equals(impl);
+        if (useDefaultExtractor || EXTRACTOR_JSOUP.equals(impl)) {
+            return new JSoupExtractor();
+        } else if (EXTRACTOR_JODD.equals(impl)) {
+            return new JoddExtractor();
+        } else {
+            throw new IllegalArgumentException("Extractor implementation:"+ impl+" is unknown");
+        }
+    }
+    
+    /**
      * 
      * @return Extractor
      */
     private Extractor getExtractorImpl() {
         if (extractor == null) {
-            boolean useDefaultExtractor = DEFAULT_EXTRACTOR.equals(getExtractor());
-            if (useDefaultExtractor || EXTRACTOR_JSOUP.equals(getExtractor())) {
-                extractor = new JSoupExtractor();
-            } else if (EXTRACTOR_JODD.equals(getExtractor())) {
-                extractor = new JoddExtractor();
-            } else {
-                throw new IllegalArgumentException("Extractor implementation:"+ getExtractor()+"
is unknown");
-            }
+            extractor = getExtractorImpl(getExtractor());
         }
         return extractor;
     }

Added: jmeter/trunk/src/components/org/apache/jmeter/visualizers/RenderAsCssJQuery.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/components/org/apache/jmeter/visualizers/RenderAsCssJQuery.java?rev=1447503&view=auto
==============================================================================
--- jmeter/trunk/src/components/org/apache/jmeter/visualizers/RenderAsCssJQuery.java (added)
+++ jmeter/trunk/src/components/org/apache/jmeter/visualizers/RenderAsCssJQuery.java Mon Feb
18 21:13:37 2013
@@ -0,0 +1,259 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed  under the  License is distributed on an "AS IS" BASIS,
+ * WITHOUT  WARRANTIES OR CONDITIONS  OF ANY KIND, either  express  or
+ * implied.
+ *
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ *
+ */
+package org.apache.jmeter.visualizers;
+
+import java.awt.BorderLayout;
+import java.awt.Color;
+import java.awt.Dimension;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.swing.JButton;
+import javax.swing.JPanel;
+import javax.swing.JScrollPane;
+import javax.swing.JSplitPane;
+import javax.swing.JTabbedPane;
+import javax.swing.JTextArea;
+import javax.swing.border.Border;
+import javax.swing.border.EmptyBorder;
+
+import org.apache.jmeter.extractor.Extractor;
+import org.apache.jmeter.extractor.HtmlExtractor;
+import org.apache.jmeter.samplers.SampleResult;
+import org.apache.jmeter.util.JMeterUtils;
+import org.apache.jorphan.gui.GuiUtils;
+import org.apache.jorphan.gui.JLabeledChoice;
+import org.apache.jorphan.gui.JLabeledTextField;
+
+/**
+ * Implement ResultsRender for CSS/JQuery tester
+ * @since 2.10
+ */
+public class RenderAsCssJQuery implements ResultRenderer, ActionListener {
+
+    private static final String CSSJQUEY_TESTER_COMMAND = "cssjquery_tester"; // $NON-NLS-1$
+
+    private JPanel cssJqueryPane;
+
+    private JTextArea cssJqueryDataField;
+
+    private JLabeledTextField cssJqueryField;
+
+    private JTextArea cssJqueryResultField;
+
+    private JLabeledTextField attributeField;
+
+    private JTabbedPane rightSide;
+
+    private JLabeledChoice cssJqueryLabeledChoice;
+
+    private SampleResult sampleResult = null;
+
+    /** {@inheritDoc} */
+    @Override
+    public void clearData() {
+        this.cssJqueryDataField.setText(""); // $NON-NLS-1$
+        // don't set empty to keep cssJquery
+        // cssJqueryField.setText(""); // $NON-NLS-1$
+        this.cssJqueryResultField.setText(""); // $NON-NLS-1$
+        // don't set empty to keep attribute
+        // this.attributeField.setText(""); // $NON-NLS-1$
+        // don't change impl
+        // this.cssJqueryLabeledChoice.setText(HtmlExtractor.DEFAULT_EXTRACTOR);
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    public void init() {
+        // Create the panels for the cssJquery tab
+        cssJqueryPane = createCssJqueryPanel();
+    }
+
+    /**
+     * Display the response as text or as rendered HTML. Change the text on the
+     * button appropriate to the current display.
+     *
+     * @param e the ActionEvent being processed
+     */
+    @Override
+    public void actionPerformed(ActionEvent e) {
+        String command = e.getActionCommand();
+        if ((sampleResult != null) && (CSSJQUEY_TESTER_COMMAND.equals(command)))
{
+            String response = ViewResultsFullVisualizer.getResponseAsString(sampleResult);
+            executeAndShowCssJqueryTester(response);
+        }
+    }
+
+    /**
+     * Launch cssJquery engine to parse a input text
+     * @param textToParse
+     */
+    private void executeAndShowCssJqueryTester(String textToParse) {
+        if (textToParse != null && textToParse.length() > 0
+                && this.cssJqueryField.getText().length() > 0) {
+            this.cssJqueryResultField.setText(process(textToParse));
+            this.cssJqueryResultField.setCaretPosition(0); // go to first line
+        }
+    }
+
+    private String process(String textToParse) {
+        List<String> result = new ArrayList<String>();
+        Extractor extractor = HtmlExtractor.getExtractorImpl(cssJqueryLabeledChoice.getText());
+        final int nbFound = extractor.extract(
+                cssJqueryField.getText(), attributeField.getText(), -1, textToParse, result,
0, null);
+
+        // Construct a multi-line string with all matches
+        StringBuilder sb = new StringBuilder();
+        sb.append("Match count: ").append(nbFound).append("\n");
+        for (int j = 0; j < nbFound; j++) {
+            String mr = result.get(j);
+            sb.append("Match[").append(j+1).append("]=").append(mr).append("\n");
+        }
+        return sb.toString();
+
+    }
+    /** {@inheritDoc} */
+   @Override
+   public void renderResult(SampleResult sampleResult) {
+       clearData();
+        String response = ViewResultsFullVisualizer.getResponseAsString(sampleResult);
+        cssJqueryDataField.setText(response);
+        cssJqueryDataField.setCaretPosition(0);
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    public void setupTabPane() {
+         // Add cssJquery tester pane
+        if (rightSide.indexOfTab(JMeterUtils.getResString("cssjquery_tester_title")) <
0) { // $NON-NLS-1$
+            rightSide.addTab(JMeterUtils.getResString("cssjquery_tester_title"), cssJqueryPane);
// $NON-NLS-1$
+        }
+        clearData();
+    }
+
+    /**
+     * @return RegExp Tester panel
+     */
+    private JPanel createCssJqueryPanel() {
+        cssJqueryDataField = new JTextArea();
+        cssJqueryDataField.setEditable(false);
+        cssJqueryDataField.setLineWrap(true);
+        cssJqueryDataField.setWrapStyleWord(true);
+
+        JScrollPane cssJqueryDataPane = GuiUtils.makeScrollPane(cssJqueryDataField);
+        cssJqueryDataPane.setMinimumSize(new Dimension(0, 200));
+
+        JPanel pane = new JPanel(new BorderLayout(0, 5));
+
+        JSplitPane mainSplit = new JSplitPane(JSplitPane.VERTICAL_SPLIT,
+                cssJqueryDataPane, createCssJqueryTasksPanel());
+        mainSplit.setDividerLocation(300);
+        pane.add(mainSplit, BorderLayout.CENTER);
+        return pane;
+    }
+
+    private static String[] getImplementations() {
+        return new String[]{
+            HtmlExtractor.EXTRACTOR_JSOUP,
+            HtmlExtractor.EXTRACTOR_JODD,
+            HtmlExtractor.DEFAULT_EXTRACTOR
+        };
+    }
+    /**
+     * Create the CssJquery task pane
+     *
+     * @return CssJquery task pane
+     */
+    private JPanel createCssJqueryTasksPanel() {
+        JPanel cssJqueryActionPanel = new JPanel(new BorderLayout(0, 5));
+        Border margin = new EmptyBorder(5, 5, 0, 5);
+        cssJqueryActionPanel.setBorder(margin);
+        cssJqueryField = new JLabeledTextField(JMeterUtils.getResString("cssjquery_tester_field"));
// $NON-NLS-1$
+        cssJqueryActionPanel.add(cssJqueryField, BorderLayout.WEST);
+        
+        cssJqueryLabeledChoice = new JLabeledChoice(
+                JMeterUtils.getResString("cssjquery_impl"), // $NON-NLS-1$
+                getImplementations()); 
+        cssJqueryActionPanel.add(cssJqueryLabeledChoice, BorderLayout.NORTH);
+        
+        JButton cssJqueryTester = new JButton(JMeterUtils.getResString("cssjquery_tester_button_test"));
// $NON-NLS-1$
+        cssJqueryTester.setActionCommand(CSSJQUEY_TESTER_COMMAND);
+        cssJqueryTester.addActionListener(this);
+        cssJqueryActionPanel.add(cssJqueryTester, BorderLayout.EAST);
+        
+        attributeField = new JLabeledTextField(JMeterUtils.getResString("cssjquery_attribute"));
// $NON-NLS-1$
+        cssJqueryActionPanel.add(attributeField, BorderLayout.SOUTH);
+
+        cssJqueryResultField = new JTextArea();
+        cssJqueryResultField.setEditable(false);
+        cssJqueryResultField.setLineWrap(true);
+        cssJqueryResultField.setWrapStyleWord(true);
+
+        JPanel cssJqueryTasksPanel = new JPanel(new BorderLayout(0, 5));
+        cssJqueryTasksPanel.add(cssJqueryActionPanel, BorderLayout.NORTH);
+        cssJqueryTasksPanel.add(GuiUtils.makeScrollPane(cssJqueryResultField), BorderLayout.CENTER);
+
+        return cssJqueryTasksPanel;
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    public synchronized void setRightSide(JTabbedPane side) {
+        rightSide = side;
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    public synchronized void setSamplerResult(Object userObject) {
+        if (userObject instanceof SampleResult) {
+            sampleResult = (SampleResult) userObject;
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    public void setLastSelectedTab(int index) {
+        // nothing to do
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    public String toString() {
+        return JMeterUtils.getResString("cssjquery_tester_title"); // $NON-NLS-1$
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    public void renderImage(SampleResult sampleResult) {
+        clearData();
+        cssJqueryDataField.setText(JMeterUtils.getResString("cssjquery_render_no_text"));
// $NON-NLS-1$
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    public void setBackgroundColor(Color backGround) {
+    }
+
+}

Propchange: jmeter/trunk/src/components/org/apache/jmeter/visualizers/RenderAsCssJQuery.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties?rev=1447503&r1=1447502&r2=1447503&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties (original)
+++ jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties Mon Feb 18 21:13:37
2013
@@ -153,6 +153,11 @@ cancel=Cancel
 cancel_exit_to_save=There are test items that have not been saved.  Do you wish to save before
exiting?
 cancel_new_to_save=There are test items that have not been saved.  Do you wish to save before
clearing the test plan?
 cancel_revert_project=There are test items that have not been saved.  Do you wish to revert
to the previously saved test plan?
+cssjquery_attribute=Attribute
+cssjquery_impl=CSS/JQuery implementation
+cssjquery_tester_button_test=Test
+cssjquery_tester_field=Selector
+cssjquery_tester_title=CSS/JQuery Tester
 change_parent=Change Controller
 char_value=Unicode character number (decimal or 0xhex)
 check_return_code_title=Check Return Code

Modified: jmeter/trunk/src/core/org/apache/jmeter/resources/messages_fr.properties
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/resources/messages_fr.properties?rev=1447503&r1=1447502&r2=1447503&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/resources/messages_fr.properties (original)
+++ jmeter/trunk/src/core/org/apache/jmeter/resources/messages_fr.properties Mon Feb 18 21:13:37
2013
@@ -147,6 +147,11 @@ cancel=Annuler
 cancel_exit_to_save=Il y a des \u00E9l\u00E9ments qui n'ont pas \u00E9t\u00E9 sauv\u00E9s.
Voulez-vous enregistrer avant de sortir ?
 cancel_new_to_save=Il y a des \u00E9l\u00E9ments qui n'ont pas \u00E9t\u00E9 sauv\u00E9s.
Voulez-vous enregistrer avant de nettoyer le plan de test ?
 cancel_revert_project=Il y a des \u00E9l\u00E9ments qui n'ont pas \u00E9t\u00E9 sauv\u00E9s.
Annuler les changements et revenir \u00E0 la derni\u00E8re sauvegarde du plan de test ?
+cssjquery_attribute=Attribut
+cssjquery_impl=Impl\u00E9mentation CSS/JQuery
+cssjquery_tester_button_test=Tester
+cssjquery_tester_field=S\u00E9lecteur
+cssjquery_tester_title=Testeur CSS/JQuery
 change_parent=Changer le contr\u00F4leur
 char_value=Caract\u221A\u00AEre num\u221A\u00A9rique Unicode (d\u221A\u00A9cimal or 0xhex)
 check_return_code_title=V\u00E9rifier le code retour

Modified: jmeter/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/jmeter/trunk/xdocs/changes.xml?rev=1447503&r1=1447502&r2=1447503&view=diff
==============================================================================
--- jmeter/trunk/xdocs/changes.xml (original)
+++ jmeter/trunk/xdocs/changes.xml Mon Feb 18 21:13:37 2013
@@ -147,6 +147,7 @@ This does not affect JMeter operation.
 <h3>Listeners</h3>
 <ul>
 <li><bugzilla>54532</bugzilla> - Improve Response Time Graph Y axis scale
with huge values or small values (&lt; 1000ms). Add a new field to define increment scale</li>
+<li><bugzilla>54576</bugzilla> - View Results Tree : Add a CSS/JQuery Tester</li>
 </ul>
 
 <h3>Timers, Assertions, Config, Pre- &amp; Post-Processors</h3>



Mime
View raw message