Search in sources :

Example 41 with Work

use of org.orcid.jaxb.model.record_rc3.Work in project ORCID-Source by ORCID.

the class WorkManagerTest method testFindWorkBulk.

@Test
public void testFindWorkBulk() {
    String putCodes = "11,12,13";
    WorkBulk workBulk = workManager.findWorkBulk("0000-0000-0000-0003", putCodes, System.currentTimeMillis());
    assertNotNull(workBulk);
    assertNotNull(workBulk.getBulk());
    assertEquals(3, workBulk.getBulk().size());
    assertTrue(workBulk.getBulk().get(0) instanceof Work);
    assertTrue(workBulk.getBulk().get(1) instanceof Work);
    assertTrue(workBulk.getBulk().get(2) instanceof Work);
}
Also used : WorkBulk(org.orcid.jaxb.model.record_v2.WorkBulk) Work(org.orcid.jaxb.model.record_v2.Work) Test(org.junit.Test) BaseTest(org.orcid.core.BaseTest)

Example 42 with Work

use of org.orcid.jaxb.model.record_rc3.Work in project ORCID-Source by ORCID.

the class ActivityValidatorTest method validateWork_emptyCountryTest.

@Test(expected = ActivityTypeValidationException.class)
public void validateWork_emptyCountryTest() {
    Work work = getWork();
    work.getCountry().setValue((Iso3166Country) null);
    activityValidator.validateWork(work, null, true, true, Visibility.PUBLIC);
}
Also used : Work(org.orcid.jaxb.model.record_v2.Work) Test(org.junit.Test)

Example 43 with Work

use of org.orcid.jaxb.model.record_rc3.Work in project ORCID-Source by ORCID.

the class ActivityValidatorTest method validateWork_emptyContributorCreditNameTest.

@Test(expected = OrcidValidationException.class)
public void validateWork_emptyContributorCreditNameTest() {
    Work work = getWork();
    work.getWorkContributors().getContributor().get(0).getCreditName().setContent("");
    activityValidator.validateWork(work, null, true, true, Visibility.PUBLIC);
}
Also used : Work(org.orcid.jaxb.model.record_v2.Work) Test(org.junit.Test)

Example 44 with Work

use of org.orcid.jaxb.model.record_rc3.Work in project ORCID-Source by ORCID.

the class ActivityValidatorTest method validateWork_invalidCitationTypeTest.

@Test(expected = ActivityTypeValidationException.class)
public void validateWork_invalidCitationTypeTest() {
    Work work = getWork();
    work.getWorkCitation().setWorkCitationType(null);
    activityValidator.validateWork(work, null, true, true, Visibility.PUBLIC);
}
Also used : Work(org.orcid.jaxb.model.record_v2.Work) Test(org.junit.Test)

Example 45 with Work

use of org.orcid.jaxb.model.record_rc3.Work in project ORCID-Source by ORCID.

the class WorksTest method createViewUpdateAndDeleteWork.

@Test
public void createViewUpdateAndDeleteWork() throws JSONException, InterruptedException, URISyntaxException {
    changeDefaultUserVisibility(webDriver, org.orcid.jaxb.model.common_v2.Visibility.PUBLIC);
    long time = System.currentTimeMillis();
    Work workToCreate = (Work) unmarshallFromPath("/record_2.0_rc2/samples/work-2.0_rc2.xml", Work.class);
    workToCreate.setPutCode(null);
    workToCreate.getExternalIdentifiers().getExternalIdentifier().clear();
    ExternalID wExtId = new ExternalID();
    wExtId.setValue("Work Id " + time);
    wExtId.setType("agr");
    wExtId.setRelationship(Relationship.SELF);
    wExtId.setUrl(new Url("http://test.orcid.org/" + time));
    workToCreate.getExternalIdentifiers().getExternalIdentifier().add(wExtId);
    String accessToken = getAccessToken();
    ClientResponse postResponse = memberV2ApiClient.createWorkXml(this.getUser1OrcidId(), workToCreate, 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(".*/v2.0_rc2/" + this.getUser1OrcidId() + "/work/\\d+"));
    ClientResponse getResponse = memberV2ApiClient.viewLocationXml(postResponse.getLocation(), accessToken);
    assertEquals(Response.Status.OK.getStatusCode(), getResponse.getStatus());
    Work gotWork = getResponse.getEntity(Work.class);
    assertEquals("common:title", gotWork.getWorkTitle().getTitle().getContent());
    assertEquals("work:citation", gotWork.getWorkCitation().getCitation());
    assertEquals(CitationType.FORMATTED_UNSPECIFIED, gotWork.getWorkCitation().getWorkCitationType());
    gotWork.getWorkTitle().getTitle().setContent("updated title");
    //Save the original visibility
    Visibility originalVisibility = gotWork.getVisibility();
    Visibility updatedVisibility = Visibility.PRIVATE.equals(originalVisibility) ? Visibility.LIMITED : Visibility.PRIVATE;
    //Verify you cant update the visibility
    gotWork.setVisibility(updatedVisibility);
    ClientResponse putResponse = memberV2ApiClient.updateLocationXml(postResponse.getLocation(), accessToken, gotWork);
    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
    gotWork.setVisibility(originalVisibility);
    putResponse = memberV2ApiClient.updateLocationXml(postResponse.getLocation(), accessToken, gotWork);
    assertEquals(Response.Status.OK.getStatusCode(), putResponse.getStatus());
    ClientResponse getAfterUpdateResponse = memberV2ApiClient.viewLocationXml(postResponse.getLocation(), accessToken);
    assertEquals(Response.Status.OK.getStatusCode(), getAfterUpdateResponse.getStatus());
    Work gotAfterUpdateWork = getAfterUpdateResponse.getEntity(Work.class);
    assertEquals("updated title", gotAfterUpdateWork.getWorkTitle().getTitle().getContent());
    assertEquals("work:citation", gotAfterUpdateWork.getWorkCitation().getCitation());
    assertEquals(CitationType.FORMATTED_UNSPECIFIED, gotAfterUpdateWork.getWorkCitation().getWorkCitationType());
    ClientResponse deleteResponse = memberV2ApiClient.deleteWorkXml(this.getUser1OrcidId(), gotWork.getPutCode(), accessToken);
    assertEquals(Response.Status.NO_CONTENT.getStatusCode(), deleteResponse.getStatus());
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) OrcidError(org.orcid.jaxb.model.error_rc2.OrcidError) ExternalID(org.orcid.jaxb.model.record_rc2.ExternalID) Work(org.orcid.jaxb.model.record_rc2.Work) Visibility(org.orcid.jaxb.model.common_rc2.Visibility) Url(org.orcid.jaxb.model.common_rc2.Url) Test(org.junit.Test)

Aggregations

Work (org.orcid.jaxb.model.record_v2.Work)150 Test (org.junit.Test)148 ClientResponse (com.sun.jersey.api.client.ClientResponse)52 ExternalID (org.orcid.jaxb.model.record_v2.ExternalID)33 DBUnitTest (org.orcid.test.DBUnitTest)24 Response (javax.ws.rs.core.Response)23 Title (org.orcid.jaxb.model.common_v2.Title)22 WorkBulk (org.orcid.jaxb.model.record_v2.WorkBulk)22 Url (org.orcid.jaxb.model.common_v2.Url)21 WorkTitle (org.orcid.jaxb.model.record_v2.WorkTitle)21 OrcidError (org.orcid.jaxb.model.error_v2.OrcidError)19 ArrayList (java.util.ArrayList)16 ExternalIDs (org.orcid.jaxb.model.record_v2.ExternalIDs)16 BaseTest (org.orcid.core.BaseTest)14 SourceEntity (org.orcid.persistence.jpa.entities.SourceEntity)13 Work (org.orcid.jaxb.model.record_rc1.Work)12 ExternalID (org.orcid.jaxb.model.record_rc3.ExternalID)11 Work (org.orcid.jaxb.model.record_rc3.Work)11 Work (org.orcid.jaxb.model.record_rc4.Work)11 Funding (org.orcid.jaxb.model.record_v2.Funding)11