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);
}
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;
}
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));
}
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));
}
Aggregations