use of cz.metacentrum.perun.core.api.Sponsorship in project perun by CESNET.
the class MembersManagerEntryIntegrationTest method addSponsor.
@Test
public void addSponsor() throws Exception {
System.out.println(CLASS_NAME + "addSponsor");
// create user which can sponsor
User sponsorUser = perun.getUsersManagerBl().getUserByMember(sess, setUpSponsor(createdVo));
AuthzResolverBlImpl.setRole(sess, sponsorUser, createdVo, Role.SPONSOR);
assertTrue("user must have SPONSOR role", perun.getVosManagerBl().isUserInRoleForVo(sess, sponsorUser, Role.SPONSOR, createdVo, true));
// create another user which can sponsor
User sponsorUser2 = perun.getUsersManagerBl().getUserByMember(sess, setUpSponsor2(createdVo));
AuthzResolverBlImpl.setRole(sess, sponsorUser2, createdVo, Role.SPONSOR);
assertTrue("user must have SPONSOR role", perun.getVosManagerBl().isUserInRoleForVo(sess, sponsorUser2, Role.SPONSOR, createdVo, true));
// create user that cannot sponsor
User notsponsorUser = perun.getUsersManagerBl().getUserByMember(sess, setUpNotSponsor(createdVo));
assertFalse("user must not have SPONSOR role", perun.getVosManagerBl().isUserInRoleForVo(sess, notsponsorUser, Role.SPONSOR, createdVo, true));
// create sponsored member
Map<String, String> nameOfUser1 = new HashMap<>();
nameOfUser1.put("guestName", "Ing. Jiří Novák, CSc.");
Member sponsoredMember = createSponsoredMember(sess, createdVo, "dummy", nameOfUser1, "secret", null, sponsorUser);
assertNotNull("sponsored member must not be null", sponsoredMember);
assertTrue("sponsored memer must have flag 'sponsored' set", sponsoredMember.isSponsored());
assertTrue("sponsored member should have status VALID", sponsoredMember.getStatus() == Status.VALID);
// try add user that cannot sponsor, should fail
try {
perun.getMembersManager().sponsorMember(sess, sponsoredMember, notsponsorUser, null);
fail("user cannot sponsor but was added as sponsor");
} catch (UserNotInRoleException ex) {
// expected
}
// try to add user that already is sponsor, should fail
try {
perun.getMembersManager().sponsorMember(sess, sponsoredMember, sponsorUser, null);
fail("user cannot sponsor twice a single member");
} catch (AlreadySponsorException ex) {
// expected
}
// try to add sponsor, should succeed
perun.getMembersManager().sponsorMember(sess, sponsoredMember, sponsorUser2, null);
List<User> sponsors = perun.getUsersManagerBl().getSponsors(sess, sponsoredMember);
assertTrue("sponsor 1 is not reported as sponsor", sponsors.contains(sponsorUser));
assertTrue("sponsor 2 is not reported as sponsor", sponsors.contains(sponsorUser2));
assertTrue("unexpected sponsors", sponsors.size() == 2);
// check that it is reported
List<RichMember> sponsoredMembers1 = perun.getMembersManager().getSponsoredMembers(sess, createdVo, sponsorUser);
assertTrue("member is not in list of sponsored members for sponsor 1", sponsoredMembers1.stream().map(PerunBean::getId).anyMatch(id -> id == sponsoredMember.getId()));
List<RichMember> sponsoredMembers2 = perun.getMembersManager().getSponsoredMembers(sess, createdVo, sponsorUser2);
assertTrue("member is not in list of sponsored members for sponsor 2", sponsoredMembers2.stream().map(PerunBean::getId).anyMatch(id -> id == sponsoredMember.getId()));
// remove sponsor and add him again, sponsorship should reactivate
Sponsorship sponsorship = perun.getMembersManagerBl().getSponsorship(sess, sponsoredMember, sponsorUser);
assertTrue(sponsorship.isActive());
perun.getMembersManager().removeSponsor(sess, sponsoredMember, sponsorUser);
sponsorship = perun.getMembersManagerBl().getSponsorship(sess, sponsoredMember, sponsorUser);
assertFalse(sponsorship.isActive());
perun.getMembersManager().sponsorMember(sess, sponsoredMember, sponsorUser, null);
sponsorship = perun.getMembersManagerBl().getSponsorship(sess, sponsoredMember, sponsorUser);
assertTrue(sponsorship.isActive());
}
use of cz.metacentrum.perun.core.api.Sponsorship in project perun by CESNET.
the class MembersManagerEntryIntegrationTest method updateSponsorshipValidityToNull.
@Test
public void updateSponsorshipValidityToNull() throws Exception {
System.out.println(CLASS_NAME + "updateSponsorshipValidityToNull");
Member member = setUpMember(createdVo);
User sponsor = perun.getUsersManagerBl().getUserByMember(sess, setUpSponsor(createdVo));
AuthzResolverBlImpl.setRole(sess, sponsor, createdVo, Role.SPONSOR);
LocalDate validity = LocalDate.now().plusMonths(1);
membersManagerEntry.setSponsorshipForMember(sess, member, sponsor, validity);
membersManagerEntry.updateSponsorshipValidity(sess, member, sponsor, null);
Sponsorship sponsorship = perun.getMembersManagerBl().getSponsorship(sess, member, sponsor);
assertThat(sponsorship.getValidityTo()).isNull();
}
use of cz.metacentrum.perun.core.api.Sponsorship in project perun by CESNET.
the class MembersManagerEntryIntegrationTest method getSponsorshipsExpiringInRangeDoesntReturnInActiveSponsorships.
@Test
public void getSponsorshipsExpiringInRangeDoesntReturnInActiveSponsorships() throws Exception {
System.out.println(CLASS_NAME + "getSponsorshipsExpiringInRangeDoesntReturnInActiveSponsorships");
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 nextMonth = today.plusMonths(1);
membersManagerEntry.setSponsorshipForMember(sess, member, sponsor1, nextDay);
membersManagerEntry.sponsorMember(sess, member, sponsor2, nextMonth);
membersManagerEntry.removeSponsor(sess, member, sponsor2);
LocalDate nextYear = today.plusYears(1);
List<Sponsorship> sponsorships = perun.getMembersManagerBl().getSponsorshipsExpiringInRange(sess, today, nextYear);
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 MembersManagerEntryIntegrationTest method getSoonExpiringSponsorshipsDoesNotReturnUpperBound.
@Test
public void getSoonExpiringSponsorshipsDoesNotReturnUpperBound() throws Exception {
System.out.println(CLASS_NAME + "getSoonExpiringSponsorshipsDoesNotReturnUpperBound");
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);
LocalDate nextYear = today.plusYears(1);
membersManagerEntry.setSponsorshipForMember(sess, member, sponsor1, nextYear);
List<Sponsorship> sponsorships = perun.getMembersManagerBl().getSponsorshipsExpiringInRange(sess, today, nextYear);
assertThat(sponsorships).isEmpty();
}
Aggregations