コード例 #1
0
  /**
   * Test that the file system manager can insert an XML element into a file.
   *
   * @throws Exception If anything goes wrong
   */
  public void testManagerCanInsertAnElementIntoFile() throws Exception {
    Document document = DocumentHelper.createDocument();
    document.addElement("Application");
    util.saveXml(document, TEST_FILE);
    fileHandler.createFile(TEST_FILE);
    manager.setFile(TEST_FILE);
    manager.loadFile();
    manager.insertElementsUnderXPath("<subnode property='hello' />", "//Application");
    manager.writeFile();

    String xml = fileHandler.readTextFile(TEST_FILE, "UTF-8");

    XMLAssert.assertXpathEvaluatesTo("hello", "//Application/subnode/@property", xml);
  }
コード例 #2
0
  /**
   * Test that the file system manager can insert an XML element with a namespace.
   *
   * @throws Exception If anything goes wrong
   */
  public void testManagerCanInsertAnElementIntoFileWithNamespace() throws Exception {
    Document document = DocumentHelper.createDocument();
    Element domain = document.addElement("domain");
    document.setRootElement(domain);
    domain.addNamespace("", "http://www.bea.com/ns/weblogic/920/domain");
    util.saveXml(document, TEST_FILE);
    fileHandler.createFile(TEST_FILE);
    manager.setNamespaces(namespaces);
    manager.setFile(TEST_FILE);
    manager.loadFile();
    manager.insertElementsUnderXPath("<subnode property='hello' />", "//weblogic:domain");
    manager.writeFile();

    String xml = fileHandler.readTextFile(TEST_FILE, "UTF-8");

    XMLAssert.assertXpathEvaluatesTo("hello", "//weblogic:domain/weblogic:subnode/@property", xml);
  }