You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jmeter.apache.org by pm...@apache.org on 2018/11/23 11:22:00 UTC
svn commit: r1847247 - in /jmeter/trunk:
src/protocol/mail/org/apache/jmeter/protocol/mail/sampler/
test/src/org/apache/jmeter/protocol/mail/
test/src/org/apache/jmeter/protocol/mail/sampler/ xdocs/ xdocs/usermanual/
Author: pmouawad
Date: Fri Nov 23 11:22:00 2018
New Revision: 1847247
URL: http://svn.apache.org/viewvc?rev=1847247&view=rev
Log:
Bug 62935 - Pass custom 'mail.*' properties to Mail Reader Sampler
Implemented by Artem Fedorov (artem.fedorov at blazemeter.com) and contributed by BlazeMeter
This closes #433
Bugzilla Id: 62935
Added:
jmeter/trunk/test/src/org/apache/jmeter/protocol/mail/
jmeter/trunk/test/src/org/apache/jmeter/protocol/mail/sampler/
jmeter/trunk/test/src/org/apache/jmeter/protocol/mail/sampler/TestMailReaderSampler.java (with props)
Modified:
jmeter/trunk/src/protocol/mail/org/apache/jmeter/protocol/mail/sampler/MailReaderSampler.java
jmeter/trunk/xdocs/changes.xml
jmeter/trunk/xdocs/usermanual/component_reference.xml
Modified: jmeter/trunk/src/protocol/mail/org/apache/jmeter/protocol/mail/sampler/MailReaderSampler.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/protocol/mail/org/apache/jmeter/protocol/mail/sampler/MailReaderSampler.java?rev=1847247&r1=1847246&r2=1847247&view=diff
==============================================================================
--- jmeter/trunk/src/protocol/mail/org/apache/jmeter/protocol/mail/sampler/MailReaderSampler.java (original)
+++ jmeter/trunk/src/protocol/mail/org/apache/jmeter/protocol/mail/sampler/MailReaderSampler.java Fri Nov 23 11:22:00 2018
@@ -54,6 +54,7 @@ import org.apache.jmeter.testelement.Tes
import org.apache.jmeter.testelement.property.BooleanProperty;
import org.apache.jmeter.testelement.property.IntegerProperty;
import org.apache.jmeter.testelement.property.StringProperty;
+import org.apache.jmeter.util.JMeterUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -202,6 +203,7 @@ public class MailReaderSampler extends A
props.put(mailProp(serverProtocol, "ssl.socketFactory.fallback"), FALSE); // $NON-NLS-1$
}
}
+ addCustomProperties(props);
// Get session
Session session = Session.getInstance(props, null);
@@ -313,6 +315,19 @@ public class MailReaderSampler extends A
return parent;
}
+ protected void addCustomProperties(Properties props) {
+ Properties jMeterProperties = JMeterUtils.getJMeterProperties();
+ @SuppressWarnings("unchecked")
+ Enumeration<String> enums = (Enumeration<String>) jMeterProperties.propertyNames();
+ while (enums.hasMoreElements()) {
+ String key = enums.nextElement();
+ if (key.startsWith("mail.")) {
+ String value = jMeterProperties.getProperty(key);
+ props.put(key, value);
+ }
+ }
+ }
+
private void appendMessageData(SampleResult child, Message message)
throws MessagingException, IOException {
StringBuilder cdata = new StringBuilder();
Added: jmeter/trunk/test/src/org/apache/jmeter/protocol/mail/sampler/TestMailReaderSampler.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/test/src/org/apache/jmeter/protocol/mail/sampler/TestMailReaderSampler.java?rev=1847247&view=auto
==============================================================================
--- jmeter/trunk/test/src/org/apache/jmeter/protocol/mail/sampler/TestMailReaderSampler.java (added)
+++ jmeter/trunk/test/src/org/apache/jmeter/protocol/mail/sampler/TestMailReaderSampler.java Fri Nov 23 11:22:00 2018
@@ -0,0 +1,58 @@
+/*
+ * 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.protocol.mail.sampler;
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Locale;
+import java.util.Properties;
+
+import org.apache.jmeter.util.JMeterUtils;
+import org.junit.Test;
+
+public class TestMailReaderSampler {
+
+ public static void createJMeterEnv() {
+ File propsFile;
+ try {
+ propsFile = File.createTempFile("jmeter", ".properties");
+ propsFile.deleteOnExit();
+ JMeterUtils.loadJMeterProperties(propsFile.getAbsolutePath());
+ } catch (IOException ex) {
+ ex.printStackTrace(System.err);
+ }
+ JMeterUtils.setLocale(new Locale("ignoreResources"));
+ }
+
+ @Test
+ public void testPassCustomProperties() {
+ createJMeterEnv();
+ Properties jMeterProperties = JMeterUtils.getJMeterProperties();
+ jMeterProperties.put("prop1.name", "prop1.value");
+ jMeterProperties.put("mail.prop2.name", "mail.prop2.value");
+
+ MailReaderSampler sampler = new MailReaderSampler();
+ Properties properties = new Properties();
+ sampler.addCustomProperties(properties);
+ assertEquals(1, properties.size());
+ assertEquals("mail.prop2.value", properties.getProperty("mail.prop2.name"));
+ }
+}
Propchange: jmeter/trunk/test/src/org/apache/jmeter/protocol/mail/sampler/TestMailReaderSampler.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jmeter/trunk/test/src/org/apache/jmeter/protocol/mail/sampler/TestMailReaderSampler.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: jmeter/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/jmeter/trunk/xdocs/changes.xml?rev=1847247&r1=1847246&r2=1847247&view=diff
==============================================================================
--- jmeter/trunk/xdocs/changes.xml [utf-8] (original)
+++ jmeter/trunk/xdocs/changes.xml [utf-8] Fri Nov 23 11:22:00 2018
@@ -84,6 +84,7 @@ of previous time slot as a base. Startin
<h3>Other samplers</h3>
<ul>
<li><bug>62934</bug>Add compatibility for JDBC drivers that do not support QueryTimeout </li>
+ <li><bug>62935</bug>Pass custom <code>mail.*</code> properties to Mail Reader Sampler. Implemented by Artem Fedorov (artem.fedorov at blazemeter.com) and contributed by BlazeMeter.</li>
</ul>
<h3>Controllers</h3>
Modified: jmeter/trunk/xdocs/usermanual/component_reference.xml
URL: http://svn.apache.org/viewvc/jmeter/trunk/xdocs/usermanual/component_reference.xml?rev=1847247&r1=1847246&r2=1847247&view=diff
==============================================================================
--- jmeter/trunk/xdocs/usermanual/component_reference.xml (original)
+++ jmeter/trunk/xdocs/usermanual/component_reference.xml Fri Nov 23 11:22:00 2018
@@ -1733,6 +1733,7 @@ Relative paths are resolved against the
<br />Failing that, against the directory containing the test script (JMX file).
</property>
</properties>
+<note>You can pass mail related environment properties by adding to user.properties any of the properties described <a href="https://javaee.github.io/javamail/docs/api/com/sun/mail/pop3/package-summary.html">here</a>.</note>
<p>
Messages are stored as subsamples of the main sampler.
Multipart message parts are stored as subsamples of the message.