I am writing integration tests for my API. I have to test flow that's why I implemented in-memory ldap. I have used InMemoryDirectoryServer which return LDAPConnection object for in memory operations. But in my LDAPService I have written function getLdapConnection which returns LDAPConnection, this function is being used for LDAP operations.
so how do I pass in-memory LDAPConnection object to my LDAPServices so each operation will take in-memory LDAPConnection object for integration testing?
I have tried creating setter method for autowired LDAPConnection object.
//Test class
public class LdapInMem
{
InMemoryDirectoryServer server;
public LDAPConnection startInMemLdapServer() throws UnknownHostException
{
//some in memory listener config
return ldapConnection;
}
}
@Service
@Repository
public class LDAPService
{
@Autowired
private LDAPServerConfig ldapServerConfig;
private LDAPConnection ldapConnection;
public LDAPConnection getLDAPConnection()
{
//some server config from ldapServerConfig
return ldapConnection;
}
public function()
{
con = getLDAPConnection();
con.do_ldap_stuff
}
public function1()
{
con = getLDAPConnection();
con.do_ldap_stuff1
}
}
//LDAP service
public void setLdapConnection(LDAPConnection ldapConnection)
{
this.ldapConnection = ldapConnection;
}
how can my testcases set ldapConnection object of LDAPService from in-memory setup while testing and normally from LDAPService while running app? So I can test my function and function1 in the flow. I expect my API to use in-memory LDAPConnection object for every LDAP operation to test integration flow.