Search in sources :

Example 71 with Url

use of org.orcid.jaxb.model.v3.dev1.common.Url in project ORCID-Source by ORCID.

the class ResearcherUrlsTest method testInvalidPutCodeReturns404.

@Test
public void testInvalidPutCodeReturns404() throws InterruptedException, JSONException {
    String accessToken = getAccessToken();
    assertNotNull(accessToken);
    org.orcid.jaxb.model.v3.dev1.record.ResearcherUrl rUrlToCreate = new org.orcid.jaxb.model.v3.dev1.record.ResearcherUrl();
    rUrlToCreate.setUrl(new org.orcid.jaxb.model.v3.dev1.common.Url("http://newurl.com/" + System.currentTimeMillis()));
    rUrlToCreate.setUrlName("url-name-" + System.currentTimeMillis());
    rUrlToCreate.setVisibility(org.orcid.jaxb.model.v3.dev1.common.Visibility.PUBLIC);
    rUrlToCreate.setPutCode(1234567890L);
    ClientResponse response = memberV3Dev1ApiClient.updateResearcherUrls(getUser1OrcidId(), rUrlToCreate, accessToken);
    assertNotNull(response);
    assertEquals(ClientResponse.Status.NOT_FOUND.getStatusCode(), response.getStatus());
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) BlackBoxBaseV3_0_dev1(org.orcid.integration.blackbox.api.v3.dev1.BlackBoxBaseV3_0_dev1) Test(org.junit.Test)

Example 72 with Url

use of org.orcid.jaxb.model.v3.dev1.common.Url in project ORCID-Source by ORCID.

the class ResearcherUrlsTest method testCantAddDuplicatedResearcherUrl.

@Test
public void testCantAddDuplicatedResearcherUrl() throws InterruptedException, JSONException, URISyntaxException {
    String accessToken = getAccessToken();
    assertNotNull(accessToken);
    Long now = System.currentTimeMillis();
    org.orcid.jaxb.model.v3.dev1.record.ResearcherUrl rUrlToCreate = new org.orcid.jaxb.model.v3.dev1.record.ResearcherUrl();
    rUrlToCreate.setUrl(new org.orcid.jaxb.model.v3.dev1.common.Url("http://newurl.com/" + now));
    rUrlToCreate.setUrlName("url-name-" + System.currentTimeMillis());
    rUrlToCreate.setVisibility(org.orcid.jaxb.model.v3.dev1.common.Visibility.PUBLIC);
    // Create it
    ClientResponse postResponse = memberV3Dev1ApiClient.createResearcherUrls(getUser1OrcidId(), rUrlToCreate, accessToken);
    assertNotNull(postResponse);
    assertEquals(Response.Status.CREATED.getStatusCode(), postResponse.getStatus());
    String location = postResponse.getHeaders().getFirst("Location");
    Long putCode1 = Long.valueOf(location.substring(location.lastIndexOf('/') + 1));
    // Add it again
    postResponse = memberV3Dev1ApiClient.createResearcherUrls(getUser1OrcidId(), rUrlToCreate, accessToken);
    assertNotNull(postResponse);
    assertEquals(Response.Status.CONFLICT.getStatusCode(), postResponse.getStatus());
    // Check it can be created by other client
    String otherClientToken = getAccessToken(getUser1OrcidId(), getUser1Password(), getScopes(ScopePathType.PERSON_UPDATE), getClient2ClientId(), getClient2ClientSecret(), getClient2RedirectUri());
    postResponse = memberV3Dev1ApiClient.createResearcherUrls(getUser1OrcidId(), rUrlToCreate, otherClientToken);
    assertNotNull(postResponse);
    assertEquals(Response.Status.CREATED.getStatusCode(), postResponse.getStatus());
    location = postResponse.getHeaders().getFirst("Location");
    Long putCode2 = Long.valueOf(location.substring(location.lastIndexOf('/') + 1));
    // Delete both
    ClientResponse deleteResponse = memberV3Dev1ApiClient.deleteResearcherUrl(getUser1OrcidId(), putCode1, accessToken);
    assertEquals(Response.Status.NO_CONTENT.getStatusCode(), deleteResponse.getStatus());
    deleteResponse = memberV3Dev1ApiClient.deleteResearcherUrl(getUser1OrcidId(), putCode2, otherClientToken);
    assertEquals(Response.Status.NO_CONTENT.getStatusCode(), deleteResponse.getStatus());
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) BlackBoxBaseV3_0_dev1(org.orcid.integration.blackbox.api.v3.dev1.BlackBoxBaseV3_0_dev1) Test(org.junit.Test)

Example 73 with Url

use of org.orcid.jaxb.model.v3.dev1.common.Url in project ORCID-Source by ORCID.

the class ResearcherUrlsTest method testCreateGetUpdateAndDeleteResearcherUrl.

@Test
public void testCreateGetUpdateAndDeleteResearcherUrl() throws InterruptedException, JSONException, URISyntaxException {
    String accessToken = getAccessToken();
    assertNotNull(accessToken);
    org.orcid.jaxb.model.v3.dev1.record.ResearcherUrl rUrlToCreate = new org.orcid.jaxb.model.v3.dev1.record.ResearcherUrl();
    long time = System.currentTimeMillis();
    String url = "http://test.orcid.org/test/" + time;
    rUrlToCreate.setUrl(new org.orcid.jaxb.model.v3.dev1.common.Url(url));
    rUrlToCreate.setUrlName(url);
    // Create
    ClientResponse postResponse = memberV3Dev1ApiClient.createResearcherUrls(getUser1OrcidId(), rUrlToCreate, accessToken);
    assertNotNull(postResponse);
    assertEquals(Response.Status.CREATED.getStatusCode(), postResponse.getStatus());
    String locationPath = postResponse.getLocation().getPath();
    assertTrue("Location header path should match pattern, but was " + locationPath, locationPath.matches(".*/v3.0_dev1/" + getUser1OrcidId() + "/researcher-urls/\\d+"));
    // Read
    ClientResponse getResponse = memberV3Dev1ApiClient.viewLocationXml(postResponse.getLocation(), accessToken);
    assertEquals(Response.Status.OK.getStatusCode(), getResponse.getStatus());
    org.orcid.jaxb.model.v3.dev1.record.ResearcherUrl gotResearcherUrl = getResponse.getEntity(org.orcid.jaxb.model.v3.dev1.record.ResearcherUrl.class);
    assertNotNull(gotResearcherUrl);
    assertNotNull(gotResearcherUrl.getPutCode());
    assertNotNull(gotResearcherUrl.getSource());
    assertNotNull(gotResearcherUrl.getCreatedDate());
    assertNotNull(gotResearcherUrl.getLastModifiedDate());
    assertEquals(getClient1ClientId(), gotResearcherUrl.getSource().retrieveSourcePath());
    assertEquals("http://test.orcid.org/test/" + time, gotResearcherUrl.getUrl().getValue());
    assertEquals("http://test.orcid.org/test/" + time, gotResearcherUrl.getUrlName());
    assertEquals("public", gotResearcherUrl.getVisibility().value());
    assertNotNull(gotResearcherUrl.getDisplayIndex());
    Long originalDisplayIndex = gotResearcherUrl.getDisplayIndex();
    // Save the original visibility
    org.orcid.jaxb.model.v3.dev1.common.Visibility originalVisibility = gotResearcherUrl.getVisibility();
    org.orcid.jaxb.model.v3.dev1.common.Visibility updatedVisibility = org.orcid.jaxb.model.v3.dev1.common.Visibility.PRIVATE.equals(originalVisibility) ? org.orcid.jaxb.model.v3.dev1.common.Visibility.LIMITED : org.orcid.jaxb.model.v3.dev1.common.Visibility.PRIVATE;
    // Verify you cant update the visibility
    gotResearcherUrl.setVisibility(updatedVisibility);
    ClientResponse putResponse = memberV3Dev1ApiClient.updateLocationXml(postResponse.getLocation(), accessToken, gotResearcherUrl);
    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
    gotResearcherUrl.setVisibility(originalVisibility);
    // Update
    org.orcid.jaxb.model.v3.dev1.common.LastModifiedDate initialLastModified = gotResearcherUrl.getLastModifiedDate();
    Long currentTime = System.currentTimeMillis();
    gotResearcherUrl.setUrlName(gotResearcherUrl.getUrlName() + " - " + currentTime);
    gotResearcherUrl.getUrl().setValue(gotResearcherUrl.getUrl().getValue() + currentTime);
    ClientResponse updatedResearcherUrlResponse = memberV3Dev1ApiClient.updateResearcherUrls(getUser1OrcidId(), gotResearcherUrl, accessToken);
    assertNotNull(updatedResearcherUrlResponse);
    assertEquals(Response.Status.OK.getStatusCode(), updatedResearcherUrlResponse.getStatus());
    org.orcid.jaxb.model.v3.dev1.record.ResearcherUrl updatedResearcherUrl = updatedResearcherUrlResponse.getEntity(org.orcid.jaxb.model.v3.dev1.record.ResearcherUrl.class);
    assertNotNull(updatedResearcherUrl);
    assertEquals("http://test.orcid.org/test/" + time + currentTime, updatedResearcherUrl.getUrl().getValue());
    assertEquals("http://test.orcid.org/test/" + time + " - " + currentTime, updatedResearcherUrl.getUrlName());
    assertEquals(originalDisplayIndex, updatedResearcherUrl.getDisplayIndex());
    // Keep it public, since it is more restrictive than the user visibility
    // default
    assertEquals(org.orcid.jaxb.model.v3.dev1.common.Visibility.PUBLIC, updatedResearcherUrl.getVisibility());
    assertFalse(initialLastModified.equals(updatedResearcherUrl.getLastModifiedDate()));
    // Delete
    ClientResponse deleteResponse = memberV3Dev1ApiClient.deleteResearcherUrl(getUser1OrcidId(), gotResearcherUrl.getPutCode(), accessToken);
    assertEquals(Response.Status.NO_CONTENT.getStatusCode(), deleteResponse.getStatus());
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) BlackBoxBaseV3_0_dev1(org.orcid.integration.blackbox.api.v3.dev1.BlackBoxBaseV3_0_dev1) Test(org.junit.Test)

Example 74 with Url

use of org.orcid.jaxb.model.v3.dev1.common.Url in project ORCID-Source by ORCID.

the class JpaJaxbResearcherUrlAdapterTest method fromResearcherUrlEntityToResearcherUrl.

@Test
public void fromResearcherUrlEntityToResearcherUrl() {
    ResearcherUrlEntity entity = getResearcherUrlEntity();
    ResearcherUrl r = jpaJaxbResearcherUrlAdapter.toResearcherUrl(entity);
    // General info
    assertNotNull(r);
    assertEquals(Long.valueOf(13579), r.getPutCode());
    assertEquals("http://orcid.org", r.getUrl().getValue());
    assertEquals("Orcid URL", r.getUrlName());
    assertEquals(Visibility.LIMITED, r.getVisibility());
    // Source
    assertEquals("APP-0001", r.getSource().retrieveSourcePath());
}
Also used : ResearcherUrlEntity(org.orcid.persistence.jpa.entities.ResearcherUrlEntity) ResearcherUrl(org.orcid.jaxb.model.v3.dev1.record.ResearcherUrl) Test(org.junit.Test)

Example 75 with Url

use of org.orcid.jaxb.model.v3.dev1.common.Url in project ORCID-Source by ORCID.

the class JpaJaxbWorkAdapterTest method testToWorkEntity.

@Test
public void testToWorkEntity() throws JAXBException {
    Work work = getWork(true);
    assertNotNull(work);
    WorkEntity workEntity = jpaJaxbWorkAdapter.toWorkEntity(work);
    assertNotNull(workEntity);
    assertEquals(org.orcid.jaxb.model.common_v2.Visibility.PRIVATE, workEntity.getVisibility());
    assertNotNull(workEntity);
    assertEquals(123, workEntity.getId().longValue());
    assertEquals("common:title", workEntity.getTitle());
    assertTrue(PojoUtil.isEmpty(workEntity.getSubtitle()));
    assertEquals("common:translated-title", workEntity.getTranslatedTitle());
    assertEquals("en", workEntity.getTranslatedTitleLanguageCode());
    assertEquals("work:short-description", workEntity.getDescription());
    assertEquals(org.orcid.jaxb.model.record_v2.CitationType.FORMATTED_UNSPECIFIED, workEntity.getCitationType());
    assertEquals(org.orcid.jaxb.model.record_v2.WorkType.ARTISTIC_PERFORMANCE, workEntity.getWorkType());
    PublicationDateEntity publicationDateEntity = workEntity.getPublicationDate();
    assertNotNull(publicationDateEntity);
    assertEquals(1848, publicationDateEntity.getYear().intValue());
    assertEquals(02, publicationDateEntity.getMonth().intValue());
    assertEquals(02, publicationDateEntity.getDay().intValue());
    assertEquals("{\"workExternalIdentifier\":[{\"relationship\":\"SELF\",\"url\":{\"value\":\"http://orcid.org\"},\"workExternalIdentifierType\":\"AGR\",\"workExternalIdentifierId\":{\"content\":\"work:external-identifier-id\"}}]}", workEntity.getExternalIdentifiersJson());
    assertEquals("http://tempuri.org", workEntity.getWorkUrl());
    assertEquals("{\"contributor\":[{\"contributorOrcid\":{\"uri\":\"http://orcid.org/8888-8888-8888-8880\",\"path\":\"8888-8888-8888-8880\",\"host\":\"orcid.org\"},\"creditName\":{\"content\":\"work:credit-name\"},\"contributorEmail\":{\"value\":\"work@contributor.email\"},\"contributorAttributes\":{\"contributorSequence\":\"FIRST\",\"contributorRole\":\"AUTHOR\"}}]}", workEntity.getContributorsJson());
    assertEquals("en", workEntity.getLanguageCode());
    assertEquals(org.orcid.jaxb.model.common_v2.Iso3166Country.AF, workEntity.getIso2Country());
    // Source
    assertNull(workEntity.getSourceId());
    assertNull(workEntity.getClientSourceId());
    assertNull(workEntity.getElementSourceId());
}
Also used : WorkEntity(org.orcid.persistence.jpa.entities.WorkEntity) PublicationDateEntity(org.orcid.persistence.jpa.entities.PublicationDateEntity) Work(org.orcid.jaxb.model.v3.dev1.record.Work) Test(org.junit.Test)

Aggregations

Url (org.orcid.jaxb.model.v3.dev1.common.Url)85 Test (org.junit.Test)76 ExternalID (org.orcid.jaxb.model.v3.dev1.record.ExternalID)68 ExternalIDs (org.orcid.jaxb.model.v3.dev1.record.ExternalIDs)50 ResearcherUrl (org.orcid.jaxb.model.v3.dev1.record.ResearcherUrl)42 Response (javax.ws.rs.core.Response)28 DBUnitTest (org.orcid.test.DBUnitTest)28 Title (org.orcid.jaxb.model.v3.dev1.common.Title)23 Work (org.orcid.jaxb.model.v3.dev1.record.Work)23 WorkTitle (org.orcid.jaxb.model.v3.dev1.record.WorkTitle)19 List (java.util.List)16 PeerReview (org.orcid.jaxb.model.v3.dev1.record.PeerReview)13 PersonExternalIdentifier (org.orcid.jaxb.model.v3.dev1.record.PersonExternalIdentifier)13 Funding (org.orcid.jaxb.model.v3.dev1.record.Funding)12 ClientResponse (com.sun.jersey.api.client.ClientResponse)10 DisambiguatedOrganization (org.orcid.jaxb.model.v3.dev1.common.DisambiguatedOrganization)8 TranslatedTitle (org.orcid.jaxb.model.v3.dev1.common.TranslatedTitle)8 WorkSummary (org.orcid.jaxb.model.v3.dev1.record.summary.WorkSummary)8 BaseTest (org.orcid.core.BaseTest)7 Organization (org.orcid.jaxb.model.v3.dev1.common.Organization)6