Search in sources :

Example 11 with Sponsorship

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());
}
Also used : InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) Arrays(java.util.Arrays) Validation(cz.metacentrum.perun.core.api.Validation) Candidate(cz.metacentrum.perun.core.api.Candidate) Vo(cz.metacentrum.perun.core.api.Vo) Date(java.util.Date) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) MemberNotExistsException(cz.metacentrum.perun.core.api.exceptions.MemberNotExistsException) SpecificUserType(cz.metacentrum.perun.core.api.SpecificUserType) MembersManager(cz.metacentrum.perun.core.api.MembersManager) ExtSource(cz.metacentrum.perun.core.api.ExtSource) AlreadySponsoredMemberException(cz.metacentrum.perun.core.api.exceptions.AlreadySponsoredMemberException) cz.metacentrum.perun.core.impl.modules.attributes.urn_perun_vo_attribute_def_def_membershipExpirationRules.expireSponsoredMembers(cz.metacentrum.perun.core.impl.modules.attributes.urn_perun_vo_attribute_def_def_membershipExpirationRules.expireSponsoredMembers) NamespaceRulesNotExistsException(cz.metacentrum.perun.core.api.exceptions.NamespaceRulesNotExistsException) ExtSourcesManager(cz.metacentrum.perun.core.api.ExtSourcesManager) PerunBean(cz.metacentrum.perun.core.api.PerunBean) Map(java.util.Map) Role(cz.metacentrum.perun.core.api.Role) GroupsManager(cz.metacentrum.perun.core.api.GroupsManager) MemberGroupStatus(cz.metacentrum.perun.core.api.MemberGroupStatus) Attribute(cz.metacentrum.perun.core.api.Attribute) Facility(cz.metacentrum.perun.core.api.Facility) MembersPageQuery(cz.metacentrum.perun.core.api.MembersPageQuery) MemberWithSponsors(cz.metacentrum.perun.core.api.MemberWithSponsors) Sponsorship(cz.metacentrum.perun.core.api.Sponsorship) BeansUtils(cz.metacentrum.perun.core.api.BeansUtils) UserExtSource(cz.metacentrum.perun.core.api.UserExtSource) AttributeDefinition(cz.metacentrum.perun.core.api.AttributeDefinition) ZoneId(java.time.ZoneId) User(cz.metacentrum.perun.core.api.User) ParseUserNameException(cz.metacentrum.perun.core.api.exceptions.ParseUserNameException) VosManager(cz.metacentrum.perun.core.api.VosManager) Sponsor(cz.metacentrum.perun.core.api.Sponsor) List(java.util.List) LocalDate(java.time.LocalDate) AlreadySponsorException(cz.metacentrum.perun.core.api.exceptions.AlreadySponsorException) RichMember(cz.metacentrum.perun.core.api.RichMember) VO_EXPIRATION_RULES_ATTR(cz.metacentrum.perun.core.impl.modules.attributes.urn_perun_vo_attribute_def_def_membershipExpirationRules.VO_EXPIRATION_RULES_ATTR) SortingOrder(cz.metacentrum.perun.core.api.SortingOrder) SponsoredUserData(cz.metacentrum.perun.core.api.SponsoredUserData) Resource(cz.metacentrum.perun.core.api.Resource) AssertionsForClassTypes.assertThatExceptionOfType(org.assertj.core.api.AssertionsForClassTypes.assertThatExceptionOfType) BanOnVo(cz.metacentrum.perun.core.api.BanOnVo) PerunSession(cz.metacentrum.perun.core.api.PerunSession) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) NamespaceRules(cz.metacentrum.perun.core.api.NamespaceRules) Paginated(cz.metacentrum.perun.core.api.Paginated) HashMap(java.util.HashMap) Group(cz.metacentrum.perun.core.api.Group) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) MembersOrderColumn(cz.metacentrum.perun.core.api.MembersOrderColumn) AuthzResolverBlImpl(cz.metacentrum.perun.core.blImpl.AuthzResolverBlImpl) UsersManager(cz.metacentrum.perun.core.api.UsersManager) SponsorshipDoesNotExistException(cz.metacentrum.perun.core.api.exceptions.SponsorshipDoesNotExistException) Before(org.junit.Before) BanOnResource(cz.metacentrum.perun.core.api.BanOnResource) Member(cz.metacentrum.perun.core.api.Member) UserNotInRoleException(cz.metacentrum.perun.core.api.exceptions.UserNotInRoleException) AbstractMembershipExpirationRulesModule(cz.metacentrum.perun.core.implApi.modules.attributes.AbstractMembershipExpirationRulesModule) Test(org.junit.Test) AlreadyMemberException(cz.metacentrum.perun.core.api.exceptions.AlreadyMemberException) AttributesManager(cz.metacentrum.perun.core.api.AttributesManager) MembershipType(cz.metacentrum.perun.core.api.MembershipType) ExtendMembershipException(cz.metacentrum.perun.core.api.exceptions.ExtendMembershipException) VoNotExistsException(cz.metacentrum.perun.core.api.exceptions.VoNotExistsException) Collectors.toList(java.util.stream.Collectors.toList) Ignore(org.junit.Ignore) UserNotExistsException(cz.metacentrum.perun.core.api.exceptions.UserNotExistsException) Assert(org.junit.Assert) Collections(java.util.Collections) Status(cz.metacentrum.perun.core.api.Status) Assert.assertEquals(org.junit.Assert.assertEquals) User(cz.metacentrum.perun.core.api.User) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) RichMember(cz.metacentrum.perun.core.api.RichMember) UserNotInRoleException(cz.metacentrum.perun.core.api.exceptions.UserNotInRoleException) AlreadySponsorException(cz.metacentrum.perun.core.api.exceptions.AlreadySponsorException) Sponsorship(cz.metacentrum.perun.core.api.Sponsorship) PerunBean(cz.metacentrum.perun.core.api.PerunBean) RichMember(cz.metacentrum.perun.core.api.RichMember) Member(cz.metacentrum.perun.core.api.Member) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Example 12 with Sponsorship

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();
}
Also used : Sponsorship(cz.metacentrum.perun.core.api.Sponsorship) User(cz.metacentrum.perun.core.api.User) RichMember(cz.metacentrum.perun.core.api.RichMember) Member(cz.metacentrum.perun.core.api.Member) LocalDate(java.time.LocalDate) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Example 13 with Sponsorship

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);
}
Also used : Sponsorship(cz.metacentrum.perun.core.api.Sponsorship) User(cz.metacentrum.perun.core.api.User) RichMember(cz.metacentrum.perun.core.api.RichMember) Member(cz.metacentrum.perun.core.api.Member) LocalDate(java.time.LocalDate) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Example 14 with Sponsorship

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();
}
Also used : Sponsorship(cz.metacentrum.perun.core.api.Sponsorship) User(cz.metacentrum.perun.core.api.User) RichMember(cz.metacentrum.perun.core.api.RichMember) Member(cz.metacentrum.perun.core.api.Member) LocalDate(java.time.LocalDate) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Aggregations

Sponsorship (cz.metacentrum.perun.core.api.Sponsorship)14 Member (cz.metacentrum.perun.core.api.Member)13 User (cz.metacentrum.perun.core.api.User)13 LocalDate (java.time.LocalDate)12 Test (org.junit.Test)12 RichMember (cz.metacentrum.perun.core.api.RichMember)10 AbstractPerunIntegrationTest (cz.metacentrum.perun.core.AbstractPerunIntegrationTest)9 RichUser (cz.metacentrum.perun.core.api.RichUser)5 SponsorshipDoesNotExistException (cz.metacentrum.perun.core.api.exceptions.SponsorshipDoesNotExistException)4 EnrichedSponsorship (cz.metacentrum.perun.core.api.EnrichedSponsorship)3 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)3 Sponsor (cz.metacentrum.perun.core.api.Sponsor)2 AlreadySponsorException (cz.metacentrum.perun.core.api.exceptions.AlreadySponsorException)2 AlreadySponsoredMemberException (cz.metacentrum.perun.core.api.exceptions.AlreadySponsoredMemberException)2 UserNotInRoleException (cz.metacentrum.perun.core.api.exceptions.UserNotInRoleException)2 Attribute (cz.metacentrum.perun.core.api.Attribute)1 AttributeDefinition (cz.metacentrum.perun.core.api.AttributeDefinition)1 AttributesManager (cz.metacentrum.perun.core.api.AttributesManager)1 BanOnResource (cz.metacentrum.perun.core.api.BanOnResource)1 BanOnVo (cz.metacentrum.perun.core.api.BanOnVo)1