use of cz.metacentrum.perun.registrar.impl.RegistrarManagerImpl 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());
}
Aggregations