Search in sources :

Example 1 with BiographyManager

use of org.orcid.core.manager.v3.BiographyManager in project ORCID-Source by ORCID.

the class ManageProfileControllerTest method testValidateBiography.

@Test
public void testValidateBiography() {
    BiographyManager mockBiographyManager = Mockito.mock(BiographyManager.class);
    SecurityContextHolder.getContext().setAuthentication(getAuthentication(USER_ORCID));
    TargetProxyHelper.injectIntoProxy(controller, "biographyManager", mockBiographyManager);
    when(mockBiographyManager.exists(Mockito.anyString())).thenReturn(true);
    BiographyForm bf = new BiographyForm();
    bf.setVisibility(org.orcid.pojo.ajaxForm.Visibility.valueOf(Visibility.PUBLIC));
    // No NPE exception on empty bio
    controller.setBiographyFormJson(bf);
    assertNotNull(bf.getErrors());
    assertTrue(bf.getErrors().isEmpty());
    String bio = StringUtils.repeat('a', 5001);
    bf.setBiography(Text.valueOf(bio));
    controller.setBiographyFormJson(bf);
    assertEquals(1, bf.getErrors().size());
    assertEquals("Length.changePersonalInfoForm.biography", bf.getErrors().get(0));
    bio = StringUtils.repeat('a', 5000);
    bf.setBiography(Text.valueOf(bio));
    bf.setVisibility(null);
    controller.setBiographyFormJson(bf);
    assertEquals(1, bf.getErrors().size());
    assertEquals("common.visibility.not_blank", bf.getErrors().get(0));
    bf.setBiography(Text.valueOf(bio));
    bf.setVisibility(org.orcid.pojo.ajaxForm.Visibility.valueOf(Visibility.PUBLIC));
    controller.setBiographyFormJson(bf);
    assertTrue(bf.getErrors().isEmpty());
    Biography bioElement = new Biography();
    bioElement.setContent(bio);
    bioElement.setVisibility(Visibility.PUBLIC);
    verify(mockBiographyManager, times(1)).updateBiography(Mockito.eq(USER_ORCID), Mockito.eq(bioElement));
}
Also used : BiographyForm(org.orcid.pojo.ajaxForm.BiographyForm) BiographyManager(org.orcid.core.manager.v3.BiographyManager) Biography(org.orcid.jaxb.model.v3.dev1.record.Biography) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1 BiographyManager (org.orcid.core.manager.v3.BiographyManager)1 Biography (org.orcid.jaxb.model.v3.dev1.record.Biography)1 BiographyForm (org.orcid.pojo.ajaxForm.BiographyForm)1