MailOperatorFactory implements OperatorFactory { @Override public Operator newOperator(OperatorContext context) { return new MailOperator(context); } @Inject  MailOperatorFactory(TemplateEngine templateEngine, Config systemConfig); String getType(); @Override Operator newOperator(OperatorContext context);  }
@Test public void sendSingleToEmail() { mailConfig.set("to", "bob@example.com"); Operator op = factory.newOperator(newContext( tempPath, newTaskRequest().withConfig(mailConfig))); op.run(); receiveCheck("bob@example.com", 1); }
@Test public void sendMultipleToEmail() { mailConfig.set("to", ImmutableList.of("bob@example.com", "charlie@example.com")); Operator op = factory.newOperator(newContext( tempPath, newTaskRequest().withConfig(mailConfig))); op.run(); receiveCheck("bob@example.com", 1); receiveCheck("charlie@example.com", 1); }
@Test public void sendSingleToAndCcBccEmail() { mailConfig.set("to", "bob@example.com") .set("bcc", ImmutableList.of("charlie@example.com")) .set("cc", ImmutableList.of("david@example.com")); Operator op = factory.newOperator(newContext( tempPath, newTaskRequest().withConfig(mailConfig))); op.run(); greenMail.waitForIncomingEmail(5000, 2); receiveCheck("bob@example.com", 1); receiveCheck("charlie@example.com", 1); receiveCheck("david@example.com", 1); }
@Test public void sendSingleToCcEmail() { mailConfig.set("to", "bob@example.com") .set("cc", ImmutableList.of("charlie@example.com")); Operator op = factory.newOperator(newContext( tempPath, newTaskRequest().withConfig(mailConfig))); op.run(); greenMail.waitForIncomingEmail(5000, 2); receiveCheck("bob@example.com", 1); receiveCheck("charlie@example.com", 1); }
@Test public void sendSingleToBccEmail() { mailConfig.set("to", "bob@example.com") .set("bcc", ImmutableList.of("charlie@example.com")); Operator op = factory.newOperator(newContext( tempPath, newTaskRequest().withConfig(mailConfig))); op.run(); greenMail.waitForIncomingEmail(5000, 2); receiveCheck("bob@example.com", 1); receiveCheck("charlie@example.com", 1); }
@Test public void errorCheckNoDestination() { try { Operator op = factory.newOperator(newContext( tempPath, newTaskRequest().withConfig(mailConfig))); op.run(); fail("should be thrown Exception."); } catch (ConfigException ignore) { } }
@Test public void errorCheckRequireTo() { mailConfig.set("cc", ImmutableList.of("bob@example.com")); try { Operator op = factory.newOperator(newContext( tempPath, newTaskRequest().withConfig(mailConfig))); op.run(); fail("should be thrown Exception."); } catch (ConfigException ignore) { } }
@Test public void errorCheckRequireTo2() { mailConfig.set("bcc", ImmutableList.of("bob@example.com")); try { Operator op = factory.newOperator(newContext( tempPath, newTaskRequest().withConfig(mailConfig))); op.run(); fail("should be thrown Exception."); } catch (ConfigException ignore) { } }
@Test public void errorCheckNoHost() { Config config = newConfig() .set("port", smtpPort) .set("subject", "test") .set("_command", "mail_body.txt") .set("timezone", "Asia/Tokyo") .set("from", "alice@example.com") .set("to", "bob@example.com"); try { Operator op = factory.newOperator(newContext( tempPath, newTaskRequest().withConfig(config))); op.run(); fail("should be thrown Exception."); } catch (TaskExecutionException ignore) { } }
@Test public void errorCheckNoPort() { Config config = newConfig() .set("host", "localhost") .set("subject", "test") .set("_command", "mail_body.txt") .set("timezone", "Asia/Tokyo") .set("from", "alice@example.com") .set("to", "bob@example.com"); try { Operator op = factory.newOperator(newContext( tempPath, newTaskRequest().withConfig(config))); op.run(); fail("should be thrown Exception."); } catch (ConfigException ignore) { } }
@Test public void errorCheckNoSubject() { Config config = newConfig() .set("host", "localhost") .set("port", smtpPort) .set("_command", "mail_body.txt") .set("timezone", "Asia/Tokyo") .set("from", "alice@example.com") .set("to", "bob@example.com"); try { Operator op = factory.newOperator(newContext( tempPath, newTaskRequest().withConfig(config))); op.run(); fail("should be thrown Exception."); } catch (ConfigException ignore) { } }
@Test public void errorCheckNoCommand() { Config config = newConfig() .set("host", "localhost") .set("port", smtpPort) .set("subject", "test") .set("timezone", "Asia/Tokyo") .set("from", "alice@example.com") .set("to", "bob@example.com"); try { Operator op = factory.newOperator(newContext( tempPath, newTaskRequest().withConfig(config))); op.run(); fail("should be thrown Exception."); } catch (ConfigException ignore) { } }
@Test public void errorCheckNoFrom() { Config config = newConfig() .set("host", "localhost") .set("port", smtpPort) .set("subject", "test") .set("_command", "mail_body.txt") .set("timezone", "Asia/Tokyo") .set("to", "bob@example.com"); try { Operator op = factory.newOperator(newContext( tempPath, newTaskRequest().withConfig(config))); op.run(); fail("should be thrown Exception."); } catch (ConfigException ignore) { } }
@Test public void errorCheckStringCc() { mailConfig.set("to", "bob@example.com") .set("cc", "charlie@example.com"); try { Operator op = factory.newOperator(newContext( tempPath, newTaskRequest().withConfig(mailConfig))); op.run(); fail("should be thrown Exception."); } catch (ConfigException ignore) { } }
@Test public void errorCheckStringBcc() { mailConfig.set("to", "bob@example.com") .set("bcc", "charlie@example.com"); try { Operator op = factory.newOperator(newContext( tempPath, newTaskRequest().withConfig(mailConfig))); op.run(); fail("should be thrown Exception."); } catch (ConfigException ignore) { } }