MailerProxyTest.java
/***************************************************************************
Copyright 2015 Emily Estes
Licensed 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 net.metanotion.email;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.Executors;
import java.util.concurrent.ExecutorService;
import javax.inject.Named;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Named interface TestInterface {
public static final class vars implements MailerProxy.Constants<TestInterface> {
public int var1;
public String var2;
public vars(final int var1, final String var2) {
this.var1 = var1;
this.var2 = var2;
}
}
public void messageOne(@Named("email") String email);
public void another(@Named("one") String one, @Named("bites") long bites, @Named("theDust") boolean theDust);
}
public final class MailerProxyTest {
private static final Logger logger = LoggerFactory.getLogger(MailerProxyTest.class);
public static void main(final String[] args) throws Exception {
final Map<String,String> templateList = MailerProxy.defaultTemplates(TestInterface.class);
for(final Map.Entry<String, String> e: templateList.entrySet()) {
logger.debug("{} - {}", e.getKey(), e.getValue());
}
for(final Class klazz: TestInterface.class.getClasses()) {
logger.debug("inner class {}", klazz.getName());
for(final java.lang.reflect.Field f: klazz.getDeclaredFields()) {
logger.debug("field {} {}", f.getName(), f);
}
}
logger.debug("Convert to map {}", MailerProxy.classToVars(new TestInterface.vars(5, "s")));
final TestInterface log = MailerProxy.mailLogger(TestInterface.class);
sendEmails(log);
final ExecutorService es = Executors.newCachedThreadPool();
final Map<String, String> constants = new HashMap<>();
final TestInterface merge =
MailerProxy.generate(TestInterface.class, es, MailMergeUtil.LOGGING, "from@example.com", constants);
sendEmails(merge);
final TestInterface.vars c = new TestInterface.vars(5, "s");
final TestInterface mergeConstants =
MailerProxy.generate(TestInterface.class, es, MailMergeUtil.LOGGING, "from@example.com", c);
sendEmails(mergeConstants);
es.shutdown();
}
public static void sendEmails(final TestInterface mailer) {
mailer.messageOne("to@example.com");
mailer.another("to@example.com", 10L, true);
}
}