Search in sources :

Example 1 with RegistrarManagerImpl

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());
}
Also used : RegistrarManagerImpl(cz.metacentrum.perun.registrar.impl.RegistrarManagerImpl) ApplicationForm(cz.metacentrum.perun.registrar.model.ApplicationForm) ApplicationFormItem(cz.metacentrum.perun.registrar.model.ApplicationFormItem) Group(cz.metacentrum.perun.core.api.Group) User(cz.metacentrum.perun.core.api.User) ApplicationFormItemData(cz.metacentrum.perun.registrar.model.ApplicationFormItemData) Application(cz.metacentrum.perun.registrar.model.Application) RichApplication(cz.metacentrum.perun.registrar.model.RichApplication) GroupsManager(cz.metacentrum.perun.core.api.GroupsManager) Test(org.junit.Test)

Aggregations

Group (cz.metacentrum.perun.core.api.Group)1 GroupsManager (cz.metacentrum.perun.core.api.GroupsManager)1 User (cz.metacentrum.perun.core.api.User)1 RegistrarManagerImpl (cz.metacentrum.perun.registrar.impl.RegistrarManagerImpl)1 Application (cz.metacentrum.perun.registrar.model.Application)1 ApplicationForm (cz.metacentrum.perun.registrar.model.ApplicationForm)1 ApplicationFormItem (cz.metacentrum.perun.registrar.model.ApplicationFormItem)1 ApplicationFormItemData (cz.metacentrum.perun.registrar.model.ApplicationFormItemData)1 RichApplication (cz.metacentrum.perun.registrar.model.RichApplication)1 Test (org.junit.Test)1