/**
 * File: LoginTest.java 27.05.2014, 12:44:50, author: mreinhardt
 * 
 * Project: OwnCloud
 *
 * https://www.martinreinhardt-online.de/apps
 */
package de.martinreinhardt.owncloud.webtest.tests;

import static org.junit.Assert.assertEquals;

import java.util.Properties;

import javax.mail.Message.RecipientType;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

import net.thucydides.core.annotations.Steps;

import com.icegreen.greenmail.user.GreenMailUser;
import com.icegreen.greenmail.user.UserException;
import com.icegreen.greenmail.util.GreenMail;
import com.icegreen.greenmail.util.ServerSetupTest;

import de.martinreinhardt.owncloud.webtest.steps.LoggedInUserSteps;
import de.martinreinhardt.owncloud.webtest.steps.RoundCubeSteps;
import de.martinreinhardt.owncloud.webtest.util.AbstractUITest;
import de.martinreinhardt.owncloud.webtest.util.EmailUserDetails;

/**
 * @author mreinhardt
 * 
 */
public abstract class RoundCubeMockedMailTest extends AbstractUITest {

	/**
	 * 
	 */
	protected static final String TEST_MAIL_SUBJECT = "RoundCube App";

	@Steps
	protected LoggedInUserSteps loggedInuserSteps;

	@Steps
	protected RoundCubeSteps appSteps;

	public void runEmailTest() throws AddressException, MessagingException,
			UserException {

		GreenMail server = new GreenMail(ServerSetupTest.ALL);
		server.start();

		EmailUserDetails userDtls = getEmailUserDetailsTest();

		final MimeMessage msg = new MimeMessage((Session) null);
		msg.setSubject(TEST_MAIL_SUBJECT);
		// msg.setFrom("from@sender.com");
		msg.setText("Some text here ...");
		msg.setRecipient(RecipientType.TO,
				new InternetAddress(userDtls.getEmail()));
		Properties props = new Properties();
		props.put("mail.store.protocol", "imap");
		props.put("mail.host", "localhost");
		props.put("mail.imap.port", "3143");

		GreenMailUser user = server.setUser(userDtls.getEmail(),
				userDtls.getUsername(), userDtls.getPassword());
		user.deliver(msg);
		assertEquals(1, server.getReceivedMessages().length);
		executeTestStepsFrontend();
	}

	public abstract EmailUserDetails getEmailUserDetailsTest();

	public abstract void executeTestStepsFrontend();
}

@@ -1419,16 +1419,42 @@
 server =
+ null;%0A%09%09try %7B%0A%09%09%09server =
  new Gre
@@ -1484,16 +1484,17 @@
 ALL);%0A%09%09
+%09
 server.s
@@ -1502,16 +1502,17 @@
 art();%0A%0A
+%09
 %09%09EmailU
@@ -1563,16 +1563,17 @@
 t();%0A%0A%09%09
+%09
 final Mi
@@ -1621,16 +1621,17 @@
  null);%0A
+%09
 %09%09msg.se
@@ -1661,16 +1661,17 @@
 ECT);%0A%09%09
+%09
 // msg.s
@@ -1693,24 +1693,25 @@
 nder.com%22);%0A
+%09
 %09%09msg.setTex
@@ -1737,16 +1737,17 @@
 ..%22);%0A%09%09
+%09
 msg.setR
@@ -1773,16 +1773,17 @@
 ype.TO,%0A
+%09
 %09%09%09%09new 
@@ -1821,16 +1821,17 @@
 il()));%0A
+%09
 %09%09Proper
@@ -1859,24 +1859,25 @@
 erties();%0A%09%09
+%09
 props.put(%22m
@@ -1902,24 +1902,25 @@
 %22, %22imap%22);%0A
+%09
 %09%09props.put(
@@ -1948,16 +1948,17 @@
 st%22);%0A%09%09
+%09
 props.pu
@@ -1987,16 +1987,17 @@
 143%22);%0A%0A
+%09
 %09%09GreenM
@@ -2051,16 +2051,17 @@
 (),%0A%09%09%09%09
+%09
 userDtls
@@ -2103,16 +2103,17 @@
 d());%0A%09%09
+%09
 user.del
@@ -2123,16 +2123,17 @@
 r(msg);%0A
+%09
 %09%09assert
@@ -2182,16 +2182,17 @@
 gth);%0A%09%09
+%09
 executeT
@@ -2211,16 +2211,83 @@
 tend();%0A
+%09%09%7D finally %7B%0A%09%09%09if (server != null) %7B%0A%09%09%09%09server.stop();%0A%09%09%09%7D%0A%09%09%7D%0A
 %09%7D%0A%0A%09pub

improve Ui tests