Class EmbeddedOpenDJ

java.lang.Object
org.lsc.opendj.EmbeddedOpenDJ

public final class EmbeddedOpenDJ extends Object
Embedded OpenDJ directory
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    A default value for the working dir
    static final String
    The of the system property that specifies the target working directory, where OpenDJ do its business (db datas, locks, logs, etc)
    static boolean
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    addEntries(String... lines)
    Adds the provided set of entries to the Directory Server using internal operations.
    static void
    addEntries(List<org.opends.server.types.Entry> entries)
    Adds the provided set of entries to the Directory Server using internal operations.
    static org.opends.server.types.ResultCode
    addEntry(org.opends.server.types.Entry entry)
    Adds the provided entry to the Directory Server using an internal operation.
    static List<org.opends.server.types.Entry>
    Returns a modifiable List of entries parsed from the provided LDIF.
    static org.opends.server.types.Entry
    This is used as a convenience when and LDIF string only includes a single entry.
    static String
    Search for a file in the possible configuration locations: As a resource on the classpath (historical method) As a file in the configuration directory
    static void
     
    static void
    initializeTestBackend(boolean createBaseEntry, String dn)
     
    static void
    main(String[] args)
    Test main class
    static List<org.opends.server.types.Entry>
    makeEntries(String... lines)
    This is a convience method that constructs an List of EntryS from the specified lines of LDIF.
    static org.opends.server.types.Entry
    makeEntry(String... lines)
    This is a convience method that constructs an Entry from the specified lines of LDIF.
    static String
    makeLdif(String... lines)
    This method provides the minor convenience of not having to specify the newline character at the end of every line of LDIF in test code.
    static void
    Sets the system context root to null.
    static void
    Initialize the server.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • PROPERTY_WORKING_DIR

      public static final String PROPERTY_WORKING_DIR
      The of the system property that specifies the target working directory, where OpenDJ do its business (db datas, locks, logs, etc)
      See Also:
    • DEFAULT_WORKING_DIR_NAME

      public static final String DEFAULT_WORKING_DIR_NAME
      A default value for the working dir
      See Also:
    • SERVER_STARTED

      public static boolean SERVER_STARTED
  • Method Details

    • startServer

      public static void startServer() throws IOException, org.opends.server.types.InitializationException, URISyntaxException
      Initialize the server. We completely override the super class server set up.
      Throws:
      IOException
      org.opends.server.types.InitializationException
      URISyntaxException
    • shutdownServer

      public static void shutdownServer(String reason)
      Sets the system context root to null.
      Parameters:
      reason - Message to log when shutting down
    • main

      public static void main(String[] args)
      Test main class
      Parameters:
      args -
    • entriesFromLdifString

      public static List<org.opends.server.types.Entry> entriesFromLdifString(String ldif) throws IOException, org.opends.server.util.LDIFException
      Returns a modifiable List of entries parsed from the provided LDIF. It's best to call this after the server has been initialized so that schema checking happens.

      Also take a look at the makeLdif method below since this makes expressing LDIF a little bit cleaner.

      Parameters:
      ldif - of the entries to parse.
      Returns:
      a List of EntryS parsed from the ldif string.
      Throws:
      IOException
      org.opends.server.util.LDIFException
      See Also:
    • entryFromLdifString

      public static org.opends.server.types.Entry entryFromLdifString(String ldif) throws Exception
      This is used as a convenience when and LDIF string only includes a single entry. It's best to call this after the server has been initialized so that schema checking happens.

      Also take a look at the makeLdif method below since this makes expressing LDIF a little bit cleaner.

      Parameters:
      ldif - Line of LDIF
      Returns:
      the first Entry parsed from the ldif String
      Throws:
      Exception - If an unexpected problem occurs.
      See Also:
    • makeLdif

      public static String makeLdif(String... lines)
      This method provides the minor convenience of not having to specify the newline character at the end of every line of LDIF in test code. This is an admittedly small advantage, but it does make things a little easier and less error prone. For example, this
       private static final String JOHN_SMITH_LDIF = TestCaseUtils.makeLdif("dn: cn=John Smith,dc=example,dc=com",
                      "objectclass: inetorgperson", "cn: John Smith", "sn: Smith", "givenname: John");
       
       
      is a little easier to work with than
       private static final String JOHN_SMITH_LDIF = "dn: cn=John Smith,dc=example,dc=com\n" + "objectclass: inetorgperson\n"
                      + "cn: John Smith\n" + "sn: Smith\n" + "givenname: John\n";
       
       
      Parameters:
      lines - Lines of LDIF without newline characters
      Returns:
      the concatenation of each line followed by a newline character
    • makeEntry

      public static org.opends.server.types.Entry makeEntry(String... lines) throws Exception
      This is a convience method that constructs an Entry from the specified lines of LDIF. Here's a sample usage
       Entry john = TestCaseUtils.makeEntry("dn: cn=John Smith,dc=example,dc=com", "objectclass: inetorgperson",
                      "cn: John Smith", "sn: Smith", "givenname: John");
       
      Parameters:
      lines - Lines of LDIF
      Returns:
      Entry constructed from the specified lines of LDIF
      Throws:
      Exception
      See Also:
    • makeEntries

      public static List<org.opends.server.types.Entry> makeEntries(String... lines) throws org.opends.server.util.LDIFException, IOException
      This is a convience method that constructs an List of EntryS from the specified lines of LDIF. Here's a sample usage
       List<Entry> smiths = TestCaseUtils.makeEntries("dn: cn=John Smith,dc=example,dc=com", "objectclass: inetorgperson",
                      "cn: John Smith", "sn: Smith", "givenname: John", "", "dn: cn=Jane Smith,dc=example,dc=com",
                      "objectclass: inetorgperson", "cn: Jane Smith", "sn: Smith", "givenname: Jane");
       
      Parameters:
      lines - Lines of LDIF
      Returns:
      List of EntryS constructed from the specified lines of LDIF
      Throws:
      IOException
      org.opends.server.util.LDIFException
      See Also:
    • addEntry

      public static org.opends.server.types.ResultCode addEntry(org.opends.server.types.Entry entry)
      Adds the provided entry to the Directory Server using an internal operation.
      Parameters:
      entry - The entry to be added.
      Returns:
      the error code
    • addEntries

      public static void addEntries(List<org.opends.server.types.Entry> entries)
      Adds the provided set of entries to the Directory Server using internal operations.
      Parameters:
      entries - The entries to be added.
    • addEntries

      public static void addEntries(String... lines) throws org.opends.server.util.LDIFException, IOException
      Adds the provided set of entries to the Directory Server using internal operations.
      Parameters:
      lines - The lines defining the entries to add. If there are multiple entries, then they should be separated by blank lines.
      Throws:
      IOException
      org.opends.server.util.LDIFException
    • initializeTestBackend

      public static void initializeTestBackend(boolean createBaseEntry, String dn) throws Exception
      Throws:
      Exception
    • importLdif

      public static void importLdif(String ldif) throws IOException, org.opends.server.util.LDIFException
      Throws:
      IOException
      org.opends.server.util.LDIFException
    • getPathToConfigFile

      public static String getPathToConfigFile(String fileName)

      Search for a file in the possible configuration locations:

      • As a resource on the classpath (historical method)
      • As a file in the configuration directory

      This method first looks on the classpath, then if that fails, looks in the configuration directory. Finally, it returns the absolute path name to the file.

      .
      Parameters:
      fileName - Name of the file or directory to locate.
      Returns:
      Absolute path name to the file, or null.