use of cz.metacentrum.perun.core.api.Sponsorship in project perun by CESNET.
the class MembersManagerBlImpl method convertUserToSponsor.
@Override
public Sponsor convertUserToSponsor(PerunSession sess, User user, Member sponsoredMember) {
Sponsor sponsor = new Sponsor(user);
Sponsorship sponsorship;
try {
sponsorship = perunBl.getMembersManagerBl().getSponsorship(sess, sponsoredMember, user);
} catch (SponsorshipDoesNotExistException e) {
throw new InternalErrorException(e);
}
sponsor.setActive(sponsorship.isActive());
sponsor.setValidityTo(sponsorship.getValidityTo());
if (user instanceof RichUser) {
sponsor.setUserAttributes(((RichUser) user).getUserAttributes());
sponsor.setUserExtSources(((RichUser) user).getUserExtSources());
}
return sponsor;
}
use of cz.metacentrum.perun.core.api.Sponsorship in project perun by CESNET.
the class MembersManagerEntryIntegrationTest method getSoonExpiringSponsorshipsReturnsLowerBound.
@Test
public void getSoonExpiringSponsorshipsReturnsLowerBound() throws Exception {
System.out.println(CLASS_NAME + "getSoonExpiringSponsorshipsReturnsLowerBound");
Member member = setUpMember(createdVo);
User sponsor1 = perun.getUsersManagerBl().getUserByMember(sess, setUpSponsor(createdVo));
AuthzResolverBlImpl.setRole(sess, sponsor1, createdVo, Role.SPONSOR);
LocalDate today = LocalDate.of(2020, 2, 2);
membersManagerEntry.setSponsorshipForMember(sess, member, sponsor1, today);
LocalDate nextYear = today.plusYears(1);
List<Sponsorship> sponsorships = perun.getMembersManagerBl().getSponsorshipsExpiringInRange(sess, today, nextYear);
assertThat(sponsorships).hasSize(1);
assertThat(sponsorships.get(0).getValidityTo()).isEqualTo(today);
}
use of cz.metacentrum.perun.core.api.Sponsorship in project perun by CESNET.
the class MembersManagerEntryIntegrationTest method getSponsorshipsExpiringInRangeDoesntReturnExpiringBeforeRange.
@Test
public void getSponsorshipsExpiringInRangeDoesntReturnExpiringBeforeRange() throws Exception {
System.out.println(CLASS_NAME + "getSponsorshipsExpiringInRangeDoesntReturnExpiringBeforeRange");
Member member = setUpMember(createdVo);
User sponsor1 = perun.getUsersManagerBl().getUserByMember(sess, setUpSponsor(createdVo));
User sponsor2 = perun.getUsersManagerBl().getUserByMember(sess, setUpSponsor2(createdVo));
AuthzResolverBlImpl.setRole(sess, sponsor1, createdVo, Role.SPONSOR);
AuthzResolverBlImpl.setRole(sess, sponsor2, createdVo, Role.SPONSOR);
LocalDate today = LocalDate.of(2020, 2, 2);
LocalDate nextDay = today.plusDays(1);
LocalDate lastWeek = today.minusWeeks(1);
membersManagerEntry.setSponsorshipForMember(sess, member, sponsor1, nextDay);
membersManagerEntry.sponsorMember(sess, member, sponsor2, lastWeek);
LocalDate nextWeek = today.plusDays(7);
List<Sponsorship> sponsorships = perun.getMembersManagerBl().getSponsorshipsExpiringInRange(sess, today, nextWeek);
assertThat(sponsorships).hasSize(1);
assertThat(sponsorships.get(0).getValidityTo()).isEqualTo(nextDay);
}
use of cz.metacentrum.perun.core.api.Sponsorship in project perun by CESNET.
the class ExpirationNotifSchedulerTest method testSponsorshipDoesntExpireToday.
@Test
public void testSponsorshipDoesntExpireToday() throws Exception {
System.out.println(CLASS_NAME + "testSponsorshipDoesntExpireToday");
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);
perun.getMembersManagerBl().setSponsorshipForMember(session, member, sponsor, today);
ReflectionTestUtils.invokeMethod(spyScheduler, "expireSponsorships");
Sponsorship sponsorship = perun.getMembersManagerBl().getSponsorship(session, member, sponsor);
assertThat(sponsorship.isActive());
}
use of cz.metacentrum.perun.core.api.Sponsorship in project perun by CESNET.
the class ExpirationNotifSchedulerTest method testSponsorshipExpires.
@Test
public void testSponsorshipExpires() throws Exception {
System.out.println(CLASS_NAME + "testSponsorshipExpires");
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 lastMonth = today.minusMonths(1);
perun.getMembersManagerBl().setSponsorshipForMember(session, member, sponsor, lastMonth);
Sponsorship sponsorshipBefore = perun.getMembersManagerBl().getSponsorship(session, member, sponsor);
assertThat(sponsorshipBefore.isActive());
ReflectionTestUtils.invokeMethod(spyScheduler, "expireSponsorships");
assertThatExceptionOfType(SponsorshipDoesNotExistException.class).isThrownBy(() -> perun.getMembersManagerBl().getSponsorship(session, member, sponsor));
}
Aggregations