mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

matthew_swift
28.47.2010 f2160f4bd1c8ac67e5a86a6710d431e8932877f9
sdk/tests/unit-tests-testng/src/org/opends/sdk/schema/RegexSyntaxTestCase.java
@@ -45,39 +45,10 @@
   * {@inheritDoc}
   */
  @Override
  protected Syntax getRule()
  {
    SchemaBuilder builder = new SchemaBuilder(Schema.getCoreSchema());
    builder.addPatternSyntax("1.1.1",
        "Host and Port in the format of HOST:PORT", Pattern
            .compile("^[a-z-A-Z]+:[0-9.]+\\d$"), false);
    return builder.toSchema().getSyntax("1.1.1");
  }
  /**
   * {@inheritDoc}
   */
  @Override
  @DataProvider(name = "acceptableValues")
  public Object[][] createAcceptableValues()
  {
    return new Object[][] { { "invalid regex", false },
        { "host:0.0.0", true }, };
  }
  @Test
  public void testInvalidPattern()
  {
    // This should fail due to invalid pattern.
    SchemaBuilder builder = new SchemaBuilder(Schema.getCoreSchema());
    builder.addSyntax(
        "( 1.1.1 DESC 'Host and Port in the format of HOST:PORT' "
            + " X-PATTERN '^[a-z-A-Z+:[0-@.]+\\d$' )", true);
    Assert.assertFalse(builder.toSchema().getWarnings().isEmpty());
    return new Object[][] { { "invalid regex", false }, { "host:0.0.0", true }, };
  }
@@ -86,11 +57,39 @@
  public void testDecode()
  {
    // This should fail due to invalid pattern.
    SchemaBuilder builder = new SchemaBuilder(Schema.getCoreSchema());
    final SchemaBuilder builder = new SchemaBuilder(Schema.getCoreSchema());
    builder.addSyntax(
        "( 1.1.1 DESC 'Host and Port in the format of HOST:PORT' "
            + " X-PATTERN '^[a-z-A-Z]+:[0-9.]+\\d$' )", true);
    builder.toSchema();
  }
  @Test
  public void testInvalidPattern()
  {
    // This should fail due to invalid pattern.
    final SchemaBuilder builder = new SchemaBuilder(Schema.getCoreSchema());
    builder.addSyntax(
        "( 1.1.1 DESC 'Host and Port in the format of HOST:PORT' "
            + " X-PATTERN '^[a-z-A-Z+:[0-@.]+\\d$' )", true);
    Assert.assertFalse(builder.toSchema().getWarnings().isEmpty());
  }
  /**
   * {@inheritDoc}
   */
  @Override
  protected Syntax getRule()
  {
    final SchemaBuilder builder = new SchemaBuilder(Schema.getCoreSchema());
    builder.addPatternSyntax("1.1.1",
        "Host and Port in the format of HOST:PORT", Pattern
            .compile("^[a-z-A-Z]+:[0-9.]+\\d$"), false);
    return builder.toSchema().getSyntax("1.1.1");
  }
}