@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 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 getMatcherShouldLoadClassWhenInSubPackageFromDefaultPackage() throws Exception { GuiceMatcherLoader guiceMailetLoader = new GuiceMatcherLoader(injector, new ExtendedClassLoader(THROWING_FILE_SYSTEM)); Matcher matcher = guiceMailetLoader.getMatcher(FakeMatcherConfig.builder() .matcherName("sub.TestMatcher") .mailetContext(FakeMailContext.defaultContext()) .build()); assertThat(matcher).isInstanceOf(All.class); }
@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()); }
@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()); }