Ejemplo n.º 1
0
  private void expandCombinations(
      List<ComboOption> optionsLeft, List<HashMap<String, Object>> expandedCombos) {
    if (!optionsLeft.isEmpty()) {
      HashMap<String, Object> map;
      if (comboOptions.size() == optionsLeft.size()) {
        map = new HashMap<String, Object>();
        expandedCombos.add(map);
      } else {
        map = expandedCombos.get(expandedCombos.size() - 1);
      }

      LinkedList<ComboOption> l = new LinkedList<ComboOption>(optionsLeft);
      ComboOption comboOption = l.removeLast();
      int i = 0;
      if (comboOption.values.isEmpty() && !l.isEmpty()) {
        expandCombinations(l, expandedCombos);
      } else {
        for (Iterator<Object> iter = comboOption.values.iterator(); iter.hasNext(); ) {
          Object value = iter.next();
          if (i != 0) {
            map = new HashMap<String, Object>(map);
            expandedCombos.add(map);
          }
          map.put(comboOption.attribute, value);
          expandCombinations(l, expandedCombos);
          i++;
        }
      }
    }
  }
Ejemplo n.º 2
0
  private CombinationTestSupport[] getCombinations() {
    try {
      Method method = getClass().getMethod("initCombos", (Class[]) null);
      method.invoke(this, (Object[]) null);
    } catch (Throwable e) {
    }

    String name = getName().split(" ")[0];
    String comboSetupMethodName =
        "initCombosFor" + Character.toUpperCase(name.charAt(0)) + name.substring(1);
    try {
      Method method = getClass().getMethod(comboSetupMethodName, (Class[]) null);
      method.invoke(this, (Object[]) null);
    } catch (Throwable e) {
    }

    try {
      ArrayList<HashMap<String, Object>> expandedOptions = new ArrayList<HashMap<String, Object>>();
      expandCombinations(new ArrayList<ComboOption>(comboOptions.values()), expandedOptions);

      if (expandedOptions.isEmpty()) {
        combosEvaluated = true;
        return new CombinationTestSupport[] {this};
      } else {

        ArrayList<CombinationTestSupport> result = new ArrayList<CombinationTestSupport>();
        // Run the test case for each possible combination
        for (Iterator<HashMap<String, Object>> iter = expandedOptions.iterator();
            iter.hasNext(); ) {
          CombinationTestSupport combo =
              (CombinationTestSupport) TestSuite.createTest(getClass(), name);
          combo.combosEvaluated = true;
          combo.setOptions(iter.next());
          result.add(combo);
        }

        CombinationTestSupport rc[] = new CombinationTestSupport[result.size()];
        result.toArray(rc);
        return rc;
      }
    } catch (Throwable e) {
      combosEvaluated = true;
      return new CombinationTestSupport[] {this};
    }
  }