All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.trevershick.test.ldap.junit4.LdapServerRule Maven / Gradle / Ivy

Go to download

Client library that makes it easy to test with an embedded LDAP server (from unboundid).

There is a newer version: 2.0.1
Show newest version
package com.github.trevershick.test.ldap.junit4;

import org.junit.rules.TestRule;
import org.junit.runner.Description;
import org.junit.runners.model.Statement;

import com.github.trevershick.test.ldap.LdapServerResource;

public class LdapServerRule implements TestRule {
	private LdapServerResource ldapServer;

	private Object target;
	
	public LdapServerRule() {
		
	}
	public LdapServerRule(Object target) {
		this.target = target;
	}
	
	public Statement apply(final Statement base, Description description) {
		return new Statement() {
			@Override
			public void evaluate() throws Throwable {
				ldapServer = new LdapServerResource(target);
				try {
					ldapServer.start();
					base.evaluate();
				} finally {
					if (ldapServer.isStarted()) {
						ldapServer.stop();
					}
				}
				ldapServer = null;
			}
		};
	}
	public int port() {
		return ldapServer.port();
	}
	public boolean serverIsStarted() {
		return ldapServer != null && ldapServer.isStarted();
	}
	public boolean serverIsStopped() {
		return ldapServer != null && ldapServer.isStopped();
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy