コード例 #1
0
 @Test
 public void canReplaceRootElement() {
   SpinXmlElement root = XML("<root/>");
   assertThat(element.name()).isEqualTo("customers");
   assertThat(element.childElements()).isNotEmpty();
   element = element.replace(root);
   assertThat(element.name()).isEqualTo("root");
   assertThat(element.childElements()).isEmpty();
 }
コード例 #2
0
 @Test
 public void canAppendChildElementAfterLastChildElement() {
   SpinXmlElement child = XML("<child/>");
   int childCount = element.childElements().size();
   SpinXmlElement lastChildElement = element.childElements().get(childCount - 1);
   element.appendAfter(child, lastChildElement);
   SpinXmlElement insertedElement = element.childElements().get(childCount);
   assertThat(insertedElement.name()).isEqualTo("child");
 }
コード例 #3
0
 @Test
 public void canAppendChildElementAfterExistingElement() {
   SpinXmlElement child = XML("<child/>");
   SpinXmlElement date = element.childElement("date");
   element.appendAfter(child, date);
   SpinXmlElement insertedElement = element.childElements().get(1);
   assertThat(insertedElement.name()).isEqualTo("child");
 }
コード例 #4
0
  @Test
  public void canRemoveChildElementCollection() {
    SpinXmlElement child1 = XML("<child/>");
    SpinXmlElement child2 = XML("<child/>");
    SpinXmlElement child3 = XML("<child/>");
    element.append(child1, child2, child3);

    assertThat(element.childElements(null, "child")).hasSize(3);

    element.remove(element.childElements(null, "child"));

    try {
      assertThat(element.childElements(null, "child"));
      fail("Child element should be removed");
    } catch (Exception e) {
      assertThat(e).isInstanceOf(SpinXmlElementException.class);
    }
  }
コード例 #5
0
  @Test
  public void canAppendChildElementCollection() {
    Collection<SpinXmlElement> childElements = new ArrayList<SpinXmlElement>();
    childElements.add(XML("<child/>"));
    childElements.add(XML("<child/>"));
    childElements.add(XML("<child/>"));

    element = element.append(childElements);

    SpinList<SpinXmlElement> childs = element.childElements(null, "child");
    assertThat(childs).hasSize(3);
  }
コード例 #6
0
  @Test
  public void canAppendMultipleChildElements() {
    SpinXmlElement child1 = XML("<child/>");
    SpinXmlElement child2 = XML("<child/>");
    SpinXmlElement child3 = XML("<child/>");

    element = element.append(child1, child2, child3);

    child1.attr("id", "child");
    child2.attr("id", "child");
    child3.attr("id", "child");

    SpinList<SpinXmlElement> childs = element.childElements(null, "child");
    assertThat(childs).hasSize(3);

    for (SpinXmlElement childElement : childs) {
      assertThat(childElement).isNotNull();
      assertThat(childElement.attr("id").value()).isEqualTo("child");
    }
  }
コード例 #7
0
 @Test(expected = IllegalArgumentException.class)
 public void cannotGetAllChildElementsByNullNamespaceAndNullName() {
   element.childElements(null, null);
 }
コード例 #8
0
 @Test(expected = SpinXmlElementException.class)
 public void cannotGetAllChildElementsByNonExistingNamespaceAndNonExistingName() {
   element.childElements(NON_EXISTING, NON_EXISTING);
 }
コード例 #9
0
 @Test
 public void canGetAllChildElementsByNullNamespaceAndName() {
   SpinList<SpinXmlElement> childElements = element.childElements(null, "info");
   assertThat(childElements).hasSize(2);
 }
コード例 #10
0
 @Test
 public void canGetAllChildElementsByNamespaceAndName() {
   SpinList<SpinXmlElement> childElements = element.childElements(EXAMPLE_NAMESPACE, "customer");
   assertThat(childElements).hasSize(3);
 }
コード例 #11
0
 @Test
 public void canGetAllChildElementsByName() {
   SpinList<SpinXmlElement> childElements = element.childElements("customer");
   assertThat(childElements).hasSize(3);
 }
コード例 #12
0
 @Test
 public void canGetAllChildElements() {
   SpinList<SpinXmlElement> childElements = element.childElements();
   assertThat(childElements).hasSize(7);
 }