Search in sources :

Example 31 with OrcidError

use of org.orcid.jaxb.model.v3.dev1.error.OrcidError in project ORCID-Source by ORCID.

the class MemberV3Dev1Test method createViewUpdateAndDeleteFunding.

@Test
public void createViewUpdateAndDeleteFunding() throws JSONException, InterruptedException, URISyntaxException {
    long time = System.currentTimeMillis();
    Funding funding = (Funding) unmarshallFromPath("/record_3.0_dev1/samples/read_samples/funding-3.0_dev1.xml", Funding.class);
    funding.setPutCode(null);
    funding.setVisibility(Visibility.PUBLIC);
    funding.getExternalIdentifiers().getExternalIdentifier().clear();
    ExternalID fExtId = new ExternalID();
    fExtId.setType(FundingExternalIdentifierType.GRANT_NUMBER.value());
    fExtId.setValue("Funding Id " + time);
    fExtId.setRelationship(Relationship.SELF);
    funding.getExternalIdentifiers().getExternalIdentifier().add(fExtId);
    String accessToken = getAccessToken();
    ClientResponse postResponse = memberV3Dev1ApiClientImpl.createFundingXml(this.getUser1OrcidId(), funding, accessToken);
    assertNotNull(postResponse);
    assertEquals(Response.Status.CREATED.getStatusCode(), postResponse.getStatus());
    String locationPath = postResponse.getLocation().getPath();
    assertTrue("Location header path should match pattern, but was " + locationPath, locationPath.matches(".*/v3.0_dev1/" + this.getUser1OrcidId() + "/funding/\\d+"));
    ClientResponse getResponse = memberV3Dev1ApiClientImpl.viewLocationXml(postResponse.getLocation(), accessToken);
    assertEquals(Response.Status.OK.getStatusCode(), getResponse.getStatus());
    Funding gotFunding = getResponse.getEntity(Funding.class);
    assertEquals("common:title", gotFunding.getTitle().getTitle().getContent());
    assertEquals("common:translated-title", gotFunding.getTitle().getTranslatedTitle().getContent());
    assertEquals("en", gotFunding.getTitle().getTranslatedTitle().getLanguageCode());
    // Save the original visibility
    Visibility originalVisibility = gotFunding.getVisibility();
    Visibility updatedVisibility = Visibility.PRIVATE.equals(originalVisibility) ? Visibility.LIMITED : Visibility.PRIVATE;
    // Verify you cant update the visibility
    gotFunding.setVisibility(updatedVisibility);
    ClientResponse putResponse = memberV3Dev1ApiClientImpl.updateLocationXml(postResponse.getLocation(), accessToken, gotFunding);
    assertEquals(Response.Status.FORBIDDEN.getStatusCode(), putResponse.getStatus());
    OrcidError error = putResponse.getEntity(OrcidError.class);
    assertNotNull(error);
    assertEquals(Integer.valueOf(9035), error.getErrorCode());
    // Set the visibility again to the initial one
    gotFunding.setVisibility(originalVisibility);
    gotFunding.getTitle().getTitle().setContent("Updated title");
    gotFunding.getTitle().getTranslatedTitle().setContent("Updated translated title");
    gotFunding.getTitle().getTranslatedTitle().setLanguageCode("es");
    putResponse = memberV3Dev1ApiClientImpl.updateLocationXml(postResponse.getLocation(), accessToken, gotFunding);
    assertEquals(Response.Status.OK.getStatusCode(), putResponse.getStatus());
    ClientResponse getAfterUpdateResponse = memberV3Dev1ApiClientImpl.viewLocationXml(postResponse.getLocation(), accessToken);
    assertEquals(Response.Status.OK.getStatusCode(), getAfterUpdateResponse.getStatus());
    Funding gotAfterUpdateFunding = getAfterUpdateResponse.getEntity(Funding.class);
    assertEquals("Updated title", gotAfterUpdateFunding.getTitle().getTitle().getContent());
    assertEquals("Updated translated title", gotAfterUpdateFunding.getTitle().getTranslatedTitle().getContent());
    assertEquals("es", gotAfterUpdateFunding.getTitle().getTranslatedTitle().getLanguageCode());
    ClientResponse deleteResponse = memberV3Dev1ApiClientImpl.deleteFundingXml(this.getUser1OrcidId(), gotFunding.getPutCode(), accessToken);
    assertEquals(Response.Status.NO_CONTENT.getStatusCode(), deleteResponse.getStatus());
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) OrcidError(org.orcid.jaxb.model.v3.dev1.error.OrcidError) Funding(org.orcid.jaxb.model.v3.dev1.record.Funding) ExternalID(org.orcid.jaxb.model.v3.dev1.record.ExternalID) Visibility(org.orcid.jaxb.model.v3.dev1.common.Visibility) Test(org.junit.Test)

Example 32 with OrcidError

use of org.orcid.jaxb.model.v3.dev1.error.OrcidError in project ORCID-Source by ORCID.

the class MemberV3Dev1Test method createViewUpdateAndDeleteInvitedPosition.

@Test
public void createViewUpdateAndDeleteInvitedPosition() throws JSONException, InterruptedException, URISyntaxException {
    InvitedPosition invitedPosition = (InvitedPosition) unmarshallFromPath("/record_3.0_dev1/samples/read_samples/invited-position-3.0_dev1.xml", InvitedPosition.class);
    invitedPosition.setPutCode(null);
    invitedPosition.setVisibility(Visibility.PUBLIC);
    String accessToken = getAccessToken();
    ClientResponse postResponse = memberV3Dev1ApiClientImpl.createInvitedPositionXml(this.getUser1OrcidId(), invitedPosition, accessToken);
    assertNotNull(postResponse);
    assertEquals(Response.Status.CREATED.getStatusCode(), postResponse.getStatus());
    String locationPath = postResponse.getLocation().getPath();
    assertTrue("Location header path should match pattern, but was " + locationPath, locationPath.matches(".*/v3.0_dev1/" + this.getUser1OrcidId() + "/invited-position/\\d+"));
    ClientResponse getResponse = memberV3Dev1ApiClientImpl.viewLocationXml(postResponse.getLocation(), accessToken);
    assertEquals(Response.Status.OK.getStatusCode(), getResponse.getStatus());
    InvitedPosition gotInvitedPosition = getResponse.getEntity(InvitedPosition.class);
    assertEquals("department-name", gotInvitedPosition.getDepartmentName());
    assertEquals("role-title", gotInvitedPosition.getRoleTitle());
    // Save the original visibility
    Visibility originalVisibility = gotInvitedPosition.getVisibility();
    Visibility updatedVisibility = Visibility.PRIVATE.equals(originalVisibility) ? Visibility.LIMITED : Visibility.PRIVATE;
    // Verify you cant update the visibility
    gotInvitedPosition.setVisibility(updatedVisibility);
    ClientResponse putResponse = memberV3Dev1ApiClientImpl.updateLocationXml(postResponse.getLocation(), accessToken, gotInvitedPosition);
    assertEquals(Response.Status.FORBIDDEN.getStatusCode(), putResponse.getStatus());
    OrcidError error = putResponse.getEntity(OrcidError.class);
    assertNotNull(error);
    assertEquals(Integer.valueOf(9035), error.getErrorCode());
    // Set the visibility again to the initial one
    gotInvitedPosition.setVisibility(originalVisibility);
    gotInvitedPosition.setDepartmentName("updated dept. name");
    gotInvitedPosition.setRoleTitle("updated role title");
    putResponse = memberV3Dev1ApiClientImpl.updateLocationXml(postResponse.getLocation(), accessToken, gotInvitedPosition);
    assertEquals(Response.Status.OK.getStatusCode(), putResponse.getStatus());
    ClientResponse getAfterUpdateResponse = memberV3Dev1ApiClientImpl.viewLocationXml(postResponse.getLocation(), accessToken);
    assertEquals(Response.Status.OK.getStatusCode(), getAfterUpdateResponse.getStatus());
    InvitedPosition gotAfterUpdateInvitedPosition = getAfterUpdateResponse.getEntity(InvitedPosition.class);
    assertEquals("updated dept. name", gotAfterUpdateInvitedPosition.getDepartmentName());
    assertEquals("updated role title", gotAfterUpdateInvitedPosition.getRoleTitle());
    ClientResponse deleteResponse = memberV3Dev1ApiClientImpl.deleteInvitedPositionXml(this.getUser1OrcidId(), gotInvitedPosition.getPutCode(), accessToken);
    assertEquals(Response.Status.NO_CONTENT.getStatusCode(), deleteResponse.getStatus());
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) OrcidError(org.orcid.jaxb.model.v3.dev1.error.OrcidError) InvitedPosition(org.orcid.jaxb.model.v3.dev1.record.InvitedPosition) Visibility(org.orcid.jaxb.model.v3.dev1.common.Visibility) Test(org.junit.Test)

Example 33 with OrcidError

use of org.orcid.jaxb.model.v3.dev1.error.OrcidError in project ORCID-Source by ORCID.

the class MemberV3Dev1Test method createViewUpdateAndDeleteMembership.

@Test
public void createViewUpdateAndDeleteMembership() throws JSONException, InterruptedException, URISyntaxException {
    Membership membership = (Membership) unmarshallFromPath("/record_3.0_dev1/samples/read_samples/membership-3.0_dev1.xml", Membership.class);
    membership.setPutCode(null);
    membership.setVisibility(Visibility.PUBLIC);
    String accessToken = getAccessToken();
    ClientResponse postResponse = memberV3Dev1ApiClientImpl.createMembershipXml(this.getUser1OrcidId(), membership, accessToken);
    assertNotNull(postResponse);
    assertEquals(Response.Status.CREATED.getStatusCode(), postResponse.getStatus());
    String locationPath = postResponse.getLocation().getPath();
    assertTrue("Location header path should match pattern, but was " + locationPath, locationPath.matches(".*/v3.0_dev1/" + this.getUser1OrcidId() + "/membership/\\d+"));
    ClientResponse getResponse = memberV3Dev1ApiClientImpl.viewLocationXml(postResponse.getLocation(), accessToken);
    assertEquals(Response.Status.OK.getStatusCode(), getResponse.getStatus());
    Membership gotMembership = getResponse.getEntity(Membership.class);
    assertEquals("department-name", gotMembership.getDepartmentName());
    assertEquals("role-title", gotMembership.getRoleTitle());
    // Save the original visibility
    Visibility originalVisibility = gotMembership.getVisibility();
    Visibility updatedVisibility = Visibility.PRIVATE.equals(originalVisibility) ? Visibility.LIMITED : Visibility.PRIVATE;
    // Verify you cant update the visibility
    gotMembership.setVisibility(updatedVisibility);
    ClientResponse putResponse = memberV3Dev1ApiClientImpl.updateLocationXml(postResponse.getLocation(), accessToken, gotMembership);
    assertEquals(Response.Status.FORBIDDEN.getStatusCode(), putResponse.getStatus());
    OrcidError error = putResponse.getEntity(OrcidError.class);
    assertNotNull(error);
    assertEquals(Integer.valueOf(9035), error.getErrorCode());
    // Set the visibility again to the initial one
    gotMembership.setVisibility(originalVisibility);
    gotMembership.setDepartmentName("updated dept. name");
    gotMembership.setRoleTitle("updated role title");
    putResponse = memberV3Dev1ApiClientImpl.updateLocationXml(postResponse.getLocation(), accessToken, gotMembership);
    assertEquals(Response.Status.OK.getStatusCode(), putResponse.getStatus());
    ClientResponse getAfterUpdateResponse = memberV3Dev1ApiClientImpl.viewLocationXml(postResponse.getLocation(), accessToken);
    assertEquals(Response.Status.OK.getStatusCode(), getAfterUpdateResponse.getStatus());
    Membership gotAfterUpdateMembership = getAfterUpdateResponse.getEntity(Membership.class);
    assertEquals("updated dept. name", gotAfterUpdateMembership.getDepartmentName());
    assertEquals("updated role title", gotAfterUpdateMembership.getRoleTitle());
    ClientResponse deleteResponse = memberV3Dev1ApiClientImpl.deleteMembershipXml(this.getUser1OrcidId(), gotMembership.getPutCode(), accessToken);
    assertEquals(Response.Status.NO_CONTENT.getStatusCode(), deleteResponse.getStatus());
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) OrcidError(org.orcid.jaxb.model.v3.dev1.error.OrcidError) Membership(org.orcid.jaxb.model.v3.dev1.record.Membership) Visibility(org.orcid.jaxb.model.v3.dev1.common.Visibility) Test(org.junit.Test)

Example 34 with OrcidError

use of org.orcid.jaxb.model.v3.dev1.error.OrcidError in project ORCID-Source by ORCID.

the class WorksTest method testThreeWithInvalidTypeAllOthersAreFine.

@Test
public void testThreeWithInvalidTypeAllOthersAreFine() throws InterruptedException, JSONException {
    String accessToken = getAccessToken();
    WorkBulk bulk = createBulk(10, null);
    // Work 3: no type
    Work work3 = (Work) bulk.getBulk().get(3);
    work3.setWorkType(null);
    bulk.getBulk().set(3, work3);
    // Work 5: empty title
    Work work5 = (Work) bulk.getBulk().get(5);
    work5.getWorkTitle().getTitle().setContent(null);
    bulk.getBulk().set(5, work5);
    // Work 7: translated title language code empty
    Work work7 = (Work) bulk.getBulk().get(7);
    work7.getWorkTitle().getTranslatedTitle().setLanguageCode(null);
    bulk.getBulk().set(7, work7);
    ClientResponse postResponse = memberV3Dev1ApiClient.createWorksJson(this.getUser1OrcidId(), bulk, accessToken);
    assertNotNull(postResponse);
    assertEquals(Response.Status.OK.getStatusCode(), postResponse.getStatus());
    bulk = postResponse.getEntity(WorkBulk.class);
    assertNotNull(bulk);
    assertNotNull(bulk.getBulk());
    for (int i = 0; i < bulk.getBulk().size(); i++) {
        BulkElement element = bulk.getBulk().get(i);
        if (i == 3 || i == 5 || i == 7) {
            assertTrue(OrcidError.class.isAssignableFrom(element.getClass()));
            OrcidError error = (OrcidError) element;
            switch(i) {
                case 3:
                    assertEquals(Integer.valueOf(9001), error.getErrorCode());
                    assertTrue(error.getDeveloperMessage().endsWith("\"http://www.orcid.org/ns/work\":type}' is expected.)"));
                    break;
                case 5:
                    assertEquals(Integer.valueOf(9001), error.getErrorCode());
                    assertTrue(error.getDeveloperMessage().contains("Object must have some value in its @XmlValue field: org.orcid.jaxb.model.v3.dev1.common.Title"));
                    break;
                case 7:
                    assertEquals(Integer.valueOf(9001), error.getErrorCode());
                    assertTrue(error.getDeveloperMessage().endsWith("Attribute 'language-code' must appear on element 'common:translated-title'.)"));
                    break;
            }
        } else {
            assertTrue(Work.class.isAssignableFrom(element.getClass()));
            Work work = (Work) element;
            assertNotNull(work.getPutCode());
            memberV3Dev1ApiClient.deleteWorkXml(this.getUser1OrcidId(), work.getPutCode(), accessToken);
        }
    }
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) OrcidError(org.orcid.jaxb.model.v3.dev1.error.OrcidError) BulkElement(org.orcid.jaxb.model.record.bulk.BulkElement) WorkBulk(org.orcid.jaxb.model.v3.dev1.record.WorkBulk) Work(org.orcid.jaxb.model.v3.dev1.record.Work) Test(org.junit.Test)

Aggregations

OrcidError (org.orcid.jaxb.model.v3.dev1.error.OrcidError)33 Test (org.junit.Test)30 Work (org.orcid.jaxb.model.v3.dev1.record.Work)18 WorkBulk (org.orcid.jaxb.model.v3.dev1.record.WorkBulk)18 ClientResponse (com.sun.jersey.api.client.ClientResponse)15 Visibility (org.orcid.jaxb.model.v3.dev1.common.Visibility)11 ExternalID (org.orcid.jaxb.model.v3.dev1.record.ExternalID)9 BulkElement (org.orcid.jaxb.model.record.bulk.BulkElement)7 BaseTest (org.orcid.core.BaseTest)5 Url (org.orcid.jaxb.model.v3.dev1.common.Url)5 SourceEntity (org.orcid.persistence.jpa.entities.SourceEntity)5 Response (javax.ws.rs.core.Response)4 Title (org.orcid.jaxb.model.v3.dev1.common.Title)4 ExternalIDs (org.orcid.jaxb.model.v3.dev1.record.ExternalIDs)4 WorkTitle (org.orcid.jaxb.model.v3.dev1.record.WorkTitle)4 ClientDetailsEntity (org.orcid.persistence.jpa.entities.ClientDetailsEntity)4 DBUnitTest (org.orcid.test.DBUnitTest)4 ArrayList (java.util.ArrayList)3 AccessControlException (java.security.AccessControlException)1 Date (java.util.Date)1