import java.net.ServerSocket;
import java.net.Socket;
import java.net.SocketTimeoutException;
-import java.security.Key;
-import java.security.cert.Certificate;
import java.util.Properties;
/**
* This class intercepts emails so that the test cases can evaluate them
* automatically.
*/
-public class TestEmailProvider extends EmailProvider {
+public class TestEmailProvider extends DelegateMailProvider {
private ServerSocket servs;
private DataInputStream in;
- private EmailProvider target;
-
protected TestEmailProvider(Properties props) {
- try {
- String name = props.getProperty("emailProvider.test.target");
- if (name != null) {
- Class<?> c = Class.forName(name);
- target = (EmailProvider) c.getDeclaredConstructor(Properties.class).newInstance(props);
- }
- } catch (ReflectiveOperationException e) {
- e.printStackTrace();
- }
+ super(props, props.getProperty("emailProvider.test.target"));
try {
servs = new ServerSocket(Integer.parseInt(props.getProperty("emailProvider.port")), 10, InetAddress.getByName("127.0.0.1"));
} catch (IOException e) {
}
@Override
- public synchronized void sendmail(String to, String subject, String message, String from, String replyto, String toname, String fromname, String errorsto, boolean extra) throws IOException {
+ public synchronized void sendMail(String to, String subject, String message, String replyto, String toname, String fromname, String errorsto, boolean extra) throws IOException {
while (true) {
- if ( !assureLocalConnection() && target != null) {
- target.sendmail(to, subject, message, from, replyto, toname, fromname, errorsto, extra);
+ if ( !ensureLocalConnection() && getTarget() != null) {
+ super.sendMail(to, subject, message, replyto, toname, fromname, errorsto, extra);
return;
}
try {
write(to);
write(subject);
write(message);
- write(from);
write(replyto);
out.flush();
return;
}
}
- private boolean assureLocalConnection() throws IOException {
+ private boolean ensureLocalConnection() throws IOException {
if (out != null) {
try {
out.writeUTF("ping");
@Override
public synchronized String checkEmailServer(int forUid, String address) throws IOException {
while (true) {
- if ( !assureLocalConnection() && target != null) {
- return checkEmailServer(forUid, address);
+ if ( !ensureLocalConnection() && getTarget() != null) {
+ return super.checkEmailServer(forUid, address);
}
try {
out.writeUTF("challengeAddrBox");
out.writeUTF(to);
}
}
-
- @Override
- protected void init(Certificate c, Key k) {
- super.init(c, k);
- if (target != null) {
- target.init(c, k);
- }
- }
}