Search in sources :

Example 41 with OtherNames

use of org.orcid.jaxb.model.v3.dev1.record.OtherNames in project ORCID-Source by ORCID.

the class MemberV3ApiServiceDelegator_OtherNamesTest method testDeleteOtherName.

@Test
public void testDeleteOtherName() {
    SecurityContextTestUtils.setUpSecurityContext("4444-4444-4444-4447", ScopePathType.PERSON_READ_LIMITED, ScopePathType.PERSON_UPDATE);
    Response response = serviceDelegator.viewOtherNames("4444-4444-4444-4447");
    assertNotNull(response);
    OtherNames otherNames = (OtherNames) response.getEntity();
    assertNotNull(otherNames);
    assertNotNull(otherNames.getOtherNames());
    assertEquals(1, otherNames.getOtherNames().size());
    response = serviceDelegator.deleteOtherName("4444-4444-4444-4447", 9L);
    assertNotNull(response);
    assertEquals(Response.Status.NO_CONTENT.getStatusCode(), response.getStatus());
    response = serviceDelegator.viewOtherNames("4444-4444-4444-4447");
    assertNotNull(response);
    otherNames = (OtherNames) response.getEntity();
    assertNotNull(otherNames);
    assertNotNull(otherNames.getOtherNames());
    assertTrue(otherNames.getOtherNames().isEmpty());
}
Also used : Response(javax.ws.rs.core.Response) OtherNames(org.orcid.jaxb.model.v3.dev1.record.OtherNames) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 42 with OtherNames

use of org.orcid.jaxb.model.v3.dev1.record.OtherNames in project ORCID-Source by ORCID.

the class MemberV3ApiServiceDelegator_OtherNamesTest method testReadPublicScope_OtherNames.

@Test
public void testReadPublicScope_OtherNames() {
    SecurityContextTestUtils.setUpSecurityContext(ORCID, ScopePathType.READ_PUBLIC);
    // Public works
    Response r = serviceDelegator.viewOtherNames(ORCID);
    assertNotNull(r);
    assertEquals(OtherNames.class.getName(), r.getEntity().getClass().getName());
    OtherNames o = (OtherNames) r.getEntity();
    assertNotNull(o);
    Utils.verifyLastModified(o.getLastModifiedDate());
    assertEquals(3, o.getOtherNames().size());
    boolean found1 = false, found2 = false, found3 = false;
    for (OtherName element : o.getOtherNames()) {
        Utils.verifyLastModified(element.getLastModifiedDate());
        if (element.getPutCode() == 13) {
            found1 = true;
        } else if (element.getPutCode() == 14) {
            found2 = true;
        } else if (element.getPutCode() == 15) {
            found3 = true;
        } else {
            fail("Invalid put code " + element.getPutCode());
        }
    }
    assertTrue(found1);
    assertTrue(found2);
    assertTrue(found3);
    r = serviceDelegator.viewOtherName(ORCID, 13L);
    assertNotNull(r);
    assertEquals(OtherName.class.getName(), r.getEntity().getClass().getName());
    // Limited where am the source should work
    serviceDelegator.viewOtherName(ORCID, 14L);
    // Limited where am not the source of should fail
    try {
        serviceDelegator.viewOtherName(ORCID, 16L);
        fail();
    } catch (OrcidAccessControlException e) {
    } catch (Exception e) {
        fail();
    }
    // Private where am the source should work
    serviceDelegator.viewOtherName(ORCID, 15L);
    // Private where am not the source should work
    try {
        serviceDelegator.viewOtherName(ORCID, 17L);
        fail();
    } catch (OrcidAccessControlException e) {
    } catch (Exception e) {
        fail();
    }
}
Also used : Response(javax.ws.rs.core.Response) OtherNames(org.orcid.jaxb.model.v3.dev1.record.OtherNames) OtherName(org.orcid.jaxb.model.v3.dev1.record.OtherName) OrcidAccessControlException(org.orcid.core.exception.OrcidAccessControlException) NoResultException(javax.persistence.NoResultException) VisibilityMismatchException(org.orcid.core.exception.VisibilityMismatchException) WrongSourceException(org.orcid.core.exception.WrongSourceException) OrcidAccessControlException(org.orcid.core.exception.OrcidAccessControlException) OrcidVisibilityException(org.orcid.core.exception.OrcidVisibilityException) OrcidUnauthorizedException(org.orcid.core.exception.OrcidUnauthorizedException) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 43 with OtherNames

use of org.orcid.jaxb.model.v3.dev1.record.OtherNames in project ORCID-Source by ORCID.

the class MemberV3ApiServiceDelegator_OtherNamesTest method testViewOtherNamesReadPublic.

@Test
public void testViewOtherNamesReadPublic() {
    SecurityContextTestUtils.setUpSecurityContextForClientOnly("APP-5555555555555555", ScopePathType.READ_PUBLIC);
    Response r = serviceDelegator.viewOtherNames(ORCID);
    OtherNames element = (OtherNames) r.getEntity();
    assertNotNull(element);
    assertEquals("/0000-0000-0000-0003/other-names", element.getPath());
    Utils.assertIsPublicOrSource(element, "APP-5555555555555555");
}
Also used : Response(javax.ws.rs.core.Response) OtherNames(org.orcid.jaxb.model.v3.dev1.record.OtherNames) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 44 with OtherNames

use of org.orcid.jaxb.model.v3.dev1.record.OtherNames in project ORCID-Source by ORCID.

the class MemberV3ApiServiceDelegator_OtherNamesTest method testViewOtherNames.

@Test
public void testViewOtherNames() {
    SecurityContextTestUtils.setUpSecurityContext("4444-4444-4444-4446", ScopePathType.PERSON_READ_LIMITED);
    Response response = serviceDelegator.viewOtherNames("4444-4444-4444-4446");
    assertNotNull(response);
    OtherNames otherNames = (OtherNames) response.getEntity();
    assertNotNull(otherNames);
    assertEquals("/4444-4444-4444-4446/other-names", otherNames.getPath());
    Utils.verifyLastModified(otherNames.getLastModifiedDate());
    assertNotNull(otherNames.getOtherNames());
    assertEquals(3, otherNames.getOtherNames().size());
    for (OtherName otherName : otherNames.getOtherNames()) {
        Utils.verifyLastModified(otherName.getLastModifiedDate());
        assertThat(otherName.getPutCode(), anyOf(is(5L), is(6L), is(8L)));
        assertThat(otherName.getContent(), anyOf(is("Other Name # 1"), is("Other Name # 2"), is("Other Name # 4")));
        if (otherName.getPutCode() == 5L) {
            assertEquals(Visibility.PUBLIC, otherName.getVisibility());
            assertEquals("APP-5555555555555555", otherName.getSource().retrieveSourcePath());
        } else if (otherName.getPutCode() == 6L) {
            assertEquals(Visibility.LIMITED, otherName.getVisibility());
            assertEquals("4444-4444-4444-4446", otherName.getSource().retrieveSourcePath());
        } else {
            assertEquals(Visibility.PRIVATE, otherName.getVisibility());
            assertEquals("APP-5555555555555555", otherName.getSource().retrieveSourcePath());
        }
    }
}
Also used : Response(javax.ws.rs.core.Response) OtherNames(org.orcid.jaxb.model.v3.dev1.record.OtherNames) OtherName(org.orcid.jaxb.model.v3.dev1.record.OtherName) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 45 with OtherNames

use of org.orcid.jaxb.model.v3.dev1.record.OtherNames in project ORCID-Source by ORCID.

the class PublicAPISecurityManagerV3Test method filterOtherNamesTest.

@Test
public void filterOtherNamesTest() {
    OtherNames x = getOtherNamesElement(Visibility.PUBLIC, Visibility.PUBLIC, Visibility.PUBLIC);
    assertEquals(3, x.getOtherNames().size());
    publicAPISecurityManagerV3.filter(x);
    assertEquals(3, x.getOtherNames().size());
    assertAllArePublic(x.getOtherNames());
    x = getOtherNamesElement(Visibility.PUBLIC, Visibility.PUBLIC, Visibility.LIMITED);
    assertEquals(3, x.getOtherNames().size());
    publicAPISecurityManagerV3.filter(x);
    assertEquals(2, x.getOtherNames().size());
    assertAllArePublic(x.getOtherNames());
    x = getOtherNamesElement(Visibility.PUBLIC, Visibility.LIMITED, Visibility.PRIVATE);
    assertEquals(3, x.getOtherNames().size());
    publicAPISecurityManagerV3.filter(x);
    assertEquals(1, x.getOtherNames().size());
    assertAllArePublic(x.getOtherNames());
    x = getOtherNamesElement(Visibility.PRIVATE, Visibility.LIMITED, Visibility.PRIVATE);
    assertEquals(3, x.getOtherNames().size());
    publicAPISecurityManagerV3.filter(x);
    assertTrue(x.getOtherNames().isEmpty());
}
Also used : OtherNames(org.orcid.jaxb.model.v3.dev1.record.OtherNames) Test(org.junit.Test)

Aggregations

OtherNames (org.orcid.jaxb.model.v3.dev1.record.OtherNames)65 OtherName (org.orcid.jaxb.model.v3.dev1.record.OtherName)55 Test (org.junit.Test)46 Biography (org.orcid.jaxb.model.v3.dev1.record.Biography)44 Name (org.orcid.jaxb.model.v3.dev1.record.Name)38 Addresses (org.orcid.jaxb.model.v3.dev1.record.Addresses)33 Keywords (org.orcid.jaxb.model.v3.dev1.record.Keywords)33 PersonExternalIdentifiers (org.orcid.jaxb.model.v3.dev1.record.PersonExternalIdentifiers)33 ResearcherUrls (org.orcid.jaxb.model.v3.dev1.record.ResearcherUrls)33 Address (org.orcid.jaxb.model.v3.dev1.record.Address)31 Emails (org.orcid.jaxb.model.v3.dev1.record.Emails)31 Email (org.orcid.jaxb.model.v3.dev1.record.Email)30 Keyword (org.orcid.jaxb.model.v3.dev1.record.Keyword)30 PersonExternalIdentifier (org.orcid.jaxb.model.v3.dev1.record.PersonExternalIdentifier)30 ResearcherUrl (org.orcid.jaxb.model.v3.dev1.record.ResearcherUrl)30 Person (org.orcid.jaxb.model.v3.dev1.record.Person)25 PersonalDetails (org.orcid.jaxb.model.v3.dev1.record.PersonalDetails)13 Record (org.orcid.jaxb.model.v3.dev1.record.Record)13 DistinctionSummary (org.orcid.jaxb.model.v3.dev1.record.summary.DistinctionSummary)13 EducationSummary (org.orcid.jaxb.model.v3.dev1.record.summary.EducationSummary)13