Repository: james-project Updated Branches: refs/heads/master 9afa62824 -> d3b455bbd
JAMES-1988 Fix typos Project: http://git-wip-us.apache.org/repos/asf/james-project/repo Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/06950a38 Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/06950a38 Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/06950a38 Branch: refs/heads/master Commit: 06950a38d073caeb400c484ed9d5f7702885ea5a Parents: 9afa628 Author: Raphael Ouazana <raphael.ouaz...@linagora.com> Authored: Tue Apr 11 10:33:28 2017 +0200 Committer: benwa <btell...@linagora.com> Committed: Wed Apr 12 08:48:59 2017 +0700 ---------------------------------------------------------------------- .../destination/extensions-jars/README.md | 5 + .../destination/included-jars/README.md | 5 - .../destination/extensions-jars/README.md | 5 + .../destination/included-jars/README.md | 5 - .../jpa/destination/extensions-jars/README.md | 5 + .../jpa/destination/included-jars/README.md | 5 - .../apache/james/utils/FileSystemFixture.java | 2 +- .../james/utils/GuiceMailetLoaderTest.java | 127 +++++++++++++++++++ .../james/utils/GuiceMatcherLoaderTest.java | 127 +++++++++++++++++++ .../james/utils/GuilceMailetLoaderTest.java | 127 ------------------- .../james/utils/GuilceMatcherLoaderTest.java | 127 ------------------- ...uice-custom-mailets-3.0.0-beta6-SNAPSHOT.jar | Bin 0 -> 11094 bytes ...uice-custom-mailets-3.0.0-beta6-SNAPSHOT.jar | Bin 11094 -> 0 bytes 13 files changed, 270 insertions(+), 270 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/james-project/blob/06950a38/dockerfiles/run/guice/cassandra-ldap/destination/extensions-jars/README.md ---------------------------------------------------------------------- diff --git a/dockerfiles/run/guice/cassandra-ldap/destination/extensions-jars/README.md b/dockerfiles/run/guice/cassandra-ldap/destination/extensions-jars/README.md new file mode 100644 index 0000000..2cea759 --- /dev/null +++ b/dockerfiles/run/guice/cassandra-ldap/destination/extensions-jars/README.md @@ -0,0 +1,5 @@ +# Adding Jars to JAMES + +The jar in this folder will be added to JAMES classpath when mounted under /root/extensions-jars inside the running container. + +You can use it to add you customs Mailets/Matchers. http://git-wip-us.apache.org/repos/asf/james-project/blob/06950a38/dockerfiles/run/guice/cassandra-ldap/destination/included-jars/README.md ---------------------------------------------------------------------- diff --git a/dockerfiles/run/guice/cassandra-ldap/destination/included-jars/README.md b/dockerfiles/run/guice/cassandra-ldap/destination/included-jars/README.md deleted file mode 100644 index 1212484..0000000 --- a/dockerfiles/run/guice/cassandra-ldap/destination/included-jars/README.md +++ /dev/null @@ -1,5 +0,0 @@ -# Adding Jars to JAMES - -The jar in this folder will be added to JAMES classpath when mounted under /root/included-jars inside the running container. - -You can use it to add you customs Mailets/Matchers. http://git-wip-us.apache.org/repos/asf/james-project/blob/06950a38/dockerfiles/run/guice/cassandra/destination/extensions-jars/README.md ---------------------------------------------------------------------- diff --git a/dockerfiles/run/guice/cassandra/destination/extensions-jars/README.md b/dockerfiles/run/guice/cassandra/destination/extensions-jars/README.md new file mode 100644 index 0000000..2cea759 --- /dev/null +++ b/dockerfiles/run/guice/cassandra/destination/extensions-jars/README.md @@ -0,0 +1,5 @@ +# Adding Jars to JAMES + +The jar in this folder will be added to JAMES classpath when mounted under /root/extensions-jars inside the running container. + +You can use it to add you customs Mailets/Matchers. http://git-wip-us.apache.org/repos/asf/james-project/blob/06950a38/dockerfiles/run/guice/cassandra/destination/included-jars/README.md ---------------------------------------------------------------------- diff --git a/dockerfiles/run/guice/cassandra/destination/included-jars/README.md b/dockerfiles/run/guice/cassandra/destination/included-jars/README.md deleted file mode 100644 index 1212484..0000000 --- a/dockerfiles/run/guice/cassandra/destination/included-jars/README.md +++ /dev/null @@ -1,5 +0,0 @@ -# Adding Jars to JAMES - -The jar in this folder will be added to JAMES classpath when mounted under /root/included-jars inside the running container. - -You can use it to add you customs Mailets/Matchers. http://git-wip-us.apache.org/repos/asf/james-project/blob/06950a38/dockerfiles/run/guice/jpa/destination/extensions-jars/README.md ---------------------------------------------------------------------- diff --git a/dockerfiles/run/guice/jpa/destination/extensions-jars/README.md b/dockerfiles/run/guice/jpa/destination/extensions-jars/README.md new file mode 100644 index 0000000..2cea759 --- /dev/null +++ b/dockerfiles/run/guice/jpa/destination/extensions-jars/README.md @@ -0,0 +1,5 @@ +# Adding Jars to JAMES + +The jar in this folder will be added to JAMES classpath when mounted under /root/extensions-jars inside the running container. + +You can use it to add you customs Mailets/Matchers. http://git-wip-us.apache.org/repos/asf/james-project/blob/06950a38/dockerfiles/run/guice/jpa/destination/included-jars/README.md ---------------------------------------------------------------------- diff --git a/dockerfiles/run/guice/jpa/destination/included-jars/README.md b/dockerfiles/run/guice/jpa/destination/included-jars/README.md deleted file mode 100644 index 1212484..0000000 --- a/dockerfiles/run/guice/jpa/destination/included-jars/README.md +++ /dev/null @@ -1,5 +0,0 @@ -# Adding Jars to JAMES - -The jar in this folder will be added to JAMES classpath when mounted under /root/included-jars inside the running container. - -You can use it to add you customs Mailets/Matchers. http://git-wip-us.apache.org/repos/asf/james-project/blob/06950a38/server/container/guice/mailet/src/test/java/org/apache/james/utils/FileSystemFixture.java ---------------------------------------------------------------------- diff --git a/server/container/guice/mailet/src/test/java/org/apache/james/utils/FileSystemFixture.java b/server/container/guice/mailet/src/test/java/org/apache/james/utils/FileSystemFixture.java index 0731a5f..fa6c580 100644 --- a/server/container/guice/mailet/src/test/java/org/apache/james/utils/FileSystemFixture.java +++ b/server/container/guice/mailet/src/test/java/org/apache/james/utils/FileSystemFixture.java @@ -54,7 +54,7 @@ public class FileSystemFixture { @Override public File getFile(String fileURL) throws FileNotFoundException { - return new File(ClassLoader.getSystemResource("recursive/included-jars").getFile()); + return new File(ClassLoader.getSystemResource("recursive/extensions-jars").getFile()); } @Override http://git-wip-us.apache.org/repos/asf/james-project/blob/06950a38/server/container/guice/mailet/src/test/java/org/apache/james/utils/GuiceMailetLoaderTest.java ---------------------------------------------------------------------- diff --git a/server/container/guice/mailet/src/test/java/org/apache/james/utils/GuiceMailetLoaderTest.java b/server/container/guice/mailet/src/test/java/org/apache/james/utils/GuiceMailetLoaderTest.java new file mode 100644 index 0000000..446af81 --- /dev/null +++ b/server/container/guice/mailet/src/test/java/org/apache/james/utils/GuiceMailetLoaderTest.java @@ -0,0 +1,127 @@ +/**************************************************************** + * 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.utils; + +import static org.apache.james.utils.FileSystemFixture.CLASSPATH_FILE_SYSTEM; +import static org.apache.james.utils.FileSystemFixture.RECURSIVE_CLASSPATH_FILE_SYSTEM; +import static org.apache.james.utils.FileSystemFixture.THROWING_FILE_SYSTEM; +import static org.assertj.core.api.Assertions.assertThat; + +import javax.mail.MessagingException; + +import org.apache.james.transport.mailets.AddFooter; +import org.apache.mailet.Mailet; +import org.apache.mailet.base.test.FakeMailContext; +import org.apache.mailet.base.test.FakeMailetConfig; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; + +import com.google.inject.Guice; +import com.google.inject.Injector; + +public class GuiceMailetLoaderTest { + + @Rule + public ExpectedException expectedException = ExpectedException.none(); + private Injector injector = Guice.createInjector(); + + @Test + public void getMailetShouldLoadClass() throws Exception { + GuiceMailetLoader guiceMailetLoader = new GuiceMailetLoader(injector, + new ExtendedClassLoader(THROWING_FILE_SYSTEM)); + + Mailet mailet = guiceMailetLoader.getMailet(FakeMailetConfig.builder() + .mailetName("AddFooter") + .mailetContext(FakeMailContext.defaultContext()) + .build()); + + assertThat(mailet).isInstanceOf(AddFooter.class); + } + + @Test + public void getMailetShouldThrowOnBadType() throws Exception { + GuiceMailetLoader guiceMailetLoader = new GuiceMailetLoader(injector, + new ExtendedClassLoader(THROWING_FILE_SYSTEM)); + + expectedException.expect(MessagingException.class); + + guiceMailetLoader.getMailet(FakeMailetConfig.builder() + .mailetName("org.apache.james.transport.matchers.SizeGreaterThan") + .mailetContext(FakeMailContext.defaultContext()) + .build()); + } + + @Test + public void getMailetShouldLoadClassWhenInExtensionsJars() throws Exception { + GuiceMailetLoader guiceMailetLoader = new GuiceMailetLoader(injector, + new ExtendedClassLoader(CLASSPATH_FILE_SYSTEM)); + + Mailet mailet = guiceMailetLoader.getMailet(FakeMailetConfig.builder() + .mailetName("CustomMailet") + .mailetContext(FakeMailContext.defaultContext()) + .build()); + + assertThat(mailet.getClass().getCanonicalName()) + .isEqualTo("org.apache.james.transport.mailets.CustomMailet"); + } + + @Test + public void getMailetShouldBrowseRecursivelyExtensionsJars() throws Exception { + GuiceMailetLoader guiceMailetLoader = new GuiceMailetLoader(injector, + new ExtendedClassLoader(RECURSIVE_CLASSPATH_FILE_SYSTEM)); + + Mailet mailet = guiceMailetLoader.getMailet(FakeMailetConfig.builder() + .mailetName("CustomMailet") + .mailetContext(FakeMailContext.defaultContext()) + .build()); + + assertThat(mailet.getClass().getCanonicalName()) + .isEqualTo("org.apache.james.transport.mailets.CustomMailet"); + } + + @Test + public void getMailedShouldAllowCustomPackages() throws Exception { + GuiceMailetLoader guiceMailetLoader = new GuiceMailetLoader(injector, + new ExtendedClassLoader(CLASSPATH_FILE_SYSTEM)); + + Mailet mailet = guiceMailetLoader.getMailet(FakeMailetConfig.builder() + .mailetName("com.custom.mailets.AnotherMailet") + .mailetContext(FakeMailContext.defaultContext()) + .build()); + + assertThat(mailet.getClass().getCanonicalName()) + .isEqualTo("com.custom.mailets.AnotherMailet"); + } + + @Test + public void getMailetShouldThrowOnUnknownMailet() throws Exception { + GuiceMailetLoader guiceMailetLoader = new GuiceMailetLoader(injector, + new ExtendedClassLoader(CLASSPATH_FILE_SYSTEM)); + + expectedException.expect(MessagingException.class); + + guiceMailetLoader.getMailet(FakeMailetConfig.builder() + .mailetName("org.apache.james.transport.mailets.Unknown") + .mailetContext(FakeMailContext.defaultContext()) + .build()); + } + +} http://git-wip-us.apache.org/repos/asf/james-project/blob/06950a38/server/container/guice/mailet/src/test/java/org/apache/james/utils/GuiceMatcherLoaderTest.java ---------------------------------------------------------------------- diff --git a/server/container/guice/mailet/src/test/java/org/apache/james/utils/GuiceMatcherLoaderTest.java b/server/container/guice/mailet/src/test/java/org/apache/james/utils/GuiceMatcherLoaderTest.java new file mode 100644 index 0000000..b1c69cb --- /dev/null +++ b/server/container/guice/mailet/src/test/java/org/apache/james/utils/GuiceMatcherLoaderTest.java @@ -0,0 +1,127 @@ +/**************************************************************** + * 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.utils; + +import static org.apache.james.utils.FileSystemFixture.CLASSPATH_FILE_SYSTEM; +import static org.apache.james.utils.FileSystemFixture.RECURSIVE_CLASSPATH_FILE_SYSTEM; +import static org.apache.james.utils.FileSystemFixture.THROWING_FILE_SYSTEM; +import static org.assertj.core.api.Assertions.assertThat; + +import javax.mail.MessagingException; + +import org.apache.james.transport.matchers.All; +import org.apache.mailet.Matcher; +import org.apache.mailet.base.test.FakeMailContext; +import org.apache.mailet.base.test.FakeMatcherConfig; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; + +import com.google.inject.Guice; +import com.google.inject.Injector; + +public class GuiceMatcherLoaderTest { + + @Rule + public ExpectedException expectedException = ExpectedException.none(); + private Injector injector = Guice.createInjector(); + + @Test + public void getMatcherShouldLoadClass() throws Exception { + GuiceMatcherLoader guiceMailetLoader = new GuiceMatcherLoader(injector, + new ExtendedClassLoader(THROWING_FILE_SYSTEM)); + + Matcher matcher = guiceMailetLoader.getMatcher(FakeMatcherConfig.builder() + .matcherName("All") + .mailetContext(FakeMailContext.defaultContext()) + .build()); + + assertThat(matcher).isInstanceOf(All.class); + } + + @Test + public void getMatcherShouldThrowOnBadType() throws Exception { + GuiceMatcherLoader guiceMatcherLoader = new GuiceMatcherLoader(injector, + new ExtendedClassLoader(THROWING_FILE_SYSTEM)); + + expectedException.expect(MessagingException.class); + + guiceMatcherLoader.getMatcher(FakeMatcherConfig.builder() + .matcherName("org.apache.james.transport.mailets.Null") + .mailetContext(FakeMailContext.defaultContext()) + .build()); + } + + @Test + public void getMatcherShouldLoadClassWhenInExtensionsJars() throws Exception { + GuiceMatcherLoader guiceMatcherLoader = new GuiceMatcherLoader(injector, + new ExtendedClassLoader(CLASSPATH_FILE_SYSTEM)); + + Matcher matcher = guiceMatcherLoader.getMatcher(FakeMatcherConfig.builder() + .matcherName("CustomMatcher") + .mailetContext(FakeMailContext.defaultContext()) + .build()); + + assertThat(matcher.getClass().getCanonicalName()) + .isEqualTo("org.apache.james.transport.matchers.CustomMatcher"); + } + + @Test + public void getMatcherShouldBrowseRecursivelyExtensionJars() throws Exception { + GuiceMatcherLoader guiceMatcherLoader = new GuiceMatcherLoader(injector, + new ExtendedClassLoader(RECURSIVE_CLASSPATH_FILE_SYSTEM)); + + Matcher matcher = guiceMatcherLoader.getMatcher(FakeMatcherConfig.builder() + .matcherName("CustomMatcher") + .mailetContext(FakeMailContext.defaultContext()) + .build()); + + assertThat(matcher.getClass().getCanonicalName()) + .isEqualTo("org.apache.james.transport.matchers.CustomMatcher"); + } + + @Test + public void getMatcherShouldAllowCustomPackages() throws Exception { + GuiceMatcherLoader guiceMatcherLoader = new GuiceMatcherLoader(injector, + new ExtendedClassLoader(RECURSIVE_CLASSPATH_FILE_SYSTEM)); + + Matcher matcher = guiceMatcherLoader.getMatcher(FakeMatcherConfig.builder() + .matcherName("com.custom.matchers.AnotherMatcher") + .mailetContext(FakeMailContext.defaultContext()) + .build()); + + assertThat(matcher.getClass().getCanonicalName()) + .isEqualTo("com.custom.matchers.AnotherMatcher"); + } + + @Test + public void getMatcherShouldThrowOnUnknownMailet() throws Exception { + GuiceMatcherLoader guiceMatcherLoader = new GuiceMatcherLoader(injector, + new ExtendedClassLoader(CLASSPATH_FILE_SYSTEM)); + + expectedException.expect(MessagingException.class); + + guiceMatcherLoader.getMatcher(FakeMatcherConfig.builder() + .matcherName("org.apache.james.transport.matchers.Unknown") + .mailetContext(FakeMailContext.defaultContext()) + .build()); + } + +} http://git-wip-us.apache.org/repos/asf/james-project/blob/06950a38/server/container/guice/mailet/src/test/java/org/apache/james/utils/GuilceMailetLoaderTest.java ---------------------------------------------------------------------- diff --git a/server/container/guice/mailet/src/test/java/org/apache/james/utils/GuilceMailetLoaderTest.java b/server/container/guice/mailet/src/test/java/org/apache/james/utils/GuilceMailetLoaderTest.java deleted file mode 100644 index 6a72ce5..0000000 --- a/server/container/guice/mailet/src/test/java/org/apache/james/utils/GuilceMailetLoaderTest.java +++ /dev/null @@ -1,127 +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.utils; - -import static org.apache.james.utils.FileSystemFixture.CLASSPATH_FILE_SYSTEM; -import static org.apache.james.utils.FileSystemFixture.RECURSIVE_CLASSPATH_FILE_SYSTEM; -import static org.apache.james.utils.FileSystemFixture.THROWING_FILE_SYSTEM; -import static org.assertj.core.api.Assertions.assertThat; - -import javax.mail.MessagingException; - -import org.apache.james.transport.mailets.AddFooter; -import org.apache.mailet.Mailet; -import org.apache.mailet.base.test.FakeMailContext; -import org.apache.mailet.base.test.FakeMailetConfig; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; - -import com.google.inject.Guice; -import com.google.inject.Injector; - -public class GuilceMailetLoaderTest { - - @Rule - public ExpectedException expectedException = ExpectedException.none(); - private Injector injector = Guice.createInjector(); - - @Test - public void getMailetShouldLoadClass() throws Exception { - GuiceMailetLoader guiceMailetLoader = new GuiceMailetLoader(injector, - new ExtendedClassLoader(THROWING_FILE_SYSTEM)); - - Mailet mailet = guiceMailetLoader.getMailet(FakeMailetConfig.builder() - .mailetName("AddFooter") - .mailetContext(FakeMailContext.defaultContext()) - .build()); - - assertThat(mailet).isInstanceOf(AddFooter.class); - } - - @Test - public void getMailetShouldThrowOnBadType() throws Exception { - GuiceMailetLoader guiceMailetLoader = new GuiceMailetLoader(injector, - new ExtendedClassLoader(THROWING_FILE_SYSTEM)); - - expectedException.expect(MessagingException.class); - - guiceMailetLoader.getMailet(FakeMailetConfig.builder() - .mailetName("org.apache.james.transport.matchers.SizeGreaterThan") - .mailetContext(FakeMailContext.defaultContext()) - .build()); - } - - @Test - public void getMailetShouldLoadClassWhenInIncludedJars() throws Exception { - GuiceMailetLoader guiceMailetLoader = new GuiceMailetLoader(injector, - new ExtendedClassLoader(CLASSPATH_FILE_SYSTEM)); - - Mailet mailet = guiceMailetLoader.getMailet(FakeMailetConfig.builder() - .mailetName("CustomMailet") - .mailetContext(FakeMailContext.defaultContext()) - .build()); - - assertThat(mailet.getClass().getCanonicalName()) - .isEqualTo("org.apache.james.transport.mailets.CustomMailet"); - } - - @Test - public void getMailetShouldShouldRecursivelyIncludeJar() throws Exception { - GuiceMailetLoader guiceMailetLoader = new GuiceMailetLoader(injector, - new ExtendedClassLoader(RECURSIVE_CLASSPATH_FILE_SYSTEM)); - - Mailet mailet = guiceMailetLoader.getMailet(FakeMailetConfig.builder() - .mailetName("CustomMailet") - .mailetContext(FakeMailContext.defaultContext()) - .build()); - - assertThat(mailet.getClass().getCanonicalName()) - .isEqualTo("org.apache.james.transport.mailets.CustomMailet"); - } - - @Test - public void getMailedShouldShouldAllowCustomPackages() throws Exception { - GuiceMailetLoader guiceMailetLoader = new GuiceMailetLoader(injector, - new ExtendedClassLoader(CLASSPATH_FILE_SYSTEM)); - - Mailet mailet = guiceMailetLoader.getMailet(FakeMailetConfig.builder() - .mailetName("com.custom.mailets.AnotherMailet") - .mailetContext(FakeMailContext.defaultContext()) - .build()); - - assertThat(mailet.getClass().getCanonicalName()) - .isEqualTo("com.custom.mailets.AnotherMailet"); - } - - @Test - public void getMailetShouldThrowOnUnknownMailet() throws Exception { - GuiceMailetLoader guiceMailetLoader = new GuiceMailetLoader(injector, - new ExtendedClassLoader(CLASSPATH_FILE_SYSTEM)); - - expectedException.expect(MessagingException.class); - - guiceMailetLoader.getMailet(FakeMailetConfig.builder() - .mailetName("org.apache.james.transport.mailets.Unknown") - .mailetContext(FakeMailContext.defaultContext()) - .build()); - } - -} http://git-wip-us.apache.org/repos/asf/james-project/blob/06950a38/server/container/guice/mailet/src/test/java/org/apache/james/utils/GuilceMatcherLoaderTest.java ---------------------------------------------------------------------- diff --git a/server/container/guice/mailet/src/test/java/org/apache/james/utils/GuilceMatcherLoaderTest.java b/server/container/guice/mailet/src/test/java/org/apache/james/utils/GuilceMatcherLoaderTest.java deleted file mode 100644 index bd8c7c3..0000000 --- a/server/container/guice/mailet/src/test/java/org/apache/james/utils/GuilceMatcherLoaderTest.java +++ /dev/null @@ -1,127 +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.utils; - -import static org.apache.james.utils.FileSystemFixture.CLASSPATH_FILE_SYSTEM; -import static org.apache.james.utils.FileSystemFixture.RECURSIVE_CLASSPATH_FILE_SYSTEM; -import static org.apache.james.utils.FileSystemFixture.THROWING_FILE_SYSTEM; -import static org.assertj.core.api.Assertions.assertThat; - -import javax.mail.MessagingException; - -import org.apache.james.transport.matchers.All; -import org.apache.mailet.Matcher; -import org.apache.mailet.base.test.FakeMailContext; -import org.apache.mailet.base.test.FakeMatcherConfig; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; - -import com.google.inject.Guice; -import com.google.inject.Injector; - -public class GuilceMatcherLoaderTest { - - @Rule - public ExpectedException expectedException = ExpectedException.none(); - private Injector injector = Guice.createInjector(); - - @Test - public void getMatcherShouldLoadClass() throws Exception { - GuiceMatcherLoader guiceMailetLoader = new GuiceMatcherLoader(injector, - new ExtendedClassLoader(THROWING_FILE_SYSTEM)); - - Matcher matcher = guiceMailetLoader.getMatcher(FakeMatcherConfig.builder() - .matcherName("All") - .mailetContext(FakeMailContext.defaultContext()) - .build()); - - assertThat(matcher).isInstanceOf(All.class); - } - - @Test - public void getMatcherShouldThrowOnBadType() throws Exception { - GuiceMatcherLoader guiceMatcherLoader = new GuiceMatcherLoader(injector, - new ExtendedClassLoader(THROWING_FILE_SYSTEM)); - - expectedException.expect(MessagingException.class); - - guiceMatcherLoader.getMatcher(FakeMatcherConfig.builder() - .matcherName("org.apache.james.transport.mailets.Null") - .mailetContext(FakeMailContext.defaultContext()) - .build()); - } - - @Test - public void getMatcherShouldLoadClassWhenInIncludedJars() throws Exception { - GuiceMatcherLoader guiceMatcherLoader = new GuiceMatcherLoader(injector, - new ExtendedClassLoader(CLASSPATH_FILE_SYSTEM)); - - Matcher matcher = guiceMatcherLoader.getMatcher(FakeMatcherConfig.builder() - .matcherName("CustomMatcher") - .mailetContext(FakeMailContext.defaultContext()) - .build()); - - assertThat(matcher.getClass().getCanonicalName()) - .isEqualTo("org.apache.james.transport.matchers.CustomMatcher"); - } - - @Test - public void getMatcherShouldShouldRecursivelyIncludeJar() throws Exception { - GuiceMatcherLoader guiceMatcherLoader = new GuiceMatcherLoader(injector, - new ExtendedClassLoader(RECURSIVE_CLASSPATH_FILE_SYSTEM)); - - Matcher matcher = guiceMatcherLoader.getMatcher(FakeMatcherConfig.builder() - .matcherName("CustomMatcher") - .mailetContext(FakeMailContext.defaultContext()) - .build()); - - assertThat(matcher.getClass().getCanonicalName()) - .isEqualTo("org.apache.james.transport.matchers.CustomMatcher"); - } - - @Test - public void getMatcherShouldAllowCustomPackages() throws Exception { - GuiceMatcherLoader guiceMatcherLoader = new GuiceMatcherLoader(injector, - new ExtendedClassLoader(RECURSIVE_CLASSPATH_FILE_SYSTEM)); - - Matcher matcher = guiceMatcherLoader.getMatcher(FakeMatcherConfig.builder() - .matcherName("com.custom.matchers.AnotherMatcher") - .mailetContext(FakeMailContext.defaultContext()) - .build()); - - assertThat(matcher.getClass().getCanonicalName()) - .isEqualTo("com.custom.matchers.AnotherMatcher"); - } - - @Test - public void getMatcherShouldThrowOnUnknownMailet() throws Exception { - GuiceMatcherLoader guiceMatcherLoader = new GuiceMatcherLoader(injector, - new ExtendedClassLoader(CLASSPATH_FILE_SYSTEM)); - - expectedException.expect(MessagingException.class); - - guiceMatcherLoader.getMatcher(FakeMatcherConfig.builder() - .matcherName("org.apache.james.transport.matchers.Unknown") - .mailetContext(FakeMailContext.defaultContext()) - .build()); - } - -} http://git-wip-us.apache.org/repos/asf/james-project/blob/06950a38/server/container/guice/mailet/src/test/resources/recursive/extensions-jars/james-server-guice-custom-mailets-3.0.0-beta6-SNAPSHOT.jar ---------------------------------------------------------------------- diff --git a/server/container/guice/mailet/src/test/resources/recursive/extensions-jars/james-server-guice-custom-mailets-3.0.0-beta6-SNAPSHOT.jar b/server/container/guice/mailet/src/test/resources/recursive/extensions-jars/james-server-guice-custom-mailets-3.0.0-beta6-SNAPSHOT.jar new file mode 100644 index 0000000..3e31ff3 Binary files /dev/null and b/server/container/guice/mailet/src/test/resources/recursive/extensions-jars/james-server-guice-custom-mailets-3.0.0-beta6-SNAPSHOT.jar differ http://git-wip-us.apache.org/repos/asf/james-project/blob/06950a38/server/container/guice/mailet/src/test/resources/recursive/included-jars/james-server-guice-custom-mailets-3.0.0-beta6-SNAPSHOT.jar ---------------------------------------------------------------------- diff --git a/server/container/guice/mailet/src/test/resources/recursive/included-jars/james-server-guice-custom-mailets-3.0.0-beta6-SNAPSHOT.jar b/server/container/guice/mailet/src/test/resources/recursive/included-jars/james-server-guice-custom-mailets-3.0.0-beta6-SNAPSHOT.jar deleted file mode 100644 index 3e31ff3..0000000 Binary files a/server/container/guice/mailet/src/test/resources/recursive/included-jars/james-server-guice-custom-mailets-3.0.0-beta6-SNAPSHOT.jar and /dev/null differ --------------------------------------------------------------------- To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org For additional commands, e-mail: server-dev-h...@james.apache.org