Search in sources :

Example 91 with ProfileEntity

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");
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) BasicHttpResponse(org.apache.http.message.BasicHttpResponse) ArgumentMatcher(org.mockito.ArgumentMatcher) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) Before(org.junit.Before)

Example 92 with ProfileEntity

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);
}
Also used : SecurityContextImpl(org.springframework.security.core.context.SecurityContextImpl) OAuth2Request(org.springframework.security.oauth2.provider.OAuth2Request) ScopePathType(org.orcid.jaxb.model.message.ScopePathType) OrcidOAuth2Authentication(org.orcid.core.oauth.OrcidOAuth2Authentication) Authentication(org.springframework.security.core.Authentication) OrcidOAuth2Authentication(org.orcid.core.oauth.OrcidOAuth2Authentication) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) HashSet(java.util.HashSet)

Example 93 with ProfileEntity

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());
}
Also used : OtherNameEntity(org.orcid.persistence.jpa.entities.OtherNameEntity) Date(java.util.Date) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) Test(org.junit.Test) DBUnitTest(org.orcid.test.DBUnitTest)

Example 94 with ProfileEntity

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());
}
Also used : ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test) Rollback(org.springframework.test.annotation.Rollback) Transactional(org.springframework.transaction.annotation.Transactional)

Example 95 with ProfileEntity

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);
}
Also used : ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test) Rollback(org.springframework.test.annotation.Rollback) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

ProfileEntity (org.orcid.persistence.jpa.entities.ProfileEntity)231 Test (org.junit.Test)65 Date (java.util.Date)64 Transactional (org.springframework.transaction.annotation.Transactional)58 DBUnitTest (org.orcid.test.DBUnitTest)44 HashMap (java.util.HashMap)41 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)37 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)36 ClientDetailsEntity (org.orcid.persistence.jpa.entities.ClientDetailsEntity)33 HashSet (java.util.HashSet)30 SourceEntity (org.orcid.persistence.jpa.entities.SourceEntity)28 Rollback (org.springframework.test.annotation.Rollback)25 RecordNameEntity (org.orcid.persistence.jpa.entities.RecordNameEntity)20 Set (java.util.Set)16 ArrayList (java.util.ArrayList)15 OrcidProfile (org.orcid.jaxb.model.message.OrcidProfile)14 EmailEntity (org.orcid.persistence.jpa.entities.EmailEntity)14 OAuth2Authentication (org.springframework.security.oauth2.provider.OAuth2Authentication)13 OAuth2Request (org.springframework.security.oauth2.provider.OAuth2Request)13 Authentication (org.springframework.security.core.Authentication)12