use of cz.metacentrum.perun.core.api.GroupsManager in project perun by CESNET.
the class RegistrarBaseIntegrationTest method testEmbeddedGroupsSubmission.
@Test
public void testEmbeddedGroupsSubmission() throws PerunException {
GroupsManager groupsManager = perun.getGroupsManager();
ApplicationForm form = registrarManager.getFormForVo(vo);
// create embedded groups form item
ApplicationFormItem embeddedGroupsItem = new ApplicationFormItem();
embeddedGroupsItem.setType(ApplicationFormItem.Type.EMBEDDED_GROUP_APPLICATION);
embeddedGroupsItem.setShortname("embeddedGroups");
embeddedGroupsItem = registrarManager.addFormItem(session, form, embeddedGroupsItem);
registrarManager.updateFormItems(session, form, Collections.singletonList(embeddedGroupsItem));
// create groups in VO
Group group1 = new Group("GroupA", "Cool folks");
Group group2 = new Group("GroupB", "Cooler folks");
groupsManager.createGroup(session, vo, group1);
groupsManager.createGroup(session, vo, group2);
registrarManager.addGroupsToAutoRegistration(session, List.of(group1, group2));
// create user
User user = new User(-1, "Jo", "Doe", "", "", "");
user = perun.getUsersManagerBl().createUser(session, user);
// prepare application
Application application = prepareApplicationToVo(user);
// set embedded groups as item in application and fill with our two groups
String embGroupsValue = String.format("Group A#%d|Group B#%d", group1.getId(), group2.getId());
List<ApplicationFormItemData> appItemsData = new ArrayList<>();
appItemsData.add(new ApplicationFormItemData(embeddedGroupsItem, "Embedded groups", embGroupsValue, "0"));
registrarManager.submitApplication(session, application, appItemsData);
List<Group> expectedEmbeddedGroups = List.of(group1, group2);
RegistrarManagerImpl registrarManagerImpl = AopTestUtils.getTargetObject(registrarManager);
assertEquals(expectedEmbeddedGroups, registrarManagerImpl.getEmbeddedGroups(session, application.getId()));
assertEquals(1, registrarManager.getApplicationsForUser(user).size());
registrarManager.approveApplication(session, application.getId());
assertEquals(3, registrarManager.getApplicationsForUser(user).size());
assertEquals(1, registrarManager.getApplicationsForGroup(session, group1, List.of("NEW", "VERIFIED")).size());
assertEquals(1, registrarManager.getApplicationsForGroup(session, group2, List.of("NEW", "VERIFIED")).size());
}
use of cz.metacentrum.perun.core.api.GroupsManager in project perun by CESNET.
the class RegistrarBaseIntegrationTest method testEmbeddedGroupsSubmission_initEmbeddedConflict.
@Test
public void testEmbeddedGroupsSubmission_initEmbeddedConflict() throws PerunException {
GroupsManager groupsManager = perun.getGroupsManager();
ApplicationForm form = registrarManager.getFormForVo(vo);
// create embedded groups form item
ApplicationFormItem embeddedGroupsItem = new ApplicationFormItem();
embeddedGroupsItem.setType(ApplicationFormItem.Type.EMBEDDED_GROUP_APPLICATION);
embeddedGroupsItem.setShortname("embeddedGroups");
embeddedGroupsItem = registrarManager.addFormItem(session, form, embeddedGroupsItem);
registrarManager.updateFormItems(session, form, Collections.singletonList(embeddedGroupsItem));
// create group in VO, generate group application form
Group group1 = new Group("GroupA", "Cool folks");
groupsManager.createGroup(session, vo, group1);
registrarManager.addGroupsToAutoRegistration(session, List.of(group1));
// create user
User user = new User(-1, "Jo", "Doe", "", "", "");
user = perun.getUsersManagerBl().createUser(session, user);
Application application = prepareApplicationToVo(user);
// set embedded groups in VO application
String embGroupsValue = String.format("Group A#%d", group1.getId());
List<ApplicationFormItemData> appItemsData = new ArrayList<>();
appItemsData.add(new ApplicationFormItemData(embeddedGroupsItem, "Embedded groups", embGroupsValue, "0"));
registrarManager.submitApplication(session, application, appItemsData);
// prepare group application and approve vo application
Application groupApp = prepareApplicationToVo(user);
groupApp.setGroup(group1);
registrarManager.submitApplication(session, groupApp, new ArrayList<>());
// normally, approval of VO generates and submits embedded groups applications
registrarManager.approveApplication(session, application.getId());
// embedded application is expected to not be created as init already exists
List<Application> group1Apps = registrarManager.getApplicationsForGroup(session, group1, List.of("NEW", "VERIFIED"));
assertEquals(1, group1Apps.size());
assertEquals(INITIAL, group1Apps.get(0).getType());
}
use of cz.metacentrum.perun.core.api.GroupsManager in project perun by CESNET.
the class RegistrarBaseIntegrationTest method setUpGroup.
private Group setUpGroup(String name, String desc) throws Exception {
GroupsManager groupsManager = perun.getGroupsManager();
// create group in VO, generate group application form
Group group = new Group(name, desc);
group = groupsManager.createGroup(session, vo, group);
registrarManager.createApplicationFormInGroup(session, group);
ApplicationForm groupForm = registrarManager.getFormForGroup(group);
groupForm.setAutomaticApproval(true);
registrarManager.updateForm(session, groupForm);
return group;
}
use of cz.metacentrum.perun.core.api.GroupsManager in project perun by CESNET.
the class RegistrarBaseIntegrationTest method testHandleGroupApplications.
@Test
public void testHandleGroupApplications() throws PerunException {
GroupsManager groupsManager = perun.getGroupsManager();
// create group in VO, generate group application form
Group group1 = new Group("GroupA", "Cool folks");
group1 = groupsManager.createGroup(session, vo, group1);
registrarManager.createApplicationFormInGroup(session, group1);
ApplicationForm groupForm = registrarManager.getFormForGroup(group1);
groupForm.setAutomaticApproval(true);
registrarManager.updateForm(session, groupForm);
// create user
User user = new User(-1, "Jo", "Doe", "", "", "");
user = perun.getUsersManagerBl().createUser(session, user);
ExtSource source = new ExtSource("ExtSource", ExtSourcesManager.EXTSOURCE_IDP);
perun.getExtSourcesManagerBl().createExtSource(session, source, new HashMap<>());
UserExtSource ues = new UserExtSource(source, session.getPerunPrincipal().getActor());
perun.getUsersManagerBl().addUserExtSource(session, user, ues);
Application voApplication = prepareApplicationToVo(user);
Application groupApplication = prepareApplicationToGroup(null, group1);
List<ApplicationFormItemData> appItemsData = new ArrayList<>();
voApplication = registrarManager.submitApplication(session, voApplication, appItemsData);
registrarManager.submitApplication(session, groupApplication, appItemsData);
registrarManager.approveApplication(session, voApplication.getId());
// We have to call this method explicitly due to transactions
registrarManager.handleUsersGroupApplications(session, vo, user);
List<Application> group1Apps = registrarManager.getApplicationsForGroup(session, group1, List.of("APPROVED"));
assertEquals(1, group1Apps.size());
assertEquals(user, group1Apps.get(0).getUser());
}
use of cz.metacentrum.perun.core.api.GroupsManager in project perun by CESNET.
the class RegistrarBaseIntegrationTest method testEmbeddedGroupsSubmission_groupAutoApprove.
@Test
public void testEmbeddedGroupsSubmission_groupAutoApprove() throws PerunException {
GroupsManager groupsManager = perun.getGroupsManager();
ApplicationForm form = registrarManager.getFormForVo(vo);
// create embedded groups form item
ApplicationFormItem embeddedGroupsItem = new ApplicationFormItem();
embeddedGroupsItem.setType(ApplicationFormItem.Type.EMBEDDED_GROUP_APPLICATION);
embeddedGroupsItem.setShortname("embeddedGroups");
embeddedGroupsItem = registrarManager.addFormItem(session, form, embeddedGroupsItem);
registrarManager.updateFormItems(session, form, Collections.singletonList(embeddedGroupsItem));
// create groups in VO
Group group = new Group("GroupA", "Cool folks");
groupsManager.createGroup(session, vo, group);
registrarManager.addGroupsToAutoRegistration(session, List.of(group));
// allow auto-approve
ApplicationForm groupForm = registrarManager.getFormForGroup(group);
groupForm.setAutomaticApprovalEmbedded(true);
registrarManager.updateForm(session, groupForm);
// create user
final User user = new User(-1, "Jo", "Doe", "", "", "");
perun.getUsersManagerBl().createUser(session, user);
Application application = prepareApplicationToVo(user);
String embGroupsValue = String.format("Group A#%d", group.getId());
List<ApplicationFormItemData> appItemsData = new ArrayList<>();
appItemsData.add(new ApplicationFormItemData(embeddedGroupsItem, "Embedded groups", embGroupsValue, "0"));
registrarManager.submitApplication(session, application, appItemsData);
registrarManager.approveApplication(session, application.getId());
List<Member> groupMembers = groupsManager.getGroupMembers(session, group);
assertThat(groupMembers).anyMatch(member -> member.getUserId() == user.getId());
}
Aggregations