Search in sources :

Example 1 with BiographyManager

use of org.orcid.core.manager.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();
    // 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));
    controller.setBiographyFormJson(bf);
    assertTrue(bf.getErrors().isEmpty());
    Biography bioElement = new Biography();
    bioElement.setContent(bio);
    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.BiographyManager) Biography(org.orcid.jaxb.model.record_v2.Biography) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)1 BiographyManager (org.orcid.core.manager.BiographyManager)1 Biography (org.orcid.jaxb.model.record_v2.Biography)1 BiographyForm (org.orcid.pojo.ajaxForm.BiographyForm)1