Search in sources :

Example 1 with EnrichedSponsorship

use of cz.metacentrum.perun.core.api.EnrichedSponsorship in project perun by CESNET.

the class AuditMessagesManagerEntryIntegrationTest method testLocalDate.

@Test
public void testLocalDate() throws Exception {
    System.out.println(CLASS_NAME + "testLocalDate");
    AuditMessagesManagerImpl auditMessagesManagerImpl = (AuditMessagesManagerImpl) ReflectionTestUtils.getField(perun.getAuditMessagesManagerBl(), "auditMessagesManagerImpl");
    assertThat(auditMessagesManagerImpl).isNotNull();
    ObjectMapper mapper = (ObjectMapper) ReflectionTestUtils.getField(auditMessagesManagerImpl, "mapper");
    assertThat(mapper).isNotNull();
    AuditEvent event = new SponsorshipEstablished(null, null, LocalDate.MIN);
    testAuditEventMapper(mapper, event);
    EnrichedSponsorship enrichedSponsorship = new EnrichedSponsorship();
    enrichedSponsorship.setValidityTo(LocalDate.MAX);
    AuditEvent event2 = new SponsorshipExpired();
    testAuditEventMapper(mapper, event2);
}
Also used : SponsorshipEstablished(cz.metacentrum.perun.audit.events.MembersManagerEvents.SponsorshipEstablished) EnrichedSponsorship(cz.metacentrum.perun.core.api.EnrichedSponsorship) SponsorshipExpired(cz.metacentrum.perun.audit.events.ExpirationNotifScheduler.SponsorshipExpired) AuditMessagesManagerImpl(cz.metacentrum.perun.core.impl.AuditMessagesManagerImpl) AuditEvent(cz.metacentrum.perun.audit.events.AuditEvent) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Example 2 with EnrichedSponsorship

use of cz.metacentrum.perun.core.api.EnrichedSponsorship in project perun by CESNET.

the class ExpirationNotifScheduler method convertSponsorshipToEnriched.

/**
 * For given sponsorship, get the sponsored member and the sponsor from DB and
 * returns it in the EnrichedSponsorship object.
 *
 * @param sponsorship sponsorship to be converted
 * @return EnrichedSponsorship with the member and sponsor from db
 * @throws UserNotExistsException if there is no user with given sponsor id
 * @throws MemberNotExistsException if there is no member with given sponsored id
 */
private EnrichedSponsorship convertSponsorshipToEnriched(Sponsorship sponsorship) throws UserNotExistsException, MemberNotExistsException {
    EnrichedSponsorship es = new EnrichedSponsorship();
    es.setActive(sponsorship.isActive());
    es.setValidityTo(sponsorship.getValidityTo());
    es.setSponsor(perun.getUsersManagerBl().getUserById(sess, sponsorship.getSponsorId()));
    es.setSponsoredMember(perun.getMembersManagerBl().getMemberById(sess, sponsorship.getSponsoredId()));
    return es;
}
Also used : EnrichedSponsorship(cz.metacentrum.perun.core.api.EnrichedSponsorship)

Example 3 with EnrichedSponsorship

use of cz.metacentrum.perun.core.api.EnrichedSponsorship 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 4 with EnrichedSponsorship

use of cz.metacentrum.perun.core.api.EnrichedSponsorship in project perun by CESNET.

the class ExpirationNotifSchedulerTest method testSponsorshipExpirationIsAuditedInDays.

/**
 * Performs test of sponsorship expiration being audited n days before its expiration.
 *
 * @param days number of days before the expiration
 */
private void testSponsorshipExpirationIsAuditedInDays(int days) throws Exception {
    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(days);
    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 SponsorshipExpirationInDays(es, days);
    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) SponsorshipExpirationInDays(cz.metacentrum.perun.audit.events.ExpirationNotifScheduler.SponsorshipExpirationInDays) AuditEvent(cz.metacentrum.perun.audit.events.AuditEvent) LocalDate(java.time.LocalDate) Member(cz.metacentrum.perun.core.api.Member)

Aggregations

EnrichedSponsorship (cz.metacentrum.perun.core.api.EnrichedSponsorship)4 AuditEvent (cz.metacentrum.perun.audit.events.AuditEvent)3 Member (cz.metacentrum.perun.core.api.Member)2 RichUser (cz.metacentrum.perun.core.api.RichUser)2 User (cz.metacentrum.perun.core.api.User)2 LocalDate (java.time.LocalDate)2 Test (org.junit.Test)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 SponsorshipExpirationInAMonth (cz.metacentrum.perun.audit.events.ExpirationNotifScheduler.SponsorshipExpirationInAMonth)1 SponsorshipExpirationInDays (cz.metacentrum.perun.audit.events.ExpirationNotifScheduler.SponsorshipExpirationInDays)1 SponsorshipExpired (cz.metacentrum.perun.audit.events.ExpirationNotifScheduler.SponsorshipExpired)1 SponsorshipEstablished (cz.metacentrum.perun.audit.events.MembersManagerEvents.SponsorshipEstablished)1 AbstractPerunIntegrationTest (cz.metacentrum.perun.core.AbstractPerunIntegrationTest)1 AuditMessagesManagerImpl (cz.metacentrum.perun.core.impl.AuditMessagesManagerImpl)1