You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lenya.apache.org by an...@apache.org on 2006/02/20 12:45:24 UTC
svn commit: r379103 - in /lenya/trunk/src: targets/
test/org/apache/lenya/ac/file/ test/org/apache/lenya/ac/impl/
test/org/apache/lenya/cms/ test/org/apache/lenya/cms/workflow/
Author: andreas
Date: Mon Feb 20 03:45:19 2006
New Revision: 379103
URL: http://svn.apache.org/viewcvs?rev=379103&view=rev
Log:
Fixed some tests
Modified:
lenya/trunk/src/targets/test-build.xml
lenya/trunk/src/test/org/apache/lenya/ac/file/FileGroupTest.java
lenya/trunk/src/test/org/apache/lenya/ac/file/FileRoleTest.java
lenya/trunk/src/test/org/apache/lenya/ac/impl/AccessControlTest.java
lenya/trunk/src/test/org/apache/lenya/ac/impl/PolicyManagerTest.java
lenya/trunk/src/test/org/apache/lenya/ac/impl/UserManagerTest.java
lenya/trunk/src/test/org/apache/lenya/cms/LenyaTestCase.java
lenya/trunk/src/test/org/apache/lenya/cms/workflow/WorkflowTest.java
Modified: lenya/trunk/src/targets/test-build.xml
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/targets/test-build.xml?rev=379103&r1=379102&r2=379103&view=diff
==============================================================================
--- lenya/trunk/src/targets/test-build.xml (original)
+++ lenya/trunk/src/targets/test-build.xml Mon Feb 20 03:45:19 2006
@@ -183,8 +183,8 @@
<test name="org.apache.lenya.ac.ldap.LDAPUserTest" todir="${junit.dir}"/>
<test name="org.apache.lenya.cms.rc.RCMLTest" todir="${junit.dir}"/>
<test name="org.apache.lenya.cms.rc.RevisionControllerTest" todir="${junit.dir}"/>
- <test name="org.apache.lenya.cms.workflow.WorkflowTest" todir="${junit.dir}"/>
-->
+ <test name="org.apache.lenya.cms.workflow.WorkflowTest" todir="${junit.dir}"/>
</junit>
</target>
Modified: lenya/trunk/src/test/org/apache/lenya/ac/file/FileGroupTest.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/test/org/apache/lenya/ac/file/FileGroupTest.java?rev=379103&r1=379102&r2=379103&view=diff
==============================================================================
--- lenya/trunk/src/test/org/apache/lenya/ac/file/FileGroupTest.java (original)
+++ lenya/trunk/src/test/org/apache/lenya/ac/file/FileGroupTest.java Mon Feb 20 03:45:19 2006
@@ -77,8 +77,9 @@
* Test getGroup
*
* @return a <code>FileGroup</code>
+ * @throws AccessControlException
*/
- protected FileGroup getGroup() {
+ protected FileGroup getGroup() throws AccessControlException {
File configurationDirectory = getAccreditablesDirectory();
System.out.println("Configuration directory: " + configurationDirectory);
FileGroup group = new FileGroup(configurationDirectory, GROUP_ID);
@@ -87,8 +88,9 @@
/**
* Tests the removeAllMembers() method.
+ * @throws AccessControlException
*/
- public void testRemoveAllMembers() {
+ public void testRemoveAllMembers() throws AccessControlException {
Group group = getGroup();
Groupable members[] = group.getMembers();
group.removeAllMembers();
Modified: lenya/trunk/src/test/org/apache/lenya/ac/file/FileRoleTest.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/test/org/apache/lenya/ac/file/FileRoleTest.java?rev=379103&r1=379102&r2=379103&view=diff
==============================================================================
--- lenya/trunk/src/test/org/apache/lenya/ac/file/FileRoleTest.java (original)
+++ lenya/trunk/src/test/org/apache/lenya/ac/file/FileRoleTest.java Mon Feb 20 03:45:19 2006
@@ -69,8 +69,9 @@
/**
* DOCUMENT ME!
+ * @throws AccessControlException
*/
- final public void testGetId() {
+ final public void testGetId() throws AccessControlException {
String id = "test";
File configDir = getAccreditablesDirectory();
FileRole role = new FileRole(configDir, id);
@@ -79,8 +80,9 @@
/**
* Test for boolean equals(Object)
+ * @throws AccessControlException
*/
- final public void testEqualsObject() {
+ final public void testEqualsObject() throws AccessControlException {
String name = "test";
File configDir = getAccreditablesDirectory();
FileRole role1 = new FileRole(configDir, name);
Modified: lenya/trunk/src/test/org/apache/lenya/ac/impl/AccessControlTest.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/test/org/apache/lenya/ac/impl/AccessControlTest.java?rev=379103&r1=379102&r2=379103&view=diff
==============================================================================
--- lenya/trunk/src/test/org/apache/lenya/ac/impl/AccessControlTest.java (original)
+++ lenya/trunk/src/test/org/apache/lenya/ac/impl/AccessControlTest.java Mon Feb 20 03:45:19 2006
@@ -22,6 +22,7 @@
import java.io.File;
import org.apache.avalon.framework.service.ServiceSelector;
+import org.apache.cocoon.environment.Session;
import org.apache.lenya.ac.AccessControlException;
import org.apache.lenya.ac.AccessControllerResolver;
import org.apache.lenya.ac.AccreditableManager;
@@ -29,8 +30,6 @@
import org.apache.lenya.ac.PolicyManager;
import org.apache.lenya.ac.User;
import org.apache.lenya.ac.file.FileAccreditableManager;
-import org.apache.lenya.ac.file.FilePolicyManager;
-import org.apache.lenya.cms.ac.DocumentPolicyManagerWrapper;
import org.apache.lenya.cms.ac.PublicationAccessControllerResolver;
import org.apache.lenya.cms.publication.Publication;
import org.apache.lenya.cms.publication.PublicationUtil;
@@ -45,8 +44,34 @@
private ServiceSelector accessControllerResolverSelector;
private AccessControllerResolver accessControllerResolver;
private DefaultAccessController accessController;
+
+ protected void login(String userId) throws AccessControlException {
+
+ User user = getAccreditableManager().getUserManager().getUser(userId);
+
+ if (user == null) {
+ throw new AccessControlException("The user [" + userId + "] does not exist!");
+ }
+
+ getAccessController().setupIdentity(getRequest());
+
+ Session session = getRequest().getSession();
+ Identity identity = (Identity) session.getAttribute(Identity.class.getName());
+
+ if (!identity.contains(user)) {
+ User oldUser = identity.getUser();
+ if (oldUser != null) {
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug("Removing user [" + oldUser + "] from identity.");
+ }
+ identity.removeIdentifiable(oldUser);
+ }
+ identity.addIdentifiable(user);
+ }
+
+ getAccessController().authorize(getRequest());
- private File accreditablesDirectory;
+ }
/**
* Returns the access controller.
@@ -81,15 +106,6 @@
assertNotNull(this.accessController);
getLogger().info("Resolved access controller: [" + this.accessController.getClass() + "]");
- File servletContext = pub.getServletContext();
- DocumentPolicyManagerWrapper wrapper = (DocumentPolicyManagerWrapper) this.accessController.getPolicyManager();
- FilePolicyManager policyManager = (FilePolicyManager) wrapper.getPolicyManager();
- policyManager.setPoliciesDirectory(servletContext);
-
- this.accreditablesDirectory = new File(pub.getDirectory(), "config/ac/passwd".replace('/',
- File.separatorChar));
- ((FileAccreditableManager) this.accessController.getAccreditableManager()).setConfigurationDirectory(this.accreditablesDirectory);
-
}
/**
@@ -144,13 +160,11 @@
protected AccreditableManager getAccreditableManager() {
return getAccessController().getAccreditableManager();
}
-
- /**
- * Returns the directories where accreditables are stored.
- * @return A file.
- */
- protected File getAccreditablesDirectory() {
- return this.accreditablesDirectory;
+
+ protected File getAccreditablesDirectory() throws AccessControlException {
+ FileAccreditableManager accrMgr = (FileAccreditableManager) getAccreditableManager();
+ return accrMgr.getConfigurationDirectory();
}
+
}
Modified: lenya/trunk/src/test/org/apache/lenya/ac/impl/PolicyManagerTest.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/test/org/apache/lenya/ac/impl/PolicyManagerTest.java?rev=379103&r1=379102&r2=379103&view=diff
==============================================================================
--- lenya/trunk/src/test/org/apache/lenya/ac/impl/PolicyManagerTest.java (original)
+++ lenya/trunk/src/test/org/apache/lenya/ac/impl/PolicyManagerTest.java Mon Feb 20 03:45:19 2006
@@ -19,8 +19,6 @@
package org.apache.lenya.ac.impl;
-import junit.textui.TestRunner;
-
import org.apache.lenya.ac.AccessControlException;
import org.apache.lenya.ac.Policy;
import org.apache.lenya.ac.PolicyManager;
Modified: lenya/trunk/src/test/org/apache/lenya/ac/impl/UserManagerTest.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/test/org/apache/lenya/ac/impl/UserManagerTest.java?rev=379103&r1=379102&r2=379103&view=diff
==============================================================================
--- lenya/trunk/src/test/org/apache/lenya/ac/impl/UserManagerTest.java (original)
+++ lenya/trunk/src/test/org/apache/lenya/ac/impl/UserManagerTest.java Mon Feb 20 03:45:19 2006
@@ -22,6 +22,7 @@
import org.apache.lenya.ac.AccessControlException;
import org.apache.lenya.ac.Group;
import org.apache.lenya.ac.User;
+import org.apache.lenya.ac.UserManager;
import org.apache.lenya.ac.UserType;
import org.apache.lenya.ac.file.FileAccreditableManager;
import org.apache.lenya.ac.file.FileGroup;
@@ -49,10 +50,7 @@
* @throws AccessControlException if an error occurs
*/
final public void testInstance() throws AccessControlException {
- File configDir = getAccreditablesDirectory();
- UserType[] userTypes = { FileAccreditableManager.getDefaultUserType() };
- FileUserManager _manager = FileUserManager.instance(configDir, userTypes,
- getLogger());
+ UserManager _manager = getAccreditableManager().getUserManager();
assertNotNull(_manager);
}
@@ -61,7 +59,8 @@
* @throws AccessControlException if an error occurs
*/
final public void testLoadConfig() throws AccessControlException {
- File configDir = getAccreditablesDirectory();
+ FileAccreditableManager accreditableManager = (FileAccreditableManager) getAccreditableManager();
+ File configDir = accreditableManager.getConfigurationDirectory();
String userName = "alice";
String editorGroupId = "editorGroup";
@@ -93,9 +92,7 @@
user.save();
FileGroupManager groupManager = null;
- UserType[] userTypes = { FileAccreditableManager.getDefaultUserType() };
- FileUserManager userManager = FileUserManager.instance(configDir, userTypes,
- getLogger());
+ UserManager userManager = getAccreditableManager().getUserManager();
assertNotNull(userManager);
groupManager = FileGroupManager.instance(configDir, getLogger());
@@ -113,7 +110,8 @@
* @throws AccessControlException if an error occurs
*/
final public void testGetUser() throws AccessControlException {
- File configDir = getAccreditablesDirectory();
+ FileAccreditableManager accrMgr = (FileAccreditableManager) getAccreditableManager();
+ File configDir = accrMgr.getConfigurationDirectory();
String userName = "testuser";
FileUser user = new FileUser(configDir, userName, "Alice in Wonderland",
"alice@wonderland.com", "secret");
Modified: lenya/trunk/src/test/org/apache/lenya/cms/LenyaTestCase.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/test/org/apache/lenya/cms/LenyaTestCase.java?rev=379103&r1=379102&r2=379103&view=diff
==============================================================================
--- lenya/trunk/src/test/org/apache/lenya/cms/LenyaTestCase.java (original)
+++ lenya/trunk/src/test/org/apache/lenya/cms/LenyaTestCase.java Mon Feb 20 03:45:19 2006
@@ -39,7 +39,7 @@
public class LenyaTestCase extends ContainerTestCase {
protected DefaultContext context;
-
+
protected void addContext(DefaultContext context) {
super.addContext(context);
@@ -71,7 +71,12 @@
context.put(Constants.CONTEXT_CLASSPATH, getClassPath(contextRoot));
// context.put(Constants.CONTEXT_CONFIG_URL, conf.toURL());
context.put(Constants.CONTEXT_DEFAULT_ENCODING, "ISO-8859-1");
-
+ }
+
+ private Request request = null;
+
+ protected Request getRequest() {
+ return this.request;
}
protected void prepare() throws Exception {
@@ -88,11 +93,10 @@
SourceResolver resolver = (SourceResolver) getManager().lookup(SourceResolver.ROLE);
MockEnvironment env = new MockEnvironment(resolver);
- String contextRoot = System.getProperty("contextRoot");
String pathInfo = getWebappUrl();
- Request request = new CommandLineRequest(env, contextRoot, "", pathInfo);
- context.put("object-model.request", request);
+ this.request = new CommandLineRequest(env, "", "", pathInfo);
+ context.put("object-model.request", this.request);
}
protected String getWebappUrl() {
Modified: lenya/trunk/src/test/org/apache/lenya/cms/workflow/WorkflowTest.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/test/org/apache/lenya/cms/workflow/WorkflowTest.java?rev=379103&r1=379102&r2=379103&view=diff
==============================================================================
--- lenya/trunk/src/test/org/apache/lenya/cms/workflow/WorkflowTest.java (original)
+++ lenya/trunk/src/test/org/apache/lenya/cms/workflow/WorkflowTest.java Mon Feb 20 03:45:19 2006
@@ -19,17 +19,7 @@
package org.apache.lenya.cms.workflow;
-import java.io.File;
-
-import org.apache.avalon.framework.container.ContainerUtil;
-import org.apache.avalon.framework.context.DefaultContext;
-import org.apache.cocoon.environment.Request;
-import org.apache.cocoon.environment.commandline.CommandLineRequest;
-import org.apache.cocoon.environment.mock.MockEnvironment;
-import org.apache.excalibur.source.SourceResolver;
import org.apache.lenya.ac.Identity;
-import org.apache.lenya.ac.Policy;
-import org.apache.lenya.ac.Role;
import org.apache.lenya.ac.User;
import org.apache.lenya.ac.impl.AccessControlTest;
import org.apache.lenya.cms.publication.Document;
@@ -37,7 +27,6 @@
import org.apache.lenya.cms.publication.Publication;
import org.apache.lenya.cms.publication.PublicationUtil;
import org.apache.lenya.cms.repository.Session;
-import org.apache.lenya.workflow.WorkflowManager;
import org.apache.lenya.workflow.Workflowable;
/**
@@ -46,7 +35,7 @@
*/
public class WorkflowTest extends AccessControlTest {
- private static final String variableName = "is-live";
+ private static final String variableName = "is_live";
protected static final String URL = "/authoring/index.html";
protected String getWebappUrl() {
@@ -63,74 +52,54 @@
DocumentIdentityMap map = getIdentityMap();
Document document = map.getFromURL(url);
- File configDir = new File(publication.getDirectory(), "config" + File.separator + "ac"
- + File.separator + "passwd");
- assertTrue(configDir.exists());
-
- Policy policy = getPolicyManager().getPolicy(getAccreditableManager(), url);
-
- WorkflowManager resolver = null;
- try {
- resolver = (WorkflowManager) getManager().lookup(WorkflowManager.ROLE);
-
- String[] emptyRoles = {};
-
- for (int situationIndex = 0; situationIndex < situations.length; situationIndex++) {
-
- Identity identity = new Identity();
- ContainerUtil.enableLogging(identity, getLogger());
- User user = getAccreditableManager().getUserManager()
- .getUser(situations[situationIndex].getUser());
- ContainerUtil.enableLogging(user, getLogger());
- identity.addIdentifiable(user);
-
- Role[] roles = policy.getRoles(identity);
- getLogger().info("Roles:");
-
- for (int roleIndex = 0; roleIndex < roles.length; roleIndex++) {
- getLogger().info(" " + roles[roleIndex]);
- }
-
- String[] roleIds = new String[roles.length];
- for (int i = 0; i < roles.length; i++) {
- roleIds[i] = roles[i].getId();
- }
- Session session = new Session(map.getIdentityMap(), identity, getLogger());
- Workflowable instance = new DocumentWorkflowable(getManager(),
- session,
- document,
- getLogger());
- assertNotNull(instance);
-
- if (situationIndex > 0) {
- getLogger().info("Current state: " + instance.getLatestVersion().getState());
- }
-
- WorkflowUtil.invoke(getManager(),
- session,
- getLogger(),
- document,
- situations[situationIndex].getEvent());
-
- assertTrue(instance.getLatestVersion().getValue(variableName) == situations[situationIndex].getValue());
-
- getLogger().info("Variable: " + variableName + " = "
- + instance.getLatestVersion().getValue(variableName));
- getLogger().info("------------------------------------------------------");
+ document.getRepositoryNode().lock();
+
+ for (int situationIndex = 0; situationIndex < situations.length; situationIndex++) {
+
+ login(situations[situationIndex].getUser());
+
+ Identity identity = (Identity) getRequest().getSession()
+ .getAttribute(Identity.class.getName());
+ User user = identity.getUser();
+ getLogger().info("User: [" + user + "]");
+
+ Session session = new Session(map.getIdentityMap(), identity, getLogger());
+ Workflowable instance = new DocumentWorkflowable(getManager(),
+ session,
+ document,
+ getLogger());
+ assertNotNull(instance);
+
+ if (situationIndex > 0) {
+ getLogger().info("Current state: " + instance.getLatestVersion().getState());
}
- } finally {
- // this.manager.release(resolver);
+
+ String event = situations[situationIndex].getEvent();
+
+ getLogger().info("Event: " + event);
+
+ WorkflowUtil.invoke(getManager(), session, getLogger(), document, event);
+
+ boolean value = instance.getLatestVersion().getValue(variableName);
+
+ getLogger().info("Variable: " + variableName + " = " + value);
+ getLogger().info("------------------------------------------------------");
+
+ assertEquals(value, situations[situationIndex].getValue());
+
}
+ document.getRepositoryNode().unlock();
+
getLogger().info("Test completed.");
}
private static final TestSituation[] situations = {
new TestSituation("lenya", "submit", false),
- new TestSituation("roger", "reject", false),
+ new TestSituation("alice", "reject", false),
new TestSituation("lenya", "submit", false),
- new TestSituation("roger", "publish", true),
- new TestSituation("roger", "deactivate", false) };
+ new TestSituation("alice", "publish", true),
+ new TestSituation("alice", "deactivate", false) };
/**
* A test situation.
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@lenya.apache.org
For additional commands, e-mail: commits-help@lenya.apache.org