You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@syncope.apache.org by il...@apache.org on 2012/05/28 17:02:18 UTC
svn commit: r1343276 - in /incubator/syncope/trunk: core/pom.xml
core/src/test/java/org/apache/syncope/core/notification/
core/src/test/java/org/apache/syncope/core/notification/NotificationTest.java
core/src/test/notifications/ parent/pom.xml
Author: ilgrosso
Date: Mon May 28 15:02:18 2012
New Revision: 1343276
URL: http://svn.apache.org/viewvc?rev=1343276&view=rev
Log:
After syncope-idm.org decommissioning, moving NotificationTest as standard test: thanks to GreenMail, no real SMPT / POP3 server is needed anymore
Added:
incubator/syncope/trunk/core/src/test/java/org/apache/syncope/core/notification/
incubator/syncope/trunk/core/src/test/java/org/apache/syncope/core/notification/NotificationTest.java
- copied, changed from r1343151, incubator/syncope/trunk/core/src/test/notifications/java/org/apache/syncope/core/notification/NotificationTest.java
Removed:
incubator/syncope/trunk/core/src/test/notifications/
Modified:
incubator/syncope/trunk/core/pom.xml
incubator/syncope/trunk/parent/pom.xml
Modified: incubator/syncope/trunk/core/pom.xml
URL: http://svn.apache.org/viewvc/incubator/syncope/trunk/core/pom.xml?rev=1343276&r1=1343275&r2=1343276&view=diff
==============================================================================
--- incubator/syncope/trunk/core/pom.xml (original)
+++ incubator/syncope/trunk/core/pom.xml Mon May 28 15:02:18 2012
@@ -327,6 +327,11 @@ under the License.
<artifactId>spring-test</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>com.icegreen</groupId>
+ <artifactId>greenmail</artifactId>
+ <scope>test</scope>
+ </dependency>
<!-- /TEST -->
</dependencies>
@@ -932,100 +937,6 @@ under the License.
</profile>
<profile>
- <id>notification-test</id>
-
- <properties>
- <mail.password />
- </properties>
-
- <build>
- <defaultGoal>clean test</defaultGoal>
-
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-surefire-plugin</artifactId>
- <inherited>true</inherited>
- <configuration>
- <skip>true</skip>
- </configuration>
- <executions>
- <execution>
- <id>notification-test-phase-execution</id>
- <phase>test</phase>
- <goals>
- <goal>test</goal>
- </goals>
- <configuration>
- <skip>false</skip>
- <includes>
- <include>**/notification/**Test.java</include>
- </includes>
- </configuration>
- </execution>
- <execution>
- <id>test-phase-execution</id>
- <phase>test</phase>
- <goals>
- <goal>test</goal>
- </goals>
- <configuration>
- <skip>true</skip>
- </configuration>
- </execution>
- <execution>
- <id>relationship-test-execution</id>
- <phase>test</phase>
- <goals>
- <goal>test</goal>
- </goals>
- <configuration>
- <skip>true</skip>
- </configuration>
- </execution>
- </executions>
- </plugin>
-
- <plugin>
- <groupId>org.codehaus.mojo</groupId>
- <artifactId>build-helper-maven-plugin</artifactId>
- <inherited>true</inherited>
- <executions>
- <execution>
- <id>add-notification-test-source</id>
- <phase>generate-test-sources</phase>
- <goals>
- <goal>add-test-source</goal>
- </goals>
- <configuration>
- <sources>
- <source>src/test/notifications/java</source>
- </sources>
- </configuration>
- </execution>
- </executions>
- </plugin>
- </plugins>
-
- <testResources>
- <testResource>
- <directory>src/test/resources</directory>
- <filtering>true</filtering>
- <excludes>
- <exclude>oracle/**</exclude>
- <exclude>postgres/**</exclude>
- <exclude>mysql/**</exclude>
- </excludes>
- </testResource>
- <testResource>
- <directory>src/test/notifications/resources</directory>
- <filtering>true</filtering>
- </testResource>
- </testResources>
- </build>
- </profile>
-
- <profile>
<id>glassfish-it</id>
<properties>
Copied: incubator/syncope/trunk/core/src/test/java/org/apache/syncope/core/notification/NotificationTest.java (from r1343151, incubator/syncope/trunk/core/src/test/notifications/java/org/apache/syncope/core/notification/NotificationTest.java)
URL: http://svn.apache.org/viewvc/incubator/syncope/trunk/core/src/test/java/org/apache/syncope/core/notification/NotificationTest.java?p2=incubator/syncope/trunk/core/src/test/java/org/apache/syncope/core/notification/NotificationTest.java&p1=incubator/syncope/trunk/core/src/test/notifications/java/org/apache/syncope/core/notification/NotificationTest.java&r1=1343151&r2=1343276&rev=1343276&view=diff
==============================================================================
--- incubator/syncope/trunk/core/src/test/notifications/java/org/apache/syncope/core/notification/NotificationTest.java (original)
+++ incubator/syncope/trunk/core/src/test/java/org/apache/syncope/core/notification/NotificationTest.java Mon May 28 15:02:18 2012
@@ -20,14 +20,10 @@ package org.apache.syncope.core.notifica
import static org.junit.Assert.*;
-import java.io.IOException;
-import java.text.DateFormat;
-import java.text.SimpleDateFormat;
+import com.icegreen.greenmail.util.GreenMail;
+import com.icegreen.greenmail.util.ServerSetup;
import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Date;
import java.util.List;
-import java.util.Properties;
import java.util.Random;
import javax.annotation.Resource;
import javax.mail.Flags.Flag;
@@ -35,10 +31,8 @@ import javax.mail.Folder;
import javax.mail.Message;
import javax.mail.Session;
import javax.mail.Store;
-import org.apache.commons.lang.StringUtils;
import org.apache.syncope.client.search.MembershipCond;
import org.apache.syncope.client.search.NodeCond;
-import org.apache.syncope.client.to.AttributeTO;
import org.apache.syncope.client.to.MembershipTO;
import org.apache.syncope.client.to.UserTO;
import org.apache.syncope.core.persistence.beans.Entitlement;
@@ -49,10 +43,12 @@ import org.apache.syncope.core.persisten
import org.apache.syncope.core.persistence.dao.EntitlementDAO;
import org.apache.syncope.core.persistence.dao.NotificationDAO;
import org.apache.syncope.core.persistence.dao.TaskDAO;
+import org.apache.syncope.core.rest.UserTestITCase;
import org.apache.syncope.core.rest.controller.TaskController;
import org.apache.syncope.core.rest.controller.UserController;
import org.apache.syncope.core.scheduling.NotificationJob;
import org.apache.syncope.types.IntMappingType;
+import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -89,13 +85,19 @@ public class NotificationTest {
*/
private static final Logger LOG = LoggerFactory.getLogger(NotificationTest.class);
- private static String smtpHost;
+ private static String smtpHost = "localhost";
- private static String pop3Host;
+ private static int smtpPort = 2525;
- private static String mailAddress;
+ private static String pop3Host = "localhost";
- private static String mailPassword;
+ private static int pop3Port = 1110;
+
+ private static String mailAddress = "notificationtest@syncope.apache.org";
+
+ private static String mailPassword = "password";
+
+ private static GreenMail greenMail;
@Resource(name = "adminUser")
private String adminUser;
@@ -122,22 +124,19 @@ public class NotificationTest {
private NotificationJob notificationJob;
@BeforeClass
- public static void loadProperties() {
- Properties props = new Properties();
-
- try {
- props.load(NotificationTest.class.getResourceAsStream("/test.properties"));
- } catch (IOException e) {
- LOG.error("Could not load properties", e);
- fail("Could not load test properties");
- }
+ public static void startGreenMail() {
+ ServerSetup[] config = new ServerSetup[2];
+ config[0] = new ServerSetup(smtpPort, smtpHost, ServerSetup.PROTOCOL_SMTP);
+ config[1] = new ServerSetup(pop3Port, pop3Host, ServerSetup.PROTOCOL_POP3);
+ greenMail = new GreenMail(config);
+ greenMail.setUser(mailAddress, mailPassword);
+ greenMail.start();
+ }
- smtpHost = props.getProperty("smtp.host");
- pop3Host = props.getProperty("pop3.host");
- mailAddress = props.getProperty("mail.address");
- mailPassword = props.getProperty("mail.password");
- if (StringUtils.isBlank(mailPassword)) {
- throw new IllegalArgumentException("Empty POP3 password: did you pass -Dmail.password=XXXX?");
+ @AfterClass
+ public static void stopGreenMail() {
+ if (greenMail != null) {
+ greenMail.stop();
}
}
@@ -153,65 +152,10 @@ public class NotificationTest {
SecurityContextHolder.getContext().setAuthentication(authentication);
}
- public static UserTO getSampleTO(final String email) {
- UserTO userTO = new UserTO();
- userTO.setPassword("password123");
- userTO.setUsername(email);
-
- AttributeTO fullnameTO = new AttributeTO();
- fullnameTO.setSchema("fullname");
- fullnameTO.addValue(email);
- userTO.addAttribute(fullnameTO);
-
- AttributeTO firstnameTO = new AttributeTO();
- firstnameTO.setSchema("firstname");
- firstnameTO.addValue(email);
- userTO.addAttribute(firstnameTO);
-
- AttributeTO surnameTO = new AttributeTO();
- surnameTO.setSchema("surname");
- surnameTO.addValue("Surname");
- userTO.addAttribute(surnameTO);
-
- AttributeTO typeTO = new AttributeTO();
- typeTO.setSchema("type");
- typeTO.addValue("a type");
- userTO.addAttribute(typeTO);
-
- AttributeTO userIdTO = new AttributeTO();
- userIdTO.setSchema("userId");
- userIdTO.addValue(email);
- userTO.addAttribute(userIdTO);
-
- AttributeTO emailTO = new AttributeTO();
- emailTO.setSchema("email");
- emailTO.addValue(email);
- userTO.addAttribute(emailTO);
-
- AttributeTO loginDateTO = new AttributeTO();
- loginDateTO.setSchema("loginDate");
- DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
- loginDateTO.addValue(sdf.format(new Date()));
- userTO.addAttribute(loginDateTO);
-
- // add a derived attribute
- AttributeTO cnTO = new AttributeTO();
- cnTO.setSchema("cn");
- userTO.addDerivedAttribute(cnTO);
-
- // add a virtual attribute
- AttributeTO virtualdata = new AttributeTO();
- virtualdata.setSchema("virtualdata");
- virtualdata.setValues(Collections.singletonList("virtualvalue"));
- userTO.addVirtualAttribute(virtualdata);
-
- return userTO;
- }
-
private boolean verifyMail(final String sender, final String subject) {
LOG.info("Waiting for notification to be sent...");
try {
- Thread.sleep(10000);
+ Thread.sleep(1000);
} catch (InterruptedException e) {
}
@@ -219,7 +163,7 @@ public class NotificationTest {
try {
Session session = Session.getDefaultInstance(System.getProperties());
Store store = session.getStore("pop3");
- store.connect(pop3Host, mailAddress, mailPassword);
+ store.connect(pop3Host, pop3Port, mailAddress, mailPassword);
Folder inbox = store.getFolder("INBOX");
assertNotNull(inbox);
@@ -261,7 +205,7 @@ public class NotificationTest {
notification.setRecipientAttrType(IntMappingType.UserSchema);
Random random = new Random(System.currentTimeMillis());
- String sender = "syncopetest-" + random.nextLong() + "@syncope-idm.org";
+ String sender = "syncopetest-" + random.nextLong() + "@syncope.apache.org";
notification.setSender(sender);
String subject = "Test notification " + random.nextLong();
notification.setSubject(subject);
@@ -272,20 +216,24 @@ public class NotificationTest {
notificationDAO.flush();
- // 2. use a real SMTP server
+ // 2. use test SMTP server
try {
SyncopeConf smtpHostConf = confDAO.find("smtp.host");
smtpHostConf.setValue(smtpHost);
confDAO.save(smtpHostConf);
+
+ SyncopeConf smtpPortConf = confDAO.find("smtp.port");
+ smtpPortConf.setValue(Integer.toString(smtpPort));
+ confDAO.save(smtpPortConf);
} catch (Exception e) {
LOG.error("Unexpected exception", e);
- fail("Unexpected exception while setting SMTP host");
+ fail("Unexpected exception while setting SMTP host and port");
}
confDAO.flush();
// 3. create user
- UserTO userTO = getSampleTO(mailAddress);
+ UserTO userTO = UserTestITCase.getSampleTO(mailAddress);
MembershipTO membershipTO = new MembershipTO();
membershipTO.setRoleId(7);
userTO.addMembership(membershipTO);
Modified: incubator/syncope/trunk/parent/pom.xml
URL: http://svn.apache.org/viewvc/incubator/syncope/trunk/parent/pom.xml?rev=1343276&r1=1343275&r2=1343276&view=diff
==============================================================================
--- incubator/syncope/trunk/parent/pom.xml (original)
+++ incubator/syncope/trunk/parent/pom.xml Mon May 28 15:02:18 2012
@@ -699,6 +699,12 @@ under the License.
<version>${connid.ldap.version}</version>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>com.icegreen</groupId>
+ <artifactId>greenmail</artifactId>
+ <version>1.3.1b</version>
+ <scope>test</scope>
+ </dependency>
<!-- /TEST -->
</dependencies>