Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'master' of git://github.com/ieb/open-experiments

Conflicts:
	slingtests/osgikernel/bundles/messaging/src/main/java/org/sakaiproject/kernel/api/message/MessageConstants.java
  • Loading branch information...
commit 27578a71e6cfbd76f89abdc1899001296552870f 2 parents cf48d02 + 2ef9b04
Simon Gaeremynck authored
Showing with 1,012 additions and 120 deletions.
  1. +1 −1  slingtests/osgikernel/app-bundles/pom.xml
  2. +1 −1  slingtests/osgikernel/bundles/activity/pom.xml
  3. +2 −2 slingtests/osgikernel/bundles/connections/pom.xml
  4. +2 −2 slingtests/osgikernel/bundles/discussion/pom.xml
  5. +6 −0 slingtests/osgikernel/bundles/email-outgoing/pom.xml
  6. +6 −3 ...kernel/bundles/email-outgoing/src/main/java/org/sakaiproject/kernel/email/outgoing/EmailMessageHandler.java
  7. +80 −54 ...ndles/email-outgoing/src/main/java/org/sakaiproject/kernel/email/outgoing/OutgoingEmailMessageListener.java
  8. +58 −0 ...el/bundles/email-outgoing/src/test/java/org/sakaiproject/kernel/email/outgoing/EmailMessageHandlerTest.java
  9. +24 −14 ...s/email-outgoing/src/test/java/org/sakaiproject/kernel/email/outgoing/OutgoingEmailMessageListenerTest.java
  10. +7 −6 ...gtests/osgikernel/bundles/messaging/src/main/java/org/sakaiproject/kernel/api/message/MessageConstants.java
  11. +37 −0 ...gikernel/bundles/messaging/src/test/java/org/sakaiproject/kernel/message/listener/MessageRouteImplTest.java
  12. +28 −0 ...ikernel/bundles/messaging/src/test/java/org/sakaiproject/kernel/message/listener/MessageRoutesImplTest.java
  13. +77 −0 ...ernel/bundles/messaging/src/test/java/org/sakaiproject/kernel/message/listener/MessageSentListenerTest.java
  14. +1 −1  slingtests/osgikernel/bundles/personal/pom.xml
  15. +4 −0 slingtests/osgikernel/bundles/proxy/src/main/java/org/sakaiproject/kernel/api/proxy/ProxyClientService.java
  16. +14 −3 slingtests/osgikernel/bundles/proxy/src/main/java/org/sakaiproject/kernel/proxy/ProxyClientServiceImpl.java
  17. +4 −7 ...gtests/osgikernel/bundles/proxy/src/main/java/org/sakaiproject/kernel/proxy/velocity/JcrResourceLoader.java
  18. +35 −4 ...gtests/osgikernel/bundles/proxy/src/test/java/org/sakaiproject/kernel/proxy/ProxyClientServiceImplTest.java
  19. +59 −7 ...n/java/org/apache/sling/jcr/jackrabbit/server/impl/security/dynamic/DynamicPrincipalManagerFactoryImpl.java
  20. +30 −2 ...s/server/src/main/java/org/apache/sling/jcr/jackrabbit/server/security/dynamic/DynamicPrincipalManager.java
  21. +2 −1  ...ernel/bundles/site/src/main/resources/SLING-INF/content/templates/interdisciplinary/_pages/all-members.json
  22. +2 −1  ...kernel/bundles/site/src/main/resources/SLING-INF/content/templates/interdisciplinary/_pages/contact-us.json
  23. +2 −1  ...rnel/bundles/site/src/main/resources/SLING-INF/content/templates/interdisciplinary/_pages/introduction.json
  24. +2 −1  ...ernel/bundles/site/src/main/resources/SLING-INF/content/templates/interdisciplinary/_pages/latest-news.json
  25. +2 −1  slingtests/osgikernel/bundles/site/src/main/resources/SLING-INF/content/templates/template/_pages/welcome.json
  26. +2 −2 slingtests/osgikernel/bundles/sling/api/pom.xml
  27. +1 −1  slingtests/osgikernel/bundles/sling/resource/pom.xml
  28. +18 −0 ...sts/osgikernel/bundles/user/src/main/java/org/sakaiproject/kernel/user/owner/OwnerPrincipalManagerImpl.java
  29. +16 −3 slingtests/osgikernel/libraries/utils/src/main/java/org/sakaiproject/kernel/util/JcrUtils.java
  30. +90 −0 slingtests/osgikernel/libraries/utils/src/main/java/org/sakaiproject/kernel/util/MultiValueInputStream.java
  31. +222 −0 slingtests/osgikernel/libraries/utils/src/test/java/org/sakaiproject/kernel/util/JcrUtilsTest.java
  32. +114 −0 ...gtests/osgikernel/libraries/utils/src/test/java/org/sakaiproject/kernel/util/MultiValueInputStreamTest.java
  33. +2 −2 slingtests/osgikernel/testscripts/SlingRuby/sling/message.rb
  34. +61 −0 slingtests/osgikernel/testscripts/SlingRuby/tests/send-email-message.rb
View
2  slingtests/osgikernel/app-bundles/pom.xml
@@ -258,7 +258,7 @@
<dependency>
<groupId>org.sakaiproject.kernel</groupId>
<artifactId>org.apache.sling.api</artifactId>
- <version>2.0.5-sakai-SNAPSHOT</version>
+ <version>2.0.6-sakai-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.sakaiproject.kernel</groupId>
View
2  slingtests/osgikernel/bundles/activity/pom.xml
@@ -119,4 +119,4 @@
<version>0.9.0</version>
</dependency>
</dependencies>
-</project>
+</project>
View
4 slingtests/osgikernel/bundles/connections/pom.xml
@@ -106,7 +106,7 @@
<dependency>
<groupId>org.sakaiproject.kernel</groupId>
<artifactId>org.apache.sling.api</artifactId>
- <version>2.0.5-sakai-SNAPSHOT</version>
+ <version>2.0.6-sakai-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<!-- servlet -->
@@ -168,4 +168,4 @@
<scope>provided</scope>
</dependency>
</dependencies>
-</project>
+</project>
View
4 slingtests/osgikernel/bundles/discussion/pom.xml
@@ -122,7 +122,7 @@
<dependency>
<groupId>org.sakaiproject.kernel</groupId>
<artifactId>org.apache.sling.api</artifactId>
- <version>2.0.5-sakai-SNAPSHOT</version>
+ <version>2.0.6-sakai-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<!-- servlet -->
@@ -184,4 +184,4 @@
<scope>provided</scope>
</dependency>
</dependencies>
-</project>
+</project>
View
6 slingtests/osgikernel/bundles/email-outgoing/pom.xml
@@ -117,5 +117,11 @@
<version>1.2</version>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.sakaiproject.kernel</groupId>
+ <artifactId>org.sakaiproject.kernel.utils</artifactId>
+ <version>0.1-SNAPSHOT</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
</project>
View
9 ...il-outgoing/src/main/java/org/sakaiproject/kernel/email/outgoing/EmailMessageHandler.java
@@ -49,7 +49,7 @@
@Reference
protected EventAdmin eventAdmin;
- private static final String TYPE = MessageConstants.TYPE_EMAIL;
+ private static final String TYPE = MessageConstants.TYPE_SMTP;
public String getType() {
return TYPE;
@@ -57,7 +57,7 @@ public String getType() {
/**
* {@inheritDoc}
- *
+ *
* @see org.sakaiproject.kernel.api.message.MessageTransport#send(org.sakaiproject.kernel.api.message.MessageRoutes,
* org.osgi.service.event.Event, javax.jcr.Node)
*/
@@ -65,7 +65,7 @@ public void send(MessageRoutes routes, Event event, Node n) {
LOGGER.debug("Started handling an email message");
List<String> recipents = new ArrayList<String>();
for (MessageRoute route : routes) {
- if ("smtp".equals(route.getTransport())) {
+ if (TYPE.equals(route.getTransport())) {
recipents.add(route.getRcpt());
}
}
@@ -82,4 +82,7 @@ public void send(MessageRoutes routes, Event event, Node n) {
}
}
+ protected void bindEventAdmin(EventAdmin eventAdmin) {
+ this.eventAdmin = eventAdmin;
+ }
}
View
134 ...ng/src/main/java/org/sakaiproject/kernel/email/outgoing/OutgoingEmailMessageListener.java
@@ -42,6 +42,8 @@
import java.util.Dictionary;
import java.util.HashMap;
import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
@@ -69,7 +71,7 @@
public static final String BROKER_URL = "email.out.brokerUrl";
@Property(value = "localhost")
private static final String SMTP_SERVER = "sakai.smtp.server";
- @Property(intValue = 8025, label = "%sakai.smtp.port.name")
+ @Property(intValue = 25, label = "%sakai.smtp.port.name")
private static final String SMTP_PORT = "sakai.smtp.port";
@Property(intValue = 240)
private static final String MAX_RETRIES = "sakai.email.maxRetries";
@@ -109,70 +111,90 @@ public OutgoingEmailMessageListener(ConnectionFactoryService connFactoryService)
this.connFactoryService = connFactoryService;
}
+ @SuppressWarnings("unchecked")
public void onMessage(Message message) {
try {
String nodePath = message.getStringProperty(NODE_PATH_PROPERTY);
- String[] recipients = StringUtils.split(message.getStringProperty(RECIPIENTS),',');
+ Object objRcpt = message.getObjectProperty(RECIPIENTS);
+ List<String> recipients = null;
+
+ if (objRcpt instanceof List<?>) {
+ recipients = (List<String>) objRcpt;
+ } else if (objRcpt instanceof String) {
+ recipients = new LinkedList<String>();
+ String[] rcpts = StringUtils.split((String) objRcpt, ',');
+ for (String rcpt : rcpts) {
+ recipients.add(rcpt);
+ }
+ }
javax.jcr.Session adminSession = repository.loginAdministrative(null);
- ResourceResolver resolver = jcrResourceResolverFactory
- .getResourceResolver(adminSession);
+ ResourceResolver resolver = jcrResourceResolverFactory.getResourceResolver(adminSession);
Node messageNode = resolver.getResource(nodePath).adaptTo(Node.class);
- // validate the message
- if (messageNode != null) {
- if (messageNode.hasProperty(MessageConstants.PROP_SAKAI_MESSAGEBOX)
- && MessageConstants.BOX_OUTBOX.equals(messageNode.getProperty(
- MessageConstants.PROP_SAKAI_MESSAGEBOX).getString())) {
- if (messageNode.hasProperty(MessageConstants.PROP_SAKAI_MESSAGEERROR)) {
- // We're retrying this message, so clear the errors
- messageNode.setProperty(MessageConstants.PROP_SAKAI_MESSAGEERROR,
- (String) null);
- }
- if (messageNode.hasProperty(MessageConstants.PROP_SAKAI_TO)
- && messageNode.hasProperty(MessageConstants.PROP_SAKAI_FROM)) {
- // make a commons-email message from the message
- MultiPartEmail email;
- try {
- email = constructMessage(messageNode, recipients);
-
- email.setSmtpPort(smtpPort);
- email.setHostName(smtpServer);
-
- email.send();
- } catch (EmailException e) {
- setError(messageNode, e.getMessage());
- // Get the SMTP error code
- // There has to be a better way to do this
- if (e.getCause() != null && e.getCause().getMessage() != null) {
- String smtpError = e.getCause().getMessage().trim();
- try {
- int errorCode = Integer.parseInt(smtpError.substring(0, 3));
- // All retry-able SMTP errors should have codes starting with 4
- scheduleRetry(errorCode, messageNode);
- } catch (NumberFormatException nfe) {
- // smtpError didn't start with an error code, let's dig for it
- String searchFor = "response:";
- int rindex = smtpError.indexOf(searchFor);
- if (rindex > -1 && (rindex + searchFor.length()) < smtpError.length()) {
- int errorCode = Integer.parseInt(smtpError.substring(searchFor
- .length(), searchFor.length() + 3));
+ if (objRcpt != null) {
+ // validate the message
+ if (messageNode != null) {
+ if (messageNode.hasProperty(MessageConstants.PROP_SAKAI_MESSAGEBOX)
+ && MessageConstants.BOX_OUTBOX.equals(messageNode.getProperty(
+ MessageConstants.PROP_SAKAI_MESSAGEBOX).getString())) {
+ if (messageNode.hasProperty(MessageConstants.PROP_SAKAI_MESSAGEERROR)) {
+ // We're retrying this message, so clear the errors
+ messageNode.setProperty(MessageConstants.PROP_SAKAI_MESSAGEERROR, (String) null);
+ }
+ if (messageNode.hasProperty(MessageConstants.PROP_SAKAI_TO)
+ && messageNode.hasProperty(MessageConstants.PROP_SAKAI_FROM)) {
+ // make a commons-email message from the message
+ MultiPartEmail email;
+ try {
+ email = constructMessage(messageNode, recipients);
+
+ email.setSmtpPort(smtpPort);
+ email.setHostName(smtpServer);
+
+ email.send();
+ } catch (EmailException e) {
+ setError(messageNode, e.getMessage());
+ // Get the SMTP error code
+ // There has to be a better way to do this
+ if (e.getCause() != null && e.getCause().getMessage() != null) {
+ String smtpError = e.getCause().getMessage().trim();
+ try {
+ int errorCode = Integer.parseInt(smtpError.substring(0, 3));
+ // All retry-able SMTP errors should have codes starting
+ // with 4
scheduleRetry(errorCode, messageNode);
+ } catch (NumberFormatException nfe) {
+ // smtpError didn't start with an error code, let's dig for
+ // it
+ String searchFor = "response:";
+ int rindex = smtpError.indexOf(searchFor);
+ if (rindex > -1 && (rindex + searchFor.length()) < smtpError.length()) {
+ int errorCode = Integer.parseInt(smtpError.substring(searchFor.length(),
+ searchFor.length() + 3));
+ scheduleRetry(errorCode, messageNode);
+ }
}
}
}
+ } else {
+ setError(messageNode, "Message must have a to and from set");
}
} else {
- setError(messageNode, "Message must have a to and from set");
+ setError(messageNode, "Not an outbox");
+ }
+ if (!messageNode.hasProperty(MessageConstants.PROP_SAKAI_MESSAGEERROR)) {
+ messageNode.setProperty(MessageConstants.PROP_SAKAI_MESSAGEBOX,
+ MessageConstants.BOX_SENT);
}
- } else {
- setError(messageNode, "Not an outbox");
}
- if (!messageNode.hasProperty(MessageConstants.PROP_SAKAI_MESSAGEERROR)) {
- messageNode.setProperty(MessageConstants.PROP_SAKAI_MESSAGEBOX,
- MessageConstants.BOX_SENT);
+ } else {
+ String retval = "null";
+ if (objRcpt != null) {
+ retval = objRcpt.getClass().toString();
}
+ setError(messageNode, "Expected recipients to be String or List<String>. Found " + retval);
}
} catch (JMSException e) {
LOGGER.error(e.getMessage(), e);
@@ -181,18 +203,19 @@ public void onMessage(Message message) {
}
}
- private MultiPartEmail constructMessage(Node messageNode, String[] recipients) throws EmailException,
+ private MultiPartEmail constructMessage(Node messageNode, List<String> recipients)
+ throws EmailException,
RepositoryException, PathNotFoundException, ValueFormatException {
MultiPartEmail email = new MultiPartEmail();
//TODO: the SAKAI_TO may make no sense in an email context
// and there does not appear to be any distinction between Bcc and To in java mail.
-
+
Set<String> toRecipients = new HashSet<String>();
Set<String> bccRecipients = new HashSet<String>();
for ( String r : recipients ) {
bccRecipients.add(r.trim());
}
-
+
if ( messageNode.hasProperty(MessageConstants.PROP_SAKAI_TO) ) {
String[] tor = StringUtils.split(messageNode.getProperty(MessageConstants.PROP_SAKAI_TO).getString(),',');
for ( String r : tor ) {
@@ -209,10 +232,13 @@ private MultiPartEmail constructMessage(Node messageNode, String[] recipients) t
for ( String r : bccRecipients ) {
email.addBcc(r);
}
-
-
- email.setFrom(messageNode.getProperty(MessageConstants.PROP_SAKAI_FROM).getString());
+ if (messageNode.hasProperty(MessageConstants.PROP_SAKAI_FROM)) {
+ String from = messageNode.getProperty(MessageConstants.PROP_SAKAI_FROM).getString();
+ email.setFrom(from);
+ } else {
+ throw new EmailException("Must provide a 'from' address.");
+ }
if (messageNode.hasProperty(MessageConstants.PROP_SAKAI_BODY)) {
email.setMsg(messageNode.getProperty(MessageConstants.PROP_SAKAI_BODY).getString());
View
58 ...utgoing/src/test/java/org/sakaiproject/kernel/email/outgoing/EmailMessageHandlerTest.java
@@ -0,0 +1,58 @@
+package org.sakaiproject.kernel.email.outgoing;
+
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.expectLastCall;
+import static org.easymock.EasyMock.isA;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.verify;
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.osgi.service.event.Event;
+import org.osgi.service.event.EventAdmin;
+import org.sakaiproject.kernel.api.message.MessageConstants;
+import org.sakaiproject.kernel.api.message.MessageRoutes;
+import org.sakaiproject.kernel.message.listener.MessageRoutesImpl;
+
+import javax.jcr.Node;
+import javax.jcr.Property;
+
+public class EmailMessageHandlerTest {
+
+ private EmailMessageHandler emh;
+
+ @Before
+ public void setup() {
+ EventAdmin eventAdmin = createMock(EventAdmin.class);
+ eventAdmin.postEvent(isA(Event.class));
+ expectLastCall();
+
+ replay(eventAdmin);
+
+ emh = new EmailMessageHandler();
+ emh.bindEventAdmin(eventAdmin);
+ }
+
+ @Test
+ public void testSend() throws Exception {
+ Property prop = createMock(Property.class);
+ expect(prop.getString()).andReturn("smtp:foo@localhost");
+
+ Node node = createMock(Node.class);
+ expect(node.getProperty(MessageConstants.PROP_SAKAI_TO)).andReturn(prop);
+ expect(node.getPath()).andReturn("/foo");
+
+ replay(prop, node);
+ MessageRoutes routes = new MessageRoutesImpl(node);
+
+ emh.send(routes, null, node);
+ verify(prop, node);
+ }
+
+ @Test
+ public void testGetType() {
+ assertEquals(MessageConstants.TYPE_SMTP, emh.getType());
+ }
+}
View
38 ...rc/test/java/org/sakaiproject/kernel/email/outgoing/OutgoingEmailMessageListenerTest.java
@@ -116,7 +116,8 @@ public static void stopWiser() {
public void testNoBoxParam() throws Exception {
Message message = createMock(Message.class);
expect(message.getStringProperty(NODE_PATH_PROPERTY)).andReturn(PATH);
- expect(message.getStringProperty(OutgoingEmailMessageListener.RECIPIENTS)).andReturn("xx@123.com,yyy@345.com");
+ expect(message.getObjectProperty(OutgoingEmailMessageListener.RECIPIENTS)).andReturn(
+ "xx@123.com,yyy@345.com");
expect(messageNode.hasProperty(MessageConstants.PROP_SAKAI_MESSAGEBOX)).andReturn(
false);
expect(
@@ -135,7 +136,8 @@ public void testNoBoxParam() throws Exception {
public void testNotOutBox() throws Exception {
Message message = createMock(Message.class);
expect(message.getStringProperty(NODE_PATH_PROPERTY)).andReturn(PATH);
- expect(message.getStringProperty(OutgoingEmailMessageListener.RECIPIENTS)).andReturn("xx@123.com,yyy@345.com");
+ expect(message.getObjectProperty(OutgoingEmailMessageListener.RECIPIENTS)).andReturn(
+ "xx@123.com,yyy@345.com");
Property boxName = createMock(Property.class);
expect(boxName.getString()).andReturn(MessageConstants.BOX_INBOX);
@@ -160,7 +162,8 @@ public void testNotOutBox() throws Exception {
public void testNoTo() throws Exception {
Message message = createMock(Message.class);
expect(message.getStringProperty(NODE_PATH_PROPERTY)).andReturn(PATH);
- expect(message.getStringProperty(OutgoingEmailMessageListener.RECIPIENTS)).andReturn("xx@123.com,yyy@345.com");
+ expect(message.getObjectProperty(OutgoingEmailMessageListener.RECIPIENTS)).andReturn(
+ "xx@123.com,yyy@345.com");
Property boxName = createMock(Property.class);
expect(boxName.getString()).andReturn(MessageConstants.BOX_OUTBOX);
@@ -188,7 +191,8 @@ public void testNoTo() throws Exception {
public void testNoFrom() throws Exception {
Message message = createMock(Message.class);
expect(message.getStringProperty(NODE_PATH_PROPERTY)).andReturn(PATH);
- expect(message.getStringProperty(OutgoingEmailMessageListener.RECIPIENTS)).andReturn("xx@123.com,yyy@345.com");
+ expect(message.getObjectProperty(OutgoingEmailMessageListener.RECIPIENTS)).andReturn(
+ "xx@123.com,yyy@345.com");
Property boxName = createMock(Property.class);
expect(boxName.getString()).andReturn(MessageConstants.BOX_OUTBOX);
@@ -217,7 +221,8 @@ public void testNoFrom() throws Exception {
public void testSingleTo() throws Exception {
Message message = createMock(Message.class);
expect(message.getStringProperty(NODE_PATH_PROPERTY)).andReturn(PATH);
- expect(message.getStringProperty(OutgoingEmailMessageListener.RECIPIENTS)).andReturn("tonobody@example.com");
+ expect(message.getObjectProperty(OutgoingEmailMessageListener.RECIPIENTS)).andReturn(
+ "tonobody@example.com");
Property boxName = createMock(Property.class);
expect(boxName.getString()).andReturn(MessageConstants.BOX_OUTBOX);
@@ -236,7 +241,7 @@ public void testSingleTo() throws Exception {
messageNode.setProperty(MessageConstants.PROP_SAKAI_MESSAGEERROR, (String) null))
.andReturn(null);
expect(messageNode.hasProperty(MessageConstants.PROP_SAKAI_TO)).andReturn(true).times(2);
- expect(messageNode.hasProperty(MessageConstants.PROP_SAKAI_FROM)).andReturn(true);
+ expect(messageNode.hasProperty(MessageConstants.PROP_SAKAI_FROM)).andReturn(true).times(2);
expect(messageNode.hasProperty(MessageConstants.PROP_SAKAI_MESSAGEERROR)).andReturn(
false).times(2);
expect(messageNode.getProperty(MessageConstants.PROP_SAKAI_TO)).andReturn(toProp);
@@ -262,7 +267,8 @@ public void testSingleTo() throws Exception {
public void testMultiTo() throws Exception {
Message message = createMock(Message.class);
expect(message.getStringProperty(NODE_PATH_PROPERTY)).andReturn(PATH);
- expect(message.getStringProperty(OutgoingEmailMessageListener.RECIPIENTS)).andReturn("tonobody0@example.com,tonobody1@example.com");
+ expect(message.getObjectProperty(OutgoingEmailMessageListener.RECIPIENTS)).andReturn(
+ "tonobody0@example.com,tonobody1@example.com");
Property boxName = createMock(Property.class);
expect(boxName.getString()).andReturn(MessageConstants.BOX_OUTBOX);
@@ -317,7 +323,8 @@ public void testMultiTo() throws Exception {
public void testBody() throws Exception {
Message message = createMock(Message.class);
expect(message.getStringProperty(NODE_PATH_PROPERTY)).andReturn(PATH);
- expect(message.getStringProperty(OutgoingEmailMessageListener.RECIPIENTS)).andReturn("tonobody@example.com");
+ expect(message.getObjectProperty(OutgoingEmailMessageListener.RECIPIENTS)).andReturn(
+ "tonobody@example.com");
Property boxName = createMock(Property.class);
expect(boxName.getString()).andReturn(MessageConstants.BOX_OUTBOX);
@@ -339,7 +346,7 @@ public void testBody() throws Exception {
messageNode.setProperty(MessageConstants.PROP_SAKAI_MESSAGEERROR, (String) null))
.andReturn(null);
expect(messageNode.hasProperty(MessageConstants.PROP_SAKAI_TO)).andReturn(true).times(2);
- expect(messageNode.hasProperty(MessageConstants.PROP_SAKAI_FROM)).andReturn(true);
+ expect(messageNode.hasProperty(MessageConstants.PROP_SAKAI_FROM)).andReturn(true).times(2);
expect(messageNode.hasProperty(MessageConstants.PROP_SAKAI_MESSAGEERROR)).andReturn(
false).times(2);
expect(messageNode.getProperty(MessageConstants.PROP_SAKAI_TO)).andReturn(toProp);
@@ -368,7 +375,8 @@ public void testBody() throws Exception {
public void testSubject() throws Exception {
Message message = createMock(Message.class);
expect(message.getStringProperty(NODE_PATH_PROPERTY)).andReturn(PATH);
- expect(message.getStringProperty(OutgoingEmailMessageListener.RECIPIENTS)).andReturn("tonobody@example.com");
+ expect(message.getObjectProperty(OutgoingEmailMessageListener.RECIPIENTS)).andReturn(
+ "tonobody@example.com");
Property boxName = createMock(Property.class);
expect(boxName.getString()).andReturn(MessageConstants.BOX_OUTBOX);
@@ -390,7 +398,7 @@ public void testSubject() throws Exception {
messageNode.setProperty(MessageConstants.PROP_SAKAI_MESSAGEERROR, (String) null))
.andReturn(null);
expect(messageNode.hasProperty(MessageConstants.PROP_SAKAI_TO)).andReturn(true).times(2);
- expect(messageNode.hasProperty(MessageConstants.PROP_SAKAI_FROM)).andReturn(true);
+ expect(messageNode.hasProperty(MessageConstants.PROP_SAKAI_FROM)).andReturn(true).times(2);
expect(messageNode.hasProperty(MessageConstants.PROP_SAKAI_MESSAGEERROR)).andReturn(
false).times(2);
expect(messageNode.getProperty(MessageConstants.PROP_SAKAI_TO)).andReturn(toProp);
@@ -430,7 +438,8 @@ public void testJMSExceptionHandling() throws Exception {
public void testRepoExceptionHandling() throws Exception {
Message message = createMock(Message.class);
expect(message.getStringProperty(NODE_PATH_PROPERTY)).andReturn(PATH);
- expect(message.getStringProperty(OutgoingEmailMessageListener.RECIPIENTS)).andReturn("xx@123.com,yyy@345.com");
+ expect(message.getObjectProperty(OutgoingEmailMessageListener.RECIPIENTS)).andReturn(
+ "xx@123.com,yyy@345.com");
expect(messageNode.hasProperty(MessageConstants.PROP_SAKAI_MESSAGEBOX)).andThrow(
new RepositoryException("Test Repository Exception"));
@@ -443,7 +452,8 @@ public void testRepoExceptionHandling() throws Exception {
public void testAttachment() throws Exception {
Message message = createMock(Message.class);
expect(message.getStringProperty(NODE_PATH_PROPERTY)).andReturn(PATH);
- expect(message.getStringProperty(OutgoingEmailMessageListener.RECIPIENTS)).andReturn("tonobody@example.com");
+ expect(message.getObjectProperty(OutgoingEmailMessageListener.RECIPIENTS)).andReturn(
+ "tonobody@example.com");
Property boxName = createMock(Property.class);
expect(boxName.getString()).andReturn(MessageConstants.BOX_OUTBOX);
@@ -495,7 +505,7 @@ public void testAttachment() throws Exception {
messageNode.setProperty(MessageConstants.PROP_SAKAI_MESSAGEERROR, (String) null))
.andReturn(null);
expect(messageNode.hasProperty(MessageConstants.PROP_SAKAI_TO)).andReturn(true).times(2);
- expect(messageNode.hasProperty(MessageConstants.PROP_SAKAI_FROM)).andReturn(true);
+ expect(messageNode.hasProperty(MessageConstants.PROP_SAKAI_FROM)).andReturn(true).times(2);
expect(messageNode.hasProperty(MessageConstants.PROP_SAKAI_MESSAGEERROR)).andReturn(
false).times(2);
expect(messageNode.getProperty(MessageConstants.PROP_SAKAI_TO)).andReturn(toProp);
View
13 ...bundles/messaging/src/main/java/org/sakaiproject/kernel/api/message/MessageConstants.java
@@ -18,7 +18,7 @@
package org.sakaiproject.kernel.api.message;
/**
- *
+ *
*/
public interface MessageConstants {
@@ -52,7 +52,7 @@
* This property will hold the value for the id of this message.
*/
public static final String PROP_SAKAI_ID = "sakai:id";
-
+
/**
* The value for this property will define what kind of message this is. ex: internal,
* email, ..
@@ -150,7 +150,7 @@
/**
* Identifier for a email message.
*/
- public static final String TYPE_EMAIL = "email";
+ public static final String TYPE_SMTP = "smtp";
/**
* Cleanup chat messages every X minutes
@@ -170,13 +170,14 @@
public static final String PROP_SAKAI_ATTACHMENT_DESCRIPTION = "sakai:attachmentDescription";
public static final String PROP_SAKAI_ATTACHMENT_CONTENT = "sakai:attachmentContent";
-
-
-
+
+
+
/**
* Values for the preprocessor
*/
public static final String REG_PROCESSOR_NAMES = "sakai.message.createpreprocessor";
public static final String MESSAGE_CREATE_PREPROCESSOR = "CreateMessagePreProcessor";
+
}
View
37 ...essaging/src/test/java/org/sakaiproject/kernel/message/listener/MessageRouteImplTest.java
@@ -0,0 +1,37 @@
+package org.sakaiproject.kernel.message.listener;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
+import org.junit.Test;
+
+public class MessageRouteImplTest {
+
+ @Test
+ public void testNullRoute() {
+ MessageRouteImpl mri = new MessageRouteImpl(null);
+ assertNull(mri.getRcpt());
+ assertNull(mri.getTransport());
+ }
+
+ @Test
+ public void testEmptyRoute() {
+ MessageRouteImpl mri = new MessageRouteImpl("");
+ assertEquals("internal", mri.getTransport());
+ assertEquals("", mri.getRcpt());
+ }
+
+ @Test
+ public void testInternalRoute() {
+ MessageRouteImpl mri = new MessageRouteImpl(":admin");
+ assertEquals("internal", mri.getTransport());
+ assertEquals("admin", mri.getRcpt());
+ }
+
+ @Test
+ public void testExternalRoute() {
+ MessageRouteImpl mri = new MessageRouteImpl("smtp:admin@localhost");
+ assertEquals("smtp", mri.getTransport());
+ assertEquals("admin@localhost", mri.getRcpt());
+ }
+}
View
28 ...ssaging/src/test/java/org/sakaiproject/kernel/message/listener/MessageRoutesImplTest.java
@@ -0,0 +1,28 @@
+package org.sakaiproject.kernel.message.listener;
+
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.replay;
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+import org.sakaiproject.kernel.api.message.MessageConstants;
+
+import javax.jcr.Node;
+import javax.jcr.Property;
+
+public class MessageRoutesImplTest {
+
+ @Test
+ public void testConstructWithNode() throws Exception {
+ Property prop = createMock(Property.class);
+ expect(prop.getString()).andReturn("smtp:foo@localhost,smtp:bar@localhost");
+
+ Node node = createMock(Node.class);
+ expect(node.getProperty(MessageConstants.PROP_SAKAI_TO)).andReturn(prop);
+
+ replay(node, prop);
+ MessageRoutesImpl mri = new MessageRoutesImpl(node);
+ assertEquals(2, mri.size());
+ }
+}
View
77 ...aging/src/test/java/org/sakaiproject/kernel/message/listener/MessageSentListenerTest.java
@@ -0,0 +1,77 @@
+package org.sakaiproject.kernel.message.listener;
+
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.eq;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.expectLastCall;
+import static org.easymock.EasyMock.isA;
+import static org.easymock.EasyMock.replay;
+
+import org.apache.sling.jcr.resource.JcrResourceConstants;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.osgi.service.event.Event;
+import org.sakaiproject.kernel.api.message.MessageConstants;
+import org.sakaiproject.kernel.api.message.MessageRouterManager;
+import org.sakaiproject.kernel.api.message.MessageRoutes;
+import org.sakaiproject.kernel.api.message.MessageTransport;
+
+import java.util.Properties;
+
+import javax.jcr.Node;
+import javax.jcr.Property;
+
+public class MessageSentListenerTest {
+ private MessageSentListener msl;
+ private MessageRouterManager messageRouterManager;
+
+ @Before
+ public void setup() throws Exception {
+ Property prop = createMock(Property.class);
+ expect(prop.getString()).andReturn(":admin");
+
+ Node node = createMock(Node.class);
+ expect(node.getProperty(MessageConstants.PROP_SAKAI_TO)).andReturn(prop);
+
+ replay(prop, node);
+
+ messageRouterManager = createMock(MessageRouterManager.class);
+ expect(messageRouterManager.getMessageRouting(isA(Node.class))).andReturn(
+ new MessageRoutesImpl(node));
+
+ replay(messageRouterManager);
+
+ msl = new MessageSentListener();
+ msl.bindMessageRouterManager(messageRouterManager);
+ }
+
+ @After
+ public void cleanup() {
+ msl.unbindMessageRouterManager(messageRouterManager);
+ }
+
+ @Test
+ public void testHandleEvent() throws Exception {
+ Property prop = createMock(Property.class);
+ expect(prop.getString()).andReturn(MessageConstants.SAKAI_MESSAGE_RT);
+
+ Node node = createMock(Node.class);
+ expect(node.getProperty(JcrResourceConstants.SLING_RESOURCE_TYPE_PROPERTY))
+ .andReturn(prop);
+
+ Properties eventProps = new Properties();
+ eventProps.put(MessageConstants.EVENT_LOCATION, node);
+ Event event = new Event("myTopic", eventProps);
+
+ MessageTransport transport = createMock(MessageTransport.class);
+ transport.send(isA(MessageRoutes.class), eq(event), eq(node));
+ expectLastCall();
+
+ replay(prop, node, transport);
+
+ msl.addTransport(transport);
+ msl.handleEvent(event);
+ msl.removeTransport(transport);
+ }
+}
View
2  slingtests/osgikernel/bundles/personal/pom.xml
@@ -106,4 +106,4 @@
<scope>provided</scope>
</dependency>
</dependencies>
-</project>
+</project>
View
4 ...nel/bundles/proxy/src/main/java/org/sakaiproject/kernel/api/proxy/ProxyClientService.java
@@ -51,6 +51,10 @@
*/
public static final String SAKAI_PROXY_REQUEST_TEMPLATE = "sakai:proxy-request-template";
+ /**
+ * A multi value property containing a list of headers to add to the request.
+ */
+ public static final String SAKAI_PROXY_HEADER = "sakai:proxy-header";
/**
* Executes a HTTP call using a path in the JCR to point to a template and a map of
View
17 ...nel/bundles/proxy/src/main/java/org/sakaiproject/kernel/proxy/ProxyClientServiceImpl.java
@@ -45,6 +45,8 @@
import org.sakaiproject.kernel.api.proxy.ProxyResponse;
import org.sakaiproject.kernel.proxy.velocity.JcrResourceLoader;
import org.sakaiproject.kernel.proxy.velocity.VelocityLogger;
+import org.sakaiproject.kernel.util.JcrUtils;
+import org.sakaiproject.kernel.util.StringUtils;
import java.io.InputStream;
import java.io.Reader;
@@ -54,6 +56,7 @@
import java.util.Map.Entry;
import javax.jcr.Node;
+import javax.jcr.Value;
/**
*
@@ -62,6 +65,7 @@
@Component(immediate = true)
public class ProxyClientServiceImpl implements ProxyClientService, ProxyNodeSource {
+
/**
*
*/
@@ -109,7 +113,7 @@
* @param ctx
* @throws Exception
*/
- protected void activate(ComponentContext ctx) throws Exception {
+ public void activate(ComponentContext ctx) throws Exception {
velocityEngine = new VelocityEngine();
velocityEngine.setProperty(VelocityEngine.RUNTIME_LOG_LOGSYSTEM, new VelocityLogger(
this.getClass()));
@@ -137,7 +141,7 @@ protected void activate(ComponentContext ctx) throws Exception {
* @param ctx
* @throws Exception
*/
- protected void deactivate(ComponentContext ctx) throws Exception {
+ public void deactivate(ComponentContext ctx) throws Exception {
httpClientConnectionManager.shutdown();
}
@@ -190,7 +194,7 @@ public ProxyResponse executeCall(Node node, Map<String, String> headers,
VelocityContext context = new VelocityContext(input);
// setup the post request
- String endpointURL = node.getProperty(SAKAI_REQUEST_PROXY_ENDPOINT).getString();
+ String endpointURL = JcrUtils.getMultiValueString(node.getProperty(SAKAI_REQUEST_PROXY_ENDPOINT));
Reader urlTemplateReader = new StringReader(endpointURL);
StringWriter urlWriter = new StringWriter();
velocityEngine.evaluate(context, urlWriter, "urlprocessing", urlTemplateReader);
@@ -245,6 +249,13 @@ public ProxyResponse executeCall(Node node, Map<String, String> headers,
for (Entry<String, String> header : headers.entrySet()) {
method.addRequestHeader(header.getKey(), header.getValue());
}
+
+ Value[] additionalHeaders = JcrUtils.getValues(node, SAKAI_PROXY_HEADER);
+ for ( Value v : additionalHeaders ) {
+ String header = v.getString();
+ String[] keyVal = StringUtils.split(header, ':', 2);
+ method.addRequestHeader(keyVal[0].trim(), keyVal[1].trim());
+ }
if (method instanceof EntityEnclosingMethod) {
String contentType = requestContentType;
View
11 ...bundles/proxy/src/main/java/org/sakaiproject/kernel/proxy/velocity/JcrResourceLoader.java
@@ -24,15 +24,15 @@
import org.apache.velocity.runtime.resource.loader.ResourceLoader;
import org.sakaiproject.kernel.api.proxy.ProxyClientService;
import org.sakaiproject.kernel.api.proxy.ProxyNodeSource;
+import org.sakaiproject.kernel.util.MultiValueInputStream;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.io.ByteArrayInputStream;
import java.io.InputStream;
-import java.io.UnsupportedEncodingException;
import javax.jcr.Node;
import javax.jcr.PathNotFoundException;
+import javax.jcr.Property;
import javax.jcr.RepositoryException;
/**
@@ -88,14 +88,11 @@ public InputStream getResourceStream(String source) throws ResourceNotFoundExcep
try {
Node node = getNode(source);
if (node != null && node.hasProperty(ProxyClientService.SAKAI_PROXY_REQUEST_TEMPLATE)) {
- return new ByteArrayInputStream(node.getProperty(
- ProxyClientService.SAKAI_PROXY_REQUEST_TEMPLATE).getString().getBytes("UTF-8"));
-
+ Property template = node.getProperty(ProxyClientService.SAKAI_PROXY_REQUEST_TEMPLATE);
+ return new MultiValueInputStream(template);
}
} catch (RepositoryException e) {
LOGGER.warn(e.getMessage());
- } catch (UnsupportedEncodingException e) {
- LOGGER.warn(e.getMessage());
}
return null;
}
View
39 ...bundles/proxy/src/test/java/org/sakaiproject/kernel/proxy/ProxyClientServiceImplTest.java
@@ -45,6 +45,8 @@
import javax.jcr.Node;
import javax.jcr.Property;
import javax.jcr.RepositoryException;
+import javax.jcr.Value;
+import javax.jcr.nodetype.PropertyDefinition;
/**
*
@@ -154,13 +156,19 @@ public void testInvokeServiceNodeEndPoint() throws ProxyClientException,
Property requestContentType = createMock(Property.class);
Property templateProperty = createMock(Property.class);
Property lastModifiedProperty = createMock(Property.class);
+ PropertyDefinition propertyDefinition = createMock(PropertyDefinition.class);
+ Value value = createMock(Value.class);
expect(node.hasProperty(ProxyClientService.SAKAI_REQUEST_PROXY_ENDPOINT)).andReturn(
true);
expect(node.getProperty(ProxyClientService.SAKAI_REQUEST_PROXY_ENDPOINT)).andReturn(
endpointProperty);
- expect(endpointProperty.getString()).andReturn(dummyServer.getUrl());
+
+ expect(endpointProperty.getDefinition()).andReturn(propertyDefinition);
+ expect(propertyDefinition.isMultiple()).andReturn(false).atLeastOnce();
+ expect(endpointProperty.getValue()).andReturn(value);
+ expect(value.getString()).andReturn(dummyServer.getUrl());
expect(node.hasProperty(ProxyClientService.SAKAI_REQUEST_PROXY_METHOD)).andReturn(
true);
@@ -178,7 +186,12 @@ public void testInvokeServiceNodeEndPoint() throws ProxyClientException,
true).atLeastOnce();
expect(node.getProperty(ProxyClientService.SAKAI_PROXY_REQUEST_TEMPLATE)).andReturn(
templateProperty).atLeastOnce();
- expect(templateProperty.getString()).andReturn(REQUEST_TEMPLATE).atLeastOnce();
+ expect(node.hasProperty(ProxyClientService.SAKAI_PROXY_HEADER)).andReturn(
+ false).atLeastOnce();
+
+ expect(templateProperty.getValue()).andReturn(value);
+ expect(templateProperty.getDefinition()).andReturn(propertyDefinition);
+ expect(value.getStream()).andReturn(new ByteArrayInputStream(REQUEST_TEMPLATE.getBytes()));
expect(node.hasProperty(JcrConstants.JCR_LASTMODIFIED)).andReturn(true).atLeastOnce();
expect(node.getProperty(JcrConstants.JCR_LASTMODIFIED)).andReturn(
@@ -220,14 +233,24 @@ public void testInvokeServiceNodeEndPointPut() throws ProxyClientException,
Property endpointProperty = createMock(Property.class);
Property requestMethodProperty = createMock(Property.class);
+ PropertyDefinition propertyDefinition = createMock(PropertyDefinition.class);
+ Value value = createMock(Value.class);
expect(node.hasProperty(ProxyClientService.SAKAI_REQUEST_PROXY_ENDPOINT)).andReturn(
true);
expect(node.getProperty(ProxyClientService.SAKAI_REQUEST_PROXY_ENDPOINT)).andReturn(
endpointProperty);
- expect(endpointProperty.getString()).andReturn(dummyServer.getUrl());
+
+ expect(endpointProperty.getDefinition()).andReturn(propertyDefinition);
+ expect(propertyDefinition.isMultiple()).andReturn(false).atLeastOnce();
+ expect(endpointProperty.getValue()).andReturn(value);
+ expect(value.getString()).andReturn(dummyServer.getUrl());
+
+ expect(node.hasProperty(ProxyClientService.SAKAI_PROXY_HEADER)).andReturn(
+ false).atLeastOnce();
+
expect(node.hasProperty(ProxyClientService.SAKAI_REQUEST_PROXY_METHOD)).andReturn(
true);
@@ -294,13 +317,21 @@ private void testRequest(String type, String expectedMethod, String body)
Property endpointProperty = createMock(Property.class);
Property requestMethodProperty = createMock(Property.class);
+ PropertyDefinition propertyDefinition = createMock(PropertyDefinition.class);
+ Value value = createMock(Value.class);
expect(node.hasProperty(ProxyClientService.SAKAI_REQUEST_PROXY_ENDPOINT)).andReturn(
true);
expect(node.getProperty(ProxyClientService.SAKAI_REQUEST_PROXY_ENDPOINT)).andReturn(
endpointProperty);
- expect(endpointProperty.getString()).andReturn(dummyServer.getUrl());
+ expect(node.hasProperty(ProxyClientService.SAKAI_PROXY_HEADER)).andReturn(
+ false).atLeastOnce();
+
+ expect(endpointProperty.getDefinition()).andReturn(propertyDefinition);
+ expect(propertyDefinition.isMultiple()).andReturn(false).atLeastOnce();
+ expect(endpointProperty.getValue()).andReturn(value);
+ expect(value.getString()).andReturn(dummyServer.getUrl());
expect(node.hasProperty(ProxyClientService.SAKAI_REQUEST_PROXY_METHOD)).andReturn(
true);
View
66 ...sling/jcr/jackrabbit/server/impl/security/dynamic/DynamicPrincipalManagerFactoryImpl.java
@@ -21,27 +21,34 @@
import org.osgi.framework.BundleContext;
import org.osgi.util.tracker.ServiceTracker;
+import java.util.ArrayList;
+import java.util.List;
+
import javax.jcr.Node;
/**
* A Singleton implementation of the DynamicPrincipalManagerFactory.
*/
-public class DynamicPrincipalManagerFactoryImpl extends ServiceTracker implements DynamicPrincipalManagerFactory {
+public class DynamicPrincipalManagerFactoryImpl extends ServiceTracker implements
+ DynamicPrincipalManagerFactory {
private DynamicPrincipalManager dynamicPrincipalManager;
/**
* Construct the Factory.
- * @param bundleContext the current bundle context.
+ *
+ * @param bundleContext
+ * the current bundle context.
*
*/
public DynamicPrincipalManagerFactoryImpl(BundleContext bundleContext) {
super(bundleContext, DynamicPrincipalManager.class.getName(), null);
dynamicPrincipalManager = new DynamicPrincipalManager() {
- public boolean hasPrincipalInContext(String principalName, Node aclNode, String userId) {
+ public boolean hasPrincipalInContext(String principalName, Node aclNode,
+ String userId) {
Object[] services = getServices();
- if ( services == null || services.length == 0 ) {
+ if (services == null || services.length == 0) {
// no managers configured, pass through, the user does not have the principal.
return false;
}
@@ -52,17 +59,62 @@ public boolean hasPrincipalInContext(String principalName, Node aclNode, String
}
}
return false;
- }
-
+ }
+
+ public List<String> getMembersOf(String principalName) {
+ Object[] services = getServices();
+ if (services == null || services.length == 0) {
+ // no managers configured, pass through, the user does not have the principal.
+ return null;
+ }
+ boolean added = false;
+ List<String> list = new ArrayList<String>();
+ for (Object serviceObject : services) {
+ DynamicPrincipalManager principalManager = (DynamicPrincipalManager) serviceObject;
+ List<String> members = principalManager.getMembersOf(principalName);
+ if (members != null) {
+ list.addAll(members);
+ added = true;
+ }
+ }
+ if (!added) {
+ return null;
+ }
+ return list;
+ }
+
+ public List<String> getMembershipFor(String principalName) {
+ Object[] services = getServices();
+ if (services == null || services.length == 0) {
+ // no managers configured, pass through, the user does not have the principal.
+ return null;
+ }
+ boolean added = false;
+ List<String> list = new ArrayList<String>();
+ for (Object serviceObject : services) {
+ DynamicPrincipalManager principalManager = (DynamicPrincipalManager) serviceObject;
+ List<String> groups = principalManager.getMembershipFor(principalName);
+ if (groups != null) {
+ list.addAll(groups);
+ added = true;
+ }
+ }
+ if (!added) {
+ return null;
+ }
+ return list;
+ }
+
};
}
+
/**
* {@inheritDoc}
+ *
* @see org.apache.sling.jcr.jackrabbit.server.impl.security.dynamic.DynamicPrincipalManagerFactory#getDynamicPrincipalManager()
*/
public DynamicPrincipalManager getDynamicPrincipalManager() {
return dynamicPrincipalManager;
}
-
}
View
32 ...java/org/apache/sling/jcr/jackrabbit/server/security/dynamic/DynamicPrincipalManager.java
@@ -16,6 +16,8 @@
*/
package org.apache.sling.jcr.jackrabbit.server.security.dynamic;
+import java.util.List;
+
import javax.jcr.Node;
/**
@@ -29,10 +31,36 @@
*
* @param principalName
* the name of the principal
- * @param aclNode the ACL node associated with the node under test
- * @param userId the user id making the request (note this is *not* the same as the user id bound to the session), may be null
+ * @param aclNode
+ * the ACL node associated with the node under test
+ * @param userId
+ * the user id making the request (note this is *not* the same as the user id
+ * bound to the session), may be null
* @return true if the user has the principal.
*/
boolean hasPrincipalInContext(String principalName, Node aclNode, String userId);
+ /**
+ * Get the members of the supplied principal, if that is a user, it may have no members,
+ * if it is a group it will may have dynamic members. If the principal is not managed by
+ * the DynamicPrincipalManager implementation they should return null.
+ *
+ * @param principalName
+ * the principal name identifying the Authorizable for which the caller wants a
+ * list of Members.
+ * @return A list of principalNames.
+ */
+ List<String> getMembersOf(String principalName);
+
+ /**
+ * Get a list of principal names that this supplied principalName has membership of. (ie
+ * if the principalName is "ieb", then this will return the membership of ieb)
+ *
+ * @param principalName
+ * the principalName for which membership is required.
+ * @return a list of groups the user is a member of, null if the question is not
+ * relevant to the implementation.
+ */
+ List<String> getMembershipFor(String principalName);
+
}
View
3  .../src/main/resources/SLING-INF/content/templates/interdisciplinary/_pages/all-members.json
@@ -3,5 +3,6 @@
"title": "All members",
"type": "webpage",
"position": "300000",
- "acl": "parent"
+ "acl": "parent",
+ "jcr:mixinTypes": "sakai:propertiesmix"
}
View
3  ...e/src/main/resources/SLING-INF/content/templates/interdisciplinary/_pages/contact-us.json
@@ -3,5 +3,6 @@
"title": "Contact Us",
"type": "webpage",
"position": "500000",
- "acl": "parent"
+ "acl": "parent",
+ "jcr:mixinTypes": "sakai:propertiesmix"
}
View
3  ...src/main/resources/SLING-INF/content/templates/interdisciplinary/_pages/introduction.json
@@ -3,5 +3,6 @@
"title": "Introduction",
"type": "webpage",
"position": "100000",
- "acl": "parent"
+ "acl": "parent",
+ "jcr:mixinTypes": "sakai:propertiesmix"
}
View
3  .../src/main/resources/SLING-INF/content/templates/interdisciplinary/_pages/latest-news.json
@@ -3,5 +3,6 @@
"title": "Latest News",
"type": "webpage",
"position": "400000",
- "acl": "parent"
+ "acl": "parent",
+ "jcr:mixinTypes": "sakai:propertiesmix"
}
View
3  .../bundles/site/src/main/resources/SLING-INF/content/templates/template/_pages/welcome.json
@@ -3,5 +3,6 @@
"title": "Welcome",
"type": "webpage",
"position": "100000",
- "acl": "parent"
+ "acl": "parent",
+ "jcr:mixinTypes": "sakai:propertiesmix"
}
View
4 slingtests/osgikernel/bundles/sling/api/pom.xml
@@ -20,7 +20,7 @@
</parent>
<artifactId>org.apache.sling.api</artifactId>
<packaging>jar</packaging>
- <version>2.0.5-sakai-SNAPSHOT</version>
+ <version>2.0.6-sakai-SNAPSHOT</version>
<name>Sakai Kernel Sling API Extension Bundle</name>
<description>Extension bundle that provides additional functionality in the Sling API
area as required by Sakai.</description>
@@ -60,7 +60,7 @@
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.api</artifactId>
- <version>2.0.5-SNAPSHOT</version>
+ <version>2.0.6</version>
<scope>compile</scope>
</dependency>
<dependency>
View
2  slingtests/osgikernel/bundles/sling/resource/pom.xml
@@ -63,7 +63,7 @@
<dependency>
<groupId>org.sakaiproject.kernel</groupId>
<artifactId>org.apache.sling.api</artifactId>
- <version>2.0.5-sakai-SNAPSHOT</version>
+ <version>2.0.6-sakai-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.sling</groupId>
View
18 ...dles/user/src/main/java/org/sakaiproject/kernel/user/owner/OwnerPrincipalManagerImpl.java
@@ -23,6 +23,8 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import java.util.List;
+
import javax.jcr.Node;
import javax.jcr.Property;
import javax.jcr.RepositoryException;
@@ -74,4 +76,20 @@ public boolean hasPrincipalInContext(String principalName, Node aclNode, String
return false;
}
+ /**
+ * {@inheritDoc}
+ * @see org.apache.sling.jcr.jackrabbit.server.security.dynamic.DynamicPrincipalManager#getMembersOf(java.lang.String)
+ */
+ public List<String> getMembersOf(String principalName) {
+ return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ * @see org.apache.sling.jcr.jackrabbit.server.security.dynamic.DynamicPrincipalManager#getMembershipFor(java.lang.String)
+ */
+ public List<String> getMembershipFor(String principalName) {
+ return null;
+ }
+
}
View
19 ...tests/osgikernel/libraries/utils/src/main/java/org/sakaiproject/kernel/util/JcrUtils.java
@@ -42,7 +42,7 @@
public class JcrUtils {
private static final Logger LOGGER = LoggerFactory.getLogger(JcrUtils.class);
-
+
/**
* Deep creates a path.
*
@@ -173,12 +173,25 @@ public static void logItem(Logger logger, Node node) throws RepositoryException,
if (pd.isMultiple()) {
return property.getValues();
} else {
- return new Value[] {property.getValue()};
+ return new Value[] { property.getValue() };
}
}
return new Value[] {};
}
-
+
+ public static String getMultiValueString(Property property) throws RepositoryException {
+ PropertyDefinition pd = property.getDefinition();
+ if (pd.isMultiple()) {
+ StringBuilder sb = new StringBuilder();
+ for (Value v : property.getValues()) {
+ sb.append(v.getString());
+ }
+ return sb.toString();
+ } else {
+ return property.getValue().getString();
+ }
+ }
+
public static NodeInputStream getInputStreamForNode(Node node) {
try {
Node content = node.isNodeType("nt:file") ? node.getNode("jcr:content") : node;
View
90 ...nel/libraries/utils/src/main/java/org/sakaiproject/kernel/util/MultiValueInputStream.java
@@ -0,0 +1,90 @@
+/*
+ * Licensed to the Sakai Foundation (SF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The SF 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.sakaiproject.kernel.util;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import javax.jcr.Property;
+import javax.jcr.RepositoryException;
+import javax.jcr.Value;
+import javax.jcr.ValueFormatException;
+import javax.jcr.nodetype.PropertyDefinition;
+
+/**
+ * Creates an Input Stream from a multi value property.
+ */
+public class MultiValueInputStream extends InputStream {
+
+ private Value[] values;
+ private int nextStream;
+ private int nvalues;
+ private InputStream currentInputStream;
+
+ /**
+ * @param template
+ * @throws RepositoryException
+ * @throws ValueFormatException
+ */
+ public MultiValueInputStream(Property property) throws ValueFormatException, RepositoryException {
+ PropertyDefinition pd = property.getDefinition();
+ if ( pd.isMultiple() ) {
+ values = property.getValues();
+ } else {
+ values = new Value[1];
+ values[0] = property.getValue();
+ }
+ nextStream = 0;
+ nvalues = values.length;
+ currentInputStream = values[nextStream].getStream();
+ nextStream++;
+ }
+
+ /**
+ * {@inheritDoc}
+ * @see java.io.InputStream#read()
+ */
+ @Override
+ public int read() throws IOException {
+ int c = currentInputStream.read();
+ while ( c < 0 && nextStream < nvalues ) {
+ currentInputStream.close();
+ try {
+ currentInputStream = values[nextStream].getStream();
+ } catch (IllegalStateException e) {
+ throw new IOException("Failed to open property value no "+nextStream+" as stream:"+e.getMessage());
+ } catch (RepositoryException e) {
+ throw new IOException("Failed to open property value no "+nextStream+" as stream:"+e.getMessage());
+ }
+ nextStream++;
+ c = currentInputStream.read();
+ }
+ return c;
+ }
+
+ /**
+ * {@inheritDoc}
+ * @see java.io.InputStream#close()
+ */
+ @Override
+ public void close() throws IOException {
+ currentInputStream.close();
+ }
+
+
+}
View
222 ...s/osgikernel/libraries/utils/src/test/java/org/sakaiproject/kernel/util/JcrUtilsTest.java
@@ -21,12 +21,27 @@
import static org.easymock.EasyMock.expect;
import static org.easymock.EasyMock.replay;
import static org.easymock.EasyMock.verify;
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import org.apache.sling.commons.json.JSONException;
import org.junit.Test;
+import org.slf4j.LoggerFactory;
+
+import java.io.ByteArrayInputStream;
import javax.jcr.Node;
+import javax.jcr.NodeIterator;
+import javax.jcr.PathNotFoundException;
+import javax.jcr.Property;
+import javax.jcr.PropertyIterator;
+import javax.jcr.PropertyType;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
+import javax.jcr.Value;
+import javax.jcr.nodetype.PropertyDefinition;
/**
*
@@ -53,4 +68,211 @@ public void testDeepCreate() throws RepositoryException {
verify(session, nodeB, nodeC, nodeD);
}
+ @Test
+ public void testGetFirstExistingNode() throws RepositoryException {
+ Session session = createMock(Session.class);
+ Node node = createMock(Node.class);
+ expect(session.getItem("/a/b/exists/doesnta/doesntb")).andThrow(
+ new PathNotFoundException());
+ expect(session.getItem("/a/b/exists/doesnta")).andThrow(new PathNotFoundException());
+ expect(session.getItem("/a/b/exists")).andReturn(node);
+ expect(node.isNode()).andReturn(true);
+ replay(session, node);
+ assertEquals(node, JcrUtils.getFirstExistingNode(session,
+ "/a/b/exists/doesnta/doesntb"));
+ verify(session, node);
+ }
+
+ @Test
+ public void testGetFirstExistingNodeProperty() throws RepositoryException {
+ Session session = createMock(Session.class);
+ Node node = createMock(Node.class);
+ Property property = createMock(Property.class);
+ expect(session.getItem("/a/b/sakai:exists/doesnta/doesntb")).andThrow(
+ new PathNotFoundException());
+ expect(session.getItem("/a/b/sakai:exists/doesnta")).andThrow(
+ new PathNotFoundException());
+ expect(session.getItem("/a/b/sakai:exists")).andReturn(property);
+ expect(property.isNode()).andReturn(false);
+ expect(property.getParent()).andReturn(node);
+ replay(session, node, property);
+ assertEquals(node, JcrUtils.getFirstExistingNode(session,
+ "/a/b/sakai:exists/doesnta/doesntb"));
+ verify(session, node, property);
+ }
+
+ @Test
+ public void testGetFirstExistingNodeNull() throws RepositoryException {
+ Session session = createMock(Session.class);
+ Node node = createMock(Node.class);
+ expect(session.getItem("/doesnta/doesntb")).andThrow(new PathNotFoundException());
+ expect(session.getItem("/doesnta")).andThrow(new PathNotFoundException());
+ expect(session.getItem("/")).andThrow(new PathNotFoundException());
+ replay(session, node);
+ assertNull(JcrUtils.getFirstExistingNode(session, "/doesnta/doesntb"));
+ verify(session, node);
+ }
+
+ @Test
+ public void testGetInputStreamForNode() throws RepositoryException {
+ Node node = createMock(Node.class);
+ Node jcrContentNode = createMock(Node.class);
+ Property property = createMock(Property.class);
+ expect(node.isNodeType("nt:file")).andReturn(true);
+ expect(node.getNode("jcr:content")).andReturn(jcrContentNode);
+ expect(jcrContentNode.hasProperty("jcr:data")).andReturn(true);
+ expect(jcrContentNode.getProperty("jcr:data")).andReturn(property);
+ expect(property.getLength()).andReturn(100L);
+ byte[] buf = new byte[100];
+ ByteArrayInputStream bais = new ByteArrayInputStream(buf);
+ expect(property.getStream()).andReturn(bais);
+ replay(node, jcrContentNode, property);
+ assertNotNull(JcrUtils.getInputStreamForNode(node));
+ verify(node, jcrContentNode, property);
+ }
+
+ @Test
+ public void testGetInputStreamForNodeNonStandard() throws RepositoryException {
+ Node node = createMock(Node.class);
+ Node jcrContentNode = createMock(Node.class);
+ Property property = createMock(Property.class);
+ expect(node.isNodeType("nt:file")).andReturn(false);
+ expect(node.hasProperty("jcr:data")).andReturn(false);
+ expect(node.getPrimaryItem()).andReturn(jcrContentNode);
+ expect(jcrContentNode.isNode()).andReturn(true);
+ expect(jcrContentNode.getPrimaryItem()).andReturn(property);
+ expect(property.isNode()).andReturn(false);
+ expect(property.getLength()).andReturn(100L);
+ byte[] buf = new byte[100];
+ ByteArrayInputStream bais = new ByteArrayInputStream(buf);
+ expect(property.getStream()).andReturn(bais);
+ replay(node, jcrContentNode, property);
+ assertNotNull(JcrUtils.getInputStreamForNode(node));
+ verify(node, jcrContentNode, property);
+ }
+
+ @Test
+ public void testGetMultiValueStringMulti() throws RepositoryException {
+ Property property = createMock(Property.class);
+ PropertyDefinition propertyDefinition = createMock(PropertyDefinition.class);
+ Value value = createMock(Value.class);
+ Value[] values = new Value[] { value, value };
+
+ expect(property.getDefinition()).andReturn(propertyDefinition);
+ expect(propertyDefinition.isMultiple()).andReturn(true);
+ expect(property.getValues()).andReturn(values);
+ expect(value.getString()).andReturn("Value").times(2);
+ replay(property, propertyDefinition, value);
+
+ assertEquals("ValueValue", JcrUtils.getMultiValueString(property));
+ verify(property, propertyDefinition, value);
+ }
+
+ @Test
+ public void testGetMultiValueStringSingle() throws RepositoryException {
+ Property property = createMock(Property.class);
+ PropertyDefinition propertyDefinition = createMock(PropertyDefinition.class);
+ Value value = createMock(Value.class);
+
+ expect(property.getDefinition()).andReturn(propertyDefinition);
+ expect(propertyDefinition.isMultiple()).andReturn(false);
+ expect(property.getValue()).andReturn(value);
+ expect(value.getString()).andReturn("Value");
+ replay(property, propertyDefinition, value);
+
+ assertEquals("Value", JcrUtils.getMultiValueString(property));
+ verify(property, propertyDefinition, value);
+ }
+
+ @Test
+ public void testGetValuesMulti() throws RepositoryException {
+ Node node = createMock(Node.class);
+ Property property = createMock(Property.class);
+ PropertyDefinition propertyDefinition = createMock(PropertyDefinition.class);
+ Value value = createMock(Value.class);
+ Value[] values = new Value[] { value, value };
+
+ expect(node.hasProperty("testProperty")).andReturn(true);
+ expect(node.getProperty("testProperty")).andReturn(property);
+ expect(property.getDefinition()).andReturn(propertyDefinition);
+ expect(propertyDefinition.isMultiple()).andReturn(true);
+ expect(property.getValues()).andReturn(values);
+
+ replay(node, property, propertyDefinition, value);
+ assertArrayEquals(values, JcrUtils.getValues(node, "testProperty"));
+ verify(node, property, propertyDefinition, value);
+ }
+
+ @Test
+ public void testGetValuesSingle() throws RepositoryException {
+ Node node = createMock(Node.class);
+ Property property = createMock(Property.class);
+ PropertyDefinition propertyDefinition = createMock(PropertyDefinition.class);
+ Value value = createMock(Value.class);
+
+ expect(node.hasProperty("testProperty")).andReturn(true);
+ expect(node.getProperty("testProperty")).andReturn(property);
+ expect(property.getDefinition()).andReturn(propertyDefinition);
+ expect(propertyDefinition.isMultiple()).andReturn(false);
+ expect(property.getValue()).andReturn(value);
+
+ replay(node, property, propertyDefinition, value);
+ Value[] values = JcrUtils.getValues(node, "testProperty");
+ assertEquals(1, values.length);
+ assertEquals(value, values[0]);
+ verify(node, property, propertyDefinition, value);
+ }
+
+ @Test
+ public void testGetValuesNone() throws RepositoryException {
+ Node node = createMock(Node.class);
+ Property property = createMock(Property.class);
+
+ expect(node.hasProperty("testProperty")).andReturn(false);
+
+ replay(node, property);
+ Value[] values = JcrUtils.getValues(node, "testProperty");
+ assertEquals(0, values.length);
+ verify(node, property);
+ }
+
+ @Test
+ public void testLogItem() throws RepositoryException, JSONException {
+ Node node = createMock(Node.class);
+ PropertyIterator propertyIterator = createMock(PropertyIterator.class);
+ NodeIterator nodeIterator = createMock(NodeIterator.class);
+ Property property = createMock(Property.class);
+ PropertyDefinition propertyDefinition = createMock(PropertyDefinition.class);
+ Value value = createMock(Value.class);
+
+ // first loop over properties
+ expect(node.getProperties()).andReturn(propertyIterator);
+ expect(propertyIterator.hasNext()).andReturn(true);
+ expect(propertyIterator.nextProperty()).andReturn(property);
+ expect(property.getName()).andReturn("prop:name").times(2);
+ expect(property.getType()).andReturn(PropertyType.STRING);
+ expect(property.getDefinition()).andReturn(propertyDefinition);
+ expect(propertyDefinition.isMultiple()).andReturn(false);
+ expect(property.getValue()).andReturn(value);
+ expect(value.getType()).andReturn(PropertyType.STRING);
+ expect(value.getString()).andReturn("propvalue");
+ expect(propertyIterator.hasNext()).andReturn(false);
+
+ expect(node.getNodes()).andReturn(nodeIterator);
+ expect(nodeIterator.hasNext()).andReturn(true);
+ // reusing node
+ expect(nodeIterator.nextNode()).andReturn(node);
+ expect(node.getName()).andReturn("ChildNodeName");
+ expect(node.getProperties()).andReturn(propertyIterator);
+ expect(propertyIterator.hasNext()).andReturn(false);
+ expect(node.getNodes()).andReturn(nodeIterator);
+ expect(nodeIterator.hasNext()).andReturn(false);
+
+ expect(nodeIterator.hasNext()).andReturn(false);
+
+ replay(node, propertyIterator, nodeIterator, property, propertyDefinition, value);
+ JcrUtils.logItem(LoggerFactory.getLogger(JcrUtilsTest.class), node);
+ verify(node, propertyIterator, nodeIterator, property, propertyDefinition, value);
+ }
+
}
View
114 ...libraries/utils/src/test/java/org/sakaiproject/kernel/util/MultiValueInputStreamTest.java
@@ -0,0 +1,114 @@
+/*
+ * Licensed to the Sakai Foundation (SF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The SF 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.sakaiproject.kernel.util;
+
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.verify;
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+import javax.jcr.Property;
+import javax.jcr.RepositoryException;
+import javax.jcr.Value;
+import javax.jcr.ValueFormatException;
+import javax.jcr.nodetype.PropertyDefinition;
+
+/**
+ *
+ */
+public class MultiValueInputStreamTest {
+
+ @Test
+ public void testMultiValueInputStreamMulti() throws ValueFormatException,
+ RepositoryException, IOException {
+ Property property = createMock(Property.class);
+ PropertyDefinition propertyDefinition = createMock(PropertyDefinition.class);
+ InputStream[] stream = new InputStream[3];
+ Value[] values = new Value[3];
+
+ byte[][] buffer = new byte[3][100];
+ for (int i = 0; i < 3; i++) {
+ values[i] = createMock(Value.class);
+ for (int j = 0; j < 100; j++) {
+ buffer[i][j] = (byte) (i + j);
+ }
+ stream[i] = new ByteArrayInputStream(buffer[i]);
+ }
+
+ expect(property.getDefinition()).andReturn(propertyDefinition);
+ expect(propertyDefinition.isMultiple()).andReturn(true);
+ expect(property.getValues()).andReturn(values);
+
+ expect(values[0].getStream()).andReturn(stream[0]);
+ expect(values[1].getStream()).andReturn(stream[1]);
+ expect(values[2].getStream()).andReturn(stream[2]);
+
+ replay(property, propertyDefinition, values[0], values[1], values[2]);
+ MultiValueInputStream multiValueInputStream = new MultiValueInputStream(property);
+
+ for (int i = 0; i < 3; i++) {
+ for (int j = 0; j < 100; j++) {
+ assertEquals("Missmatch at " + i + ":" + j, buffer[i][j], multiValueInputStream
+ .read());
+ }
+ }
+
+ multiValueInputStream.close();
+ verify(property, propertyDefinition, values[0], values[1], values[2]);
+ }
+
+ @Test
+ public void testMultiValueInputStreamSingle() throws ValueFormatException,
+ RepositoryException, IOException {
+ Property property = createMock(Property.class);
+ PropertyDefinition propertyDefinition = createMock(PropertyDefinition.class);
+
+ byte[] buffer = new byte[100];
+
+ Value value = createMock(Value.class);
+ for (int j = 0; j < 100; j++) {
+ buffer[j] = (byte) (j);
+ }
+ InputStream stream = new ByteArrayInputStream(buffer);
+
+ expect(property.getDefinition()).andReturn(propertyDefinition);
+ expect(propertyDefinition.isMultiple()).andReturn(false);
+ expect(property.getValue()).andReturn(value);
+
+ expect(value.getStream()).andReturn(stream);
+
+ replay(property, propertyDefinition, value);
+ MultiValueInputStream multiValueInputStream = new MultiValueInputStream(property);
+
+ for (int j = 0; j < 100; j++) {
+ assertEquals("Missmatch at " + j, buffer[j], multiValueInputStream.read());
+ }
+
+ multiValueInputStream.close();
+
+ verify(property, propertyDefinition, value);
+ }
+
+}
View
4 slingtests/osgikernel/testscripts/SlingRuby/sling/message.rb
@@ -8,8 +8,8 @@ def initialize(sling)
@sling = sling
end
- def create(name, type)
- return @sling.execute_post(@sling.url_for("_user/message.create.html"), "sakai:type" => type, "sakai:to" => name, "sakai:sendstate" => "pending", "sakai:messagebox" => "drafts" )
+ def create(name, type, box = "drafts")
+ return @sling.execute_post(@sling.url_for("_user/message.create.html"), "sakai:type" => type, "sakai:to" => name, "sakai:sendstate" => "pending", "sakai:messagebox" => box )
end
def send(messageId)
View
61 slingtests/osgikernel/testscripts/SlingRuby/tests/send-email-message.rb
@@ -0,0 +1,61 @@
+#!/usr/bin/env ruby
+
+require 'rubygems'
+require 'daemons'
+require 'mailtrap'
+
+require 'sling/sling'
+require 'sling/test'
+require 'sling/message'
+require 'test/unit.rb'
+require 'test/unit/ui/console/testrunner.rb'
+
+include SlingMessage
+
+class TC_OutgoingMessage < SlingTest
+
+ def setup
+ super
+ @mm = MessageManager.new(@s)
+
+ mailtrap('start')
+ end
+
+ def teardown
+ # mailtrap should be set to receive just once, so it will stop the process
+ # automaticlly after that.
+ #mailtrap('stop')
+ end
+
+ def test_send_message
+ m = Time.now.to_i.to_s
+ user = "auser#{m}"
+ a = @um.create_user(user)
+
+ puts "Sending mail to user #{user}"
+ @mm.create("smtp:#{user}@example.com", 'smtp', 'outbox')
+ end
+
+ def mailtrap(state)
+ options = {
+ :ARGV => [state, '-f', '--'],
+ :dir_mode => :normal,
+ :dir => '/var/tmp',
+ :multiple => true,
+ :mode => :exec,
+ :backtrace => true,
+ :log_output => true
+ }
+
+ host = 'localhost'
+ port = 25
+ once = true
+ log_file = '/var/tmp/mailtrap.log'
+
+ Daemons.run_proc( 'mailtrap', options ) do
+ Mailtrap.new(host, port, once, log_file)
+ end
+ end
+end
+
+Test::Unit::UI::Console::TestRunner.run(TC_OutgoingMessage)
Please sign in to comment.
Something went wrong with that request. Please try again.