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

matthew_swift
28.47.2010 f2160f4bd1c8ac67e5a86a6710d431e8932877f9
sdk/tests/unit-tests-testng/src/org/opends/sdk/schema/AbstractSchemaElementTestCase.java
@@ -43,30 +43,23 @@
/**
 * Abstract schema element tests.
 */
public abstract class AbstractSchemaElementTestCase extends
    SchemaTestCase
public abstract class AbstractSchemaElementTestCase extends SchemaTestCase
{
  protected static final Map<String, List<String>> EMPTY_PROPS =
      Collections.emptyMap();
  protected static final List<String> EMPTY_NAMES =
      Collections.emptyList();
  protected abstract SchemaElement getElement(String description,
      Map<String, List<String>> extraProperties) throws SchemaException;
  protected static final Map<String, List<String>> EMPTY_PROPS = Collections
      .emptyMap();
  protected static final List<String> EMPTY_NAMES = Collections.emptyList();
  @DataProvider(name = "equalsTestData")
  public abstract Object[][] createEqualsTestData()
      throws SchemaException, DecodeException;
  public abstract Object[][] createEqualsTestData() throws SchemaException,
      DecodeException;
  /**
   * Check that the equals operator works as expected.
   *
   *
   * @param e1
   *          The first element
   * @param e2
@@ -77,8 +70,8 @@
   *           If the test failed unexpectedly.
   */
  @Test(dataProvider = "equalsTestData")
  public final void testEquals(SchemaElement e1, SchemaElement e2,
      boolean result) throws Exception
  public final void testEquals(final SchemaElement e1, final SchemaElement e2,
      final boolean result) throws Exception
  {
    Assert.assertEquals(e1.equals(e2), result);
@@ -88,8 +81,98 @@
  /**
   * Check that the {@link SchemaElement#getDescription()} method returns a
   * description.
   *
   * @throws Exception
   *           If the test failed unexpectedly.
   */
  @Test
  public final void testGetDescription() throws Exception
  {
    final SchemaElement e = getElement("hello", EMPTY_PROPS);
    Assert.assertEquals(e.getDescription(), "hello");
  }
  /**
   * Check that the {@link SchemaElement#getDescription()} method returns
   * <code>null</code> when there is no description.
   *
   * @throws Exception
   *           If the test failed unexpectedly.
   */
  @Test
  public final void testGetDescriptionDefault() throws Exception
  {
    final SchemaElement e = getElement("", EMPTY_PROPS);
    Assert.assertEquals(e.getDescription(), "");
  }
  /**
   * Check that the {@link SchemaElement#getExtraProperty(String)} method
   * returns values.
   *
   * @throws Exception
   *           If the test failed unexpectedly.
   */
  @Test
  public final void testGetExtraProperty() throws Exception
  {
    final List<String> values = new ArrayList<String>();
    values.add("one");
    values.add("two");
    final Map<String, List<String>> props = Collections.singletonMap("test",
        values);
    final SchemaElement e = getElement("", props);
    int i = 0;
    for (final String value : e.getExtraProperty("test"))
    {
      Assert.assertEquals(value, values.get(i));
      i++;
    }
  }
  /**
   * Check that the {@link SchemaElement#getExtraProperty(String)} method
   * returns <code>null</code> when there is no property.
   *
   * @throws Exception
   *           If the test failed unexpectedly.
   */
  @Test
  public final void testGetExtraPropertyDefault() throws Exception
  {
    final SchemaElement e = getElement("", EMPTY_PROPS);
    Assert.assertTrue(e.getExtraProperty("test").isEmpty());
  }
  /**
   * Check that the {@link SchemaElement#getExtraPropertyNames()} method.
   *
   * @throws Exception
   *           If the test failed unexpectedly.
   */
  @Test
  public final void testGetExtraPropertyNames() throws Exception
  {
    final SchemaElement e = getElement("", EMPTY_PROPS);
    Assert.assertTrue(e.getExtraProperty("test").isEmpty());
  }
  /**
   * Check that the hasCode method operator works as expected.
   *
   *
   * @param e1
   *          The first element
   * @param e2
@@ -100,8 +183,8 @@
   *           If the test failed unexpectedly.
   */
  @Test(dataProvider = "equalsTestData")
  public final void testHashCode(SchemaElement e1, SchemaElement e2,
      boolean result) throws Exception
  public final void testHashCode(final SchemaElement e1,
      final SchemaElement e2, final boolean result) throws Exception
  {
    Assert.assertEquals(e1.hashCode() == e2.hashCode(), result);
@@ -109,94 +192,6 @@
  /**
   * Check that the {@link SchemaElement#getDescription()} method
   * returns <code>null</code> when there is no description.
   *
   * @throws Exception
   *           If the test failed unexpectedly.
   */
  @Test
  public final void testGetDescriptionDefault() throws Exception
  {
    SchemaElement e = getElement("", EMPTY_PROPS);
    Assert.assertEquals(e.getDescription(), "");
  }
  /**
   * Check that the {@link SchemaElement#getDescription()} method
   * returns a description.
   *
   * @throws Exception
   *           If the test failed unexpectedly.
   */
  @Test
  public final void testGetDescription() throws Exception
  {
    SchemaElement e = getElement("hello", EMPTY_PROPS);
    Assert.assertEquals(e.getDescription(), "hello");
  }
  /**
   * Check that the {@link SchemaElement#getExtraProperty(String)}
   * method returns <code>null</code> when there is no property.
   *
   * @throws Exception
   *           If the test failed unexpectedly.
   */
  @Test
  public final void testGetExtraPropertyDefault() throws Exception
  {
    SchemaElement e = getElement("", EMPTY_PROPS);
    Assert.assertNull(e.getExtraProperty("test"));
  }
  /**
   * Check that the {@link SchemaElement#getExtraProperty(String)}
   * method returns values.
   *
   * @throws Exception
   *           If the test failed unexpectedly.
   */
  @Test
  public final void testGetExtraProperty() throws Exception
  {
    List<String> values = new ArrayList<String>();
    values.add("one");
    values.add("two");
    Map<String, List<String>> props =
        Collections.singletonMap("test", values);
    SchemaElement e = getElement("", props);
    Assert.assertNotNull(e.getExtraProperty("test"));
    int i = 0;
    for (String value : e.getExtraProperty("test"))
    {
      Assert.assertEquals(value, values.get(i));
      i++;
    }
  }
  /**
   * Check that the {@link SchemaElement#getExtraPropertyNames()}
   * method.
   *
   * @throws Exception
   *           If the test failed unexpectedly.
   */
  @Test
  public final void testGetExtraPropertyNames() throws Exception
  {
    SchemaElement e = getElement("", EMPTY_PROPS);
    Assert.assertNull(e.getExtraProperty("test"));
    Assert.assertFalse(e.getExtraPropertyNames().iterator().hasNext());
  }
  protected abstract SchemaElement getElement(String description,
      Map<String, List<String>> extraProperties) throws SchemaException;
}