Search in sources :

Example 86 with Funding

use of org.orcid.jaxb.model.record_rc4.Funding in project ORCID-Source by ORCID.

the class MemberV2ApiServiceDelegator_FundingTest method testUpdateFunding.

@Test
public void testUpdateFunding() {
    SecurityContextTestUtils.setUpSecurityContext("4444-4444-4444-4447", ScopePathType.READ_LIMITED, ScopePathType.ACTIVITIES_UPDATE);
    Response response = serviceDelegator.viewFunding("4444-4444-4444-4447", 6L);
    assertNotNull(response);
    Funding funding = (Funding) response.getEntity();
    assertNotNull(funding);
    assertEquals("Public Funding # 1", funding.getTitle().getTitle().getContent());
    assertEquals("This is the description for funding with id 6", funding.getDescription());
    LastModifiedDate before = funding.getLastModifiedDate();
    funding.getTitle().getTitle().setContent("Updated funding title");
    funding.setDescription("This is an updated description");
    ExternalID fExtId = new ExternalID();
    fExtId.setRelationship(Relationship.PART_OF);
    fExtId.setType(FundingExternalIdentifierType.GRANT_NUMBER.value());
    fExtId.setUrl(new Url("http://fundingExtId.com"));
    fExtId.setValue("new-funding-ext-id");
    ExternalIDs fExtIds = new ExternalIDs();
    fExtIds.getExternalIdentifier().add(fExtId);
    funding.setExternalIdentifiers(fExtIds);
    response = serviceDelegator.updateFunding("4444-4444-4444-4447", 6L, funding);
    assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
    response = serviceDelegator.viewFunding("4444-4444-4444-4447", 6L);
    assertNotNull(response);
    funding = (Funding) response.getEntity();
    assertNotNull(funding);
    Utils.verifyLastModified(funding.getLastModifiedDate());
    assertTrue(funding.getLastModifiedDate().after(before));
    assertEquals("Updated funding title", funding.getTitle().getTitle().getContent());
    assertEquals("This is an updated description", funding.getDescription());
    // Rollback changes
    funding.getTitle().getTitle().setContent("Public Funding # 1");
    funding.setDescription("This is the description for funding with id 6");
    response = serviceDelegator.updateFunding("4444-4444-4444-4447", 6L, funding);
    assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
}
Also used : Response(javax.ws.rs.core.Response) LastModifiedDate(org.orcid.jaxb.model.common_v2.LastModifiedDate) ExternalIDs(org.orcid.jaxb.model.record_v2.ExternalIDs) Funding(org.orcid.jaxb.model.record_v2.Funding) ExternalID(org.orcid.jaxb.model.record_v2.ExternalID) Url(org.orcid.jaxb.model.common_v2.Url) ResearcherUrl(org.orcid.jaxb.model.record_v2.ResearcherUrl) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 87 with Funding

use of org.orcid.jaxb.model.record_rc4.Funding in project ORCID-Source by ORCID.

the class MemberV2ApiServiceDelegator_FundingTest method testUpdateFundingYouAreNotTheSourceOf.

@Test(expected = WrongSourceException.class)
public void testUpdateFundingYouAreNotTheSourceOf() {
    SecurityContextTestUtils.setUpSecurityContext("4444-4444-4444-4446", ScopePathType.READ_LIMITED, ScopePathType.ACTIVITIES_UPDATE);
    Response response = serviceDelegator.viewFunding("4444-4444-4444-4446", 5L);
    assertNotNull(response);
    Funding funding = (Funding) response.getEntity();
    assertNotNull(funding);
    funding.getTitle().getTitle().setContent("Updated funding title");
    ExternalID fExtId = new ExternalID();
    fExtId.setRelationship(Relationship.PART_OF);
    fExtId.setType(FundingExternalIdentifierType.GRANT_NUMBER.value());
    fExtId.setUrl(new Url("http://fundingExtId.com"));
    fExtId.setValue("new-funding-ext-id");
    ExternalIDs fExtIds = new ExternalIDs();
    fExtIds.getExternalIdentifier().add(fExtId);
    funding.setExternalIdentifiers(fExtIds);
    serviceDelegator.updateFunding("4444-4444-4444-4446", 5L, funding);
    fail();
}
Also used : Response(javax.ws.rs.core.Response) ExternalIDs(org.orcid.jaxb.model.record_v2.ExternalIDs) Funding(org.orcid.jaxb.model.record_v2.Funding) ExternalID(org.orcid.jaxb.model.record_v2.ExternalID) Url(org.orcid.jaxb.model.common_v2.Url) ResearcherUrl(org.orcid.jaxb.model.record_v2.ResearcherUrl) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 88 with Funding

use of org.orcid.jaxb.model.record_rc4.Funding in project ORCID-Source by ORCID.

the class MemberV2ApiServiceDelegator_FundingTest method testDeleteFunding.

@Test(expected = NoResultException.class)
public void testDeleteFunding() {
    SecurityContextTestUtils.setUpSecurityContext("4444-4444-4444-4442", ScopePathType.READ_LIMITED, ScopePathType.ACTIVITIES_UPDATE);
    Response response = serviceDelegator.viewFunding("4444-4444-4444-4442", 7L);
    assertNotNull(response);
    Funding funding = (Funding) response.getEntity();
    assertNotNull(funding);
    response = serviceDelegator.deleteFunding("4444-4444-4444-4442", 7L);
    assertNotNull(response);
    assertEquals(Response.Status.NO_CONTENT.getStatusCode(), response.getStatus());
    serviceDelegator.viewFunding("4444-4444-4444-4442", 7L);
}
Also used : Response(javax.ws.rs.core.Response) Funding(org.orcid.jaxb.model.record_v2.Funding) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 89 with Funding

use of org.orcid.jaxb.model.record_rc4.Funding in project ORCID-Source by ORCID.

the class MemberV2ApiServiceDelegator_FundingTest method testViewPrivateFunding.

@Test
public void testViewPrivateFunding() {
    // Use the smallest scope in the pyramid to verify that you can read
    // your own limited and protected data
    SecurityContextTestUtils.setUpSecurityContext("4444-4444-4444-4446", ScopePathType.READ_LIMITED);
    Response response = serviceDelegator.viewFunding("4444-4444-4444-4446", 4L);
    assertNotNull(response);
    Funding funding = (Funding) response.getEntity();
    assertNotNull(funding);
    Utils.verifyLastModified(funding.getLastModifiedDate());
    assertNotNull(funding.getTitle());
    assertNotNull(funding.getTitle().getTitle());
    assertEquals(Long.valueOf(4), funding.getPutCode());
    assertEquals("/4444-4444-4444-4446/funding/4", funding.getPath());
    assertEquals("Private Funding", funding.getTitle().getTitle().getContent());
    assertEquals(Visibility.PRIVATE.value(), funding.getVisibility().value());
}
Also used : Response(javax.ws.rs.core.Response) Funding(org.orcid.jaxb.model.record_v2.Funding) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 90 with Funding

use of org.orcid.jaxb.model.record_rc4.Funding in project ORCID-Source by ORCID.

the class MemberV2ApiServiceDelegator_FundingTest method testAddFunding.

@Test
public void testAddFunding() {
    SecurityContextTestUtils.setUpSecurityContext("4444-4444-4444-4447", ScopePathType.READ_LIMITED, ScopePathType.ACTIVITIES_UPDATE);
    Response response = serviceDelegator.viewActivities("4444-4444-4444-4447");
    assertNotNull(response);
    ActivitiesSummary summary = (ActivitiesSummary) response.getEntity();
    assertNotNull(summary);
    Utils.verifyLastModified(summary.getLastModifiedDate());
    assertNotNull(summary.getFundings());
    Utils.verifyLastModified(summary.getFundings().getLastModifiedDate());
    assertNotNull(summary.getFundings().getFundingGroup());
    assertNotNull(summary.getFundings().getFundingGroup().get(0));
    Utils.verifyLastModified(summary.getLastModifiedDate());
    assertNotNull(summary.getFundings().getFundingGroup().get(0).getFundingSummary());
    assertEquals(1, summary.getFundings().getFundingGroup().get(0).getFundingSummary().size());
    assertNotNull(summary.getFundings().getFundingGroup().get(0).getFundingSummary().get(0));
    Utils.verifyLastModified(summary.getLastModifiedDate());
    assertNotNull(summary.getFundings().getFundingGroup().get(0).getFundingSummary().get(0).getTitle());
    assertNotNull(summary.getFundings().getFundingGroup().get(0).getFundingSummary().get(0).getTitle().getTitle());
    assertEquals("Public Funding # 1", summary.getFundings().getFundingGroup().get(0).getFundingSummary().get(0).getTitle().getTitle().getContent());
    Funding newFunding = Utils.getFunding();
    response = serviceDelegator.createFunding("4444-4444-4444-4447", newFunding);
    assertNotNull(response);
    assertEquals(Response.Status.CREATED.getStatusCode(), response.getStatus());
    response = serviceDelegator.viewActivities("4444-4444-4444-4447");
    assertNotNull(response);
    summary = (ActivitiesSummary) response.getEntity();
    assertNotNull(summary);
    Utils.verifyLastModified(summary.getLastModifiedDate());
    assertNotNull(summary.getFundings());
    assertNotNull(summary.getFundings().getFundingGroup());
    assertEquals(2, summary.getFundings().getFundingGroup().size());
    boolean haveOld = false;
    boolean haveNew = false;
    for (FundingGroup group : summary.getFundings().getFundingGroup()) {
        assertNotNull(group.getFundingSummary().get(0));
        assertNotNull(group.getFundingSummary().get(0).getTitle());
        assertNotNull(group.getFundingSummary().get(0).getTitle().getTitle());
        assertNotNull(group.getFundingSummary().get(0).getTitle().getTitle().getContent());
        if ("Public Funding # 1".equals(group.getFundingSummary().get(0).getTitle().getTitle().getContent())) {
            haveOld = true;
        } else if ("Public Funding # 2".equals(group.getFundingSummary().get(0).getTitle().getTitle().getContent())) {
            haveNew = true;
        }
    }
    assertTrue(haveOld);
    assertTrue(haveNew);
}
Also used : Response(javax.ws.rs.core.Response) Funding(org.orcid.jaxb.model.record_v2.Funding) FundingGroup(org.orcid.jaxb.model.record.summary_v2.FundingGroup) ActivitiesSummary(org.orcid.jaxb.model.record.summary_v2.ActivitiesSummary) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Aggregations

Funding (org.orcid.jaxb.model.record_v2.Funding)82 Test (org.junit.Test)73 ClientResponse (com.sun.jersey.api.client.ClientResponse)28 ArrayList (java.util.ArrayList)16 ExternalID (org.orcid.jaxb.model.record_v2.ExternalID)16 Response (javax.ws.rs.core.Response)15 DBUnitTest (org.orcid.test.DBUnitTest)15 Url (org.orcid.jaxb.model.common_v2.Url)14 Title (org.orcid.jaxb.model.common_v2.Title)11 Work (org.orcid.jaxb.model.record_v2.Work)10 List (java.util.List)9 FundingTitle (org.orcid.jaxb.model.record_v2.FundingTitle)9 ResearcherUrl (org.orcid.jaxb.model.record_v2.ResearcherUrl)9 Funding (org.orcid.jaxb.model.record_rc1.Funding)8 IOException (java.io.IOException)7 InputStreamReader (java.io.InputStreamReader)6 Reader (java.io.Reader)6 BaseTest (org.orcid.core.BaseTest)6 Funding (org.orcid.jaxb.model.record_rc4.Funding)6 Education (org.orcid.jaxb.model.record_v2.Education)6