Search in sources :

Example 11 with OrcidError

use of org.orcid.jaxb.model.error_rc3.OrcidError in project ORCID-Source by ORCID.

the class VerifyOrcidBeforeFetchElementTest method testFunding.

@Test
public void testFunding() throws InterruptedException, JSONException, URISyntaxException {
    long time = System.currentTimeMillis();
    Funding funding = (Funding) unmarshallFromPath("/record_2.0_rc1/samples/funding-2.0_rc1.xml", Funding.class);
    funding.setPutCode(null);
    funding.setVisibility(Visibility.PUBLIC);
    funding.getExternalIdentifiers().getExternalIdentifier().clear();
    FundingExternalIdentifier fExtId = new FundingExternalIdentifier();
    fExtId.setType(FundingExternalIdentifierType.GRANT_NUMBER);
    fExtId.setValue("Funding Id " + time);
    fExtId.setRelationship(Relationship.SELF);
    funding.getExternalIdentifiers().getExternalIdentifier().add(fExtId);
    String user1AccessToken = getAccessToken();
    // Create an funding
    ClientResponse postResponse = memberV2ApiClient.createFundingXml(getUser1OrcidId(), funding, user1AccessToken);
    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(".*/v2.0_rc1/" + getUser1OrcidId() + "/funding/\\d+"));
    // Fetch it with the owner
    ClientResponse getResponse = memberV2ApiClient.viewLocationXml(postResponse.getLocation(), user1AccessToken);
    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());
    // Try to fetch it with other user orcid
    // Using the members API
    String user2AccessToken = getAccessToken(getUser2OrcidId(), getUser2Password(), getScopes(ScopePathType.ACTIVITIES_UPDATE), getClient1ClientId(), getClient1ClientSecret(), getClient1RedirectUri());
    ClientResponse user2GetResponse = memberV2ApiClient.viewFundingXml(getUser2OrcidId(), gotFunding.getPutCode(), user2AccessToken);
    assertNotNull(user2GetResponse);
    assertEquals(Response.Status.NOT_FOUND.getStatusCode(), user2GetResponse.getStatus());
    OrcidError error = user2GetResponse.getEntity(OrcidError.class);
    assertNotNull(error);
    assertEquals(Integer.valueOf(9016), error.getErrorCode());
    // Using the public API
    user2GetResponse = publicV2ApiClient.viewFundingXml(getUser2OrcidId(), String.valueOf(gotFunding.getPutCode()));
    assertNotNull(user2GetResponse);
    assertEquals(Response.Status.NOT_FOUND.getStatusCode(), user2GetResponse.getStatus());
    error = user2GetResponse.getEntity(OrcidError.class);
    assertNotNull(error);
    assertEquals(Integer.valueOf(9016), error.getErrorCode());
    // Delete it
    ClientResponse deletedResponse = memberV2ApiClient.deleteFundingXml(getUser1OrcidId(), gotFunding.getPutCode(), user1AccessToken);
    assertNotNull(deletedResponse);
    assertEquals(Response.Status.NO_CONTENT.getStatusCode(), deletedResponse.getStatus());
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) OrcidError(org.orcid.jaxb.model.error_rc1.OrcidError) Funding(org.orcid.jaxb.model.record_rc1.Funding) FundingExternalIdentifier(org.orcid.jaxb.model.record_rc1.FundingExternalIdentifier) Test(org.junit.Test)

Example 12 with OrcidError

use of org.orcid.jaxb.model.error_rc3.OrcidError in project ORCID-Source by ORCID.

the class MemberV2ApiServiceVersionedDelegatorTest method testViewBulkWorksWithBadPutCode.

@Test
public void testViewBulkWorksWithBadPutCode() {
    SecurityContextTestUtils.setUpSecurityContext("0000-0000-0000-0003", ScopePathType.READ_LIMITED);
    Response response = serviceDelegator.viewBulkWorks("0000-0000-0000-0003", "11,12,13,bad");
    WorkBulk workBulk = (WorkBulk) response.getEntity();
    assertNotNull(workBulk);
    assertNotNull(workBulk.getBulk());
    assertEquals(4, workBulk.getBulk().size());
    assertTrue(workBulk.getBulk().get(0) instanceof Work);
    assertTrue(workBulk.getBulk().get(1) instanceof Work);
    // private work
    assertTrue(workBulk.getBulk().get(2) instanceof Work);
    // bad put code
    assertTrue(workBulk.getBulk().get(3) instanceof OrcidError);
}
Also used : Response(javax.ws.rs.core.Response) OrcidError(org.orcid.jaxb.model.error_v2.OrcidError) WorkBulk(org.orcid.jaxb.model.record_v2.WorkBulk) Work(org.orcid.jaxb.model.record_v2.Work) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 13 with OrcidError

use of org.orcid.jaxb.model.error_rc3.OrcidError in project ORCID-Source by ORCID.

the class MemberV2ApiServiceVersionedDelegatorTest method testViewBulkWorks.

@Test
public void testViewBulkWorks() {
    SecurityContextTestUtils.setUpSecurityContext("0000-0000-0000-0003", ScopePathType.READ_LIMITED);
    Response response = serviceDelegator.viewBulkWorks("0000-0000-0000-0003", "11,12,13,16");
    WorkBulk workBulk = (WorkBulk) response.getEntity();
    assertNotNull(workBulk);
    assertNotNull(workBulk.getBulk());
    assertEquals(4, workBulk.getBulk().size());
    assertTrue(workBulk.getBulk().get(0) instanceof Work);
    assertTrue(workBulk.getBulk().get(1) instanceof Work);
    // private work but matching source
    assertTrue(workBulk.getBulk().get(2) instanceof Work);
    // private work not matching source
    assertTrue(workBulk.getBulk().get(3) instanceof OrcidError);
}
Also used : Response(javax.ws.rs.core.Response) OrcidError(org.orcid.jaxb.model.error_v2.OrcidError) WorkBulk(org.orcid.jaxb.model.record_v2.WorkBulk) Work(org.orcid.jaxb.model.record_v2.Work) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 14 with OrcidError

use of org.orcid.jaxb.model.error_rc3.OrcidError in project ORCID-Source by ORCID.

the class MemberV2ApiServiceDelegator_WorksTest method testViewBulkWorksWithBadPutCode.

@Test
public void testViewBulkWorksWithBadPutCode() {
    SecurityContextTestUtils.setUpSecurityContext(ORCID, ScopePathType.READ_LIMITED);
    Response response = serviceDelegator.viewBulkWorks(ORCID, "11,12,13,bad");
    WorkBulk workBulk = (WorkBulk) response.getEntity();
    assertNotNull(workBulk);
    assertNotNull(workBulk.getBulk());
    assertEquals(4, workBulk.getBulk().size());
    assertTrue(workBulk.getBulk().get(0) instanceof Work);
    assertTrue(workBulk.getBulk().get(1) instanceof Work);
    // private work
    assertTrue(workBulk.getBulk().get(2) instanceof Work);
    // bad put code
    assertTrue(workBulk.getBulk().get(3) instanceof OrcidError);
}
Also used : Response(javax.ws.rs.core.Response) OrcidError(org.orcid.jaxb.model.error_v2.OrcidError) WorkBulk(org.orcid.jaxb.model.record_v2.WorkBulk) Work(org.orcid.jaxb.model.record_v2.Work) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 15 with OrcidError

use of org.orcid.jaxb.model.error_rc3.OrcidError in project ORCID-Source by ORCID.

the class WorksTest method testCantAddMoreThan1000WorksAtATime.

@Test
public void testCantAddMoreThan1000WorksAtATime() throws InterruptedException, JSONException {
    String accessToken = getAccessToken();
    WorkBulk bulk = createBulk(1001, null);
    ClientResponse postResponse = memberV2ApiClient.createWorksJson(this.getUser1OrcidId(), bulk, accessToken);
    assertNotNull(postResponse);
    assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), postResponse.getStatus());
    OrcidError error = postResponse.getEntity(OrcidError.class);
    assertNotNull(error);
    assertEquals(Integer.valueOf(9006), error.getErrorCode());
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) OrcidError(org.orcid.jaxb.model.error_v2.OrcidError) WorkBulk(org.orcid.jaxb.model.record_v2.WorkBulk) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)70 ClientResponse (com.sun.jersey.api.client.ClientResponse)56 OrcidError (org.orcid.jaxb.model.error_v2.OrcidError)51 OrcidError (org.orcid.jaxb.model.error_rc1.OrcidError)25 WorkBulk (org.orcid.jaxb.model.record_v2.WorkBulk)23 Work (org.orcid.jaxb.model.record_v2.Work)22 BulkElement (org.orcid.jaxb.model.record.bulk.BulkElement)13 ExternalID (org.orcid.jaxb.model.record_v2.ExternalID)12 Visibility (org.orcid.jaxb.model.common_v2.Visibility)11 Response (javax.ws.rs.core.Response)8 OrcidError (org.orcid.jaxb.model.error_rc3.OrcidError)8 OrcidError (org.orcid.jaxb.model.error_rc4.OrcidError)8 Url (org.orcid.jaxb.model.common_v2.Url)7 LockedRecordException (org.orcid.listener.exception.LockedRecordException)7 DBUnitTest (org.orcid.test.DBUnitTest)7 Locale (java.util.Locale)6 DeprecatedRecordException (org.orcid.listener.exception.DeprecatedRecordException)6 Visibility (org.orcid.jaxb.model.common_rc1.Visibility)5 Visibility (org.orcid.jaxb.model.common_rc2.Visibility)5 Visibility (org.orcid.jaxb.model.common_rc4.Visibility)5