Search in sources :

Example 51 with Address

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

the class MemberV2ApiServiceDelegator_AddressesTest method testViewAddresses.

@Test
public void testViewAddresses() {
    SecurityContextTestUtils.setUpSecurityContext("4444-4444-4444-4447", ScopePathType.PERSON_READ_LIMITED);
    Response response = serviceDelegator.viewAddresses("4444-4444-4444-4447");
    assertNotNull(response);
    Addresses addresses = (Addresses) response.getEntity();
    assertNotNull(addresses);
    assertEquals("/4444-4444-4444-4447/address", addresses.getPath());
    Utils.verifyLastModified(addresses.getLastModifiedDate());
    assertNotNull(addresses.getAddress());
    assertEquals(3, addresses.getAddress().size());
    for (Address address : addresses.getAddress()) {
        Utils.verifyLastModified(address.getLastModifiedDate());
        assertThat(address.getPutCode(), anyOf(is(2L), is(3L), is(4L)));
        assertThat(address.getCountry().getValue(), anyOf(is(Iso3166Country.CR), is(Iso3166Country.US)));
        if (address.getPutCode() == 2L) {
            assertEquals(Visibility.PUBLIC, address.getVisibility());
            assertEquals("4444-4444-4444-4447", address.getSource().retrieveSourcePath());
        } else if (address.getPutCode() == 3L) {
            assertEquals(Visibility.LIMITED, address.getVisibility());
            assertEquals("APP-5555555555555555", address.getSource().retrieveSourcePath());
        } else if (address.getPutCode() == 4L) {
            assertEquals(Visibility.PRIVATE, address.getVisibility());
            assertEquals("APP-5555555555555555", address.getSource().retrieveSourcePath());
        }
    }
}
Also used : Response(javax.ws.rs.core.Response) Addresses(org.orcid.jaxb.model.record_v2.Addresses) Address(org.orcid.jaxb.model.record_v2.Address) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 52 with Address

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

the class MemberV2ApiServiceDelegator_AddressesTest method testReadPublicScope_Address.

@Test
public void testReadPublicScope_Address() {
    SecurityContextTestUtils.setUpSecurityContext(ORCID, ScopePathType.READ_PUBLIC);
    // Public works
    Response r = serviceDelegator.viewAddresses(ORCID);
    assertNotNull(r);
    assertEquals(Addresses.class.getName(), r.getEntity().getClass().getName());
    Addresses a = (Addresses) r.getEntity();
    assertNotNull(a);
    assertEquals("/0000-0000-0000-0003/address", a.getPath());
    Utils.verifyLastModified(a.getLastModifiedDate());
    assertEquals(3, a.getAddress().size());
    boolean found9 = false, found10 = false, found11 = false;
    for (Address address : a.getAddress()) {
        if (address.getPutCode() == 9) {
            found9 = true;
        } else if (address.getPutCode() == 10) {
            found10 = true;
        } else if (address.getPutCode() == 11) {
            found11 = true;
        } else {
            fail("Invalid put code " + address.getPutCode());
        }
    }
    assertTrue(found9);
    assertTrue(found10);
    assertTrue(found11);
    r = serviceDelegator.viewAddress(ORCID, 9L);
    assertNotNull(r);
    assertEquals(Address.class.getName(), r.getEntity().getClass().getName());
    // Limited where am the source should work
    serviceDelegator.viewAddress(ORCID, 10L);
    try {
        // Limited am not the source should fail
        serviceDelegator.viewAddress(ORCID, 12L);
        fail();
    } catch (OrcidAccessControlException e) {
    } catch (Exception e) {
        fail();
    }
    // Private where am the source should work
    serviceDelegator.viewAddress(ORCID, 11L);
    try {
        // Private am not the source should fail
        serviceDelegator.viewAddress(ORCID, 13L);
        fail();
    } catch (OrcidAccessControlException e) {
    } catch (Exception e) {
        fail();
    }
}
Also used : Response(javax.ws.rs.core.Response) Addresses(org.orcid.jaxb.model.record_v2.Addresses) Address(org.orcid.jaxb.model.record_v2.Address) OrcidAccessControlException(org.orcid.core.exception.OrcidAccessControlException) NoResultException(javax.persistence.NoResultException) OrcidAccessControlException(org.orcid.core.exception.OrcidAccessControlException) VisibilityMismatchException(org.orcid.core.exception.VisibilityMismatchException) OrcidVisibilityException(org.orcid.core.exception.OrcidVisibilityException) OrcidUnauthorizedException(org.orcid.core.exception.OrcidUnauthorizedException) WrongSourceException(org.orcid.core.exception.WrongSourceException) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 53 with Address

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

the class MemberV2ApiServiceDelegator_AddressesTest method testViewLimitedAddress.

@Test
public void testViewLimitedAddress() {
    SecurityContextTestUtils.setUpSecurityContext("4444-4444-4444-4447", ScopePathType.PERSON_READ_LIMITED);
    Response response = serviceDelegator.viewAddress("4444-4444-4444-4447", 3L);
    assertNotNull(response);
    Address address = (Address) response.getEntity();
    assertNotNull(address);
    assertEquals("/4444-4444-4444-4447/address/3", address.getPath());
    Utils.verifyLastModified(address.getLastModifiedDate());
    assertEquals(Visibility.LIMITED, address.getVisibility());
    assertEquals("APP-5555555555555555", address.getSource().retrieveSourcePath());
    assertEquals(Iso3166Country.CR, address.getCountry().getValue());
}
Also used : Response(javax.ws.rs.core.Response) Address(org.orcid.jaxb.model.record_v2.Address) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 54 with Address

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

the class MemberV2ApiServiceDelegator_AddressesTest method testUpdateAddressChangingVisibilityTest.

@Test(expected = VisibilityMismatchException.class)
public void testUpdateAddressChangingVisibilityTest() {
    SecurityContextTestUtils.setUpSecurityContext("4444-4444-4444-4442", ScopePathType.PERSON_READ_LIMITED, ScopePathType.PERSON_UPDATE);
    Response response = serviceDelegator.viewAddress("4444-4444-4444-4442", 1L);
    assertNotNull(response);
    Address address = (Address) response.getEntity();
    assertNotNull(address);
    assertEquals(Visibility.PUBLIC, address.getVisibility());
    address.setVisibility(Visibility.PRIVATE);
    response = serviceDelegator.updateAddress("4444-4444-4444-4442", 1L, address);
    fail();
}
Also used : Response(javax.ws.rs.core.Response) Address(org.orcid.jaxb.model.record_v2.Address) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 55 with Address

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

the class MemberV2ApiServiceDelegator_AddressesTest method testViewAddressesReadPublic.

@Test
public void testViewAddressesReadPublic() {
    SecurityContextTestUtils.setUpSecurityContextForClientOnly("APP-5555555555555555", ScopePathType.READ_PUBLIC);
    Response r = serviceDelegator.viewAddresses(ORCID);
    Addresses element = (Addresses) r.getEntity();
    assertNotNull(element);
    assertEquals("/0000-0000-0000-0003/address", element.getPath());
    Utils.assertIsPublicOrSource(element, "APP-5555555555555555");
}
Also used : Response(javax.ws.rs.core.Response) Addresses(org.orcid.jaxb.model.record_v2.Addresses) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)90 Address (org.orcid.jaxb.model.record_v2.Address)84 Addresses (org.orcid.jaxb.model.record_v2.Addresses)48 ResearcherUrl (org.orcid.jaxb.model.record_v2.ResearcherUrl)47 OtherName (org.orcid.jaxb.model.record_v2.OtherName)46 Keyword (org.orcid.jaxb.model.record_v2.Keyword)44 PersonExternalIdentifier (org.orcid.jaxb.model.record_v2.PersonExternalIdentifier)44 Email (org.orcid.jaxb.model.record_v2.Email)43 Biography (org.orcid.jaxb.model.record_v2.Biography)36 OtherNames (org.orcid.jaxb.model.record_v2.OtherNames)36 Keywords (org.orcid.jaxb.model.record_v2.Keywords)34 PersonExternalIdentifiers (org.orcid.jaxb.model.record_v2.PersonExternalIdentifiers)34 ResearcherUrls (org.orcid.jaxb.model.record_v2.ResearcherUrls)34 Emails (org.orcid.jaxb.model.record_v2.Emails)32 Name (org.orcid.jaxb.model.record_v2.Name)31 Person (org.orcid.jaxb.model.record_v2.Person)30 DBUnitTest (org.orcid.test.DBUnitTest)21 Response (javax.ws.rs.core.Response)19 FundingSummary (org.orcid.jaxb.model.record.summary_v2.FundingSummary)19 EducationSummary (org.orcid.jaxb.model.record.summary_v2.EducationSummary)18