use of org.orcid.persistence.jpa.entities.ProfileEntity in project ORCID-Source by ORCID.
the class WebhookManagerImplTest method init.
@Before
public void init() throws Exception {
assertNotNull(webhookManager);
WebhookManagerImpl webhookManagerImpl = getTargetObject(webhookManager, WebhookManagerImpl.class);
webhookManagerImpl.setHttpClient(mockHttpClient);
when(mockHttpClient.execute(ArgumentMatchers.<HttpUriRequest>any())).thenReturn(new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_NOT_FOUND, "Not found"));
when(mockHttpClient.execute(ArgumentMatchers.<HttpPost>argThat(new ArgumentMatcher<HttpPost>() {
public boolean matches(HttpPost argument) {
if (argument == null || !(argument instanceof HttpPost)) {
return false;
}
HttpPost httpPost = (HttpPost) argument;
return httpPost.getURI().getHost().equals("qa-1.orcid.org");
}
}))).thenReturn(new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, "OK"));
webhookManagerImpl.setWebhookDao(mockWebhookDao);
ProfileEntity profile = new ProfileEntity();
profile.setId("0000-0000-0000-0001");
clientDetails = new ClientDetailsEntity();
clientDetails.setGroupProfileId(profile.getId());
clientDetails.setId("123456789");
assertFalse(PojoUtil.isEmpty(clientDetails.getGroupProfileId()));
assertNotNull(clientDetails.getId());
testProfile = new ProfileEntity("4444-4444-4444-4444");
}
use of org.orcid.persistence.jpa.entities.ProfileEntity in project ORCID-Source by ORCID.
the class TokenTargetFilterTest method setUpSecurityContext.
private void setUpSecurityContext(String userOrcid, String clientId, ScopePathType... scopePathTypes) {
SecurityContextImpl securityContext = new SecurityContextImpl();
OrcidOAuth2Authentication mockedAuthentication = mock(OrcidOAuth2Authentication.class);
securityContext.setAuthentication(mockedAuthentication);
SecurityContextHolder.setContext(securityContext);
if (userOrcid != null) {
ProfileEntity userProfileEntity = new ProfileEntity(userOrcid);
when(mockedAuthentication.getPrincipal()).thenReturn(userProfileEntity);
Authentication userAuthentication = mock(Authentication.class);
when(userAuthentication.getPrincipal()).thenReturn(userProfileEntity);
when(mockedAuthentication.getUserAuthentication()).thenReturn(userAuthentication);
} else {
when(mockedAuthentication.getPrincipal()).thenReturn(clientId);
}
Set<String> scopes = new HashSet<String>();
if (scopePathTypes != null) {
for (ScopePathType scopePathType : scopePathTypes) {
scopes.add(scopePathType.value());
}
}
OAuth2Request authorizationRequest = new OAuth2Request(Collections.<String, String>emptyMap(), clientId, Collections.<GrantedAuthority>emptyList(), true, scopes, Collections.<String>emptySet(), null, Collections.<String>emptySet(), Collections.<String, Serializable>emptyMap());
when(mockedAuthentication.getOAuth2Request()).thenReturn(authorizationRequest);
when(mockedAuthentication.isAuthenticated()).thenReturn(true);
}
use of org.orcid.persistence.jpa.entities.ProfileEntity in project ORCID-Source by ORCID.
the class OtherNameDaoTest method testAddOtherName.
@Test
public void testAddOtherName() {
Date profileLastModifiedOrig = profileDao.retrieveLastModifiedDate("4444-4444-4444-4441");
assertEquals(2, otherNameDao.getOtherNames("4444-4444-4444-4441", 0L).size());
boolean result = otherNameDao.addOtherName("4444-4444-4444-4441", "OtherName");
assertEquals(true, result);
assertEquals(3, otherNameDao.getOtherNames("4444-4444-4444-4441", 0L).size());
assertFalse("Profile last modified date should have been updated", profileLastModifiedOrig.after(profileDao.retrieveLastModifiedDate("4444-4444-4444-4441")));
OtherNameEntity entity = new OtherNameEntity();
entity.setDisplayName("The other name");
entity.setProfile(new ProfileEntity("4444-4444-4444-4441"));
entity.setSourceId("4444-4444-4444-4441");
entity.setVisibility(Visibility.PUBLIC);
otherNameDao.persist(entity);
assertEquals(4, otherNameDao.getOtherNames("4444-4444-4444-4441", 0L).size());
}
use of org.orcid.persistence.jpa.entities.ProfileEntity in project ORCID-Source by ORCID.
the class ProfileDaoTest method testInsertClient.
@Test
@Rollback(true)
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void testInsertClient() {
String clientOrcid = "4444-1111-6666-4444";
ClientDetailsEntity client = new ClientDetailsEntity();
client.setId(clientOrcid);
String groupOrcid = "4444-4444-4444-4441";
client.setGroupProfileId(groupOrcid);
clientDetailsDao.persist(client);
clientDetailsDao.flush();
client = clientDetailsDao.find(clientOrcid);
assertNotNull(client);
assertEquals(clientOrcid, client.getId());
ProfileEntity groupProfile = profileDao.find(groupOrcid);
assertNotNull(groupProfile);
assertNotNull(groupProfile.getClients());
assertEquals(1, groupProfile.getClients().size());
assertEquals(clientOrcid, groupProfile.getClients().iterator().next().getId());
}
use of org.orcid.persistence.jpa.entities.ProfileEntity in project ORCID-Source by ORCID.
the class ProfileDaoTest method testGetConfirmedProfileCount.
@Test
@Rollback(true)
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void testGetConfirmedProfileCount() {
String orcid = "4444-4444-4444-4446";
Long confirmedProfileCount = profileDao.getConfirmedProfileCount();
assertEquals(Long.valueOf(20), confirmedProfileCount);
ProfileEntity profileEntity = profileDao.find(orcid);
profileEntity.setCompletedDate(null);
profileDao.persist(profileEntity);
confirmedProfileCount = profileDao.getConfirmedProfileCount();
assertEquals(Long.valueOf(19), confirmedProfileCount);
}
Aggregations