Author: tmortagne
Date: 2008-02-15 16:14:10 +0100 (Fri, 15 Feb 2008)
New Revision: 7756
Modified:
xwiki-products/xwiki-enterprise/trunk/distribution-test/ldap-tests/
xwiki-products/xwiki-enterprise/trunk/distribution-test/ldap-tests/src/test/it/com/xpn/xwiki/it/AllTests.java
xwiki-products/xwiki-enterprise/trunk/distribution-test/ldap-tests/src/test/it/com/xpn/xwiki/it/XWikiLDAPConnectionTest.java
xwiki-products/xwiki-enterprise/trunk/distribution-test/ldap-tests/src/test/it/com/xpn/xwiki/it/XWikiLDAPUtilsTest.java
xwiki-products/xwiki-enterprise/trunk/distribution-test/ldap-tests/src/test/it/com/xpn/xwiki/it/framework/XWikiLDAPTestSetup.java
Log:
XE-194:
* add test
* javadoc/checkstyle fixes on tests
Property changes on:
xwiki-products/xwiki-enterprise/trunk/distribution-test/ldap-tests
___________________________________________________________________
Name: svn:ignore
- target
.classpath
.project
+ target
.classpath
.project
.checkstyle
Modified:
xwiki-products/xwiki-enterprise/trunk/distribution-test/ldap-tests/src/test/it/com/xpn/xwiki/it/AllTests.java
===================================================================
---
xwiki-products/xwiki-enterprise/trunk/distribution-test/ldap-tests/src/test/it/com/xpn/xwiki/it/AllTests.java
2008-02-15 15:12:34 UTC (rev 7755)
+++
xwiki-products/xwiki-enterprise/trunk/distribution-test/ldap-tests/src/test/it/com/xpn/xwiki/it/AllTests.java
2008-02-15 15:14:10 UTC (rev 7756)
@@ -20,7 +20,6 @@
package com.xpn.xwiki.it;
import com.xpn.xwiki.it.framework.XWikiLDAPTestSetup;
-import com.xpn.xwiki.test.XWikiTestSetup;
import junit.framework.Test;
import junit.framework.TestCase;
@@ -35,8 +34,15 @@
*/
public class AllTests extends TestCase
{
+ /**
+ * The pattern to filter the tests to launch.
+ */
private static final String PATTERN = ".*" + System.getProperty("pattern",
"");
+ /**
+ * @return the test suite.
+ * @throws Exception error when creation the tests suite.
+ */
public static Test suite() throws Exception
{
TestSuite suite = new TestSuite();
Modified:
xwiki-products/xwiki-enterprise/trunk/distribution-test/ldap-tests/src/test/it/com/xpn/xwiki/it/XWikiLDAPConnectionTest.java
===================================================================
---
xwiki-products/xwiki-enterprise/trunk/distribution-test/ldap-tests/src/test/it/com/xpn/xwiki/it/XWikiLDAPConnectionTest.java
2008-02-15 15:12:34 UTC (rev 7755)
+++
xwiki-products/xwiki-enterprise/trunk/distribution-test/ldap-tests/src/test/it/com/xpn/xwiki/it/XWikiLDAPConnectionTest.java
2008-02-15 15:14:10 UTC (rev 7756)
@@ -6,34 +6,42 @@
import com.xpn.xwiki.plugin.ldap.XWikiLDAPConnection;
/**
- * Tests [EMAIL PROTECTED] XWikiLDAPConnectionTest};
+ * Tests [EMAIL PROTECTED] XWikiLDAPConnectionTest}.
*
* @version $Id: $
*/
public class XWikiLDAPConnectionTest extends TestCase
{
/**
- * Initialize the server.
+ * [EMAIL PROTECTED]
+ *
+ * @see junit.framework.TestCase#setUp()
*/
public void setUp() throws Exception
{
-
+
}
+ /**
+ * Test open and close of the LDAP connection.
+ */
public void testOpenClose()
{
int port = XWikiLDAPTestSetup.getLDAPPort();
-
+
XWikiLDAPConnection connection = new XWikiLDAPConnection();
-
+
assertTrue("LDAP connection failed", connection.open("localhost", port,
- "cn=Horatio Hornblower,ou=people,o=sevenSeas", "pass", null,
false));
+ XWikiLDAPTestSetup.HORATIOHORNBLOWER_DN,
XWikiLDAPTestSetup.HORATIOHORNBLOWER_PWD,
+ null, false));
connection.close();
}
/**
- * Shutdown the server.
+ * [EMAIL PROTECTED]
+ *
+ * @see junit.framework.TestCase#tearDown()
*/
public void tearDown() throws Exception
{
Modified:
xwiki-products/xwiki-enterprise/trunk/distribution-test/ldap-tests/src/test/it/com/xpn/xwiki/it/XWikiLDAPUtilsTest.java
===================================================================
---
xwiki-products/xwiki-enterprise/trunk/distribution-test/ldap-tests/src/test/it/com/xpn/xwiki/it/XWikiLDAPUtilsTest.java
2008-02-15 15:12:34 UTC (rev 7755)
+++
xwiki-products/xwiki-enterprise/trunk/distribution-test/ldap-tests/src/test/it/com/xpn/xwiki/it/XWikiLDAPUtilsTest.java
2008-02-15 15:14:10 UTC (rev 7756)
@@ -1,11 +1,6 @@
package com.xpn.xwiki.it;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
import java.util.Map;
-import java.util.Set;
import junit.framework.TestCase;
@@ -21,29 +16,36 @@
import com.xpn.xwiki.web.XWikiEngineContext;
/**
- * Tests [EMAIL PROTECTED] XWikiLDAPUtilsTest};
+ * Tests [EMAIL PROTECTED] XWikiLDAPUtilsTest}.
*
* @version $Id: $
*/
public class XWikiLDAPUtilsTest extends TestCase
{
+ /**
+ * The name of the group cache.
+ */
+ public static final String GROUPCACHE8NAME = "groups";
+
+ /**
+ * The LDAP connection tool.
+ */
private XWikiLDAPConnection connection = new XWikiLDAPConnection();
+ /**
+ * The LDAP tool.
+ */
private XWikiLDAPUtils ldapUtils = new XWikiLDAPUtils(connection);
+ /**
+ * The XWiki context.
+ */
private XWikiContext context;
- private static Set HMSLYDIA_MEMBERS = new HashSet();
-
- static {
- HMSLYDIA_MEMBERS.add("cn=Horatio Hornblower,ou=people,o=sevenSeas");
- HMSLYDIA_MEMBERS.add("cn=William Bush,ou=people,o=sevenSeas");
- HMSLYDIA_MEMBERS.add("cn=Thomas Quist,ou=people,o=sevenSeas");
- HMSLYDIA_MEMBERS.add("cn=Moultrie Crystal,ou=people,o=sevenSeas");
- }
-
/**
- * Initialize the server.
+ * [EMAIL PROTECTED]
+ *
+ * @see junit.framework.TestCase#setUp()
*/
public void setUp() throws Exception
{
@@ -52,67 +54,89 @@
new XWiki(new XWikiConfig(), this.context)
{
private XWikiCacheService cacheService;
-
+
public void initXWiki(XWikiConfig config, XWikiContext context,
- XWikiEngineContext engine_context, boolean noupdate) throws
XWikiException
+ XWikiEngineContext enginecontext, boolean noupdate) throws
XWikiException
{
context.setWiki(this);
setConfig(config);
}
-
+
public XWikiCacheService getCacheService()
{
if (this.cacheService == null) {
cacheService = new OSCacheService();
-
cacheService.init(this);
}
-
+
return cacheService;
}
};
-
+
this.ldapUtils.setUidAttributeName(XWikiLDAPTestSetup.LDAP_USERUID_FIELD);
-
+
int port = XWikiLDAPTestSetup.getLDAPPort();
-
- this.connection.open("localhost", port,
- "cn=Horatio Hornblower,ou=people,o=sevenSeas", "pass", null,
false);
+
+ this.connection.open("localhost", port,
XWikiLDAPTestSetup.HORATIOHORNBLOWER_DN,
+ XWikiLDAPTestSetup.HORATIOHORNBLOWER_PWD, null, false);
}
+ /**
+ * Verify if the user uid attribute name has been correctly set.
+ */
public void testGetUidAttributeName()
{
assertSame("Wrong uid attribute name",
XWikiLDAPTestSetup.LDAP_USERUID_FIELD,
this.ldapUtils.getUidAttributeName());
}
+ /**
+ * Verify that the cache is not created each time it's getted.
+ *
+ * @throws XWikiException error when getting the cache.
+ */
public void testGetCache() throws XWikiException
{
assertTrue("Cache is recreated",
- this.ldapUtils.getCache("cache_name", this.context) ==
this.ldapUtils.getCache(
- "cache_name", this.context));
+ this.ldapUtils.getCache(GROUPCACHE8NAME, this.context) ==
this.ldapUtils.getCache(
+ GROUPCACHE8NAME, this.context));
}
- public void testGetGroupMembers()
+ /**
+ * Test [EMAIL PROTECTED] XWikiLDAPUtils#getGroupMembers(String,
XWikiContext)}.
+ *
+ * @throws XWikiException error when getting group members from cache.
+ */
+ public void testGetGroupMembers() throws XWikiException
{
- List subGroups = new ArrayList();
- Map members = new HashMap();
+ Map members =
+ this.ldapUtils.getGroupMembers(XWikiLDAPTestSetup.HMSLYDIA_DN,
this.context);
- assertTrue("Fail to get members", this.ldapUtils.getGroupMembers(
- "cn=HMS Lydia,ou=crews,ou=groups,o=sevenSeas", members, subGroups,
this.context));
-
assertFalse("No member was found", members.isEmpty());
- assertTrue("Wrong members was found",
HMSLYDIA_MEMBERS.equals(members.keySet()));
+ assertTrue("Wrong members was found",
XWikiLDAPTestSetup.HMSLYDIA_MEMBERS.equals(members
+ .keySet()));
}
- public void testIsUserInGroup()
+ /**
+ * Test [EMAIL PROTECTED] XWikiLDAPUtils#isUserInGroup(String, String,
XWikiContext)}.
+ *
+ * @throws XWikiException error when getting group members from cache.
+ */
+ public void testIsUserInGroup() throws XWikiException
{
-
+ String userDN =
+
this.ldapUtils.isUserInGroup(XWikiLDAPTestSetup.HORATIOHORNBLOWER_UID,
+ XWikiLDAPTestSetup.HMSLYDIA_DN, this.context);
+
+ assertNotNull("Users not found", userDN);
+ assertEquals(XWikiLDAPTestSetup.HORATIOHORNBLOWER_DN, userDN);
}
/**
- * Shutdown the server.
+ * [EMAIL PROTECTED]
+ *
+ * @see junit.framework.TestCase#tearDown()
*/
public void tearDown() throws Exception
{
Modified:
xwiki-products/xwiki-enterprise/trunk/distribution-test/ldap-tests/src/test/it/com/xpn/xwiki/it/framework/XWikiLDAPTestSetup.java
===================================================================
---
xwiki-products/xwiki-enterprise/trunk/distribution-test/ldap-tests/src/test/it/com/xpn/xwiki/it/framework/XWikiLDAPTestSetup.java
2008-02-15 15:12:34 UTC (rev 7755)
+++
xwiki-products/xwiki-enterprise/trunk/distribution-test/ldap-tests/src/test/it/com/xpn/xwiki/it/framework/XWikiLDAPTestSetup.java
2008-02-15 15:14:10 UTC (rev 7756)
@@ -18,7 +18,6 @@
import junit.framework.Test;
-import com.xpn.xwiki.plugin.ldap.XWikiLDAPConnection;
import com.xpn.xwiki.test.XWikiTestSetup;
/**
@@ -37,25 +36,86 @@
*/
public class XWikiLDAPTestSetup extends XWikiTestSetup
{
+ /**
+ * The name of the LDAP property containing user unique id.
+ */
public static final String LDAP_USERUID_FIELD = "uid";
- public static final String PROPNAME_LDAPPORT = "ldap_port";
+ /**
+ * The name of the system property containing the LDAP embedded server
port.
+ */
+ public static final String SYSPROPNAME_LDAPPORT = "ldap_port";
+ /**
+ * The directory where is the instance of XWiki Enterprise used for theses
tests.
+ */
public static final String EXECUTION_DIRECTORY =
System.getProperty("xwikiExecutionDirectory");
+ /**
+ * The xwiki.cfg file used by the instance of XWiki Enterprise used for
theses tests.
+ */
public static final String XWIKI_CFG_FILE =
EXECUTION_DIRECTORY + "/webapps/xwiki/WEB-INF/xwiki.cfg";
+ // Somes datas examples
+
+ /**
+ * The LDAP DN of user Horatio Hornblower.
+ */
+ public static final String HORATIOHORNBLOWER_DN =
+ "cn=Horatio Hornblower,ou=people,o=sevenSeas";
+
+ /**
+ * The LDAP password of user Horatio Hornblower.
+ */
+ public static final String HORATIOHORNBLOWER_PWD = "pass";
+
+ /**
+ * The LDAP unique id of user Horatio Hornblower.
+ */
+ public static final String HORATIOHORNBLOWER_UID = "hhornblo";
+
+ /**
+ * The LDAP DN of group HMS Lydia.
+ */
+ public static final String HMSLYDIA_DN = "cn=HMS
Lydia,ou=crews,ou=groups,o=sevenSeas";
+
+ /**
+ * The LDAP members of group HMS Lydia.
+ */
+ public static final Set HMSLYDIA_MEMBERS = new HashSet();
+
+ static {
+ HMSLYDIA_MEMBERS.add(XWikiLDAPTestSetup.HORATIOHORNBLOWER_DN);
+ HMSLYDIA_MEMBERS.add("cn=William Bush,ou=people,o=sevenSeas");
+ HMSLYDIA_MEMBERS.add("cn=Thomas Quist,ou=people,o=sevenSeas");
+ HMSLYDIA_MEMBERS.add("cn=Moultrie Crystal,ou=people,o=sevenSeas");
+ }
+
+ // ///
+
+ /**
+ * Tool to start and stop embedded LDAP server.
+ */
private LDAPRunner ldap = new LDAPRunner();
+ /**
+ * The default xwiki.cfg properties.
+ */
private Properties initialXWikiConf;
+ /**
+ * The xwiki.cfg properties modified for the test.
+ */
private Properties currentXWikiConf;
+ /**
+ * @return return the port of the current instance of LDAP server.
+ */
public static int getLDAPPort()
{
- return Integer.parseInt(System.getProperty(PROPNAME_LDAPPORT));
+ return Integer.parseInt(System.getProperty(SYSPROPNAME_LDAPPORT));
}
public XWikiLDAPTestSetup(Test test) throws IOException
@@ -107,7 +167,7 @@
{
this.ldap.start();
- System.setProperty(PROPNAME_LDAPPORT, "" + ldap.getPort());
+ System.setProperty(SYSPROPNAME_LDAPPORT, "" + ldap.getPort());
this.currentXWikiConf.setProperty("xwiki.authentication.ldap.port", ""
+ ldap.getPort());
FileOutputStream fos = new FileOutputStream(XWIKI_CFG_FILE);
@@ -134,6 +194,11 @@
}
}
+/**
+ * Tool to start and stop embedded LDAP server.
+ *
+ * @version $Id: $
+ */
class LDAPRunner extends AbstractServerTest
{
/**
@@ -186,11 +251,6 @@
// Load a demo ldif file
importLdif(this.getClass().getResourceAsStream("init.ldif"));
-
- XWikiLDAPConnection connection = new XWikiLDAPConnection();
-
- connection.open("localhost", this.port, "cn=Horatio
Hornblower,ou=people,o=sevenSeas",
- "pass", null, false);
}
/**
_______________________________________________
notifications mailing list
[email protected]
http://lists.xwiki.org/mailman/listinfo/notifications