如何使用嵌入式/ inMemory ldap在Spring Boot中测试API

时间:2019-07-18 11:29:10

标签: rest spring-boot integration-testing in-memory unboundid-ldap-sdk

我创建了一个与ldap和postgresql交互以进行数据访问的API。 现在,当我为控制器方法编写集成测试时,我找不到任何使编译器意识到何时在内存/嵌入式ldap中进行测试的方法。

我尝试编写其他inMemory配置和.properties文件进行测试。

@Configuration
@PropertySource("classpath:application.properties")

public class InMemoryLdapConfig {


    InMemoryDirectoryServer server;

    public LDAPConnection getInMemoryConnection() throws LDAPException, LDIFException, IOException {
        InMemoryDirectoryServerConfig config = new InMemoryDirectoryServerConfig("dc=maxcrc,dc=com");
        config.addAdditionalBindCredentials("cn=manager", "secret");
        config.setSchema(Schema.getSchema(".\\LDAPResources\\addObjectClass.ldif"));
        //config.setSchema(Schema.getSchema(".\\LDAPResources\\schema.ldif"));
        InetAddress host = null;
        host = Inet4Address.getLoopbackAddress();
        config.setListenerConfigs(InMemoryListenerConfig.createLDAPConfig("Ldap"));//("Ldap", host, 10389, null))

        server = new InMemoryDirectoryServer(config);
    //  server.importFromLDIF(true, ".\\LDAPResources\\addObjectClass.ldif");
        server.importFromLDIF(true,".\\LDAPResources\\userTest.ldif");
        server.startListening();
        LDAPConnection con = server.getConnection();        
        return con;

    }```

Instead of writing different in memory configuration file it goes to actual ldap and retrieve data from there. how to make compiler know that use in memory ldap for test.

0 个答案:

没有答案