Search in sources :

Example 31 with Keywords

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

the class ValidateV2RC2SamplesTest method testMarshallKeyword.

@Test
public void testMarshallKeyword() throws JAXBException, SAXException, URISyntaxException {
    Keywords object = (Keywords) unmarshallFromPath("/record_2.0_rc2/samples/keywords-2.0_rc2.xml", Keywords.class);
    marshall(object, "/record_2.0_rc2/keyword-2.0_rc2.xsd");
}
Also used : Keywords(org.orcid.jaxb.model.record_rc2.Keywords) Test(org.junit.Test)

Example 32 with Keywords

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

the class PublicAPISecurityManagerV2Test method getKeywordsElement.

private Keywords getKeywordsElement(Visibility... vs) {
    Keywords elements = new Keywords();
    for (Visibility v : vs) {
        Keyword element = new Keyword();
        element.setVisibility(v);
        if (elements.getKeywords() == null) {
            elements.setKeywords(new ArrayList<Keyword>());
        }
        elements.getKeywords().add(element);
    }
    return elements;
}
Also used : Keywords(org.orcid.jaxb.model.record_v2.Keywords) Keyword(org.orcid.jaxb.model.record_v2.Keyword) Visibility(org.orcid.jaxb.model.common_v2.Visibility)

Example 33 with Keywords

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

the class MemberV2ApiServiceDelegator_KeywordsTest method testReadPublicScope_Keywords.

@Test
public void testReadPublicScope_Keywords() {
    SecurityContextTestUtils.setUpSecurityContext(ORCID, ScopePathType.READ_PUBLIC);
    // Public works
    Response r = serviceDelegator.viewKeywords(ORCID);
    assertNotNull(r);
    assertEquals(Keywords.class.getName(), r.getEntity().getClass().getName());
    Keywords k = (Keywords) r.getEntity();
    assertNotNull(k);
    Utils.verifyLastModified(k.getLastModifiedDate());
    assertEquals(3, k.getKeywords().size());
    boolean found1 = false, found2 = false, found3 = false;
    for (Keyword element : k.getKeywords()) {
        Utils.verifyLastModified(element.getLastModifiedDate());
        if (element.getPutCode() == 9) {
            found1 = true;
        } else if (element.getPutCode() == 10) {
            found2 = true;
        } else if (element.getPutCode() == 11) {
            found3 = true;
        } else {
            fail("Invalid put code " + element.getPutCode());
        }
    }
    assertTrue(found1);
    assertTrue(found2);
    assertTrue(found3);
    r = serviceDelegator.viewKeyword(ORCID, 9L);
    assertNotNull(r);
    assertEquals(Keyword.class.getName(), r.getEntity().getClass().getName());
    // Limited where am the source of should work
    serviceDelegator.viewKeyword(ORCID, 10L);
    // Limited where am not the source of should fail
    try {
        serviceDelegator.viewKeyword(ORCID, 12L);
        fail();
    } catch (OrcidAccessControlException e) {
    } catch (Exception e) {
        fail();
    }
    // Private where am the source of should work
    serviceDelegator.viewKeyword(ORCID, 11L);
    // Private where am not the source of should fail
    try {
        serviceDelegator.viewKeyword(ORCID, 13L);
        fail();
    } catch (OrcidAccessControlException e) {
    } catch (Exception e) {
        fail();
    }
}
Also used : Response(javax.ws.rs.core.Response) Keywords(org.orcid.jaxb.model.record_v2.Keywords) Keyword(org.orcid.jaxb.model.record_v2.Keyword) 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 34 with Keywords

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

the class MemberV2ApiServiceDelegator_KeywordsTest method testDeleteKeyword.

@Test
public void testDeleteKeyword() {
    SecurityContextTestUtils.setUpSecurityContext("4444-4444-4444-4499", ScopePathType.PERSON_READ_LIMITED, ScopePathType.PERSON_UPDATE);
    Response response = serviceDelegator.viewKeywords("4444-4444-4444-4499");
    assertNotNull(response);
    Keywords keywords = (Keywords) response.getEntity();
    assertNotNull(keywords);
    assertNotNull(keywords.getKeywords());
    assertEquals(1, keywords.getKeywords().size());
    response = serviceDelegator.deleteKeyword("4444-4444-4444-4499", 8L);
    assertNotNull(response);
    assertEquals(Response.Status.NO_CONTENT.getStatusCode(), response.getStatus());
    response = serviceDelegator.viewKeywords("4444-4444-4444-4499");
    assertNotNull(response);
    keywords = (Keywords) response.getEntity();
    assertNotNull(keywords);
    assertNotNull(keywords.getKeywords());
    assertTrue(keywords.getKeywords().isEmpty());
}
Also used : Response(javax.ws.rs.core.Response) Keywords(org.orcid.jaxb.model.record_v2.Keywords) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 35 with Keywords

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

the class MemberV2ApiServiceDelegator_KeywordsTest method testViewKeywords.

@Test
public void testViewKeywords() {
    SecurityContextTestUtils.setUpSecurityContext("4444-4444-4444-4443", ScopePathType.PERSON_READ_LIMITED);
    Response response = serviceDelegator.viewKeywords("4444-4444-4444-4443");
    assertNotNull(response);
    Keywords keywords = (Keywords) response.getEntity();
    assertNotNull(keywords);
    assertEquals("/4444-4444-4444-4443/keywords", keywords.getPath());
    Utils.verifyLastModified(keywords.getLastModifiedDate());
    assertNotNull(keywords.getKeywords());
    assertEquals(3, keywords.getKeywords().size());
    for (Keyword keyword : keywords.getKeywords()) {
        Utils.verifyLastModified(keyword.getLastModifiedDate());
        assertThat(keyword.getPutCode(), anyOf(is(1L), is(2L), is(4L)));
        assertThat(keyword.getContent(), anyOf(is("tea making"), is("coffee making"), is("what else can we make?")));
        if (keyword.getPutCode() == 1L) {
            assertEquals(Visibility.PUBLIC, keyword.getVisibility());
            assertEquals("APP-5555555555555555", keyword.getSource().retrieveSourcePath());
        } else if (keyword.getPutCode() == 2L) {
            assertEquals(Visibility.LIMITED, keyword.getVisibility());
            assertEquals("4444-4444-4444-4443", keyword.getSource().retrieveSourcePath());
        } else {
            assertEquals(Visibility.PRIVATE, keyword.getVisibility());
            assertEquals("APP-5555555555555555", keyword.getSource().retrieveSourcePath());
        }
    }
}
Also used : Response(javax.ws.rs.core.Response) Keywords(org.orcid.jaxb.model.record_v2.Keywords) Keyword(org.orcid.jaxb.model.record_v2.Keyword) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)58 Keywords (org.orcid.jaxb.model.record_v2.Keywords)54 Keyword (org.orcid.jaxb.model.record_v2.Keyword)41 Addresses (org.orcid.jaxb.model.record_v2.Addresses)35 OtherNames (org.orcid.jaxb.model.record_v2.OtherNames)35 PersonExternalIdentifiers (org.orcid.jaxb.model.record_v2.PersonExternalIdentifiers)35 ResearcherUrls (org.orcid.jaxb.model.record_v2.ResearcherUrls)35 Biography (org.orcid.jaxb.model.record_v2.Biography)33 Emails (org.orcid.jaxb.model.record_v2.Emails)33 Address (org.orcid.jaxb.model.record_v2.Address)32 OtherName (org.orcid.jaxb.model.record_v2.OtherName)32 Email (org.orcid.jaxb.model.record_v2.Email)31 PersonExternalIdentifier (org.orcid.jaxb.model.record_v2.PersonExternalIdentifier)31 ResearcherUrl (org.orcid.jaxb.model.record_v2.ResearcherUrl)31 Name (org.orcid.jaxb.model.record_v2.Name)28 Person (org.orcid.jaxb.model.record_v2.Person)25 ClientResponse (com.sun.jersey.api.client.ClientResponse)17 EducationSummary (org.orcid.jaxb.model.record.summary_v2.EducationSummary)15 EmploymentSummary (org.orcid.jaxb.model.record.summary_v2.EmploymentSummary)15 FundingSummary (org.orcid.jaxb.model.record.summary_v2.FundingSummary)15