Search in sources :

Example 11 with NullTaskImpl

use of com.evolveum.midpoint.task.api.test.NullTaskImpl in project midpoint by Evolveum.

the class CleanupTest method prepareAuditEventRecords.

private void prepareAuditEventRecords() throws Exception {
    Calendar calendar = create_2013_07_12_12_00_Calendar();
    for (int i = 0; i < 3; i++) {
        long timestamp = calendar.getTimeInMillis();
        AuditEventRecord record = new AuditEventRecord();
        record.addDelta(createObjectDeltaOperation(i));
        record.setTimestamp(timestamp);
        record.addPropertyValue("prop1", "val1");
        record.addReferenceValue("ref1", ObjectTypeUtil.createObjectRef("oid1", ObjectTypes.USER).asReferenceValue());
        logger.info("Adding audit record with timestamp {}", new Date(timestamp));
        auditService.audit(record, new NullTaskImpl(), createOperationResult());
        calendar.add(Calendar.HOUR_OF_DAY, 1);
    }
    assertAndReturnAuditEventRecord(3);
}
Also used : Calendar(java.util.Calendar) AuditEventRecord(com.evolveum.midpoint.audit.api.AuditEventRecord) MAuditEventRecord(com.evolveum.midpoint.repo.sql.audit.beans.MAuditEventRecord) Date(java.util.Date) NullTaskImpl(com.evolveum.midpoint.task.api.test.NullTaskImpl)

Example 12 with NullTaskImpl

use of com.evolveum.midpoint.task.api.test.NullTaskImpl in project midpoint by Evolveum.

the class AuditCleanupPerformanceTest method prepareAuditEventRecords.

private void prepareAuditEventRecords() throws Exception {
    long start = System.currentTimeMillis();
    for (int i = 0; i < RECORDS; ) {
        AuditEventRecord record = new AuditEventRecord();
        record.addDelta(createObjectDeltaOperation(i));
        record.setTimestamp(System.currentTimeMillis());
        record.addPropertyValue("prop1", "val1");
        record.addReferenceValue("ref1", ObjectTypeUtil.createObjectRef("oid1", ObjectTypes.USER).asReferenceValue());
        auditService.audit(record, new NullTaskImpl(), new OperationResult("dummy"));
        i++;
        if (i % 1000 == 0 || i == RECORDS) {
            long duration = System.currentTimeMillis() - start;
            System.out.println(i + " records created in " + duration + " ms (" + duration / i + " ms per record)");
        }
    }
    assertThat(count(QAuditEventRecordMapping.get())).isEqualTo(RECORDS);
}
Also used : OperationResult(com.evolveum.midpoint.schema.result.OperationResult) AuditEventRecord(com.evolveum.midpoint.audit.api.AuditEventRecord) NullTaskImpl(com.evolveum.midpoint.task.api.test.NullTaskImpl)

Example 13 with NullTaskImpl

use of com.evolveum.midpoint.task.api.test.NullTaskImpl in project midpoint by Evolveum.

the class AuditTest method test100AuditSimple.

@Test
public void test100AuditSimple() throws QueryException {
    OperationResult result = createOperationResult();
    when();
    AuditEventRecord record = new AuditEventRecord();
    record.addPropertyValue("prop1", "val1.1");
    record.addPropertyValue("prop1", "val1.2");
    record.addPropertyValue("prop2", "val2");
    record.addPropertyValue("prop3", null);
    AuditReferenceValue refVal1_1 = new AuditReferenceValue("oid1.1", UserType.COMPLEX_TYPE, poly("user1.1"));
    AuditReferenceValue refVal1_2 = new AuditReferenceValue("oid1.2", RoleType.COMPLEX_TYPE, poly("role1.2"));
    AuditReferenceValue refVal2 = new AuditReferenceValue("oid2", null, poly("object2"));
    AuditReferenceValue refVal3 = new AuditReferenceValue();
    record.addReferenceValue("ref1", refVal1_1);
    record.addReferenceValue("ref1", refVal1_2);
    record.addReferenceValue("ref2", refVal2);
    record.addReferenceValue("ref3", refVal3);
    logger.info("Adding audit record {}", record);
    auditService.audit(record, new NullTaskImpl(), result);
    then();
    System.out.println("Record written:\n" + record.debugDump());
    System.out.println("Repo ID: " + record.getRepoId());
    MAuditEventRecord loaded = getAuditEventRecord(1, 0);
    System.out.println("Record loaded:\n" + loaded);
    assertThat(loaded.properties).withFailMessage("Wrong # of properties").hasSize(3);
    assertThat(loaded.properties.get("prop1")).describedAs("prop1 values").containsExactlyInAnyOrder("val1.1", "val1.2");
    assertThat(loaded.properties.get("prop2")).describedAs("prop2 values").containsExactlyInAnyOrder("val2");
    assertThat(loaded.properties.get("prop3")).describedAs("prop3 values").containsExactlyInAnyOrder((String) null);
    assertThat(loaded.refValues).withFailMessage("Wrong # of references").hasSize(3);
    assertThat(loaded.refValues.get("ref1")).describedAs("ref1 values").flatExtracting(this::toAuditReferenceValue).containsExactlyInAnyOrder(refVal1_1, refVal1_2);
    assertThat(loaded.refValues.get("ref2")).describedAs("ref2 values").flatExtracting(this::toAuditReferenceValue).containsExactlyInAnyOrder(refVal2);
    assertThat(loaded.refValues.get("ref3")).describedAs("ref3 values").flatExtracting(this::toAuditReferenceValue).containsExactlyInAnyOrder(refVal3);
}
Also used : MAuditEventRecord(com.evolveum.midpoint.repo.sql.audit.beans.MAuditEventRecord) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) AuditReferenceValue(com.evolveum.midpoint.audit.api.AuditReferenceValue) QAuditEventRecord(com.evolveum.midpoint.repo.sql.audit.querymodel.QAuditEventRecord) AuditEventRecord(com.evolveum.midpoint.audit.api.AuditEventRecord) MAuditEventRecord(com.evolveum.midpoint.repo.sql.audit.beans.MAuditEventRecord) NullTaskImpl(com.evolveum.midpoint.task.api.test.NullTaskImpl) Test(org.testng.annotations.Test)

Aggregations

NullTaskImpl (com.evolveum.midpoint.task.api.test.NullTaskImpl)13 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)11 AuditEventRecord (com.evolveum.midpoint.audit.api.AuditEventRecord)5 MAuditEventRecord (com.evolveum.midpoint.repo.sql.audit.beans.MAuditEventRecord)4 QAuditEventRecord (com.evolveum.midpoint.repo.sql.audit.querymodel.QAuditEventRecord)3 Test (org.testng.annotations.Test)3 AuditReferenceValue (com.evolveum.midpoint.audit.api.AuditReferenceValue)1 PrismObject (com.evolveum.midpoint.prism.PrismObject)1 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)1 UniformItemPath (com.evolveum.midpoint.prism.path.UniformItemPath)1 ObjectDeltaObject (com.evolveum.midpoint.prism.util.ObjectDeltaObject)1 DirectoryFileObjectResolver (com.evolveum.midpoint.repo.common.DirectoryFileObjectResolver)1 ObjectResolver (com.evolveum.midpoint.repo.common.ObjectResolver)1 ObjectDeltaOperation (com.evolveum.midpoint.schema.ObjectDeltaOperation)1 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)1 Calendar (java.util.Calendar)1 Date (java.util.Date)1