Search in sources :

Example 56 with PersonExternalIdentifier

use of org.orcid.jaxb.model.v3.dev1.record.PersonExternalIdentifier in project ORCID-Source by ORCID.

the class MemberV3ApiServiceDelegator_ExternalIdentifiersTest method testReadPublicScope_ExternalIdentifiers.

@Test
public void testReadPublicScope_ExternalIdentifiers() {
    SecurityContextTestUtils.setUpSecurityContext(ORCID, ScopePathType.READ_PUBLIC);
    // Public works
    Response r = serviceDelegator.viewExternalIdentifiers(ORCID);
    assertNotNull(r);
    assertEquals(PersonExternalIdentifiers.class.getName(), r.getEntity().getClass().getName());
    PersonExternalIdentifiers p = (PersonExternalIdentifiers) r.getEntity();
    assertNotNull(p);
    assertEquals("/0000-0000-0000-0003/external-identifiers", p.getPath());
    Utils.verifyLastModified(p.getLastModifiedDate());
    assertEquals(3, p.getExternalIdentifiers().size());
    boolean found13 = false, found14 = false, found15 = false;
    for (PersonExternalIdentifier element : p.getExternalIdentifiers()) {
        if (element.getPutCode() == 13) {
            found13 = true;
        } else if (element.getPutCode() == 14) {
            found14 = true;
        } else if (element.getPutCode() == 15) {
            found15 = true;
        } else {
            fail("Invalid put code " + element.getPutCode());
        }
    }
    assertTrue(found13);
    assertTrue(found14);
    assertTrue(found15);
    r = serviceDelegator.viewExternalIdentifier(ORCID, 13L);
    assertNotNull(r);
    assertEquals(PersonExternalIdentifier.class.getName(), r.getEntity().getClass().getName());
    // Limited am the source of should work
    serviceDelegator.viewExternalIdentifier(ORCID, 14L);
    // Limited fail
    try {
        serviceDelegator.viewExternalIdentifier(ORCID, 16L);
        fail();
    } catch (OrcidAccessControlException e) {
    } catch (Exception e) {
        fail();
    }
    // Private am the source of should work
    serviceDelegator.viewExternalIdentifier(ORCID, 15L);
    // Private fail
    try {
        serviceDelegator.viewExternalIdentifier(ORCID, 17L);
        fail();
    } catch (OrcidAccessControlException e) {
    } catch (Exception e) {
        fail();
    }
}
Also used : Response(javax.ws.rs.core.Response) PersonExternalIdentifiers(org.orcid.jaxb.model.v3.dev1.record.PersonExternalIdentifiers) PersonExternalIdentifier(org.orcid.jaxb.model.v3.dev1.record.PersonExternalIdentifier) OrcidAccessControlException(org.orcid.core.exception.OrcidAccessControlException) NoResultException(javax.persistence.NoResultException) VisibilityMismatchException(org.orcid.core.exception.VisibilityMismatchException) WrongSourceException(org.orcid.core.exception.WrongSourceException) OrcidAccessControlException(org.orcid.core.exception.OrcidAccessControlException) OrcidVisibilityException(org.orcid.core.exception.OrcidVisibilityException) OrcidUnauthorizedException(org.orcid.core.exception.OrcidUnauthorizedException) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 57 with PersonExternalIdentifier

use of org.orcid.jaxb.model.v3.dev1.record.PersonExternalIdentifier in project ORCID-Source by ORCID.

the class MemberV3ApiServiceDelegator_ExternalIdentifiersTest method testUpdateExaternalIdentifierYouAreNotTheSourceOf.

@Test(expected = WrongSourceException.class)
public void testUpdateExaternalIdentifierYouAreNotTheSourceOf() {
    SecurityContextTestUtils.setUpSecurityContext("4444-4444-4444-4442", ScopePathType.PERSON_READ_LIMITED, ScopePathType.PERSON_UPDATE);
    Response response = serviceDelegator.viewExternalIdentifier("4444-4444-4444-4442", 3L);
    assertNotNull(response);
    PersonExternalIdentifier extId = (PersonExternalIdentifier) response.getEntity();
    assertNotNull(extId);
    assertEquals("Facebook", extId.getType());
    assertEquals("abc456", extId.getValue());
    assertNotNull(extId.getUrl());
    assertEquals("http://www.facebook.com/abc456", extId.getUrl().getValue());
    extId.setType("other-common-name");
    extId.setValue("other-reference");
    extId.setUrl(new Url("http://otherUrl.com"));
    serviceDelegator.updateExternalIdentifier("4444-4444-4444-4442", 3L, extId);
    fail();
}
Also used : Response(javax.ws.rs.core.Response) PersonExternalIdentifier(org.orcid.jaxb.model.v3.dev1.record.PersonExternalIdentifier) ResearcherUrl(org.orcid.jaxb.model.v3.dev1.record.ResearcherUrl) Url(org.orcid.jaxb.model.v3.dev1.common.Url) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 58 with PersonExternalIdentifier

use of org.orcid.jaxb.model.v3.dev1.record.PersonExternalIdentifier in project ORCID-Source by ORCID.

the class MemberV3ApiServiceDelegator_ExternalIdentifiersTest method testViewExternalIdentifierReadPublic.

@Test
public void testViewExternalIdentifierReadPublic() {
    SecurityContextTestUtils.setUpSecurityContextForClientOnly("APP-5555555555555555", ScopePathType.READ_PUBLIC);
    Response r = serviceDelegator.viewExternalIdentifier(ORCID, 13L);
    PersonExternalIdentifier element = (PersonExternalIdentifier) r.getEntity();
    assertNotNull(element);
    assertEquals("/0000-0000-0000-0003/external-identifiers/13", element.getPath());
    Utils.assertIsPublicOrSource(element, "APP-5555555555555555");
}
Also used : Response(javax.ws.rs.core.Response) PersonExternalIdentifier(org.orcid.jaxb.model.v3.dev1.record.PersonExternalIdentifier) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 59 with PersonExternalIdentifier

use of org.orcid.jaxb.model.v3.dev1.record.PersonExternalIdentifier in project ORCID-Source by ORCID.

the class MemberV3ApiServiceDelegator_ExternalIdentifiersTest method testUpdateExternalIdentifierChangingVisibilityTest.

@Test(expected = VisibilityMismatchException.class)
public void testUpdateExternalIdentifierChangingVisibilityTest() {
    SecurityContextTestUtils.setUpSecurityContext("4444-4444-4444-4442", ScopePathType.PERSON_READ_LIMITED, ScopePathType.PERSON_UPDATE);
    Response response = serviceDelegator.viewExternalIdentifier("4444-4444-4444-4442", 2L);
    assertNotNull(response);
    PersonExternalIdentifier extId = (PersonExternalIdentifier) response.getEntity();
    assertNotNull(extId);
    assertEquals(Visibility.PUBLIC, extId.getVisibility());
    extId.setVisibility(Visibility.PRIVATE);
    response = serviceDelegator.updateExternalIdentifier("4444-4444-4444-4442", 2L, extId);
    fail();
}
Also used : Response(javax.ws.rs.core.Response) PersonExternalIdentifier(org.orcid.jaxb.model.v3.dev1.record.PersonExternalIdentifier) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 60 with PersonExternalIdentifier

use of org.orcid.jaxb.model.v3.dev1.record.PersonExternalIdentifier in project ORCID-Source by ORCID.

the class MemberV3ApiServiceDelegator_GeneralTest method testOrcidProfileCreate_CANT_UpdateOnClaimedAccounts.

@Test
public void testOrcidProfileCreate_CANT_UpdateOnClaimedAccounts() {
    SecurityContextTestUtils.setUpSecurityContext(ORCID, ScopePathType.READ_LIMITED);
    Response response = serviceDelegator.viewAddress(ORCID, 9L);
    assertNotNull(response);
    Address a = (Address) response.getEntity();
    assertNotNull(a);
    try {
        SecurityContextTestUtils.setUpSecurityContextForClientOnly();
        serviceDelegator.updateAddress(ORCID, a.getPutCode(), a);
        fail();
    } catch (IllegalStateException e) {
        assertEquals("Non client credential scope found in client request", e.getMessage());
    }
    SecurityContextTestUtils.setUpSecurityContext(ORCID, ScopePathType.READ_LIMITED);
    response = serviceDelegator.viewEducation(ORCID, 20L);
    assertNotNull(response);
    Education edu = (Education) response.getEntity();
    assertNotNull(edu);
    try {
        SecurityContextTestUtils.setUpSecurityContextForClientOnly();
        serviceDelegator.updateEducation(ORCID, edu.getPutCode(), edu);
        fail();
    } catch (IllegalStateException e) {
        assertEquals("Non client credential scope found in client request", e.getMessage());
    }
    SecurityContextTestUtils.setUpSecurityContext(ORCID, ScopePathType.READ_LIMITED);
    response = serviceDelegator.viewEmployment(ORCID, 17L);
    assertNotNull(response);
    Employment emp = (Employment) response.getEntity();
    assertNotNull(emp);
    try {
        SecurityContextTestUtils.setUpSecurityContextForClientOnly();
        serviceDelegator.updateEmployment(ORCID, emp.getPutCode(), emp);
        fail();
    } catch (IllegalStateException e) {
        assertEquals("Non client credential scope found in client request", e.getMessage());
    }
    SecurityContextTestUtils.setUpSecurityContext(ORCID, ScopePathType.READ_LIMITED);
    response = serviceDelegator.viewExternalIdentifier(ORCID, 13L);
    assertNotNull(response);
    PersonExternalIdentifier extId = (PersonExternalIdentifier) response.getEntity();
    assertNotNull(extId);
    try {
        SecurityContextTestUtils.setUpSecurityContextForClientOnly();
        serviceDelegator.updateExternalIdentifier(ORCID, extId.getPutCode(), extId);
        fail();
    } catch (IllegalStateException e) {
        assertEquals("Non client credential scope found in client request", e.getMessage());
    }
    SecurityContextTestUtils.setUpSecurityContext(ORCID, ScopePathType.READ_LIMITED);
    response = serviceDelegator.viewFunding(ORCID, 10L);
    assertNotNull(response);
    Funding f = (Funding) response.getEntity();
    assertNotNull(f);
    try {
        SecurityContextTestUtils.setUpSecurityContextForClientOnly();
        serviceDelegator.updateFunding(ORCID, f.getPutCode(), f);
        fail();
    } catch (IllegalStateException e) {
        assertEquals("Non client credential scope found in client request", e.getMessage());
    }
    SecurityContextTestUtils.setUpSecurityContext(ORCID, ScopePathType.READ_LIMITED);
    response = serviceDelegator.viewKeyword(ORCID, 9L);
    assertNotNull(response);
    Keyword k = (Keyword) response.getEntity();
    assertNotNull(k);
    try {
        SecurityContextTestUtils.setUpSecurityContextForClientOnly();
        serviceDelegator.updateKeyword(ORCID, k.getPutCode(), k);
        fail();
    } catch (IllegalStateException e) {
        assertEquals("Non client credential scope found in client request", e.getMessage());
    }
    SecurityContextTestUtils.setUpSecurityContext(ORCID, ScopePathType.READ_LIMITED);
    response = serviceDelegator.viewOtherName(ORCID, 13L);
    assertNotNull(response);
    OtherName o = (OtherName) response.getEntity();
    assertNotNull(o);
    try {
        SecurityContextTestUtils.setUpSecurityContextForClientOnly();
        serviceDelegator.updateOtherName(ORCID, o.getPutCode(), o);
        fail();
    } catch (IllegalStateException e) {
        assertEquals("Non client credential scope found in client request", e.getMessage());
    }
    SecurityContextTestUtils.setUpSecurityContext(ORCID, ScopePathType.READ_LIMITED);
    response = serviceDelegator.viewPeerReview(ORCID, 9L);
    assertNotNull(response);
    PeerReview p = (PeerReview) response.getEntity();
    assertNotNull(p);
    try {
        SecurityContextTestUtils.setUpSecurityContextForClientOnly();
        serviceDelegator.updatePeerReview(ORCID, p.getPutCode(), p);
        fail();
    } catch (IllegalStateException e) {
        assertEquals("Non client credential scope found in client request", e.getMessage());
    }
    SecurityContextTestUtils.setUpSecurityContext(ORCID, ScopePathType.READ_LIMITED);
    response = serviceDelegator.viewResearcherUrl(ORCID, 13L);
    assertNotNull(response);
    ResearcherUrl r = (ResearcherUrl) response.getEntity();
    assertNotNull(r);
    try {
        SecurityContextTestUtils.setUpSecurityContextForClientOnly();
        serviceDelegator.updateResearcherUrl(ORCID, r.getPutCode(), r);
        fail();
    } catch (IllegalStateException e) {
        assertEquals("Non client credential scope found in client request", e.getMessage());
    }
    SecurityContextTestUtils.setUpSecurityContext(ORCID, ScopePathType.READ_LIMITED);
    response = serviceDelegator.viewWork(ORCID, 11L);
    assertNotNull(response);
    Work w = (Work) response.getEntity();
    assertNotNull(w);
    try {
        SecurityContextTestUtils.setUpSecurityContextForClientOnly();
        serviceDelegator.updateWork(ORCID, w.getPutCode(), w);
        fail();
    } catch (IllegalStateException e) {
        assertEquals("Non client credential scope found in client request", e.getMessage());
    }
}
Also used : Response(javax.ws.rs.core.Response) Address(org.orcid.jaxb.model.v3.dev1.record.Address) Keyword(org.orcid.jaxb.model.v3.dev1.record.Keyword) Education(org.orcid.jaxb.model.v3.dev1.record.Education) Employment(org.orcid.jaxb.model.v3.dev1.record.Employment) Funding(org.orcid.jaxb.model.v3.dev1.record.Funding) OtherName(org.orcid.jaxb.model.v3.dev1.record.OtherName) Work(org.orcid.jaxb.model.v3.dev1.record.Work) ResearcherUrl(org.orcid.jaxb.model.v3.dev1.record.ResearcherUrl) PersonExternalIdentifier(org.orcid.jaxb.model.v3.dev1.record.PersonExternalIdentifier) PeerReview(org.orcid.jaxb.model.v3.dev1.record.PeerReview) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Aggregations

PersonExternalIdentifier (org.orcid.jaxb.model.v3.dev1.record.PersonExternalIdentifier)93 Test (org.junit.Test)68 ResearcherUrl (org.orcid.jaxb.model.v3.dev1.record.ResearcherUrl)42 PersonExternalIdentifiers (org.orcid.jaxb.model.v3.dev1.record.PersonExternalIdentifiers)40 Address (org.orcid.jaxb.model.v3.dev1.record.Address)39 OtherName (org.orcid.jaxb.model.v3.dev1.record.OtherName)39 Keyword (org.orcid.jaxb.model.v3.dev1.record.Keyword)38 Email (org.orcid.jaxb.model.v3.dev1.record.Email)36 Biography (org.orcid.jaxb.model.v3.dev1.record.Biography)31 OtherNames (org.orcid.jaxb.model.v3.dev1.record.OtherNames)31 Addresses (org.orcid.jaxb.model.v3.dev1.record.Addresses)30 Emails (org.orcid.jaxb.model.v3.dev1.record.Emails)30 Keywords (org.orcid.jaxb.model.v3.dev1.record.Keywords)30 ResearcherUrls (org.orcid.jaxb.model.v3.dev1.record.ResearcherUrls)30 Person (org.orcid.jaxb.model.v3.dev1.record.Person)28 Name (org.orcid.jaxb.model.v3.dev1.record.Name)27 DBUnitTest (org.orcid.test.DBUnitTest)21 Response (javax.ws.rs.core.Response)19 Record (org.orcid.jaxb.model.v3.dev1.record.Record)15 EducationSummary (org.orcid.jaxb.model.v3.dev1.record.summary.EducationSummary)15