Beispiel #1
0
 /*
  * @see java.lang.Object#toString()
  */
 @Override
 public String toString() {
   StringBuilder sb = new StringBuilder();
   sb.append(getClass().getName() + " {\n");
   for (CheckItem item : this) {
     sb.append("    " + item.toString() + "\n");
   }
   sb.append("  }");
   return sb.toString();
 }
 public String toString() {
   String res;
   res = getClass().getName() + " {\n";
   Enumeration cur = elements();
   while (cur.hasMoreElements()) {
     CheckItem item = (CheckItem) cur.nextElement();
     res += "    " + item.toString() + "\n";
   }
   res += "  }";
   return res;
 }
  /*
   * (non-Javadoc)
   *
   * @see
   * pt.lsts.neptus.types.XmlOutputMethods#asDocument(java.lang.String)
   */
  @Override
  public Document asDocument(String rootElementName) {
    Document document = DocumentHelper.createDocument();
    Element root = document.addElement(rootElementName);

    root.addComment(ConfigFetch.getSaveAsCommentForXML());

    root.addAttribute("name", getName());

    if (getVersion() != null && !"".equalsIgnoreCase(getVersion())) {
      root.addAttribute("version", getVersion());
    }

    if (getDescription() != null) {
      // root.addAttribute("description", getDescription());
      root.addElement("description").setText(getDescription());
    }

    if (isFlat()) {
      if (!groupList.isEmpty()) {
        LinkedList<CheckItem> lkl = groupList.values().iterator().next();
        Iterator<CheckItem> it = lkl.iterator();
        while (it.hasNext()) {
          CheckItem ci = it.next();
          root.add(ci.asElement());
        }
      }
    } else {
      Iterator<String> it = groupList.keySet().iterator();
      while (it.hasNext()) {
        String name = it.next();
        Element groupElem = root.addElement("group");
        groupElem.addAttribute("name", name);
        LinkedList<CheckItem> lkl = groupList.get(name);
        Iterator<CheckItem> it1 = lkl.iterator();
        while (it1.hasNext()) {
          CheckItem ci = it1.next();
          groupElem.add(ci.asElement());
        }
      }
    }

    return document;
  }
  /** Test constructor and some basic methods. */
  public void testBasics() {

    String category = "";
    String description = "";

    // initialize the ChecklistStatus
    ChecklistStatus list = new ChecklistStatus();

    // add some test data
    list.addItem("Test1");
    list.addItem("Test2");
    list.setNextCategory("Test Category");
    list.addItem("Test3");
    list.addItem("Test4");

    // verify the size of the list
    assertTrue("ChecklistStatus.size() is incorrect", list.size() == 4);

    // verify the items were correctly added
    int iter = 0;
    for (CheckItem item : list.getCheckItemList()) {

      switch (++iter) {
        case 1:
          category = "General";
          description = "Test1";
          break;

        case 2:
          category = "General";
          description = "Test2";
          break;

        case 3:
          category = "Test Category";
          description = "Test3";
          break;

        case 4:
          category = "Test Category";
          description = "Test4";
          break;
      }

      // test that the category and description are correct
      assertTrue(
          "ChecklistStatus items incorrectly added (category: "
              + category
              + ", description: )"
              + description,
          category == item.getCategory() && description == item.getDescription());
    }

    // create a new list to test the addAll
    ChecklistStatus list2 = new ChecklistStatus();

    // add all of the test items from the first list
    list2.addAll(list);

    // verify the size of the new list
    assertTrue("ChecklistStatus.addAll(Checklist) failed", list2.size() == 4);
  }