Search in sources :

Example 11 with OrcidClientGroup

use of org.orcid.jaxb.model.clientgroup.OrcidClientGroup in project ORCID-Source by ORCID.

the class OrcidClientGroupManagerTest method testCreateOrcidClientGroup.

@Test
public void testCreateOrcidClientGroup() {
    OrcidClientGroup createdGroup = orcidClientGroupManager.createOrUpdateOrcidClientGroup(group);
    assertNotNull(createdGroup);
    assertEquals(group.getGroupName(), createdGroup.getGroupName());
    assertEquals(group.getEmail(), createdGroup.getEmail());
    assertNotNull(createdGroup.getGroupOrcid());
    List<OrcidClient> createdClients = createdGroup.getOrcidClient();
    assertNotNull(createdClients);
    assertEquals(2, createdClients.size());
    Map<String, OrcidClient> createdClientsMappedByName = new HashMap<String, OrcidClient>();
    for (OrcidClient createdClient : createdClients) {
        assertNotNull(createdClient.getClientId());
        assertNotNull(createdClient.getClientSecret());
        assertNotNull(createdClient.getIdp());
        createdClientsMappedByName.put(createdClient.getDisplayName(), createdClient);
    }
    OrcidClient complexityClient = createdClientsMappedByName.get("Ecological Complexity");
    assertNotNull(complexityClient);
    assertEquals("http://www.journals.elsevier.com/ecological-complexity", complexityClient.getWebsite());
    assertEquals("An International Journal on Biocomplexity in the Environment and Theoretical Ecology", complexityClient.getShortDescription());
    List<RedirectUri> createdRedirectUris = complexityClient.getRedirectUris().getRedirectUri();
    assertNotNull(createdRedirectUris);
    assertEquals(1, createdRedirectUris.size());
    assertEquals("http://www.journals.elsevier.com/ecological-complexity/orcid-callback", createdRedirectUris.get(0).getValue());
    assertEquals("grant-read-wizard", createdRedirectUris.get(0).getType().value());
    List<ScopePathType> scopesForRedirect = createdRedirectUris.get(0).getScope();
    assertTrue(scopesForRedirect.size() == 2);
    assertTrue(scopesForRedirect.contains(ScopePathType.ORCID_PROFILE_CREATE) && scopesForRedirect.contains(ScopePathType.ORCID_BIO_READ_LIMITED));
    assertEquals("http://www.journals.elsevier.com/ecological-complexity/orcid-callback", createdRedirectUris.get(0).getValue());
    assertEquals("grant-read-wizard", createdRedirectUris.get(0).getType().value());
    // Look up client details directly to check scopes
    ClientDetailsEntity complexityEntity = clientDetailsManager.findByClientId(complexityClient.getClientId());
    Set<String> clientScopeTypes = complexityEntity.getScope();
    assertNotNull(clientScopeTypes);
    assertTrue(clientScopeTypes.contains("/orcid-bio/update"));
    assertTrue(clientScopeTypes.contains("/orcid-bio/read-limited"));
    assertTrue(clientScopeTypes.contains("/orcid-works/read-limited"));
    assertFalse(clientScopeTypes.contains("/orcid-profile/create"));
    assertTrue(clientScopeTypes.contains("/authenticate"));
}
Also used : ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) ScopePathType(org.orcid.jaxb.model.message.ScopePathType) OrcidClientGroup(org.orcid.jaxb.model.clientgroup.OrcidClientGroup) HashMap(java.util.HashMap) OrcidClient(org.orcid.jaxb.model.clientgroup.OrcidClient) RedirectUri(org.orcid.jaxb.model.clientgroup.RedirectUri) Test(org.junit.Test) BaseTest(org.orcid.core.BaseTest)

Example 12 with OrcidClientGroup

use of org.orcid.jaxb.model.clientgroup.OrcidClientGroup in project ORCID-Source by ORCID.

the class OrcidClientGroupManagerTest method testGetOrcidClientList.

@Test
public void testGetOrcidClientList() {
    OrcidClientGroup createdGroup = orcidClientGroupManager.createOrUpdateOrcidClientGroup(group);
    createdGroup = orcidClientGroupManager.retrieveOrcidClientGroup(createdGroup.getGroupOrcid());
    assertNotNull(createdGroup);
    assertNotNull(createdGroup.getOrcidClient());
    assertEquals(2, createdGroup.getOrcidClient().size());
}
Also used : OrcidClientGroup(org.orcid.jaxb.model.clientgroup.OrcidClientGroup) Test(org.junit.Test) BaseTest(org.orcid.core.BaseTest)

Example 13 with OrcidClientGroup

use of org.orcid.jaxb.model.clientgroup.OrcidClientGroup in project ORCID-Source by ORCID.

the class OrcidClientGroupManagerTest method testAddUpdaterToBasicInstitutionGroup.

@Test
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void testAddUpdaterToBasicInstitutionGroup() {
    final OrcidClientGroup group = new OrcidClientGroup();
    group.setGroupName("Elsevier");
    group.setEmail("basic-institution-member@elsevier.com" + System.currentTimeMillis());
    group.setType(MemberType.BASIC_INSTITUTION);
    OrcidClientGroup createdGroup = transactionTemplate.execute(new TransactionCallback<OrcidClientGroup>() {

        public OrcidClientGroup doInTransaction(TransactionStatus status) {
            return orcidClientGroupManager.createOrUpdateOrcidClientGroup(group);
        }
    });
    RedirectUris redirectUris = new RedirectUris();
    RedirectUri redirectUri = new RedirectUri("http://uri.com");
    redirectUris.getRedirectUri().add(redirectUri);
    OrcidClient client1 = new OrcidClient();
    client1.setDisplayName("Name");
    client1.setRedirectUris(redirectUris);
    client1.setShortDescription("Description");
    client1.setType(ClientType.UPDATER);
    client1.setWebsite("http://site.com");
    // Add one creator client to a basic group should fail
    try {
        OrcidClient orcidClient = orcidClientGroupManager.createAndPersistClientProfile(createdGroup.getGroupOrcid(), client1);
        assertEquals(orcidClient.getType(), ClientType.CREATOR);
    } catch (OrcidClientGroupManagementException e) {
    }
}
Also used : OrcidClientGroup(org.orcid.jaxb.model.clientgroup.OrcidClientGroup) OrcidClient(org.orcid.jaxb.model.clientgroup.OrcidClient) OrcidClientGroupManagementException(org.orcid.core.exception.OrcidClientGroupManagementException) TransactionStatus(org.springframework.transaction.TransactionStatus) RedirectUris(org.orcid.jaxb.model.clientgroup.RedirectUris) RedirectUri(org.orcid.jaxb.model.clientgroup.RedirectUri) Test(org.junit.Test) BaseTest(org.orcid.core.BaseTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 14 with OrcidClientGroup

use of org.orcid.jaxb.model.clientgroup.OrcidClientGroup in project ORCID-Source by ORCID.

the class OrcidClientGroupManagerTest method testAddMoreThanOneClientToBasicGroup.

@Test
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void testAddMoreThanOneClientToBasicGroup() {
    final OrcidClientGroup group = new OrcidClientGroup();
    group.setGroupName("Elsevier");
    group.setEmail("basic-member@elsevier.com" + System.currentTimeMillis());
    group.setType(MemberType.BASIC);
    OrcidClientGroup createdGroup = transactionTemplate.execute(new TransactionCallback<OrcidClientGroup>() {

        public OrcidClientGroup doInTransaction(TransactionStatus status) {
            return orcidClientGroupManager.createOrUpdateOrcidClientGroup(group);
        }
    });
    RedirectUris redirectUris = new RedirectUris();
    RedirectUri redirectUri = new RedirectUri("http://uri.com");
    redirectUris.getRedirectUri().add(redirectUri);
    OrcidClient client1 = new OrcidClient();
    client1.setDisplayName("Name");
    client1.setRedirectUris(redirectUris);
    client1.setShortDescription("Description");
    client1.setType(ClientType.UPDATER);
    client1.setWebsite("http://site.com");
    // Add one client
    try {
        orcidClientGroupManager.createAndPersistClientProfile(createdGroup.getGroupOrcid(), client1);
    } catch (OrcidClientGroupManagementException e) {
        fail();
    }
    OrcidClient client2 = new OrcidClient();
    client2.setDisplayName("Name");
    client2.setRedirectUris(redirectUris);
    client2.setShortDescription("Description");
    client2.setType(ClientType.UPDATER);
    client2.setWebsite("http://site.com");
    // Add other client should fail
    try {
        orcidClientGroupManager.createAndPersistClientProfile(createdGroup.getGroupOrcid(), client2);
        fail();
    } catch (OrcidClientGroupManagementException e) {
    }
}
Also used : OrcidClientGroup(org.orcid.jaxb.model.clientgroup.OrcidClientGroup) OrcidClient(org.orcid.jaxb.model.clientgroup.OrcidClient) OrcidClientGroupManagementException(org.orcid.core.exception.OrcidClientGroupManagementException) TransactionStatus(org.springframework.transaction.TransactionStatus) RedirectUris(org.orcid.jaxb.model.clientgroup.RedirectUris) RedirectUri(org.orcid.jaxb.model.clientgroup.RedirectUri) Test(org.junit.Test) BaseTest(org.orcid.core.BaseTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 15 with OrcidClientGroup

use of org.orcid.jaxb.model.clientgroup.OrcidClientGroup in project ORCID-Source by ORCID.

the class OrcidClientGroupManagerTest method testUpdateGroup.

@Test
public void testUpdateGroup() {
    final OrcidClientGroup createdGroup = transactionTemplate.execute(new TransactionCallback<OrcidClientGroup>() {

        public OrcidClientGroup doInTransaction(TransactionStatus status) {
            return orcidClientGroupManager.createOrUpdateOrcidClientGroup(group);
        }
    });
    assertNotNull(createdGroup);
    assertEquals(MemberType.PREMIUM, createdGroup.getType());
    Set<String> premiumScopes = orcidClientGroupManager.premiumUpdaterScopes();
    //Get existing clients
    List<ClientDetailsEntity> clients = clientDetailsManager.findByGroupId(createdGroup.getGroupOrcid());
    assertEquals(2, clients.size());
    for (ClientDetailsEntity clientDetails : clients) {
        assertEquals(ClientType.PREMIUM_UPDATER, clientDetails.getClientType());
        assertTrue(clientDetails.isScoped());
        assertEquals(premiumScopes.size(), clientDetails.getScope().size());
    }
    //Update the group type
    createdGroup.setType(MemberType.PREMIUM_INSTITUTION);
    transactionTemplate.execute(new TransactionCallbackWithoutResult() {

        @Override
        protected void doInTransactionWithoutResult(TransactionStatus status) {
            orcidClientGroupManager.updateGroup(createdGroup);
        }
    });
    Set<String> premiumInstitutionScopes = orcidClientGroupManager.premiumCreatorScopes();
    clients = clientDetailsManager.findByGroupId(createdGroup.getGroupOrcid());
    assertEquals(2, clients.size());
    for (ClientDetailsEntity clientDetails : clients) {
        assertEquals(ClientType.PREMIUM_CREATOR, clientDetails.getClientType());
        assertTrue(clientDetails.isScoped());
        assertEquals(premiumInstitutionScopes.size(), clientDetails.getScope().size());
    }
}
Also used : ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) OrcidClientGroup(org.orcid.jaxb.model.clientgroup.OrcidClientGroup) TransactionStatus(org.springframework.transaction.TransactionStatus) TransactionCallbackWithoutResult(org.springframework.transaction.support.TransactionCallbackWithoutResult) Test(org.junit.Test) BaseTest(org.orcid.core.BaseTest)

Aggregations

OrcidClientGroup (org.orcid.jaxb.model.clientgroup.OrcidClientGroup)20 OrcidClient (org.orcid.jaxb.model.clientgroup.OrcidClient)13 Test (org.junit.Test)11 BaseTest (org.orcid.core.BaseTest)11 Transactional (org.springframework.transaction.annotation.Transactional)10 RedirectUri (org.orcid.jaxb.model.clientgroup.RedirectUri)9 TransactionStatus (org.springframework.transaction.TransactionStatus)8 OrcidClientGroupManagementException (org.orcid.core.exception.OrcidClientGroupManagementException)7 RedirectUris (org.orcid.jaxb.model.clientgroup.RedirectUris)6 ClientDetailsEntity (org.orcid.persistence.jpa.entities.ClientDetailsEntity)5 HashMap (java.util.HashMap)3 OrcidProfile (org.orcid.jaxb.model.message.OrcidProfile)2 ScopePathType (org.orcid.jaxb.model.message.ScopePathType)2 ProfileEntity (org.orcid.persistence.jpa.entities.ProfileEntity)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 ArrayList (java.util.ArrayList)1 Produces (javax.ws.rs.Produces)1 EmailEntity (org.orcid.persistence.jpa.entities.EmailEntity)1 OrcidEntityIdComparator (org.orcid.persistence.jpa.entities.OrcidEntityIdComparator)1 Client (org.orcid.pojo.ajaxForm.Client)1