Search in sources :

Example 1 with SponsorshipExpirationInAMonth

use of cz.metacentrum.perun.audit.events.ExpirationNotifScheduler.SponsorshipExpirationInAMonth in project perun by CESNET.

the class ExpirationNotifSchedulerTest method testSponsorshipExpirationIsAuditedAMonthBefore.

@Test
public void testSponsorshipExpirationIsAuditedAMonthBefore() throws Exception {
    System.out.println(CLASS_NAME + "testSponsorshipExpirationIsAuditedAMonthBefore");
    LocalDate today = LocalDate.of(2020, 2, 2);
    when(spyScheduler.getCurrentLocalDate()).thenReturn(today);
    Member member = setUpMember();
    User sponsor = perun.getUsersManagerBl().getUserByMember(session, setUpMember());
    AuthzResolverBlImpl.setRole(session, sponsor, vo, Role.SPONSOR);
    LocalDate nextDay = today.plusDays(28);
    perun.getMembersManagerBl().setSponsorshipForMember(session, member, sponsor, nextDay);
    ReflectionTestUtils.invokeMethod(spyScheduler, "auditSponsorshipExpirations");
    EnrichedSponsorship es = new EnrichedSponsorship();
    es.setSponsoredMember(perun.getMembersManagerBl().getMemberById(session, member.getId()));
    es.setSponsor(perun.getUsersManagerBl().getUserById(session, sponsor.getId()));
    AuditEvent expectedEvent = new SponsorshipExpirationInAMonth(es);
    verify(auditerMock).log(any(), eq(expectedEvent));
}
Also used : User(cz.metacentrum.perun.core.api.User) RichUser(cz.metacentrum.perun.core.api.RichUser) EnrichedSponsorship(cz.metacentrum.perun.core.api.EnrichedSponsorship) SponsorshipExpirationInAMonth(cz.metacentrum.perun.audit.events.ExpirationNotifScheduler.SponsorshipExpirationInAMonth) AuditEvent(cz.metacentrum.perun.audit.events.AuditEvent) LocalDate(java.time.LocalDate) Member(cz.metacentrum.perun.core.api.Member) Test(org.junit.Test)

Example 2 with SponsorshipExpirationInAMonth

use of cz.metacentrum.perun.audit.events.ExpirationNotifScheduler.SponsorshipExpirationInAMonth in project perun by CESNET.

the class ExpirationNotifScheduler method auditSponsorshipExpirations.

/**
 * Logs information about incoming sponsorship expirations.
 * 1,7,14 days in advance, logs the SponsorshipExpirationInDays event
 * 28 days in advance, logs the SponsorshipExpirationInAMonth event
 */
private void auditSponsorshipExpirations() {
    IntStream.of(1, 7, 14).forEach(this::auditSponsorshipExpirationsInDays);
    // need to use 28 days instead of plusMonth(1), otherwise, some days might be skipped or
    // processed multiple times
    LocalDate nextMonth = getCurrentLocalDate().plusDays(28);
    auditSponsorshipExpirationsForDate(nextMonth, sponsorship -> perun.getAuditer().log(sess, new SponsorshipExpirationInAMonth(sponsorship)));
}
Also used : SponsorshipExpirationInAMonth(cz.metacentrum.perun.audit.events.ExpirationNotifScheduler.SponsorshipExpirationInAMonth) LocalDate(java.time.LocalDate)

Aggregations

SponsorshipExpirationInAMonth (cz.metacentrum.perun.audit.events.ExpirationNotifScheduler.SponsorshipExpirationInAMonth)2 LocalDate (java.time.LocalDate)2 AuditEvent (cz.metacentrum.perun.audit.events.AuditEvent)1 EnrichedSponsorship (cz.metacentrum.perun.core.api.EnrichedSponsorship)1 Member (cz.metacentrum.perun.core.api.Member)1 RichUser (cz.metacentrum.perun.core.api.RichUser)1 User (cz.metacentrum.perun.core.api.User)1 Test (org.junit.Test)1