Home | History | Annotate | Download | only in mail
      1 /*
      2  * Copyright (C) 2009 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package com.android.email.mail;
     18 
     19 import com.android.email.Email;
     20 
     21 import android.test.AndroidTestCase;
     22 import android.test.suitebuilder.annotation.MediumTest;
     23 
     24 /**
     25  * Tests of StoreInfo & Store lookup in the Store abstract class
     26  */
     27 @MediumTest
     28 public class StoreTests extends AndroidTestCase {
     29 
     30     /**
     31      * Test StoreInfo & Store lookup for POP accounts
     32      */
     33     public void testStoreLookupPOP() throws MessagingException {
     34         final String storeUri = "pop3://user:password (at) server.com";
     35         Store.StoreInfo info = Store.StoreInfo.getStoreInfo(storeUri, getContext());
     36 
     37         assertNotNull("storeInfo null", info);
     38         assertNotNull("scheme null", info.mScheme);
     39         assertNotNull("classname null", info.mClassName);
     40         assertFalse(info.mPushSupported);
     41         assertEquals(Email.VISIBLE_LIMIT_DEFAULT, info.mVisibleLimitDefault);
     42         assertEquals(Email.VISIBLE_LIMIT_INCREMENT, info.mVisibleLimitIncrement);
     43 
     44         // This will throw MessagingException if the result would have been null
     45         Store store = Store.getInstance(storeUri, getContext(), null);
     46     }
     47 
     48     /**
     49      * Test StoreInfo & Store lookup for IMAP accounts
     50      */
     51     public void testStoreLookupIMAP() throws MessagingException {
     52         final String storeUri = "imap://user:password (at) server.com";
     53         Store.StoreInfo info = Store.StoreInfo.getStoreInfo(storeUri, getContext());
     54 
     55         assertNotNull("storeInfo null", info);
     56         assertNotNull("scheme null", info.mScheme);
     57         assertNotNull("classname null", info.mClassName);
     58         assertFalse(info.mPushSupported);
     59         assertEquals(Email.VISIBLE_LIMIT_DEFAULT, info.mVisibleLimitDefault);
     60         assertEquals(Email.VISIBLE_LIMIT_INCREMENT, info.mVisibleLimitIncrement);
     61 
     62         // This will throw MessagingException if the result would have been null
     63         Store store = Store.getInstance(storeUri, getContext(), null);
     64     }
     65 
     66     /**
     67      * Test StoreInfo & Store lookup for EAS accounts
     68      * TODO: EAS store will probably require implementation of Store.PersistentDataCallbacks
     69      */
     70     public void testStoreLookupEAS() throws MessagingException {
     71         final String storeUri = "eas://user:password (at) server.com";
     72         Store.StoreInfo info = Store.StoreInfo.getStoreInfo(storeUri, getContext());
     73         if (info != null) {
     74             assertNotNull("scheme null", info.mScheme);
     75             assertNotNull("classname null", info.mClassName);
     76             assertTrue(info.mPushSupported);
     77             assertEquals(-1, info.mVisibleLimitDefault);
     78             assertEquals(-1, info.mVisibleLimitIncrement);
     79 
     80             // This will throw MessagingException if the result would have been null
     81             Store store = Store.getInstance(storeUri, getContext(), null);
     82         } else {
     83             try {
     84                 Store store = Store.getInstance(storeUri, getContext(), null);
     85                 fail("MessagingException expected when EAS not supported");
     86             } catch (MessagingException me) {
     87                 // expected - fall through
     88             }
     89         }
     90     }
     91 
     92     /**
     93      * Test StoreInfo & Store lookup for unknown accounts
     94      */
     95     public void testStoreLookupUnknown() {
     96         final String storeUri = "bogus-scheme://user:password (at) server.com";
     97         Store.StoreInfo info = Store.StoreInfo.getStoreInfo(storeUri, getContext());
     98         assertNull(info);
     99 
    100         try {
    101             Store store = Store.getInstance(storeUri, getContext(), null);
    102             fail("MessagingException expected from bogus URI scheme");
    103         } catch (MessagingException me) {
    104             // expected - fall through
    105         }
    106     }
    107 
    108 }
    109