Search in sources :

Example 41 with WorkBulk

use of org.orcid.jaxb.model.record_v2.WorkBulk in project ORCID-Source by ORCID.

the class OrcidSecurityManager_WorkBulkTest method testPrivateWorkBulkReadLimitedToken.

@Test
public void testPrivateWorkBulkReadLimitedToken() {
    WorkBulk workBulk = new WorkBulk();
    workBulk.setBulk(Arrays.asList(createWork(Visibility.PRIVATE, CLIENT_2)));
    SecurityContextTestUtils.setUpSecurityContext(ORCID_1, CLIENT_1, ScopePathType.READ_LIMITED);
    orcidSecurityManager.checkAndFilter(ORCID_1, workBulk, ScopePathType.ORCID_WORKS_READ_LIMITED);
    assertNotNull(workBulk);
    assertEquals(1, workBulk.getBulk().size());
    assertTrue(workBulk.getBulk().get(0) instanceof OrcidError);
}
Also used : OrcidError(org.orcid.jaxb.model.error_v2.OrcidError) WorkBulk(org.orcid.jaxb.model.record_v2.WorkBulk) Test(org.junit.Test)

Example 42 with WorkBulk

use of org.orcid.jaxb.model.record_v2.WorkBulk in project ORCID-Source by ORCID.

the class OrcidSecurityManager_WorkBulkTest method testPrivateWorkBulkReadLimitedTokenMixedSources.

@Test
public void testPrivateWorkBulkReadLimitedTokenMixedSources() {
    WorkBulk workBulk = new WorkBulk();
    workBulk.setBulk(Arrays.asList(createWork(Visibility.PRIVATE, CLIENT_1), createWork(Visibility.PRIVATE, CLIENT_2)));
    SecurityContextTestUtils.setUpSecurityContext(ORCID_1, CLIENT_2, ScopePathType.READ_LIMITED);
    orcidSecurityManager.checkAndFilter(ORCID_1, workBulk, ScopePathType.ORCID_WORKS_READ_LIMITED);
    assertNotNull(workBulk);
    assertEquals(2, workBulk.getBulk().size());
    assertTrue(workBulk.getBulk().get(0) instanceof OrcidError);
    assertTrue(workBulk.getBulk().get(1) instanceof Work);
}
Also used : OrcidError(org.orcid.jaxb.model.error_v2.OrcidError) WorkBulk(org.orcid.jaxb.model.record_v2.WorkBulk) Work(org.orcid.jaxb.model.record_v2.Work) Test(org.junit.Test)

Example 43 with WorkBulk

use of org.orcid.jaxb.model.record_v2.WorkBulk in project ORCID-Source by ORCID.

the class OrcidSecurityManager_WorkBulkTest method testPrivateWorkBulkReadLimitedTokenNoSource.

@Test
public void testPrivateWorkBulkReadLimitedTokenNoSource() {
    WorkBulk workBulk = new WorkBulk();
    workBulk.setBulk(Arrays.asList(createWork(Visibility.PRIVATE, null)));
    SecurityContextTestUtils.setUpSecurityContext(ORCID_1, CLIENT_2, ScopePathType.READ_LIMITED);
    orcidSecurityManager.checkAndFilter(ORCID_1, workBulk, ScopePathType.ORCID_WORKS_READ_LIMITED);
    assertNotNull(workBulk);
    assertEquals(1, workBulk.getBulk().size());
    assertTrue(workBulk.getBulk().get(0) instanceof OrcidError);
}
Also used : OrcidError(org.orcid.jaxb.model.error_v2.OrcidError) WorkBulk(org.orcid.jaxb.model.record_v2.WorkBulk) Test(org.junit.Test)

Example 44 with WorkBulk

use of org.orcid.jaxb.model.record_v2.WorkBulk in project ORCID-Source by ORCID.

the class OrcidSecurityManager_WorkBulkTest method testLimitedWorkBulkReadPublicTokenMixedSources.

@Test
public void testLimitedWorkBulkReadPublicTokenMixedSources() {
    WorkBulk workBulk = new WorkBulk();
    workBulk.setBulk(Arrays.asList(createWork(Visibility.PUBLIC, CLIENT_1), createWork(Visibility.LIMITED, CLIENT_2)));
    SecurityContextTestUtils.setUpSecurityContext(ORCID_1, CLIENT_1, ScopePathType.READ_PUBLIC);
    orcidSecurityManager.checkAndFilter(ORCID_1, workBulk, ScopePathType.ORCID_WORKS_READ_LIMITED);
    assertNotNull(workBulk);
    assertEquals(2, workBulk.getBulk().size());
    assertTrue(workBulk.getBulk().get(0) instanceof Work);
    assertTrue(workBulk.getBulk().get(1) instanceof OrcidError);
}
Also used : OrcidError(org.orcid.jaxb.model.error_v2.OrcidError) WorkBulk(org.orcid.jaxb.model.record_v2.WorkBulk) Work(org.orcid.jaxb.model.record_v2.Work) Test(org.junit.Test)

Example 45 with WorkBulk

use of org.orcid.jaxb.model.record_v2.WorkBulk 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 = memberV2_1ApiClient.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(9037), error.getErrorCode());
                    assertTrue(error.getDeveloperMessage().startsWith("Invalid work type"));
                    break;
                case 5:
                    assertEquals(Integer.valueOf(9022), error.getErrorCode());
                    break;
                case 7:
                    assertEquals(Integer.valueOf(9037), error.getErrorCode());
                    assertTrue(error.getDeveloperMessage().startsWith("Invalid translated title"));
                    break;
            }
        } else {
            assertTrue(Work.class.isAssignableFrom(element.getClass()));
            Work work = (Work) element;
            assertNotNull(work.getPutCode());
            memberV2_1ApiClient.deleteWorkXml(this.getUser1OrcidId(), work.getPutCode(), accessToken);
        }
    }
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) OrcidError(org.orcid.jaxb.model.error_v2.OrcidError) BulkElement(org.orcid.jaxb.model.record_v2.BulkElement) WorkBulk(org.orcid.jaxb.model.record_v2.WorkBulk) Work(org.orcid.jaxb.model.record_v2.Work) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)39 WorkBulk (org.orcid.jaxb.model.record_v2.WorkBulk)36 OrcidError (org.orcid.jaxb.model.error_v2.OrcidError)24 Work (org.orcid.jaxb.model.record_v2.Work)23 ClientResponse (com.sun.jersey.api.client.ClientResponse)16 BulkElement (org.orcid.jaxb.model.record_v2.BulkElement)13 Response (javax.ws.rs.core.Response)7 DBUnitTest (org.orcid.test.DBUnitTest)7 BaseTest (org.orcid.core.BaseTest)5 WorkBulk (org.orcid.jaxb.model.record_rc3.WorkBulk)5 WorkBulk (org.orcid.jaxb.model.record_rc4.WorkBulk)5 ExternalID (org.orcid.jaxb.model.record_v2.ExternalID)5 ArrayList (java.util.ArrayList)4 Url (org.orcid.jaxb.model.common_v2.Url)4 SourceEntity (org.orcid.persistence.jpa.entities.SourceEntity)4 Title (org.orcid.jaxb.model.common_v2.Title)3 OrcidError (org.orcid.jaxb.model.error_rc3.OrcidError)3 OrcidError (org.orcid.jaxb.model.error_rc4.OrcidError)3 BulkElement (org.orcid.jaxb.model.record_rc3.BulkElement)3 Work (org.orcid.jaxb.model.record_rc3.Work)3