Search in sources :

Example 96 with OrcidMessage

use of org.orcid.jaxb.model.message.OrcidMessage in project ORCID-Source by ORCID.

the class T2OrcidApiServiceVersionedDelegatorTest method testAttemptCreateWithTotallyIncorrectVersion.

@Test(expected = OrcidValidationException.class)
public void testAttemptCreateWithTotallyIncorrectVersion() {
    setUpSecurityContextForClientOnly();
    OrcidMessage orcidMessage = createStubOrcidMessage();
    orcidMessage.setMessageVersion("abc");
    Email email = new Email("madeupemail4@semantico.com");
    orcidMessage.getOrcidProfile().getOrcidBio().getContactDetails().getEmail().add(email);
    t2OrcidApiServiceDelegatorV2_1.createProfile(mockedUriInfo, orcidMessage);
}
Also used : Email(org.orcid.jaxb.model.message.Email) OrcidMessage(org.orcid.jaxb.model.message.OrcidMessage) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 97 with OrcidMessage

use of org.orcid.jaxb.model.message.OrcidMessage in project ORCID-Source by ORCID.

the class T2OrcidApiServiceDelegatorTest method testAddWorks.

@Test
public void testAddWorks() {
    SecurityContextTestUtils.setUpSecurityContext();
    OrcidMessage orcidMessage = new OrcidMessage();
    orcidMessage.setMessageVersion("1.2_rc6");
    OrcidProfile orcidProfile = new OrcidProfile();
    orcidMessage.setOrcidProfile(orcidProfile);
    orcidProfile.setOrcidIdentifier(new OrcidIdentifier("4444-4444-4444-4441"));
    OrcidActivities orcidActivities = new OrcidActivities();
    orcidProfile.setOrcidActivities(orcidActivities);
    OrcidWorks orcidWorks = new OrcidWorks();
    orcidActivities.setOrcidWorks(orcidWorks);
    Response response = t2OrcidApiServiceDelegator.addWorks(mockedUriInfo, "4444-4444-4444-4441", orcidMessage);
    assertNotNull(response);
    assertEquals(201, response.getStatus());
}
Also used : OrcidProfile(org.orcid.jaxb.model.message.OrcidProfile) Response(javax.ws.rs.core.Response) OrcidIdentifier(org.orcid.jaxb.model.message.OrcidIdentifier) OrcidMessage(org.orcid.jaxb.model.message.OrcidMessage) OrcidActivities(org.orcid.jaxb.model.message.OrcidActivities) OrcidWorks(org.orcid.jaxb.model.message.OrcidWorks) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 98 with OrcidMessage

use of org.orcid.jaxb.model.message.OrcidMessage in project ORCID-Source by ORCID.

the class T2OrcidApiServiceDelegatorTest method testAddDuplicatedExtIdsDontModifyProfile.

@Test
public void testAddDuplicatedExtIdsDontModifyProfile() {
    String userOrcid = "0000-0000-0000-0005";
    OrcidMessage message = new OrcidMessage();
    message.setMessageVersion("1.2_rc6");
    message.setOrcidProfile(new OrcidProfile());
    message.getOrcidProfile().setOrcidBio(new OrcidBio());
    ExternalIdentifiers extIds = new ExternalIdentifiers();
    ExternalIdentifier extId1 = new ExternalIdentifier();
    String commonName = "common-name-1-" + System.currentTimeMillis();
    extId1.setExternalIdCommonName(new ExternalIdCommonName(commonName));
    extId1.setExternalIdReference(new ExternalIdReference("ext-id-reference-1"));
    extId1.setExternalIdUrl(new ExternalIdUrl("http://test.orcid.org/" + System.currentTimeMillis()));
    extIds.getExternalIdentifier().add(extId1);
    message.getOrcidProfile().getOrcidBio().setExternalIdentifiers(extIds);
    // Add for client 1
    SecurityContextTestUtils.setUpSecurityContext(userOrcid, "APP-5555555555555555", ScopePathType.PERSON_UPDATE, ScopePathType.PERSON_READ_LIMITED);
    Response r = t2OrcidApiServiceDelegator.addExternalIdentifiers(null, userOrcid, message);
    assertNotNull(r);
    OrcidMessage newMessage1 = (OrcidMessage) r.getEntity();
    assertNotNull(newMessage1);
    assertNotNull(newMessage1.getOrcidProfile());
    assertNotNull(newMessage1.getOrcidProfile().getOrcidBio());
    assertNotNull(newMessage1.getOrcidProfile().getOrcidBio().getExternalIdentifiers());
    assertNotNull(newMessage1.getOrcidProfile().getOrcidBio().getExternalIdentifiers().getExternalIdentifier());
    assertEquals(1, newMessage1.getOrcidProfile().getOrcidBio().getExternalIdentifiers().getExternalIdentifier().size());
    assertEquals(commonName, newMessage1.getOrcidProfile().getOrcidBio().getExternalIdentifiers().getExternalIdentifier().get(0).getExternalIdCommonName().getContent());
    assertEquals("APP-5555555555555555", newMessage1.getOrcidProfile().getOrcidBio().getExternalIdentifiers().getExternalIdentifier().get(0).getSource().retrieveSourcePath());
    // Reset message to add it again
    message = new OrcidMessage();
    message.setMessageVersion("1.2_rc6");
    message.setOrcidProfile(new OrcidProfile());
    message.getOrcidProfile().setOrcidBio(new OrcidBio());
    extId1.setSource(null);
    message.getOrcidProfile().getOrcidBio().setExternalIdentifiers(extIds);
    r = t2OrcidApiServiceDelegator.addExternalIdentifiers(null, userOrcid, message);
    // If we add it again, no error, but it is not duplicated
    assertNotNull(r);
    OrcidMessage newMessage2 = (OrcidMessage) r.getEntity();
    assertNotNull(newMessage2);
    assertNotNull(newMessage2.getOrcidProfile());
    assertNotNull(newMessage2.getOrcidProfile().getOrcidBio());
    assertNotNull(newMessage2.getOrcidProfile().getOrcidBio().getExternalIdentifiers());
    assertNotNull(newMessage2.getOrcidProfile().getOrcidBio().getExternalIdentifiers().getExternalIdentifier());
    assertEquals(1, newMessage2.getOrcidProfile().getOrcidBio().getExternalIdentifiers().getExternalIdentifier().size());
    assertEquals(commonName, newMessage2.getOrcidProfile().getOrcidBio().getExternalIdentifiers().getExternalIdentifier().get(0).getExternalIdCommonName().getContent());
    assertEquals("APP-5555555555555555", newMessage2.getOrcidProfile().getOrcidBio().getExternalIdentifiers().getExternalIdentifier().get(0).getSource().retrieveSourcePath());
}
Also used : OrcidProfile(org.orcid.jaxb.model.message.OrcidProfile) Response(javax.ws.rs.core.Response) ExternalIdCommonName(org.orcid.jaxb.model.message.ExternalIdCommonName) OrcidBio(org.orcid.jaxb.model.message.OrcidBio) ExternalIdReference(org.orcid.jaxb.model.message.ExternalIdReference) WorkExternalIdentifier(org.orcid.jaxb.model.message.WorkExternalIdentifier) ExternalIdentifier(org.orcid.jaxb.model.message.ExternalIdentifier) FundingExternalIdentifier(org.orcid.jaxb.model.message.FundingExternalIdentifier) OrcidMessage(org.orcid.jaxb.model.message.OrcidMessage) WorkExternalIdentifiers(org.orcid.jaxb.model.message.WorkExternalIdentifiers) FundingExternalIdentifiers(org.orcid.jaxb.model.message.FundingExternalIdentifiers) ExternalIdentifiers(org.orcid.jaxb.model.message.ExternalIdentifiers) ExternalIdUrl(org.orcid.jaxb.model.message.ExternalIdUrl) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 99 with OrcidMessage

use of org.orcid.jaxb.model.message.OrcidMessage in project ORCID-Source by ORCID.

the class T2OrcidApiServiceDelegatorTest method testReadPrivateEmailsOnBio.

@Test
public void testReadPrivateEmailsOnBio() {
    SecurityContextTestUtils.setUpSecurityContext("4444-4444-4444-4497", ScopePathType.ORCID_BIO_READ_LIMITED, ScopePathType.EMAIL_READ_PRIVATE);
    /*Example A List on 4444-4444-4444-4497:
        Item 1 Private (client is source)
        Item 2 Private (other source)
        Item 3 Limited
        Item 4 Public 
        */
    OrcidProfile p = ((OrcidMessage) t2OrcidApiServiceDelegator.findBioDetails("4444-4444-4444-4497").getEntity()).getOrcidProfile();
    List<Email> emails = p.getOrcidBio().getContactDetails().getEmail();
    assertEquals(3, emails.size());
    boolean privateFound = false;
    boolean publicFound = false;
    boolean limitedFound = false;
    for (Email email : emails) {
        if ("public_4444-4444-4444-4497@test.orcid.org".equals(email.getValue()) && Visibility.PUBLIC.equals(email.getVisibility())) {
            publicFound = true;
        } else if ("limited_4444-4444-4444-4497@test.orcid.org".equals(email.getValue()) && Visibility.LIMITED.equals(email.getVisibility())) {
            limitedFound = true;
        } else if ("private_4444-4444-4444-4497@test.orcid.org".equals(email.getValue()) && Visibility.PRIVATE.equals(email.getVisibility())) {
            privateFound = true;
        }
    }
    assertTrue(publicFound);
    assertTrue(limitedFound);
    assertTrue(privateFound);
}
Also used : OrcidProfile(org.orcid.jaxb.model.message.OrcidProfile) Email(org.orcid.jaxb.model.message.Email) OrcidMessage(org.orcid.jaxb.model.message.OrcidMessage) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 100 with OrcidMessage

use of org.orcid.jaxb.model.message.OrcidMessage in project ORCID-Source by ORCID.

the class T2OrcidApiServiceDelegatorTest method testAddAffiliationToDeprecatedAccount.

@Test(expected = OrcidDeprecatedException.class)
public void testAddAffiliationToDeprecatedAccount() {
    SecurityContextTestUtils.setUpSecurityContext();
    OrcidMessage orcidMessage = new OrcidMessage();
    orcidMessage.setMessageVersion("1.2_rc6");
    OrcidProfile orcidProfile = new OrcidProfile();
    orcidMessage.setOrcidProfile(orcidProfile);
    orcidProfile.setOrcidIdentifier(new OrcidIdentifier("4444-4444-4444-444X"));
    OrcidActivities orcidActivities = new OrcidActivities();
    orcidProfile.setOrcidActivities(orcidActivities);
    OrganizationAddress address = new OrganizationAddress();
    address.setCity("City");
    address.setCountry(Iso3166Country.US);
    Organization org = new Organization();
    org.setAddress(address);
    org.setName("Testing org name");
    Affiliations affiliations = new Affiliations();
    Affiliation affiliation = new Affiliation();
    affiliation.setDepartmentName("Dept name");
    affiliation.setOrganization(org);
    affiliation.setType(AffiliationType.EMPLOYMENT);
    affiliations.getAffiliation().add(affiliation);
    orcidActivities.setAffiliations(affiliations);
    t2OrcidApiServiceDelegator.addAffiliations(mockedUriInfo, "4444-4444-4444-444X", orcidMessage);
}
Also used : OrcidProfile(org.orcid.jaxb.model.message.OrcidProfile) Organization(org.orcid.jaxb.model.message.Organization) Affiliations(org.orcid.jaxb.model.message.Affiliations) OrcidIdentifier(org.orcid.jaxb.model.message.OrcidIdentifier) OrcidMessage(org.orcid.jaxb.model.message.OrcidMessage) OrganizationAddress(org.orcid.jaxb.model.message.OrganizationAddress) OrcidActivities(org.orcid.jaxb.model.message.OrcidActivities) Affiliation(org.orcid.jaxb.model.message.Affiliation) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Aggregations

OrcidMessage (org.orcid.jaxb.model.message.OrcidMessage)173 Test (org.junit.Test)108 OrcidProfile (org.orcid.jaxb.model.message.OrcidProfile)64 DBUnitTest (org.orcid.test.DBUnitTest)49 ClientResponse (com.sun.jersey.api.client.ClientResponse)36 Response (javax.ws.rs.core.Response)26 OrcidWork (org.orcid.jaxb.model.message.OrcidWork)22 Transactional (org.springframework.transaction.annotation.Transactional)22 OrcidActivities (org.orcid.jaxb.model.message.OrcidActivities)20 OrcidBio (org.orcid.jaxb.model.message.OrcidBio)19 Email (org.orcid.jaxb.model.message.Email)18 BaseTest (org.orcid.core.BaseTest)17 OrcidIdentifier (org.orcid.jaxb.model.message.OrcidIdentifier)16 Affiliation (org.orcid.jaxb.model.message.Affiliation)13 OrcidSearchResult (org.orcid.jaxb.model.message.OrcidSearchResult)12 WorkExternalIdentifier (org.orcid.jaxb.model.message.WorkExternalIdentifier)12 JAXBContext (javax.xml.bind.JAXBContext)11 Unmarshaller (javax.xml.bind.Unmarshaller)11 Organization (org.orcid.jaxb.model.message.Organization)11 OrganizationAddress (org.orcid.jaxb.model.message.OrganizationAddress)11