cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aprat...@apache.org
Subject [3/7] git commit: updated refs/heads/ldapplugin to 25e8e9b
Date Fri, 02 Aug 2013 10:42:15 GMT
General cleanup, source formatting, remove whitespace

Signed-off-by: Abhinandan Prateek <aprateek@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/25e8e9b8
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/25e8e9b8
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/25e8e9b8

Branch: refs/heads/ldapplugin
Commit: 25e8e9b85fa95a83634f12fd93a319df6d026718
Parents: 00c17ad
Author: Ian Duffy <ian@ianduffy.ie>
Authored: Fri Aug 2 09:28:48 2013 +0100
Committer: Abhinandan Prateek <aprateek@apache.org>
Committed: Fri Aug 2 14:20:47 2013 +0530

----------------------------------------------------------------------
 .../api/command/LdapCreateAccount.java          |  16 +-
 .../api/command/LdapListAllUsersCmd.java        |   3 +-
 .../api/command/LdapListConfigurationCmd.java   |   2 +-
 .../api/command/LdapUserSearchCmd.java          |   3 +-
 .../cloudstack/ldap/LdapAuthenticator.java      |   9 +-
 .../cloudstack/ldap/LdapConfiguration.java      |   8 +-
 .../cloudstack/ldap/LdapConfigurationVO.java    |   2 +-
 .../cloudstack/ldap/LdapContextFactory.java     |  41 +-
 .../org/apache/cloudstack/ldap/LdapManager.java |   2 +
 .../apache/cloudstack/ldap/LdapUserManager.java |  47 +-
 .../org/apache/cloudstack/ldap/LdapUtils.java   |   2 +-
 .../ldap/BasicNamingEnumerationImpl.groovy      |  32 +-
 .../ldap/LdapAddConfigurationCmdSpec.groovy     |  87 ++--
 .../ldap/LdapAuthenticatorSpec.groovy           |  95 ++--
 .../ldap/LdapConfigurationDaoImplSpec.groovy    |   5 +-
 .../ldap/LdapConfigurationResponseSpec.groovy   |  35 +-
 .../ldap/LdapConfigurationSpec.groovy           | 226 +++++----
 .../ldap/LdapConfigurationVOSpec.groovy         |  23 +-
 .../ldap/LdapContextFactorySpec.groovy          | 108 ++---
 .../ldap/LdapCreateAccountCmdSpec.groovy        | 172 +++----
 .../ldap/LdapDeleteConfigurationCmdSpec.groovy  |  51 +-
 .../ldap/LdapListAllUsersCmdSpec.groovy         |  62 ++-
 .../ldap/LdapListConfigurationCmdSpec.groovy    | 101 ++--
 .../cloudstack/ldap/LdapManagerImplSpec.groovy  | 476 ++++++++++---------
 .../ldap/LdapSearchUserCmdSpec.groovy           |  28 +-
 .../cloudstack/ldap/LdapUserManagerSpec.groovy  | 196 ++++----
 .../cloudstack/ldap/LdapUserResponseSpec.groovy |  61 ++-
 .../apache/cloudstack/ldap/LdapUserSpec.groovy  |  69 ++-
 .../apache/cloudstack/ldap/LdapUtilsSpec.groovy |  36 +-
 .../NoLdapUserMatchingQueryExceptionSpec.groovy |   1 -
 .../ldap/NoSuchLdapUserExceptionSpec.groovy     |   1 -
 server/src/com/cloud/configuration/Config.java  |  13 +-
 setup/db/db/schema-410to420.sql                 |  83 ++--
 ui/dictionary.jsp                               |   2 +-
 ui/scripts/autoscaler.js                        |   2 +-
 ui/scripts/sharedFunctions.js                   |   2 +-
 ui/scripts/system.js                            |  64 +--
 ui/scripts/ui-custom/accountsWizard.js          |   2 +-
 ui/scripts/ui-custom/installWizard.js           |   7 +-
 ui/scripts/ui/dialog.js                         |  56 +--
 ui/scripts/ui/widgets/listView.js               |  10 +-
 ui/scripts/ui/widgets/multiEdit.js              |   4 +-
 ui/scripts/zoneWizard.js                        |  69 +--
 43 files changed, 1151 insertions(+), 1163 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/25e8e9b8/plugins/user-authenticators/ldap/src/org/apache/cloudstack/api/command/LdapCreateAccount.java
----------------------------------------------------------------------
diff --git a/plugins/user-authenticators/ldap/src/org/apache/cloudstack/api/command/LdapCreateAccount.java b/plugins/user-authenticators/ldap/src/org/apache/cloudstack/api/command/LdapCreateAccount.java
index 47e5bf4..87944b0 100644
--- a/plugins/user-authenticators/ldap/src/org/apache/cloudstack/api/command/LdapCreateAccount.java
+++ b/plugins/user-authenticators/ldap/src/org/apache/cloudstack/api/command/LdapCreateAccount.java
@@ -92,15 +92,15 @@ public class LdapCreateAccount extends BaseCmd {
 	public void execute() throws ServerApiException {
 		updateCallContext();
 		try {
-			LdapUser user = _ldapManager.getUser(username);
+			final LdapUser user = _ldapManager.getUser(username);
 			validateUser(user);
-			UserAccount userAccount = _accountService.createUserAccount(
+			final UserAccount userAccount = _accountService.createUserAccount(
 					username, generatePassword(), user.getFirstname(),
 					user.getLastname(), user.getEmail(), timezone, accountName,
 					accountType, domainId, networkDomain, details, accountUUID,
 					userUUID);
 			if (userAccount != null) {
-				AccountResponse response = _responseGenerator
+				final AccountResponse response = _responseGenerator
 						.createUserAccountResponse(userAccount);
 				response.setResponseName(getCommandName());
 				setResponseObject(response);
@@ -108,7 +108,7 @@ public class LdapCreateAccount extends BaseCmd {
 				throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR,
 						"Failed to create a user account");
 			}
-		} catch (NamingException e) {
+		} catch (final NamingException e) {
 			throw new ServerApiException(
 					ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR,
 					"No LDAP user exists with the username of " + username);
@@ -117,11 +117,11 @@ public class LdapCreateAccount extends BaseCmd {
 
 	private String generatePassword() throws ServerApiException {
 		try {
-			SecureRandom randomGen = SecureRandom.getInstance("SHA1PRNG");
-			byte bytes[] = new byte[20];
+			final SecureRandom randomGen = SecureRandom.getInstance("SHA1PRNG");
+			final byte bytes[] = new byte[20];
 			randomGen.nextBytes(bytes);
 			return Base64.encode(bytes).toString();
-		} catch (NoSuchAlgorithmException e) {
+		} catch (final NoSuchAlgorithmException e) {
 			throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR,
 					"Failed to generate random password");
 		}
@@ -142,7 +142,7 @@ public class LdapCreateAccount extends BaseCmd {
 				"Account Name: " + accountName + ", Domain Id:" + domainId);
 	}
 
-	private boolean validateUser(LdapUser user) throws ServerApiException {
+	private boolean validateUser(final LdapUser user) throws ServerApiException {
 		if (user.getEmail() == null) {
 			throw new ServerApiException(
 					ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, username

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/25e8e9b8/plugins/user-authenticators/ldap/src/org/apache/cloudstack/api/command/LdapListAllUsersCmd.java
----------------------------------------------------------------------
diff --git a/plugins/user-authenticators/ldap/src/org/apache/cloudstack/api/command/LdapListAllUsersCmd.java b/plugins/user-authenticators/ldap/src/org/apache/cloudstack/api/command/LdapListAllUsersCmd.java
index c5cecc7..c371cff 100644
--- a/plugins/user-authenticators/ldap/src/org/apache/cloudstack/api/command/LdapListAllUsersCmd.java
+++ b/plugins/user-authenticators/ldap/src/org/apache/cloudstack/api/command/LdapListAllUsersCmd.java
@@ -51,7 +51,8 @@ public class LdapListAllUsersCmd extends BaseListCmd {
 		_ldapManager = ldapManager;
 	}
 
-	private List<LdapUserResponse> createLdapUserResponse(List<LdapUser> users) {
+	private List<LdapUserResponse> createLdapUserResponse(
+			final List<LdapUser> users) {
 		final List<LdapUserResponse> ldapResponses = new ArrayList<LdapUserResponse>();
 		for (final LdapUser user : users) {
 			final LdapUserResponse ldapResponse = _ldapManager

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/25e8e9b8/plugins/user-authenticators/ldap/src/org/apache/cloudstack/api/command/LdapListConfigurationCmd.java
----------------------------------------------------------------------
diff --git a/plugins/user-authenticators/ldap/src/org/apache/cloudstack/api/command/LdapListConfigurationCmd.java b/plugins/user-authenticators/ldap/src/org/apache/cloudstack/api/command/LdapListConfigurationCmd.java
index 7abfefe..3d9323d 100644
--- a/plugins/user-authenticators/ldap/src/org/apache/cloudstack/api/command/LdapListConfigurationCmd.java
+++ b/plugins/user-authenticators/ldap/src/org/apache/cloudstack/api/command/LdapListConfigurationCmd.java
@@ -59,7 +59,7 @@ public class LdapListConfigurationCmd extends BaseListCmd {
 	}
 
 	private List<LdapConfigurationResponse> createLdapConfigurationResponses(
-			List<? extends LdapConfigurationVO> configurations) {
+			final List<? extends LdapConfigurationVO> configurations) {
 		final List<LdapConfigurationResponse> responses = new ArrayList<LdapConfigurationResponse>();
 		for (final LdapConfigurationVO resource : configurations) {
 			final LdapConfigurationResponse configurationResponse = _ldapManager

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/25e8e9b8/plugins/user-authenticators/ldap/src/org/apache/cloudstack/api/command/LdapUserSearchCmd.java
----------------------------------------------------------------------
diff --git a/plugins/user-authenticators/ldap/src/org/apache/cloudstack/api/command/LdapUserSearchCmd.java b/plugins/user-authenticators/ldap/src/org/apache/cloudstack/api/command/LdapUserSearchCmd.java
index 7359882..e72371c 100644
--- a/plugins/user-authenticators/ldap/src/org/apache/cloudstack/api/command/LdapUserSearchCmd.java
+++ b/plugins/user-authenticators/ldap/src/org/apache/cloudstack/api/command/LdapUserSearchCmd.java
@@ -54,7 +54,8 @@ public class LdapUserSearchCmd extends BaseListCmd {
 		_ldapManager = ldapManager;
 	}
 
-	private List<LdapUserResponse> createLdapUserResponse(List<LdapUser> users) {
+	private List<LdapUserResponse> createLdapUserResponse(
+			final List<LdapUser> users) {
 		final List<LdapUserResponse> ldapUserResponses = new ArrayList<LdapUserResponse>();
 		if (users != null) {
 			for (final LdapUser user : users) {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/25e8e9b8/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapAuthenticator.java
----------------------------------------------------------------------
diff --git a/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapAuthenticator.java b/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapAuthenticator.java
index fdea9b6..559a979 100644
--- a/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapAuthenticator.java
+++ b/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapAuthenticator.java
@@ -20,7 +20,6 @@ import java.util.Map;
 
 import javax.inject.Inject;
 
-import org.apache.cloudstack.api.command.LdapListConfigurationCmd;
 import org.apache.log4j.Logger;
 
 import com.cloud.server.auth.DefaultUserAuthenticator;
@@ -58,7 +57,7 @@ public class LdapAuthenticator extends DefaultUserAuthenticator {
 			s_logger.debug("Unable to find user with " + username
 					+ " in domain " + domainId);
 			return false;
-		} else if (isLdapConfigurationPresent()) {
+		} else if (_ldapManager.isLdapEnabled()) {
 			return _ldapManager.canAuthenticate(username, password);
 		} else {
 			return false;
@@ -69,10 +68,4 @@ public class LdapAuthenticator extends DefaultUserAuthenticator {
 	public String encode(final String password) {
 		return password;
 	}
-
-	private boolean isLdapConfigurationPresent() {
-		return _ldapManager.listConfigurations(
-				new LdapListConfigurationCmd(_ldapManager)).second() > 0;
-	}
-
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/25e8e9b8/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapConfiguration.java
----------------------------------------------------------------------
diff --git a/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapConfiguration.java b/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapConfiguration.java
index c0b4a32..5e56c21 100644
--- a/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapConfiguration.java
+++ b/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapConfiguration.java
@@ -118,12 +118,8 @@ public class LdapConfiguration {
 
 	public boolean getSSLStatus() {
 		boolean sslStatus = false;
-		String dbValueForSSLStatus = _configDao.getValue("ldap.ssl.enabled");
-		if (dbValueForSSLStatus != null) {
-			sslStatus = dbValueForSSLStatus == "false" ? false : true;
-		}
-		if (getTrustStore() == null || getTrustStorePassword() == null) {
-			sslStatus = false;
+		if (getTrustStore() != null && getTrustStorePassword() != null) {
+			sslStatus = true;
 		}
 		return sslStatus;
 	}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/25e8e9b8/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapConfigurationVO.java
----------------------------------------------------------------------
diff --git a/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapConfigurationVO.java b/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapConfigurationVO.java
index 0b548f3..98e42f8 100644
--- a/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapConfigurationVO.java
+++ b/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapConfigurationVO.java
@@ -60,7 +60,7 @@ public class LdapConfigurationVO implements InternalIdentity {
 		return port;
 	}
 
-	public void setId(long id) {
+	public void setId(final long id) {
 		this.id = id;
 	}
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/25e8e9b8/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapContextFactory.java
----------------------------------------------------------------------
diff --git a/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapContextFactory.java b/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapContextFactory.java
index c971b70..ceeed68 100644
--- a/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapContextFactory.java
+++ b/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapContextFactory.java
@@ -71,14 +71,25 @@ public class LdapContextFactory {
 		return createInitialDirContext(principal, password, false);
 	}
 
+	private void enableSSL(final Hashtable<String, String> environment) {
+		final boolean sslStatus = _ldapConfiguration.getSSLStatus();
+
+		if (sslStatus) {
+			s_logger.info("LDAP SSL enabled.");
+			environment.put(Context.SECURITY_PROTOCOL, "ssl");
+			System.setProperty("javax.net.ssl.trustStore",
+					_ldapConfiguration.getTrustStore());
+			System.setProperty("javax.net.ssl.trustStorePassword",
+					_ldapConfiguration.getTrustStorePassword());
+		}
+	}
+
 	private Hashtable<String, String> getEnvironment(final String principal,
 			final String password, final String providerUrl,
 			final boolean isSystemContext) {
 		final String factory = _ldapConfiguration.getFactory();
 		final String url = providerUrl == null ? _ldapConfiguration
 				.getProviderUrl() : providerUrl;
-		final String authentication = _ldapConfiguration.getAuthentication();
-		final boolean sslStatus = _ldapConfiguration.getSSLStatus();
 
 		final Hashtable<String, String> environment = new Hashtable<String, String>();
 
@@ -87,19 +98,8 @@ public class LdapContextFactory {
 		environment.put("com.sun.jndi.ldap.read.timeout", "500");
 		environment.put("com.sun.jndi.ldap.connect.pool", "true");
 
-		if (sslStatus) {
-			environment.put(Context.SECURITY_PROTOCOL, "ssl");
-			System.setProperty("javax.net.ssl.trustStore",
-					_ldapConfiguration.getTrustStore());
-			System.setProperty("javax.net.ssl.trustStorePassword",
-					_ldapConfiguration.getTrustStorePassword());
-		}
-
-		if ("none".equals(authentication) && !isSystemContext) {
-			environment.put(Context.SECURITY_AUTHENTICATION, "simple");
-		} else {
-			environment.put(Context.SECURITY_AUTHENTICATION, authentication);
-		}
+		enableSSL(environment);
+		setAuthentication(environment, isSystemContext);
 
 		if (principal != null) {
 			environment.put(Context.SECURITY_PRINCIPAL, principal);
@@ -112,6 +112,17 @@ public class LdapContextFactory {
 		return environment;
 	}
 
+	private void setAuthentication(final Hashtable<String, String> environment,
+			final boolean isSystemContext) {
+		final String authentication = _ldapConfiguration.getAuthentication();
+
+		if ("none".equals(authentication) && !isSystemContext) {
+			environment.put(Context.SECURITY_AUTHENTICATION, "simple");
+		} else {
+			environment.put(Context.SECURITY_AUTHENTICATION, authentication);
+		}
+	}
+
 	public void testConnection(final String providerUrl) throws NamingException {
 		try {
 			createBindContext(providerUrl);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/25e8e9b8/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapManager.java
----------------------------------------------------------------------
diff --git a/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapManager.java b/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapManager.java
index eb4332d..683822d 100644
--- a/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapManager.java
+++ b/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapManager.java
@@ -47,6 +47,8 @@ public interface LdapManager extends PluggableService {
 
 	List<LdapUser> getUsers() throws NoLdapUserMatchingQueryException;
 
+	boolean isLdapEnabled();
+
 	Pair<List<? extends LdapConfigurationVO>, Integer> listConfigurations(
 			LdapListConfigurationCmd cmd);
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/25e8e9b8/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapUserManager.java
----------------------------------------------------------------------
diff --git a/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapUserManager.java b/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapUserManager.java
index f522503..7494346 100644
--- a/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapUserManager.java
+++ b/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapUserManager.java
@@ -58,6 +58,36 @@ public class LdapUserManager {
 		return new LdapUser(username, email, firstname, lastname, principal);
 	}
 
+	private String generateSearchFilter(final String username) {
+		final StringBuilder userObjectFilter = new StringBuilder();
+		userObjectFilter.append("(objectClass=");
+		userObjectFilter.append(_ldapConfiguration.getUserObject());
+		userObjectFilter.append(")");
+
+		final StringBuilder usernameFilter = new StringBuilder();
+		usernameFilter.append("(");
+		usernameFilter.append(_ldapConfiguration.getUsernameAttribute());
+		usernameFilter.append("=");
+		usernameFilter.append((username == null ? "*" : username));
+		usernameFilter.append(")");
+
+		final StringBuilder memberOfFilter = new StringBuilder();
+		if (_ldapConfiguration.getSearchGroupPrinciple() != null) {
+			memberOfFilter.append("(memberof=");
+			memberOfFilter.append(_ldapConfiguration.getSearchGroupPrinciple());
+			memberOfFilter.append(")");
+		}
+
+		final StringBuilder result = new StringBuilder();
+		result.append("(&");
+		result.append(userObjectFilter);
+		result.append(usernameFilter);
+		result.append(memberOfFilter);
+		result.append(")");
+
+		return result.toString();
+	}
+
 	public LdapUser getUser(final String username, final DirContext context)
 			throws NamingException {
 		final NamingEnumeration<SearchResult> result = searchUsers(username,
@@ -104,20 +134,7 @@ public class LdapUserManager {
 		controls.setReturningAttributes(_ldapConfiguration
 				.getReturnAttributes());
 
-		final String userObjectFilter = "(objectClass="
-				+ _ldapConfiguration.getUserObject() + ")";
-		final String usernameFilter = "("
-				+ _ldapConfiguration.getUsernameAttribute() + "="
-				+ (username == null ? "*" : username) + ")";
-		String memberOfFilter = "";
-		if (_ldapConfiguration.getSearchGroupPrinciple() != null) {
-			memberOfFilter = "(memberof="
-					+ _ldapConfiguration.getSearchGroupPrinciple() + ")";
-		}
-
-		final String filter = "(&" + userObjectFilter + usernameFilter
-				+ memberOfFilter + ")";
-
-		return context.search(_ldapConfiguration.getBaseDn(), filter, controls);
+		return context.search(_ldapConfiguration.getBaseDn(),
+				generateSearchFilter(username), controls);
 	}
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/25e8e9b8/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapUtils.java
----------------------------------------------------------------------
diff --git a/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapUtils.java b/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapUtils.java
index ff8c88c..e1f999b 100644
--- a/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapUtils.java
+++ b/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapUtils.java
@@ -23,7 +23,7 @@ import javax.naming.directory.Attributes;
 public final class LdapUtils {
 	public static String escapeLDAPSearchFilter(final String filter) {
 		final StringBuilder sb = new StringBuilder();
-		for (char character : filter.toCharArray()) {
+		for (final char character : filter.toCharArray()) {
 			switch (character) {
 			case '\\':
 				sb.append("\\5c");

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/25e8e9b8/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/BasicNamingEnumerationImpl.groovy
----------------------------------------------------------------------
diff --git a/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/BasicNamingEnumerationImpl.groovy b/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/BasicNamingEnumerationImpl.groovy
index ab7e22a..67d5272 100644
--- a/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/BasicNamingEnumerationImpl.groovy
+++ b/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/BasicNamingEnumerationImpl.groovy
@@ -16,24 +16,18 @@
 // under the License.
 package groovy.org.apache.cloudstack.ldap
 
-import javax.naming.NamingEnumeration
-import javax.naming.NamingException
-import javax.naming.directory.SearchResult
+import java.util.LinkedList;
+
+import javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
+import javax.naming.directory.SearchResult;
 
 class BasicNamingEnumerationImpl implements NamingEnumeration {
 
     private LinkedList<String> items = new LinkedList<SearchResult>();
 
-    @Override
-    public boolean hasMoreElements() {
-        return items.size != 0;
-    }
-
-    @Override
-    public Object nextElement() {
-        SearchResult result = items.getFirst();
-        items.removeFirst();
-        return result;
+    public void add(SearchResult item) {
+	items.add(item)
     }
 
     @Override
@@ -46,11 +40,19 @@ class BasicNamingEnumerationImpl implements NamingEnumeration {
     }
 
     @Override
+    public boolean hasMoreElements() {
+	return items.size != 0;
+    }
+
+    @Override
     public Object next() throws NamingException {
         return nextElement();
     }
 
-    public void add(SearchResult item) {
-        items.add(item)
+    @Override
+    public Object nextElement() {
+	SearchResult result = items.getFirst();
+	items.removeFirst();
+	return result;
     }
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/25e8e9b8/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapAddConfigurationCmdSpec.groovy
----------------------------------------------------------------------
diff --git a/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapAddConfigurationCmdSpec.groovy b/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapAddConfigurationCmdSpec.groovy
index 3dcb23f..18df10d 100644
--- a/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapAddConfigurationCmdSpec.groovy
+++ b/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapAddConfigurationCmdSpec.groovy
@@ -16,74 +16,69 @@
 // under the License.
 package groovy.org.apache.cloudstack.ldap
 
-import com.cloud.exception.InvalidParameterValueException
-import org.apache.cloudstack.api.ServerApiException
-import org.apache.cloudstack.api.command.LdapAddConfigurationCmd
-import org.apache.cloudstack.api.response.LdapConfigurationResponse
-import org.apache.cloudstack.ldap.LdapManager
 
 class LdapAddConfigurationCmdSpec extends spock.lang.Specification {
 
+    def "Test failed response from execute"() {
+	given: "We have an LDAP manager, no configuration and a LdapAddConfigurationCmd"
+	def ldapManager = Mock(LdapManager)
+	ldapManager.addConfiguration(_, _) >> { throw new InvalidParameterValueException() }
+	def ldapAddConfigurationCmd = new LdapAddConfigurationCmd(ldapManager)
+	when: "LdapAddCofnigurationCmd is executed"
+	ldapAddConfigurationCmd.execute()
+	then: "an exception is thrown"
+	thrown ServerApiException
+    }
+
+    def "Test getEntityOwnerId is 1"() {
+	given: "We have an LdapManager and LdapConfigurationCmd"
+	def ldapManager = Mock(LdapManager)
+	def ldapAddConfigurationCmd = new LdapAddConfigurationCmd(ldapManager)
+	when: "Get Entity Owner Id is called"
+	long ownerId = ldapAddConfigurationCmd.getEntityOwnerId()
+	then: "1 is returned"
+	ownerId == 1
+    }
+
     def "Test successful response from execute"() {
-        given:
-        def ldapManager = Mock(LdapManager)
+	given: "We have an LDAP Manager that has a configuration and a LdapAddConfigurationCmd"
+	def ldapManager = Mock(LdapManager)
         ldapManager.addConfiguration(_, _) >> new LdapConfigurationResponse("localhost", 389)
         def ldapAddConfigurationCmd = new LdapAddConfigurationCmd(ldapManager)
-        when:
+	when: "LdapAddConfigurationCmd is executed"
         ldapAddConfigurationCmd.execute()
-        then:
+	then: "the responseObject should have the hostname localhost and port 389"
         ldapAddConfigurationCmd.responseObject.hostname == "localhost"
-        ldapAddConfigurationCmd.responseObject.port == 389
+	ldapAddConfigurationCmd.responseObject.port == 389
     }
 
-    def "Test failed response from execute"() {
-        given:
-        def ldapManager = Mock(LdapManager)
-        ldapManager.addConfiguration(_, _) >> { throw new InvalidParameterValueException() }
-        def ldapAddConfigurationCmd = new LdapAddConfigurationCmd(ldapManager)
-        when:
-        ldapAddConfigurationCmd.execute()
-        then:
-        thrown ServerApiException
+    def "Test successful return of getCommandName"() {
+	given: "We have an LdapManager and LdapConfigurationCmd"
+	def ldapManager = Mock(LdapManager)
+	def ldapAddConfigurationCmd = new LdapAddConfigurationCmd(ldapManager)
+	when: "Get Command Name is called"
+	String commandName = ldapAddConfigurationCmd.getCommandName()
+	then: "ldapconfigurationresponse is returned"
+	commandName == "ldapconfigurationresponse"
     }
 
     def "Test successful setting of hostname"() {
-        given:
+	given: "We have an LdapManager and LdapAddConfigurationCmd"
         def ldapManager = Mock(LdapManager)
         def ldapAddConfigurationCmd = new LdapAddConfigurationCmd(ldapManager)
-        when:
+	when: "The hostname is set"
         ldapAddConfigurationCmd.setHostname("localhost")
-        then:
+	then: "Get hostname returns the set hostname"
         ldapAddConfigurationCmd.getHostname() == "localhost"
     }
 
     def "Test successful setting of port"() {
-        given:
+	given: "We have an LdapManager and LdapAddConfigurationCmd"
         def ldapManager = Mock(LdapManager)
         def ldapAddConfigurationCmd = new LdapAddConfigurationCmd(ldapManager)
-        when:
+	when: "The port is set"
         ldapAddConfigurationCmd.setPort(389)
-        then:
-        ldapAddConfigurationCmd.getPort() == 389
-    }
-
-    def "Test getEntityOwnerId is 0"() {
-        given:
-        def ldapManager = Mock(LdapManager)
-        def ldapAddConfigurationCmd = new LdapAddConfigurationCmd(ldapManager)
-        when:
-        long ownerId = ldapAddConfigurationCmd.getEntityOwnerId()
-        then:
-        ownerId == 1
-    }
-
-    def "Test successful return of getCommandName"() {
-        given:
-        def ldapManager = Mock(LdapManager)
-        def ldapAddConfigurationCmd = new LdapAddConfigurationCmd(ldapManager)
-        when:
-        String commandName = ldapAddConfigurationCmd.getCommandName()
-        then:
-        commandName == "ldapconfigurationresponse"
+	then: "Get port returns the port"
+	ldapAddConfigurationCmd.getPort() == 389
     }
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/25e8e9b8/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapAuthenticatorSpec.groovy
----------------------------------------------------------------------
diff --git a/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapAuthenticatorSpec.groovy b/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapAuthenticatorSpec.groovy
index 573f88c..a055fbc 100644
--- a/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapAuthenticatorSpec.groovy
+++ b/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapAuthenticatorSpec.groovy
@@ -16,75 +16,78 @@
 // under the License.
 package groovy.org.apache.cloudstack.ldap
 
-import com.cloud.user.UserAccountVO
-import com.cloud.user.dao.UserAccountDao
-import com.cloud.utils.Pair
-import org.apache.cloudstack.ldap.LdapAuthenticator
-import org.apache.cloudstack.ldap.LdapConfigurationVO
-import org.apache.cloudstack.ldap.LdapManager
 
 class LdapAuthenticatorSpec extends spock.lang.Specification {
 
     def "Test a failed authentication due to user not being found within cloudstack"() {
-        given:
+	given: "We have an LdapManager, userAccountDao and ldapAuthenticator and the user doesn't exist within cloudstack."
         LdapManager ldapManager = Mock(LdapManager)
         UserAccountDao userAccountDao = Mock(UserAccountDao)
         userAccountDao.getUserAccount(_, _) >> null
         def ldapAuthenticator = new LdapAuthenticator(ldapManager, userAccountDao)
-        when:
+	when: "A user authentications"
         def result = ldapAuthenticator.authenticate("rmurphy", "password", 0, null)
-        then:
-        result == false
+	then: "their authentication fails"
+	result == false
     }
 
-    def "Test failed authentication due to ldap not being configured"() {
-        given:
-        def ldapManager = Mock(LdapManager)
-        List<LdapConfigurationVO> ldapConfigurationList = new ArrayList()
-        Pair<List<LdapConfigurationVO>, Integer> ldapConfigurations = new Pair<List<LdapConfigurationVO>, Integer>();
-        ldapConfigurations.set(ldapConfigurationList, ldapConfigurationList.size())
-        ldapManager.listConfigurations(_) >> ldapConfigurations
+    def "Test failed authentication due to ldap bind being unsuccessful"() {
+	given: "We have an LdapManager, LdapConfiguration, userAccountDao and LdapAuthenticator"
+	def ldapManager = Mock(LdapManager)
+	ldapManager.isLdapEnabled() >> true
+	ldapManager.canAuthenticate(_, _) >> false
 
-        UserAccountDao userAccountDao = Mock(UserAccountDao)
-        userAccountDao.getUserAccount(_, _) >> new UserAccountVO()
+	UserAccountDao userAccountDao = Mock(UserAccountDao)
+	userAccountDao.getUserAccount(_, _) >> new UserAccountVO()
+	def ldapAuthenticator = new LdapAuthenticator(ldapManager, userAccountDao)
 
-        def ldapAuthenticator = new LdapAuthenticator(ldapManager, userAccountDao)
-        when:
-        def result = ldapAuthenticator.authenticate("rmurphy", "password", 0, null)
-        then:
-        result == false
+	when: "The user authenticates with an incorrect password"
+	def result = ldapAuthenticator.authenticate("rmurphy", "password", 0, null)
+
+	then: "their authentication fails"
+	result == false
     }
 
-    def "Test failed authentication due to ldap bind being unsuccessful"() {
-        given:
+    def "Test failed authentication due to ldap not being configured"() {
+	given: "We have an LdapManager, A configured LDAP server, a userAccountDao and LdapAuthenticator"
+	def ldapManager = Mock(LdapManager)
+		ldapManager.isLdapEnabled() >> false
 
-        def ldapManager = Mock(LdapManager)
-        List<LdapConfigurationVO> ldapConfigurationList = new ArrayList()
-        ldapConfigurationList.add(new LdapConfigurationVO("localhost", 389))
-        Pair<List<LdapConfigurationVO>, Integer> ldapConfigurations = new Pair<List<LdapConfigurationVO>, Integer>();
-        ldapConfigurations.set(ldapConfigurationList, ldapConfigurationList.size())
-        ldapManager.listConfigurations(_) >> ldapConfigurations
-        ldapManager.canAuthenticate(_, _) >> false
+	UserAccountDao userAccountDao = Mock(UserAccountDao)
+	userAccountDao.getUserAccount(_, _) >> new UserAccountVO()
 
-        UserAccountDao userAccountDao = Mock(UserAccountDao)
-        userAccountDao.getUserAccount(_, _) >> new UserAccountVO()
-        def ldapAuthenticator = new LdapAuthenticator(ldapManager, userAccountDao)
+	def ldapAuthenticator = new LdapAuthenticator(ldapManager, userAccountDao)
+	when: "The user authenticates"
+	def result = ldapAuthenticator.authenticate("rmurphy", "password", 0, null)
+	then: "their authentication fails"
+	result == false
+    }
 
-        when:
-        def result = ldapAuthenticator.authenticate("rmurphy", "password", 0, null)
+	def "Test successful authentication"() {
+		given: "We have an LdapManager, LdapConfiguration, userAccountDao and LdapAuthenticator"
+		def ldapManager = Mock(LdapManager)
+		ldapManager.isLdapEnabled() >> true
+		ldapManager.canAuthenticate(_, _) >> true
 
-        then:
-        result == false
-    }
+		UserAccountDao userAccountDao = Mock(UserAccountDao)
+		userAccountDao.getUserAccount(_, _) >> new UserAccountVO()
+		def ldapAuthenticator = new LdapAuthenticator(ldapManager, userAccountDao)
+
+		when: "The user authenticates with an incorrect password"
+		def result = ldapAuthenticator.authenticate("rmurphy", "password", 0, null)
+
+		then: "their authentication passes"
+		result == true
+	}
 
     def "Test that encode doesn't change the input"() {
-        given:
-        LdapManager ldapManager = Mock(LdapManager)
+	given: "We have an LdapManager, userAccountDao and LdapAuthenticator"
+	LdapManager ldapManager = Mock(LdapManager)
         UserAccountDao userAccountDao = Mock(UserAccountDao)
         def ldapAuthenticator = new LdapAuthenticator(ldapManager, userAccountDao)
-        when:
+	when: "a users password is encoded"
         def result = ldapAuthenticator.encode("password")
-        then:
+	then: "it doesn't change"
         result == "password"
     }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/25e8e9b8/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapConfigurationDaoImplSpec.groovy
----------------------------------------------------------------------
diff --git a/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapConfigurationDaoImplSpec.groovy b/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapConfigurationDaoImplSpec.groovy
index 191b609..02de0f5 100644
--- a/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapConfigurationDaoImplSpec.groovy
+++ b/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapConfigurationDaoImplSpec.groovy
@@ -16,13 +16,12 @@
 // under the License.
 package groovy.org.apache.cloudstack.ldap
 
-import org.apache.cloudstack.ldap.dao.LdapConfigurationDaoImpl
 
 class LdapConfigurationDaoImplSpec extends spock.lang.Specification {
     def "Test setting up of a LdapConfigurationDao"() {
-        given:
+	given: "We have an LdapConfigurationDao implementation"
         def ldapConfigurationDaoImpl = new LdapConfigurationDaoImpl();
-        expect:
+	expect: "that hostnameSearch and listAllConfigurationsSearch is configured"
         ldapConfigurationDaoImpl.hostnameSearch != null;
         ldapConfigurationDaoImpl.listAllConfigurationsSearch != null
     }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/25e8e9b8/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapConfigurationResponseSpec.groovy
----------------------------------------------------------------------
diff --git a/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapConfigurationResponseSpec.groovy b/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapConfigurationResponseSpec.groovy
index 4e6bebb..cc9de9b 100644
--- a/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapConfigurationResponseSpec.groovy
+++ b/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapConfigurationResponseSpec.groovy
@@ -16,34 +16,33 @@
 // under the License.
 package groovy.org.apache.cloudstack.ldap
 
-import org.apache.cloudstack.api.response.LdapConfigurationResponse
 
 class LdapConfigurationResponseSpec extends spock.lang.Specification {
     def "Testing succcessful setting of LdapConfigurationResponse hostname"() {
-        given:
+	given: "We have a LdapConfigurationResponse"
         LdapConfigurationResponse response = new LdapConfigurationResponse();
-        when:
+	when: "The hostname is set"
         response.setHostname("localhost");
-        then:
-        response.getHostname() == "localhost";
-    }
-
-    def "Testing successful setting of LdapConfigurationResponse port"() {
-        given:
-        LdapConfigurationResponse response = new LdapConfigurationResponse()
-        when:
-        response.setPort(389)
-        then:
-        response.getPort() == 389
+	then: "Get hostname should return the set value"
+	response.getHostname() == "localhost";
     }
 
     def "Testing successful setting of LdapConfigurationResponse hostname and port via constructor"() {
-        given:
-        LdapConfigurationResponse response
-        when:
+	given: "We have a LdapConfiguration response"
+	LdapConfigurationResponse response
+	when: "both hostname and port are set by constructor"
         response = new LdapConfigurationResponse("localhost", 389)
-        then:
+	then: "Get hostname and port should return the set values."
         response.getHostname() == "localhost"
         response.getPort() == 389
     }
+
+    def "Testing successful setting of LdapConfigurationResponse port"() {
+	given: "We have a LdapConfigurationResponse"
+	LdapConfigurationResponse response = new LdapConfigurationResponse()
+	when: "The port is set"
+	response.setPort(389)
+	then: "Get port should return the set value"
+	response.getPort() == 389
+    }
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/25e8e9b8/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapConfigurationSpec.groovy
----------------------------------------------------------------------
diff --git a/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapConfigurationSpec.groovy b/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapConfigurationSpec.groovy
index a867fd6..c8555a9 100644
--- a/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapConfigurationSpec.groovy
+++ b/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapConfigurationSpec.groovy
@@ -16,166 +16,200 @@
 // under the License.
 package groovy.org.apache.cloudstack.ldap
 
-import com.cloud.configuration.dao.ConfigurationDao
-import com.cloud.utils.Pair
-import org.apache.cloudstack.api.ServerApiException
-import org.apache.cloudstack.ldap.LdapConfiguration
-import org.apache.cloudstack.ldap.LdapConfigurationVO
-import org.apache.cloudstack.ldap.LdapManager
-
-import javax.naming.directory.SearchControls
 
 class LdapConfigurationSpec extends spock.lang.Specification {
-    def "Test that providerUrl successfully returns a URL when a configuration is available"() {
-        given:
-        def configDao = Mock(ConfigurationDao)
+    def "Test that get search group principle returns successfully"() {
+		given: "We have a ConfigDao with a value for ldap.search.group.principle and an LdapConfiguration"
+		def configDao = Mock(ConfigurationDao)
+		configDao.getValue("ldap.search.group.principle") >> "cn=cloudstack,cn=users,dc=cloudstack,dc=org"
+		def ldapManager = Mock(LdapManager)
+		LdapConfiguration ldapConfiguration = new LdapConfiguration(configDao, ldapManager)
 
-        def ldapManager = Mock(LdapManager)
-        List<LdapConfigurationVO> ldapConfigurationList = new ArrayList()
-        ldapConfigurationList.add(new LdapConfigurationVO("localhost", 389))
-        Pair<List<LdapConfigurationVO>, Integer> result = new Pair<List<LdapConfigurationVO>, Integer>();
-        result.set(ldapConfigurationList, ldapConfigurationList.size())
-        ldapManager.listConfigurations(_) >> result
+		when: "A request is made to get the search group principle"
+		String result = ldapConfiguration.getSearchGroupPrinciple();
 
-        LdapConfiguration ldapConfiguration = new LdapConfiguration(configDao, ldapManager)
+		then: "The result holds the same value configDao did"
+		result == "cn=cloudstack,cn=users,dc=cloudstack,dc=org"
+	}
 
-        when:
-        String providerUrl = ldapConfiguration.getProviderUrl()
-
-        then:
-        providerUrl == "ldap://localhost:389"
+    def "Test that getAuthentication returns none"() {
+	given: "We have a ConfigDao, LdapManager and LdapConfiguration"
+	def configDao = Mock(ConfigurationDao)
+	def ldapManager = Mock(LdapManager)
+	def ldapConfiguration = new LdapConfiguration(configDao, ldapManager)
+	when: "Get authentication is called"
+	String authentication = ldapConfiguration.getAuthentication()
+	then: "none should be returned"
+	authentication == "none"
     }
 
     def "Test that getAuthentication returns simple"() {
-        given:
+	given: "We have a configDao, LdapManager and LdapConfiguration with bind principle and password set"
         def configDao = Mock(ConfigurationDao)
         def ldapManager = Mock(LdapManager)
         def ldapConfiguration = new LdapConfiguration(configDao, ldapManager)
         configDao.getValue("ldap.bind.password") >> "password"
         configDao.getValue("ldap.bind.principal") >> "cn=rmurphy,dc=cloudstack,dc=org"
-        when:
+	when: "Get authentication is called"
         String authentication = ldapConfiguration.getAuthentication()
-        then:
-        authentication == "simple"
+	then: "authentication should be set to simple"
+	authentication == "simple"
     }
 
-    def "Test that getAuthentication returns none"() {
-        given:
-        def configDao = Mock(ConfigurationDao)
-        def ldapManager = Mock(LdapManager)
-        def ldapConfiguration = new LdapConfiguration(configDao, ldapManager)
-        when:
-        String authentication = ldapConfiguration.getAuthentication()
-        then:
-        authentication == "none"
+    def "Test that getBaseDn returns dc=cloudstack,dc=org"() {
+	given: "We have a ConfigDao, LdapManager and ldapConfiguration with a baseDn value set."
+	def configDao = Mock(ConfigurationDao)
+	configDao.getValue("ldap.basedn") >> "dc=cloudstack,dc=org"
+	def ldapManager = Mock(LdapManager)
+	def ldapConfiguration = new LdapConfiguration(configDao, ldapManager)
+	when: "Get basedn is called"
+	String baseDn = ldapConfiguration.getBaseDn();
+	then: "The set baseDn should be returned"
+	baseDn == "dc=cloudstack,dc=org"
     }
 
     def "Test that getEmailAttribute returns mail"() {
-        given:
+	given: "Given that we have a ConfigDao, LdapManager and LdapConfiguration"
         def configDao = Mock(ConfigurationDao)
         configDao.getValue("ldap.email.attribute") >> "mail"
         def ldapManager = Mock(LdapManager)
         def ldapConfiguration = new LdapConfiguration(configDao, ldapManager)
-        when:
+	when: "Get Email Attribute is called"
         String emailAttribute = ldapConfiguration.getEmailAttribute()
-        then:
-        emailAttribute == "mail"
+	then: "mail should be returned"
+	emailAttribute == "mail"
     }
 
-    def "Test that getUsernameAttribute returns uid"() {
-        given:
-        def configDao = Mock(ConfigurationDao)
-        configDao.getValue("ldap.username.attribute") >> "uid"
-        def ldapManager = Mock(LdapManager)
-        def ldapConfiguration = new LdapConfiguration(configDao, ldapManager)
-        when:
-        String usernameAttribute = ldapConfiguration.getUsernameAttribute()
-        then:
-        usernameAttribute == "uid"
+    def "Test that getFactory returns com.sun.jndi.ldap.LdapCtxFactory"() {
+	given: "We have a ConfigDao, LdapManager and LdapConfiguration"
+	def configDao = Mock(ConfigurationDao)
+	def ldapManager = Mock(LdapManager)
+	def ldapConfiguration = new LdapConfiguration(configDao, ldapManager)
+	when: "Get Factory is scalled"
+	String factory = ldapConfiguration.getFactory();
+	then: "com.sun.jndi.ldap.LdapCtxFactory is returned"
+	factory == "com.sun.jndi.ldap.LdapCtxFactory"
     }
 
     def "Test that getFirstnameAttribute returns givenname"() {
-        given:
+	given: "We have a ConfigDao, LdapManager and LdapConfiguration"
         def configDao = Mock(ConfigurationDao)
         configDao.getValue("ldap.firstname.attribute") >> "givenname"
         def ldapManager = Mock(LdapManager)
         def ldapConfiguration = new LdapConfiguration(configDao, ldapManager)
-        when:
+	when: "Get firstname attribute is called"
         String firstname = ldapConfiguration.getFirstnameAttribute()
-        then:
+	then: "givennam should be returned"
         firstname == "givenname"
     }
 
     def "Test that getLastnameAttribute returns givenname"() {
-        given:
+	given: "We have a ConfigDao, LdapManager and LdapConfiguration"
         def configDao = Mock(ConfigurationDao)
         configDao.getValue("ldap.lastname.attribute") >> "sn"
         def ldapManager = Mock(LdapManager)
         def ldapConfiguration = new LdapConfiguration(configDao, ldapManager)
-        when:
+	when: "Get Lastname Attribute is scalled "
         String lastname = ldapConfiguration.getLastnameAttribute()
-        then:
-        lastname == "sn"
-    }
-
-    def "Test that getUserObject returns inetOrgPerson"() {
-        given:
-        def configDao = Mock(ConfigurationDao)
-        configDao.getValue("ldap.user.object") >> "inetOrgPerson"
-        def ldapManager = Mock(LdapManager)
-        def ldapConfiguration = new LdapConfiguration(configDao, ldapManager)
-        when:
-        String userObject = ldapConfiguration.getUserObject()
-        then:
-        userObject == "inetOrgPerson"
+	then: "sn should be returned"
+	lastname == "sn"
     }
 
     def "Test that getReturnAttributes returns the correct data"() {
-        given:
-        def configDao = Mock(ConfigurationDao)
+	given: "We have a ConfigDao, LdapManager and LdapConfiguration"
+	def configDao = Mock(ConfigurationDao)
         configDao.getValue("ldap.firstname.attribute") >> "givenname"
         configDao.getValue("ldap.lastname.attribute") >> "sn"
         configDao.getValue("ldap.username.attribute") >> "uid"
         configDao.getValue("ldap.email.attribute") >> "mail"
         def ldapManager = Mock(LdapManager)
         def ldapConfiguration = new LdapConfiguration(configDao, ldapManager)
-        when:
+	when: "Get return attributes is called"
         String[] returnAttributes = ldapConfiguration.getReturnAttributes()
-        then:
+	then: "An array containing uid, mail, givenname and sn is returned"
         returnAttributes == ["uid", "mail", "givenname", "sn"]
     }
 
     def "Test that getScope returns SearchControls.SUBTREE_SCOPE"() {
-        given:
+	given: "We have ConfigDao, LdapManager and LdapConfiguration"
         def configDao = Mock(ConfigurationDao)
         def ldapManager = Mock(LdapManager)
         def ldapConfiguration = new LdapConfiguration(configDao, ldapManager)
-        when:
+	when: "Get scope is called"
         int scope = ldapConfiguration.getScope()
-        then:
-        scope == SearchControls.SUBTREE_SCOPE;
+	then: "SearchControls.SUBTRE_SCOPE should be returned"
+	scope == SearchControls.SUBTREE_SCOPE;
     }
 
-    def "Test that getBaseDn returns dc=cloudstack,dc=org"() {
-        given:
-        def configDao = Mock(ConfigurationDao)
-        configDao.getValue("ldap.basedn") >> "dc=cloudstack,dc=org"
-        def ldapManager = Mock(LdapManager)
-        def ldapConfiguration = new LdapConfiguration(configDao, ldapManager)
-        when:
-        String baseDn = ldapConfiguration.getBaseDn();
-        then:
-        baseDn == "dc=cloudstack,dc=org"
+    def "Test that getSSLStatus can be true"() {
+		given: "We have a ConfigDao with values for truststore and truststore password set"
+		def configDao = Mock(ConfigurationDao)
+		configDao.getValue("ldap.truststore") >> "/tmp/ldap.ts"
+		configDao.getValue("ldap.truststore.password") >> "password"
+		def ldapManager = Mock(LdapManager)
+		LdapConfiguration ldapConfiguration = new LdapConfiguration(configDao, ldapManager)
+
+		when: "A request is made to get the status of SSL"
+		boolean result = ldapConfiguration.getSSLStatus();
+
+		then: "The response should be true"
+		result == true
+	}
+
+    def "Test that getTrustStorePassword resopnds"() {
+		given: "We have a ConfigDao with a value for truststore password"
+		def configDao = Mock(ConfigurationDao)
+		configDao.getValue("ldap.truststore.password") >> "password"
+		def ldapManager = Mock(LdapManager)
+		LdapConfiguration ldapConfiguration = new LdapConfiguration(configDao, ldapManager)
+
+		when: "A request is made to get the truststore password"
+		String result = ldapConfiguration.getTrustStorePassword()
+
+		then: "The result is password"
+		result == "password";
+	}
+
+	def "Test that getUsernameAttribute returns uid"() {
+	given: "We have ConfigDao, LdapManager and LdapConfiguration"
+	def configDao = Mock(ConfigurationDao)
+	configDao.getValue("ldap.username.attribute") >> "uid"
+	def ldapManager = Mock(LdapManager)
+	def ldapConfiguration = new LdapConfiguration(configDao, ldapManager)
+	when: "Get Username Attribute is called"
+	String usernameAttribute = ldapConfiguration.getUsernameAttribute()
+	then: "uid should be returned"
+	usernameAttribute == "uid"
     }
 
-    def "Test that getFactory returns com.sun.jndi.ldap.LdapCtxFactory"() {
-        given:
-        def configDao = Mock(ConfigurationDao)
-        def ldapManager = Mock(LdapManager)
-        def ldapConfiguration = new LdapConfiguration(configDao, ldapManager)
-        when:
-        String factory = ldapConfiguration.getFactory();
-        then:
-        factory == "com.sun.jndi.ldap.LdapCtxFactory"
+	def "Test that getUserObject returns inetOrgPerson"() {
+	given: "We have a ConfigDao, LdapManager and LdapConfiguration"
+	def configDao = Mock(ConfigurationDao)
+	configDao.getValue("ldap.user.object") >> "inetOrgPerson"
+	def ldapManager = Mock(LdapManager)
+	def ldapConfiguration = new LdapConfiguration(configDao, ldapManager)
+	when: "Get user object is called"
+	String userObject = ldapConfiguration.getUserObject()
+	then: "inetOrgPerson is returned"
+	userObject == "inetOrgPerson"
+    }
+
+	def "Test that providerUrl successfully returns a URL when a configuration is available"() {
+	given: "We have a ConfigDao, LdapManager, LdapConfiguration"
+	def configDao = Mock(ConfigurationDao)
+	def ldapManager = Mock(LdapManager)
+	List<LdapConfigurationVO> ldapConfigurationList = new ArrayList()
+	ldapConfigurationList.add(new LdapConfigurationVO("localhost", 389))
+	Pair<List<LdapConfigurationVO>, Integer> result = new Pair<List<LdapConfigurationVO>, Integer>();
+	result.set(ldapConfigurationList, ldapConfigurationList.size())
+	ldapManager.listConfigurations(_) >> result
+
+	LdapConfiguration ldapConfiguration = new LdapConfiguration(configDao, ldapManager)
+
+	when: "A request is made to get the providerUrl"
+	String providerUrl = ldapConfiguration.getProviderUrl()
+
+	then: "The providerUrl should be given."
+	providerUrl == "ldap://localhost:389"
     }
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/25e8e9b8/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapConfigurationVOSpec.groovy
----------------------------------------------------------------------
diff --git a/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapConfigurationVOSpec.groovy b/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapConfigurationVOSpec.groovy
index 66b3f44..b5d007e 100644
--- a/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapConfigurationVOSpec.groovy
+++ b/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapConfigurationVOSpec.groovy
@@ -16,21 +16,20 @@
 // under the License.
 package groovy.org.apache.cloudstack.ldap
 
-import org.apache.cloudstack.ldap.LdapConfigurationVO
 
 
 class LdapConfigurationVOSpec extends spock.lang.Specification {
     def "Testing that the ID hostname and port is correctly set within the LDAP configuration VO"() {
-	given: "You have created an LDAP Configuration VO"
-	def configuration = new LdapConfigurationVO(hostname, port)
-	configuration.setId(id)
-	expect: "The id hostname and port is equal to the given data source"
-	configuration.getId() == id
-	configuration.getHostname() == hostname
-	configuration.getPort() == port
-	where: "The id, hostname and port is set to "
-	hostname << ["", null, "localhost"]
-	id << [0, 1000, -1000]
-	port << [0, 1000, -1000]
+		given: "You have created an LDAP Configuration VO"
+		def configuration = new LdapConfigurationVO(hostname, port)
+		configuration.setId(id)
+		expect: "The id hostname and port is equal to the given data source"
+		configuration.getId() == id
+		configuration.getHostname() == hostname
+		configuration.getPort() == port
+		where: "The id, hostname and port is set to "
+		hostname << ["", null, "localhost"]
+		id << [0, 1000, -1000]
+		port << [0, 1000, -1000]
     }
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/25e8e9b8/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapContextFactorySpec.groovy
----------------------------------------------------------------------
diff --git a/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapContextFactorySpec.groovy b/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapContextFactorySpec.groovy
index e9b3b6e..9d9ea65 100644
--- a/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapContextFactorySpec.groovy
+++ b/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapContextFactorySpec.groovy
@@ -16,13 +16,7 @@
 // under the License.
 package groovy.org.apache.cloudstack.ldap
 
-import org.apache.cloudstack.ldap.LdapConfiguration
-import org.apache.cloudstack.ldap.LdapContextFactory
-import spock.lang.Shared
-
-import javax.naming.NamingException
-import javax.naming.directory.SearchControls
-import javax.naming.ldap.LdapContext
+import spock.lang.Shared;
 
 class LdapContextFactorySpec extends spock.lang.Specification {
     @Shared
@@ -53,82 +47,72 @@ class LdapContextFactorySpec extends spock.lang.Specification {
 
         username = "rmurphy"
         principal = "cn=" + username + "," + ldapConfiguration.getBaseDn()
-        password = "password"
+	password = "password"
     }
 
-    def "Test successfully creating a system environment with anon bind"() {
-        given:
-        def ldapContextFactory = new LdapContextFactory(ldapConfiguration)
+    def "Test succcessfully creating a initial context"() {
+	given: "We have a LdapContextFactory"
+	def ldapContextFactory = new LdapContextFactory(ldapConfiguration)
+	when: "A context attempts to bind and no Ldap server is avaiable"
+	ldapContextFactory.createInitialDirContext(null, null, true)
+	then: "An expection is thrown"
+	thrown NamingException
+    }
 
-        when:
-        def result = ldapContextFactory.getEnvironment(principal, password, null, false)
+    def "Test successful failed connection"() {
+	given: "We have a LdapContextFactory"
+	def ldapContextFactory = Spy(LdapContextFactory, constructorArgs: [ldapConfiguration])
+	when: "Test connection is executed"
+	ldapContextFactory.testConnection(ldapConfiguration.getProviderUrl())
+	then: "An exception is thrown"
+	thrown NamingException
+    }
 
-        then:
-        result['java.naming.provider.url'] == ldapConfiguration.getProviderUrl()
-        result['java.naming.factory.initial'] == ldapConfiguration.getFactory()
-        result['java.naming.security.principal'] == principal
-        result['java.naming.security.authentication'] == "simple"
-        result['java.naming.security.credentials'] == password
+    def "Test successfully binding as a user"() {
+	given: "We have a LdapContextFactory"
+	def ldapContextFactory = new LdapContextFactory(ldapConfiguration)
+	when: "A user attempts to bind and no LDAP server is avaiable"
+	ldapContextFactory.createUserContext(principal, password)
+	then: "An exception is thrown"
+	thrown NamingException
     }
 
     def "Test successfully creating a environment with username and password"() {
-        given:
+	given: "We have an LdapContextFactory"
         def ldapContextFactory = new LdapContextFactory(ldapConfiguration)
 
-        when:
+	when: "A request for an environment is made"
         def result = ldapContextFactory.getEnvironment(null, null, null, true)
 
-        then:
+	then: "The resulting values should be set"
         result['java.naming.provider.url'] == ldapConfiguration.getProviderUrl()
         result['java.naming.factory.initial'] == ldapConfiguration.getFactory()
         result['java.naming.security.principal'] == null
         result['java.naming.security.authentication'] == ldapConfiguration.getAuthentication()
-        result['java.naming.security.credentials'] == null
+	result['java.naming.security.credentials'] == null
     }
 
-    def "Test successfully binding as a user"() {
-        given:
-        def ldapContextFactory = new LdapContextFactory(ldapConfiguration)
-        when:
-        ldapContextFactory.createUserContext(principal, password)
-        then:
-        thrown NamingException
+    def "Test successfully creating a system environment with anon bind"() {
+	given: "We have an LdapContext Factory"
+	def ldapContextFactory = new LdapContextFactory(ldapConfiguration)
+
+	when: "A request for an environment is made"
+	def result = ldapContextFactory.getEnvironment(principal, password, null, false)
+
+	then: "The resulting values should be set"
+	result['java.naming.provider.url'] == ldapConfiguration.getProviderUrl()
+	result['java.naming.factory.initial'] == ldapConfiguration.getFactory()
+	result['java.naming.security.principal'] == principal
+	result['java.naming.security.authentication'] == "simple"
+	result['java.naming.security.credentials'] == password
     }
 
     def "Test successully binding as system"() {
-        given:
+	given: "We have a LdapContextFactory"
         def ldapContextFactory = new LdapContextFactory(ldapConfiguration)
-        when:
+	when: "A bind context attempts to bind and no Ldap server is avaiable"
         ldapContextFactory.createBindContext()
-        then:
-        thrown NamingException
-    }
-
-    def "Test succcessfully creating a initial context"() {
-        given:
-        def ldapContextFactory = new LdapContextFactory(ldapConfiguration)
-        when:
-        ldapContextFactory.createInitialDirContext(null, null, true)
-        then:
-        thrown NamingException
-    }
-
-    def "Test successful failed connection"() {
-        given:
-        def ldapContextFactory = Spy(LdapContextFactory, constructorArgs: [ldapConfiguration])
-        when:
-        ldapContextFactory.testConnection(ldapConfiguration.getProviderUrl())
-        then:
-        thrown NamingException
-    }
-
-    def "Test successful connection"() {
-        given:
-        def ldapContextFactory = Spy(LdapContextFactory, constructorArgs: [ldapConfiguration])
-        ldapContextFactory.createBindContext(_) >> Mock(LdapContext)
-        when:
-        ldapContextFactory.testConnection(ldapConfiguration.getProviderUrl())
-        then:
-        notThrown NamingException
+	then: "An exception is thrown"
+	thrown NamingException
     }
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/25e8e9b8/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapCreateAccountCmdSpec.groovy
----------------------------------------------------------------------
diff --git a/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapCreateAccountCmdSpec.groovy b/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapCreateAccountCmdSpec.groovy
index 07056b0..d2b2332 100644
--- a/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapCreateAccountCmdSpec.groovy
+++ b/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapCreateAccountCmdSpec.groovy
@@ -16,20 +16,6 @@
 // under the License.
 package groovy.org.apache.cloudstack.ldap
 
-import com.cloud.exception.InvalidParameterValueException
-import org.apache.cloudstack.api.ServerApiException
-import org.apache.cloudstack.api.command.LdapAddConfigurationCmd
-import org.apache.cloudstack.api.response.LdapConfigurationResponse
-
-import org.apache.cloudstack.ldap.LdapUser;
-import org.apache.cloudstack.ldap.LdapManager;
-
-import org.apache.cloudstack.api.command.LdapCreateAccount
-
-import com.cloud.user.AccountService;
-import com.cloud.user.UserAccountVO;
-
-import javax.naming.NamingException
 
 class LdapCreateAccountCmdSpec extends spock.lang.Specification {
 /*
@@ -47,108 +33,96 @@ class LdapCreateAccountCmdSpec extends spock.lang.Specification {
 	thrown ServerApiException
     } */
 
-    def "Test validation of a user"() {
-	given:
-	LdapManager ldapManager = Mock(LdapManager)
-	AccountService accountService = Mock(AccountService)
-
-	def ldapCreateAccount = Spy(LdapCreateAccount, constructorArgs: [ldapManager, accountService])
-
-	when:
-	def commandName = ldapCreateAccount.getCommandName()
-
-	then:
-	commandName == "createaccountresponse"
+    def "Test command name"() {
+		given: "We have an LdapManager, AccountService and LdapCreateAccount"
+		LdapManager ldapManager = Mock(LdapManager)
+		AccountService accountService = Mock(AccountService)
+		def ldapCreateAccount = new LdapCreateAccount(ldapManager, accountService)
+		when: "Get command name is called"
+		def result = ldapCreateAccount.getCommandName()
+		then: "createaccountresponse is returned"
+		result == "createaccountresponse"
     }
 
     def "Test getEntityOwnerId is 1"() {
-	given:
-	LdapManager ldapManager = Mock(LdapManager)
-	AccountService accountService = Mock(AccountService)
-
-	def ldapCreateAccount = Spy(LdapCreateAccount, constructorArgs: [ldapManager, accountService])
-	when:
-	long ownerId = ldapCreateAccount.getEntityOwnerId()
-	then:
-	ownerId == 1
+		given: "We have an LdapManager, AccountService andL dapCreateAccount"
+		LdapManager ldapManager = Mock(LdapManager)
+		AccountService accountService = Mock(AccountService)
+
+		def ldapCreateAccount = Spy(LdapCreateAccount, constructorArgs: [ldapManager, accountService])
+		when: "Get entity owner id is called"
+		long ownerId = ldapCreateAccount.getEntityOwnerId()
+		then: "1 is returned"
+		ownerId == 1
     }
 
+    def "Test password generation"() {
+		given: "We have an LdapManager, AccountService and LdapCreateAccount"
+		LdapManager ldapManager = Mock(LdapManager)
+		AccountService accountService = Mock(AccountService)
+		def ldapCreateAccount = new LdapCreateAccount(ldapManager, accountService)
+		when: "A password is generated"
+		def result = ldapCreateAccount.generatePassword()
+		then: "The result shouldn't be null or empty"
+		result != ""
+		result != null
+	}
+
     def "Test validate User"() {
-	given:
-	LdapManager ldapManager = Mock(LdapManager)
-	AccountService accountService = Mock(AccountService)
-	def ldapCreateAccount = new LdapCreateAccount(ldapManager, accountService);
-	when:
-	def result = ldapCreateAccount.validateUser(new LdapUser("username","email","firstname","lastname","principal"))
-	then:
-	result == true
+		given: "We have an LdapManager, AccountService andL dapCreateAccount"
+		LdapManager ldapManager = Mock(LdapManager)
+		AccountService accountService = Mock(AccountService)
+		def ldapCreateAccount = new LdapCreateAccount(ldapManager, accountService);
+		when: "a user with an username, email, firstname and lastname is validated"
+		def result = ldapCreateAccount.validateUser(new LdapUser("username","email","firstname","lastname","principal"))
+		then: "the result is true"
+		result == true
    }
 
     def "Test validate User empty email"() {
-	given:
-	LdapManager ldapManager = Mock(LdapManager)
-	AccountService accountService = Mock(AccountService)
-	def ldapCreateAccount = new LdapCreateAccount(ldapManager, accountService)
-	when:
-	ldapCreateAccount.validateUser(new LdapUser("username",null,"firstname","lastname","principal"))
-	then:
-	thrown Exception
+		given: "We have an LdapManager, AccountService andL dapCreateAccount"
+		LdapManager ldapManager = Mock(LdapManager)
+		AccountService accountService = Mock(AccountService)
+		def ldapCreateAccount = new LdapCreateAccount(ldapManager, accountService)
+		when: "A user with no email address attempts to validate"
+		ldapCreateAccount.validateUser(new LdapUser("username",null,"firstname","lastname","principal"))
+		then: "An exception is thrown"
+		thrown Exception
    }
 
     def "Test validate User empty firstname"() {
-	given:
-	LdapManager ldapManager = Mock(LdapManager)
-	AccountService accountService = Mock(AccountService)
-	def ldapCreateAccount = new LdapCreateAccount(ldapManager, accountService)
-	when:
-	ldapCreateAccount.validateUser(new LdapUser("username","email",null,"lastname","principal"))
-	then:
-	thrown Exception
+		given: "We have an LdapManager, AccountService andL dapCreateAccount"
+		LdapManager ldapManager = Mock(LdapManager)
+		AccountService accountService = Mock(AccountService)
+		def ldapCreateAccount = new LdapCreateAccount(ldapManager, accountService)
+		when: "A user with no firstname attempts to validate"
+		ldapCreateAccount.validateUser(new LdapUser("username","email",null,"lastname","principal"))
+		then: "An exception is thrown"
+		thrown Exception
    }
 
-    def "Test validate User empty lastname"() {
-	given:
-	LdapManager ldapManager = Mock(LdapManager)
-	AccountService accountService = Mock(AccountService)
-	def ldapCreateAccount = new LdapCreateAccount(ldapManager, accountService)
-	when:
-	ldapCreateAccount.validateUser(new LdapUser("username","email","firstname",null,"principal"))
-	then:
-	thrown Exception
+	def "Test validate User empty lastname"() {
+		given: "We have an LdapManager, AccountService and LdapCreateAccount"
+		LdapManager ldapManager = Mock(LdapManager)
+		AccountService accountService = Mock(AccountService)
+		def ldapCreateAccount = new LdapCreateAccount(ldapManager, accountService)
+		when: "A user with no lastname attempts to validate"
+		ldapCreateAccount.validateUser(new LdapUser("username","email","firstname",null,"principal"))
+		then: "An exception is thown"
+		thrown Exception
    }
 
-    def "Test failed password generation"() {
-	given:
-	LdapManager ldapManager = Mock(LdapManager)
-	AccountService accountService = Mock(AccountService)
-	def ldapCreateAccount = new LdapCreateAccount(ldapManager, accountService)
-	when:
-	def result = ldapCreateAccount.generatePassword()
-	then:
-	result != ""
-	result != null
-    }
+    def "Test validation of a user"() {
+		given: "We have an LdapManager, AccountService andL dapCreateAccount"
+		LdapManager ldapManager = Mock(LdapManager)
+		AccountService accountService = Mock(AccountService)
 
-    def "Test password generation"() {
-	given:
-	LdapManager ldapManager = Mock(LdapManager)
-	AccountService accountService = Mock(AccountService)
-	def ldapCreateAccount = new LdapCreateAccount(ldapManager, accountService)
-	when:
-	def result = ldapCreateAccount.generatePassword()
-	then:
-	result != ""
-	result != null
-    }
+		def ldapCreateAccount = Spy(LdapCreateAccount, constructorArgs: [ldapManager, accountService])
 
-    def "Test command name"() {
-	given:
-	LdapManager ldapManager = Mock(LdapManager)
-	AccountService accountService = Mock(AccountService)
-	def ldapCreateAccount = new LdapCreateAccount(ldapManager, accountService)
-	when:
-	def result = ldapCreateAccount.getCommandName()
-	then:
-	result == "createaccountresponse"
+		when: "Get command name is called"
+		def commandName = ldapCreateAccount.getCommandName()
+
+		then: "createaccountresponse is returned"
+		commandName == "createaccountresponse"
     }
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/25e8e9b8/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapDeleteConfigurationCmdSpec.groovy
----------------------------------------------------------------------
diff --git a/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapDeleteConfigurationCmdSpec.groovy b/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapDeleteConfigurationCmdSpec.groovy
index b702689..a8374b0 100644
--- a/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapDeleteConfigurationCmdSpec.groovy
+++ b/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapDeleteConfigurationCmdSpec.groovy
@@ -16,53 +16,48 @@
 // under the License.
 package groovy.org.apache.cloudstack.ldap
 
-import com.cloud.exception.InvalidParameterValueException
-import org.apache.cloudstack.api.ServerApiException
-import org.apache.cloudstack.api.command.LdapDeleteConfigurationCmd
-import org.apache.cloudstack.api.response.LdapConfigurationResponse
-import org.apache.cloudstack.ldap.LdapManager
 
 class LdapDeleteConfigurationCmdSpec extends spock.lang.Specification {
 
-    def "Test successful response from execute"() {
-        given:
-        def ldapManager = Mock(LdapManager)
-        ldapManager.deleteConfiguration(_) >> new LdapConfigurationResponse("localhost")
-        def ldapDeleteConfigurationCmd = new LdapDeleteConfigurationCmd(ldapManager)
-        when:
-        ldapDeleteConfigurationCmd.execute()
-        then:
-        ldapDeleteConfigurationCmd.responseObject.hostname == "localhost"
-    }
-
     def "Test failed response from execute"() {
-        given:
-        def ldapManager = Mock(LdapManager)
+	given: "We have an LdapManager and LdapDeleteConfigurationCmd"
+	def ldapManager = Mock(LdapManager)
         ldapManager.deleteConfiguration(_) >> { throw new InvalidParameterValueException() }
         def ldapDeleteConfigurationCmd = new LdapDeleteConfigurationCmd(ldapManager)
-        when:
+	when:"LdapDeleteConfigurationCmd is executed and no configuration exists"
         ldapDeleteConfigurationCmd.execute()
-        then:
+	then: "An exception is thrown"
         thrown ServerApiException
     }
 
     def "Test getEntityOwnerId is 1"() {
-        given:
+	given: "We have an LdapManager and LdapDeleteConfigurationCmd"
         def ldapManager = Mock(LdapManager)
         def ldapDeleteConfigurationCmd = new LdapDeleteConfigurationCmd(ldapManager)
-        when:
+	when: "Get entity owner id is called"
         long ownerId = ldapDeleteConfigurationCmd.getEntityOwnerId()
-        then:
-        ownerId == 1
+	then: "1 is returned"
+	ownerId == 1
+    }
+
+    def "Test successful response from execute"() {
+	given: "We have an LdapManager and LdapDeleteConfigurationCmd"
+	def ldapManager = Mock(LdapManager)
+	ldapManager.deleteConfiguration(_) >> new LdapConfigurationResponse("localhost")
+	def ldapDeleteConfigurationCmd = new LdapDeleteConfigurationCmd(ldapManager)
+	when: "LdapDeleteConfigurationCmd is executed"
+	ldapDeleteConfigurationCmd.execute()
+	then: "The given configuration should be deleted and returned"
+	ldapDeleteConfigurationCmd.responseObject.hostname == "localhost"
     }
 
     def "Test successful return of getCommandName"() {
-        given:
-        def ldapManager = Mock(LdapManager)
+	given: "We have an LdapManager and LdapDeleteConfigurationCmd"
+	def ldapManager = Mock(LdapManager)
         def ldapDeleteConfigurationCmd = new LdapDeleteConfigurationCmd(ldapManager)
-        when:
+	when: "Get Command name is called"
         String commandName = ldapDeleteConfigurationCmd.getCommandName()
-        then:
+	then: "ldapconfigurationresponse is returned"
         commandName == "ldapconfigurationresponse"
     }
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/25e8e9b8/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapListAllUsersCmdSpec.groovy
----------------------------------------------------------------------
diff --git a/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapListAllUsersCmdSpec.groovy b/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapListAllUsersCmdSpec.groovy
index f6ade31..bb6845c 100644
--- a/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapListAllUsersCmdSpec.groovy
+++ b/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapListAllUsersCmdSpec.groovy
@@ -16,57 +16,51 @@
 // under the License.
 package groovy.org.apache.cloudstack.ldap
 
-import org.apache.cloudstack.api.ServerApiException
-import org.apache.cloudstack.api.command.LdapListAllUsersCmd
-import org.apache.cloudstack.api.response.LdapUserResponse
-import org.apache.cloudstack.ldap.LdapManager
-import org.apache.cloudstack.ldap.LdapUser
-import org.apache.cloudstack.ldap.NoLdapUserMatchingQueryException
 
 class LdapListAllUsersCmdSpec extends spock.lang.Specification {
-    def "Test successful response from execute"() {
-        given:
-        def ldapManager = Mock(LdapManager)
-        List<LdapUser> users = new ArrayList()
-        users.add(new LdapUser("rmurphy", "rmurphy@test.com", "Ryan", "Murphy", "cn=rmurphy,dc=cloudstack,dc=org"))
-        ldapManager.getUsers() >> users
-        LdapUserResponse response = new LdapUserResponse("rmurphy", "rmurphy@test.com", "Ryan", "Murphy", "cn=rmurphy,dc=cloudstack,dc=org")
-        ldapManager.createLdapUserResponse(_) >> response
-        def ldapListAllUsersCmd = new LdapListAllUsersCmd(ldapManager)
-        when:
-        ldapListAllUsersCmd.execute()
-        then:
-        ldapListAllUsersCmd.responseObject.getResponses().size() != 0
+    def "Test getEntityOwnerId is 1"() {
+	given: "We have an LdapManager and LdapListAllUsersCmd"
+	def ldapManager = Mock(LdapManager)
+	def ldapListAllUsersCmd = new LdapListAllUsersCmd(ldapManager)
+	when: "Get entity owner id is called"
+	long ownerId = ldapListAllUsersCmd.getEntityOwnerId()
+	then: "a 1 should be returned"
+	ownerId == 1
     }
 
     def "Test successful empty response from execute"() {
-        given:
+	given: "We have a LdapManager with no users and a LdapListAllUsersCmd"
         def ldapManager = Mock(LdapManager)
         ldapManager.getUsers() >> {throw new NoLdapUserMatchingQueryException()}
         def ldapListAllUsersCmd = new LdapListAllUsersCmd(ldapManager)
-        when:
+	when: "LdapListAllUsersCmd is executed"
         ldapListAllUsersCmd.execute()
-        then:
-	ldapListAllUsersCmd.responseObject.getResponses().size() == 0
+	then: "An array of size 0 is returned"
+		ldapListAllUsersCmd.responseObject.getResponses().size() == 0
     }
 
-    def "Test getEntityOwnerId is 1"() {
-        given:
-        def ldapManager = Mock(LdapManager)
-        def ldapListAllUsersCmd = new LdapListAllUsersCmd(ldapManager)
-        when:
-        long ownerId = ldapListAllUsersCmd.getEntityOwnerId()
-        then:
-        ownerId == 1
+    def "Test successful response from execute"() {
+	given: "We have an LdapManager, one user and a LdapListAllUsersCmd"
+	def ldapManager = Mock(LdapManager)
+	List<LdapUser> users = new ArrayList()
+	users.add(new LdapUser("rmurphy", "rmurphy@test.com", "Ryan", "Murphy", "cn=rmurphy,dc=cloudstack,dc=org"))
+	ldapManager.getUsers() >> users
+	LdapUserResponse response = new LdapUserResponse("rmurphy", "rmurphy@test.com", "Ryan", "Murphy", "cn=rmurphy,dc=cloudstack,dc=org")
+	ldapManager.createLdapUserResponse(_) >> response
+	def ldapListAllUsersCmd = new LdapListAllUsersCmd(ldapManager)
+	when: "LdapListAllUsersCmd is executed"
+	ldapListAllUsersCmd.execute()
+	then: "a list of size not 0 is returned"
+	ldapListAllUsersCmd.responseObject.getResponses().size() != 0
     }
 
     def "Test successful return of getCommandName"() {
-        given:
+	given: "We have an LdapManager and a LdapListAllUsersCmd"
         def ldapManager = Mock(LdapManager)
         def ldapListAllUsersCmd = new LdapListAllUsersCmd(ldapManager)
-        when:
+	when: "Get command name is called"
         String commandName = ldapListAllUsersCmd.getCommandName()
-        then:
+	then: "ldapuserresponse is returned"
         commandName == "ldapuserresponse"
     }
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/25e8e9b8/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapListConfigurationCmdSpec.groovy
----------------------------------------------------------------------
diff --git a/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapListConfigurationCmdSpec.groovy b/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapListConfigurationCmdSpec.groovy
index d83b926..11226d7 100644
--- a/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapListConfigurationCmdSpec.groovy
+++ b/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapListConfigurationCmdSpec.groovy
@@ -16,19 +16,36 @@
 // under the License.
 package groovy.org.apache.cloudstack.ldap
 
-import org.apache.cloudstack.api.ServerApiException
-import org.apache.cloudstack.api.command.LdapListConfigurationCmd
-import org.apache.cloudstack.api.response.LdapConfigurationResponse
-import org.apache.cloudstack.ldap.LdapConfigurationVO
-import org.apache.cloudstack.ldap.LdapManager
-
-import com.cloud.utils.Pair
 
 class LdapListConfigurationCmdSpec extends spock.lang.Specification {
 
+    def "Test failed response from execute"() {
+	given: "We have an LdapManager and a LdapListConfigurationsCmd"
+	def ldapManager = Mock(LdapManager)
+	List<LdapConfigurationVO> ldapConfigurationList = new ArrayList()
+	Pair<List<LdapConfigurationVO>, Integer> ldapConfigurations = new Pair<List<LdapConfigurationVO>, Integer>();
+	ldapConfigurations.set(ldapConfigurationList, ldapConfigurationList.size())
+	ldapManager.listConfigurations(_) >> ldapConfigurations
+	def ldapListConfigurationCmd = new LdapListConfigurationCmd(ldapManager)
+	when: "LdapListConfigurationCmd is executed"
+	ldapListConfigurationCmd.execute()
+	then: "Its response object contains an array that is 0"
+	ldapListConfigurationCmd.getResponseObject().getResponses().size() == 0
+    }
+
+    def "Test getEntityOwnerId is 1"() {
+	given: "We have an LdapManager and ListLdapConfigurationCmd"
+	def ldapManager = Mock(LdapManager)
+	def ldapListConfigurationCmd = new LdapListConfigurationCmd(ldapManager)
+	when: "Get entity owner id is called"
+	long ownerId = ldapListConfigurationCmd.getEntityOwnerId()
+	then: "a 1 is returned"
+	ownerId == 1
+    }
+
     def "Test successful response from execute"() {
-        given:
-        def ldapManager = Mock(LdapManager)
+	given: "We have an LdapManager with a configuration and a LdapListConfigurationsCmd"
+	def ldapManager = Mock(LdapManager)
         List<LdapConfigurationVO> ldapConfigurationList = new ArrayList()
         ldapConfigurationList.add(new LdapConfigurationVO("localhost", 389))
         Pair<List<LdapConfigurationVO>, Integer> ldapConfigurations = new Pair<List<LdapConfigurationVO>, Integer>();
@@ -36,65 +53,39 @@ class LdapListConfigurationCmdSpec extends spock.lang.Specification {
         ldapManager.listConfigurations(_) >> ldapConfigurations
         ldapManager.createLdapConfigurationResponse(_) >> new LdapConfigurationResponse("localhost", 389)
         def ldapListConfigurationCmd = new LdapListConfigurationCmd(ldapManager)
-        when:
+	when: "LdapListConfigurationsCmd is executed"
         ldapListConfigurationCmd.execute()
-        then:
-        ldapListConfigurationCmd.getResponseObject().getResponses().size() != 0
+	then: "Its response object contains an array that is not 0 in size"
+	ldapListConfigurationCmd.getResponseObject().getResponses().size() != 0
     }
 
-    def "Test failed response from execute"() {
-        given:
-
-        def ldapManager = Mock(LdapManager)
-        List<LdapConfigurationVO> ldapConfigurationList = new ArrayList()
-        Pair<List<LdapConfigurationVO>, Integer> ldapConfigurations = new Pair<List<LdapConfigurationVO>, Integer>();
-        ldapConfigurations.set(ldapConfigurationList, ldapConfigurationList.size())
-        ldapManager.listConfigurations(_) >> ldapConfigurations
-
-        def ldapListConfigurationCmd = new LdapListConfigurationCmd(ldapManager)
-        when:
-        ldapListConfigurationCmd.execute()
-        then:
-        ldapListConfigurationCmd.getResponseObject().getResponses().size() == 0
+    def "Test successful return of getCommandName"() {
+	given: "We have an LdapManager and LdapListConfigurationCmd"
+	def ldapManager = Mock(LdapManager)
+	def ldapListConfigurationCmd = new LdapListConfigurationCmd(ldapManager)
+	when: "Get command name is called"
+	String commandName = ldapListConfigurationCmd.getCommandName()
+	then: "ldapconfigurationresponse is returned"
+	commandName == "ldapconfigurationresponse"
     }
 
     def "Test successful setting of hostname"() {
-        given:
+	given: "We have an LdapManager and LdapListConfigurationCmd"
         def ldapManager = Mock(LdapManager)
         def ldapListConfigurationCmd = new LdapListConfigurationCmd(ldapManager)
-        when:
+	when: "The hostname is set"
         ldapListConfigurationCmd.setHostname("localhost")
-        then:
-        ldapListConfigurationCmd.getHostname() == "localhost"
+	then: "Get hostname returns the set value"
+	ldapListConfigurationCmd.getHostname() == "localhost"
     }
 
     def "Test successful setting of Port"() {
-        given:
-        def ldapManager = Mock(LdapManager)
+	given: "We have an LdapManager and LdapListConfigurationCmd"
+	def ldapManager = Mock(LdapManager)
         def ldapListConfigurationCmd = new LdapListConfigurationCmd(ldapManager)
-        when:
+	when: "The port is set"
         ldapListConfigurationCmd.setPort(389)
-        then:
-        ldapListConfigurationCmd.getPort() == 389
-    }
-
-    def "Test getEntityOwnerId is 0"() {
-        given:
-        def ldapManager = Mock(LdapManager)
-        def ldapListConfigurationCmd = new LdapListConfigurationCmd(ldapManager)
-        when:
-        long ownerId = ldapListConfigurationCmd.getEntityOwnerId()
-        then:
-        ownerId == 1
-    }
-
-    def "Test successful return of getCommandName"() {
-        given:
-        def ldapManager = Mock(LdapManager)
-        def ldapListConfigurationCmd = new LdapListConfigurationCmd(ldapManager)
-        when:
-        String commandName = ldapListConfigurationCmd.getCommandName()
-        then:
-        commandName == "ldapconfigurationresponse"
+	then: "Get port returns the set value"
+	ldapListConfigurationCmd.getPort() == 389
     }
 }


Mime
View raw message