Skip to content

Commit 319c129

Browse files
committed
Initial tests
1 parent e0d4d67 commit 319c129

1 file changed

Lines changed: 37 additions & 13 deletions

File tree

src/org/labkey/test/util/AuditLogHelper.java

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import org.jetbrains.annotations.NotNull;
55
import org.jetbrains.annotations.Nullable;
66
import org.json.JSONException;
7+
import org.labkey.api.collections.CaseInsensitiveHashMap;
78
import org.labkey.remoteapi.CommandException;
89
import org.labkey.remoteapi.Connection;
910
import org.labkey.remoteapi.query.ContainerFilter;
@@ -29,10 +30,10 @@
2930
import java.util.Map;
3031
import java.util.Objects;
3132
import java.util.Set;
32-
import java.util.stream.Stream;
3333

3434
import static java.lang.Integer.parseInt;
3535
import static org.junit.Assert.assertEquals;
36+
import static org.junit.Assert.assertFalse;
3637
import static org.junit.Assert.assertTrue;
3738
import static org.junit.Assert.fail;
3839
import static org.labkey.test.WebDriverWrapper.WAIT_FOR_JAVASCRIPT;
@@ -85,16 +86,19 @@ public enum AuditBehaviorType
8586

8687
public enum AuditEvent
8788
{
88-
SAMPLE_TIMELINE_EVENT("SampleTimelineEvent"),
89-
SOURCES_AUDIT_EVENT("SourcesAuditEvent"), // avaialble with SampleManagement module
89+
ASSAY_AUDIT_EVENT("AssayAuditEvent"), // available with SampleManagement module
90+
ASSAY_RESULT_AUDIT_EVENT("AssayResultAuditEvent"), // available with SampleManagement module
91+
EXPERIMENT_AUDIT_EVENT("ExperimentAuditEvent"),
92+
FILE_SYSTEM_EVENT("FileSystem"),
9093
INVENTORY_AUDIT_EVENT("InventoryAuditEvent"),
9194
LIST_AUDIT_EVENT("ListAuditEvent"),
92-
ASSAY_AUDIT_EVENT("AssayAuditEvent"), // avaialble with SampleManagement module
93-
ASSAY_RESULT_AUDIT_EVENT("AssayResultAuditEvent"), // avaialble with SampleManagement module
94-
EXPERIMENT_AUDIT_EVENT("ExperimentAuditEvent"),
95-
SAMPLE_WORKFLOW_AUDIT_EVENT("SamplesWorkflowAuditEvent"),
95+
PLATE_AUDIT_EVENT("PlateAuditEvent"), // available in Biologics module
96+
PLATE_DATA_AUDIT_EVENT("PlateDataAuditEvent"), // available in Biologics module
97+
PLATE_SET_AUDIT_EVENT("PlateSetAuditEvent"), // available in Biologics module
9698
QUERY_UPDATE_AUDIT_EVENT("QueryUpdateAuditEvent"),
97-
FILE_SYSTEM_EVENT("FileSystem");
99+
SAMPLE_TIMELINE_EVENT("SampleTimelineEvent"),
100+
SAMPLE_WORKFLOW_AUDIT_EVENT("SamplesWorkflowAuditEvent"),
101+
SOURCES_AUDIT_EVENT("SourcesAuditEvent"); // available with SampleManagement module
98102

99103
private final String _name;
100104

@@ -257,16 +261,16 @@ public void checkAuditEventDiffCount(String containerPath, AuditEvent auditEvent
257261
boolean isInventoryUpdateType = event.get("InventoryUpdateType") != null;
258262
int expectedDiffCount = isInventoryUpdateType ? 0 : expectedDiffCounts.get(i);
259263
String dataChangesStr = (String) event.get(eventDiffFieldName);
260-
String[] dataChanges = dataChangesStr != null ? dataChangesStr.split("&") : new String[0];
264+
Map<String, String> dataChanges = decodeValues(dataChangesStr);
261265

262266
// filter out SampleStateLabel as that is not a change, it is added for display purposes
263-
dataChanges = Stream.of(dataChanges).filter(s -> !s.toLowerCase().startsWith("samplestatelabel=")).toArray(String[]::new);
267+
dataChanges.remove("SampleStateLabel");
264268
// filter out RowId as that is not a change, it is added for display purposes
265-
dataChanges = Stream.of(dataChanges).filter(s -> !s.toLowerCase().startsWith("rowid=")).toArray(String[]::new);
269+
dataChanges.remove("RowId");
266270

267271
log("Audit record data changes diff count check (" + eventDiffFieldName + "): " + dataChangesStr);
268-
assertEquals("Audit record data changes did not include the expected number of diffs in " + eventDiffFieldName + ", expected " + expectedDiffCount + " but was " + dataChanges.length + ": " + dataChangesStr,
269-
expectedDiffCount, dataChanges.length);
272+
assertEquals("Audit record data changes did not include the expected number of diffs in " + eventDiffFieldName + ", expected " + expectedDiffCount + " but was " + dataChanges.size() + ": " + dataChangesStr,
273+
expectedDiffCount, dataChanges.size());
270274
}
271275
}
272276

@@ -527,6 +531,26 @@ public String getLogString()
527531
}
528532
}
529533

534+
public static Map<String, String> decodeValues(String recordMapString)
535+
{
536+
if (recordMapString == null || recordMapString.isEmpty())
537+
return Collections.emptyMap();
538+
539+
Map<String, String> recordMap = new CaseInsensitiveHashMap<>();
540+
for (String part : recordMapString.split("&"))
541+
{
542+
String[] keyValue = part.split("=");
543+
assertEquals("Audit record map string does not have expected shape", 2, keyValue.length);
544+
545+
String key = EscapeUtil.decode(keyValue[0]);
546+
assertFalse(String.format("Audit record map already contains key for %s", key), recordMap.containsKey(key));
547+
548+
recordMap.put(key, EscapeUtil.decode(keyValue[1]));
549+
}
550+
551+
return recordMap;
552+
}
553+
530554
/**
531555
* URL-encode fields and values for {@link DetailedAuditEventRow#newValues} or {@link DetailedAuditEventRow#oldValues}
532556
* @param pairs alternating field names and their associated values

0 commit comments

Comments
 (0)