/*
 * Copyright 2013-2014 eBay Software Foundation
 *
 * 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 com.kylinolap.common.util;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.junit.Test;

import com.kylinolap.common.KylinConfig;

public class MailServiceTest {

    @Test
    public void testSendEmail() throws IOException {
        
        @SuppressWarnings("deprecation")
        KylinConfig config = KylinConfig.getInstanceForTest(AbstractKylinTestCase.SANDBOX_TEST_DATA);

        MailService mailservice = new MailService(config);
        boolean sent = sendTestEmail(mailservice);
        assert sent;
        
        // set mail.enabled=false, and run again, this time should be no mail delviered
        config.setProperty(KylinConfig.MAIL_ENABLED, "false");
        mailservice = new MailService(config);
        sent = sendTestEmail(mailservice);
        assert !sent;
        
    }
    
    private boolean sendTestEmail(MailService mailservice) {

        List<String> receivers = new ArrayList<String>(1);
        receivers.add("foobar@foobar.com");
        try {
            return mailservice.sendMail(receivers, "A test email from Kylin", "Hello!");
        } catch (IOException e) {
            e.printStackTrace();
        }

        return false;
    }
}

/*
 * Copyright 2013-2014 eBay Software Foundation
 *
 * 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 com.kylinolap.common.util;

import com.kylinolap.common.KylinConfig;
import org.junit.Test;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class MailServiceTest {

    @Test
    public void testSendEmail() throws IOException {

        @SuppressWarnings("deprecation")
        KylinConfig config = KylinConfig.getInstanceForTest(AbstractKylinTestCase.SANDBOX_TEST_DATA);

        if (!"true".equalsIgnoreCase(config.getProperty(KylinConfig.MAIL_ENABLED, "false")))
            return;

        MailService mailservice = new MailService(config);
        boolean sent = sendTestEmail(mailservice);
        assert sent;

        // set mail.enabled=false, and run again, this time should be no mail delviered
        config.setProperty(KylinConfig.MAIL_ENABLED, "false");
        mailservice = new MailService(config);
        sent = sendTestEmail(mailservice);
        assert !sent;

    }

    private boolean sendTestEmail(MailService mailservice) {

        List<String> receivers = new ArrayList<String>(1);
        receivers.add("foobar@foobar.com");
        try {
            return mailservice.sendMail(receivers, "A test email from Kylin", "Hello!");
        } catch (IOException e) {
            e.printStackTrace();
        }

        return false;
    }
}

Update MailServiceTest test