001    package org.hackystat.sensorshell.usermap;
002    
003    import java.io.File;
004    import java.util.Locale;
005    
006    import org.hackystat.sensorshell.usermap.UserMap.UserMapKey;
007    
008    import junit.framework.TestCase;
009    
010    /**
011     * A test case class to test the UserMap class. It makes sure that instantiation, and therefore
012     * formatting of the UserMap.xml file, is done correctly. It also ensures that it correctly provides
013     * its core functionality by testing to see that it gives back a dummy Hackystat value for a given
014     * dummy tool account.
015     * 
016     * @author Julie Ann Sakuda
017     */
018    public class TestUserMap extends TestCase {
019    
020      private String tool = "test";
021      private String toolAccount = "dummyaccount";
022      private String user = "test@hackystat.org";
023      private String password = "test@hackystat.org";
024      private String sensorbase = "http://localhost/";
025    
026      /**
027       * Test the UserMap class and the formatting of the UserMap.xml.
028       * 
029       * @throws Exception if errors occur.
030       */
031      public void testMap() throws Exception {
032        UserMap userMap = null;
033        userMap = new UserMap(new File(System.getProperty("usermaptestfile")));
034        assertNotNull("Checking that the UserMap is not null", userMap);
035        assertEquals("Check user", user, userMap.get(tool, toolAccount, UserMapKey.USER));
036        assertEquals("Check password", password, userMap.get(tool, toolAccount, UserMapKey.PASSWORD));
037        assertEquals("Check sensorbase", sensorbase, userMap.get(tool, toolAccount,
038            UserMapKey.SENSORBASE));
039      }
040      
041      /** 
042       * Test that the tool and toolaccount in the user map are case-insensitive on retrieval.
043       * 
044       *  @throws Exception if an error occurs.
045       */
046      public void testCaseInsensitiveRetrievals() throws Exception {
047        UserMap userMap = null;
048        userMap = new UserMap(new File(System.getProperty("usermaptestfile")));
049        assertNotNull("Checking that the UserMap is not null", userMap);
050        assertNotNull("Checking get 1", userMap.get(tool, toolAccount, UserMapKey.USER));
051        assertNotNull("Checking get 2", 
052            userMap.get(tool.toUpperCase(Locale.ENGLISH), toolAccount, UserMapKey.USER));
053        assertNotNull("Checking get 3", 
054            userMap.get(tool, toolAccount.toUpperCase(Locale.ENGLISH), UserMapKey.USER));
055      }
056    }