use of org.orcid.pojo.ajaxForm.Checkbox in project ORCID-Source by ORCID.
the class ProfileEntityManagerImplTest method testClaimChangingVisibility.
@Test
@Transactional
public void testClaimChangingVisibility() {
Claim claim = new Claim();
claim.setActivitiesVisibilityDefault(org.orcid.pojo.ajaxForm.Visibility.valueOf(Visibility.PRIVATE));
claim.setPassword(Text.valueOf("passwordTest1"));
claim.setPasswordConfirm(Text.valueOf("passwordTest1"));
Checkbox checked = new Checkbox();
checked.setValue(true);
claim.setSendChangeNotifications(checked);
claim.setSendOrcidNews(checked);
claim.setTermsOfUse(checked);
assertTrue(profileEntityManager.claimProfileAndUpdatePreferences("0000-0000-0000-0001", "public_0000-0000-0000-0001@test.orcid.org", Locale.EN, claim));
ProfileEntity profile = profileEntityManager.findByOrcid("0000-0000-0000-0001");
assertNotNull(profile);
assertNotNull(profile.getBiographyEntity());
assertEquals(org.orcid.jaxb.model.common_v2.Visibility.PRIVATE, profile.getBiographyEntity().getVisibility());
assertNotNull(profile.getAddresses());
assertEquals(3, profile.getAddresses().size());
for (AddressEntity a : profile.getAddresses()) {
assertEquals(org.orcid.jaxb.model.common_v2.Visibility.PRIVATE, a.getVisibility());
}
assertNotNull(profile.getExternalIdentifiers());
assertEquals(3, profile.getExternalIdentifiers().size());
for (ExternalIdentifierEntity e : profile.getExternalIdentifiers()) {
assertEquals(org.orcid.jaxb.model.common_v2.Visibility.PRIVATE, e.getVisibility());
}
assertNotNull(profile.getKeywords());
assertEquals(3, profile.getKeywords().size());
for (ProfileKeywordEntity k : profile.getKeywords()) {
assertEquals(org.orcid.jaxb.model.common_v2.Visibility.PRIVATE, k.getVisibility());
}
assertNotNull(profile.getOtherNames());
assertEquals(3, profile.getOtherNames().size());
for (OtherNameEntity o : profile.getOtherNames()) {
assertEquals(org.orcid.jaxb.model.common_v2.Visibility.PRIVATE, o.getVisibility());
}
assertNotNull(profile.getResearcherUrls());
assertEquals(3, profile.getResearcherUrls().size());
for (ResearcherUrlEntity r : profile.getResearcherUrls()) {
assertEquals(org.orcid.jaxb.model.common_v2.Visibility.PRIVATE, r.getVisibility());
}
}
use of org.orcid.pojo.ajaxForm.Checkbox in project ORCID-Source by ORCID.
the class RegistrationControllerTest method testStripHtmlFromNames.
@Test
public void testStripHtmlFromNames() throws UnsupportedEncodingException {
HttpSession session = mock(HttpSession.class);
when(servletRequest.getSession()).thenReturn(session);
Text email = Text.valueOf(System.currentTimeMillis() + "@test.orcid.org");
when(registrationManager.createMinimalRegistration(Matchers.any(Registration.class), eq(false), Matchers.any(java.util.Locale.class), Matchers.anyString())).thenAnswer(new Answer<String>() {
@Override
public String answer(InvocationOnMock invocation) throws Throwable {
return "0000-0000-0000-0000";
}
});
Registration reg = new Registration();
org.orcid.pojo.ajaxForm.Visibility fv = new org.orcid.pojo.ajaxForm.Visibility();
fv.setVisibility(Visibility.PUBLIC);
reg.setActivitiesVisibilityDefault(fv);
reg.setEmail(email);
reg.setEmailConfirm(email);
reg.setFamilyNames(Text.valueOf("<button onclick=\"alert('hello')\">Family Name</button>"));
reg.setGivenNames(Text.valueOf("<button onclick=\"alert('hello')\">Given Names</button>"));
reg.setPassword(Text.valueOf("1234abcd"));
reg.setPasswordConfirm(Text.valueOf("1234abcd"));
reg.setValNumClient(2L);
reg.setValNumServer(4L);
Checkbox c = new Checkbox();
c.setValue(true);
reg.setTermsOfUse(c);
reg.setCreationType(Text.valueOf(CreationMethod.API.value()));
registrationController.setRegisterConfirm(servletRequest, servletResponse, reg);
ArgumentCaptor<Registration> argument1 = ArgumentCaptor.forClass(Registration.class);
ArgumentCaptor<Boolean> argument2 = ArgumentCaptor.forClass(Boolean.class);
ArgumentCaptor<Locale> argument3 = ArgumentCaptor.forClass(Locale.class);
ArgumentCaptor<String> argument4 = ArgumentCaptor.forClass(String.class);
verify(registrationManager).createMinimalRegistration(argument1.capture(), argument2.capture(), argument3.capture(), argument4.capture());
assertNotNull(argument1.getValue());
Registration form = argument1.getValue();
assertEquals("Given Names", form.getGivenNames().getValue());
assertEquals("Family Name", form.getFamilyNames().getValue());
}
use of org.orcid.pojo.ajaxForm.Checkbox in project ORCID-Source by ORCID.
the class OauthRegistrationControllerTest method testStripHtmlFromNames.
@SuppressWarnings("unchecked")
@Test
public void testStripHtmlFromNames() throws UnsupportedEncodingException {
HttpSession session = mock(HttpSession.class);
RequestInfoForm rf = new RequestInfoForm();
RedirectView mv = new RedirectView();
when(servletRequest.getSession()).thenReturn(session);
when(servletRequest.getSession().getAttribute("requestInfoForm")).thenReturn(rf);
when(authorizationEndpoint.approveOrDeny(Matchers.anyMap(), Matchers.anyMap(), Matchers.any(SessionStatus.class), Matchers.any(Principal.class))).thenReturn(mv);
when(authenticationManager.authenticate(Matchers.any(Authentication.class))).thenAnswer(new Answer<Authentication>() {
@Override
public Authentication answer(InvocationOnMock invocation) throws Throwable {
OrcidOAuth2Authentication mockedAuthentication = mock(OrcidOAuth2Authentication.class);
return mockedAuthentication;
}
});
Text email = Text.valueOf(System.currentTimeMillis() + "@test.orcid.org");
OauthRegistrationForm reg = new OauthRegistrationForm();
org.orcid.pojo.ajaxForm.Visibility fv = new org.orcid.pojo.ajaxForm.Visibility();
fv.setVisibility(org.orcid.jaxb.model.common_v2.Visibility.PUBLIC);
reg.setActivitiesVisibilityDefault(fv);
reg.setEmail(email);
reg.setEmailConfirm(email);
reg.setFamilyNames(Text.valueOf("<button onclick=\"alert('hello')\">Family Name</button>"));
reg.setGivenNames(Text.valueOf("<button onclick=\"alert('hello')\">Given Names</button>"));
reg.setPassword(Text.valueOf("1234abcd"));
reg.setPasswordConfirm(Text.valueOf("1234abcd"));
reg.setValNumClient(2L);
reg.setValNumServer(4L);
reg.setApproved(true);
Checkbox c = new Checkbox();
c.setValue(true);
reg.setTermsOfUse(c);
reg.setCreationType(Text.valueOf(CreationMethod.DIRECT.value()));
reg.setPersistentTokenEnabled(true);
oauthRegistrationController.registerAndAuthorize(servletRequest, servletResponse, reg);
ArgumentCaptor<HttpServletRequest> argument1 = ArgumentCaptor.forClass(HttpServletRequest.class);
ArgumentCaptor<Registration> argument2 = ArgumentCaptor.forClass(Registration.class);
ArgumentCaptor<Boolean> argument3 = ArgumentCaptor.forClass(Boolean.class);
ArgumentCaptor<Locale> argument4 = ArgumentCaptor.forClass(Locale.class);
ArgumentCaptor<String> argument5 = ArgumentCaptor.forClass(String.class);
verify(registrationController).createMinimalRegistration(argument1.capture(), argument2.capture(), argument3.capture(), argument4.capture(), argument5.capture());
assertNotNull(argument2.getValue());
Registration registration = argument2.getValue();
assertEquals(email.getValue(), registration.getEmail().getValue());
assertEquals("Given Names", registration.getGivenNames().getValue());
assertEquals("Family Name", registration.getFamilyNames().getValue());
}
use of org.orcid.pojo.ajaxForm.Checkbox in project ORCID-Source by ORCID.
the class ClaimControllerTest method testClaim.
@Test
@Transactional
public void testClaim() {
String email = "public_0000-0000-0000-0001@test.orcid.org";
SecurityContextHolder.getContext().setAuthentication(null);
when(profileEntityCacheManager.retrieve(Mockito.anyString())).thenReturn(getProfileEntityToTestClam(false));
when(encryptionManager.decryptForExternalUse(any(String.class))).thenReturn(email);
HttpServletRequest request = mock(HttpServletRequest.class);
HttpServletResponse response = mock(HttpServletResponse.class);
when(request.getAttribute(DispatcherServlet.LOCALE_RESOLVER_ATTRIBUTE)).thenReturn(null);
when(request.getLocale()).thenReturn(java.util.Locale.US);
String orcid = "0000-0000-0000-0001";
when(emailManager.findOrcidIdByEmail(email)).thenReturn(orcid);
when(profileEntityManager.claimProfileAndUpdatePreferences(any(String.class), any(String.class), any(Locale.class), any(Claim.class))).thenReturn(true);
Claim claim = new Claim();
claim.setActivitiesVisibilityDefault(org.orcid.pojo.ajaxForm.Visibility.valueOf(Visibility.PRIVATE));
claim.setPassword(Text.valueOf("passwordTest1"));
claim.setPasswordConfirm(Text.valueOf("passwordTest1"));
Checkbox checked = new Checkbox();
checked.setValue(true);
claim.setSendChangeNotifications(checked);
claim.setSendOrcidNews(checked);
claim.setTermsOfUse(checked);
try {
claim = claimController.submitClaimJson(request, response, email, claim);
assertNotNull(claim);
assertTrue(claim.getErrors().isEmpty());
assertTrue("Value was: " + claim.getUrl(), claim.getUrl().endsWith("/my-orcid?recordClaimed"));
} catch (NoSuchRequestHandlingMethodException e) {
fail();
} catch (UnsupportedEncodingException e) {
fail();
}
}
Aggregations