/*
 * 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;
    }
}

@@ -642,16 +642,81 @@
 .util;%0A%0A
+import com.kylinolap.common.KylinConfig;%0Aimport org.junit.Test;%0A%0A
 import j
@@ -791,74 +791,8 @@
 t;%0A%0A
-import org.junit.Test;%0A%0Aimport com.kylinolap.common.KylinConfig;%0A%0A
 publ
@@ -882,24 +882,16 @@
 ption %7B%0A
-        
 %0A       
@@ -1027,16 +1027,130 @@
 DATA);%0A%0A
+        if (!%22true%22.equalsIgnoreCase(config.getProperty(KylinConfig.MAIL_ENABLED, %22false%22)))%0A            return;%0A%0A
         
@@ -1268,32 +1268,24 @@
 ssert sent;%0A
-        
 %0A        // 
@@ -1540,27 +1540,15 @@
 nt;%0A
-        
 %0A    %7D%0A
-    
 %0A   

Update MailServiceTest test