Search in sources :

Example 56 with Keywords

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

the class KeywordsTest method testCreateGetUpdateAndDeleteKeyword_rc4.

/**
     * --------- -- -- -- RC4 -- -- -- ---------
     * 
     */
@SuppressWarnings({ "deprecation", "rawtypes" })
@Test
public void testCreateGetUpdateAndDeleteKeyword_rc4() throws InterruptedException, JSONException {
    changeDefaultUserVisibility(org.orcid.jaxb.model.common_v2.Visibility.LIMITED);
    changeCurrentKeywordsVisibility(org.orcid.jaxb.model.common_v2.Visibility.PUBLIC);
    String accessToken = getAccessToken();
    assertNotNull(accessToken);
    org.orcid.jaxb.model.record_rc4.Keyword newKeyword = new org.orcid.jaxb.model.record_rc4.Keyword();
    newKeyword.setContent("keyword-3");
    newKeyword.setVisibility(org.orcid.jaxb.model.common_rc4.Visibility.PUBLIC);
    // Create
    ClientResponse response = memberV2ApiClient_rc4.createKeyword(getUser1OrcidId(), newKeyword, accessToken);
    assertNotNull(response);
    assertEquals(ClientResponse.Status.CREATED.getStatusCode(), response.getStatus());
    Map map = response.getMetadata();
    assertNotNull(map);
    assertTrue(map.containsKey("Location"));
    List resultWithPutCode = (List) map.get("Location");
    String location = resultWithPutCode.get(0).toString();
    Long putCode = Long.valueOf(location.substring(location.lastIndexOf('/') + 1));
    // Get all and verify
    response = memberV2ApiClient_rc4.viewKeywords(getUser1OrcidId(), accessToken);
    assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
    org.orcid.jaxb.model.record_rc4.Keywords keywords = response.getEntity(org.orcid.jaxb.model.record_rc4.Keywords.class);
    assertNotNull(keywords);
    assertNotNull(keywords.getKeywords());
    boolean found1 = false;
    boolean found2 = false;
    boolean foundNew = false;
    for (org.orcid.jaxb.model.record_rc4.Keyword existingKeyword : keywords.getKeywords()) {
        if (existingKeyword.getContent().equals(keyword1)) {
            assertEquals(org.orcid.jaxb.model.common_rc4.Visibility.PUBLIC, existingKeyword.getVisibility());
            found1 = true;
        } else if (existingKeyword.getContent().equals(keyword2)) {
            assertEquals(org.orcid.jaxb.model.common_rc4.Visibility.PUBLIC, existingKeyword.getVisibility());
            found2 = true;
        } else if (existingKeyword.getContent().equals(newKeyword.getContent())) {
            assertEquals(org.orcid.jaxb.model.common_rc4.Visibility.LIMITED, existingKeyword.getVisibility());
            assertEquals("keyword-3", existingKeyword.getContent());
            assertEquals(getClient1ClientId(), existingKeyword.getSource().retrieveSourcePath());
            foundNew = true;
        }
    }
    assertTrue(found1);
    assertTrue(found2);
    assertTrue(foundNew);
    // Get it
    response = memberV2ApiClient_rc4.viewKeyword(getUser1OrcidId(), putCode, accessToken);
    assertNotNull(response);
    newKeyword = response.getEntity(org.orcid.jaxb.model.record_rc4.Keyword.class);
    assertNotNull(newKeyword);
    assertNotNull(newKeyword.getSource());
    assertEquals(getClient1ClientId(), newKeyword.getSource().retrieveSourcePath());
    assertEquals("keyword-3", newKeyword.getContent());
    assertEquals(org.orcid.jaxb.model.common_rc4.Visibility.LIMITED, newKeyword.getVisibility());
    assertNotNull(newKeyword.getDisplayIndex());
    Long originalDisplayIndex = newKeyword.getDisplayIndex();
    // Save the original visibility
    org.orcid.jaxb.model.common_rc4.Visibility originalVisibility = newKeyword.getVisibility();
    org.orcid.jaxb.model.common_rc4.Visibility updatedVisibility = org.orcid.jaxb.model.common_rc4.Visibility.PRIVATE;
    // Verify you cant update the visibility
    newKeyword.setVisibility(updatedVisibility);
    ClientResponse putResponse = memberV2ApiClient_rc4.updateKeyword(getUser1OrcidId(), newKeyword, accessToken);
    assertEquals(Response.Status.FORBIDDEN.getStatusCode(), putResponse.getStatus());
    org.orcid.jaxb.model.error_rc4.OrcidError error = putResponse.getEntity(org.orcid.jaxb.model.error_rc4.OrcidError.class);
    assertNotNull(error);
    assertEquals(Integer.valueOf(9035), error.getErrorCode());
    // Set the visibility again to the initial one
    newKeyword.setVisibility(originalVisibility);
    // Update
    newKeyword.setContent("keyword-3-updated");
    response = memberV2ApiClient_rc4.updateKeyword(getUser1OrcidId(), newKeyword, accessToken);
    assertNotNull(response);
    assertEquals(ClientResponse.Status.OK.getStatusCode(), response.getStatus());
    response = memberV2ApiClient_rc4.viewKeyword(getUser1OrcidId(), putCode, accessToken);
    assertNotNull(response);
    org.orcid.jaxb.model.record_rc4.Keyword updatedKeyword = response.getEntity(org.orcid.jaxb.model.record_rc4.Keyword.class);
    assertNotNull(updatedKeyword);
    assertEquals("keyword-3-updated", updatedKeyword.getContent());
    assertEquals(newKeyword.getPutCode(), updatedKeyword.getPutCode());
    assertEquals(originalDisplayIndex, updatedKeyword.getDisplayIndex());
    // Delete
    response = memberV2ApiClient_rc4.deleteKeyword(getUser1OrcidId(), putCode, accessToken);
    assertNotNull(response);
    assertEquals(ClientResponse.Status.NO_CONTENT.getStatusCode(), response.getStatus());
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) Keyword(org.orcid.jaxb.model.record_rc3.Keyword) List(java.util.List) Map(java.util.Map) Test(org.junit.Test)

Example 57 with Keywords

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

the class KeywordsTest method testCreateGetUpdateAndDeleteKeyword_V2_1.

/**
     * --------- -- -- -- V2.1 -- -- -- ---------
     * 
     */
@SuppressWarnings({ "deprecation", "rawtypes" })
@Test
public void testCreateGetUpdateAndDeleteKeyword_V2_1() throws InterruptedException, JSONException {
    changeDefaultUserVisibility(org.orcid.jaxb.model.common_v2.Visibility.LIMITED);
    changeCurrentKeywordsVisibility(org.orcid.jaxb.model.common_v2.Visibility.PUBLIC);
    String accessToken = getAccessToken();
    assertNotNull(accessToken);
    org.orcid.jaxb.model.record_v2.Keyword newKeyword = new org.orcid.jaxb.model.record_v2.Keyword();
    newKeyword.setContent("keyword-3");
    newKeyword.setVisibility(org.orcid.jaxb.model.common_v2.Visibility.PUBLIC);
    // Create
    ClientResponse response = memberV2_1ApiClient_release.createKeyword(getUser1OrcidId(), newKeyword, accessToken);
    assertNotNull(response);
    assertEquals(ClientResponse.Status.CREATED.getStatusCode(), response.getStatus());
    Map map = response.getMetadata();
    assertNotNull(map);
    assertTrue(map.containsKey("Location"));
    List resultWithPutCode = (List) map.get("Location");
    String location = resultWithPutCode.get(0).toString();
    Long putCode = Long.valueOf(location.substring(location.lastIndexOf('/') + 1));
    // Get all and verify
    response = memberV2_1ApiClient_release.viewKeywords(getUser1OrcidId(), accessToken);
    assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
    org.orcid.jaxb.model.record_v2.Keywords keywords = response.getEntity(org.orcid.jaxb.model.record_v2.Keywords.class);
    assertNotNull(keywords);
    assertNotNull(keywords.getKeywords());
    boolean found1 = false;
    boolean found2 = false;
    boolean foundNew = false;
    for (org.orcid.jaxb.model.record_v2.Keyword existingKeyword : keywords.getKeywords()) {
        if (existingKeyword.getContent().equals(keyword1)) {
            assertEquals(org.orcid.jaxb.model.common_v2.Visibility.PUBLIC, existingKeyword.getVisibility());
            found1 = true;
        } else if (existingKeyword.getContent().equals(keyword2)) {
            assertEquals(org.orcid.jaxb.model.common_v2.Visibility.PUBLIC, existingKeyword.getVisibility());
            found2 = true;
        } else if (existingKeyword.getContent().equals(newKeyword.getContent())) {
            assertEquals(org.orcid.jaxb.model.common_v2.Visibility.LIMITED, existingKeyword.getVisibility());
            assertEquals("keyword-3", existingKeyword.getContent());
            assertEquals(getClient1ClientId(), existingKeyword.getSource().retrieveSourcePath());
            foundNew = true;
        }
    }
    assertTrue(found1);
    assertTrue(found2);
    assertTrue(foundNew);
    // Get it
    response = memberV2_1ApiClient_release.viewKeyword(getUser1OrcidId(), putCode, accessToken);
    assertNotNull(response);
    newKeyword = response.getEntity(org.orcid.jaxb.model.record_v2.Keyword.class);
    assertNotNull(newKeyword);
    assertNotNull(newKeyword.getSource());
    assertEquals(getClient1ClientId(), newKeyword.getSource().retrieveSourcePath());
    assertEquals("keyword-3", newKeyword.getContent());
    assertEquals(org.orcid.jaxb.model.common_v2.Visibility.LIMITED, newKeyword.getVisibility());
    assertNotNull(newKeyword.getDisplayIndex());
    Long originalDisplayIndex = newKeyword.getDisplayIndex();
    // Save the original visibility
    org.orcid.jaxb.model.common_v2.Visibility originalVisibility = newKeyword.getVisibility();
    org.orcid.jaxb.model.common_v2.Visibility updatedVisibility = org.orcid.jaxb.model.common_v2.Visibility.PRIVATE;
    // Verify you cant update the visibility
    newKeyword.setVisibility(updatedVisibility);
    ClientResponse putResponse = memberV2_1ApiClient_release.updateKeyword(getUser1OrcidId(), newKeyword, accessToken);
    assertEquals(Response.Status.FORBIDDEN.getStatusCode(), putResponse.getStatus());
    org.orcid.jaxb.model.error_v2.OrcidError error = putResponse.getEntity(org.orcid.jaxb.model.error_v2.OrcidError.class);
    assertNotNull(error);
    assertEquals(Integer.valueOf(9035), error.getErrorCode());
    // Set the visibility again to the initial one
    newKeyword.setVisibility(originalVisibility);
    // Update
    newKeyword.setContent("keyword-3-updated");
    response = memberV2_1ApiClient_release.updateKeyword(getUser1OrcidId(), newKeyword, accessToken);
    assertNotNull(response);
    assertEquals(ClientResponse.Status.OK.getStatusCode(), response.getStatus());
    response = memberV2_1ApiClient_release.viewKeyword(getUser1OrcidId(), putCode, accessToken);
    assertNotNull(response);
    org.orcid.jaxb.model.record_v2.Keyword updatedKeyword = response.getEntity(org.orcid.jaxb.model.record_v2.Keyword.class);
    assertNotNull(updatedKeyword);
    assertEquals("keyword-3-updated", updatedKeyword.getContent());
    assertEquals(newKeyword.getPutCode(), updatedKeyword.getPutCode());
    assertEquals(originalDisplayIndex, updatedKeyword.getDisplayIndex());
    // Delete
    response = memberV2_1ApiClient_release.deleteKeyword(getUser1OrcidId(), putCode, accessToken);
    assertNotNull(response);
    assertEquals(ClientResponse.Status.NO_CONTENT.getStatusCode(), response.getStatus());
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) Keyword(org.orcid.jaxb.model.record_rc3.Keyword) List(java.util.List) Map(java.util.Map) Test(org.junit.Test)

Example 58 with Keywords

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

the class KeywordsTest method testCreateGetUpdateAndDeleteKeyword_rc3.

/**
     * --------- -- -- -- RC3 -- -- -- ---------
     * 
     */
@SuppressWarnings({ "deprecation", "rawtypes" })
@Test
public void testCreateGetUpdateAndDeleteKeyword_rc3() throws InterruptedException, JSONException {
    changeDefaultUserVisibility(org.orcid.jaxb.model.common_v2.Visibility.LIMITED);
    changeCurrentKeywordsVisibility(org.orcid.jaxb.model.common_v2.Visibility.PUBLIC);
    String accessToken = getAccessToken();
    assertNotNull(accessToken);
    org.orcid.jaxb.model.record_rc3.Keyword newKeyword = new org.orcid.jaxb.model.record_rc3.Keyword();
    newKeyword.setContent("keyword-3");
    newKeyword.setVisibility(org.orcid.jaxb.model.common_rc3.Visibility.PUBLIC);
    // Create
    ClientResponse response = memberV2ApiClient_rc3.createKeyword(getUser1OrcidId(), newKeyword, accessToken);
    assertNotNull(response);
    assertEquals(ClientResponse.Status.CREATED.getStatusCode(), response.getStatus());
    Map map = response.getMetadata();
    assertNotNull(map);
    assertTrue(map.containsKey("Location"));
    List resultWithPutCode = (List) map.get("Location");
    String location = resultWithPutCode.get(0).toString();
    Long putCode = Long.valueOf(location.substring(location.lastIndexOf('/') + 1));
    // Get all and verify
    response = memberV2ApiClient_rc3.viewKeywords(getUser1OrcidId(), accessToken);
    assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
    Keywords keywords = response.getEntity(Keywords.class);
    assertNotNull(keywords);
    assertNotNull(keywords.getKeywords());
    boolean found1 = false;
    boolean found2 = false;
    boolean foundNew = false;
    for (org.orcid.jaxb.model.record_rc3.Keyword existingKeyword : keywords.getKeywords()) {
        if (existingKeyword.getContent().equals(keyword1)) {
            assertEquals(org.orcid.jaxb.model.common_rc3.Visibility.PUBLIC, existingKeyword.getVisibility());
            found1 = true;
        } else if (existingKeyword.getContent().equals(keyword2)) {
            assertEquals(org.orcid.jaxb.model.common_rc3.Visibility.PUBLIC, existingKeyword.getVisibility());
            found2 = true;
        } else if (existingKeyword.getContent().equals(newKeyword.getContent())) {
            assertEquals(org.orcid.jaxb.model.common_rc3.Visibility.LIMITED, existingKeyword.getVisibility());
            assertEquals("keyword-3", existingKeyword.getContent());
            assertEquals(getClient1ClientId(), existingKeyword.getSource().retrieveSourcePath());
            foundNew = true;
        }
    }
    assertTrue(found1);
    assertTrue(found2);
    assertTrue(foundNew);
    // Get it
    response = memberV2ApiClient_rc3.viewKeyword(getUser1OrcidId(), putCode, accessToken);
    assertNotNull(response);
    newKeyword = response.getEntity(Keyword.class);
    assertNotNull(newKeyword);
    assertNotNull(newKeyword.getSource());
    assertEquals(getClient1ClientId(), newKeyword.getSource().retrieveSourcePath());
    assertEquals("keyword-3", newKeyword.getContent());
    assertEquals(org.orcid.jaxb.model.common_rc3.Visibility.LIMITED, newKeyword.getVisibility());
    assertNotNull(newKeyword.getDisplayIndex());
    Long originalDisplayIndex = newKeyword.getDisplayIndex();
    // Save the original visibility
    org.orcid.jaxb.model.common_rc3.Visibility originalVisibility = newKeyword.getVisibility();
    org.orcid.jaxb.model.common_rc3.Visibility updatedVisibility = org.orcid.jaxb.model.common_rc3.Visibility.PRIVATE;
    // Verify you cant update the visibility
    newKeyword.setVisibility(updatedVisibility);
    ClientResponse putResponse = memberV2ApiClient_rc3.updateKeyword(getUser1OrcidId(), newKeyword, accessToken);
    assertEquals(Response.Status.FORBIDDEN.getStatusCode(), putResponse.getStatus());
    org.orcid.jaxb.model.error_rc3.OrcidError error = putResponse.getEntity(org.orcid.jaxb.model.error_rc3.OrcidError.class);
    assertNotNull(error);
    assertEquals(Integer.valueOf(9035), error.getErrorCode());
    // Set the visibility again to the initial one
    newKeyword.setVisibility(originalVisibility);
    // Update
    newKeyword.setContent("keyword-3-updated");
    response = memberV2ApiClient_rc3.updateKeyword(getUser1OrcidId(), newKeyword, accessToken);
    assertNotNull(response);
    assertEquals(ClientResponse.Status.OK.getStatusCode(), response.getStatus());
    response = memberV2ApiClient_rc3.viewKeyword(getUser1OrcidId(), putCode, accessToken);
    assertNotNull(response);
    org.orcid.jaxb.model.record_rc3.Keyword updatedKeyword = response.getEntity(Keyword.class);
    assertNotNull(updatedKeyword);
    assertEquals("keyword-3-updated", updatedKeyword.getContent());
    assertEquals(newKeyword.getPutCode(), updatedKeyword.getPutCode());
    assertEquals(originalDisplayIndex, updatedKeyword.getDisplayIndex());
    // Delete
    response = memberV2ApiClient_rc3.deleteKeyword(getUser1OrcidId(), putCode, accessToken);
    assertNotNull(response);
    assertEquals(ClientResponse.Status.NO_CONTENT.getStatusCode(), response.getStatus());
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) Keywords(org.orcid.jaxb.model.record_rc3.Keywords) Keyword(org.orcid.jaxb.model.record_rc3.Keyword) List(java.util.List) Map(java.util.Map) Keyword(org.orcid.jaxb.model.record_rc3.Keyword) Test(org.junit.Test)

Example 59 with Keywords

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

the class KeywordsTest method testCreateGetUpdateAndDeleteKeyword_rc2.

/**
     * --------- -- -- -- RC2 -- -- -- ---------
     * 
     */
@SuppressWarnings({ "deprecation", "rawtypes" })
@Test
public void testCreateGetUpdateAndDeleteKeyword_rc2() throws InterruptedException, JSONException {
    changeDefaultUserVisibility(org.orcid.jaxb.model.common_v2.Visibility.LIMITED);
    changeCurrentKeywordsVisibility(org.orcid.jaxb.model.common_v2.Visibility.PUBLIC);
    String accessToken = getAccessToken();
    assertNotNull(accessToken);
    org.orcid.jaxb.model.record_rc2.Keyword newKeyword = new org.orcid.jaxb.model.record_rc2.Keyword();
    newKeyword.setContent("keyword-3");
    newKeyword.setVisibility(org.orcid.jaxb.model.common_rc2.Visibility.PUBLIC);
    // Create
    ClientResponse response = memberV2ApiClient_rc2.createKeyword(getUser1OrcidId(), newKeyword, accessToken);
    assertNotNull(response);
    assertEquals(ClientResponse.Status.CREATED.getStatusCode(), response.getStatus());
    Map map = response.getMetadata();
    assertNotNull(map);
    assertTrue(map.containsKey("Location"));
    List resultWithPutCode = (List) map.get("Location");
    String location = resultWithPutCode.get(0).toString();
    Long putCode = Long.valueOf(location.substring(location.lastIndexOf('/') + 1));
    // Get all and verify
    response = memberV2ApiClient_rc2.viewKeywords(getUser1OrcidId(), accessToken);
    assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
    org.orcid.jaxb.model.record_rc2.Keywords keywords = response.getEntity(org.orcid.jaxb.model.record_rc2.Keywords.class);
    assertNotNull(keywords);
    assertNotNull(keywords.getKeywords());
    boolean found1 = false;
    boolean found2 = false;
    boolean foundNew = false;
    for (org.orcid.jaxb.model.record_rc2.Keyword existingKeyword : keywords.getKeywords()) {
        if (existingKeyword.getContent().equals(keyword1)) {
            assertEquals(org.orcid.jaxb.model.common_rc2.Visibility.PUBLIC, existingKeyword.getVisibility());
            found1 = true;
        } else if (existingKeyword.getContent().equals(keyword2)) {
            assertEquals(org.orcid.jaxb.model.common_rc2.Visibility.PUBLIC, existingKeyword.getVisibility());
            found2 = true;
        } else if (existingKeyword.getContent().equals(newKeyword.getContent())) {
            assertEquals(org.orcid.jaxb.model.common_rc2.Visibility.LIMITED, existingKeyword.getVisibility());
            assertEquals("keyword-3", existingKeyword.getContent());
            assertEquals(getClient1ClientId(), existingKeyword.getSource().retrieveSourcePath());
            foundNew = true;
        }
    }
    assertTrue(found1);
    assertTrue(found2);
    assertTrue(foundNew);
    // Get it
    response = memberV2ApiClient_rc2.viewKeyword(getUser1OrcidId(), putCode, accessToken);
    assertNotNull(response);
    newKeyword = response.getEntity(org.orcid.jaxb.model.record_rc2.Keyword.class);
    assertNotNull(newKeyword);
    assertNotNull(newKeyword.getSource());
    assertEquals(getClient1ClientId(), newKeyword.getSource().retrieveSourcePath());
    assertEquals("keyword-3", newKeyword.getContent());
    assertEquals(org.orcid.jaxb.model.common_rc2.Visibility.LIMITED, newKeyword.getVisibility());
    assertNotNull(newKeyword.getDisplayIndex());
    Long originalDisplayIndex = newKeyword.getDisplayIndex();
    // Save the original visibility
    org.orcid.jaxb.model.common_rc2.Visibility originalVisibility = newKeyword.getVisibility();
    org.orcid.jaxb.model.common_rc2.Visibility updatedVisibility = org.orcid.jaxb.model.common_rc2.Visibility.PRIVATE;
    // Verify you cant update the visibility
    newKeyword.setVisibility(updatedVisibility);
    ClientResponse putResponse = memberV2ApiClient_rc2.updateKeyword(getUser1OrcidId(), newKeyword, accessToken);
    assertEquals(Response.Status.FORBIDDEN.getStatusCode(), putResponse.getStatus());
    org.orcid.jaxb.model.error_rc2.OrcidError error = putResponse.getEntity(org.orcid.jaxb.model.error_rc2.OrcidError.class);
    assertNotNull(error);
    assertEquals(Integer.valueOf(9035), error.getErrorCode());
    // Set the visibility again to the initial one
    newKeyword.setVisibility(originalVisibility);
    // Update
    newKeyword.setContent("keyword-3-updated");
    response = memberV2ApiClient_rc2.updateKeyword(getUser1OrcidId(), newKeyword, accessToken);
    assertNotNull(response);
    assertEquals(ClientResponse.Status.OK.getStatusCode(), response.getStatus());
    response = memberV2ApiClient_rc2.viewKeyword(getUser1OrcidId(), putCode, accessToken);
    assertNotNull(response);
    org.orcid.jaxb.model.record_rc2.Keyword updatedKeyword = response.getEntity(org.orcid.jaxb.model.record_rc2.Keyword.class);
    assertNotNull(updatedKeyword);
    assertEquals("keyword-3-updated", updatedKeyword.getContent());
    assertEquals(newKeyword.getPutCode(), updatedKeyword.getPutCode());
    assertEquals(originalDisplayIndex, updatedKeyword.getDisplayIndex());
    // Delete
    response = memberV2ApiClient_rc2.deleteKeyword(getUser1OrcidId(), putCode, accessToken);
    assertNotNull(response);
    assertEquals(ClientResponse.Status.NO_CONTENT.getStatusCode(), response.getStatus());
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) Keyword(org.orcid.jaxb.model.record_rc3.Keyword) List(java.util.List) Map(java.util.Map) Test(org.junit.Test)

Example 60 with Keywords

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

the class KeywordsTest method testCreateGetUpdateAndDeleteKeyword_release.

/**
     * --------- -- -- -- Release -- -- -- ---------
     * 
     */
@SuppressWarnings({ "deprecation", "rawtypes" })
@Test
public void testCreateGetUpdateAndDeleteKeyword_release() throws InterruptedException, JSONException {
    changeDefaultUserVisibility(org.orcid.jaxb.model.common_v2.Visibility.LIMITED);
    changeCurrentKeywordsVisibility(org.orcid.jaxb.model.common_v2.Visibility.PUBLIC);
    String accessToken = getAccessToken();
    assertNotNull(accessToken);
    org.orcid.jaxb.model.record_v2.Keyword newKeyword = new org.orcid.jaxb.model.record_v2.Keyword();
    newKeyword.setContent("keyword-3");
    newKeyword.setVisibility(org.orcid.jaxb.model.common_v2.Visibility.PUBLIC);
    // Create
    ClientResponse response = memberV2ApiClient_release.createKeyword(getUser1OrcidId(), newKeyword, accessToken);
    assertNotNull(response);
    assertEquals(ClientResponse.Status.CREATED.getStatusCode(), response.getStatus());
    Map map = response.getMetadata();
    assertNotNull(map);
    assertTrue(map.containsKey("Location"));
    List resultWithPutCode = (List) map.get("Location");
    String location = resultWithPutCode.get(0).toString();
    Long putCode = Long.valueOf(location.substring(location.lastIndexOf('/') + 1));
    // Get all and verify
    response = memberV2ApiClient_release.viewKeywords(getUser1OrcidId(), accessToken);
    assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
    org.orcid.jaxb.model.record_v2.Keywords keywords = response.getEntity(org.orcid.jaxb.model.record_v2.Keywords.class);
    assertNotNull(keywords);
    assertNotNull(keywords.getKeywords());
    boolean found1 = false;
    boolean found2 = false;
    boolean foundNew = false;
    for (org.orcid.jaxb.model.record_v2.Keyword existingKeyword : keywords.getKeywords()) {
        if (existingKeyword.getContent().equals(keyword1)) {
            assertEquals(org.orcid.jaxb.model.common_v2.Visibility.PUBLIC, existingKeyword.getVisibility());
            found1 = true;
        } else if (existingKeyword.getContent().equals(keyword2)) {
            assertEquals(org.orcid.jaxb.model.common_v2.Visibility.PUBLIC, existingKeyword.getVisibility());
            found2 = true;
        } else if (existingKeyword.getContent().equals(newKeyword.getContent())) {
            assertEquals(org.orcid.jaxb.model.common_v2.Visibility.LIMITED, existingKeyword.getVisibility());
            assertEquals("keyword-3", existingKeyword.getContent());
            assertEquals(getClient1ClientId(), existingKeyword.getSource().retrieveSourcePath());
            foundNew = true;
        }
    }
    assertTrue(found1);
    assertTrue(found2);
    assertTrue(foundNew);
    // Get it
    response = memberV2ApiClient_release.viewKeyword(getUser1OrcidId(), putCode, accessToken);
    assertNotNull(response);
    newKeyword = response.getEntity(org.orcid.jaxb.model.record_v2.Keyword.class);
    assertNotNull(newKeyword);
    assertNotNull(newKeyword.getSource());
    assertEquals(getClient1ClientId(), newKeyword.getSource().retrieveSourcePath());
    assertEquals("keyword-3", newKeyword.getContent());
    assertEquals(org.orcid.jaxb.model.common_v2.Visibility.LIMITED, newKeyword.getVisibility());
    assertNotNull(newKeyword.getDisplayIndex());
    Long originalDisplayIndex = newKeyword.getDisplayIndex();
    // Save the original visibility
    org.orcid.jaxb.model.common_v2.Visibility originalVisibility = newKeyword.getVisibility();
    org.orcid.jaxb.model.common_v2.Visibility updatedVisibility = org.orcid.jaxb.model.common_v2.Visibility.PRIVATE;
    // Verify you cant update the visibility
    newKeyword.setVisibility(updatedVisibility);
    ClientResponse putResponse = memberV2ApiClient_release.updateKeyword(getUser1OrcidId(), newKeyword, accessToken);
    assertEquals(Response.Status.FORBIDDEN.getStatusCode(), putResponse.getStatus());
    org.orcid.jaxb.model.error_v2.OrcidError error = putResponse.getEntity(org.orcid.jaxb.model.error_v2.OrcidError.class);
    assertNotNull(error);
    assertEquals(Integer.valueOf(9035), error.getErrorCode());
    // Set the visibility again to the initial one
    newKeyword.setVisibility(originalVisibility);
    // Update
    newKeyword.setContent("keyword-3-updated");
    response = memberV2ApiClient_release.updateKeyword(getUser1OrcidId(), newKeyword, accessToken);
    assertNotNull(response);
    assertEquals(ClientResponse.Status.OK.getStatusCode(), response.getStatus());
    response = memberV2ApiClient_release.viewKeyword(getUser1OrcidId(), putCode, accessToken);
    assertNotNull(response);
    org.orcid.jaxb.model.record_v2.Keyword updatedKeyword = response.getEntity(org.orcid.jaxb.model.record_v2.Keyword.class);
    assertNotNull(updatedKeyword);
    assertEquals("keyword-3-updated", updatedKeyword.getContent());
    assertEquals(newKeyword.getPutCode(), updatedKeyword.getPutCode());
    assertEquals(originalDisplayIndex, updatedKeyword.getDisplayIndex());
    // Delete
    response = memberV2ApiClient_release.deleteKeyword(getUser1OrcidId(), putCode, accessToken);
    assertNotNull(response);
    assertEquals(ClientResponse.Status.NO_CONTENT.getStatusCode(), response.getStatus());
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) Keyword(org.orcid.jaxb.model.record_rc3.Keyword) List(java.util.List) Map(java.util.Map) 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