/** 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());
 }
  /** 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());
    }
  }
Ejemplo n.º 3
0
  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);
    }
  }