Minor Audit test changes

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@16015 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Derek Hulley
2009-09-01 14:37:26 +00:00
parent 09f8a1b501
commit 1793a46d7c
4 changed files with 30 additions and 17 deletions

View File

@@ -28,6 +28,7 @@ import java.io.Serializable;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.alfresco.repo.audit.model.AuditApplication;
import org.alfresco.repo.audit.model._3.AuditPath; import org.alfresco.repo.audit.model._3.AuditPath;
import org.alfresco.service.cmr.audit.AuditInfo; import org.alfresco.service.cmr.audit.AuditInfo;
import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeRef;
@@ -87,32 +88,38 @@ public interface AuditComponent
* the same root path. * the same root path.
* <p/> * <p/>
* The name of the application controls part of the audit model will be used. The root path must * The name of the application controls part of the audit model will be used. The root path must
* start with the matching <b>key</b> attribute that was declared for the matching * start with the path separator '/' ({@link AuditApplication#AUDIT_PATH_SEPARATOR}) and the matching
* <b>Application</b> element in the audit configuration. * <b>key</b> attribute that was declared for the <b>Application</b> element in the audit configuration.
* <p/> * <p/>
* This is a read-write method. Client code must wrap calls in the appropriate transactional wrappers. * This is a read-write method. Client code must wrap calls in the appropriate transactional wrappers.
* *
* @param applicationName the name of the application to log against * @param applicationName the name of the application to log against
* @param rootPath a base path of {@link AuditPath} key entries concatenated with <b>.</b> (period) * @param rootPath a base path of {@link AuditPath} key entries concatenated with
* @return Returns the unique session * {@link AuditApplication#AUDIT_PATH_SEPARATOR}.
* @return Returns the unique session or <tt>null</tt> if no session was created
* @throws IllegalStateException if there is not a writable transaction present * @throws IllegalStateException if there is not a writable transaction present
*/ */
AuditSession startAuditSession(String applicationName, String rootPath); AuditSession startAuditSession(String applicationName, String rootPath);
/** /**
* {@inheritDoc #startAuditSession(String, String)} * {@inheritDoc AuditComponent#startAuditSession(String, String)}
* @param applicationName the name of the application to log against
* @param rootPath a base path of {@link AuditPath} key entries concatenated with the path separator
* '/' ({@link AuditApplication#AUDIT_PATH_SEPARATOR})
* @param values values to associate with the session. These values will override or * @param values values to associate with the session. These values will override or
* complement generated session-specific values * complement generated session-specific values
* @param rootPath a base path of {@link AuditPath} key entries concatenated with
* {@link AuditApplication#AUDIT_PATH_SEPARATOR}.
* @throws IllegalStateException if there is not a writable transaction present * @throws IllegalStateException if there is not a writable transaction present
*/ */
AuditSession startAuditSession(String applicationName, String rootPath, Map<String, Serializable> values); AuditSession startAuditSession(String applicationName, String rootPath, Map<String, Serializable> values);
/** /**
* Record a set of values against the given session. The map is a path (starting with '/') relative * Record a set of values against the given session. The map is a path - starting with '/'
* to the root path given when {@link #startAuditSession(String, String) starting the session}. All * ({@link AuditApplication#AUDIT_PATH_SEPARATOR}), relative to the root path given when
* resulting path values (session root path + map entry paths) must have data recorder entries and * {@link #startAuditSession(String, String) starting the session}. All resulting path values
* be enabled for data to be recorded. * (session root path + map entry paths) must have data recorder entries and be enabled for data to be recorded.
* <p/> * <p/>
* The return values reflect what was actually persisted and is controlled by the data extractors * The return values reflect what was actually persisted and is controlled by the data extractors
* defined in the audit configuration. * defined in the audit configuration.

View File

@@ -60,6 +60,7 @@ import org.springframework.util.ResourceUtils;
public class AuditComponentTest extends TestCase public class AuditComponentTest extends TestCase
{ {
private static final String APPLICATION_TEST = "Alfresco Test"; private static final String APPLICATION_TEST = "Alfresco Test";
private static final String APPLICATION_ACTIONS_TEST = "Actions Test";
private static ApplicationContext ctx = ApplicationContextHelper.getApplicationContext(); private static ApplicationContext ctx = ApplicationContextHelper.getApplicationContext();
@@ -206,8 +207,8 @@ public class AuditComponentTest extends TestCase
{ {
public Map<String, Serializable> execute() throws Throwable public Map<String, Serializable> execute() throws Throwable
{ {
String actionPath = AuditApplication.buildPath("test/actions", action); String actionPath = AuditApplication.buildPath("actions-test/actions", action);
AuditSession session = auditComponent.startAuditSession(APPLICATION_TEST, actionPath); AuditSession session = auditComponent.startAuditSession(APPLICATION_ACTIONS_TEST, actionPath);
return auditComponent.audit(session, adjustedValues); return auditComponent.audit(session, adjustedValues);
} }
@@ -215,6 +216,9 @@ public class AuditComponentTest extends TestCase
return transactionService.getRetryingTransactionHelper().doInTransaction(auditCallback); return transactionService.getRetryingTransactionHelper().doInTransaction(auditCallback);
} }
/**
* Utility method to compare a 'results' map with a map of expected values
*/
private void checkAuditMaps(Map<String, Serializable> result, Map<String, Serializable> expected) private void checkAuditMaps(Map<String, Serializable> result, Map<String, Serializable> expected)
{ {
Map<String, Serializable> copyResult = new HashMap<String, Serializable>(result); Map<String, Serializable> copyResult = new HashMap<String, Serializable>(result);
@@ -275,10 +279,10 @@ public class AuditComponentTest extends TestCase
Map<String, Serializable> result = auditTestAction("action-01", nodeRef, parameters); Map<String, Serializable> result = auditTestAction("action-01", nodeRef, parameters);
Map<String, Serializable> expected = new HashMap<String, Serializable>(); Map<String, Serializable> expected = new HashMap<String, Serializable>();
expected.put("/test/actions/action-01/context-node/noderef", nodeRef); expected.put("/actions-test/actions/action-01/context-node/noderef", nodeRef);
expected.put("/test/actions/action-01/params/A/value", valueA); expected.put("/actions-test/actions/action-01/params/A/value", valueA);
expected.put("/test/actions/action-01/params/B/value", valueB); expected.put("/actions-test/actions/action-01/params/B/value", valueB);
expected.put("/test/actions/action-01/params/C/value", valueC); expected.put("/actions-test/actions/action-01/params/C/value", valueC);
// Check // Check
checkAuditMaps(result, expected); checkAuditMaps(result, expected);

View File

@@ -26,7 +26,6 @@ package org.alfresco.service.cmr.audit;
import java.util.List; import java.util.List;
import org.alfresco.repo.audit.AuditState;
import org.alfresco.service.NotAuditable; import org.alfresco.service.NotAuditable;
import org.alfresco.service.PublicService; import org.alfresco.service.PublicService;
import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeRef;
@@ -43,7 +42,6 @@ import org.alfresco.service.cmr.repository.NodeRef;
@PublicService @PublicService
public interface AuditService public interface AuditService
{ {
/** /**
* Add an application audit entry. * Add an application audit entry.
* *

View File

@@ -64,6 +64,10 @@
</AuditPath> </AuditPath>
</AuditPath> </AuditPath>
</AuditPath> </AuditPath>
</Application>
<Application name="Actions Test" key="actions-test">
<GenerateValue key="time" dataGenerator="systemTime" scope="SESSION"/>
<AuditPath key="actions"> <AuditPath key="actions">
<AuditPath key="action-01"> <AuditPath key="action-01">
<AuditPath key="context-node"> <AuditPath key="context-node">