Search in sources :

Example 26 with TestLogHandler

use of com.unboundid.util.TestLogHandler in project ldapsdk by pingidentity.

the class ReadOnlyInMemoryDirectoryServerConfigTestCase method testExtensiveConfig.

/**
 * Provides a set of tests with a more extensive configuration.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testExtensiveConfig() throws Exception {
    final InMemoryDirectoryServerConfig config = new InMemoryDirectoryServerConfig("dc=example,dc=com", "o=example.com");
    config.setAllowedOperationTypes(OperationType.BIND, OperationType.COMPARE, OperationType.SEARCH);
    config.setAuthenticationRequiredOperationTypes(OperationType.ADD, OperationType.DELETE, OperationType.MODIFY, OperationType.MODIFY_DN);
    config.addAdditionalBindCredentials("cn=Directory Manager", "password");
    config.setListenerExceptionHandler(new TestLDAPListenerExceptionHandler());
    config.setSchema(Schema.getDefaultStandardSchema());
    config.setEnforceAttributeSyntaxCompliance(false);
    config.setEnforceSingleStructuralObjectClass(false);
    config.setAccessLogHandler(new TestLogHandler());
    config.setLDAPDebugLogHandler(new TestLogHandler());
    config.addExtendedOperationHandler(new TestExtendedOperationHandler());
    config.addSASLBindHandler(new TestSASLBindHandler());
    config.setGenerateOperationalAttributes(false);
    config.setMaxChangeLogEntries(100);
    config.setEqualityIndexAttributes("uid", "cn");
    config.setReferentialIntegrityAttributes("member", "uniqueMember", "owner", "seeAlso");
    ReadOnlyInMemoryDirectoryServerConfig readOnlyConfig = new ReadOnlyInMemoryDirectoryServerConfig(config);
    // Make sure that it is possible to create a directory server instance using
    // the read-only configuration, and get the read-only configuration from it.
    final InMemoryDirectoryServer ds = new InMemoryDirectoryServer(readOnlyConfig);
    assertNotNull(ds);
    readOnlyConfig = ds.getConfig();
    // Test methods related to the set of base DNs.
    assertNotNull(readOnlyConfig.getBaseDNs());
    assertEquals(readOnlyConfig.getBaseDNs().length, 2);
    assertEquals(readOnlyConfig.getBaseDNs()[0], new DN("dc=example,dc=com"));
    assertEquals(readOnlyConfig.getBaseDNs()[1], new DN("o=example.com"));
    try {
        readOnlyConfig.setBaseDNs("c=US");
        fail("Expected an exception when trying to call setBaseDNs");
    } catch (final UnsupportedOperationException e) {
    // This was expected.
    }
    try {
        readOnlyConfig.setBaseDNs(new DN("c=US"));
        fail("Expected an exception when trying to call setBaseDNs");
    } catch (final UnsupportedOperationException e) {
    // This was expected.
    }
    // Test methods related to the set of allowed operation types.
    assertNotNull(readOnlyConfig.getAllowedOperationTypes());
    assertEquals(readOnlyConfig.getAllowedOperationTypes(), EnumSet.of(OperationType.BIND, OperationType.COMPARE, OperationType.SEARCH));
    try {
        readOnlyConfig.getAllowedOperationTypes().add(OperationType.ADD);
        fail("Expected an exception when trying to alter the set returned by " + "getAllowedOperationTypes");
    } catch (final UnsupportedOperationException e) {
    // This was expected.
    }
    try {
        readOnlyConfig.setAllowedOperationTypes(OperationType.BIND, OperationType.COMPARE, OperationType.SEARCH);
        fail("Expected an exception when trying to call " + "setAllowedOperationTypes");
    } catch (final UnsupportedOperationException e) {
    // This was expected.
    }
    try {
        readOnlyConfig.setAllowedOperationTypes(EnumSet.of(OperationType.BIND, OperationType.COMPARE, OperationType.SEARCH));
        fail("Expected an exception when trying to call " + "setAllowedOperationTypes");
    } catch (final UnsupportedOperationException e) {
    // This was expected.
    }
    // Test methods related to the set of authentication required operation
    // types.
    assertNotNull(readOnlyConfig.getAuthenticationRequiredOperationTypes());
    assertEquals(readOnlyConfig.getAuthenticationRequiredOperationTypes(), EnumSet.of(OperationType.ADD, OperationType.DELETE, OperationType.MODIFY, OperationType.MODIFY_DN));
    try {
        readOnlyConfig.getAuthenticationRequiredOperationTypes().add(OperationType.ADD);
        fail("Expected an exception when trying to alter the set returned by " + "getAuthenticationRequiredOperationTypes");
    } catch (final UnsupportedOperationException e) {
    // This was expected.
    }
    try {
        readOnlyConfig.setAuthenticationRequiredOperationTypes(OperationType.ADD, OperationType.DELETE, OperationType.MODIFY, OperationType.MODIFY_DN);
        fail("Expected an exception when trying to call " + "setAuthenticationRequiredOperationTypes");
    } catch (final UnsupportedOperationException e) {
    // This was expected.
    }
    try {
        readOnlyConfig.setAuthenticationRequiredOperationTypes(EnumSet.of(OperationType.ADD, OperationType.DELETE, OperationType.MODIFY, OperationType.MODIFY_DN));
        fail("Expected an exception when trying to call " + "setAuthenticationRequiredOperationTypes");
    } catch (final UnsupportedOperationException e) {
    // This was expected.
    }
    // Test methods related to the additional bind credentials.
    assertNotNull(readOnlyConfig.getAdditionalBindCredentials());
    assertFalse(readOnlyConfig.getAdditionalBindCredentials().isEmpty());
    try {
        readOnlyConfig.getAdditionalBindCredentials().put(new DN("cn=Directory Manager 2"), "password".getBytes("UTF-8"));
        fail("Expected an exception when trying to alter the map returned by " + "getAdditionalBindCredentials");
    } catch (final UnsupportedOperationException e) {
    // This was expected.
    }
    try {
        readOnlyConfig.addAdditionalBindCredentials("cn=Directory Manager 2", "password");
        fail("Expected an exception when trying to call " + "addAdditionalBindCredentials");
    } catch (final UnsupportedOperationException e) {
    // This was expected.
    }
    try {
        readOnlyConfig.addAdditionalBindCredentials("cn=Directory Manager 2", "password".getBytes("UTF-8"));
        fail("Expected an exception when trying to call " + "addAdditionalBindCredentials");
    } catch (final UnsupportedOperationException e) {
    // This was expected.
    }
    // Test methods related to the listener configs.
    assertNotNull(readOnlyConfig.getListenerConfigs());
    assertFalse(readOnlyConfig.getListenerConfigs().isEmpty());
    try {
        readOnlyConfig.getListenerConfigs().clear();
        fail("Expected an exception when trying to call " + "getListenerConfigs.clear");
    } catch (final UnsupportedOperationException e) {
    // This was expected.
    }
    try {
        readOnlyConfig.setListenerConfigs(InMemoryListenerConfig.createLDAPConfig("LDAP"));
        fail("Expected an exception when trying to call setListenerConfigs");
    } catch (final UnsupportedOperationException e) {
    // This was expected.
    }
    try {
        readOnlyConfig.setListenerConfigs(Arrays.asList(InMemoryListenerConfig.createLDAPConfig("LDAP")));
        fail("Expected an exception when trying to call setListenerConfigs");
    } catch (final UnsupportedOperationException e) {
    // This was expected.
    }
    // Test methods related to the exception handler.
    assertNotNull(readOnlyConfig.getListenerExceptionHandler());
    try {
        readOnlyConfig.setListenerExceptionHandler(null);
        fail("Expected an exception when trying to call " + "setListenerExceptionHandler");
    } catch (final UnsupportedOperationException e) {
    // This was expected.
    }
    // Test methods related to the schema.
    assertNotNull(readOnlyConfig.getSchema());
    try {
        readOnlyConfig.setSchema(null);
        fail("Expected an exception when trying to call setSchema");
    } catch (final UnsupportedOperationException e) {
    // This was expected.
    }
    // Test methods related to attribute syntax enforcement.
    assertFalse(readOnlyConfig.enforceAttributeSyntaxCompliance());
    try {
        readOnlyConfig.setEnforceAttributeSyntaxCompliance(true);
        fail("Expected an exception when trying to call " + "setEnforceAttributeSyntaxCompliance");
    } catch (final UnsupportedOperationException e) {
    // This was expected.
    }
    // Test methods related to single structural object class enforcement.
    assertFalse(readOnlyConfig.enforceSingleStructuralObjectClass());
    try {
        readOnlyConfig.setEnforceSingleStructuralObjectClass(true);
        fail("Expected an exception when trying to call " + "setEnforceSingleStructuralObjectClass");
    } catch (final UnsupportedOperationException e) {
    // This was expected.
    }
    // Test methods related to the access log handler.
    assertNotNull(readOnlyConfig.getAccessLogHandler());
    try {
        readOnlyConfig.setAccessLogHandler(null);
        fail("Expected an exception when trying to call setAccessLogHandler");
    } catch (final UnsupportedOperationException e) {
    // This was expected.
    }
    // Test methods related to the LDAP debug log handler.
    assertNotNull(readOnlyConfig.getLDAPDebugLogHandler());
    try {
        readOnlyConfig.setLDAPDebugLogHandler(null);
        fail("Expected an exception when trying to call setLDAPDebugLogHandler");
    } catch (final UnsupportedOperationException e) {
    // This was expected.
    }
    // Test methods related to the extended operation handlers.
    assertNotNull(readOnlyConfig.getExtendedOperationHandlers());
    assertFalse(readOnlyConfig.getExtendedOperationHandlers().isEmpty());
    try {
        readOnlyConfig.getExtendedOperationHandlers().add(new TestExtendedOperationHandler());
        fail("Expected an exception when trying to alter the list returned by " + "getExtendedOperationHandlers");
    } catch (final UnsupportedOperationException e) {
    // This was expected.
    }
    try {
        readOnlyConfig.addExtendedOperationHandler(new TestExtendedOperationHandler());
        fail("Expected an exception when trying to call " + "addExtendedOperationHandler");
    } catch (final UnsupportedOperationException e) {
    // This was expected.
    }
    // Test methods related to the SASL bind handlers.
    assertNotNull(readOnlyConfig.getSASLBindHandlers());
    assertFalse(readOnlyConfig.getSASLBindHandlers().isEmpty());
    try {
        readOnlyConfig.getSASLBindHandlers().add(new TestSASLBindHandler());
        fail("Expected an exception when trying to alter the list returned by " + "getSASLBindHandlers");
    } catch (final UnsupportedOperationException e) {
    // This was expected.
    }
    try {
        readOnlyConfig.addSASLBindHandler(new TestSASLBindHandler());
        fail("Expected an exception when trying to call addSASLBindHandler");
    } catch (final UnsupportedOperationException e) {
    // This was expected.
    }
    // Test methods related to the generation of operational attributes.
    assertFalse(readOnlyConfig.generateOperationalAttributes());
    try {
        readOnlyConfig.setGenerateOperationalAttributes(true);
        fail("Expected an exception when trying to call " + "setGenerateOperationalAttributes");
    } catch (final UnsupportedOperationException e) {
    // This was expected.
    }
    // Test methods related to changelog entries.
    assertEquals(readOnlyConfig.getMaxChangeLogEntries(), 100);
    try {
        readOnlyConfig.setMaxChangeLogEntries(0);
        fail("Expected an exception when trying to call " + "setMaxChangeLogEntries");
    } catch (final UnsupportedOperationException e) {
    // This was expected.
    }
    // Test methods related to equality index attributes.
    assertNotNull(readOnlyConfig.getEqualityIndexAttributes());
    assertFalse(readOnlyConfig.getEqualityIndexAttributes().isEmpty());
    assertEquals(readOnlyConfig.getEqualityIndexAttributes().size(), 2);
    assertTrue(readOnlyConfig.getEqualityIndexAttributes().contains("uid"));
    assertTrue(readOnlyConfig.getEqualityIndexAttributes().contains("cn"));
    // Test methods related to referential integrity attributes.
    assertNotNull(readOnlyConfig.getReferentialIntegrityAttributes());
    assertFalse(readOnlyConfig.getReferentialIntegrityAttributes().isEmpty());
    assertEquals(readOnlyConfig.getReferentialIntegrityAttributes().size(), 4);
    assertTrue(readOnlyConfig.getReferentialIntegrityAttributes().contains("member"));
    assertTrue(readOnlyConfig.getReferentialIntegrityAttributes().contains("uniqueMember"));
    assertTrue(readOnlyConfig.getReferentialIntegrityAttributes().contains("owner"));
    assertTrue(readOnlyConfig.getReferentialIntegrityAttributes().contains("seeAlso"));
    try {
        readOnlyConfig.setReferentialIntegrityAttributes("member");
        fail("Expected an exception when trying to call " + "setReferentialIntegrityAttributes");
    } catch (final UnsupportedOperationException e) {
    // This was expected
    }
    try {
        readOnlyConfig.setReferentialIntegrityAttributes(Arrays.asList("member", "uniqueMember", "owner", "seeAlso"));
        fail("Expected an exception when trying to call " + "setReferentialIntegrityAttributes");
    } catch (final UnsupportedOperationException e) {
    // This was expected
    }
    // Test the toString method.
    assertNotNull(readOnlyConfig.toString());
}
Also used : TestLogHandler(com.unboundid.util.TestLogHandler) DN(com.unboundid.ldap.sdk.DN) Test(org.testng.annotations.Test)

Aggregations

TestLogHandler (com.unboundid.util.TestLogHandler)26 Test (org.testng.annotations.Test)26 InMemoryDirectoryServer (com.unboundid.ldap.listener.InMemoryDirectoryServer)21 JSONObject (com.unboundid.util.json.JSONObject)21 ASN1OctetString (com.unboundid.asn1.ASN1OctetString)6 DN (com.unboundid.ldap.sdk.DN)2 ASN1BitString (com.unboundid.asn1.ASN1BitString)1 ASN1UTF8String (com.unboundid.asn1.ASN1UTF8String)1 InMemoryDirectoryServerConfig (com.unboundid.ldap.listener.InMemoryDirectoryServerConfig)1 TestIntermediateResponseExtendedOperationHandler (com.unboundid.ldap.listener.TestIntermediateResponseExtendedOperationHandler)1 OperationType (com.unboundid.ldap.sdk.OperationType)1 DebugType (com.unboundid.util.DebugType)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 KeyStore (java.security.KeyStore)1 Certificate (java.security.cert.Certificate)1 Level (java.util.logging.Level)1 Logger (java.util.logging.Logger)1