/** Test for html email */
  public void testHtml() {

    Map<String, String> parameters = new HashMap<String, String>();
    parameters.put("type", "html");
    ConnectionParameters cp =
        new ConnectionParameters(
            new MockConnectionEl(parameters, "mailto:[email protected]?subject=Hello"),
            MockDriverContext.INSTANCE);
    MailConnection mc =
        new MailConnection(cp) {
          @Override
          protected void send(MimeMessage message) {
            try {
              assertEquals(
                  "*****@*****.**",
                  message.getRecipients(Message.RecipientType.TO)[0].toString());
              assertEquals("Hello", message.getSubject());
              assertEquals(
                  "Message. *example*",
                  ((MimeMultipart) message.getContent()).getBodyPart(0).getContent());
            } catch (Exception e) {
              throw new IllegalStateException(e);
            }
          }
        };
    mc.executeScript(new StringResource("Message. $example"), MockParametersCallbacks.SIMPLE);
  }
  @Before
  public void before() throws KettleException {
    MockitoAnnotations.initMocks(this);

    Mockito.when(parentJob.getLogLevel()).thenReturn(LogLevel.BASIC);
    entry.setParentJob(parentJob);
    entry.setSaveMessage(true);

    Mockito.when(message.getMessageNumber()).thenReturn(1);
    Mockito.when(mailConn.getMessage()).thenReturn(message);

    Mockito.doNothing().when(mailConn).openFolder(Mockito.anyBoolean());
    Mockito.doNothing().when(mailConn).openFolder(Mockito.anyString(), Mockito.anyBoolean());

    Mockito.when(mailConn.getMessagesCount()).thenReturn(1);
  }
 /** Tests mailto with bind variables */
 public void testDynamicMailto() {
   Map<String, String> parameters = new HashMap<String, String>();
   ConnectionParameters cp =
       new ConnectionParameters(
           new MockConnectionEl(parameters, "mailto:$address?subject=$subject"),
           MockDriverContext.INSTANCE);
   final Map<String, String> params = new HashMap<String, String>();
   MailConnection mc =
       new MailConnection(cp) {
         @Override
         protected void send(MimeMessage message) {
           try {
             assertEquals(
                 params.get("address"),
                 message.getRecipients(Message.RecipientType.TO)[0].toString());
             assertEquals("Message. " + params.get("example"), message.getContent());
             assertEquals(params.get("subject"), message.getSubject());
           } catch (Exception e) {
             throw new IllegalStateException(e);
           }
         }
       };
   params.put("address", "*****@*****.**");
   params.put("example", "*example*");
   params.put("subject", "Hello1");
   mc.executeScript(
       new StringResource("Message. $example"), MockParametersCallbacks.fromMap(params));
   params.put("address", "*****@*****.**");
   params.put("subject", "Hello2");
   mc.executeScript(
       new StringResource("Message. $example"), MockParametersCallbacks.fromMap(params));
   params.put("address", "////@");
   try {
     mc.executeScript(
         new StringResource("Message. $example"), MockParametersCallbacks.fromMap(params));
   } catch (MailProviderException e) {
     assertTrue("Invalid address must be reported", e.getMessage().indexOf("////@") >= 0);
   }
 }