コード例 #1
0
 public void testChildrenNamed() {
   Node element2Node = XMLTools.child(this.rootNode, "element-2");
   Node[] children = XMLTools.children(element2Node, "element-2.0");
   assertEquals(3, children.length);
   for (int i = 0; i < children.length; i++) {
     assertEquals("element-2.0", children[i].getNodeName());
   }
 }
コード例 #2
0
 public void testChildTextContentDefaultValue() {
   assertEquals(
       "element 3 contents",
       XMLTools.childTextContent(this.rootNode, "element-3", "default value 3"));
   assertEquals(
       "default value 4",
       XMLTools.childTextContent(this.rootNode, "element-4", "default value 4"));
 }
コード例 #3
0
  public void testChildBooleanContentDefaultValue() {
    Node node = XMLTools.child(this.rootNode, "element-1");
    assertTrue(XMLTools.childBooleanContent(node, "element-1-boolean-true-1", false));
    assertTrue(XMLTools.childBooleanContent(node, "element-1-boolean-true-2", false));
    assertTrue(XMLTools.childBooleanContent(node, "element-1-boolean-true-3", false));
    assertFalse(XMLTools.childBooleanContent(node, "element-1-boolean-true-bogus", false));

    assertFalse(XMLTools.childBooleanContent(node, "element-1-boolean-false-1", true));
    assertFalse(XMLTools.childBooleanContent(node, "element-1-boolean-false-2", true));
    assertFalse(XMLTools.childBooleanContent(node, "element-1-boolean-false-3", true));
    assertTrue(XMLTools.childBooleanContent(node, "element-1-boolean-false-bogus", true));
  }
コード例 #4
0
 public void testChildren() {
   Node[] children = XMLTools.children(this.rootNode);
   assertEquals(4, children.length);
   for (int i = 1; i < 4; i++) {
     assertEquals("element-" + i, children[i].getNodeName());
   }
 }
コード例 #5
0
  public void testChildBooleanContent() {
    Node node = XMLTools.child(this.rootNode, "element-1");
    assertTrue(XMLTools.childBooleanContent(node, "element-1-boolean-true-1"));
    assertTrue(XMLTools.childBooleanContent(node, "element-1-boolean-true-2"));
    assertTrue(XMLTools.childBooleanContent(node, "element-1-boolean-true-3"));

    assertFalse(XMLTools.childBooleanContent(node, "element-1-boolean-false-1"));
    assertFalse(XMLTools.childBooleanContent(node, "element-1-boolean-false-2"));
    assertFalse(XMLTools.childBooleanContent(node, "element-1-boolean-false-3"));
  }
コード例 #6
0
  public void testTextContent() {
    Node node = XMLTools.child(this.rootNode, "element-0");
    Node childNode = XMLTools.child(node, "element-0-text-1");
    assertEquals("some text", XMLTools.textContent(childNode));

    childNode = XMLTools.child(node, "element-0-text-2");
    assertEquals("", XMLTools.textContent(childNode));

    childNode = XMLTools.child(node, "element-0-text-3");
    assertEquals("", XMLTools.textContent(childNode));

    childNode = XMLTools.child(node, "element-0-non-text");
    boolean exCaught = false;
    try {
      String text = XMLTools.textContent(childNode);
      text = text.toString();
    } catch (IllegalArgumentException ex) {
      exCaught = true;
    }
    assertTrue(exCaught);
  }
コード例 #7
0
 public void testChild() {
   assertEquals("element-1", XMLTools.child(this.rootNode, "element-1").getNodeName());
   assertEquals("element-3", XMLTools.child(this.rootNode, "element-3").getNodeName());
   assertEquals(null, XMLTools.child(this.rootNode, "element-1x"));
 }
コード例 #8
0
 private Document buildTestDocument() {
   return XMLTools.parse(new StringReader(this.buildTestDocumentString()));
 }
コード例 #9
0
 protected void setUp() throws Exception {
   super.setUp();
   this.testDocument = this.buildTestDocument();
   this.rootNode = XMLTools.child(this.testDocument, "root-element");
 }
コード例 #10
0
 public void testChildIntContentDefaultValue() {
   Node node = XMLTools.child(this.rootNode, "element-1");
   assertEquals(42, XMLTools.childIntContent(node, "element-1-int", 99));
   assertEquals(99, XMLTools.childIntContent(node, "element-1-int-x", 99));
 }
コード例 #11
0
 public void testChildIntContent() {
   Node node = XMLTools.child(this.rootNode, "element-1");
   assertEquals(42, XMLTools.childIntContent(node, "element-1-int"));
 }
コード例 #12
0
 public void testChildTextContent() {
   assertEquals("element 3 contents", XMLTools.childTextContent(this.rootNode, "element-3"));
 }