@Test public void getMailedShouldAllowCustomPackages() throws Exception { GuiceMailetLoader guiceMailetLoader = new GuiceMailetLoader(injector, new ExtendedClassLoader(CLASSPATH_FILE_SYSTEM), NO_MAILET_CONFIG_OVERRIDES); 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 getMailetShouldBrowseRecursivelyExtensionsJars() throws Exception { GuiceMailetLoader guiceMailetLoader = new GuiceMailetLoader(injector, new ExtendedClassLoader(RECURSIVE_CLASSPATH_FILE_SYSTEM), NO_MAILET_CONFIG_OVERRIDES); 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 getMailetShouldLoadClassWhenInExtensionsJars() throws Exception { GuiceMailetLoader guiceMailetLoader = new GuiceMailetLoader(injector, new ExtendedClassLoader(CLASSPATH_FILE_SYSTEM), NO_MAILET_CONFIG_OVERRIDES); 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 getMailetShouldLoadClass() throws Exception { GuiceMailetLoader guiceMailetLoader = new GuiceMailetLoader(injector, new ExtendedClassLoader(THROWING_FILE_SYSTEM), NO_MAILET_CONFIG_OVERRIDES); Mailet mailet = guiceMailetLoader.getMailet(FakeMailetConfig.builder() .mailetName("AddFooter") .mailetContext(FakeMailContext.defaultContext()) .build()); assertThat(mailet).isInstanceOf(AddFooter.class); }
@Test public void getMailetShouldLoadClassWhenInSubPackageFromDefaultPackage() throws Exception { GuiceMailetLoader guiceMailetLoader = new GuiceMailetLoader(injector, new ExtendedClassLoader(THROWING_FILE_SYSTEM), NO_MAILET_CONFIG_OVERRIDES); Mailet mailet = guiceMailetLoader.getMailet(FakeMailetConfig.builder() .mailetName("sub.TestMailet") .mailetContext(FakeMailContext.defaultContext()) .build()); assertThat(mailet).isInstanceOf(TestMailet.class); }
@Test public void getMailetShouldThrowOnBadType() throws Exception { GuiceMailetLoader guiceMailetLoader = new GuiceMailetLoader(injector, new ExtendedClassLoader(THROWING_FILE_SYSTEM), NO_MAILET_CONFIG_OVERRIDES); expectedException.expect(MessagingException.class); guiceMailetLoader.getMailet(FakeMailetConfig.builder() .mailetName("org.apache.james.transport.matchers.SizeGreaterThan") .mailetContext(FakeMailContext.defaultContext()) .build()); }
@Test public void getMailetShouldThrowOnUnknownMailet() throws Exception { GuiceMailetLoader guiceMailetLoader = new GuiceMailetLoader(injector, new ExtendedClassLoader(CLASSPATH_FILE_SYSTEM), NO_MAILET_CONFIG_OVERRIDES); expectedException.expect(MessagingException.class); guiceMailetLoader.getMailet(FakeMailetConfig.builder() .mailetName("org.apache.james.transport.mailets.Unknown") .mailetContext(FakeMailContext.defaultContext()) .build()); }