Add and wire up greenmail for mocking up a server
diff --git a/pom.xml b/pom.xml
index ec9564b..a487d3f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -109,6 +109,20 @@
</dependency>
<dependency>
+ <groupId>com.icegreen</groupId>
+ <artifactId>greenmail-standalone</artifactId>
+ <version>1.5.10</version>
+ </dependency>
+
+ <dependency>
+ <groupId>com.sun.javaee.tck</groupId>
+ <artifactId>javamail</artifactId>
+ <version>${javaee.tck.version}</version>
+ <scope>system</scope>
+ <systemPath>${javaee.cts.home}/dist/com/sun/ts/tests/javamail/ee/internetaddress/internetaddress_appclient_vehicle_client.jar</systemPath>
+ </dependency>
+
+ <dependency>
<groupId>com.sun.javaee.tck</groupId>
<artifactId>tsharness</artifactId>
<version>${javaee.tck.version}</version>
@@ -746,16 +760,27 @@
<goals>
<goal>java</goal>
</goals>
+ <configuration>
+ <cleanupDaemonThreads>false</cleanupDaemonThreads>
+ <killAfter>-1</killAfter>
+ <arguments>
+ <argument>${derby.server.port}</argument>
+ </arguments>
+ <mainClass>org.apache.openejb.cts.DerbyRunner</mainClass>
+ </configuration>
+ </execution>
+ <execution>
+ <id>start-greenmail</id>
+ <phase>pre-integration-test</phase>
+ <goals>
+ <goal>java</goal>
+ </goals>
+ <configuration>
+ <cleanupDaemonThreads>false</cleanupDaemonThreads>
+ <mainClass>org.apache.openejb.cts.GreenmailRunner</mainClass>
+ </configuration>
</execution>
</executions>
- <configuration>
- <cleanupDaemonThreads>false</cleanupDaemonThreads>
- <killAfter>-1</killAfter>
- <arguments>
- <argument>${derby.server.port}</argument>
- </arguments>
- <mainClass>org.apache.openejb.cts.DerbyRunner</mainClass>
- </configuration>
</plugin>
<plugin>
@@ -806,7 +831,7 @@
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>true</overWriteSnapshots>
<excludeTransitive>true</excludeTransitive>
- <includeArtifactIds>openejb-lite,activemq-client,activemq-client,tsharness,cts,whitebox,dbprocedures,geronimo-mail,openejb-derbynet,derby,derbynet,derbyclient,webdeployer</includeArtifactIds>
+ <includeArtifactIds>activemq-client,activemq-client,tsharness,cts,whitebox,dbprocedures,geronimo-mail,openejb-derbynet,derby,derbynet,derbyclient,webdeployer</includeArtifactIds>
</configuration>
</execution>
</executions>
diff --git a/src/main/java/org/apache/openejb/cts/DerbyRunner.java b/src/main/java/org/apache/openejb/cts/DerbyRunner.java
index 99aa2dd..65b0e29 100644
--- a/src/main/java/org/apache/openejb/cts/DerbyRunner.java
+++ b/src/main/java/org/apache/openejb/cts/DerbyRunner.java
@@ -26,10 +26,9 @@
public class DerbyRunner {
private static class DerbyThread extends Thread {
- private static final Logger log = Logger.getLogger(DerbyRunner.class);
private static final int SLEEP_INTERVAL = 60000;
+ private final int port;
private NetworkServerControl serverControl;
- private int port = NetworkServerControl.DEFAULT_PORTNUMBER;
public DerbyThread(final int derbyPort) {
port = derbyPort;
@@ -40,6 +39,7 @@
try {
serverControl = new NetworkServerControl(InetAddress.getByAddress(new byte[]{127, 0, 0, 1}), port);
serverControl.start(new Log4jPrintWriter("Derby", Level.INFO));
+
} catch (final Exception e) {
e.printStackTrace();
}
diff --git a/src/main/java/org/apache/openejb/cts/GreenmailRunner.java b/src/main/java/org/apache/openejb/cts/GreenmailRunner.java
new file mode 100644
index 0000000..dcfe624
--- /dev/null
+++ b/src/main/java/org/apache/openejb/cts/GreenmailRunner.java
@@ -0,0 +1,93 @@
+/**
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.openejb.cts;
+
+import com.icegreen.greenmail.standalone.GreenMailStandaloneRunner;
+import org.apache.derby.drda.NetworkServerControl;
+import org.apache.log4j.Level;
+import org.apache.openejb.testng.PropertiesBuilder;
+import org.apache.openejb.util.Join;
+import org.apache.openejb.util.Log4jPrintWriter;
+
+import java.net.InetAddress;
+import java.util.Properties;
+
+public class GreenmailRunner {
+
+ private static class GreenmailThread extends Thread {
+ private static final int SLEEP_INTERVAL = 60000;
+ private final int smtp;
+ private final int imap;
+ private GreenMailStandaloneRunner greenMailStandaloneRunner;
+
+ public GreenmailThread(final int smtp, final int imap) {
+ this.smtp = smtp;
+ this.imap = imap;
+ }
+
+ public void run() {
+ System.out.println(String.format("Starting greenmail with imap port %s and smtp port %s", imap, smtp));
+ try {
+
+ final Properties properties = new PropertiesBuilder()
+ .p("greenmail.verbose", "true")
+ .p("greenmail.setup.test.smtp", "true")
+ .p("greenmail.setup.test.imap", "true")
+ .p("greenmail.auth.disabled", "true")
+ .p("greenmail.users", "foo@foo.com")
+ .build();
+
+
+ greenMailStandaloneRunner = new GreenMailStandaloneRunner();
+ greenMailStandaloneRunner.doRun(properties);
+
+ } catch (final Exception e) {
+ e.printStackTrace();
+ }
+
+ while (true) {
+ try {
+ Thread.sleep(SLEEP_INTERVAL);
+ } catch (final InterruptedException e) {
+ break;
+ }
+ }
+
+ System.out.println("Embedded greenmail thread stopping");
+ }
+
+ }
+
+
+ public static void main(final String[] args) {
+ int smtp = 25;
+ int imap = 143;
+ if (args.length == 2) {
+ try {
+ smtp = Integer.parseInt(args[0]);
+ imap = Integer.parseInt(args[1]);
+ } catch (final NumberFormatException e) {
+ System.out.println(String.format("Could not convert ports %s. Using the default smtp %s and imap %s",
+ Join.join(", ", args), smtp, imap));
+ }
+ }
+ final GreenmailThread thread = new GreenmailThread(smtp, imap);
+ thread.setDaemon(true);
+ thread.setName("GreenmailServerDaemon");
+ thread.start();
+ }
+}
diff --git a/src/test/resources/testsuite.properties b/src/test/resources/testsuite.properties
index ded4f26..d269fa1 100644
--- a/src/test/resources/testsuite.properties
+++ b/src/test/resources/testsuite.properties
@@ -222,3 +222,7 @@
javatest.timeout.factor=3.0
+
+imap.port = 3143
+smtp.port = 3025
+javamail.mailbox = INBOX