You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by ad...@apache.org on 2017/12/05 07:30:44 UTC
[04/19] james-project git commit: JAMES-2242 Remove unused
MailetContext subclass
JAMES-2242 Remove unused MailetContext subclass
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/41c00e7d
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/41c00e7d
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/41c00e7d
Branch: refs/heads/master
Commit: 41c00e7dc30066c98eead45d05bd94bbca5113ab
Parents: 765a8fd
Author: benwa <bt...@linagora.com>
Authored: Wed Nov 29 16:41:24 2017 +0700
Committer: Antoine Duprat <ad...@linagora.com>
Committed: Mon Dec 4 14:42:14 2017 +0100
----------------------------------------------------------------------
.../api/mock/MockMailetContext.java | 195 ---------------
.../impl/camel/CamelCompositeProcessorTest.java | 4 +-
.../impl/camel/CamelMailetProcessorTest.java | 4 +-
.../transport/mailets/RecordingMailContext.java | 235 -------------------
.../smtpserver/mock/mailet/MockMailContext.java | 167 -------------
5 files changed, 4 insertions(+), 601 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/41c00e7d/server/mailet/mailetcontainer-api/src/test/java/org/apache/james/mailetcontainer/api/mock/MockMailetContext.java
----------------------------------------------------------------------
diff --git a/server/mailet/mailetcontainer-api/src/test/java/org/apache/james/mailetcontainer/api/mock/MockMailetContext.java b/server/mailet/mailetcontainer-api/src/test/java/org/apache/james/mailetcontainer/api/mock/MockMailetContext.java
deleted file mode 100644
index ac061d7..0000000
--- a/server/mailet/mailetcontainer-api/src/test/java/org/apache/james/mailetcontainer/api/mock/MockMailetContext.java
+++ /dev/null
@@ -1,195 +0,0 @@
-/****************************************************************
- * 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.api.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.LookupException;
-import org.apache.mailet.Mail;
-import org.apache.james.core.MailAddress;
-import org.apache.mailet.MailetContext;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-@SuppressWarnings("deprecation")
-public class MockMailetContext implements MailetContext {
-
- private static final Logger LOGGER = LoggerFactory.getLogger(MockMailetContext.class);
-
- private final Map<String, Object> attributes = new HashMap<>();
- private final List<Mail> mails = new ArrayList<>();
-
- @Override
- public void bounce(Mail arg0, String arg1) throws MessagingException {
- throw new UnsupportedOperationException("Not implemented");
- }
-
- @Override
- public void bounce(Mail arg0, String arg1, MailAddress arg2) throws MessagingException {
- throw new UnsupportedOperationException("Not implemented");
- }
-
- @Override
- public List<String> dnsLookup(String s, RecordType recordType) throws LookupException {
- throw new UnsupportedOperationException("Not implemented");
- }
-
- @Override
- public Object getAttribute(String arg0) {
- return attributes.get(arg0);
- }
-
- @Override
- public Iterator<String> 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
- */
- @Override
- public Collection<String> getMailServers(String host) {
- List<String> servers = new ArrayList<>();
- if ("localhost".equalsIgnoreCase(host)) {
- servers.add("mx.localhost");
- }
- return servers;
- }
-
- @Override
- public int getMajorVersion() {
- return 0;
- }
-
- @Override
- public int getMinorVersion() {
- return 0;
- }
-
- @Override
- public MailAddress getPostmaster() {
- try {
- return new MailAddress("postmaster@localhost");
- } catch (AddressException e) {
- // will never happen
- return null;
- }
- }
-
- @Override
- public Iterator<HostAddress> getSMTPHostAddresses(String arg0) {
- return new ArrayList<HostAddress>().iterator();
- }
-
- @Override
- public String getServerInfo() {
- return "Mock Server";
- }
-
- /**
- * @see #isLocalUser(String)
- */
- @Override
- public boolean isLocalEmail(MailAddress arg0) {
- return isLocalUser(arg0.toString());
- }
-
- /**
- * Return true if "localhost" was given
- */
- @Override
- public boolean isLocalServer(String server) {
- return "localhost".equalsIgnoreCase(server);
- }
-
- /**
- * Return true if "localuser@localhost" was given
- */
- @Override
- public boolean isLocalUser(String user) {
- return "localuser@localhost".equalsIgnoreCase(user);
- }
-
- @Override
- public void log(String msg) {
- System.out.println(msg);
- }
-
- @Override
- public void log(String arg0, Throwable arg1) {
- System.out.println(arg0);
- arg1.printStackTrace();
- }
-
- @Override
- public void log(LogLevel logLevel, String s) {
- throw new UnsupportedOperationException("Not implemented");
- }
-
- @Override
- public void log(LogLevel logLevel, String s, Throwable throwable) {
- throw new UnsupportedOperationException("Not implemented");
- }
-
- @Override
- public void removeAttribute(String arg0) {
- attributes.remove(arg0);
- }
-
- @Override
- public void sendMail(MimeMessage arg0) throws MessagingException {
- throw new UnsupportedOperationException("Not implemented");
- }
-
- @Override
- public void sendMail(Mail mail) throws MessagingException {
- mails.add(mail);
- }
-
- @Override
- public void sendMail(MailAddress arg0, Collection<MailAddress> arg1, MimeMessage arg2) throws MessagingException {
- throw new UnsupportedOperationException("Not implemented");
- }
-
- @Override
- public void sendMail(MailAddress arg0, Collection<MailAddress> arg1, MimeMessage arg2, String arg3) throws MessagingException {
- throw new UnsupportedOperationException("Not implemented");
- }
-
- @Override
- public void setAttribute(String arg0, Object arg1) {
- attributes.put(arg0, arg1);
- }
-
- @Override
- public Logger getLogger() {
- return LOGGER;
- }
-}
http://git-wip-us.apache.org/repos/asf/james-project/blob/41c00e7d/server/mailet/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/impl/camel/CamelCompositeProcessorTest.java
----------------------------------------------------------------------
diff --git a/server/mailet/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/impl/camel/CamelCompositeProcessorTest.java b/server/mailet/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/impl/camel/CamelCompositeProcessorTest.java
index d1373ce..7dd9a6a 100644
--- a/server/mailet/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/impl/camel/CamelCompositeProcessorTest.java
+++ b/server/mailet/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/impl/camel/CamelCompositeProcessorTest.java
@@ -20,12 +20,12 @@ package org.apache.james.mailetcontainer.impl.camel;
import org.apache.camel.impl.DefaultCamelContext;
import org.apache.commons.configuration.HierarchicalConfiguration;
-import org.apache.james.mailetcontainer.api.mock.MockMailetContext;
import org.apache.james.mailetcontainer.api.mock.MockMailetLoader;
import org.apache.james.mailetcontainer.api.mock.MockMatcherLoader;
import org.apache.james.mailetcontainer.lib.AbstractStateCompositeProcessor;
import org.apache.james.mailetcontainer.lib.AbstractStateCompositeProcessorTest;
import org.apache.james.metrics.api.NoopMetricFactory;
+import org.apache.mailet.base.test.FakeMailContext;
public class CamelCompositeProcessorTest extends AbstractStateCompositeProcessorTest {
@@ -36,7 +36,7 @@ public class CamelCompositeProcessorTest extends AbstractStateCompositeProcessor
processor.setCamelContext(new DefaultCamelContext());
processor.setMailetLoader(new MockMailetLoader());
processor.setMatcherLoader(new MockMatcherLoader());
- processor.setMailetContext(new MockMailetContext());
+ processor.setMailetContext(FakeMailContext.defaultContext());
processor.configure(config);
processor.init();
return processor;
http://git-wip-us.apache.org/repos/asf/james-project/blob/41c00e7d/server/mailet/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/impl/camel/CamelMailetProcessorTest.java
----------------------------------------------------------------------
diff --git a/server/mailet/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/impl/camel/CamelMailetProcessorTest.java b/server/mailet/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/impl/camel/CamelMailetProcessorTest.java
index d76bae2..9a8488c 100644
--- a/server/mailet/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/impl/camel/CamelMailetProcessorTest.java
+++ b/server/mailet/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/impl/camel/CamelMailetProcessorTest.java
@@ -24,12 +24,12 @@ import static org.mockito.Mockito.mock;
import org.apache.camel.impl.DefaultCamelContext;
import org.apache.commons.configuration.HierarchicalConfiguration;
import org.apache.james.mailetcontainer.api.MailProcessor;
-import org.apache.james.mailetcontainer.api.mock.MockMailetContext;
import org.apache.james.mailetcontainer.api.mock.MockMailetLoader;
import org.apache.james.mailetcontainer.api.mock.MockMatcherLoader;
import org.apache.james.mailetcontainer.lib.AbstractStateMailetProcessor;
import org.apache.james.mailetcontainer.lib.AbstractStateMailetProcessorTest;
import org.apache.james.metrics.api.NoopMetricFactory;
+import org.apache.mailet.base.test.FakeMailContext;
public class CamelMailetProcessorTest extends AbstractStateMailetProcessorTest {
@@ -39,7 +39,7 @@ public class CamelMailetProcessorTest extends AbstractStateMailetProcessorTest {
try {
processor = new CamelMailetProcessor(new NoopMetricFactory());
processor.setCamelContext(new DefaultCamelContext());
- processor.setMailetContext(new MockMailetContext());
+ processor.setMailetContext(FakeMailContext.defaultContext());
processor.setMailetLoader(new MockMailetLoader());
processor.setMatcherLoader(new MockMatcherLoader());
processor.setRootMailProcessor(mock(MailProcessor.class));
http://git-wip-us.apache.org/repos/asf/james-project/blob/41c00e7d/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/RecordingMailContext.java
----------------------------------------------------------------------
diff --git a/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/RecordingMailContext.java b/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/RecordingMailContext.java
deleted file mode 100644
index 6866a48..0000000
--- a/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/RecordingMailContext.java
+++ /dev/null
@@ -1,235 +0,0 @@
-/****************************************************************
- * 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.transport.mailets;
-
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-
-import javax.mail.MessagingException;
-import javax.mail.internet.MimeMessage;
-
-import org.apache.mailet.HostAddress;
-import org.apache.mailet.LookupException;
-import org.apache.mailet.Mail;
-import org.apache.james.core.MailAddress;
-import org.apache.mailet.MailetContext;
-import org.apache.mailet.TemporaryLookupException;
-import org.apache.mailet.base.test.FakeMailContext;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * @since 15.12.12 12:02
- */
-@SuppressWarnings("deprecation")
-public class RecordingMailContext implements MailetContext {
- private static final Logger LOGGER = LoggerFactory.getLogger(RecordingMailContext.class);
-
- private final List<SendMailEvent> sendmails = new LinkedList<>();
- private final FakeMailContext context;
-
- public RecordingMailContext() {
- context = FakeMailContext.defaultContext();
- }
-
- @Override
- public boolean isLocalServer(String serverName) {
- return "localhost".equals(serverName);
- }
-
- @Override
- public void sendMail(Mail mail) throws MessagingException {
- sendmails.add(new SendMailEvent(mail));
- }
-
- @Override
- public void sendMail(MimeMessage msg) throws MessagingException {
- sendmails.add(new SendMailEvent(msg));
- }
-
- @Override
- public void sendMail(MailAddress sender, Collection<MailAddress> recipients, MimeMessage msg) throws MessagingException {
- sendmails.add(new SendMailEvent(msg, sender, recipients));
- }
-
- @Override
- public void sendMail(MailAddress sender, Collection<MailAddress> recipients, MimeMessage msg, String state) throws MessagingException {
- sendmails.add(new SendMailEvent(msg, sender, recipients, state));
- }
-
- public List<SendMailEvent> getSendmails() {
- return sendmails;
- }
-
- public static class SendMailEvent {
- private final Object message;
- private final MailAddress sender;
- private final Collection<MailAddress> recipients;
- private final String state;
-
- private SendMailEvent(Object message, MailAddress sender, Collection<MailAddress> recipients, String state) {
- this.message = message;
- this.sender = sender;
- this.recipients = recipients;
- this.state = state;
- }
-
- public SendMailEvent(Mail mail) {
- this(mail, null, null, null);
- }
-
- public SendMailEvent(MimeMessage mail) {
- this(mail, null, null, null);
- }
-
- public SendMailEvent(MimeMessage mail, MailAddress sender, Collection<MailAddress> recipients) {
- this(mail, sender, recipients, null);
- }
- public SendMailEvent(MimeMessage mail, MailAddress sender, Collection<MailAddress> recipients, String state) {
- this((Object)mail, sender, recipients, state);
- }
-
- public Mail getMail() {
- if (message instanceof Mail) {
- return (Mail) message;
- }
- return null;
- }
- public MimeMessage getMessage() {
- if (message instanceof MimeMessage) {
- return (MimeMessage) message;
- }
- return null;
- }
-
- public MailAddress getSender() {
- return sender;
- }
-
- public Collection<MailAddress> getRecipients() {
- return recipients;
- }
-
- public String getState() {
- return state;
- }
- }
-
- @Override
- public int getMajorVersion() {
- return context.getMajorVersion();
- }
-
- @Override
- public int getMinorVersion() {
- return context.getMinorVersion();
- }
-
- @Override
- public String getServerInfo() {
- return context.getServerInfo();
- }
-
- @Override
- public Iterator<String> getAttributeNames() {
- return context.getAttributeNames();
- }
-
- @Override
- public Object getAttribute(String name) {
- return context.getAttribute(name);
- }
-
- @Override
- public void setAttribute(String name, Object value) {
- context.setAttribute(name, value);
- }
-
- @Override
- public void removeAttribute(String name) {
- context.removeAttribute(name);
- }
-
- @Override
- public void log(String message) {
- LOGGER.info(message);
- }
-
- @Override
- public void log(String message, Throwable t) {
- LOGGER.error(message, t);
- }
-
- @Override
- public void log(LogLevel level, String message) {
- context.log(level, message);
- }
-
- @Override
- public void log(LogLevel level, String message, Throwable t) {
- context.log(level, message, t);
- }
-
- @Override
- public MailAddress getPostmaster() {
- return context.getPostmaster();
- }
-
- @Override
- public boolean isLocalUser(String userAccount) {
- return context.isLocalUser(userAccount);
- }
-
- @Override
- public boolean isLocalEmail(MailAddress mailAddress) {
- return context.isLocalEmail(mailAddress);
- }
-
- @Override
- public Collection<String> getMailServers(String domain) {
- return context.getMailServers(domain);
- }
-
- @Override
- public Iterator<HostAddress> getSMTPHostAddresses(String domain) {
- return context.getSMTPHostAddresses(domain);
- }
-
- @Override
- public void bounce(Mail mail, String message) throws MessagingException {
- context.bounce(mail, message);
- }
-
- @Override
- public void bounce(Mail mail, String message, MailAddress bouncer) throws MessagingException {
- context.bounce(mail, message, bouncer);
- }
-
- @Override
- public List<String> dnsLookup(String name, RecordType type) throws TemporaryLookupException, LookupException {
- return context.dnsLookup(name, type);
- }
-
- @Override
- public Logger getLogger() {
- return context.getLogger();
- }
-}
http://git-wip-us.apache.org/repos/asf/james-project/blob/41c00e7d/server/protocols/protocols-smtp/src/test/java/org/apache/james/smtpserver/mock/mailet/MockMailContext.java
----------------------------------------------------------------------
diff --git a/server/protocols/protocols-smtp/src/test/java/org/apache/james/smtpserver/mock/mailet/MockMailContext.java b/server/protocols/protocols-smtp/src/test/java/org/apache/james/smtpserver/mock/mailet/MockMailContext.java
deleted file mode 100644
index 9e1b342..0000000
--- a/server/protocols/protocols-smtp/src/test/java/org/apache/james/smtpserver/mock/mailet/MockMailContext.java
+++ /dev/null
@@ -1,167 +0,0 @@
-/****************************************************************
- * 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.smtpserver.mock.mailet;
-
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-
-import javax.mail.MessagingException;
-import javax.mail.internet.MimeMessage;
-
-import org.apache.mailet.HostAddress;
-import org.apache.mailet.LookupException;
-import org.apache.mailet.Mail;
-import org.apache.james.core.MailAddress;
-import org.apache.mailet.MailetContext;
-import org.slf4j.Logger;
-
-@SuppressWarnings("deprecation")
-public class MockMailContext implements MailetContext {
-
- final HashMap<String, Object> attributes = new HashMap<>();
-
- @Override
- public void bounce(Mail mail, String message) throws MessagingException {
- // trivial implementation
- }
-
- @Override
- public void bounce(Mail mail, String message, MailAddress bouncer) throws MessagingException {
- // trivial implementation
- }
-
- @Override
- public List<String> dnsLookup(String s, RecordType recordType) throws LookupException {
- throw new UnsupportedOperationException("Not yet implemented");
- }
-
- @Override
- public Collection<String> getMailServers(String host) {
- return null; // trivial implementation
- }
-
- @Override
- public MailAddress getPostmaster() {
- return null; // trivial implementation
- }
-
- @Override
- public Object getAttribute(String name) {
- return attributes.get(name);
- }
-
- @Override
- public Iterator<String> getAttributeNames() {
- return attributes.keySet().iterator();
- }
-
- @Override
- public int getMajorVersion() {
- return 0; // trivial implementation
- }
-
- @Override
- public int getMinorVersion() {
- return 0; // trivial implementation
- }
-
- @Override
- public String getServerInfo() {
- return "Mock Server";
- }
-
- @Override
- public boolean isLocalServer(String serverName) {
- return false; // trivial implementation
- }
-
- @Override
- public boolean isLocalUser(String userAccount) {
- return false; // trivial implementation
- }
-
- @Override
- public boolean isLocalEmail(MailAddress mailAddress) {
- return false; // trivial implementation
- }
-
- @Override
- public void log(String message) {
- System.out.println(message);
- }
-
- @Override
- public void log(String message, Throwable t) {
- System.out.println(message);
- t.printStackTrace(System.out);
- }
-
- @Override
- public void log(LogLevel logLevel, String s) {
- //To change body of implemented methods use File | Settings | File Templates.
- }
-
- @Override
- public void log(LogLevel logLevel, String s, Throwable throwable) {
- //To change body of implemented methods use File | Settings | File Templates.
- }
-
- @Override
- public void removeAttribute(String name) {
- // trivial implementation
- }
-
- @Override
- public void sendMail(MimeMessage msg) throws MessagingException {
- throw new UnsupportedOperationException("MOCKed method");
- }
-
- @Override
- public void sendMail(MailAddress sender, Collection<MailAddress> recipients, MimeMessage msg) throws MessagingException {
- throw new UnsupportedOperationException("MOCKed method");
- }
-
- @Override
- public void sendMail(MailAddress sender, Collection<MailAddress> recipients, MimeMessage msg, String state) throws
- MessagingException {
- throw new UnsupportedOperationException("MOCKed method");
- }
-
- @Override
- public void sendMail(Mail mail) throws MessagingException {
- throw new UnsupportedOperationException("MOCKed method");
- }
-
- @Override
- public void setAttribute(String name, Object object) {
- attributes.put(name, object);
- }
-
- @Override
- public Iterator<HostAddress> getSMTPHostAddresses(String domainName) {
- return null; // trivial implementation
- }
-
- @Override
- public Logger getLogger() {
- return null;
- }
-}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org