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));
}
Aggregations