javamanager/javainstaller/installer/tsrc/javasrc/com/nokia/mj/impl/installer/customisationproperties/CustomisationPropertiesTest.java
branchRCL_3
changeset 19 04becd199f91
child 23 98ccebc37403
equal deleted inserted replaced
16:f5050f1da672 19:04becd199f91
       
     1 /*
       
     2 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 package com.nokia.mj.impl.installer.customisationproperties;
       
    20 
       
    21 import java.util.Hashtable;
       
    22 import java.util.Vector;
       
    23 
       
    24 import com.nokia.mj.impl.installer.utils.DriveInfo;
       
    25 import com.nokia.mj.impl.installer.utils.InstallerException;
       
    26 import com.nokia.mj.impl.installer.utils.InstallerMain;
       
    27 import com.nokia.mj.impl.installer.utils.Platform;
       
    28 
       
    29 import j2meunit.framework.Test;
       
    30 import j2meunit.framework.TestCase;
       
    31 import j2meunit.framework.TestMethod;
       
    32 import j2meunit.framework.TestSuite;
       
    33 
       
    34 /**
       
    35  * ApplicationRegistrator unit tests.
       
    36  *
       
    37  * @author Nokia Corporation
       
    38  * @version $Rev: 9041 $
       
    39  */
       
    40 public class CustomisationPropertiesTest extends TestCase implements InstallerMain
       
    41 {
       
    42 
       
    43 
       
    44     // Begin j2meunit test framework setup
       
    45     public void installerMain(String[] args)
       
    46     {
       
    47         TestSuite suite = new TestSuite(this.getClass().getName());
       
    48 
       
    49         suite.addTest(new CustomisationPropertiesTest("testSplitCommaSeparatedString", new TestMethod()
       
    50         {
       
    51             public void run(TestCase tc)
       
    52             {
       
    53                 ((CustomisationPropertiesTest)tc).testSplitCommaSeparatedString();
       
    54             }
       
    55         }));
       
    56 
       
    57         if (Platform.isS60())
       
    58         {
       
    59             suite.addTest(new CustomisationPropertiesTest("testDefaultInstallationDrive", new TestMethod()
       
    60             {
       
    61                 public void run(TestCase tc)
       
    62                 {
       
    63                     ((CustomisationPropertiesTest)tc).testDefaultInstallationDrive();
       
    64                 }
       
    65             }));
       
    66 
       
    67             suite.addTest(new CustomisationPropertiesTest("testPossibleInstallationDrives", new TestMethod()
       
    68             {
       
    69                 public void run(TestCase tc)
       
    70                 {
       
    71                     ((CustomisationPropertiesTest)tc).testPossibleInstallationDrives();
       
    72                 }
       
    73             }));
       
    74 
       
    75             suite.addTest(new CustomisationPropertiesTest("testTypesOfPossibleInstallationDrives", new TestMethod()
       
    76             {
       
    77                 public void run(TestCase tc)
       
    78                 {
       
    79                     ((CustomisationPropertiesTest)tc).testTypesOfPossibleInstallationDrives();
       
    80                 }
       
    81             }));
       
    82 
       
    83             suite.addTest(new CustomisationPropertiesTest("testPreinstalledDefaultDrive", new TestMethod()
       
    84             {
       
    85                 public void run(TestCase tc)
       
    86                 {
       
    87                     ((CustomisationPropertiesTest)tc).testPreinstalledDefaultDrive();
       
    88                 }
       
    89             }));
       
    90 
       
    91             suite.addTest(new CustomisationPropertiesTest("testDefaultInstallationFolder", new TestMethod()
       
    92             {
       
    93                 public void run(TestCase tc)
       
    94                 {
       
    95                     ((CustomisationPropertiesTest)tc).testDefaultInstallationFolder();
       
    96                 }
       
    97             }));
       
    98 
       
    99             suite.addTest(new CustomisationPropertiesTest("testPossibleInstallationFolders", new TestMethod()
       
   100             {
       
   101                 public void run(TestCase tc)
       
   102                 {
       
   103                     ((CustomisationPropertiesTest)tc).testPossibleInstallationFolders();
       
   104                 }
       
   105             }));
       
   106 
       
   107             suite.addTest(new CustomisationPropertiesTest("testShellFolderAttributeNames", new TestMethod()
       
   108             {
       
   109                 public void run(TestCase tc)
       
   110                 {
       
   111                     ((CustomisationPropertiesTest)tc).testShellFolderAttributeNames();
       
   112                 }
       
   113             }));
       
   114         }
       
   115 
       
   116         com.nokia.mj.impl.utils.OmjTestRunner.run(suite);
       
   117     }
       
   118 
       
   119     public CustomisationPropertiesTest()
       
   120     {
       
   121     }
       
   122 
       
   123     public CustomisationPropertiesTest(String aTestName, TestMethod aTestMethod)
       
   124     {
       
   125         super(aTestName, aTestMethod);
       
   126     }
       
   127 
       
   128     public void assertFalse(String aMsg, boolean aCondition)
       
   129     {
       
   130         assertTrue(aMsg, !aCondition);
       
   131     }
       
   132 
       
   133     // End j2meunit test framework setup
       
   134     protected void setUp()
       
   135     {
       
   136     }
       
   137 
       
   138     protected void tearDown()
       
   139     {
       
   140     }
       
   141 
       
   142     public void testSplitCommaSeparatedString()
       
   143     {
       
   144         CustomisationProperties cust = new CustomisationProperties();
       
   145 
       
   146         Vector value;
       
   147 
       
   148         value = cust.splitCommaSeparatedString(null);
       
   149         assertTrue("Splitting null did not result empty vector", value.size() == 0);
       
   150 
       
   151         value = cust.splitCommaSeparatedString("");
       
   152         assertTrue("Splitting empty did not result empty vector", value.size() == 0);
       
   153 
       
   154 
       
   155         value = cust.splitCommaSeparatedString(",");
       
   156         assertTrue("Splitting comma did not result empty vector", value.size() == 0);
       
   157 
       
   158         value = cust.splitCommaSeparatedString(" ,,    ,   , ,, ");
       
   159         assertTrue("Splitting \" ,,    ,   , ,, \" did not result empty vector", value.size() == 0);
       
   160 
       
   161         value = cust.splitCommaSeparatedString(",Games,Applications,");
       
   162         assertTrue("Splitting ,Games,Applications, did not result vector with 2 objects", value.size() == 2);
       
   163         assertTrue("Splitting ,Games,Applications, did not result Games", ((String)value.get(0)).equals("Games"));
       
   164         assertTrue("Splitting ,Games,Applications, did not result Applications", ((String)value.get(1)).equals("Applications"));
       
   165 
       
   166 
       
   167         value = cust.splitCommaSeparatedString(" ,Games ,, , Applications,  ");
       
   168         assertTrue("Splitting \" ,Games ,, , Applications,  \" did not result vector with 2 objects", value.size() == 2);
       
   169         assertTrue("Splitting \" ,Games ,, , Applications,  \" did not result Games", ((String)value.get(0)).equals("Games"));
       
   170         assertTrue("Splitting \" ,Games ,, , Applications,  \" did not result Applications", ((String)value.get(1)).equals("Applications"));
       
   171     }
       
   172 
       
   173 
       
   174     public void testDefaultInstallationDrive()
       
   175     {
       
   176         CustomisationProperties cust = new CustomisationProperties();
       
   177 
       
   178         Vector value = null;
       
   179 
       
   180         // Test DefaultInstallationDrive
       
   181         try
       
   182         {
       
   183             value = cust.getProperty(CustomisationProperties.DefaultInstallationDrive);
       
   184         }
       
   185         catch (Throwable t)
       
   186         {
       
   187             assertTrue("Unexpected throwable " + t.toString(), false);
       
   188         }
       
   189         assertTrue("DefaultInstallationDrive value is null", (value != null));
       
   190         assertTrue("DefaultInstallationDrive value does not contain any strings", (value.size() > 0));
       
   191 
       
   192         String drive = (String)value.firstElement();
       
   193         assertTrue("DefaultInstallationDrive is null", (drive != null));
       
   194         assertTrue("DefaultInstallationDrive is C:", drive.equals("C:"));
       
   195 
       
   196 
       
   197         value = cust.getIntegerProperty(CustomisationProperties.DefaultInstallationDrive);
       
   198         assertTrue("DefaultInstallationDrive value is null", (value != null));
       
   199         assertTrue("DefaultInstallationDrive value does not contain any integers", (value.size() > 0));
       
   200 
       
   201         Integer idrive = (Integer)value.firstElement();
       
   202         assertTrue("DefaultInstallationDrive is null", (idrive != null));
       
   203         assertTrue("DefaultInstallationDrive is not C:", idrive.intValue() == 2);
       
   204     }
       
   205 
       
   206     public void testPossibleInstallationDrives()
       
   207     {
       
   208         CustomisationProperties cust = new CustomisationProperties();
       
   209 
       
   210         Vector value = null;
       
   211         // Test PossibleInstallationDrives
       
   212         value = cust.getProperty(CustomisationProperties.PossibleInstallationDrives);
       
   213         assertTrue("PossibleInstallationDrives value is null", (value != null));
       
   214         assertTrue("PossibleInstallationDrives value does not contain any strings", (value.size() > 0));
       
   215 
       
   216         String drive = (String)value.firstElement();
       
   217         assertTrue("PossibleInstallationDrives is null", (drive != null));
       
   218         assertTrue("First PossibleInstallationDrive is not C:", drive.equals("C:"));
       
   219         // second possible drive
       
   220         drive = (String)value.get(1);
       
   221         assertTrue("PossibleInstallationDrives is null", (drive != null));
       
   222         assertTrue("Second PossibleInstallationDrive is not E:", drive.equals("E:"));
       
   223 
       
   224         value = cust.getIntegerProperty(CustomisationProperties.PossibleInstallationDrives);
       
   225         assertTrue("PossibleInstallationDrives value is null", (value != null));
       
   226         assertTrue("PossibleInstallationDrives value does not contain any integers", (value.size() > 0));
       
   227 
       
   228         Integer idrive = (Integer)value.get(1);
       
   229         assertTrue("Second PossibleInstallationDrive is E:", idrive.intValue() == 4);
       
   230     }
       
   231 
       
   232     public void testTypesOfPossibleInstallationDrives()
       
   233     {
       
   234         CustomisationProperties cust = new CustomisationProperties();
       
   235 
       
   236         Vector value = null;
       
   237         // Test TypesOfPossibleInstallationDrives
       
   238         value = cust.getIntegerProperty(CustomisationProperties.TypesOfPossibleInstallationDrives);
       
   239         assertTrue("TypesOfPossibleInstallationDrives value is null", (value != null));
       
   240         assertTrue("TypesOfPossibleInstallationDrives value does not contain any integers", (value.size() > 0));
       
   241 
       
   242         Integer type = (Integer)value.firstElement();
       
   243         assertTrue("TypesOfPossibleInstallationDrives is null", (type != null));
       
   244         assertTrue("Type of first drive is not PHONE_MEMORY, it is " + type.toString(),
       
   245                    (type.intValue() == DriveInfo.PHONE_MEMORY));
       
   246         // second possible drive is E:
       
   247         type = (Integer)value.get(1);
       
   248         assertTrue("Type of second drive is null", (type != null));
       
   249         assertTrue("Type of second drive is not MEMORY_CARD, it is " + type.toString(),
       
   250                    (type.intValue() == DriveInfo.MEMORY_CARD));
       
   251     }
       
   252 
       
   253     public void testPreinstalledDefaultDrive()
       
   254     {
       
   255         CustomisationProperties cust = new CustomisationProperties();
       
   256 
       
   257         Vector value = null;
       
   258         // Test PreinstalledDefaultDrive
       
   259         value = cust.getProperty(CustomisationProperties.PreinstalledDefaultDrive);
       
   260         assertTrue("PreinstalledDefaultDrive value is null", (value != null));
       
   261         assertTrue("PreinstalledDefaultDrive value does not contain any strings", (value.size() > 0));
       
   262 
       
   263         String drive = (String)value.firstElement();
       
   264         assertTrue("PreinstalledDefaultDrive is null", (drive != null));
       
   265         assertTrue("PreinstalledDefaultDrive is not C:", drive.equals("C:"));
       
   266     }
       
   267 
       
   268     public void testDefaultInstallationFolder()
       
   269     {
       
   270         CustomisationProperties cust = new CustomisationProperties();
       
   271 
       
   272         Vector value = null;
       
   273         // Test DefaultInstallationFolder
       
   274         value = cust.getProperty(CustomisationProperties.DefaultInstallationFolder);
       
   275         assertTrue("DefaultInstallationFolder value is null", (value != null));
       
   276         assertTrue("DefaultInstallationFolder value does not contain any strings", (value.size() > 0));
       
   277 
       
   278         String folder = (String)value.firstElement();
       
   279         assertTrue("DefaultInstallationFolder is null", (folder != null));
       
   280         assertTrue("DefaultInstallationFolder is not empty string", folder.equals(""));
       
   281     }
       
   282 
       
   283     public void testPossibleInstallationFolders()
       
   284     {
       
   285         CustomisationProperties cust = new CustomisationProperties();
       
   286 
       
   287         Vector valueDef = cust.getProperty(CustomisationProperties.DefaultInstallationFolder);
       
   288         Vector value = cust.getProperty(CustomisationProperties.PossibleInstallationFolders);
       
   289 
       
   290         assertTrue("DefaultInstallationFolder value is null", (valueDef != null));
       
   291         assertTrue("DefaultInstallationFolder value does not contain any strings", (valueDef.size() > 0));
       
   292         String defFolder = (String)valueDef.firstElement();
       
   293 
       
   294         assertTrue("PossibleInstallationFolders value is null", (value != null));
       
   295         assertTrue("PossibleInstallationFolders value does not contain any strings", (value.size() > 0));
       
   296 
       
   297         // default installation folder is one of the possible folders
       
   298         assertTrue("Default folder is not one of possible installation folders", value.contains(defFolder));
       
   299     }
       
   300 
       
   301     public void testShellFolderAttributeNames()
       
   302     {
       
   303         CustomisationProperties cust = new CustomisationProperties();
       
   304 
       
   305         Vector value = cust.getProperty(CustomisationProperties.ShellFolderAttributeNames);
       
   306 
       
   307         assertTrue("ShellFolderAttributeNames value is null", (value != null));
       
   308         assertTrue("ShellFolderAttributeNames value does not contain any strings", (value.size() > 0));
       
   309         String firstName = (String)value.firstElement();
       
   310 
       
   311         // 'Nokia-MIDlet-Category' is one of the attribute names
       
   312         assertTrue("Nokia-MIDlet-Category is not allowed attribute name", value.contains("Nokia-MIDlet-Category"));
       
   313     }
       
   314 
       
   315 }