@CreateTransport( protocol = "LDAPS" )
})
public void testCreateLdapServer() throws Exception
{
// First, get the service
DirectoryService service = DSAnnotationProcessor.getDirectoryService();
// Check that the service is running
assertTrue( service.isStarted() );
assertEquals( "MethodDSWithPartitionAndServer", service.getInstanceId() );
Set<String> expectedNames = new HashSet<String>();
expectedNames.add( "example" );
expectedNames.add( "schema" );
assertEquals( 2, service.getPartitions().size() );
for ( Partition partition : service.getPartitions() )
{
assertTrue( expectedNames.contains( partition.getId() ) );
if ( "example".equalsIgnoreCase( partition.getId() ) )
{
assertTrue( partition.isInitialized() );
assertEquals( "dc=example,dc=com", partition.getSuffixDn().getName() );
}
else if ( "schema".equalsIgnoreCase( partition.getId() ) )
{
assertTrue( partition.isInitialized() );
assertEquals( "ou=schema", partition.getSuffixDn().getName() );
}
}
assertTrue( service.getAdminSession().exists( new Dn( "dc=example,dc=com" ) ) );
// Now, get the server
LdapServer ldapServer = ServerAnnotationProcessor.getLdapServer( service );
// Check that the server is running
assertTrue( ldapServer.isStarted() );
// Try to read an entry in the server
LdapContext ctx = ( LdapContext ) getWiredContext( ldapServer, null ).lookup( "dc=example,dc=com" );
SearchControls controls = new SearchControls();
controls.setSearchScope( SearchControls.OBJECT_SCOPE );
controls.setReturningAttributes( new String[]{"*"} );
NamingEnumeration<SearchResult> enumeration = ctx.search( "", "(objectClass=*)", controls );
// collect all results
HashSet<String> results = new HashSet<String>();
while ( enumeration.hasMore() )
{
SearchResult result = enumeration.next();
results.add( result.getNameInNamespace() );
}
assertEquals( 1, results.size() );
assertTrue( results.contains( "dc=example,dc=com" ) );
enumeration.close();
ctx.close();
ldapServer.stop();
service.shutdown();
FileUtils.deleteDirectory( service.getInstanceLayout().getInstanceDirectory() );
}