コード例 #1
0
  @Override
  public void write(ConfigurationNode node, NodeFactory factory) {
    node.addAttribute(factory.createNode(ConfigurationXml.ATTRIBUTE_TITLE, title));

    for (Scenario scenario : scenarios) {
      ConfigurationNode scenarioNode = factory.createNode(DefaultScenarioGroup.NODE_SCENARIO);

      scenario.write(scenarioNode, factory);

      node.addChild(scenarioNode);
    }
  }
  /** Tests accessing attributes. */
  public void testAttributes() {
    root.addAttribute(new DefaultConfigurationNode("testAttr", "true"));
    assertEquals("Did not find attribute of root node", "true", context.getValue("@testAttr"));
    assertEquals(
        "Incorrect attribute value",
        "1",
        context.getValue("/" + CHILD_NAME2 + "[1]/@" + ATTR_NAME));

    assertTrue(
        "Found elements with name attribute",
        context.selectNodes("//" + CHILD_NAME2 + "[@name]").isEmpty());
    ConfigurationNode node =
        (ConfigurationNode) root.getChild(2).getChild(1).getChildren(CHILD_NAME2).get(1);
    node.addAttribute(new DefaultConfigurationNode("name", "testValue"));
    List nodes = context.selectNodes("//" + CHILD_NAME2 + "[@name]");
    assertEquals("Name attribute not found", 1, nodes.size());
    assertEquals("Wrong node returned", node, nodes.get(0));
  }