@Test
 public void testGetWithPublicAPI() {
   ClientResponse getAllResponse = publicV2ApiClient.viewResearcherUrlsXML(user1OrcidId);
   assertNotNull(getAllResponse);
   ResearcherUrls researcherUrls = getAllResponse.getEntity(ResearcherUrls.class);
   assertNotNull(researcherUrls);
   assertNotNull(researcherUrls.getResearcherUrls());
   for (ResearcherUrl rUrl : researcherUrls.getResearcherUrls()) {
     assertNotNull(rUrl);
     assertEquals(Visibility.PUBLIC, rUrl.getVisibility());
     ClientResponse theRUrl =
         publicV2ApiClient.viewResearcherUrlXML(user1OrcidId, String.valueOf(rUrl.getPutCode()));
     assertNotNull(theRUrl);
     ResearcherUrl researcherUrl = theRUrl.getEntity(ResearcherUrl.class);
     assertEquals(researcherUrl.getCreatedDate(), rUrl.getCreatedDate());
     assertEquals(researcherUrl.getLastModifiedDate(), rUrl.getLastModifiedDate());
     assertEquals(researcherUrl.getPutCode(), rUrl.getPutCode());
     assertEquals(researcherUrl.getSource(), rUrl.getSource());
     assertEquals(researcherUrl.getUrl(), rUrl.getUrl());
     assertEquals(researcherUrl.getUrlName(), rUrl.getUrlName());
     assertEquals(researcherUrl.getVisibility(), rUrl.getVisibility());
   }
 }
  @Test
  public void testAddMultipleResearcherUrlAndGetThem()
      throws InterruptedException, JSONException, URISyntaxException {
    String accessToken =
        getAccessToken(this.client1ClientId, this.client1ClientSecret, this.client1RedirectUri);
    assertNotNull(accessToken);
    Long now = System.currentTimeMillis();
    ResearcherUrl rUrlToCreate = new ResearcherUrl();
    rUrlToCreate.setVisibility(Visibility.PUBLIC);

    for (int i = 0; i < 3; i++) {
      // Change the name
      rUrlToCreate.setUrlName("url-name-" + now + "-" + i);
      rUrlToCreate.setUrl(new Url("http://newurl.com/" + now + "/" + i));
      // Create it
      ClientResponse postResponse =
          memberV2ApiClient.createResearcherUrls(user1OrcidId, rUrlToCreate, accessToken);
      assertNotNull(postResponse);
      assertEquals(Response.Status.CREATED.getStatusCode(), postResponse.getStatus());
    }

    ClientResponse getAllResponse =
        memberV2ApiClient.getResearcherUrls(this.user1OrcidId, accessToken);
    assertNotNull(getAllResponse);
    ResearcherUrls researcherUrls = getAllResponse.getEntity(ResearcherUrls.class);
    assertNotNull(researcherUrls);
    assertNotNull(researcherUrls.getPath());
    assertTrue(researcherUrls.getPath().contains(this.user1OrcidId));
    assertNotNull(researcherUrls.getResearcherUrls());

    boolean found1 = false, found2 = false, found3 = false;

    for (ResearcherUrl rUrl : researcherUrls.getResearcherUrls()) {
      if (rUrl.getUrlName().equals("url-name-" + now + "-0")) {
        found1 = true;
      } else if (rUrl.getUrlName().equals("url-name-" + now + "-1")) {
        found2 = true;
      } else if (rUrl.getUrlName().equals("url-name-" + now + "-2")) {
        found3 = true;
      }
    }

    assertTrue(found1 && found2 && found3);

    // Clean
    for (ResearcherUrl rUrl : researcherUrls.getResearcherUrls()) {
      memberV2ApiClient.deletePeerReviewXml(this.user1OrcidId, rUrl.getPutCode(), accessToken);
    }
  }
  @Test
  public void testTryingToAddInvalidResearcherUrls()
      throws InterruptedException, JSONException, URISyntaxException {
    String accessToken =
        getAccessToken(this.client1ClientId, this.client1ClientSecret, this.client1RedirectUri);
    assertNotNull(accessToken);
    ResearcherUrl rUrlToCreate = new ResearcherUrl();
    rUrlToCreate.setUrl(new Url(""));
    rUrlToCreate.setUrlName("");
    // Create
    ClientResponse postResponse =
        memberV2ApiClient.createResearcherUrls(user1OrcidId, rUrlToCreate, accessToken);
    assertNotNull(postResponse);
    assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), postResponse.getStatus());

    String _351Chars = new String();
    for (int i = 0; i < 531; i++) {
      _351Chars += "a";
    }

    rUrlToCreate.setUrl(new Url(_351Chars));
    postResponse = memberV2ApiClient.createResearcherUrls(user1OrcidId, rUrlToCreate, accessToken);
    assertNotNull(postResponse);
    assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), postResponse.getStatus());

    rUrlToCreate.setUrl(new Url("http://myurl.com"));
    rUrlToCreate.setUrlName(_351Chars);
    postResponse = memberV2ApiClient.createResearcherUrls(user1OrcidId, rUrlToCreate, accessToken);
    assertNotNull(postResponse);
    assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), postResponse.getStatus());

    rUrlToCreate.setUrlName("The name");
    postResponse = memberV2ApiClient.createResearcherUrls(user1OrcidId, rUrlToCreate, accessToken);
    assertNotNull(postResponse);
    assertEquals(Response.Status.CREATED.getStatusCode(), postResponse.getStatus());

    // Read it to delete it
    ClientResponse getResponse =
        memberV2ApiClient.viewLocationXml(postResponse.getLocation(), accessToken);
    assertEquals(Response.Status.OK.getStatusCode(), getResponse.getStatus());
    ResearcherUrl gotResearcherUrl = getResponse.getEntity(ResearcherUrl.class);
    ClientResponse deleteResponse =
        memberV2ApiClient.deleteResearcherUrl(
            this.user1OrcidId, gotResearcherUrl.getPutCode(), accessToken);
    assertEquals(Response.Status.NO_CONTENT.getStatusCode(), deleteResponse.getStatus());
  }
Exemplo n.º 4
0
 public ClientResponse updateResearcherUrls(String orcid, ResearcherUrl rUrl, String accessToken) {
   URI uri = UriBuilder.fromPath(RESEARCHER_URLS + PUTCODE).build(orcid, rUrl.getPutCode());
   return orcidClientHelper.putClientResponseWithToken(uri, VND_ORCID_XML, rUrl, accessToken);
 }
  @Test
  public void testResearcherUrl() throws InterruptedException, JSONException, URISyntaxException {
    String accessToken =
        getAccessToken(this.client1ClientId, this.client1ClientSecret, this.client1RedirectUri);
    assertNotNull(accessToken);
    ResearcherUrl rUrlToCreate =
        (ResearcherUrl)
            unmarshallFromPath(
                "/record_2.0_rc2/samples/researcher-url-2.0_rc2.xml", ResearcherUrl.class);
    assertNotNull(rUrlToCreate);
    Long time = System.currentTimeMillis();
    rUrlToCreate.setCreatedDate(null);
    rUrlToCreate.setLastModifiedDate(null);
    rUrlToCreate.setPath(null);
    rUrlToCreate.setPutCode(null);
    rUrlToCreate.setSource(null);
    rUrlToCreate.setUrl(new Url(rUrlToCreate.getUrl().getValue() + time));
    rUrlToCreate.setUrlName(String.valueOf(time));

    // Create
    ClientResponse postResponse =
        memberV2ApiClient.createResearcherUrls(user1OrcidId, 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(".*/v2.0_rc2/" + user1OrcidId + "/researcher-urls/\\d+"));

    // Read
    ClientResponse getResponse =
        memberV2ApiClient.viewLocationXml(postResponse.getLocation(), accessToken);
    assertEquals(Response.Status.OK.getStatusCode(), getResponse.getStatus());
    ResearcherUrl gotResearcherUrl = getResponse.getEntity(ResearcherUrl.class);
    assertNotNull(gotResearcherUrl);
    assertNotNull(gotResearcherUrl.getPutCode());
    assertNotNull(gotResearcherUrl.getSource());
    assertNotNull(gotResearcherUrl.getCreatedDate());
    assertNotNull(gotResearcherUrl.getLastModifiedDate());
    assertEquals(this.client1ClientId, gotResearcherUrl.getSource().retrieveSourcePath());
    assertEquals("http://site1.com/" + time, gotResearcherUrl.getUrl().getValue());
    assertEquals(String.valueOf(time), gotResearcherUrl.getUrlName());
    assertEquals("public", gotResearcherUrl.getVisibility().value());

    // Update
    LastModifiedDate initialLastModified = gotResearcherUrl.getLastModifiedDate();
    Long currentTime = System.currentTimeMillis();
    gotResearcherUrl.setUrlName(gotResearcherUrl.getUrlName() + " - " + currentTime);
    gotResearcherUrl.getUrl().setValue(gotResearcherUrl.getUrl().getValue() + currentTime);
    gotResearcherUrl.setVisibility(Visibility.LIMITED);
    ClientResponse updatedResearcherUrlResponse =
        memberV2ApiClient.updateResearcherUrls(this.user1OrcidId, gotResearcherUrl, accessToken);
    assertNotNull(updatedResearcherUrlResponse);
    assertEquals(Response.Status.OK.getStatusCode(), updatedResearcherUrlResponse.getStatus());
    ResearcherUrl updatedResearcherUrl =
        updatedResearcherUrlResponse.getEntity(ResearcherUrl.class);
    assertNotNull(updatedResearcherUrl);
    assertEquals(
        "http://site1.com/" + time + currentTime, updatedResearcherUrl.getUrl().getValue());
    assertEquals(String.valueOf(time) + " - " + currentTime, updatedResearcherUrl.getUrlName());
    // Keep it public, since it is more restrictive than the user visibility
    // default
    assertEquals("public", updatedResearcherUrl.getVisibility().value());
    assertFalse(initialLastModified.equals(updatedResearcherUrl.getLastModifiedDate()));

    // Delete
    ClientResponse deleteResponse =
        memberV2ApiClient.deleteResearcherUrl(
            this.user1OrcidId, gotResearcherUrl.getPutCode(), accessToken);
    assertEquals(Response.Status.NO_CONTENT.getStatusCode(), deleteResponse.getStatus());
  }