use of com.unboundid.ldap.sdk.examples.LDAPSearch in project ldapsdk by pingidentity.
the class InteractiveCommandLineToolTestCase method testLDAPSearchAuthenticatedRootDSESearch.
/**
* Tests the ldapsearch tool to run a full search to retrieve the root DSE.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testLDAPSearchAuthenticatedRootDSESearch() throws Exception {
final InMemoryDirectoryServer ds = getTestDS();
System.setIn(getInputStream(// Server address
"localhost", // Do not attempt to communicate securely.
"5", // Server port
String.valueOf(ds.getListenPort()), // Default to simple authentication.
"", // Bind DN
"cn=Directory Manager", // Bind password
"password", // Empty base DN
"", // First trailing argument
"(objectClass=*)", // Second trailing argument
"*", // Third trailing argument
"+", // No more trailing arguments
"", // Select the scope argument
"3", // Select a baseObject scope.
"1", // Display the command that will be run.
"d", // Return from displaying the command.
"", // Run the tool.
"r"));
final ByteArrayOutputStream out = new ByteArrayOutputStream();
final LDAPSearch tool = new LDAPSearch(out, out);
final ResultCode resultCode = tool.runTool();
assertEquals(resultCode, ResultCode.SUCCESS, "Tool output: " + StaticUtils.toUTF8String(out.toByteArray()));
}
use of com.unboundid.ldap.sdk.examples.LDAPSearch in project ldapsdk by pingidentity.
the class LDAPCommandLineToolTestCase method testPropertiesFilePropertyMissingEquals.
/**
* Tests the behavior with a properties file that has a property line that
* does not include an equal sign to separate the property name from the
* value.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testPropertiesFilePropertyMissingEquals() throws Exception {
final InMemoryDirectoryServer ds = getTestDS();
final File propertiesFile = createTempFile("# The hostname", "hostname=127.0.0.1", "", "# The port", "--port " + ds.getListenPort());
final LDAPSearch ldapSearch = new LDAPSearch(null, null);
final ResultCode rc = ldapSearch.runTool("--propertiesFilePath", propertiesFile.getAbsolutePath(), "--baseDN", "", "(objectClass=*)");
assertFalse(rc == ResultCode.SUCCESS);
}
use of com.unboundid.ldap.sdk.examples.LDAPSearch in project ldapsdk by pingidentity.
the class LDAPCommandLineToolTestCase method testPropertiesFileCommentWithExpectedContinuation.
/**
* Tests the behavior with a properties file that has a comment line when a
* continuation was expected.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testPropertiesFileCommentWithExpectedContinuation() throws Exception {
final InMemoryDirectoryServer ds = getTestDS();
final File propertiesFile = createTempFile("# The hostname", "hostname=\\", "# The port", "port=" + ds.getListenPort());
final LDAPSearch ldapSearch = new LDAPSearch(null, null);
final ResultCode rc = ldapSearch.runTool("--propertiesFilePath", propertiesFile.getAbsolutePath(), "--baseDN", "", "(objectClass=*)");
assertFalse(rc == ResultCode.SUCCESS);
}
use of com.unboundid.ldap.sdk.examples.LDAPSearch in project ldapsdk by pingidentity.
the class LDAPCommandLineToolTestCase method testStartTLS.
/**
* Provides test coverage for StartTLS-based communication.
* <BR><BR>
* Access to an SSL-enabled Directory Server instance is required for complete
* processing.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testStartTLS() throws Exception {
if (!isSSLEnabledDirectoryInstanceAvailable()) {
return;
}
LDAPSearch ldapSearch = new LDAPSearch(null, null);
ResultCode rc = ldapSearch.runTool("-h", getTestHost(), "-p", String.valueOf(getTestPort()), "-q", "-X", "-D", getTestBindDN(), "-w", getTestBindPassword(), "-b", "", "-s", "base", "(objectClass=*)");
assertEquals(rc, ResultCode.SUCCESS);
assertTrue(ldapSearch.anyLDAPArgumentsProvided());
}
use of com.unboundid.ldap.sdk.examples.LDAPSearch in project ldapsdk by pingidentity.
the class LDAPCommandLineToolTestCase method testGetConnectionPool.
/**
* Provides test coverage for the method used to get a connection pool.
* <BR><BR>
* Access to an SSL-enabled Directory Server instance is required for complete
* processing.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testGetConnectionPool() throws Exception {
if (!isSSLEnabledDirectoryInstanceAvailable()) {
return;
}
LDAPSearch ldapSearch = new LDAPSearch(null, null);
ResultCode rc = ldapSearch.runTool("-h", getTestHost(), "-p", String.valueOf(getTestPort()), "-q", "-X", "-D", getTestBindDN(), "-w", getTestBindPassword(), "-b", "", "-s", "base", "(objectClass=*)");
assertEquals(rc, ResultCode.SUCCESS);
LDAPConnectionPool pool = ldapSearch.getConnectionPool(1, 5);
assertNotNull(pool);
assertNotNull(pool.getRootDSE());
LDAPConnection conn = pool.getConnection();
assertNotNull(conn);
assertNotNull(conn.getRootDSE());
LDAPConnection conn2 = pool.getConnection();
assertNotNull(conn2);
assertNotNull(conn2.getRootDSE());
pool.releaseConnection(conn);
pool.releaseConnection(conn2);
pool.close();
assertTrue(ldapSearch.anyLDAPArgumentsProvided());
}
Aggregations