use of com.evolveum.midpoint.repo.sql.util.SimpleTaskAdapter in project midpoint by Evolveum.
the class AuditTest method test110AuditSecond.
@Test
public void test110AuditSecond() throws Exception {
LOGGER.info("===[ test110AuditSecond ]===");
// WHEN
AuditEventRecord record = new AuditEventRecord();
record.addPropertyValue("prop", "val");
LOGGER.info("Adding audit record {}", record);
auditService.audit(record, new SimpleTaskAdapter());
// THEN
System.out.println("Record written:\n" + record.debugDump());
System.out.println("Repo ID: " + record.getRepoId());
AuditEventRecord loaded = getAuditEventRecord(2, 1);
System.out.println("Record loaded:\n" + loaded.debugDump());
System.out.println("Repo ID: " + loaded.getRepoId());
assertEquals("Wrong # of properties", 1, loaded.getProperties().size());
assertEquals("Wrong prop values", new HashSet<>(Collections.singletonList("val")), loaded.getPropertyValues("prop"));
assertEquals("Wrong # of references", 0, loaded.getReferences().size());
}
use of com.evolveum.midpoint.repo.sql.util.SimpleTaskAdapter in project midpoint by Evolveum.
the class AuditTest method test100AuditSimple.
@Test
public void test100AuditSimple() throws Exception {
LOGGER.info("===[ test100AuditSimple ]===");
// 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, new PolyString("user1.1"));
AuditReferenceValue refVal1_2 = new AuditReferenceValue("oid1.2", RoleType.COMPLEX_TYPE, new PolyString("role1.2"));
AuditReferenceValue refVal2 = new AuditReferenceValue("oid2", null, new PolyString("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 SimpleTaskAdapter());
// THEN
System.out.println("Record written:\n" + record.debugDump());
System.out.println("Repo ID: " + record.getRepoId());
AuditEventRecord loaded = getAuditEventRecord(1, 0);
System.out.println("Record loaded:\n" + loaded.debugDump());
System.out.println("Repo ID: " + loaded.getRepoId());
assertEquals("Wrong # of properties", 3, loaded.getProperties().size());
assertEquals("Wrong prop1 values", new HashSet<>(Arrays.asList("val1.1", "val1.2")), loaded.getPropertyValues("prop1"));
assertEquals("Wrong prop2 values", new HashSet<>(Collections.singletonList("val2")), loaded.getPropertyValues("prop2"));
assertEquals("Wrong prop3 values", new HashSet<>(Collections.singletonList(null)), loaded.getPropertyValues("prop3"));
assertEquals("Wrong # of references", 3, loaded.getReferences().size());
assertEquals("Wrong ref1 values", new HashSet<>(Arrays.asList(refVal1_1, refVal1_2)), loaded.getReferenceValues("ref1"));
assertEquals("Wrong ref2 values", new HashSet<>(Collections.singletonList(refVal2)), loaded.getReferenceValues("ref2"));
assertEquals("Wrong ref3 values", new HashSet<>(Collections.singletonList(refVal3)), loaded.getReferenceValues("ref3"));
}
use of com.evolveum.midpoint.repo.sql.util.SimpleTaskAdapter 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 Object[] { new Date(timestamp) });
auditService.audit(record, new SimpleTaskAdapter());
calendar.add(Calendar.HOUR_OF_DAY, 1);
}
Session session = getFactory().openSession();
try {
session.beginTransaction();
Query query = session.createQuery("select count(*) from " + RAuditEventRecord.class.getSimpleName());
Long count = (Long) query.uniqueResult();
AssertJUnit.assertEquals(3L, (long) count);
session.getTransaction().commit();
} finally {
session.close();
}
}
Aggregations