示例#1
0
  @Test
  public void testParseRequiredFlag() throws IOException, JDOMException {
    final StringBuffer configXml = new StringBuffer();
    configXml.append("<config>");
    configXml.append("  <user-fields>");
    configXml.append("    <first-name required='true' />");
    configXml.append("    <initials required='false' />");
    configXml.append("    <birthday/>");
    configXml.append("  </user-fields>");
    configXml.append("</config>");
    final Element configEl = JDOMUtil.parseDocument(configXml.toString()).getRootElement();

    final UserStoreConfig config = UserStoreConfigParser.parse(configEl);

    final Collection<UserStoreUserFieldConfig> allUserFieldConfigs = config.getUserFieldConfigs();

    for (final UserStoreUserFieldConfig userFieldConfig : allUserFieldConfigs) {
      if (userFieldConfig.getType().getName().equals("first-name")) {
        assertEquals(true, userFieldConfig.isRequired());
      } else if (userFieldConfig.getType().getName().equals("initials")) {
        assertEquals(false, userFieldConfig.isRequired());
      } else if (userFieldConfig.getType().getName().equals("birthday")) {
        assertEquals(false, userFieldConfig.isRequired());
      }
    }
  }
示例#2
0
  @Test
  public void testAllParseUserFieldTypes() throws IOException, JDOMException {
    final StringBuffer configXml = new StringBuffer();
    configXml.append("<config>");
    configXml.append("  <user-fields>");
    for (final UserFieldType type : UserFieldType.values()) {
      configXml.append("    <" + type.getName() + "/>");
    }
    configXml.append("  </user-fields>");
    configXml.append("</config>");
    final Element configEl = JDOMUtil.parseDocument(configXml.toString()).getRootElement();

    final UserStoreConfig config = UserStoreConfigParser.parse(configEl);

    assertNotNull(config);
    assertNotNull(config.getUserFieldConfigs());
    assertEquals(UserFieldType.values().length, config.getUserFieldConfigs().size());

    /* Verify unique types */
    final Set<UserFieldType> userFields = new HashSet<UserFieldType>();
    for (final UserStoreUserFieldConfig userFieldConfig : config.getUserFieldConfigs()) {
      userFields.add(userFieldConfig.getType());
    }
    assertEquals(UserFieldType.values().length, userFields.size());
  }
示例#3
0
  @Test
  public void testParseNull() throws IOException, JDOMException {
    final Element configEl = null;

    final UserStoreConfig config = UserStoreConfigParser.parse(configEl);

    assertNotNull(config);
    assertNotNull(config.getUserFieldConfigs());
  }
示例#4
0
  @Test
  public void testParseMissingUserElement() throws IOException, JDOMException {
    final StringBuffer configXml = new StringBuffer();
    configXml.append("<config>");
    configXml.append("</config>");
    final Element configEl = JDOMUtil.parseDocument(configXml.toString()).getRootElement();

    try {
      UserStoreConfigParser.parse(configEl);
      fail("An exception should have been thrown.");
    } catch (Exception ex) {
      assertEquals(InvalidUserStoreConfigException.class.getName(), ex.getClass().getName());
    }
  }
示例#5
0
  @Test
  public void testParseIllegalUserFieldAttributeValue_Required() throws IOException, JDOMException {
    final StringBuffer configXml = new StringBuffer();
    configXml.append("<config>");
    configXml.append("  <user-fields>");
    configXml.append("    <prefix required=\"fisk\"/>");
    configXml.append("  </user-fields>");
    configXml.append("</config>");
    final Element configEl = JDOMUtil.parseDocument(configXml.toString()).getRootElement();

    try {
      UserStoreConfigParser.parse(configEl);
      fail("An exception should have been thrown.");
    } catch (Exception ex) {
      assertEquals(InvalidUserStoreConfigException.class.getName(), ex.getClass().getName());
    }
  }
示例#6
0
  @Test
  public void testParseIllegalUserFieldAttributePresent_Name() throws IOException, JDOMException {
    final StringBuffer configXml = new StringBuffer();
    configXml.append("<config>");
    configXml.append("  <user-fields>");
    configXml.append("    <prefix name=\"fisk\"/>");
    configXml.append("  </user-fields>");
    configXml.append("</config>");
    final Element configEl = JDOMUtil.parseDocument(configXml.toString()).getRootElement();

    try {
      UserStoreConfigParser.parse(configEl);
      fail("An exception should have been thrown.");
    } catch (Exception ex) {
      assertTrue(ex instanceof InvalidUserStoreConfigException);
    }
  }
示例#7
0
  @Test
  public void testParseIsoFlag() throws IOException, JDOMException {
    final StringBuffer configXml = new StringBuffer();
    configXml.append("<config>");
    configXml.append("  <user-fields>");
    configXml.append("    <address iso='true' />");
    configXml.append("  </user-fields>");
    configXml.append("</config>");
    final Element configEl = JDOMUtil.parseDocument(configXml.toString()).getRootElement();

    final UserStoreConfig config = UserStoreConfigParser.parse(configEl);

    final Collection<UserStoreUserFieldConfig> allUserFieldConfigs = config.getUserFieldConfigs();

    for (final UserStoreUserFieldConfig userFieldConfig : allUserFieldConfigs) {
      if (userFieldConfig.getType().getName().equals("address")) {
        assertEquals(true, userFieldConfig.useIso());
      }
    }
  }