Author: norman
Date: Thu Dec 23 10:54:08 2010
New Revision: 1052220
URL: http://svn.apache.org/viewvc?rev=1052220&view=rev
Log:
Add some test code for AbstractStateCompositeProcessor subclasses
Added:
james/server/trunk/mailetcontainer-camel/src/test/
james/server/trunk/mailetcontainer-camel/src/test/java/
james/server/trunk/mailetcontainer-camel/src/test/java/org/
james/server/trunk/mailetcontainer-camel/src/test/java/org/apache/
james/server/trunk/mailetcontainer-camel/src/test/java/org/apache/james/
james/server/trunk/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/
james/server/trunk/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/camel/
james/server/trunk/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/camel/CamelCompositeProcessorTest.java
james/server/trunk/mailetcontainer-library/src/test/java/org/apache/james/mailetcontainer/lib/AbstractStateCompositeProcessorTest.java
james/server/trunk/mailetcontainer-library/src/test/java/org/apache/james/mailetcontainer/lib/AbstractStateMailetProcessorTest.java
james/server/trunk/mailetcontainer-library/src/test/java/org/apache/james/mailetcontainer/lib/mock/
james/server/trunk/mailetcontainer-library/src/test/java/org/apache/james/mailetcontainer/lib/mock/MockMailProcessor.java
james/server/trunk/mailetcontainer-library/src/test/java/org/apache/james/mailetcontainer/lib/mock/MockMailet.java
james/server/trunk/mailetcontainer-library/src/test/java/org/apache/james/mailetcontainer/lib/mock/MockMailetContext.java
james/server/trunk/mailetcontainer-library/src/test/java/org/apache/james/mailetcontainer/lib/mock/MockMailetLoader.java
james/server/trunk/mailetcontainer-library/src/test/java/org/apache/james/mailetcontainer/lib/mock/MockMatcher.java
james/server/trunk/mailetcontainer-library/src/test/java/org/apache/james/mailetcontainer/lib/mock/MockMatcherLoader.java
Modified:
james/server/trunk/mailetcontainer-camel/pom.xml
james/server/trunk/pom.xml
Modified: james/server/trunk/mailetcontainer-camel/pom.xml
URL:
http://svn.apache.org/viewvc/james/server/trunk/mailetcontainer-camel/pom.xml?rev=1052220&r1=1052219&r2=1052220&view=diff
==============================================================================
--- james/server/trunk/mailetcontainer-camel/pom.xml (original)
+++ james/server/trunk/mailetcontainer-camel/pom.xml Thu Dec 23 10:54:08 2010
@@ -72,5 +72,18 @@
<groupId>org.apache.camel</groupId>
<artifactId>camel-core</artifactId>
</dependency>
+
+ <!-- test dependency -->
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.james</groupId>
+ <artifactId>james-server-mailetcontainer-library</artifactId>
+ <type>test-jar</type>
+ <scope>test</scope>
+ </dependency>
</dependencies>
</project>
Added:
james/server/trunk/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/camel/CamelCompositeProcessorTest.java
URL:
http://svn.apache.org/viewvc/james/server/trunk/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/camel/CamelCompositeProcessorTest.java?rev=1052220&view=auto
==============================================================================
---
james/server/trunk/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/camel/CamelCompositeProcessorTest.java
(added)
+++
james/server/trunk/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/camel/CamelCompositeProcessorTest.java
Thu Dec 23 10:54:08 2010
@@ -0,0 +1,52 @@
+/****************************************************************
+ * 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 *
+ * *
+ * 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.apache.james.mailetcontainer.camel;
+
+import org.apache.camel.impl.DefaultCamelContext;
+import org.apache.commons.configuration.ConfigurationException;
+import org.apache.commons.configuration.HierarchicalConfiguration;
+import org.apache.commons.logging.impl.SimpleLog;
+import
org.apache.james.mailetcontainer.lib.AbstractStateCompositeProcessorTest;
+import org.apache.james.mailetcontainer.lib.AbstractStateCompositeProcessor;
+import org.apache.james.mailetcontainer.lib.mock.MockMailetLoader;
+import org.apache.james.mailetcontainer.lib.mock.MockMailetContext;
+import org.apache.james.mailetcontainer.lib.mock.MockMatcherLoader;
+
+public class CamelCompositeProcessorTest extends
AbstractStateCompositeProcessorTest{
+
+ @Override
+ protected AbstractStateCompositeProcessor
createProcessor(HierarchicalConfiguration config) throws
ConfigurationException, Exception {
+ CamelCompositeProcessor processor = new CamelCompositeProcessor();
+ try {
+ processor.setLog(new SimpleLog("MockLog"));
+ processor.setCamelContext(new DefaultCamelContext());
+ processor.setMailetLoader(new MockMailetLoader());
+ processor.setMatcherLoader(new MockMatcherLoader());
+ processor.setMailetContext(new MockMailetContext());
+ processor.configure(config);
+ processor.init();
+ return processor;
+ } catch (Exception e) {
+ processor.dispose();
+ throw e;
+ }
+
+ }
+
+}
Added:
james/server/trunk/mailetcontainer-library/src/test/java/org/apache/james/mailetcontainer/lib/AbstractStateCompositeProcessorTest.java
URL:
http://svn.apache.org/viewvc/james/server/trunk/mailetcontainer-library/src/test/java/org/apache/james/mailetcontainer/lib/AbstractStateCompositeProcessorTest.java?rev=1052220&view=auto
==============================================================================
---
james/server/trunk/mailetcontainer-library/src/test/java/org/apache/james/mailetcontainer/lib/AbstractStateCompositeProcessorTest.java
(added)
+++
james/server/trunk/mailetcontainer-library/src/test/java/org/apache/james/mailetcontainer/lib/AbstractStateCompositeProcessorTest.java
Thu Dec 23 10:54:08 2010
@@ -0,0 +1,176 @@
+/****************************************************************
+ * 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 *
+ * *
+ * 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.apache.james.mailetcontainer.lib;
+
+import java.io.ByteArrayInputStream;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import javax.mail.MessagingException;
+
+import org.apache.commons.configuration.ConfigurationException;
+import org.apache.commons.configuration.DefaultConfigurationBuilder;
+import org.apache.commons.configuration.HierarchicalConfiguration;
+import org.apache.commons.logging.impl.SimpleLog;
+import org.apache.james.core.MailImpl;
+import org.apache.james.mailetcontainer.api.MailProcessor;
+import org.apache.james.mailetcontainer.lib.mock.MockMailProcessor;
+import org.apache.mailet.Mail;
+
+import junit.framework.TestCase;
+
+public abstract class AbstractStateCompositeProcessorTest extends TestCase{
+
+
+ public void testChooseRightProcessor() throws Exception {
+
+ Map<String,String> configMap = new HashMap<String, String>();
+ configMap.put("root", "test");
+ configMap.put("test", "invalid");
+ configMap.put("error", "invalid");
+
+ final AtomicInteger count = new AtomicInteger(0);
+ AbstractStateCompositeProcessor processor = new
AbstractStateCompositeProcessor() {
+
+ @Override
+ protected MailProcessor createMailProcessor(final String state,
HierarchicalConfiguration config) throws Exception {
+ String newstate = config.getString("[...@newstate]");
+ return new MockMailProcessor(newstate) {
+
+ @Override
+ public void service(Mail mail) throws MessagingException {
+ // check if the right processor was selected depending
on the state
+ assertEquals(state, mail.getState());
+ super.service(mail);
+ count.incrementAndGet();
+ }
+
+ };
+ }
+ };
+ SimpleLog log = new SimpleLog("MockLog");
+ log.setLevel(SimpleLog.LOG_LEVEL_DEBUG);
+ processor.setLog(log);
+ processor.configure(createMockConfig(configMap));
+ processor.init();
+
+ try {
+ processor.service(new MailImpl());
+ fail("Should have failed because of an not configured processor");
+ } catch (MessagingException ex) {
+ // we should have gone throw 2 processors
+ assertEquals(2, count.get());
+ } finally {
+ processor.dispose();
+ }
+
+ }
+
+
+ protected abstract AbstractStateCompositeProcessor
createProcessor(HierarchicalConfiguration config) throws
ConfigurationException, Exception;
+
+
+ public void testGhostProcessor() throws Exception {
+ AbstractStateCompositeProcessor processor = null;
+
+ try {
+ processor = createProcessor(createConfig(Arrays.asList("root",
"error", "ghost")));
+
+ fail("ghost processor should not be allowed");
+ } catch (ConfigurationException e) {
+ // expected
+ } finally {
+ if (processor != null) {
+ processor.dispose();
+ }
+ }
+
+ }
+
+ public void testNoRootProcessor() throws Exception {
+ AbstractStateCompositeProcessor processor = null;
+ try {
+ processor = createProcessor(createConfig(Arrays.asList("test",
"error")));
+ fail("root processor is needed");
+ } catch (ConfigurationException e) {
+ // expected
+ } finally {
+ if (processor != null) {
+ processor.dispose();
+ }
+ }
+ }
+
+ public void testNoErrorProcessor() throws Exception {
+ AbstractStateCompositeProcessor processor = null;
+ try {
+ processor = createProcessor(createConfig(Arrays.asList("test",
"root")));
+ fail("error processor is needed");
+ } catch (ConfigurationException e) {
+ // expected
+ } finally {
+ if (processor != null) {
+ processor.dispose();
+ }
+ }
+ }
+
+ private HierarchicalConfiguration createConfig(List<String> states) throws
ConfigurationException {
+
+ StringBuilder sb = new StringBuilder();
+ sb.append("<?xml version=\"1.0\"?>");
+ sb.append("<processors>");
+ for (int i = 0 ; i < states.size(); i++) {
+ sb.append("<processor state=\"");
+ sb.append(states.get(i));
+ sb.append("\"/>");
+ }
+ sb.append("</processors>");
+
+ DefaultConfigurationBuilder builder = new
DefaultConfigurationBuilder();
+ builder.load(new ByteArrayInputStream(sb.toString().getBytes()));
+ return builder;
+ }
+
+ private HierarchicalConfiguration createMockConfig(Map<String,String>
states) throws ConfigurationException {
+
+ StringBuilder sb = new StringBuilder();
+ sb.append("<?xml version=\"1.0\"?>");
+ sb.append("<processors>");
+ Iterator<String> keys = states.keySet().iterator();
+ while(keys.hasNext()) {
+ String state = keys.next();
+ String newstate = states.get(state);
+ sb.append("<processor state=\"");
+ sb.append(state);
+ sb.append("\" newstate=\"");
+ sb.append(newstate);
+ sb.append("\"/>");
+ }
+ sb.append("</processors>");
+
+ DefaultConfigurationBuilder builder = new
DefaultConfigurationBuilder();
+ builder.load(new ByteArrayInputStream(sb.toString().getBytes()));
+ return builder;
+ }
+}
Added:
james/server/trunk/mailetcontainer-library/src/test/java/org/apache/james/mailetcontainer/lib/AbstractStateMailetProcessorTest.java
URL:
http://svn.apache.org/viewvc/james/server/trunk/mailetcontainer-library/src/test/java/org/apache/james/mailetcontainer/lib/AbstractStateMailetProcessorTest.java?rev=1052220&view=auto
==============================================================================
---
james/server/trunk/mailetcontainer-library/src/test/java/org/apache/james/mailetcontainer/lib/AbstractStateMailetProcessorTest.java
(added)
+++
james/server/trunk/mailetcontainer-library/src/test/java/org/apache/james/mailetcontainer/lib/AbstractStateMailetProcessorTest.java
Thu Dec 23 10:54:08 2010
@@ -0,0 +1,51 @@
+/****************************************************************
+ * 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 *
+ * *
+ * 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.apache.james.mailetcontainer.lib;
+
+import java.io.ByteArrayInputStream;
+
+import org.apache.commons.configuration.ConfigurationException;
+import org.apache.commons.configuration.DefaultConfigurationBuilder;
+import org.apache.commons.configuration.HierarchicalConfiguration;
+import org.apache.james.mailetcontainer.lib.mock.MockMailet;
+import org.apache.james.mailetcontainer.lib.mock.MockMatcher;
+
+import junit.framework.TestCase;
+
+public abstract class AbstractStateMailetProcessorTest extends TestCase{
+
+ protected abstract AbstractStateMailetProcessor
createProcessor(HierarchicalConfiguration configuration) throws
ConfigurationException, Exception;
+
+
+
+ private HierarchicalConfiguration createConfig() throws
ConfigurationException {
+ StringBuilder sb = new StringBuilder();
+ sb.append("<processor>");
+ sb.append("<mailet
match=\"").append(MockMatcher.class.getName()).append("=t...@localhost\"").append("
class=\"").append(MockMailet.class.getName()).append("\">");
+ sb.append("<flag>test</flag>");
+ sb.append("</mailet>");
+
+ sb.append("</processor");
+
+ DefaultConfigurationBuilder builder = new
DefaultConfigurationBuilder();
+ builder.load(new ByteArrayInputStream(sb.toString().getBytes()));
+ return builder;
+ }
+}
Added:
james/server/trunk/mailetcontainer-library/src/test/java/org/apache/james/mailetcontainer/lib/mock/MockMailProcessor.java
URL:
http://svn.apache.org/viewvc/james/server/trunk/mailetcontainer-library/src/test/java/org/apache/james/mailetcontainer/lib/mock/MockMailProcessor.java?rev=1052220&view=auto
==============================================================================
---
james/server/trunk/mailetcontainer-library/src/test/java/org/apache/james/mailetcontainer/lib/mock/MockMailProcessor.java
(added)
+++
james/server/trunk/mailetcontainer-library/src/test/java/org/apache/james/mailetcontainer/lib/mock/MockMailProcessor.java
Thu Dec 23 10:54:08 2010
@@ -0,0 +1,47 @@
+/****************************************************************
+ * 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 *
+ * *
+ * 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.apache.james.mailetcontainer.lib.mock;
+
+import javax.mail.MessagingException;
+
+import org.apache.james.mailetcontainer.api.MailProcessor;
+import org.apache.mailet.Mail;
+
+public class MockMailProcessor implements MailProcessor{
+
+ private boolean shouldThrow = false;
+ private String newState = null;
+
+ public MockMailProcessor(boolean shouldThrow) {
+ this.shouldThrow = shouldThrow;
+ }
+
+ public MockMailProcessor(String newState) {
+ this.newState = newState;
+ }
+
+ public void service(Mail mail) throws MessagingException {
+ if (shouldThrow) {
+ throw new MessagingException();
+ } else {
+ mail.setState(newState);
+ }
+ }
+
+}
Added:
james/server/trunk/mailetcontainer-library/src/test/java/org/apache/james/mailetcontainer/lib/mock/MockMailet.java
URL:
http://svn.apache.org/viewvc/james/server/trunk/mailetcontainer-library/src/test/java/org/apache/james/mailetcontainer/lib/mock/MockMailet.java?rev=1052220&view=auto
==============================================================================
---
james/server/trunk/mailetcontainer-library/src/test/java/org/apache/james/mailetcontainer/lib/mock/MockMailet.java
(added)
+++
james/server/trunk/mailetcontainer-library/src/test/java/org/apache/james/mailetcontainer/lib/mock/MockMailet.java
Thu Dec 23 10:54:08 2010
@@ -0,0 +1,51 @@
+/****************************************************************
+ * 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 *
+ * *
+ * 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.apache.james.mailetcontainer.lib.mock;
+
+import javax.mail.MessagingException;
+
+import org.apache.mailet.Mail;
+import org.apache.mailet.Mailet;
+import org.apache.mailet.MailetConfig;
+
+public class MockMailet implements Mailet{
+
+ private MailetConfig config;
+
+ public void destroy() {
+ }
+
+ public MailetConfig getMailetConfig() {
+ return config;
+ }
+
+ public String getMailetInfo() {
+ return "";
+ }
+
+ public void init(MailetConfig config) throws MessagingException {
+ this.config = config;
+ }
+
+ public void service(Mail mail) throws MessagingException {
+ mail.setAttribute(config.getInitParameter("flag"), mail);
+ }
+
+}
Added:
james/server/trunk/mailetcontainer-library/src/test/java/org/apache/james/mailetcontainer/lib/mock/MockMailetContext.java
URL:
http://svn.apache.org/viewvc/james/server/trunk/mailetcontainer-library/src/test/java/org/apache/james/mailetcontainer/lib/mock/MockMailetContext.java?rev=1052220&view=auto
==============================================================================
---
james/server/trunk/mailetcontainer-library/src/test/java/org/apache/james/mailetcontainer/lib/mock/MockMailetContext.java
(added)
+++
james/server/trunk/mailetcontainer-library/src/test/java/org/apache/james/mailetcontainer/lib/mock/MockMailetContext.java
Thu Dec 23 10:54:08 2010
@@ -0,0 +1,160 @@
+/****************************************************************
+ * 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 *
+ * *
+ * 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.apache.james.mailetcontainer.lib.mock;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import javax.mail.MessagingException;
+import javax.mail.internet.AddressException;
+import javax.mail.internet.MimeMessage;
+
+import org.apache.mailet.HostAddress;
+import org.apache.mailet.Mail;
+import org.apache.mailet.MailAddress;
+import org.apache.mailet.MailetContext;
+
+public class MockMailetContext implements MailetContext{
+
+ private Map<String, Object> attributes = new HashMap<String, Object>();
+
+ public void bounce(Mail arg0, String arg1) throws MessagingException {
+ throw new UnsupportedOperationException("Not implemented");
+
+ }
+
+ public void bounce(Mail arg0, String arg1, MailAddress arg2) throws
MessagingException {
+ throw new UnsupportedOperationException("Not implemented");
+
+ }
+
+ public Object getAttribute(String arg0) {
+ return attributes.get(arg0);
+ }
+
+ public Iterator getAttributeNames() {
+ return attributes.keySet().iterator();
+ }
+
+ /**
+ * Return an {...@link Collection} which holds "mx.localhost" if the given
host was "localhost". Otherwise
+ * and empty {...@link Collection} is returned
+ */
+ public Collection getMailServers(String host) {
+ List<String> servers = new ArrayList<String>();
+ if ("localhost".equalsIgnoreCase(host)) {
+ servers.add("mx.localhost");
+ }
+ return servers;
+ }
+
+ public int getMajorVersion() {
+ return 0;
+ }
+
+ public int getMinorVersion() {
+ return 0;
+ }
+
+ public MailAddress getPostmaster() {
+ try {
+ return new MailAddress("postmas...@localhost");
+ } catch (AddressException e) {
+ // will never happen
+ return null;
+ }
+ }
+
+ public Iterator getSMTPHostAddresses(String arg0) {
+ return new ArrayList<HostAddress>().iterator();
+ }
+
+ public String getServerInfo() {
+ return "Mock Server";
+ }
+
+ /**
+ * @see #isLocalUser(String)
+ */
+ public boolean isLocalEmail(MailAddress arg0) {
+ return isLocalUser(arg0.toString());
+ }
+
+ /**
+ * Return true if "localhost" was given
+ */
+ public boolean isLocalServer(String server) {
+ return "localhost".equalsIgnoreCase(server);
+ }
+
+ /**
+ * Return true if "localu...@localhost" was given
+ */
+ public boolean isLocalUser(String user) {
+ return "localu...@localhost".equalsIgnoreCase(user);
+ }
+
+ public void log(String msg) {
+ System.out.println(msg);
+ }
+
+ public void log(String arg0, Throwable arg1) {
+ System.out.println(arg0);
+ arg1.printStackTrace();
+
+ }
+
+ public void removeAttribute(String arg0) {
+ attributes.remove(arg0);
+ }
+
+ public void sendMail(MimeMessage arg0) throws MessagingException {
+ throw new UnsupportedOperationException("Not implemented");
+
+ }
+
+ public void sendMail(Mail arg0) throws MessagingException {
+ throw new UnsupportedOperationException("Not implemented");
+
+ }
+
+ public void sendMail(MailAddress arg0, Collection arg1, MimeMessage arg2)
throws MessagingException {
+ throw new UnsupportedOperationException("Not implemented");
+
+ }
+
+ public void sendMail(MailAddress arg0, Collection arg1, MimeMessage arg2,
String arg3) throws MessagingException {
+ throw new UnsupportedOperationException("Not implemented");
+
+ }
+
+ public void setAttribute(String arg0, Object arg1) {
+ attributes.put(arg0, arg1);
+ }
+
+ public void storeMail(MailAddress arg0, MailAddress arg1, MimeMessage
arg2) throws MessagingException {
+ throw new UnsupportedOperationException("Not implemented");
+ }
+
+}
Added:
james/server/trunk/mailetcontainer-library/src/test/java/org/apache/james/mailetcontainer/lib/mock/MockMailetLoader.java
URL:
http://svn.apache.org/viewvc/james/server/trunk/mailetcontainer-library/src/test/java/org/apache/james/mailetcontainer/lib/mock/MockMailetLoader.java?rev=1052220&view=auto
==============================================================================
---
james/server/trunk/mailetcontainer-library/src/test/java/org/apache/james/mailetcontainer/lib/mock/MockMailetLoader.java
(added)
+++
james/server/trunk/mailetcontainer-library/src/test/java/org/apache/james/mailetcontainer/lib/mock/MockMailetLoader.java
Thu Dec 23 10:54:08 2010
@@ -0,0 +1,42 @@
+/****************************************************************
+ * 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 *
+ * *
+ * 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.apache.james.mailetcontainer.lib.mock;
+
+import javax.mail.MessagingException;
+
+import org.apache.james.mailetcontainer.api.MailetLoader;
+import org.apache.mailet.Mailet;
+import org.apache.mailet.MailetConfig;
+
+public class MockMailetLoader implements MailetLoader{
+
+ @SuppressWarnings("unchecked")
+ public Mailet getMailet(MailetConfig config) throws MessagingException {
+ try {
+ Class<Mailet> clazz =
(Class<Mailet>)Thread.currentThread().getContextClassLoader().loadClass(config.getMailetName());
+ Mailet m = clazz.newInstance();
+ m.init(config);
+ return m;
+ } catch (Exception e) {
+ throw new MessagingException("Unable to load mailet " +
config.getMailetName());
+ }
+
+ }
+
+}
Added:
james/server/trunk/mailetcontainer-library/src/test/java/org/apache/james/mailetcontainer/lib/mock/MockMatcher.java
URL:
http://svn.apache.org/viewvc/james/server/trunk/mailetcontainer-library/src/test/java/org/apache/james/mailetcontainer/lib/mock/MockMatcher.java?rev=1052220&view=auto
==============================================================================
---
james/server/trunk/mailetcontainer-library/src/test/java/org/apache/james/mailetcontainer/lib/mock/MockMatcher.java
(added)
+++
james/server/trunk/mailetcontainer-library/src/test/java/org/apache/james/mailetcontainer/lib/mock/MockMatcher.java
Thu Dec 23 10:54:08 2010
@@ -0,0 +1,73 @@
+/****************************************************************
+ * 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 *
+ * *
+ * 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.apache.james.mailetcontainer.lib.mock;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.mail.MessagingException;
+
+import org.apache.mailet.Mail;
+import org.apache.mailet.MailAddress;
+import org.apache.mailet.Matcher;
+import org.apache.mailet.MatcherConfig;
+
+public class MockMatcher implements Matcher{
+
+ private List<String> matches = new ArrayList<String>();
+ private MatcherConfig config;
+
+ public void destroy() {
+
+ }
+
+ public MatcherConfig getMatcherConfig() {
+ return config;
+ }
+
+ public String getMatcherInfo() {
+ return getClass().getName();
+ }
+
+ public void init(MatcherConfig config) throws MessagingException {
+ this.config = config;
+ matches.addAll(Arrays.asList(config.getCondition().split(",")));
+ }
+
+ public Collection match(Mail mail) throws MessagingException {
+ List<MailAddress> match = new ArrayList<MailAddress>();
+
+ Iterator<MailAddress> rcpts = mail.getRecipients().iterator();
+ while (rcpts.hasNext()) {
+ MailAddress addr = rcpts.next();
+ if (matches.contains(addr.toString())) {
+ match.add(addr);
+ }
+ }
+ if (match.isEmpty()) {
+ return null;
+ }
+ return match;
+ }
+
+}
Added:
james/server/trunk/mailetcontainer-library/src/test/java/org/apache/james/mailetcontainer/lib/mock/MockMatcherLoader.java
URL:
http://svn.apache.org/viewvc/james/server/trunk/mailetcontainer-library/src/test/java/org/apache/james/mailetcontainer/lib/mock/MockMatcherLoader.java?rev=1052220&view=auto
==============================================================================
---
james/server/trunk/mailetcontainer-library/src/test/java/org/apache/james/mailetcontainer/lib/mock/MockMatcherLoader.java
(added)
+++
james/server/trunk/mailetcontainer-library/src/test/java/org/apache/james/mailetcontainer/lib/mock/MockMatcherLoader.java
Thu Dec 23 10:54:08 2010
@@ -0,0 +1,43 @@
+/****************************************************************
+ * 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 *
+ * *
+ * 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.apache.james.mailetcontainer.lib.mock;
+
+import javax.mail.MessagingException;
+
+import org.apache.james.mailetcontainer.api.MatcherLoader;
+import org.apache.mailet.Matcher;
+import org.apache.mailet.MatcherConfig;
+
+public class MockMatcherLoader implements MatcherLoader{
+
+ @SuppressWarnings("unchecked")
+ public Matcher getMatcher(MatcherConfig config) throws MessagingException {
+
+ try {
+ Class<Matcher> clazz =
(Class<Matcher>)Thread.currentThread().getContextClassLoader().loadClass(config.getMatcherName());
+ Matcher m = clazz.newInstance();
+ m.init(config);
+ return m;
+ } catch (Exception e) {
+ throw new MessagingException("Unable to load matcher " +
config.getMatcherName());
+ }
+
+ }
+
+}
Modified: james/server/trunk/pom.xml
URL:
http://svn.apache.org/viewvc/james/server/trunk/pom.xml?rev=1052220&r1=1052219&r2=1052220&view=diff
==============================================================================
--- james/server/trunk/pom.xml (original)
+++ james/server/trunk/pom.xml Thu Dec 23 10:54:08 2010
@@ -444,7 +444,13 @@
<artifactId>james-server-mailetcontainer-library</artifactId>
<version>${project.version}</version>
</dependency>
-
+ <dependency>
+ <groupId>org.apache.james</groupId>
+ <artifactId>james-server-mailetcontainer-library</artifactId>
+ <type>test-jar</type>
+ <scope>test</scope>
+ <version>${project.version}</version>
+ </dependency>
<dependency>
<groupId>org.apache.james</groupId>
<artifactId>james-server-mailetcontainer-camel</artifactId>
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]