use of org.orcid.pojo.ajaxForm.BiographyForm in project ORCID-Source by ORCID.
the class ManageProfileController method getBiographyForm.
@RequestMapping(value = "/biographyForm.json", method = RequestMethod.GET)
@ResponseBody
public BiographyForm getBiographyForm() {
Biography bio = biographyManager.getBiography(getCurrentUserOrcid(), profileEntityManager.getLastModified(getCurrentUserOrcid()));
BiographyForm form = BiographyForm.valueOf(bio);
if (form.getVisiblity() == null) {
ProfileEntity profile = profileEntityCacheManager.retrieve(getCurrentUserOrcid());
form.setVisiblity(Visibility.valueOf(profile.getActivitiesVisibilityDefault()));
}
return form;
}
use of org.orcid.pojo.ajaxForm.BiographyForm 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));
}
Aggregations