On 11 March 2016 at 17:53, Philippe Mouawad <[email protected]> wrote: > Hello, > I don't find it clean to have code in class that is here only to allow > Headless testing. > Is it the only way to do that ?
I agree it's not ideal, but AFAICT the simplest way to test classes that use RSyntaxtTextArea is to overload the init() method. An alternative would be to update all those classes to ensure that RSyntaxtTextArea is only invoked in GUI mode. Since the tests need to call createTestElement and modifyTestElement, that would be even more invasive. At least with this fix only two classes are affected (ignoring the one-off change to use a static instance method, which we should possibly have done in the first place). > Can't we instanciate a TestFactory for JSyntaxTextArea instead of putting > that in the business class ? It's not the unit test for JSyntaxTextArea that fails, it's the unit tests for the classes which _use_ it that fail. I don't see how that can be done from the test classes only. If you can, please advise. At least in the meantime, the missing tests are being run. Note: if RSyntaxText is ever fixed, we can drop the exception handling code. Note that many other classes have package-protected methods that are only needed for unit tests. So long as we document this and it does not impact normal running I don't see a problem. > > On Friday, March 11, 2016, <[email protected]> wrote: > >> Author: sebb >> Date: Fri Mar 11 13:38:53 2016 >> New Revision: 1734555 >> >> URL: http://svn.apache.org/viewvc?rev=1734555&view=rev >> Log: >> RSyntaxtTextArea not compatible with headless testing >> Replace calls to constructors with getInstance >> Bugzilla Id: 59165 >> >> Modified: >> >> jmeter/trunk/src/components/org/apache/jmeter/assertions/gui/BeanShellAssertionGui.java >> >> jmeter/trunk/src/components/org/apache/jmeter/assertions/gui/XPathPanel.java >> jmeter/trunk/src/core/org/apache/jmeter/config/gui/RowDetailDialog.java >> jmeter/trunk/src/core/org/apache/jmeter/gui/LoggerPanel.java >> >> jmeter/trunk/src/core/org/apache/jmeter/testbeans/gui/TextAreaEditor.java >> >> jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/config/gui/UrlConfigGui.java >> >> jmeter/trunk/src/protocol/java/org/apache/jmeter/protocol/java/control/gui/BeanShellSamplerGui.java >> >> jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/control/gui/JMSPublisherGui.java >> >> jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/control/gui/JMSSamplerGui.java >> >> jmeter/trunk/src/protocol/tcp/org/apache/jmeter/protocol/tcp/config/gui/TCPConfigGui.java >> >> Modified: >> jmeter/trunk/src/components/org/apache/jmeter/assertions/gui/BeanShellAssertionGui.java >> URL: >> http://svn.apache.org/viewvc/jmeter/trunk/src/components/org/apache/jmeter/assertions/gui/BeanShellAssertionGui.java?rev=1734555&r1=1734554&r2=1734555&view=diff >> >> ============================================================================== >> --- >> jmeter/trunk/src/components/org/apache/jmeter/assertions/gui/BeanShellAssertionGui.java >> (original) >> +++ >> jmeter/trunk/src/components/org/apache/jmeter/assertions/gui/BeanShellAssertionGui.java >> Fri Mar 11 13:38:53 2016 >> @@ -141,14 +141,14 @@ public class BeanShellAssertionGui exten >> } >> >> private JPanel createScriptPanel() { >> - scriptField = new JSyntaxTextArea(20,20); >> + scriptField = JSyntaxTextArea.getInstance(20,20); >> >> JLabel label = new >> JLabel(JMeterUtils.getResString("bsh_assertion_script")); //$NON-NLS-1$ >> label.setLabelFor(scriptField); >> >> JPanel panel = new JPanel(new BorderLayout()); >> panel.add(label, BorderLayout.NORTH); >> - panel.add(new JTextScrollPane(scriptField), BorderLayout.CENTER); >> + panel.add(JTextScrollPane.getInstance(scriptField), >> BorderLayout.CENTER); >> >> JTextArea explain = new >> JTextArea(JMeterUtils.getResString("bsh_assertion_script_variables")); >> //$NON-NLS-1$ >> explain.setLineWrap(true); >> >> Modified: >> jmeter/trunk/src/components/org/apache/jmeter/assertions/gui/XPathPanel.java >> URL: >> http://svn.apache.org/viewvc/jmeter/trunk/src/components/org/apache/jmeter/assertions/gui/XPathPanel.java?rev=1734555&r1=1734554&r2=1734555&view=diff >> >> ============================================================================== >> --- >> jmeter/trunk/src/components/org/apache/jmeter/assertions/gui/XPathPanel.java >> (original) >> +++ >> jmeter/trunk/src/components/org/apache/jmeter/assertions/gui/XPathPanel.java >> Fri Mar 11 13:38:53 2016 >> @@ -64,7 +64,7 @@ public class XPathPanel extends JPanel { >> private void init() { // WARNING: called from ctor so must not be >> overridden (i.e. must be private or final) >> Box hbox = Box.createHorizontalBox(); >> hbox.add(Box.createHorizontalGlue()); >> - hbox.add(new JTextScrollPane(getXPathField())); >> + hbox.add(JTextScrollPane.getInstance(getXPathField())); >> hbox.add(Box.createHorizontalGlue()); >> hbox.add(getCheckXPathButton()); >> >> @@ -161,7 +161,7 @@ public class XPathPanel extends JPanel { >> */ >> public JSyntaxTextArea getXPathField() { >> if (xpath == null) { >> - xpath = new JSyntaxTextArea(20, 80); >> + xpath = JSyntaxTextArea.getInstance(20, 80); >> xpath.setLanguage("xpath"); //$NON-NLS-1$ >> } >> return xpath; >> >> Modified: >> jmeter/trunk/src/core/org/apache/jmeter/config/gui/RowDetailDialog.java >> URL: >> http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/config/gui/RowDetailDialog.java?rev=1734555&r1=1734554&r2=1734555&view=diff >> >> ============================================================================== >> --- >> jmeter/trunk/src/core/org/apache/jmeter/config/gui/RowDetailDialog.java >> (original) >> +++ >> jmeter/trunk/src/core/org/apache/jmeter/config/gui/RowDetailDialog.java Fri >> Mar 11 13:38:53 2016 >> @@ -141,12 +141,12 @@ public class RowDetailDialog extends JDi >> namePane.add(nameTF, BorderLayout.CENTER); >> >> valueLabel = new JLabel(JMeterUtils.getResString("value")); >> //$NON-NLS-1$ >> - valueTA = new JSyntaxTextArea(30, 80); >> + valueTA = JSyntaxTextArea.getInstance(30, 80); >> valueTA.getDocument().addDocumentListener(this); >> setValues(selectedRow); >> JPanel valuePane = new JPanel(new BorderLayout()); >> valuePane.add(valueLabel, BorderLayout.NORTH); >> - JTextScrollPane jTextScrollPane = new JTextScrollPane(valueTA); >> + JTextScrollPane jTextScrollPane = >> JTextScrollPane.getInstance(valueTA); >> valuePane.add(jTextScrollPane, BorderLayout.CENTER); >> >> JPanel detailPanel = new JPanel(new BorderLayout()); >> >> Modified: jmeter/trunk/src/core/org/apache/jmeter/gui/LoggerPanel.java >> URL: >> http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/gui/LoggerPanel.java?rev=1734555&r1=1734554&r2=1734555&view=diff >> >> ============================================================================== >> --- jmeter/trunk/src/core/org/apache/jmeter/gui/LoggerPanel.java (original) >> +++ jmeter/trunk/src/core/org/apache/jmeter/gui/LoggerPanel.java Fri Mar >> 11 13:38:53 2016 >> @@ -70,7 +70,7 @@ public class LoggerPanel extends JPanel >> >> if (JMeterUtils.getPropDefault("loggerpanel.usejsyntaxtext", >> true)) { >> // JSyntax Text Area >> - JSyntaxTextArea jSyntaxTextArea = new JSyntaxTextArea(15, 80, >> true); >> + JSyntaxTextArea jSyntaxTextArea = >> JSyntaxTextArea.getInstance(15, 80, true); >> >> jSyntaxTextArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_NONE); >> jSyntaxTextArea.setCodeFoldingEnabled(false); >> jSyntaxTextArea.setAntiAliasingEnabled(false); >> @@ -78,7 +78,7 @@ public class LoggerPanel extends JPanel >> jSyntaxTextArea.setLineWrap(false); >> jSyntaxTextArea.setLanguage("text"); >> jSyntaxTextArea.setMargin(new Insets(2, 2, 2, 2)); // space >> between borders and text >> - areaScrollPane = new JTextScrollPane(jSyntaxTextArea); >> + areaScrollPane = JTextScrollPane.getInstance(jSyntaxTextArea); >> jTextArea = jSyntaxTextArea; >> } else { >> // Plain text area >> >> Modified: >> jmeter/trunk/src/core/org/apache/jmeter/testbeans/gui/TextAreaEditor.java >> URL: >> http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/testbeans/gui/TextAreaEditor.java?rev=1734555&r1=1734554&r2=1734555&view=diff >> >> ============================================================================== >> --- >> jmeter/trunk/src/core/org/apache/jmeter/testbeans/gui/TextAreaEditor.java >> (original) >> +++ >> jmeter/trunk/src/core/org/apache/jmeter/testbeans/gui/TextAreaEditor.java >> Fri Mar 11 13:38:53 2016 >> @@ -59,8 +59,8 @@ public class TextAreaEditor extends Prop >> */ >> public TextAreaEditor() { >> super(); >> - textUI = new JSyntaxTextArea(20, 20); >> - scroller = new JTextScrollPane(textUI, true); >> + textUI = JSyntaxTextArea.getInstance(20, 20); >> + scroller = JTextScrollPane.getInstance(textUI, true); >> init(); >> } >> >> @@ -70,8 +70,8 @@ public class TextAreaEditor extends Prop >> // TODO is this ever used? >> public TextAreaEditor(Object source) { >> super(source); >> - textUI = new JSyntaxTextArea(20, 20); >> - scroller = new JTextScrollPane(textUI, true); >> + textUI = JSyntaxTextArea.getInstance(20, 20); >> + scroller = JTextScrollPane.getInstance(textUI, true); >> init(); >> setValue(source); >> } >> @@ -84,9 +84,9 @@ public class TextAreaEditor extends Prop >> * to be used for the editor. Must not be <code>null</code> >> */ >> public TextAreaEditor(PropertyDescriptor descriptor) { >> - textUI = new JSyntaxTextArea(20, 20); >> + textUI = JSyntaxTextArea.getInstance(20, 20); >> textUI.setLanguage((String) >> descriptor.getValue(GenericTestBeanCustomizer.TEXT_LANGUAGE)); >> - scroller = new JTextScrollPane(textUI, true); >> + scroller = JTextScrollPane.getInstance(textUI, true); >> init(); >> } >> >> >> Modified: >> jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/config/gui/UrlConfigGui.java >> URL: >> http://svn.apache.org/viewvc/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/config/gui/UrlConfigGui.java?rev=1734555&r1=1734554&r2=1734555&view=diff >> >> ============================================================================== >> --- >> jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/config/gui/UrlConfigGui.java >> (original) >> +++ >> jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/config/gui/UrlConfigGui.java >> Fri Mar 11 13:38:53 2016 >> @@ -660,8 +660,8 @@ public class UrlConfigGui extends JPanel >> int indx = TAB_PARAMETERS; >> if(showRawBodyPane) { >> tabRawBodyIndex = ++indx; >> - postBodyContent = new JSyntaxTextArea(30, 50);// $NON-NLS-1$ >> - >> postContentTabbedPane.add(JMeterUtils.getResString("post_body"), new >> JTextScrollPane(postBodyContent));// $NON-NLS-1$ >> + postBodyContent = JSyntaxTextArea.getInstance(30, 50);// >> $NON-NLS-1$ >> + >> postContentTabbedPane.add(JMeterUtils.getResString("post_body"), >> JTextScrollPane.getInstance(postBodyContent));// $NON-NLS-1$ >> } >> >> if(showFileUploadPane) { >> >> Modified: >> jmeter/trunk/src/protocol/java/org/apache/jmeter/protocol/java/control/gui/BeanShellSamplerGui.java >> URL: >> http://svn.apache.org/viewvc/jmeter/trunk/src/protocol/java/org/apache/jmeter/protocol/java/control/gui/BeanShellSamplerGui.java?rev=1734555&r1=1734554&r2=1734555&view=diff >> >> ============================================================================== >> --- >> jmeter/trunk/src/protocol/java/org/apache/jmeter/protocol/java/control/gui/BeanShellSamplerGui.java >> (original) >> +++ >> jmeter/trunk/src/protocol/java/org/apache/jmeter/protocol/java/control/gui/BeanShellSamplerGui.java >> Fri Mar 11 13:38:53 2016 >> @@ -155,14 +155,14 @@ public class BeanShellSamplerGui extends >> } >> >> private JPanel createScriptPanel() { >> - scriptField = new JSyntaxTextArea(20, 20); >> + scriptField = JSyntaxTextArea.getInstance(20, 20); >> >> JLabel label = new >> JLabel(JMeterUtils.getResString("bsh_script")); // $NON-NLS-1$ >> label.setLabelFor(scriptField); >> >> JPanel panel = new JPanel(new BorderLayout()); >> panel.add(label, BorderLayout.NORTH); >> - panel.add(new JTextScrollPane(scriptField), BorderLayout.CENTER); >> + panel.add(JTextScrollPane.getInstance(scriptField), >> BorderLayout.CENTER); >> >> JTextArea explain = new >> JTextArea(JMeterUtils.getResString("bsh_script_variables")); //$NON-NLS-1$ >> explain.setLineWrap(true); >> >> Modified: >> jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/control/gui/JMSPublisherGui.java >> URL: >> http://svn.apache.org/viewvc/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/control/gui/JMSPublisherGui.java?rev=1734555&r1=1734554&r2=1734555&view=diff >> >> ============================================================================== >> --- >> jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/control/gui/JMSPublisherGui.java >> (original) >> +++ >> jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/control/gui/JMSPublisherGui.java >> Fri Mar 11 13:38:53 2016 >> @@ -106,7 +106,7 @@ public class JMSPublisherGui extends Abs >> >> private final FilePanel randomFile = new >> FilePanel(JMeterUtils.getResString("jms_random_file"), ALL_FILES); >> //$NON-NLS-1$ >> >> - private final JSyntaxTextArea textMessage = new JSyntaxTextArea(10, >> 50); // $NON-NLS-1$ >> + private final JSyntaxTextArea textMessage = >> JSyntaxTextArea.getInstance(10, 50); // $NON-NLS-1$ >> >> private final JLabeledRadioI18N msgChoice = new >> JLabeledRadioI18N("jms_message_type", MSGTYPES_ITEMS, TEXT_MSG_RSC); >> //$NON-NLS-1$ >> >> @@ -220,7 +220,7 @@ public class JMSPublisherGui extends Abs >> >> JPanel messageContentPanel = new JPanel(new BorderLayout()); >> messageContentPanel.add(new >> JLabel(JMeterUtils.getResString("jms_text_area")), BorderLayout.NORTH); >> - messageContentPanel.add(new JTextScrollPane(textMessage), >> BorderLayout.CENTER); >> + messageContentPanel.add(JTextScrollPane.getInstance(textMessage), >> BorderLayout.CENTER); >> >> mainPanel.add(messageContentPanel); >> useProperties.addChangeListener(this); >> >> Modified: >> jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/control/gui/JMSSamplerGui.java >> URL: >> http://svn.apache.org/viewvc/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/control/gui/JMSSamplerGui.java?rev=1734555&r1=1734554&r2=1734555&view=diff >> >> ============================================================================== >> --- >> jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/control/gui/JMSSamplerGui.java >> (original) >> +++ >> jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/control/gui/JMSSamplerGui.java >> Fri Mar 11 13:38:53 2016 >> @@ -64,7 +64,7 @@ public class JMSSamplerGui extends Abstr >> >> private JLabeledTextField jmsSelector = new >> JLabeledTextField(JMeterUtils.getResString("jms_selector")); //$NON-NLS-1$ >> >> - private JSyntaxTextArea messageContent = new JSyntaxTextArea(10, 50); >> //$NON-NLS-1$ >> + private JSyntaxTextArea messageContent = >> JSyntaxTextArea.getInstance(10, 50); //$NON-NLS-1$ >> >> private JLabeledTextField initialContextFactory = new >> JLabeledTextField( >> JMeterUtils.getResString("jms_initial_context_factory")); >> //$NON-NLS-1$ >> @@ -257,7 +257,7 @@ public class JMSSamplerGui extends Abstr >> >> JPanel messageContentPanel = new JPanel(new BorderLayout()); >> messageContentPanel.add(new >> JLabel(JMeterUtils.getResString("jms_msg_content")), BorderLayout.NORTH); >> - messageContentPanel.add(new JTextScrollPane(messageContent), >> BorderLayout.CENTER); >> + >> messageContentPanel.add(JTextScrollPane.getInstance(messageContent), >> BorderLayout.CENTER); >> messagePanel.add(messageContentPanel, BorderLayout.CENTER); >> >> jmsPropertiesPanel = new JMSPropertiesPanel(); //$NON-NLS-1$ >> >> Modified: >> jmeter/trunk/src/protocol/tcp/org/apache/jmeter/protocol/tcp/config/gui/TCPConfigGui.java >> URL: >> http://svn.apache.org/viewvc/jmeter/trunk/src/protocol/tcp/org/apache/jmeter/protocol/tcp/config/gui/TCPConfigGui.java?rev=1734555&r1=1734554&r2=1734555&view=diff >> >> ============================================================================== >> --- >> jmeter/trunk/src/protocol/tcp/org/apache/jmeter/protocol/tcp/config/gui/TCPConfigGui.java >> (original) >> +++ >> jmeter/trunk/src/protocol/tcp/org/apache/jmeter/protocol/tcp/config/gui/TCPConfigGui.java >> Fri Mar 11 13:38:53 2016 >> @@ -219,7 +219,7 @@ public class TCPConfigGui extends Abstra >> >> private JPanel createRequestPanel() { >> JLabel reqLabel = new >> JLabel(JMeterUtils.getResString("tcp_request_data")); // $NON-NLS-1$ >> - requestData = new JSyntaxTextArea(15, 80); >> + requestData = JSyntaxTextArea.getInstance(15, 80); >> requestData.setLanguage("text"); //$NON-NLS-1$ >> reqLabel.setLabelFor(requestData); >> >> @@ -227,7 +227,7 @@ public class TCPConfigGui extends Abstra >> >> >> reqDataPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder())); >> >> reqDataPanel.add(reqLabel, BorderLayout.WEST); >> - reqDataPanel.add(new JTextScrollPane(requestData), >> BorderLayout.CENTER); >> + reqDataPanel.add(JTextScrollPane.getInstance(requestData), >> BorderLayout.CENTER); >> return reqDataPanel; >> } >> >> >> >> > > -- > Cordialement. > Philippe Mouawad.
