/** Tests accessing the following sibling axis. */
 public void testFollowingSiblingAxis() {
   List nodes = context.selectNodes("/" + CHILD_NAME1 + "[2]/following-sibling::*");
   assertEquals("Wrong number of following siblings", 1, nodes.size());
   ConfigurationNode node = (ConfigurationNode) nodes.get(0);
   assertEquals("Wrong node type", CHILD_NAME2, node.getName());
   assertEquals("Wrong index", String.valueOf(CHILD_COUNT), node.getValue());
 }
  @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);
    }
  }
 private boolean getBooleanValue(String name, boolean d) {
   List<ConfigurationNode> properties = getRootNode().getChildren();
   if (properties == null || properties.size() == 0) {
     return d;
   }
   for (ConfigurationNode p : properties) {
     if (p.getChildren("name") != null
         && p.getChildren("name").size() > 0
         && name.equals(p.getChildren("name").get(0).getValue())) {
       return Boolean.parseBoolean((String) p.getChildren("value").get(0).getValue());
     }
   }
   return d;
 }
 private float getFloatValue(String name, float d) {
   List<ConfigurationNode> properties = getRootNode().getChildren();
   if (properties == null || properties.size() == 0) {
     return d;
   }
   for (ConfigurationNode p : properties) {
     if (p.getChildren("name") != null
         && p.getChildren("name").size() > 0
         && name.equals(p.getChildren("name").get(0).getValue())) {
       return Float.parseFloat((String) p.getChildren("value").get(0).getValue());
     }
   }
   return d;
 }
  /** Tests simple XPath expressions. */
  public void testSimpleXPath() {
    List nodes = context.selectNodes(CHILD_NAME1);
    assertEquals("Incorrect number of results", 2, nodes.size());
    for (Iterator it = nodes.iterator(); it.hasNext(); ) {
      ConfigurationNode node = (ConfigurationNode) it.next();
      assertEquals("Incorrect node name", CHILD_NAME1, node.getName());
      assertEquals("Incorrect parent node", root, node.getParentNode());
    }

    nodes = context.selectNodes("/" + CHILD_NAME1);
    assertEquals("Incorrect number of results", 2, nodes.size());

    nodes = context.selectNodes(CHILD_NAME2 + "/" + CHILD_NAME1 + "/" + CHILD_NAME2);
    assertEquals("Incorrect number of results", 18, nodes.size());
  }
  /** 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));
  }
  /** Tests using indices to specify elements. */
  public void testIndices() {
    assertEquals(
        "Incorrect value",
        "1.2.3",
        context.getValue("/" + CHILD_NAME2 + "[1]/" + CHILD_NAME1 + "[1]/" + CHILD_NAME2 + "[2]"));
    assertEquals(
        "Incorrect value of last node",
        String.valueOf(CHILD_COUNT),
        context.getValue(CHILD_NAME2 + "[last()]"));

    List nodes = context.selectNodes("/" + CHILD_NAME1 + "[1]/*");
    assertEquals("Wrong number of children", CHILD_COUNT, nodes.size());
    int index = 1;
    for (Iterator it = nodes.iterator(); it.hasNext(); index++) {
      ConfigurationNode node = (ConfigurationNode) it.next();
      assertEquals("Wrong node value for child " + index, "2." + index, node.getValue());
    }
  }
  public LdapTestsSetup() {
    String confFile = System.getenv("LDAP_TESTER_PROPERTIES_FILE");
    if (confFile == null) {
      confFile = "ldap.integ/ldap-test.properties";
    }

    try {
      testProperties = new PropertiesConfiguration(confFile);

      Configuration usersSubset = testProperties.subset("users");
      HierarchicalConfiguration usersConfig = ConfigurationUtils.convertToHierarchical(usersSubset);
      List<ConfigurationNode> childrens = usersConfig.getRootNode().getChildren();
      for (ConfigurationNode node : childrens) {
        String name = node.getName();
        users.put(name, new Person(usersSubset.subset(name)));
      }

      Configuration groupsSubset = testProperties.subset("groups");
      HierarchicalConfiguration groupsConfig =
          ConfigurationUtils.convertToHierarchical(groupsSubset);
      childrens = groupsConfig.getRootNode().getChildren();
      for (ConfigurationNode node : childrens) {
        String name = node.getName();
        groups.put(name, new Group(groupsSubset.subset(name)));
      }

      Configuration ldapConfigurationSubset = testProperties.subset("configuration");
      HierarchicalConfiguration ldapConfig =
          ConfigurationUtils.convertToHierarchical(ldapConfigurationSubset);
      childrens = ldapConfig.getRootNode().getChildren();
      for (ConfigurationNode node : childrens) {
        String key = node.getName();
        String value = (String) node.getValue();
        ldapConfiguration.put(key, value);
      }
    } catch (ConfigurationException ex) {
      String message = "Problem loading configuration: " + ex.getMessage();
      log.error(message);
      throw new IllegalStateException(message);
    }
  }