Search in sources :

Example 66 with Title

use of org.orcid.jaxb.model.v3.dev1.common.Title in project ORCID-Source by ORCID.

the class JpaJaxbEmploymentAdapterTest method testToOrgAffiliationRelationEntity.

@Test
public void testToOrgAffiliationRelationEntity() throws JAXBException {
    Employment e = getEmployment(true);
    assertNotNull(e);
    OrgAffiliationRelationEntity oar = jpaJaxbEmploymentAdapter.toOrgAffiliationRelationEntity(e);
    assertNotNull(oar);
    // General info
    assertEquals(Long.valueOf(0), oar.getId());
    assertEquals(org.orcid.jaxb.model.common_v2.Visibility.PRIVATE.value(), oar.getVisibility().value());
    assertEquals("employment:department-name", oar.getDepartment());
    assertEquals("employment:role-title", oar.getTitle());
    // Dates
    assertEquals(Integer.valueOf(2), oar.getStartDate().getDay());
    assertEquals(Integer.valueOf(2), oar.getStartDate().getMonth());
    assertEquals(Integer.valueOf(1848), oar.getStartDate().getYear());
    assertEquals(Integer.valueOf(2), oar.getEndDate().getDay());
    assertEquals(Integer.valueOf(2), oar.getEndDate().getMonth());
    assertEquals(Integer.valueOf(1848), oar.getEndDate().getYear());
    // Source
    assertNull(oar.getSourceId());
    assertNull(oar.getClientSourceId());
    assertNull(oar.getElementSourceId());
}
Also used : Employment(org.orcid.jaxb.model.v3.dev1.record.Employment) OrgAffiliationRelationEntity(org.orcid.persistence.jpa.entities.OrgAffiliationRelationEntity) Test(org.junit.Test)

Example 67 with Title

use of org.orcid.jaxb.model.v3.dev1.common.Title in project ORCID-Source by ORCID.

the class MemberV3ApiServiceDelegator_QualificationsTest method testUpdateQualificationYouAreNotTheSourceOf.

@Test(expected = WrongSourceException.class)
public void testUpdateQualificationYouAreNotTheSourceOf() {
    SecurityContextTestUtils.setUpSecurityContext(ORCID, ScopePathType.READ_LIMITED, ScopePathType.ACTIVITIES_UPDATE);
    Response response = serviceDelegator.viewQualification(ORCID, 45L);
    assertNotNull(response);
    Qualification qualification = (Qualification) response.getEntity();
    assertNotNull(qualification);
    qualification.setDepartmentName("Updated department name");
    qualification.setRoleTitle("The updated role title");
    serviceDelegator.updateQualification(ORCID, 45L, qualification);
    fail();
}
Also used : Response(javax.ws.rs.core.Response) Qualification(org.orcid.jaxb.model.v3.dev1.record.Qualification) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 68 with Title

use of org.orcid.jaxb.model.v3.dev1.common.Title in project ORCID-Source by ORCID.

the class MemberV3ApiServiceDelegator_WorksTest method testCreateBulkWorksWithBlankTitles.

@Test
public void testCreateBulkWorksWithBlankTitles() {
    RequestAttributes previousAttrs = RequestContextHolder.getRequestAttributes();
    RequestAttributes attrs = new ServletRequestAttributes(new MockHttpServletRequest());
    attrs.setAttribute(ApiVersionFilter.API_VERSION_REQUEST_ATTRIBUTE_NAME, "3.0_dev1", RequestAttributes.SCOPE_REQUEST);
    RequestContextHolder.setRequestAttributes(attrs);
    Long time = System.currentTimeMillis();
    SecurityContextTestUtils.setUpSecurityContext(ORCID, ScopePathType.READ_LIMITED, ScopePathType.ACTIVITIES_UPDATE);
    WorkBulk bulk = new WorkBulk();
    for (int i = 0; i < 5; i++) {
        Work work = new Work();
        WorkTitle title = new WorkTitle();
        title.setTitle(i == 0 ? new Title(" ") : new Title("title " + i));
        work.setWorkTitle(title);
        ExternalIDs extIds = new ExternalIDs();
        ExternalID extId = new ExternalID();
        extId.setRelationship(Relationship.SELF);
        extId.setType("doi");
        extId.setUrl(new Url("http://doi/" + i + "/" + time));
        extId.setValue("doi-" + i + "-" + time);
        extIds.getExternalIdentifier().add(extId);
        work.setWorkExternalIdentifiers(extIds);
        work.setWorkType(WorkType.BOOK);
        bulk.getBulk().add(work);
    }
    Response response = serviceDelegator.createWorks(ORCID, bulk);
    assertNotNull(response);
    assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
    bulk = (WorkBulk) response.getEntity();
    assertNotNull(bulk);
    assertEquals(5, bulk.getBulk().size());
    for (int i = 0; i < 5; i++) {
        if (i == 0) {
            assertTrue(bulk.getBulk().get(i) instanceof OrcidError);
        } else {
            assertTrue(bulk.getBulk().get(i) instanceof Work);
            serviceDelegator.deleteWork(ORCID, ((Work) bulk.getBulk().get(i)).getPutCode());
        }
    }
    RequestContextHolder.setRequestAttributes(previousAttrs);
}
Also used : OrcidError(org.orcid.jaxb.model.v3.dev1.error.OrcidError) ExternalIDs(org.orcid.jaxb.model.v3.dev1.record.ExternalIDs) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) WorkBulk(org.orcid.jaxb.model.v3.dev1.record.WorkBulk) ServletRequestAttributes(org.springframework.web.context.request.ServletRequestAttributes) ExternalID(org.orcid.jaxb.model.v3.dev1.record.ExternalID) Title(org.orcid.jaxb.model.v3.dev1.common.Title) TranslatedTitle(org.orcid.jaxb.model.v3.dev1.common.TranslatedTitle) WorkTitle(org.orcid.jaxb.model.v3.dev1.record.WorkTitle) RequestAttributes(org.springframework.web.context.request.RequestAttributes) ServletRequestAttributes(org.springframework.web.context.request.ServletRequestAttributes) ResearcherUrl(org.orcid.jaxb.model.v3.dev1.record.ResearcherUrl) Url(org.orcid.jaxb.model.v3.dev1.common.Url) Response(javax.ws.rs.core.Response) WorkTitle(org.orcid.jaxb.model.v3.dev1.record.WorkTitle) Work(org.orcid.jaxb.model.v3.dev1.record.Work) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 69 with Title

use of org.orcid.jaxb.model.v3.dev1.common.Title in project ORCID-Source by ORCID.

the class MemberV3ApiServiceDelegator_WorksTest method testCreateWorksWithBulkAllOK.

@Test
public void testCreateWorksWithBulkAllOK() {
    RequestAttributes previousAttrs = RequestContextHolder.getRequestAttributes();
    RequestAttributes attrs = new ServletRequestAttributes(new MockHttpServletRequest());
    attrs.setAttribute(ApiVersionFilter.API_VERSION_REQUEST_ATTRIBUTE_NAME, "3.0_dev1", RequestAttributes.SCOPE_REQUEST);
    RequestContextHolder.setRequestAttributes(attrs);
    Long time = System.currentTimeMillis();
    SecurityContextTestUtils.setUpSecurityContext(ORCID, ScopePathType.READ_LIMITED, ScopePathType.ACTIVITIES_UPDATE);
    WorkBulk bulk = new WorkBulk();
    for (int i = 0; i < 5; i++) {
        Work work = new Work();
        WorkTitle title = new WorkTitle();
        title.setTitle(new Title("Bulk work " + i + " " + time));
        work.setWorkTitle(title);
        ExternalIDs extIds = new ExternalIDs();
        ExternalID extId = new ExternalID();
        extId.setRelationship(Relationship.SELF);
        extId.setType("doi");
        extId.setUrl(new Url("http://doi/" + i + "/" + time));
        extId.setValue("doi-" + i + "-" + time);
        extIds.getExternalIdentifier().add(extId);
        work.setWorkExternalIdentifiers(extIds);
        work.setWorkType(WorkType.BOOK);
        bulk.getBulk().add(work);
    }
    Response response = serviceDelegator.createWorks(ORCID, bulk);
    assertNotNull(response);
    assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
    bulk = (WorkBulk) response.getEntity();
    assertNotNull(bulk);
    assertEquals(5, bulk.getBulk().size());
    for (int i = 0; i < 5; i++) {
        assertTrue(Work.class.isAssignableFrom(bulk.getBulk().get(i).getClass()));
        Work w = (Work) bulk.getBulk().get(i);
        Utils.verifyLastModified(w.getLastModifiedDate());
        assertNotNull(w.getPutCode());
        assertTrue(0L < w.getPutCode());
        assertEquals("Bulk work " + i + " " + time, w.getWorkTitle().getTitle().getContent());
        assertNotNull(w.getExternalIdentifiers().getExternalIdentifier());
        assertEquals("doi-" + i + "-" + time, w.getExternalIdentifiers().getExternalIdentifier().get(0).getValue());
        Response r = serviceDelegator.viewWork(ORCID, w.getPutCode());
        assertNotNull(r);
        assertEquals(Response.Status.OK.getStatusCode(), r.getStatus());
        assertEquals("Bulk work " + i + " " + time, ((Work) r.getEntity()).getWorkTitle().getTitle().getContent());
        // Delete the work
        r = serviceDelegator.deleteWork(ORCID, w.getPutCode());
        assertNotNull(r);
        assertEquals(Response.Status.NO_CONTENT.getStatusCode(), r.getStatus());
    }
    RequestContextHolder.setRequestAttributes(previousAttrs);
}
Also used : ExternalIDs(org.orcid.jaxb.model.v3.dev1.record.ExternalIDs) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) WorkBulk(org.orcid.jaxb.model.v3.dev1.record.WorkBulk) ServletRequestAttributes(org.springframework.web.context.request.ServletRequestAttributes) ExternalID(org.orcid.jaxb.model.v3.dev1.record.ExternalID) Title(org.orcid.jaxb.model.v3.dev1.common.Title) TranslatedTitle(org.orcid.jaxb.model.v3.dev1.common.TranslatedTitle) WorkTitle(org.orcid.jaxb.model.v3.dev1.record.WorkTitle) RequestAttributes(org.springframework.web.context.request.RequestAttributes) ServletRequestAttributes(org.springframework.web.context.request.ServletRequestAttributes) ResearcherUrl(org.orcid.jaxb.model.v3.dev1.record.ResearcherUrl) Url(org.orcid.jaxb.model.v3.dev1.common.Url) Response(javax.ws.rs.core.Response) WorkTitle(org.orcid.jaxb.model.v3.dev1.record.WorkTitle) Work(org.orcid.jaxb.model.v3.dev1.record.Work) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 70 with Title

use of org.orcid.jaxb.model.v3.dev1.common.Title in project ORCID-Source by ORCID.

the class MemberV3ApiServiceDelegator_WorksTest method testUpdateWork.

@Test
public void testUpdateWork() {
    SecurityContextTestUtils.setUpSecurityContext("4444-4444-4444-4443", ScopePathType.READ_LIMITED, ScopePathType.ACTIVITIES_UPDATE);
    Response response = serviceDelegator.viewWork("4444-4444-4444-4443", 1L);
    assertNotNull(response);
    Work work = (Work) response.getEntity();
    assertNotNull(work);
    Utils.verifyLastModified(work.getLastModifiedDate());
    assertEquals(Long.valueOf(1), work.getPutCode());
    assertNotNull(work.getWorkTitle());
    assertNotNull(work.getWorkTitle().getTitle());
    assertEquals("A day in the life", work.getWorkTitle().getTitle().getContent());
    assertEquals(WorkType.BOOK, work.getWorkType());
    assertEquals(Visibility.PUBLIC, work.getVisibility());
    work.setWorkType(WorkType.EDITED_BOOK);
    work.getWorkTitle().getTitle().setContent("Updated work title");
    response = serviceDelegator.updateWork("4444-4444-4444-4443", 1L, work);
    assertNotNull(response);
    assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
    response = serviceDelegator.viewWork("4444-4444-4444-4443", 1L);
    assertNotNull(response);
    work = (Work) response.getEntity();
    assertNotNull(work);
    Utils.verifyLastModified(work.getLastModifiedDate());
    assertEquals(Long.valueOf(1), work.getPutCode());
    assertNotNull(work.getWorkTitle());
    assertNotNull(work.getWorkTitle().getTitle());
    assertEquals("Updated work title", work.getWorkTitle().getTitle().getContent());
    assertEquals(WorkType.EDITED_BOOK, work.getWorkType());
    // Rollback changes so we dont break other tests
    work.setWorkType(WorkType.BOOK);
    work.getWorkTitle().getTitle().setContent("A day in the life");
    response = serviceDelegator.updateWork("4444-4444-4444-4443", 1L, work);
    assertNotNull(response);
    assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
}
Also used : Response(javax.ws.rs.core.Response) Work(org.orcid.jaxb.model.v3.dev1.record.Work) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)81 Title (org.orcid.jaxb.model.v3.dev1.common.Title)44 Work (org.orcid.jaxb.model.v3.dev1.record.Work)43 WorkTitle (org.orcid.jaxb.model.v3.dev1.record.WorkTitle)40 ExternalID (org.orcid.jaxb.model.v3.dev1.record.ExternalID)38 Url (org.orcid.jaxb.model.v3.dev1.common.Url)33 DBUnitTest (org.orcid.test.DBUnitTest)29 ExternalIDs (org.orcid.jaxb.model.v3.dev1.record.ExternalIDs)27 ClientResponse (com.sun.jersey.api.client.ClientResponse)26 Response (javax.ws.rs.core.Response)25 Funding (org.orcid.jaxb.model.v3.dev1.record.Funding)23 FundingTitle (org.orcid.jaxb.model.v3.dev1.record.FundingTitle)19 OrcidError (org.orcid.jaxb.model.v3.dev1.error.OrcidError)17 PeerReview (org.orcid.jaxb.model.v3.dev1.record.PeerReview)17 TranslatedTitle (org.orcid.jaxb.model.v3.dev1.common.TranslatedTitle)14 ResearcherUrl (org.orcid.jaxb.model.v3.dev1.record.ResearcherUrl)14 ArrayList (java.util.ArrayList)13 DisambiguatedOrganization (org.orcid.jaxb.model.v3.dev1.common.DisambiguatedOrganization)13 LastModifiedDate (org.orcid.jaxb.model.v3.dev1.common.LastModifiedDate)13 Visibility (org.orcid.jaxb.model.v3.dev1.common.Visibility)13