This is an automated email from the ASF dual-hosted git repository. btellier pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/james-project.git
commit b4c67dd1838ea6a6fdc730dc517287028dd631c2 Author: Benoit Tellier <[email protected]> AuthorDate: Wed Sep 18 11:23:23 2019 +0700 JAMES-2886 Test transitive extension-jar resolution with jar-with-dependency - Instantiate a dependency within the constructor - Instantiate a dependency within the service method --- .../apache/james/utils/GuiceMailetLoaderTest.java | 30 +++++++++++++ ...r-guice-custom-mailets-3.0.0-beta6-SNAPSHOT.jar | Bin 11094 -> 0 bytes ...ailets-3.5.0-SNAPSHOT-jar-with-dependencies.jar | Bin 0 -> 30472149 bytes .../container/guice/testing/custom-mailets/pom.xml | 29 +++++++++++-- ...tomMailetWithCustomDependencyInConstructor.java | 47 +++++++++++++++++++++ .../CustomMailetWithCustomDependencyInService.java | 42 ++++++++++++++++++ .../guice/testing/{ => dependency}/pom.xml | 15 +++---- .../org/apache/james/dependency/MyDependency.java | 23 ++++++++++ server/container/guice/testing/pom.xml | 3 +- 9 files changed, 175 insertions(+), 14 deletions(-) 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 index 129f8e7..cdce656 100644 --- 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 @@ -23,12 +23,14 @@ import static org.apache.james.filesystem.api.FileSystemFixture.CLASSPATH_FILE_S import static org.apache.james.filesystem.api.FileSystemFixture.RECURSIVE_CLASSPATH_FILE_SYSTEM; import static org.apache.james.filesystem.api.FileSystemFixture.THROWING_FILE_SYSTEM; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatCode; import javax.mail.MessagingException; import org.apache.james.transport.mailets.AddFooter; import org.apache.james.transport.mailets.sub.TestMailet; import org.apache.mailet.Mailet; +import org.apache.mailet.base.test.FakeMail; import org.apache.mailet.base.test.FakeMailContext; import org.apache.mailet.base.test.FakeMailetConfig; import org.junit.Rule; @@ -147,4 +149,32 @@ public class GuiceMailetLoaderTest { .build()); } + @Test + public void getMailetShouldLoadMailetsWithCustomDependencyInConstructor() throws Exception { + GuiceMailetLoader guiceMailetLoader = new GuiceMailetLoader(injector, + new ExtendedClassLoader(RECURSIVE_CLASSPATH_FILE_SYSTEM), + NO_MAILET_CONFIG_OVERRIDES); + + Mailet mailet = guiceMailetLoader.getMailet(FakeMailetConfig.builder() + .mailetName("CustomMailetWithCustomDependencyInConstructor") + .mailetContext(FakeMailContext.defaultContext()) + .build()); + + assertThat(mailet.getClass().getCanonicalName()) + .isEqualTo("org.apache.james.transport.mailets.CustomMailetWithCustomDependencyInConstructor"); + } + + @Test + public void getMailetShouldLoadMailetsWithCustomDependencyInService() throws Exception { + GuiceMailetLoader guiceMailetLoader = new GuiceMailetLoader(injector, + new ExtendedClassLoader(RECURSIVE_CLASSPATH_FILE_SYSTEM), + NO_MAILET_CONFIG_OVERRIDES); + + Mailet mailet = guiceMailetLoader.getMailet(FakeMailetConfig.builder() + .mailetName("CustomMailetWithCustomDependencyInService") + .mailetContext(FakeMailContext.defaultContext()) + .build()); + + assertThatCode(() -> mailet.service(FakeMail.defaultFakeMail())).doesNotThrowAnyException(); + } } 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 deleted file mode 100644 index 3e31ff3..0000000 Binary files a/server/container/guice/mailet/src/test/resources/recursive/extensions-jars/james-server-guice-custom-mailets-3.0.0-beta6-SNAPSHOT.jar and /dev/null differ diff --git a/server/container/guice/mailet/src/test/resources/recursive/extensions-jars/james-server-guice-custom-mailets-3.5.0-SNAPSHOT-jar-with-dependencies.jar b/server/container/guice/mailet/src/test/resources/recursive/extensions-jars/james-server-guice-custom-mailets-3.5.0-SNAPSHOT-jar-with-dependencies.jar new file mode 100644 index 0000000..99e2b38 Binary files /dev/null and b/server/container/guice/mailet/src/test/resources/recursive/extensions-jars/james-server-guice-custom-mailets-3.5.0-SNAPSHOT-jar-with-dependencies.jar differ diff --git a/server/container/guice/testing/custom-mailets/pom.xml b/server/container/guice/testing/custom-mailets/pom.xml index ff7c8d8..353fe59 100644 --- a/server/container/guice/testing/custom-mailets/pom.xml +++ b/server/container/guice/testing/custom-mailets/pom.xml @@ -21,7 +21,7 @@ <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.apache.james</groupId> - <artifactId>james-server-guice</artifactId> + <artifactId>james-server-guice-testing</artifactId> <version>3.5.0-SNAPSHOT</version> <relativePath>../pom.xml</relativePath> </parent> @@ -42,8 +42,31 @@ </dependency> <dependency> <groupId>${james.groupId}</groupId> - <artifactId>testing-base</artifactId> - <scope>test</scope> + <artifactId>james-server-guice-custom-mailets-dependency</artifactId> + <version>${project.version}</version> </dependency> </dependencies> + + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-assembly-plugin</artifactId> + <configuration> + <descriptorRefs> + <descriptorRef>jar-with-dependencies</descriptorRef> + </descriptorRefs> + </configuration> + <executions> + <execution> + <id>make-assembly</id> + <phase>package</phase> + <goals> + <goal>single</goal> + </goals> + </execution> + </executions> + </plugin> + </plugins> + </build> </project> diff --git a/server/container/guice/testing/custom-mailets/src/main/java/org/apache/james/transport/mailets/CustomMailetWithCustomDependencyInConstructor.java b/server/container/guice/testing/custom-mailets/src/main/java/org/apache/james/transport/mailets/CustomMailetWithCustomDependencyInConstructor.java new file mode 100644 index 0000000..a9445b7 --- /dev/null +++ b/server/container/guice/testing/custom-mailets/src/main/java/org/apache/james/transport/mailets/CustomMailetWithCustomDependencyInConstructor.java @@ -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.transport.mailets; + +import javax.mail.MessagingException; + +import org.apache.james.dependency.MyDependency; +import org.apache.mailet.ExcludeFromDocumentation; +import org.apache.mailet.Mail; +import org.apache.mailet.base.GenericMailet; + + +/** + * Mailet introduced for testing purposes. + * + * Does nothing. + */ + +@ExcludeFromDocumentation +public class CustomMailetWithCustomDependencyInConstructor extends GenericMailet { + + public CustomMailetWithCustomDependencyInConstructor() { + new MyDependency(); + } + + @Override + public void service(Mail mail) throws MessagingException { + + } +} diff --git a/server/container/guice/testing/custom-mailets/src/main/java/org/apache/james/transport/mailets/CustomMailetWithCustomDependencyInService.java b/server/container/guice/testing/custom-mailets/src/main/java/org/apache/james/transport/mailets/CustomMailetWithCustomDependencyInService.java new file mode 100644 index 0000000..9d329eb --- /dev/null +++ b/server/container/guice/testing/custom-mailets/src/main/java/org/apache/james/transport/mailets/CustomMailetWithCustomDependencyInService.java @@ -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.transport.mailets; + +import javax.mail.MessagingException; + +import org.apache.james.dependency.MyDependency; +import org.apache.mailet.ExcludeFromDocumentation; +import org.apache.mailet.Mail; +import org.apache.mailet.base.GenericMailet; + + +/** + * Mailet introduced for testing purposes. + * + * Does nothing. + */ + +@ExcludeFromDocumentation +public class CustomMailetWithCustomDependencyInService extends GenericMailet { + @Override + public void service(Mail mail) throws MessagingException { + new MyDependency(); + } +} diff --git a/server/container/guice/testing/pom.xml b/server/container/guice/testing/dependency/pom.xml similarity index 73% copy from server/container/guice/testing/pom.xml copy to server/container/guice/testing/dependency/pom.xml index 06f8524..a91670d 100644 --- a/server/container/guice/testing/pom.xml +++ b/server/container/guice/testing/dependency/pom.xml @@ -17,22 +17,17 @@ specific language governing permissions and limitations under the License. --> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> - <parent> <groupId>org.apache.james</groupId> - <artifactId>james-server</artifactId> + <artifactId>james-server-guice-testing</artifactId> <version>3.5.0-SNAPSHOT</version> <relativePath>../pom.xml</relativePath> </parent> - <artifactId>james-server-guice-testing</artifactId> - <packaging>pom</packaging> - <name>Apache James :: Server :: Guice :: testing</name> + <artifactId>james-server-guice-custom-mailets-dependency</artifactId> - <modules> - <module>custom-mailets</module> - </modules> + <name>Apache James :: Server :: Guice :: Mailet :: Custom testing mailets :: dependency</name> + <description>Dependency not part of James classpath that custom mailets can depends on</description> </project> \ No newline at end of file diff --git a/server/container/guice/testing/dependency/src/main/java/org/apache/james/dependency/MyDependency.java b/server/container/guice/testing/dependency/src/main/java/org/apache/james/dependency/MyDependency.java new file mode 100644 index 0000000..e023758 --- /dev/null +++ b/server/container/guice/testing/dependency/src/main/java/org/apache/james/dependency/MyDependency.java @@ -0,0 +1,23 @@ +/**************************************************************** + * 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.dependency; + +public class MyDependency { +} diff --git a/server/container/guice/testing/pom.xml b/server/container/guice/testing/pom.xml index 06f8524..c646376 100644 --- a/server/container/guice/testing/pom.xml +++ b/server/container/guice/testing/pom.xml @@ -23,7 +23,7 @@ <parent> <groupId>org.apache.james</groupId> - <artifactId>james-server</artifactId> + <artifactId>james-server-guice</artifactId> <version>3.5.0-SNAPSHOT</version> <relativePath>../pom.xml</relativePath> </parent> @@ -34,5 +34,6 @@ <modules> <module>custom-mailets</module> + <module>dependency</module> </modules> </project> \ No newline at end of file --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
