Overwiew of using Jice for collection classes. Further docs at Jice site.

HashMap Example

In this example we will load a HashMap object with two entries:

  • name = key1 ; value = value1
  • name = key2 ; value = value2

Notice the action attribute of the entry element.
This element specifies that the entry element is to be put in the container HashMap.

The method call parent.put(key,value) is a method of the class HashMap; where parent refers to the HashMap instance itself.
In similar ways you can use other collection objects as Vector, ArrayList ecc.

Jice Element For an HashMap

    <method name="testGetHashMap"> 
         <param name="hashmap" type="" use-jice="yes">
             <map xmlns="" class="java.util.HashMap">
               <entry action="parent.put(key,value)">
                 <key>key1</key> <value>value1</value>
               <entry action="parent.put(key,value)">
                 <key>key2</key> <value>value2</value>

Example JTestCase Test

 * This program is licensed under Common Public License Version 0.5.
 * For License Information and conditions of use, see "LICENSE" in packaged
package org.jtestcase;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Locale;
import java.util.Vector;

import junit.framework.TestCase;

   * Tests getting jice elements as parameters
   @throws Exception
  public void testGetHashMap() throws Exception {

    Vector testCases = null;
    HashMap params = null;
    _jtestcase = new JTestCase(dataFile, getName());

    testCases = _jtestcase

    // for each test case
    for (int i = 0; i < testCases.size(); i++) {
      TestCaseInstance testCase = ((TestCaseInstancetestCases
      params = testCase.getTestCaseParams();
      HashMap jiceHashMap = (HashMapparams.get("hashmap");
      assertTrue("hashmap key1 value name not correct"((String)jiceHashMap.get("key1")).equals("value1"));
      assertTrue("hashmap key2 value name not correct"((String)jiceHashMap.get("key2")).equals("value2"));