@Test public void canReplaceAElement() { SpinXmlElement child = XML("<child/>"); SpinXmlElement date = element.childElement("date"); assertThat(date).isNotNull(); date.replace(child); assertThat(element.childElement(null, "child")).isNotNull(); try { element.childElement("date"); } catch (Exception e) { assertThat(e).isInstanceOf(SpinXmlElementException.class); } }
@Test public void canRemoveAChildElement() { SpinXmlElement child = XML("<child/>"); element.append(child); assertThat(element.childElement(null, "child")).isNotNull(); element.remove(child); try { assertThat(element.childElement(null, "child")); fail("Child element should be removed"); } catch (Exception e) { assertThat(e).isInstanceOf(SpinXmlElementException.class); } }
@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"); }
@Test public void canAppendChildElementWithNamespace() { SpinXmlElement child = XML("<child xmlns=\"" + EXAMPLE_NAMESPACE + "\"/>"); element = element.append(child); child.attr("id", "child"); child = element.childElement(EXAMPLE_NAMESPACE, "child"); assertThat(child).isNotNull(); assertThat(child.attr("id").value()).isEqualTo("child"); }
@Test public void canAppendChildElement() { SpinXmlElement child = XML("<child/>"); element = element.append(child); child.attr("id", "child"); child = element.childElement(null, "child"); assertThat(child).isNotNull(); assertThat(child.attr("id").value()).isEqualTo("child"); }
@Test(expected = IllegalArgumentException.class) public void cannotReplaceByANullChildElement() { SpinXmlElement date = element.childElement("date"); element.replaceChild(date, null); }
@Test(expected = IllegalArgumentException.class) public void cannotGetChildElementByNullNamespaceAndNullName() { element.childElement(null, null); }
@Test(expected = SpinXmlElementException.class) public void cannotGetChildElementByNonExistingNamespaceAndNonExistingName() { element.childElement(NON_EXISTING, NON_EXISTING); }
@Test public void canGetSingleChildElementByNullNamespaceAndName() { SpinXmlElement childElement = element.childElement(null, "file"); assertThat(childElement).isNotNull(); }
@Test public void canGetSingleChildElementByNamespaceAndName() { SpinXmlElement childElement = element.childElement(EXAMPLE_NAMESPACE, "date"); assertThat(childElement).isNotNull(); assertThat(childElement.attr("name").value()).isEqualTo("20140512"); }