Skip to content

Commit

Permalink
MID-6319: AuditSearchTest skeleton + changes of new AuditService methods
Browse files Browse the repository at this point in the history
  • Loading branch information
virgo47 committed Jun 22, 2020
1 parent a364a90 commit e8de670
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 27 deletions.
Expand Up @@ -73,14 +73,12 @@ default void applyAuditConfiguration(SystemConfigurationAuditType configuration)

// TODO MID-6319 cleanup after done
// see com.evolveum.midpoint.repo.api.RepositoryService.countObjects for javadoc and rephrase it here
<T extends ObjectType> long countObjects(
Class<T> type, ObjectQuery query,
long countObjects(ObjectQuery query,
Collection<SelectorOptions<GetOperationOptions>> options, OperationResult parentResult)
throws SchemaException;

@NotNull
<T extends ObjectType> SearchResultList<PrismObject<T>> searchObjects(
Class<T> type, ObjectQuery query,
SearchResultList<AuditEventRecord> searchObjects(ObjectQuery query,
Collection<SelectorOptions<GetOperationOptions>> options, OperationResult parentResult)
throws SchemaException;
}
Expand Up @@ -186,16 +186,14 @@ public void reindexEntry(AuditEventRecord record) {
}

@Override
public <T extends ObjectType> long countObjects(
Class<T> type, ObjectQuery query,
public long countObjects(ObjectQuery query,
Collection<SelectorOptions<GetOperationOptions>> options, OperationResult parentResult) {
throw new UnsupportedOperationException("countObjects not supported");
}

@Override
@NotNull
public <T extends ObjectType> SearchResultList<PrismObject<T>> searchObjects(
Class<T> type, ObjectQuery query,
public SearchResultList<AuditEventRecord> searchObjects(ObjectQuery query,
Collection<SelectorOptions<GetOperationOptions>> options, OperationResult parentResult) {
throw new UnsupportedOperationException("searchObjects not supported");
}
Expand Down
@@ -0,0 +1,59 @@
/*
* Copyright (c) 2010-2017 Evolveum and contributors
*
* This work is dual-licensed under the Apache License 2.0
* and European Union Public License. See LICENSE file for details.
*/

package com.evolveum.midpoint.repo.sql;

import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ContextConfiguration;
import org.testng.annotations.Test;

import com.evolveum.midpoint.audit.api.AuditEventRecord;
import com.evolveum.midpoint.prism.query.ObjectQuery;
import com.evolveum.midpoint.schema.SearchResultList;
import com.evolveum.midpoint.tools.testng.UnusedTestElement;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.xml.ns._public.common.audit_3.AuditEventRecordType;
import com.evolveum.midpoint.xml.ns._public.common.audit_3.AuditEventTypeType;

// TODO MID-6319 - finish and add to test suite
@UnusedTestElement
@ContextConfiguration(locations = { "../../../../../ctx-test.xml" })
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS)
public class AuditSearchTest extends BaseSQLRepoTest {

@Override
public void initSystem() throws Exception {
// TODO add some sample audits here
}

@Test
public void test100SearchAllAuditEvents() throws SchemaException {
when("Searching audit with query without any conditions");
ObjectQuery query = prismContext.queryFor(AuditEventRecordType.class).build();
SearchResultList<AuditEventRecord> prismObjects =
auditService.searchObjects(query, null, null);

then("All audit events are returned");
System.out.println("prismObjects = " + prismObjects);
// TODO
}

@Test
public void test110SearchAllAuditEventsOfSomeType() throws SchemaException {
when("searching audit filtered by event type");
ObjectQuery query = prismContext.queryFor(AuditEventRecordType.class)
.item(AuditEventRecordType.F_EVENT_TYPE).eq(AuditEventTypeType.ADD_OBJECT)
.build();
SearchResultList<AuditEventRecord> prismObjects =
auditService.searchObjects(query, null, null);

then("only audit events of a particular type are returned");
System.out.println("prismObjects = " + prismObjects);
// TODO
}
}

Expand Up @@ -903,17 +903,18 @@ public void applyAuditConfiguration(SystemConfigurationAuditType configuration)
}

@Override
public <T extends ObjectType> long countObjects(
Class<T> type, ObjectQuery query,
public long countObjects(ObjectQuery query,
Collection<SelectorOptions<GetOperationOptions>> options, OperationResult parentResult) {
// TODO MID-6319
return 0;
}

@Override
@NotNull
public <T extends ObjectType> SearchResultList<PrismObject<T>> searchObjects(
Class<T> type, ObjectQuery query,
public SearchResultList<AuditEventRecord> searchObjects(
ObjectQuery query,
Collection<SelectorOptions<GetOperationOptions>> options, OperationResult parentResult) {
// TODO MID-6319
return new SearchResultList<>();
}
}
Expand Up @@ -17,7 +17,6 @@
import org.jetbrains.annotations.NotNull;

import com.evolveum.midpoint.audit.api.*;
import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.prism.PrismPropertyValue;
import com.evolveum.midpoint.prism.PrismReferenceValue;
import com.evolveum.midpoint.prism.delta.ChangeType;
Expand Down Expand Up @@ -539,16 +538,14 @@ public void setEnabled(boolean enabled) {
}

@Override
public <T extends ObjectType> long countObjects(
Class<T> type, ObjectQuery query,
public long countObjects(ObjectQuery query,
Collection<SelectorOptions<GetOperationOptions>> options, OperationResult parentResult) {
throw new UnsupportedOperationException("countObjects not supported");
}

@Override
@NotNull
public <T extends ObjectType> SearchResultList<PrismObject<T>> searchObjects(
Class<T> type, ObjectQuery query,
public SearchResultList<AuditEventRecord> searchObjects(ObjectQuery query,
Collection<SelectorOptions<GetOperationOptions>> options, OperationResult parentResult) {
throw new UnsupportedOperationException("searchObjects not supported");
}
Expand Down
Expand Up @@ -78,7 +78,7 @@ public void audit(AuditEventRecord record, Task task) {
return;
}

assertCorrectness(record, task);
assertCorrectness(task);
completeRecord(record, task);

for (AuditService service : services) {
Expand Down Expand Up @@ -112,7 +112,7 @@ public void unregisterService(AuditService service) {
services.remove(service);
}

private void assertCorrectness(AuditEventRecord record, Task task) {
private void assertCorrectness(Task task) {
if (task == null) {
LOGGER.warn("Task is null in a call to audit service");
}
Expand Down Expand Up @@ -261,13 +261,13 @@ public void applyAuditConfiguration(SystemConfigurationAuditType configuration)
}

@Override
public <T extends ObjectType> long countObjects(Class<T> type, ObjectQuery query,
public long countObjects(ObjectQuery query,
Collection<SelectorOptions<GetOperationOptions>> options, OperationResult parentResult)
throws SchemaException {
long count = 0;
for (AuditService service : services) {
if (service.supportsRetrieval()) {
long c = service.countObjects(type, query, options, parentResult);
long c = service.countObjects(query, options, parentResult);
count += c;
}
}
Expand All @@ -276,16 +276,15 @@ public <T extends ObjectType> long countObjects(Class<T> type, ObjectQuery query

@Override
@NotNull
public <T extends ObjectType> SearchResultList<PrismObject<T>> searchObjects(
Class<T> type, ObjectQuery query,
public SearchResultList<AuditEventRecord> searchObjects(ObjectQuery query,
Collection<SelectorOptions<GetOperationOptions>> options, OperationResult parentResult)
throws SchemaException {
// TODO: MID-6319 - does it even make sense?
SearchResultList<PrismObject<T>> result = new SearchResultList<>();
// TODO: MID-6319 - does it even make sense to merge multiple results for audit?
SearchResultList<AuditEventRecord> result = new SearchResultList<>();
for (AuditService service : services) {
if (service.supportsRetrieval()) {
SearchResultList<PrismObject<T>> oneResult =
service.searchObjects(type, query, options, parentResult);
SearchResultList<AuditEventRecord> oneResult =
service.searchObjects(query, options, parentResult);
if (!oneResult.isEmpty()) {
result.addAll(oneResult);
}
Expand Down

0 comments on commit e8de670

Please sign in to comment.