@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 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()); }