Search in sources :

Example 1 with SimpleTaskAdapter

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());
}
Also used : RAuditEventRecord(com.evolveum.midpoint.repo.sql.data.audit.RAuditEventRecord) AuditEventRecord(com.evolveum.midpoint.audit.api.AuditEventRecord) SimpleTaskAdapter(com.evolveum.midpoint.repo.sql.util.SimpleTaskAdapter) Test(org.testng.annotations.Test)

Example 2 with SimpleTaskAdapter

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"));
}
Also used : PolyString(com.evolveum.midpoint.prism.polystring.PolyString) AuditReferenceValue(com.evolveum.midpoint.audit.api.AuditReferenceValue) RAuditEventRecord(com.evolveum.midpoint.repo.sql.data.audit.RAuditEventRecord) AuditEventRecord(com.evolveum.midpoint.audit.api.AuditEventRecord) SimpleTaskAdapter(com.evolveum.midpoint.repo.sql.util.SimpleTaskAdapter) Test(org.testng.annotations.Test)

Example 3 with SimpleTaskAdapter

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();
    }
}
Also used : Query(org.hibernate.Query) Calendar(java.util.Calendar) RAuditEventRecord(com.evolveum.midpoint.repo.sql.data.audit.RAuditEventRecord) AuditEventRecord(com.evolveum.midpoint.audit.api.AuditEventRecord) Date(java.util.Date) SimpleTaskAdapter(com.evolveum.midpoint.repo.sql.util.SimpleTaskAdapter) Session(org.hibernate.Session)

Aggregations

AuditEventRecord (com.evolveum.midpoint.audit.api.AuditEventRecord)3 RAuditEventRecord (com.evolveum.midpoint.repo.sql.data.audit.RAuditEventRecord)3 SimpleTaskAdapter (com.evolveum.midpoint.repo.sql.util.SimpleTaskAdapter)3 Test (org.testng.annotations.Test)2 AuditReferenceValue (com.evolveum.midpoint.audit.api.AuditReferenceValue)1 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)1 Calendar (java.util.Calendar)1 Date (java.util.Date)1 Query (org.hibernate.Query)1 Session (org.hibernate.Session)1