Search in sources :

Example 1 with INITIAL

use of cz.metacentrum.perun.registrar.model.Application.AppType.INITIAL in project perun by CESNET.

the class AppAutoRejectionSchedulerTest method setUpAndSubmitAppForPotentialAutoRejection.

/**
 * In the first step method sets the return value for getCurrentLocalDay method. Then sets the application expiration
 * attribute for Vo or Group and creates and submits application. If the application has an item mapping to
 * user:preferredLanguage attribute, set it the given lang value.
 *
 * @param days number of days for move today
 * @param group optional group
 * @param attribute application expiration attribute for Vo or Group
 * @return submitted application
 * @throws Exception exception
 */
private Application setUpAndSubmitAppForPotentialAutoRejection(int days, Group group, String attribute, String lang, User user) throws Exception {
    // change today date for test
    LocalDate today = LocalDate.now().plusDays(days);
    when(spyScheduler.getCurrentLocalDate()).thenReturn(today);
    // set application expiration attribute for Vo
    Attribute appExp = new Attribute(perun.getAttributesManager().getAttributeDefinition(session, attribute));
    Map<String, String> attrValue = new LinkedHashMap<>();
    attrValue.put("emailVerification", "14");
    attrValue.put("ignoredByAdmin", "60");
    appExp.setValue(attrValue);
    if (group != null) {
        perun.getAttributesManagerBl().setAttribute(session, group, appExp);
    } else {
        perun.getAttributesManagerBl().setAttribute(session, vo, appExp);
    }
    // create application
    Application application = new Application();
    application.setType(INITIAL);
    application.setCreatedBy("testUser");
    application.setVo(vo);
    // get application form item data
    ApplicationForm applicationForm;
    if (group != null) {
        application.setGroup(group);
        registrarManager.createApplicationFormInGroup(session, group);
        applicationForm = registrarManager.getFormForGroup(group);
    } else {
        applicationForm = registrarManager.getFormForVo(vo);
    }
    List<ApplicationFormItemData> data = registrarManager.getFormItemsWithPrefilledValues(session, INITIAL, applicationForm).stream().map(item -> convertAppFormItemWithPrefValToAppFormItemData(item, lang)).collect(Collectors.toList());
    application.setUser(user);
    return registrarManager.submitApplication(session, application, data);
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) JdbcPerunTemplate(org.springframework.jdbc.core.JdbcPerunTemplate) INITIAL(cz.metacentrum.perun.registrar.model.Application.AppType.INITIAL) Vo(cz.metacentrum.perun.core.api.Vo) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Autowired(org.springframework.beans.factory.annotation.Autowired) HashMap(java.util.HashMap) Mockito.spy(org.mockito.Mockito.spy) GroupExistsException(cz.metacentrum.perun.core.api.exceptions.GroupExistsException) Group(cz.metacentrum.perun.core.api.Group) Compatibility(cz.metacentrum.perun.core.impl.Compatibility) LinkedHashMap(java.util.LinkedHashMap) ExtSource(cz.metacentrum.perun.core.api.ExtSource) ExtSourcesManager(cz.metacentrum.perun.core.api.ExtSourcesManager) Map(java.util.Map) AppAutoRejectionScheduler(cz.metacentrum.perun.registrar.impl.AppAutoRejectionScheduler) ApplicationForm(cz.metacentrum.perun.registrar.model.ApplicationForm) ApplicationFormItemWithPrefilledValue(cz.metacentrum.perun.registrar.model.ApplicationFormItemWithPrefilledValue) Before(org.junit.Before) Attribute(cz.metacentrum.perun.core.api.Attribute) ApplicationFormItem(cz.metacentrum.perun.registrar.model.ApplicationFormItem) ReflectionTestUtils(org.springframework.test.util.ReflectionTestUtils) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) AttributesManager(cz.metacentrum.perun.core.api.AttributesManager) Auditer(cz.metacentrum.perun.core.impl.Auditer) ApplicationFormItemData(cz.metacentrum.perun.registrar.model.ApplicationFormItemData) Collectors(java.util.stream.Collectors) User(cz.metacentrum.perun.core.api.User) Mockito.verify(org.mockito.Mockito.verify) Application(cz.metacentrum.perun.registrar.model.Application) List(java.util.List) LocalDate(java.time.LocalDate) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) Mockito.mock(org.mockito.Mockito.mock) ApplicationForm(cz.metacentrum.perun.registrar.model.ApplicationForm) Attribute(cz.metacentrum.perun.core.api.Attribute) ApplicationFormItemData(cz.metacentrum.perun.registrar.model.ApplicationFormItemData) LocalDate(java.time.LocalDate) Application(cz.metacentrum.perun.registrar.model.Application) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

Attribute (cz.metacentrum.perun.core.api.Attribute)1 AttributesManager (cz.metacentrum.perun.core.api.AttributesManager)1 ExtSource (cz.metacentrum.perun.core.api.ExtSource)1 ExtSourcesManager (cz.metacentrum.perun.core.api.ExtSourcesManager)1 Group (cz.metacentrum.perun.core.api.Group)1 User (cz.metacentrum.perun.core.api.User)1 Vo (cz.metacentrum.perun.core.api.Vo)1 GroupExistsException (cz.metacentrum.perun.core.api.exceptions.GroupExistsException)1 Auditer (cz.metacentrum.perun.core.impl.Auditer)1 Compatibility (cz.metacentrum.perun.core.impl.Compatibility)1 AppAutoRejectionScheduler (cz.metacentrum.perun.registrar.impl.AppAutoRejectionScheduler)1 Application (cz.metacentrum.perun.registrar.model.Application)1 INITIAL (cz.metacentrum.perun.registrar.model.Application.AppType.INITIAL)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 ApplicationFormItemWithPrefilledValue (cz.metacentrum.perun.registrar.model.ApplicationFormItemWithPrefilledValue)1 LocalDate (java.time.LocalDate)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1